diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-12-12 12:29:20 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-12-12 16:00:53 (GMT) |
commit | 4315ccbd51f63e408d69d944f162d0ead4f9addd (patch) | |
tree | 046b3734d18c7c5e76040e8798a6f4af5e5045cb /Swift | |
parent | aaf38fe2e6804bd87ea5e99a05ed57070cbe1c57 (diff) | |
download | swift-contrib-4315ccbd51f63e408d69d944f162d0ead4f9addd.zip swift-contrib-4315ccbd51f63e408d69d944f162d0ead4f9addd.tar.bz2 |
Refactored own nickname handling.
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/Controllers/MainController.cpp | 2 | ||||
-rw-r--r-- | Swift/Controllers/RosterController.cpp | 28 | ||||
-rw-r--r-- | Swift/Controllers/RosterController.h | 6 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/MainWindow.h | 4 | ||||
-rw-r--r-- | Swift/Controllers/UnitTest/MockMainWindow.h | 3 | ||||
-rw-r--r-- | Swift/Controllers/UnitTest/RosterControllerTest.cpp | 6 | ||||
-rw-r--r-- | Swift/QtUI/QtMainWindow.cpp | 13 | ||||
-rw-r--r-- | Swift/QtUI/QtMainWindow.h | 5 | ||||
-rw-r--r-- | Swift/QtUI/QtNameWidget.cpp | 83 | ||||
-rw-r--r-- | Swift/QtUI/QtNameWidget.h | 50 | ||||
-rw-r--r-- | Swift/QtUI/QtRosterHeader.cpp | 59 | ||||
-rw-r--r-- | Swift/QtUI/QtRosterHeader.h | 11 | ||||
-rw-r--r-- | Swift/QtUI/SConscript | 1 |
13 files changed, 197 insertions, 74 deletions
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index c1d8682..f215dc6 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -230,7 +230,7 @@ void MainController::handleConnected() { bool freshLogin = rosterController_ == NULL; myStatusLooksOnline_ = true; if (freshLogin) { - rosterController_ = new RosterController(jid_, client_->getRoster(), client_->getAvatarManager(), mainWindowFactory_, client_->getNickResolver(), client_->getPresenceOracle(), client_->getSubscriptionManager(), eventController_, uiEventStream_, client_->getIQRouter(), settings_); + rosterController_ = new RosterController(jid_, client_->getRoster(), client_->getAvatarManager(), mainWindowFactory_, client_->getNickManager(), client_->getNickResolver(), client_->getPresenceOracle(), client_->getSubscriptionManager(), eventController_, uiEventStream_, client_->getIQRouter(), settings_); rosterController_->onChangeStatusRequest.connect(boost::bind(&MainController::handleChangeStatusRequest, this, _1, _2)); rosterController_->onSignOutRequest.connect(boost::bind(&MainController::signOut, this)); diff --git a/Swift/Controllers/RosterController.cpp b/Swift/Controllers/RosterController.cpp index cb044fb..1feeb58 100644 --- a/Swift/Controllers/RosterController.cpp +++ b/Swift/Controllers/RosterController.cpp @@ -32,6 +32,7 @@ #include "Swift/Controllers/UIEvents/RenameRosterItemUIEvent.h" #include "Swift/Controllers/UIEvents/RegroupRosterItemUIEvent.h" #include "Swift/Controllers/UIEvents/ToggleShowOfflineUIEvent.h" +#include <Swiften/Client/NickManager.h> namespace Swift { @@ -40,8 +41,8 @@ static const String SHOW_OFFLINE = "showOffline"; /** * The controller does not gain ownership of these parameters. */ -RosterController::RosterController(const JID& jid, XMPPRoster* xmppRoster, AvatarManager* avatarManager, MainWindowFactory* mainWindowFactory, NickResolver* nickResolver, PresenceOracle* presenceOracle, SubscriptionManager* subscriptionManager, EventController* eventController, UIEventStream* uiEventStream, IQRouter* iqRouter, SettingsProvider* settings) - : myJID_(jid), xmppRoster_(xmppRoster), mainWindowFactory_(mainWindowFactory), mainWindow_(mainWindowFactory_->createMainWindow(uiEventStream)), roster_(new Roster()), offlineFilter_(new OfflineRosterFilter()) { +RosterController::RosterController(const JID& jid, XMPPRoster* xmppRoster, AvatarManager* avatarManager, MainWindowFactory* mainWindowFactory, NickManager* nickManager, NickResolver* nickResolver, PresenceOracle* presenceOracle, SubscriptionManager* subscriptionManager, EventController* eventController, UIEventStream* uiEventStream, IQRouter* iqRouter, SettingsProvider* settings) + : myJID_(jid), xmppRoster_(xmppRoster), mainWindowFactory_(mainWindowFactory), mainWindow_(mainWindowFactory_->createMainWindow(uiEventStream)), roster_(new Roster()), offlineFilter_(new OfflineRosterFilter()), nickManager_(nickManager), nickResolver_(nickResolver) { iqRouter_ = iqRouter; presenceOracle_ = presenceOracle; subscriptionManager_ = subscriptionManager; @@ -63,13 +64,21 @@ RosterController::RosterController(const JID& jid, XMPPRoster* xmppRoster, Avata avatarManager_ = avatarManager; avatarManager_->onAvatarChanged.connect(boost::bind(&RosterController::handleAvatarChanged, this, _1)); mainWindow_->setMyAvatarPath(avatarManager_->getAvatarPath(myJID_).string()); - setNickResolver(nickResolver); + + nickManager_->onOwnNickChanged.connect(boost::bind(&MainWindow::setMyNick, mainWindow_, _1)); + mainWindow_->setMyJID(jid); + mainWindow_->setMyNick(nickManager_->getOwnNick()); + + mainWindow_->onChangeNickRequest.connect(boost::bind(&NickManager::setOwnNick, nickManager_, _1)); + if (settings->getBoolSetting(SHOW_OFFLINE, false)) { uiEventStream->onUIEvent(boost::shared_ptr<UIEvent>(new ToggleShowOfflineUIEvent(true))); } } RosterController::~RosterController() { + nickManager_->onOwnNickChanged.disconnect(boost::bind(&MainWindow::setMyNick, mainWindow_, _1)); + delete offlineFilter_; delete expandiness_; mainWindow_->setRosterModel(NULL); @@ -79,19 +88,6 @@ RosterController::~RosterController() { delete roster_; } -void RosterController::setNickResolver(NickResolver* nickResolver) { - nickResolver_ = nickResolver; - if (nickResolver_ != NULL) { - handleOwnNickChanged(nickResolver_->jidToNick(myJID_)); - - nickResolver_->onOwnNickChanged.connect(boost::bind(&RosterController::handleOwnNickChanged, this, _1)); - } -} - -void RosterController::handleOwnNickChanged(const String& nick) { - mainWindow_->setMyName(nick); -} - void RosterController::setEnabled(bool enabled) { if (!enabled) { roster_->applyOnItems(AppearOffline()); diff --git a/Swift/Controllers/RosterController.h b/Swift/Controllers/RosterController.h index 2b1793e..79c14b9 100644 --- a/Swift/Controllers/RosterController.h +++ b/Swift/Controllers/RosterController.h @@ -33,14 +33,14 @@ namespace Swift { class UIEventStream; class IQRouter; class SettingsProvider; + class NickManager; class RosterController { public: - RosterController(const JID& jid, XMPPRoster* xmppRoster, AvatarManager* avatarManager, MainWindowFactory* mainWindowFactory, NickResolver* nickResolver, PresenceOracle* presenceOracle, SubscriptionManager* subscriptionManager, EventController* eventController, UIEventStream* uiEventStream, IQRouter* iqRouter_, SettingsProvider* settings); + RosterController(const JID& jid, XMPPRoster* xmppRoster, AvatarManager* avatarManager, MainWindowFactory* mainWindowFactory, NickManager* nickManager, NickResolver* nickResolver, PresenceOracle* presenceOracle, SubscriptionManager* subscriptionManager, EventController* eventController, UIEventStream* uiEventStream, IQRouter* iqRouter_, SettingsProvider* settings); ~RosterController(); void showRosterWindow(); MainWindow* getWindow() {return mainWindow_;}; - void setNickResolver(NickResolver* nickResolver); boost::signal<void (StatusShow::Type, const String&)> onChangeStatusRequest; boost::signal<void ()> onSignOutRequest; void handleAvatarChanged(const JID& jid); @@ -59,7 +59,6 @@ namespace Swift { void handleSubscriptionRequestDeclined(SubscriptionRequestEvent* event); void handleUIEvent(boost::shared_ptr<UIEvent> event); void handleRosterSetError(ErrorPayload::ref error, boost::shared_ptr<RosterPayload> rosterPayload); - void handleOwnNickChanged(const String& nick); void applyAllPresenceTo(const JID& jid); JID myJID_; XMPPRoster* xmppRoster_; @@ -68,6 +67,7 @@ namespace Swift { Roster* roster_; OfflineRosterFilter* offlineFilter_; AvatarManager* avatarManager_; + NickManager* nickManager_; NickResolver* nickResolver_; PresenceOracle* presenceOracle_; SubscriptionManager* subscriptionManager_; diff --git a/Swift/Controllers/UIInterfaces/MainWindow.h b/Swift/Controllers/UIInterfaces/MainWindow.h index 0d33466..124d229 100644 --- a/Swift/Controllers/UIInterfaces/MainWindow.h +++ b/Swift/Controllers/UIInterfaces/MainWindow.h @@ -25,7 +25,8 @@ namespace Swift { return canDelete_; } - virtual void setMyName(const String& name) = 0; + virtual void setMyNick(const String& name) = 0; + virtual void setMyJID(const JID& jid) = 0; virtual void setMyAvatarPath(const String& path) = 0; virtual void setMyStatusText(const String& status) = 0; virtual void setMyStatusType(StatusShow::Type type) = 0; @@ -35,6 +36,7 @@ namespace Swift { boost::signal<void (StatusShow::Type, const String&)> onChangeStatusRequest; boost::signal<void ()> onSignOutRequest; + boost::signal<void (const String&)> onChangeNickRequest; private: bool canDelete_; diff --git a/Swift/Controllers/UnitTest/MockMainWindow.h b/Swift/Controllers/UnitTest/MockMainWindow.h index 3d786d9..79c148a 100644 --- a/Swift/Controllers/UnitTest/MockMainWindow.h +++ b/Swift/Controllers/UnitTest/MockMainWindow.h @@ -15,7 +15,8 @@ namespace Swift { MockMainWindow() {}; virtual ~MockMainWindow() {}; virtual void setRosterModel(Roster* roster) {this->roster = roster;}; - virtual void setMyName(const String& /*name*/) {};; + virtual void setMyNick(const String& /*name*/) {};; + virtual void setMyJID(const JID& /*jid*/) {};; virtual void setMyAvatarPath(const String& /*path*/) {}; virtual void setMyStatusText(const String& /*status*/) {}; virtual void setMyStatusType(StatusShow::Type /*type*/) {}; diff --git a/Swift/Controllers/UnitTest/RosterControllerTest.cpp b/Swift/Controllers/UnitTest/RosterControllerTest.cpp index 50419f9..df93ca5 100644 --- a/Swift/Controllers/UnitTest/RosterControllerTest.cpp +++ b/Swift/Controllers/UnitTest/RosterControllerTest.cpp @@ -30,6 +30,7 @@ #include "Swift/Controllers/UIEvents/RenameRosterItemUIEvent.h" #include "Swift/Controllers/UIEvents/RegroupRosterItemUIEvent.h" #include "Swiften/MUC/MUCRegistry.h" +#include <Swiften/Client/DummyNickManager.h> using namespace Swift; @@ -67,12 +68,14 @@ class RosterControllerTest : public CppUnit::TestFixture eventController_ = new EventController(); uiEventStream_ = new UIEventStream(); settings_ = new DummySettingsProvider(); - rosterController_ = new RosterController(jid_, xmppRoster_, avatarManager_, mainWindowFactory_, nickResolver_, presenceOracle_, subscriptionManager_, eventController_, uiEventStream_, router_, settings_); + nickManager_ = new DummyNickManager(); + rosterController_ = new RosterController(jid_, xmppRoster_, avatarManager_, mainWindowFactory_, nickManager_, nickResolver_, presenceOracle_, subscriptionManager_, eventController_, uiEventStream_, router_, settings_); mainWindow_ = mainWindowFactory_->last; }; void tearDown() { delete rosterController_; + delete nickManager_; delete nickResolver_; delete mucRegistry_; delete mainWindowFactory_; @@ -304,6 +307,7 @@ class RosterControllerTest : public CppUnit::TestFixture MUCRegistry* mucRegistry_; AvatarManager* avatarManager_; MockMainWindowFactory* mainWindowFactory_; + NickManager* nickManager_; NickResolver* nickResolver_; RosterController* rosterController_; DummyIQChannel* channel_; diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp index 710ef61..fb84da4 100644 --- a/Swift/QtUI/QtMainWindow.cpp +++ b/Swift/QtUI/QtMainWindow.cpp @@ -40,6 +40,7 @@ QtMainWindow::QtMainWindow(UIEventStream* uiEventStream) : QWidget(), MainWindow meView_ = new QtRosterHeader(this); mainLayout->addWidget(meView_); connect(meView_, SIGNAL(onChangeStatusRequest(StatusShow::Type, const QString&)), this, SLOT(handleStatusChanged(StatusShow::Type, const QString&))); + connect(meView_, SIGNAL(onChangeNickRequest(const QString&)), this, SLOT(handleChangeNickRequest(const QString&))); tabs_ = new QtTabWidget(this); #if QT_VERSION >= 0x040500 @@ -162,8 +163,12 @@ void QtMainWindow::handleShowOfflineToggled(bool state) { } } -void QtMainWindow::setMyName(const String& name) { - meView_->setName(P2QSTRING(name)); +void QtMainWindow::setMyNick(const String& nick) { + meView_->setNick(P2QSTRING(nick)); +} + +void QtMainWindow::setMyJID(const JID& jid) { + meView_->setJID(P2QSTRING(jid.toBare().toString())); } void QtMainWindow::setMyAvatarPath(const String& path) { @@ -182,5 +187,9 @@ void QtMainWindow::setConnecting() { meView_->setConnecting(); } +void QtMainWindow::handleChangeNickRequest(const QString& nick) { + onChangeNickRequest(Q2PSTRING(nick)); +} + } diff --git a/Swift/QtUI/QtMainWindow.h b/Swift/QtUI/QtMainWindow.h index 9e200b1..ccec12c 100644 --- a/Swift/QtUI/QtMainWindow.h +++ b/Swift/QtUI/QtMainWindow.h @@ -38,7 +38,8 @@ namespace Swift { QtMainWindow(UIEventStream* eventStream); ~QtMainWindow(); std::vector<QMenu*> getMenus() {return menus_;} - void setMyName(const String& name); + void setMyNick(const String& name); + void setMyJID(const JID& jid); void setMyAvatarPath(const String& path); void setMyStatusText(const String& status); void setMyStatusType(StatusShow::Type type); @@ -55,6 +56,8 @@ namespace Swift { void handleAddContactDialogComplete(const JID& contact, const QString& name); void handleAddActionTriggered(bool checked); void handleEventCountUpdated(int count); + void handleChangeNickRequest(const QString& nick); + private: std::vector<QMenu*> menus_; QtTreeWidget* treeWidget_; diff --git a/Swift/QtUI/QtNameWidget.cpp b/Swift/QtUI/QtNameWidget.cpp new file mode 100644 index 0000000..bf38da8 --- /dev/null +++ b/Swift/QtUI/QtNameWidget.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "QtNameWidget.h" + +#include <QStackedWidget> +#include <QHBoxLayout> +#include <QMouseEvent> + +#include <Swift/QtUI/QtElidingLabel.h> +#include <Swift/QtUI/QtSwiftUtil.h> +#include <Swift/QtUI/QtLineEdit.h> + +namespace Swift { + +QtNameWidget::QtNameWidget(QWidget *parent) : QWidget(parent) { + QHBoxLayout* mainLayout = new QHBoxLayout(this); + mainLayout->setSpacing(0); + mainLayout->setContentsMargins(0,0,0,0); + + stack = new QStackedWidget(this); + mainLayout->addWidget(stack); + + textLabel = new QtElidingLabel(this); + QFont font = textLabel->font(); + font.setBold(true); + textLabel->setFont(font); + stack->addWidget(textLabel); + + nickEdit = new QtLineEdit(this); + connect(nickEdit, SIGNAL(returnPressed()), this, SLOT(handleEditComplete())); + connect(nickEdit, SIGNAL(escapePressed()), this, SLOT(handleEditCancelled())); + stack->addWidget(nickEdit); +} + +void QtNameWidget::mouseDoubleClickEvent(QMouseEvent* event) { + if (stack->currentWidget() != nickEdit) { + if (event->button() == Qt::LeftButton) { + nickEdit->setText(nick); + stack->setCurrentWidget(nickEdit); + } + } +} + +void QtNameWidget::handleEditComplete() { + stack->setCurrentWidget(textLabel); + emit onChangeNickRequest(nickEdit->text()); +} + +void QtNameWidget::handleEditCancelled() { + stack->setCurrentWidget(textLabel); +} + +void QtNameWidget::setNick(const QString& nick) { + this->nick = nick; + updateText(); +} + +void QtNameWidget::setJID(const QString& jid) { + this->jid = jid; + updateText(); +} + +void QtNameWidget::updateText() { + QString text; + if (nick.isEmpty()) { + text = jid; + } + else { + text = nick + " (" + jid + ")"; + } + text.replace("<","<"); + textLabel->setText(text); +} + +} + + + + diff --git a/Swift/QtUI/QtNameWidget.h b/Swift/QtUI/QtNameWidget.h new file mode 100644 index 0000000..c1c3e07 --- /dev/null +++ b/Swift/QtUI/QtNameWidget.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <QWidget> + +class QLabel; +class QStackedWidget; + +namespace Swift { + class QtElidingLabel; + class QtLineEdit; + + class QtNameWidget : public QWidget { + Q_OBJECT + + public: + QtNameWidget(QWidget *parent); + + void setNick(const QString& text); + void setJID(const QString& jid); + + signals: + /** + * When this is emitted, the widget is disabled until + * setNick() is called. + */ + void onChangeNickRequest(const QString& nick); + + private slots: + void handleEditComplete(); + void handleEditCancelled(); + virtual void mouseDoubleClickEvent(QMouseEvent* event); + + private: + void updateText(); + + private: + QStackedWidget* stack; + QtElidingLabel* textLabel; + QtLineEdit* nickEdit; + QString jid; + QString nick; + }; +} + diff --git a/Swift/QtUI/QtRosterHeader.cpp b/Swift/QtUI/QtRosterHeader.cpp index e6b5f1b..efc198a 100644 --- a/Swift/QtUI/QtRosterHeader.cpp +++ b/Swift/QtUI/QtRosterHeader.cpp @@ -14,8 +14,8 @@ #include <QMouseEvent> #include "QtStatusWidget.h" -#include "Swift/QtUI/QtElidingLabel.h" - +#include <Swift/QtUI/QtElidingLabel.h> +#include <Swift/QtUI/QtNameWidget.h> namespace Swift { QtRosterHeader::QtRosterHeader(QWidget* parent) : QWidget(parent) { @@ -39,12 +39,9 @@ QtRosterHeader::QtRosterHeader(QWidget* parent) : QWidget(parent) { rightLayout->setContentsMargins(4,0,0,0); topLayout->addLayout(rightLayout); - nameLabel_ = new QtElidingLabel(this); - setName("Me"); - QFont font = nameLabel_->font(); - font.setBold(true); - nameLabel_->setFont(font); - rightLayout->addWidget(nameLabel_); + nameWidget_ = new QtNameWidget(this); + connect(nameWidget_, SIGNAL(onChangeNickRequest(const QString&)), this, SIGNAL(onChangeNickRequest(const QString&))); + rightLayout->addWidget(nameWidget_); statusWidget_ = new QtStatusWidget(this); @@ -95,40 +92,6 @@ void QtRosterHeader::setConnecting() { statusWidget_->setConnecting(); } -void QtRosterHeader::setName(const QString& name) { - name_ = name; - QString escapedName = name_; - escapedName.replace("<","<"); -// nameLabel_->setText("<b>" + escapedName + "</b>"); - nameLabel_->setText(escapedName); -// resizeNameLabel(); -} - -// void QtRosterHeader::resizeNameLabel() { -// QString escapedName = name_; -// escapedName.replace("<","<"); -// nameLabel_->setText("<b>" + escapedName + "</b>"); -// return; -// //FIXME: Make this not an infinite loop, so it can be continued. - -// int reductionCount = 0; -// while (nameLabel_->sizeHint().width() + statusWidget_->width() + 30 > width()) { -// //qDebug() << nameLabel_->sizeHint().width() << " " << statusWidget_->width() << " " << width(); -// reductionCount++; -// QString reducedName = name_; -// reducedName.remove(name_.length() - reductionCount, reductionCount); -// reducedName.replace("<","<"); -// nameLabel_->setText("<b>" + reducedName + + "...</b>"); -// // qDebug() << "Shrunk " << escapedName << " down to " << reducedName; -// } -// nameLabel_->setToolTip(name_); -// } - -//void QtRosterHeader::resizeEvent(QResizeEvent* event) { -// QWidget::resizeEvent(event); -// resizeNameLabel(); -//} - void QtRosterHeader::setAvatar(const QString& path) { QIcon avatar(path); if (avatar.isNull()) { @@ -138,9 +101,15 @@ void QtRosterHeader::setAvatar(const QString& path) { avatarLabel_->setPixmap(avatar.pixmap(avatarSize_, avatarSize_)); } -//QSize QtRosterHeader::sizeHint() const { -// return minimumSizeHint(); -//} +void QtRosterHeader::setNick(const QString& nick) { + nameWidget_->setNick(nick); +} + +void QtRosterHeader::setJID(const QString& jid) { + nameWidget_->setJID(jid); +} + + const int QtRosterHeader::avatarSize_ = 40; diff --git a/Swift/QtUI/QtRosterHeader.h b/Swift/QtUI/QtRosterHeader.h index 6330200..cd5f26c 100644 --- a/Swift/QtUI/QtRosterHeader.h +++ b/Swift/QtUI/QtRosterHeader.h @@ -21,25 +21,30 @@ class QHBoxLayout; namespace Swift { class QtStatusWidget; - class QtElidingLabel; + class QtNameWidget; class QtRosterHeader : public QWidget { Q_OBJECT public: QtRosterHeader(QWidget* parent = NULL); void setAvatar(const QString& path); - void setName(const QString& name); + + void setJID(const QString& jid); + void setNick(const QString& nick); + void setStatusText(const QString& statusMessage); void setStatusType(StatusShow::Type type); void setConnecting(); signals: void onChangeStatusRequest(StatusShow::Type showType, const QString &statusMessage); + void onChangeNickRequest(const QString &nick); + private slots: void handleChangeStatusRequest(StatusShow::Type type, const QString &statusMessage); private: QString name_; QLabel* avatarLabel_; - QtElidingLabel* nameLabel_; + QtNameWidget* nameWidget_; QtTextEdit* statusEdit_; QToolBar* toolBar_; QtStatusWidget* statusWidget_; diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index 53c023a..864fdb5 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -69,6 +69,7 @@ sources = [ "QtLoginWindowFactory.cpp", "QtMainWindow.cpp", "QtMainWindowFactory.cpp", + "QtNameWidget.cpp", "QtSettingsProvider.cpp", "QtStatusWidget.cpp", "QtSwift.cpp", |