summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2009-11-26 17:31:53 (GMT)
committerKevin Smith <git@kismith.co.uk>2009-11-26 17:46:21 (GMT)
commiteebdef9a7724ff7fa86a5d1cca37759d37bbb336 (patch)
tree7dd76b8e5d364eb1b019b2511a839a9eac8397e4 /Swift/QtUI/QtLoginWindow.cpp
parent39e58e4593f54a65f810e73728fe2490958fcba2 (diff)
downloadswift-eebdef9a7724ff7fa86a5d1cca37759d37bbb336.zip
swift-eebdef9a7724ff7fa86a5d1cca37759d37bbb336.tar.bz2
Plumbing to show a dummy XMLConsoleWidget in the chat tabs.
This should all work now, and the XMLConsoleController needs to talk to the QtXMLConsoleWidget through the XMLConsoleWidget interface. Resolves: #256
Diffstat (limited to 'Swift/QtUI/QtLoginWindow.cpp')
-rw-r--r--Swift/QtUI/QtLoginWindow.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/Swift/QtUI/QtLoginWindow.cpp b/Swift/QtUI/QtLoginWindow.cpp
index 6466692..2fd27c6 100644
--- a/Swift/QtUI/QtLoginWindow.cpp
+++ b/Swift/QtUI/QtLoginWindow.cpp
@@ -1,154 +1,163 @@
#include "QtLoginWindow.h"
+#include "Swift/Controllers/UIEvents/UIEventStream.h"
+#include "Swift/Controllers/UIEvents/RequestXMLConsoleUIEvent.h"
#include "QtAboutWidget.h"
#include "QtSwiftUtil.h"
#include "QtMainWindow.h"
#include <algorithm>
#include <QApplication>
#include <QBoxLayout>
#include <QComboBox>
#include <QDesktopWidget>
#include <QFileDialog>
#include <QStatusBar>
#include <QToolButton>
#include <QLabel>
#include <QMenuBar>
#include <cassert>
namespace Swift{
-QtLoginWindow::QtLoginWindow() : QMainWindow() {
+QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream) : QMainWindow() {
+ uiEventStream_ = uiEventStream;
setWindowTitle("Swift");
resize(200, 500);
setContentsMargins(0,0,0,0);
QWidget *centralWidget = new QWidget(this);
setCentralWidget(centralWidget);
QBoxLayout *topLayout = new QBoxLayout(QBoxLayout::TopToBottom, centralWidget);
stack_ = new QStackedWidget(centralWidget);
topLayout->addWidget(stack_);
topLayout->setMargin(0);
QWidget *wrapperWidget = new QWidget(this);
wrapperWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, wrapperWidget);
layout->addStretch();
QLabel* logo = new QLabel(this);
logo->setPixmap(QPixmap(":/logo-shaded-text.256.png"));
logo->setScaledContents(true);
logo->setFixedSize(192,192);
layout->addWidget(logo);
layout->addStretch();
QLabel* jidLabel = new QLabel(this);
jidLabel->setText("<font size='-1'>User address</font>");
layout->addWidget(jidLabel);
username_ = new QComboBox(this);
username_->setEditable(true);
layout->addWidget(username_);
QLabel* passwordLabel = new QLabel();
passwordLabel->setText("<font size='-1'>Password</font>");
layout->addWidget(passwordLabel);
QWidget* w = new QWidget(this);
w->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
layout->addWidget(w);
QHBoxLayout* credentialsLayout = new QHBoxLayout(w);
credentialsLayout->setMargin(0);
credentialsLayout->setSpacing(3);
password_ = new QLineEdit(this);
password_->setEchoMode(QLineEdit::Password);
connect(password_, SIGNAL(returnPressed()), this, SLOT(loginClicked()));
connect(username_->lineEdit(), SIGNAL(returnPressed()), password_, SLOT(setFocus()));
connect(username_, SIGNAL(editTextChanged(const QString&)), this, SLOT(handleUsernameTextChanged()));
credentialsLayout->addWidget(password_);
certificateButton_ = new QToolButton(this);
certificateButton_->setCheckable(true);
certificateButton_->setIcon(QIcon(":/icons/certificate.png"));
credentialsLayout->addWidget(certificateButton_);
connect(certificateButton_, SIGNAL(clicked(bool)), SLOT(handleCertficateChecked(bool)));
loginButton_ = new QPushButton(this);
loginButton_->setText(tr("Connect"));
loginButton_->setAutoDefault(true);
loginButton_->setDefault(true);
layout->addWidget(loginButton_);
message_ = new QLabel(this);
message_->setTextFormat(Qt::RichText);
message_->setWordWrap(true);
layout->addWidget(message_);
layout->addStretch();
remember_ = new QCheckBox(tr("Remember Password?"), this);
layout->addWidget(remember_);
connect(loginButton_, SIGNAL(clicked()), SLOT(loginClicked()));
stack_->addWidget(wrapperWidget);
#ifdef SWIFTEN_PLATFORM_MACOSX
menuBar_ = new QMenuBar(NULL);
#else
menuBar_ = menuBar();
#endif
QApplication::setQuitOnLastWindowClosed(false);
swiftMenu_ = new QMenu(tr("Swift"), this);
QAction* aboutAction = new QAction("About Swift", this);
connect(aboutAction, SIGNAL(activated()), SLOT(handleAbout()));
swiftMenu_->addAction(aboutAction);
+
+ toolsMenu_ = new QMenu(tr("Tools"), this);
+
+ QAction* xmlConsoleAction = new QAction(tr("Show Debug Console"), this);
+ connect(xmlConsoleAction, SIGNAL(activated()), SLOT(handleShowXMLConsole()));
+ toolsMenu_->addAction(xmlConsoleAction);
QAction* quitAction = new QAction("Quit", this);
connect(quitAction, SIGNAL(activated()), SLOT(handleQuit()));
swiftMenu_->addAction(quitAction);
setInitialMenus();
this->show();
}
/**
* Move and resize the window, but respect minimum sizes.
* (Like QWidget::setGeometry, only that will truncate the window
* the setGeometry docs say that it shouldn't do this, but I've just seen it
* maybe we can remove this method if that's a Qt bug (or I'm misusing it)).
*/
void QtLoginWindow::setGentleGeometry(const QRect& rect) {
resize(rect.size());
move(rect.topLeft());
}
QRect QtLoginWindow::defaultPosition() {
QDesktopWidget desktop;
int windowWidth = 200;
int windowHeight = 500;
QRect screen = desktop.screenGeometry(-1); //appear on default screen
windowWidth = std::min(windowWidth, screen.width());
windowHeight = std::min(windowHeight, screen.height());
int left = (screen.width() - windowWidth) / 2;
int height = (screen.height() - windowHeight) / 2;
return QRect(left, height, windowWidth, windowHeight);
}
void QtLoginWindow::addAvailableAccount(const String& defaultJID, const String& defaultPassword, const String& defaultCertificate) {
QString username = P2QSTRING(defaultJID);
int index = -1;
for (int i = 0; i < usernames_.count(); i++) {
if (username == usernames_[i]) {
index = i;
}
}
if (index == -1) {
usernames_.append(username);
passwords_.append(P2QSTRING(defaultPassword));
certificateFiles_.append(P2QSTRING(defaultCertificate));
username_->addItem(username);
} else {
usernames_[index] = username;
passwords_[index] = P2QSTRING(defaultPassword);
@@ -165,99 +174,104 @@ void QtLoginWindow::handleUsernameTextChanged() {
}
}
if (!certificateFile_.isEmpty()) {
certificateButton_->setChecked(true);
}
remember_->setChecked(password_->text() != "");
}
void QtLoginWindow::loggedOut() {
if (stack_->count() > 1) {
QWidget* current = stack_->currentWidget();
stack_->setCurrentIndex(0);
stack_->removeWidget(current);
}
setInitialMenus();
setEnabled(true);
}
void QtLoginWindow::loginClicked() {
setEnabled(false);
message_->setText("");
onLoginRequest(Q2PSTRING(username_->currentText()), Q2PSTRING(password_->text()), Q2PSTRING(certificateFile_), remember_->isChecked());
}
void QtLoginWindow::handleCertficateChecked(bool checked) {
if (checked) {
certificateFile_ = QFileDialog::getOpenFileName(this, "Select an authentication certificate", QString(), QString("*.cert"));
if (certificateFile_.isEmpty()) {
certificateButton_->setChecked(false);
}
}
else {
certificateFile_ = "";
}
}
void QtLoginWindow::handleAbout() {
if (!aboutDialog_) {
aboutDialog_ = new QtAboutWidget();
aboutDialog_->show();
}
else {
aboutDialog_->show();
aboutDialog_->raise();
aboutDialog_->activateWindow();
}
}
+void QtLoginWindow::handleShowXMLConsole() {
+ uiEventStream_->send(boost::shared_ptr<RequestXMLConsoleUIEvent>(new RequestXMLConsoleUIEvent()));
+}
+
void QtLoginWindow::handleQuit() {
QApplication::quit();
}
void QtLoginWindow::setInitialMenus() {
menuBar_->clear();
menuBar_->addMenu(swiftMenu_);
+ menuBar_->addMenu(toolsMenu_);
}
void QtLoginWindow::morphInto(MainWindow *mainWindow) {
QtMainWindow *qtMainWindow = dynamic_cast<QtMainWindow*>(mainWindow);
assert(qtMainWindow);
stack_->addWidget(qtMainWindow);
stack_->setCurrentWidget(qtMainWindow);
setEnabled(true);
setInitialMenus();
foreach (QMenu* menu, qtMainWindow->getMenus()) {
menuBar_->addMenu(menu);
}
}
void QtLoginWindow::setMessage(const String& message) {
if (!message.isEmpty()) {
message_->setText("<center><font color=\"red\">" + P2QSTRING(message) + "</font></center>");
}
else {
message_->setText("");
}
}
void QtLoginWindow::bringToFront() {
if (isHidden()) {
showNormal();
raise();
activateWindow();
}
else {
hide();
}
}
void QtLoginWindow::resizeEvent(QResizeEvent*) {
emit geometryChanged();
}
void QtLoginWindow::moveEvent(QMoveEvent*) {
emit geometryChanged();
}
}