From 811aa9951613990956ad9027f4b969c8886b1123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Mon, 21 Feb 2011 21:46:55 +0100 Subject: Added "Remove" context menu. Resolves: #768 diff --git a/Swift/QtUI/QtContactEditWindow.cpp b/Swift/QtUI/QtContactEditWindow.cpp index 543d39a..5affaef 100644 --- a/Swift/QtUI/QtContactEditWindow.cpp +++ b/Swift/QtUI/QtContactEditWindow.cpp @@ -72,16 +72,19 @@ void QtContactEditWindow::hide() { } void QtContactEditWindow::handleRemoveContact() { + if (confirmContactDeletion(jid_)) { + onRemoveContactRequest(); + } +} + +bool QtContactEditWindow::confirmContactDeletion(const JID& jid) { QMessageBox msgBox; msgBox.setWindowTitle(tr("Confirm contact deletion")); msgBox.setText(tr("Are you sure you want to delete this contact?")); - msgBox.setInformativeText(QString(tr("This will remove the contact '%1' from all groups they may be in.")).arg(P2QSTRING(jid_.toString()))); + msgBox.setInformativeText(QString(tr("This will remove the contact '%1' from all groups they may be in.")).arg(P2QSTRING(jid.toString()))); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox.setDefaultButton(QMessageBox::Yes); - int ret = msgBox.exec(); - if (ret == QMessageBox::Yes) { - onRemoveContactRequest(); - } + return msgBox.exec() == QMessageBox::Yes; } void QtContactEditWindow::handleUpdateContact() { diff --git a/Swift/QtUI/QtContactEditWindow.h b/Swift/QtUI/QtContactEditWindow.h index 2d283de..b25e8b9 100644 --- a/Swift/QtUI/QtContactEditWindow.h +++ b/Swift/QtUI/QtContactEditWindow.h @@ -30,6 +30,8 @@ namespace Swift { void show(); void hide(); + static bool confirmContactDeletion(const JID& jid); + private slots: void handleRemoveContact(); void handleUpdateContact(); diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp index 55ceabc..99cbcf5 100644 --- a/Swift/QtUI/QtMainWindow.cpp +++ b/Swift/QtUI/QtMainWindow.cpp @@ -58,6 +58,7 @@ QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventS contactTabLayout->setContentsMargins(0, 0, 0, 0); treeWidget_ = new QtTreeWidget(uiEventStream_); + treeWidget_->setEditable(true); contactTabLayout->addWidget(treeWidget_); tabs_->addTab(contactsTabWidget_, tr("&Contacts")); diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp index e88e1bb..a76dc70 100644 --- a/Swift/QtUI/Roster/QtTreeWidget.cpp +++ b/Swift/QtUI/Roster/QtTreeWidget.cpp @@ -17,8 +17,10 @@ #include "Swift/Controllers/UIEvents/UIEventStream.h" #include "Swift/Controllers/UIEvents/RequestChatUIEvent.h" #include "Swift/Controllers/UIEvents/RequestContactEditorUIEvent.h" +#include "Swift/Controllers/UIEvents/RemoveRosterItemUIEvent.h" #include "Swift/Controllers/UIEvents/RenameGroupUIEvent.h" #include "QtSwiftUtil.h" +#include "QtContactEditWindow.h" namespace Swift { @@ -87,10 +89,16 @@ void QtTreeWidget::contextMenuEvent(QContextMenuEvent* event) { QMenu contextMenu; if (ContactRosterItem* contact = dynamic_cast(item)) { QAction* editContact = contextMenu.addAction(tr("Edit")); + QAction* removeContact = contextMenu.addAction(tr("Remove")); QAction* result = contextMenu.exec(event->globalPos()); if (result == editContact) { eventStream_->send(boost::make_shared(contact->getJID())); } + else if (result == removeContact) { + if (QtContactEditWindow::confirmContactDeletion(contact->getJID())) { + eventStream_->send(boost::make_shared(contact->getJID())); + } + } } else if (GroupRosterItem* group = dynamic_cast(item)) { QAction* renameGroup = contextMenu.addAction(tr("Rename")); -- cgit v0.10.2-6-g49f6