diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-12-12 16:49:18 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-12-12 16:49:18 (GMT) |
commit | e90e08301a03a4ad562a35e60927815d43daebec (patch) | |
tree | 3bfeec305b49c7366586d75cb17c77beac01db14 | |
parent | 4315ccbd51f63e408d69d944f162d0ead4f9addd (diff) | |
download | swift-contrib-e90e08301a03a4ad562a35e60927815d43daebec.zip swift-contrib-e90e08301a03a4ad562a35e60927815d43daebec.tar.bz2 |
Removing nickname change functionality from roster header.
-rw-r--r-- | Swift/Controllers/RosterController.cpp | 2 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/MainWindow.h | 1 | ||||
-rw-r--r-- | Swift/QtUI/QtMainWindow.cpp | 5 | ||||
-rw-r--r-- | Swift/QtUI/QtMainWindow.h | 1 | ||||
-rw-r--r-- | Swift/QtUI/QtNameWidget.cpp | 68 | ||||
-rw-r--r-- | Swift/QtUI/QtNameWidget.h | 25 | ||||
-rw-r--r-- | Swift/QtUI/QtRosterHeader.cpp | 1 | ||||
-rw-r--r-- | Swift/QtUI/QtRosterHeader.h | 1 | ||||
-rw-r--r-- | Swiften/Client/NickManagerImpl.cpp | 9 | ||||
-rw-r--r-- | Swiften/Client/NickManagerImpl.h | 1 |
10 files changed, 49 insertions, 65 deletions
diff --git a/Swift/Controllers/RosterController.cpp b/Swift/Controllers/RosterController.cpp index 1feeb58..282f041 100644 --- a/Swift/Controllers/RosterController.cpp +++ b/Swift/Controllers/RosterController.cpp @@ -69,8 +69,6 @@ RosterController::RosterController(const JID& jid, XMPPRoster* xmppRoster, Avata 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))); } diff --git a/Swift/Controllers/UIInterfaces/MainWindow.h b/Swift/Controllers/UIInterfaces/MainWindow.h index 124d229..125aae5 100644 --- a/Swift/Controllers/UIInterfaces/MainWindow.h +++ b/Swift/Controllers/UIInterfaces/MainWindow.h @@ -36,7 +36,6 @@ 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/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp index fb84da4..5cbc40c 100644 --- a/Swift/QtUI/QtMainWindow.cpp +++ b/Swift/QtUI/QtMainWindow.cpp @@ -40,7 +40,6 @@ 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 @@ -187,9 +186,5 @@ 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 ccec12c..62aafba 100644 --- a/Swift/QtUI/QtMainWindow.h +++ b/Swift/QtUI/QtMainWindow.h @@ -56,7 +56,6 @@ 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_; diff --git a/Swift/QtUI/QtNameWidget.cpp b/Swift/QtUI/QtNameWidget.cpp index bf38da8..d123bad 100644 --- a/Swift/QtUI/QtNameWidget.cpp +++ b/Swift/QtUI/QtNameWidget.cpp @@ -6,52 +6,25 @@ #include "QtNameWidget.h" -#include <QStackedWidget> #include <QHBoxLayout> +#include <QMenu> #include <QMouseEvent> +#include <QtDebug> #include <Swift/QtUI/QtElidingLabel.h> -#include <Swift/QtUI/QtSwiftUtil.h> -#include <Swift/QtUI/QtLineEdit.h> namespace Swift { -QtNameWidget::QtNameWidget(QWidget *parent) : QWidget(parent) { +QtNameWidget::QtNameWidget(QWidget *parent) : QWidget(parent), mode(ShowNick) { 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); + mainLayout->addWidget(textLabel); } void QtNameWidget::setNick(const QString& nick) { @@ -64,13 +37,40 @@ void QtNameWidget::setJID(const QString& jid) { updateText(); } +void QtNameWidget::mousePressEvent(QMouseEvent* event) { + QMenu menu; + + QAction* showAsNick = new QAction("Show nickname", this); + showAsNick->setCheckable(true); + if (mode == ShowNick) { + showAsNick->setChecked(true); + } + menu.addAction(showAsNick); + + QAction* showAsJID = new QAction("Show ID", this); + showAsJID->setCheckable(true); + if (mode == ShowJID) { + showAsJID->setChecked(true); + } + menu.addAction(showAsJID); + + QAction* result = menu.exec(event->globalPos()); + if (result == showAsJID) { + mode = ShowJID; + } + else { + mode = ShowNick; + } + updateText(); +} + void QtNameWidget::updateText() { QString text; - if (nick.isEmpty()) { - text = jid; + if (mode == ShowNick && !nick.isEmpty()) { + text = nick; } else { - text = nick + " (" + jid + ")"; + text = jid; } text.replace("<","<"); textLabel->setText(text); diff --git a/Swift/QtUI/QtNameWidget.h b/Swift/QtUI/QtNameWidget.h index c1c3e07..52586b7 100644 --- a/Swift/QtUI/QtNameWidget.h +++ b/Swift/QtUI/QtNameWidget.h @@ -8,12 +8,8 @@ #include <QWidget> -class QLabel; -class QStackedWidget; - namespace Swift { class QtElidingLabel; - class QtLineEdit; class QtNameWidget : public QWidget { Q_OBJECT @@ -24,25 +20,18 @@ namespace Swift { 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(); + virtual void mousePressEvent(QMouseEvent* event); private: - QStackedWidget* stack; + enum Mode { + ShowNick, + ShowJID, + }; + + Mode mode; QtElidingLabel* textLabel; - QtLineEdit* nickEdit; QString jid; QString nick; }; diff --git a/Swift/QtUI/QtRosterHeader.cpp b/Swift/QtUI/QtRosterHeader.cpp index efc198a..4649839 100644 --- a/Swift/QtUI/QtRosterHeader.cpp +++ b/Swift/QtUI/QtRosterHeader.cpp @@ -40,7 +40,6 @@ QtRosterHeader::QtRosterHeader(QWidget* parent) : QWidget(parent) { topLayout->addLayout(rightLayout); nameWidget_ = new QtNameWidget(this); - connect(nameWidget_, SIGNAL(onChangeNickRequest(const QString&)), this, SIGNAL(onChangeNickRequest(const QString&))); rightLayout->addWidget(nameWidget_); diff --git a/Swift/QtUI/QtRosterHeader.h b/Swift/QtUI/QtRosterHeader.h index cd5f26c..23e6be0 100644 --- a/Swift/QtUI/QtRosterHeader.h +++ b/Swift/QtUI/QtRosterHeader.h @@ -37,7 +37,6 @@ namespace Swift { 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); diff --git a/Swiften/Client/NickManagerImpl.cpp b/Swiften/Client/NickManagerImpl.cpp index 09f8de5..fd37222 100644 --- a/Swiften/Client/NickManagerImpl.cpp +++ b/Swiften/Client/NickManagerImpl.cpp @@ -14,6 +14,8 @@ namespace Swift { NickManagerImpl::NickManagerImpl(const JID& ownJID, VCardManager* vcardManager) : ownJID(ownJID), vcardManager(vcardManager) { vcardManager->onVCardChanged.connect(boost::bind(&NickManagerImpl::handleVCardReceived, this, _1, _2)); + + updateOwnNickFromVCard(vcardManager->getVCard(ownJID.toBare())); } NickManagerImpl::~NickManagerImpl() { @@ -21,7 +23,7 @@ NickManagerImpl::~NickManagerImpl() { } String NickManagerImpl::getOwnNick() const { - return ownJID; + return ownNick; } void NickManagerImpl::setOwnNick(const String&) { @@ -31,9 +33,12 @@ void NickManagerImpl::handleVCardReceived(const JID& jid, VCard::ref vcard) { if (!jid.equals(ownJID, JID::WithoutResource)) { return; } + updateOwnNickFromVCard(vcard); +} +void NickManagerImpl::updateOwnNickFromVCard(VCard::ref vcard) { String nick; - if (!vcard->getNickname().isEmpty()) { + if (vcard && !vcard->getNickname().isEmpty()) { nick = vcard->getNickname(); } if (ownNick != nick) { diff --git a/Swiften/Client/NickManagerImpl.h b/Swiften/Client/NickManagerImpl.h index 87c9711..8796dbe 100644 --- a/Swiften/Client/NickManagerImpl.h +++ b/Swiften/Client/NickManagerImpl.h @@ -24,6 +24,7 @@ namespace Swift { private: void handleVCardReceived(const JID& jid, VCard::ref vCard); + void updateOwnNickFromVCard(VCard::ref vcard); private: JID ownJID; |