diff options
author | Kevin Smith <git@kismith.co.uk> | 2010-10-04 16:08:10 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2010-10-04 16:08:10 (GMT) |
commit | 8ca471e7304e813fa55ebf512a8f30f146fe6b41 (patch) | |
tree | e962968f1f7afc0bc6c73a776e3ee75e8c7deaba /Swift/QtUI/ContextMenus | |
parent | 026e8a67d871d99f4f0c0bddb6d16d12521f1e1c (diff) | |
download | swift-8ca471e7304e813fa55ebf512a8f30f146fe6b41.zip swift-8ca471e7304e813fa55ebf512a8f30f146fe6b41.tar.bz2 |
Assign contacts to groups.
Another patch will follow shortly to stop them appearing offline
after a roster change like this.
Resolves: #272
Release-Notes: It's now possible to assign your contacts to groups.
Diffstat (limited to 'Swift/QtUI/ContextMenus')
-rw-r--r-- | Swift/QtUI/ContextMenus/QtRosterContextMenu.cpp | 42 | ||||
-rw-r--r-- | Swift/QtUI/ContextMenus/QtRosterContextMenu.h | 5 |
2 files changed, 41 insertions, 6 deletions
diff --git a/Swift/QtUI/ContextMenus/QtRosterContextMenu.cpp b/Swift/QtUI/ContextMenus/QtRosterContextMenu.cpp index 59c3b78..1641266 100644 --- a/Swift/QtUI/ContextMenus/QtRosterContextMenu.cpp +++ b/Swift/QtUI/ContextMenus/QtRosterContextMenu.cpp @@ -10,20 +10,26 @@ #include <QLineEdit> #include <QMenu> #include <QDebug> +#include <QDialog> #include <boost/shared_ptr.hpp> #include "Swiften/Roster/ContactRosterItem.h" +#include "Swiften/Roster/GroupRosterItem.h" #include "Swiften/Base/String.h" +#include "Swiften/Roster/Roster.h" #include "Swift/Controllers/UIEvents/UIEvent.h" #include "Swift/Controllers/UIEvents/RemoveRosterItemUIEvent.h" #include "Swift/Controllers/UIEvents/RenameRosterItemUIEvent.h" #include "Swift/QtUI/QtSwiftUtil.h" +#include "Swift/QtUI/QtSetGroupsDialog.h" + namespace Swift { -QtRosterContextMenu::QtRosterContextMenu(UIEventStream* eventStream) { +QtRosterContextMenu::QtRosterContextMenu(UIEventStream* eventStream, QtTreeWidget* treeWidget) { eventStream_ = eventStream; + treeWidget_ = treeWidget; } void QtRosterContextMenu::show(RosterItem* item) { @@ -32,10 +38,36 @@ void QtRosterContextMenu::show(RosterItem* item) { return; } item_ = item; - QMenu* contextMenu = new QMenu(); - contextMenu->addAction("Remove", this, SLOT(handleRemoveContact())); - contextMenu->addAction("Rename", this, SLOT(handleRenameContact())); - contextMenu->exec(QCursor::pos()); + QMenu contextMenu; + contextMenu.addAction("Remove", this, SLOT(handleRemoveContact())); + contextMenu.addAction("Rename", this, SLOT(handleRenameContact())); + contextMenu.addAction("Groups", this, SLOT(handleRegroupContact())); + /*QMenu* groupsMenu = contextMenu.addMenu("Groups"); + std::map<QAction, String> groupActions; + for (int i = 0; i < 0; i++) { + String groupName; + groupActions[groupsMenu->addAction(P2QSTRING(groupName))] = groupName; + } + groupsMenu->addSeparator(); + groupsMenu->addAction("New Group", this SLOT(handleNewGroup()));*/ + contextMenu.exec(QCursor::pos()); +} + +void QtRosterContextMenu::handleRegroupContact() { + QList<QString> allGroups; + foreach (RosterItem* item, treeWidget_->getRoster()->getRoot()->getChildren()) { + GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item); + if (group) { + allGroups.push_back(P2QSTRING(group->getDisplayName())); + } + } + ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item_); + assert(contact); + QtSetGroupsDialog groupDialog(contact, allGroups); + + if (groupDialog.exec() == QDialog::Accepted) { + eventStream_->send(groupDialog.getRegroupEvent()); + } } void QtRosterContextMenu::handleRemoveContact() { diff --git a/Swift/QtUI/ContextMenus/QtRosterContextMenu.h b/Swift/QtUI/ContextMenus/QtRosterContextMenu.h index 44f3314..f2c7e1f 100644 --- a/Swift/QtUI/ContextMenus/QtRosterContextMenu.h +++ b/Swift/QtUI/ContextMenus/QtRosterContextMenu.h @@ -9,6 +9,7 @@ #include <QObject> #include "Swift/QtUI/ContextMenus/QtContextMenu.h" +#include "Swift/QtUI/Roster/QtTreeWidget.h" #include "Swift/Controllers/UIEvents/UIEventStream.h" namespace Swift { @@ -16,15 +17,17 @@ namespace Swift { class QtRosterContextMenu : public QObject, public QtContextMenu { Q_OBJECT public: - QtRosterContextMenu(UIEventStream* eventStream); + QtRosterContextMenu(UIEventStream* eventStream, QtTreeWidget* treeWidget); void show(RosterItem* item); private slots: void handleRemoveContact(); void handleRenameContact(); + void handleRegroupContact(); private: RosterItem* item_; UIEventStream* eventStream_; + QtTreeWidget* treeWidget_; }; } |