diff options
| author | Kevin Smith <git@kismith.co.uk> | 2011-10-29 10:59:11 (GMT) |
|---|---|---|
| committer | Kevin Smith <git@kismith.co.uk> | 2011-10-29 10:59:11 (GMT) |
| commit | 06e40dd580e43e11e519acbb2d30156c18081f79 (patch) | |
| tree | 83503e4acac19c40c745c44504e3675894cb2dea /Swift/QtUI | |
| parent | 7cb49cb679156151f19a556de76274c5a25e6de2 (diff) | |
| download | swift-contrib-06e40dd580e43e11e519acbb2d30156c18081f79.zip swift-contrib-06e40dd580e43e11e519acbb2d30156c18081f79.tar.bz2 | |
Make the --eagle-mode banner per-login, not per-run
Diffstat (limited to 'Swift/QtUI')
| -rw-r--r-- | Swift/QtUI/QtLoginWindow.cpp | 42 | ||||
| -rw-r--r-- | Swift/QtUI/QtLoginWindow.h | 5 | ||||
| -rw-r--r-- | Swift/QtUI/QtSwift.cpp | 24 | ||||
| -rw-r--r-- | Swift/QtUI/QtUIFactory.cpp | 2 |
4 files changed, 35 insertions, 38 deletions
diff --git a/Swift/QtUI/QtLoginWindow.cpp b/Swift/QtUI/QtLoginWindow.cpp index 0db6071..87dd849 100644 --- a/Swift/QtUI/QtLoginWindow.cpp +++ b/Swift/QtUI/QtLoginWindow.cpp @@ -1,79 +1,80 @@ /* * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include "QtLoginWindow.h" #include <boost/bind.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <algorithm> #include <cassert> #include <QApplication> #include <QBoxLayout> #include <QComboBox> #include <QDesktopWidget> #include <QFileDialog> #include <QStatusBar> #include <QToolButton> #include <QLabel> #include <QMenuBar> #include <QHBoxLayout> #include <qdebug.h> #include <QCloseEvent> #include <QCursor> #include <QMessageBox> #include <QKeyEvent> #include "Swift/Controllers/UIEvents/UIEventStream.h" #include "Swift/Controllers/UIEvents/RequestXMLConsoleUIEvent.h" #include "Swift/Controllers/UIEvents/RequestFileTransferListUIEvent.h" #include "Swift/Controllers/UIEvents/ToggleSoundsUIEvent.h" #include "Swift/Controllers/UIEvents/ToggleNotificationsUIEvent.h" #include "Swiften/Base/Platform.h" +#include "Swiften/Base/Paths.h" #include "QtAboutWidget.h" #include "QtSwiftUtil.h" #include "QtMainWindow.h" #include "QtUtilities.h" namespace Swift{ -QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream) : QMainWindow(), forgetful_(false) { +QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream, bool eagleMode) : QMainWindow(), eagleMode_(eagleMode) { uiEventStream_ = uiEventStream; setWindowTitle("Swift"); #ifndef Q_WS_MAC setWindowIcon(QIcon(":/logo-icon-16.png")); #endif QtUtilities::setX11Resource(this, "Main"); 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); loginWidgetWrapper_ = new QWidget(this); loginWidgetWrapper_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, loginWidgetWrapper_); layout->addStretch(2); QLabel* logo = new QLabel(this); logo->setPixmap(QPixmap(":/logo-shaded-text.256.png")); logo->setScaledContents(true); logo->setFixedSize(192,192); QWidget *logoWidget = new QWidget(this); QHBoxLayout *logoLayout = new QHBoxLayout(); logoLayout->setMargin(0); logoLayout->addStretch(0); logoLayout->addWidget(logo); logoLayout->addStretch(0); logoWidget->setLayout(logoLayout); layout->addWidget(logoWidget); @@ -170,82 +171,81 @@ QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream) : QMainWindow(), forg #ifdef SWIFT_EXPERIMENTAL_FT fileTransferOverviewAction_ = new QAction(tr("Show &File Transfer Overview"), this); connect(fileTransferOverviewAction_, SIGNAL(triggered()), SLOT(handleShowFileTransferOverview())); generalMenu_->addAction(fileTransferOverviewAction_); #endif toggleSoundsAction_ = new QAction(tr("&Play Sounds"), this); toggleSoundsAction_->setCheckable(true); toggleSoundsAction_->setChecked(true); connect(toggleSoundsAction_, SIGNAL(toggled(bool)), SLOT(handleToggleSounds(bool))); generalMenu_->addAction(toggleSoundsAction_); toggleNotificationsAction_ = new QAction(tr("Display Pop-up &Notifications"), this); toggleNotificationsAction_->setCheckable(true); toggleNotificationsAction_->setChecked(true); connect(toggleNotificationsAction_, SIGNAL(toggled(bool)), SLOT(handleToggleNotifications(bool))); #if defined(SWIFTEN_PLATFORM_LINUX) || defined(SWIFTEN_PLATFORM_WINDOWS) generalMenu_->addAction(toggleNotificationsAction_); #endif #ifndef SWIFTEN_PLATFORM_MACOSX swiftMenu_->addSeparator(); #endif #ifdef SWIFTEN_PLATFORM_MACOSX QAction* quitAction = new QAction("&Quit", this); #else QAction* quitAction = new QAction(tr("&Quit"), this); #endif connect(quitAction, SIGNAL(triggered()), SLOT(handleQuit())); swiftMenu_->addAction(quitAction); setInitialMenus(); uiEventStream_->onUIEvent.connect(boost::bind(&QtLoginWindow::handleUIEvent, this, _1)); - this->show(); -} -void QtLoginWindow::setRememberingAllowed(bool allowed) { - forgetful_ = true; - remember_->setEnabled(allowed); - loginAutomatically_->setEnabled(allowed); - xmlConsoleAction_->setEnabled(allowed); - if (!allowed) { + + remember_->setEnabled(!eagleMode_); + loginAutomatically_->setEnabled(!eagleMode_); + xmlConsoleAction_->setEnabled(!eagleMode_); + if (eagleMode_) { remember_->setChecked(false); loginAutomatically_->setChecked(false); } + + this->show(); } bool QtLoginWindow::eventFilter(QObject *obj, QEvent *event) { if (obj == username_->view() && event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); if (keyEvent->key() == Qt::Key_Delete || keyEvent->key() == Qt::Key_Backspace) { QString jid(username_->view()->currentIndex().data().toString()); int result = QMessageBox::question(this, tr("Remove profile"), tr("Remove the profile '%1'?").arg(jid), QMessageBox::Yes | QMessageBox::No); if (result == QMessageBox::Yes) { onPurgeSavedLoginRequest(Q2PSTRING(jid)); } return true; } } return QObject::eventFilter(obj, event); } void QtLoginWindow::handleUIEvent(boost::shared_ptr<UIEvent> event) { boost::shared_ptr<ToggleSoundsUIEvent> soundEvent = boost::dynamic_pointer_cast<ToggleSoundsUIEvent>(event); if (soundEvent) { toggleSoundsAction_->setChecked(soundEvent->getEnabled()); } boost::shared_ptr<ToggleNotificationsUIEvent> notificationsEvent = boost::dynamic_pointer_cast<ToggleNotificationsUIEvent>(event); if (notificationsEvent) { toggleNotificationsAction_->setChecked(notificationsEvent->getEnabled()); } } void QtLoginWindow::selectUser(const std::string& username) { for (int i = 0; i < usernames_.count(); i++) { if (P2QSTRING(username) == usernames_[i]) { username_->setCurrentIndex(i); password_->setFocus(); break; } @@ -290,72 +290,94 @@ void QtLoginWindow::addAvailableAccount(const std::string& defaultJID, const std 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]); remember_->setChecked(password_->text() != ""); } } if (!certificateFile_.isEmpty()) { certificateButton_->setChecked(true); } } void QtLoginWindow::loggedOut() { stack_->removeWidget(stack_->currentWidget()); stack_->addWidget(loginWidgetWrapper_); stack_->setCurrentWidget(loginWidgetWrapper_); setInitialMenus(); setIsLoggingIn(false); } void QtLoginWindow::setIsLoggingIn(bool loggingIn) { /* Change the for loop as well if you add to this.*/ QWidget* widgets[5] = {username_, password_, remember_, loginAutomatically_, certificateButton_}; loginButton_->setText(loggingIn ? tr("Cancel") : tr("Connect")); for (int i = 0; i < 5; i++) { widgets[i]->setEnabled(!loggingIn); } } void QtLoginWindow::loginClicked() { if (username_->isEnabled()) { + if (eagleMode_) { + QString clickThroughPath(P2QSTRING((Paths::getExecutablePath() / "eagle-banner.txt").string())); + QFile clickThroughFile(clickThroughPath); + if (clickThroughFile.exists() && clickThroughFile.open(QIODevice::ReadOnly)) { + QString banner; + while (!clickThroughFile.atEnd()) { + QByteArray line = clickThroughFile.readLine(); + banner += line + "\n"; + } + if (!banner.isEmpty()) { + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Confirm terms of use")); + msgBox.setText(""); + msgBox.setInformativeText(banner); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::No); + if (msgBox.exec() != QMessageBox::Yes) { + return; + } + } + } + } onLoginRequest(Q2PSTRING(username_->currentText()), Q2PSTRING(password_->text()), Q2PSTRING(certificateFile_), remember_->isChecked(), loginAutomatically_->isChecked()); - if (forgetful_) { /* Mustn't remember logins */ + if (eagleMode_) { /* Mustn't remember logins */ username_->clearEditText(); password_->setText(""); } } else { onCancelLoginRequest(); } } void QtLoginWindow::setLoginAutomatically(bool loginAutomatically) { loginAutomatically_->setChecked(loginAutomatically); } void QtLoginWindow::handleCertficateChecked(bool checked) { if (checked) { certificateFile_ = QFileDialog::getOpenFileName(this, tr("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(); } } diff --git a/Swift/QtUI/QtLoginWindow.h b/Swift/QtUI/QtLoginWindow.h index 414bb20..acf327f 100644 --- a/Swift/QtUI/QtLoginWindow.h +++ b/Swift/QtUI/QtLoginWindow.h @@ -1,94 +1,93 @@ /* * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <QMainWindow> #include <QPointer> #include <QLineEdit> #include <QPushButton> #include <QCheckBox> #include <QStackedWidget> #include <QMenuBar> #include "Swift/Controllers/UIInterfaces/LoginWindow.h" #include "Swift/Controllers/UIEvents/UIEventStream.h" #include "Swift/Controllers/UIInterfaces/MainWindow.h" #include "QtAboutWidget.h" class QLabel; class QToolButton; class QComboBox; namespace Swift { class QtLoginWindow : public QMainWindow, public LoginWindow { Q_OBJECT public: - QtLoginWindow(UIEventStream* uiEventStream); + QtLoginWindow(UIEventStream* uiEventStream, bool eagleMode); void morphInto(MainWindow *mainWindow); virtual void loggedOut(); virtual void setMessage(const std::string& message); virtual void addAvailableAccount(const std::string& defaultJID, const std::string& defaultPassword, const std::string& defaultCertificate); virtual void removeAvailableAccount(const std::string& jid); virtual void setLoginAutomatically(bool loginAutomatically); virtual void setIsLoggingIn(bool loggingIn); - virtual void setRememberingAllowed(bool allowed); void selectUser(const std::string& user); bool askUserToTrustCertificatePermanently(const std::string& message, Certificate::ref certificate); void hide(); virtual void quit(); signals: void geometryChanged(); private slots: void loginClicked(); void handleCertficateChecked(bool); void handleQuit(); void handleShowXMLConsole(); void handleShowFileTransferOverview(); void handleToggleSounds(bool enabled); void handleToggleNotifications(bool enabled); void handleAbout(); void bringToFront(); void handleUsernameTextChanged(); void resizeEvent(QResizeEvent* event); void moveEvent(QMoveEvent* event); void handleUIEvent(boost::shared_ptr<UIEvent> event); protected: bool eventFilter(QObject *obj, QEvent *event); private: void setInitialMenus(); QWidget* loginWidgetWrapper_; QStringList usernames_; QStringList passwords_; QStringList certificateFiles_; QComboBox* username_; QLineEdit* password_; QPushButton* loginButton_; /* If you add a widget here, change setLoggingIn as well.*/ QCheckBox* remember_; QCheckBox* loginAutomatically_; QStackedWidget* stack_; QLabel* message_; QString certificateFile_; QToolButton* certificateButton_; QMenuBar* menuBar_; QMenu* swiftMenu_; QMenu* generalMenu_; QAction* toggleSoundsAction_; QAction* toggleNotificationsAction_; UIEventStream* uiEventStream_; QPointer<QtAboutWidget> aboutDialog_; - bool forgetful_; + bool eagleMode_; QAction* xmlConsoleAction_; QAction* fileTransferOverviewAction_; }; } diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp index 7c0a2bd..7f11b5c 100644 --- a/Swift/QtUI/QtSwift.cpp +++ b/Swift/QtUI/QtSwift.cpp @@ -1,71 +1,70 @@ /* * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include "QtSwift.h" #include <string> #include <QSplitter> #include <QFile> #include <boost/bind.hpp> #include <QMessageBox> #include <QApplication> #include "QtLoginWindow.h" #include "QtChatTabs.h" #include "QtSystemTray.h" #include "QtSoundPlayer.h" #include "QtSwiftUtil.h" #include "QtUIFactory.h" #include "QtChatWindowFactory.h" #include <Swiften/Base/Log.h> #include <Swift/Controllers/Storages/CertificateFileStorageFactory.h> #include "Swift/Controllers/Storages/FileStoragesFactory.h" #include "SwifTools/Application/PlatformApplicationPathProvider.h" #include <string> #include "Swiften/Base/Platform.h" #include "Swiften/Elements/Presence.h" #include "Swiften/Client/Client.h" #include "Swift/Controllers/MainController.h" #include "Swift/Controllers/ApplicationInfo.h" #include "Swift/Controllers/BuildVersion.h" #include "SwifTools/AutoUpdater/AutoUpdater.h" #include "SwifTools/AutoUpdater/PlatformAutoUpdaterFactory.h" -#include "Swiften/Base/Paths.h" #if defined(SWIFTEN_PLATFORM_WINDOWS) #include "WindowsNotifier.h" #elif defined(HAVE_GROWL) #include "SwifTools/Notifier/GrowlNotifier.h" #elif defined(SWIFTEN_PLATFORM_LINUX) #include "FreeDesktopNotifier.h" #else #include "SwifTools/Notifier/NullNotifier.h" #endif #if defined(SWIFTEN_PLATFORM_MACOSX) #include "SwifTools/Dock/MacOSXDock.h" #else #include "SwifTools/Dock/NullDock.h" #endif #if defined(SWIFTEN_PLATFORM_MACOSX) #include "QtURIHandler.h" #elif defined(SWIFTEN_PLATFORM_WIN32) #include <SwifTools/URIHandler/NullURIHandler.h> #else #include "QtDBUSURIHandler.h" #endif namespace Swift{ #if defined(SWIFTEN_PLATFORM_MACOSX) #define SWIFT_APPCAST_URL "http://swift.im/appcast/swift-mac-dev.xml" #else #define SWIFT_APPCAST_URL "" #endif po::options_description QtSwift::getOptionsDescription() { po::options_description result("Options"); @@ -143,90 +142,67 @@ QtSwift::QtSwift(const po::variables_map& options) : networkFactories_(&clientMa #elif defined(SWIFTEN_PLATFORM_WIN32) uriHandler_ = new NullURIHandler(); #else uriHandler_ = new QtDBUSURIHandler(); #endif if (splitter_) { splitter_->show(); } for (int i = 0; i < numberOfAccounts; i++) { if (i > 0) { // Don't add the first tray (see note above) systemTrays_.push_back(new QtSystemTray()); } QtUIFactory* uiFactory = new QtUIFactory(settings_, tabs_, splitter_, systemTrays_[i], chatWindowFactory_, startMinimized, eagleMode); uiFactories_.push_back(uiFactory); MainController* mainController = new MainController( &clientMainThreadCaller_, &networkFactories_, uiFactory, settings_, systemTrays_[i], soundPlayer_, storagesFactory_, certificateStorageFactory_, dock_, notifier_, uriHandler_, &idleDetector_, options.count("latency-debug") > 0, eagleMode); mainControllers_.push_back(mainController); } - if (eagleMode) { - QString clickThroughPath(P2QSTRING((Paths::getExecutablePath() / "eagle-banner.txt").string())); - QFile clickThroughFile(clickThroughPath); - if (clickThroughFile.exists() && clickThroughFile.open(QIODevice::ReadOnly)) { - QString banner; - while (!clickThroughFile.atEnd()) { - QByteArray line = clickThroughFile.readLine(); - banner += line + "\n"; - } - if (!banner.isEmpty()) { - QMessageBox msgBox; - msgBox.setWindowTitle(tr("Confirm terms of use")); - msgBox.setText(tr("Do you agree to the terms of use?")); - msgBox.setInformativeText(banner); - msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); - msgBox.setDefaultButton(QMessageBox::No); - if (msgBox.exec() != QMessageBox::Yes) { - exit(0); - } - } - } - } - // PlatformAutoUpdaterFactory autoUpdaterFactory; // if (autoUpdaterFactory.isSupported()) { // autoUpdater_ = autoUpdaterFactory.createAutoUpdater(SWIFT_APPCAST_URL); // autoUpdater_->checkForUpdates(); // } } QtSwift::~QtSwift() { delete notifier_; delete autoUpdater_; foreach (QtUIFactory* factory, uiFactories_) { delete factory; } foreach (MainController* controller, mainControllers_) { delete controller; } delete settings_; foreach (QtSystemTray* tray, systemTrays_) { delete tray; } delete tabs_; delete splitter_; delete uriHandler_; delete dock_; delete soundPlayer_; delete chatWindowFactory_; delete certificateStorageFactory_; delete storagesFactory_; } } diff --git a/Swift/QtUI/QtUIFactory.cpp b/Swift/QtUI/QtUIFactory.cpp index faeebdc..5f55795 100644 --- a/Swift/QtUI/QtUIFactory.cpp +++ b/Swift/QtUI/QtUIFactory.cpp @@ -28,71 +28,71 @@ #define CHATWINDOW_FONT_SIZE "chatWindowFontSize" namespace Swift { QtUIFactory::QtUIFactory(QtSettingsProvider* settings, QtChatTabs* tabs, QSplitter* netbookSplitter, QtSystemTray* systemTray, QtChatWindowFactory* chatWindowFactory, bool startMinimized, bool eagleMode) : settings(settings), tabs(tabs), netbookSplitter(netbookSplitter), systemTray(systemTray), chatWindowFactory(chatWindowFactory), lastMainWindow(NULL), loginWindow(NULL), startMinimized(startMinimized), eagleMode(eagleMode) { chatFontSize = settings->getIntSetting(CHATWINDOW_FONT_SIZE, 0); } XMLConsoleWidget* QtUIFactory::createXMLConsoleWidget() { QtXMLConsoleWidget* widget = new QtXMLConsoleWidget(); tabs->addTab(widget); if (!tabs->isVisible()) { tabs->show(); } widget->show(); return widget; } FileTransferListWidget* QtUIFactory::createFileTransferListWidget() { QtFileTransferListWidget* widget = new QtFileTransferListWidget(); tabs->addTab(widget); if (!tabs->isVisible()) { tabs->show(); } widget->show(); return widget; } MainWindow* QtUIFactory::createMainWindow(UIEventStream* eventStream) { lastMainWindow = new QtMainWindow(settings, eventStream); return lastMainWindow; } LoginWindow* QtUIFactory::createLoginWindow(UIEventStream* eventStream) { - loginWindow = new QtLoginWindow(eventStream); + loginWindow = new QtLoginWindow(eventStream, eagleMode); if (netbookSplitter) { netbookSplitter->insertWidget(0, loginWindow); } connect(systemTray, SIGNAL(clicked()), loginWindow, SLOT(bringToFront())); #ifndef SWIFT_MOBILE QVariant loginWindowGeometryVariant = settings->getQSettings()->value("loginWindowGeometry"); if (loginWindowGeometryVariant.isValid()) { loginWindow->restoreGeometry(loginWindowGeometryVariant.toByteArray()); } connect(loginWindow, SIGNAL(geometryChanged()), this, SLOT(handleLoginWindowGeometryChanged())); if (startMinimized) loginWindow->hide(); #endif return loginWindow; } void QtUIFactory::handleLoginWindowGeometryChanged() { settings->getQSettings()->setValue("loginWindowGeometry", loginWindow->saveGeometry()); } EventWindow* QtUIFactory::createEventWindow() { return lastMainWindow->getEventWindow(); } ChatListWindow* QtUIFactory::createChatListWindow(UIEventStream*) { return lastMainWindow->getChatListWindow(); } MUCSearchWindow* QtUIFactory::createMUCSearchWindow() { return new QtMUCSearchWindow(); } ChatWindow* QtUIFactory::createChatWindow(const JID& contact, UIEventStream* eventStream) { QtChatWindow* window = dynamic_cast<QtChatWindow*>(chatWindowFactory->createChatWindow(contact, eventStream)); chatWindows.push_back(window); |
Swift