From d7fb4678b37a80f615755609648aad8dcef6ac00 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Fri, 8 Oct 2010 12:07:28 +0100 Subject: Rename groups. Resolves: #577 Release-Notes: Roster groups can now be renamed. diff --git a/Swift/QtUI/ContextMenus/QtRosterContextMenu.cpp b/Swift/QtUI/ContextMenus/QtRosterContextMenu.cpp index 1641266..d4473d8 100644 --- a/Swift/QtUI/ContextMenus/QtRosterContextMenu.cpp +++ b/Swift/QtUI/ContextMenus/QtRosterContextMenu.cpp @@ -34,22 +34,17 @@ QtRosterContextMenu::QtRosterContextMenu(UIEventStream* eventStream, QtTreeWidge void QtRosterContextMenu::show(RosterItem* item) { ContactRosterItem* contact = dynamic_cast(item); - if (!contact) { - return; - } item_ = item; 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 groupActions; - for (int i = 0; i < 0; i++) { - String groupName; - groupActions[groupsMenu->addAction(P2QSTRING(groupName))] = groupName; + if (contact) { + contextMenu.addAction("Remove", this, SLOT(handleRemoveContact())); + contextMenu.addAction("Rename", this, SLOT(handleRenameContact())); + contextMenu.addAction("Groups", this, SLOT(handleRegroupContact())); + } + GroupRosterItem* group = dynamic_cast(item); + if (group) { + contextMenu.addAction("Rename", this, SLOT(handleRenameGroup())); } - groupsMenu->addSeparator(); - groupsMenu->addAction("New Group", this SLOT(handleNewGroup()));*/ contextMenu.exec(QCursor::pos()); } @@ -86,4 +81,23 @@ void QtRosterContextMenu::handleRenameContact() { } } +void QtRosterContextMenu::handleRenameGroup() { + GroupRosterItem* group = dynamic_cast(item_); + assert(group); + bool ok; + QString newName = QInputDialog::getText(NULL, "Rename group", "New name for " + P2QSTRING(item_->getDisplayName()), QLineEdit::Normal, P2QSTRING(item_->getDisplayName()), &ok); + if (ok) { + std::vector addedGroups; + std::vector removedGroups; + addedGroups.push_back(Q2PSTRING(newName)); + removedGroups.push_back(group->getDisplayName()); + foreach (RosterItem* child, group->getChildren()) { + ContactRosterItem* contact = dynamic_cast(child); + assert(contact); + boost::shared_ptr regroupItem(new RegroupRosterItemUIEvent(contact->getJID(), addedGroups, removedGroups)); + eventStream_->send(regroupItem); + } + } +} + } diff --git a/Swift/QtUI/ContextMenus/QtRosterContextMenu.h b/Swift/QtUI/ContextMenus/QtRosterContextMenu.h index f2c7e1f..53f4bdd 100644 --- a/Swift/QtUI/ContextMenus/QtRosterContextMenu.h +++ b/Swift/QtUI/ContextMenus/QtRosterContextMenu.h @@ -23,6 +23,7 @@ namespace Swift { private slots: void handleRemoveContact(); void handleRenameContact(); + void handleRenameGroup(); void handleRegroupContact(); private: -- cgit v0.10.2-6-g49f6