diff options
Diffstat (limited to 'Swift/QtUI')
| -rw-r--r-- | Swift/QtUI/QtLoginWindow.cpp | 9 | ||||
| -rw-r--r-- | Swift/QtUI/QtLoginWindow.h | 1 |
2 files changed, 10 insertions, 0 deletions
diff --git a/Swift/QtUI/QtLoginWindow.cpp b/Swift/QtUI/QtLoginWindow.cpp index 2fd27c6..a222e8e 100644 --- a/Swift/QtUI/QtLoginWindow.cpp +++ b/Swift/QtUI/QtLoginWindow.cpp @@ -88,96 +88,105 @@ QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream) : QMainWindow() { 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()); } +void QtLoginWindow::selectUser(const String& username) { + for (int i = 0; i < usernames_.count(); i++) { + if (P2QSTRING(username) == usernames_[i]) { + username_->setCurrentIndex(i); + break; + } + } +} + 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); certificateFiles_[index] = P2QSTRING(defaultCertificate); } } void QtLoginWindow::handleUsernameTextChanged() { QString username = username_->currentText(); for (int i = 0; i < usernames_.count(); i++) { if (username_->currentText() == usernames_[i]) { certificateFile_ == certificateFiles_[i]; password_->setText(passwords_[i]); } } if (!certificateFile_.isEmpty()) { certificateButton_->setChecked(true); } remember_->setChecked(password_->text() != ""); } void QtLoginWindow::loggedOut() { if (stack_->count() > 1) { diff --git a/Swift/QtUI/QtLoginWindow.h b/Swift/QtUI/QtLoginWindow.h index 491521b..38852ce 100644 --- a/Swift/QtUI/QtLoginWindow.h +++ b/Swift/QtUI/QtLoginWindow.h @@ -1,68 +1,69 @@ #ifndef SWIFT_QtLoginWindow_H #define SWIFT_QtLoginWindow_H #include <QMainWindow> #include <QPointer> #include <QLineEdit> #include <QPushButton> #include <QCheckBox> #include <QStackedWidget> #include <QMenuBar> #include "Swift/Controllers/UIInterfaces/LoginWindow.h" #include "Swift/Controllers/MainWindow.h" #include "QtAboutWidget.h" class QLabel; class QToolButton; class QComboBox; namespace Swift { class UIEventStream; class QtLoginWindow : public QMainWindow, public LoginWindow { Q_OBJECT public: QtLoginWindow(UIEventStream* uiEventStream); void morphInto(MainWindow *mainWindow); virtual void loggedOut(); virtual void setMessage(const String& message); virtual void addAvailableAccount(const String& defaultJID, const String& defaultPassword, const String& defaultCertificate); static QRect defaultPosition(); void setGentleGeometry(const QRect&); + void selectUser(const String& user); signals: void geometryChanged(); private slots: void loginClicked(); void handleCertficateChecked(bool); void handleQuit(); void handleShowXMLConsole(); void handleAbout(); void bringToFront(); void handleUsernameTextChanged(); void resizeEvent(QResizeEvent* event); void moveEvent(QMoveEvent* event); private: void setInitialMenus(); QStringList usernames_; QStringList passwords_; QStringList certificateFiles_; QComboBox* username_; QLineEdit* password_; QPushButton* loginButton_; QCheckBox* remember_; QStackedWidget* stack_; QLabel* message_; QString certificateFile_; QToolButton* certificateButton_; QMenuBar* menuBar_; QMenu* swiftMenu_; QMenu* toolsMenu_; UIEventStream* uiEventStream_; QPointer<QtAboutWidget> aboutDialog_; }; } #endif |
Swift