diff options
Diffstat (limited to 'Swift/QtUI/QtMainWindow.cpp')
-rw-r--r-- | Swift/QtUI/QtMainWindow.cpp | 175 |
1 files changed, 159 insertions, 16 deletions
diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp index 05c78b3..52b6bcc 100644 --- a/Swift/QtUI/QtMainWindow.cpp +++ b/Swift/QtUI/QtMainWindow.cpp @@ -1,9 +1,9 @@ /* - * Copyright (c) 2010-2011 Kevin Smith + * Copyright (c) 2010-2014 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "QtMainWindow.h" +#include <Swift/QtUI/QtMainWindow.h> #include <boost/optional.hpp> @@ -22,10 +22,8 @@ #include <QTabWidget> -#include <Swift/QtUI/QtSwiftUtil.h> -#include <Swift/QtUI/QtTabWidget.h> -#include <Swift/QtUI/QtSettingsProvider.h> -#include <Swift/QtUI/QtLoginWindow.h> -#include <Roster/QtRosterWidget.h> +#include <Swiften/Base/Platform.h> + #include <Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h> +#include <Swift/Controllers/UIEvents/RequestHistoryUIEvent.h> #include <Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h> #include <Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h> @@ -33,10 +31,26 @@ #include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h> #include <Swift/Controllers/UIEvents/RequestAdHocUIEvent.h> -#include <Swift/QtUI/QtUISettingConstants.h> +#include <Swift/Controllers/UIEvents/RequestBlockListDialogUIEvent.h> #include <Swift/Controllers/SettingConstants.h> +#include <Swift/QtUI/Roster/QtFilterWidget.h> +#include <Swift/QtUI/QtSwiftUtil.h> +#include <Swift/QtUI/QtTabWidget.h> +#include <Swift/QtUI/QtSettingsProvider.h> +#include <Swift/QtUI/QtLoginWindow.h> +#include <Swift/QtUI/Roster/QtRosterWidget.h> +#include <Swift/QtUI/QtUISettingConstants.h> +#include <Swift/QtUI/QtAdHocCommandWithJIDWindow.h> +#if defined(SWIFTEN_PLATFORM_MACOSX) +#include <Swift/QtUI/CocoaUIHelpers.h> +#elif defined(SWIFTEN_PLATFORM_WINDOWS) +#include <Swift/QtUI/WinUIHelpers.h> +#else +#include <Swift/QtUI/QtCertificateViewerDialog.h> +#endif + namespace Swift { -QtMainWindow::QtMainWindow(SettingsProvider* settings, UIEventStream* uiEventStream, QtLoginWindow::QtMenus loginMenus) : QWidget(), MainWindow(false), loginMenus_(loginMenus) { +QtMainWindow::QtMainWindow(SettingsProvider* settings, UIEventStream* uiEventStream, QtLoginWindow::QtMenus loginMenus, StatusCache* statusCache, bool emoticonsExist, bool enableAdHocCommandOnJID) : QWidget(), MainWindow(false), loginMenus_(loginMenus) { uiEventStream_ = uiEventStream; settings_ = settings; @@ -45,8 +59,9 @@ QtMainWindow::QtMainWindow(SettingsProvider* settings, UIEventStream* uiEventStr mainLayout->setContentsMargins(0,0,0,0); mainLayout->setSpacing(0); - meView_ = new QtRosterHeader(settings, this); + meView_ = new QtRosterHeader(settings, statusCache, this); mainLayout->addWidget(meView_); connect(meView_, SIGNAL(onChangeStatusRequest(StatusShow::Type, const QString&)), this, SLOT(handleStatusChanged(StatusShow::Type, const QString&))); connect(meView_, SIGNAL(onEditProfileRequest()), this, SLOT(handleEditProfileRequest())); + connect(meView_, SIGNAL(onShowCertificateInfo()), this, SLOT(handleShowCertificateInfo())); tabs_ = new QtTabWidget(this); @@ -64,5 +79,7 @@ QtMainWindow::QtMainWindow(SettingsProvider* settings, UIEventStream* uiEventStr treeWidget_ = new QtRosterWidget(uiEventStream_, settings_, this); + contactTabLayout->addWidget(treeWidget_); + new QtFilterWidget(this, treeWidget_, uiEventStream_, contactTabLayout); tabs_->addTab(contactsTabWidget_, tr("&Contacts")); @@ -81,8 +98,30 @@ QtMainWindow::QtMainWindow(SettingsProvider* settings, UIEventStream* uiEventStr connect(tabs_, SIGNAL(currentChanged(int)), this, SLOT(handleTabChanged(int))); + tabBarCombo_ = NULL; + if (settings_->getSetting(QtUISettingConstants::USE_SCREENREADER)) { + tabs_->tabBar()->hide(); + tabBarCombo_ = new QComboBox(this); + tabBarCombo_->setAccessibleName("Current View"); + tabBarCombo_->addItem(tr("Contacts")); + tabBarCombo_->addItem(tr("Chats")); + tabBarCombo_->addItem(tr("Notices")); + tabBarCombo_->setCurrentIndex(tabs_->currentIndex()); + mainLayout->addWidget(tabBarCombo_); + connect(tabBarCombo_, SIGNAL(currentIndexChanged(int)), tabs_, SLOT(setCurrentIndex(int))); + } + + this->setLayout(mainLayout); QMenu* viewMenu = new QMenu(tr("&View"), this); menus_.push_back(viewMenu); + + compactRosterAction_ = new QAction(tr("&Compact Roster"), this); + compactRosterAction_->setCheckable(true); + compactRosterAction_->setChecked(false); + connect(compactRosterAction_, SIGNAL(toggled(bool)), SLOT(handleCompactRosterToggled(bool))); + viewMenu->addAction(compactRosterAction_); + handleCompactRosterToggled(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER)); + showOfflineAction_ = new QAction(tr("&Show offline contacts"), this); showOfflineAction_->setCheckable(true); @@ -92,4 +131,13 @@ QtMainWindow::QtMainWindow(SettingsProvider* settings, UIEventStream* uiEventStr handleShowOfflineToggled(settings_->getSetting(SettingConstants::SHOW_OFFLINE)); + if (emoticonsExist) { + showEmoticonsAction_ = new QAction(tr("&Show Emoticons"), this); + showEmoticonsAction_->setCheckable(true); + showEmoticonsAction_->setChecked(false); + connect(showEmoticonsAction_, SIGNAL(toggled(bool)), SLOT(handleShowEmoticonsToggled(bool))); + viewMenu->addAction(showEmoticonsAction_); + handleShowEmoticonsToggled(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS)); + } + //QAction* compactRosterAction_ = new QAction(tr("&Compact Roster"), this); //compactRosterAction_->setCheckable(true); @@ -100,20 +148,45 @@ QtMainWindow::QtMainWindow(SettingsProvider* settings, UIEventStream* uiEventStr QMenu* actionsMenu = new QMenu(tr("&Actions"), this); menus_.push_back(actionsMenu); - QAction* editProfileAction = new QAction(tr("Edit &Profile"), this); + QAction* editProfileAction = new QAction(tr("Edit &Profile…"), this); connect(editProfileAction, SIGNAL(triggered()), SLOT(handleEditProfileAction())); actionsMenu->addAction(editProfileAction); - QAction* joinMUCAction = new QAction(tr("Enter &Room"), this); + onlineOnlyActions_ << editProfileAction; + QAction* joinMUCAction = new QAction(tr("Enter &Room…"), this); connect(joinMUCAction, SIGNAL(triggered()), SLOT(handleJoinMUCAction())); actionsMenu->addAction(joinMUCAction); - addUserAction_ = new QAction(tr("&Add Contact"), this); + onlineOnlyActions_ << joinMUCAction; +#ifdef SWIFT_EXPERIMENTAL_HISTORY + QAction* viewLogsAction = new QAction(tr("&View History…"), this); + connect(viewLogsAction, SIGNAL(triggered()), SLOT(handleViewLogsAction())); + actionsMenu->addAction(viewLogsAction); +#endif + openBlockingListEditor_ = new QAction(tr("Edit &Blocking List…"), this); + connect(openBlockingListEditor_, SIGNAL(triggered()), SLOT(handleEditBlockingList())); + actionsMenu->addAction(openBlockingListEditor_); + onlineOnlyActions_ << openBlockingListEditor_; + openBlockingListEditor_->setVisible(false); + addUserAction_ = new QAction(tr("&Add Contact…"), this); + addUserAction_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); + addUserAction_->setShortcutContext(Qt::ApplicationShortcut); connect(addUserAction_, SIGNAL(triggered(bool)), this, SLOT(handleAddUserActionTriggered(bool))); actionsMenu->addAction(addUserAction_); - editUserAction_ = new QAction(tr("&Edit Selected Contact"), this); + onlineOnlyActions_ << addUserAction_; + editUserAction_ = new QAction(tr("&Edit Selected Contact…"), this); connect(editUserAction_, SIGNAL(triggered(bool)), treeWidget_, SLOT(handleEditUserActionTriggered(bool))); actionsMenu->addAction(editUserAction_); + onlineOnlyActions_ << editUserAction_; editUserAction_->setEnabled(false); - chatUserAction_ = new QAction(tr("Start &Chat"), this); + chatUserAction_ = new QAction(tr("Start &Chat…"), this); + chatUserAction_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N)); + chatUserAction_->setShortcutContext(Qt::ApplicationShortcut); connect(chatUserAction_, SIGNAL(triggered(bool)), this, SLOT(handleChatUserActionTriggered(bool))); actionsMenu->addAction(chatUserAction_); + onlineOnlyActions_ << chatUserAction_; + if (enableAdHocCommandOnJID) { + otherAdHocAction_ = new QAction(tr("Run Other Command"), this); + connect(otherAdHocAction_, SIGNAL(triggered()), this, SLOT(handleOtherAdHocActionTriggered())); + actionsMenu->addAction(otherAdHocAction_); + onlineOnlyActions_ << otherAdHocAction_; + } serverAdHocMenu_ = new QMenu(tr("Run Server Command"), this); actionsMenu->addMenu(serverAdHocMenu_); @@ -131,5 +204,5 @@ QtMainWindow::QtMainWindow(SettingsProvider* settings, UIEventStream* uiEventStr loginMenus_.generalMenu->insertAction(generalMenuActions.at(generalMenuActions.count()-2),toggleRequestDeliveryReceipts_); - treeWidget_->onSomethingSelectedChanged.connect(boost::bind(&QAction::setEnabled, editUserAction_, _1)); + treeWidget_->onSomethingSelectedChanged.connect(boost::bind(&QtMainWindow::handleSomethingSelectedChanged, this, _1)); setAvailableAdHocCommands(std::vector<DiscoItems::Item>()); @@ -154,4 +227,17 @@ void QtMainWindow::handleToggleRequestDeliveryReceipts(bool enabled) { } +void QtMainWindow::handleShowCertificateInfo() { + onShowCertificateRequest(); +} + +void QtMainWindow::handleEditBlockingList() { + uiEventStream_->send(boost::make_shared<RequestBlockListDialogUIEvent>()); +} + +void QtMainWindow::handleSomethingSelectedChanged(bool itemSelected) { + bool isOnline = addUserAction_->isEnabled(); + editUserAction_->setEnabled(isOnline && itemSelected); +} + QtEventWindow* QtMainWindow::getEventWindow() { return eventWindow_; @@ -202,4 +288,8 @@ void QtMainWindow::handleChatUserActionTriggered(bool /*checked*/) { } +void QtMainWindow::handleOtherAdHocActionTriggered() { + new QtAdHocCommandWithJIDWindow(uiEventStream_); +} + void QtMainWindow::handleSignOutAction() { loginMenus_.generalMenu->removeAction(toggleRequestDeliveryReceipts_); @@ -215,4 +305,8 @@ void QtMainWindow::handleJoinMUCAction() { } +void QtMainWindow::handleViewLogsAction() { + uiEventStream_->send(boost::make_shared<RequestHistoryUIEvent>()); +} + void QtMainWindow::handleStatusChanged(StatusShow::Type showType, const QString &statusMessage) { onChangeStatusRequest(showType, Q2PSTRING(statusMessage)); @@ -223,7 +317,18 @@ void QtMainWindow::handleSettingChanged(const std::string& settingPath) { handleShowOfflineToggled(settings_->getSetting(SettingConstants::SHOW_OFFLINE)); } + if (settingPath == QtUISettingConstants::SHOW_EMOTICONS.getKey()) { + handleShowEmoticonsToggled(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS)); + } if (settingPath == SettingConstants::REQUEST_DELIVERYRECEIPTS.getKey()) { toggleRequestDeliveryReceipts_->setChecked(settings_->getSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS)); } + if (settingPath == QtUISettingConstants::COMPACT_ROSTER.getKey()) { + handleCompactRosterToggled(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER)); + } +} + +void QtMainWindow::handleCompactRosterToggled(bool state) { + settings_->storeSetting(QtUISettingConstants::COMPACT_ROSTER, state); + compactRosterAction_->setChecked(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER)); } @@ -233,4 +338,9 @@ void QtMainWindow::handleShowOfflineToggled(bool state) { } +void QtMainWindow::handleShowEmoticonsToggled(bool state) { + settings_->storeSetting(QtUISettingConstants::SHOW_EMOTICONS, state); + showEmoticonsAction_->setChecked(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS)); +} + void QtMainWindow::setMyNick(const std::string& nick) { meView_->setNick(P2QSTRING(nick)); @@ -251,4 +361,15 @@ void QtMainWindow::setMyStatusText(const std::string& status) { void QtMainWindow::setMyStatusType(StatusShow::Type type) { meView_->setStatusType(type); + const bool online = (type != StatusShow::None); + treeWidget_->setOnline(online); + chatListWindow_->setOnline(online); + foreach (QAction *action, onlineOnlyActions_) { + action->setEnabled(online); + } + serverAdHocMenu_->setEnabled(online); +} + +void QtMainWindow::setMyContactRosterItem(boost::shared_ptr<ContactRosterItem> contact) { + meView_->setContactRosterItem(contact); } @@ -257,4 +378,22 @@ void QtMainWindow::setConnecting() { } +void QtMainWindow::setStreamEncryptionStatus(bool tlsInPlaceAndValid) { + meView_->setStreamEncryptionStatus(tlsInPlaceAndValid); +} + +void QtMainWindow::openCertificateDialog(const std::vector<Certificate::ref>& chain) { + openCertificateDialog(chain, this); +} + +void QtMainWindow::openCertificateDialog(const std::vector<Certificate::ref>& chain, QWidget* parent) { +#if defined(SWIFTEN_PLATFORM_MACOSX) + CocoaUIHelpers::displayCertificateChainAsSheet(parent, chain); +#elif defined(SWIFTEN_PLATFORM_WINDOWS) + WinUIHelpers::displayCertificateChainAsSheet(parent, chain); +#else + QtCertificateViewerDialog::displayCertificateChainAsSheet(parent, chain); +#endif +} + void QtMainWindow::handleAdHocActionTriggered(bool /*checked*/) { QAction* action = qobject_cast<QAction*>(sender()); @@ -285,4 +424,8 @@ void QtMainWindow::setAvailableAdHocCommands(const std::vector<DiscoItems::Item> } +void QtMainWindow::setBlockingCommandAvailable(bool isAvailable) { + openBlockingListEditor_->setVisible(isAvailable); +} + } |