summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/ChatList/QtChatListWindow.h3
-rw-r--r--Swift/QtUI/ContextMenus/QtContextMenu.cpp14
-rw-r--r--Swift/QtUI/ContextMenus/QtContextMenu.h17
-rw-r--r--Swift/QtUI/ContextMenus/QtRosterContextMenu.cpp112
-rw-r--r--Swift/QtUI/ContextMenus/QtRosterContextMenu.h34
-rw-r--r--Swift/QtUI/QtContactEditWindow.cpp136
-rw-r--r--Swift/QtUI/QtContactEditWindow.h52
-rw-r--r--Swift/QtUI/QtMainWindow.cpp3
-rw-r--r--Swift/QtUI/QtMainWindow.h8
-rw-r--r--Swift/QtUI/QtSetGroupsDialog.cpp106
-rw-r--r--Swift/QtUI/QtSetGroupsDialog.h37
-rw-r--r--Swift/QtUI/QtUIFactory.cpp6
-rw-r--r--Swift/QtUI/QtUIFactory.h1
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.cpp43
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.h3
-rw-r--r--Swift/QtUI/SConscript4
16 files changed, 227 insertions, 352 deletions
diff --git a/Swift/QtUI/ChatList/QtChatListWindow.h b/Swift/QtUI/ChatList/QtChatListWindow.h
index b389474..3a3e95f 100644
--- a/Swift/QtUI/ChatList/QtChatListWindow.h
+++ b/Swift/QtUI/ChatList/QtChatListWindow.h
@@ -12,7 +12,6 @@
#include "Swift/Controllers/UIEvents/UIEventStream.h"
#include "Swift/QtUI/ChatList/ChatListModel.h"
#include "Swift/QtUI/ChatList/ChatListDelegate.h"
-#include "Swift/QtUI/ContextMenus/QtContextMenu.h"
namespace Swift {
@@ -34,13 +33,13 @@ namespace Swift {
protected:
void contextMenuEvent(QContextMenuEvent* event);
+
private:
void setupContextMenus();
bool bookmarksEnabled_;
UIEventStream* eventStream_;
ChatListModel* model_;
ChatListDelegate* delegate_;
- QtContextMenu* contextMenu_;
QMenu* mucMenu_;
QMenu* emptyMenu_;
ChatListItem* contextMenuItem_;
diff --git a/Swift/QtUI/ContextMenus/QtContextMenu.cpp b/Swift/QtUI/ContextMenus/QtContextMenu.cpp
deleted file mode 100644
index c74fb31..0000000
--- a/Swift/QtUI/ContextMenus/QtContextMenu.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright (c) 2010 Kevin Smith
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#include "ContextMenus/QtContextMenu.h"
-
-namespace Swift {
-
-QtContextMenu::~QtContextMenu() {
-}
-
-}
diff --git a/Swift/QtUI/ContextMenus/QtContextMenu.h b/Swift/QtUI/ContextMenus/QtContextMenu.h
deleted file mode 100644
index 9e73ef9..0000000
--- a/Swift/QtUI/ContextMenus/QtContextMenu.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * Copyright (c) 2010 Kevin Smith
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#pragma once
-
-namespace Swift {
- class RosterItem;
- class QtContextMenu {
- public:
- virtual ~QtContextMenu();
-
- virtual void show(RosterItem* item) = 0;
- };
-}
diff --git a/Swift/QtUI/ContextMenus/QtRosterContextMenu.cpp b/Swift/QtUI/ContextMenus/QtRosterContextMenu.cpp
deleted file mode 100644
index 9bbbbca..0000000
--- a/Swift/QtUI/ContextMenus/QtRosterContextMenu.cpp
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright (c) 2010 Kevin Smith
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#include "Swift/QtUI/ContextMenus/QtRosterContextMenu.h"
-
-#include <QInputDialog>
-#include <QLineEdit>
-#include <QMenu>
-#include <QDebug>
-#include <QDialog>
-#include <QMessageBox>
-
-#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, QtTreeWidget* treeWidget) : eventStream_(eventStream), treeWidget_(treeWidget), item_(NULL) {
-}
-
-void QtRosterContextMenu::show(RosterItem* item) {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- item_ = item;
- QMenu contextMenu;
- if (contact) {
- contextMenu.addAction("Rename", this, SLOT(handleRenameContact()));
- contextMenu.addAction("Groups", this, SLOT(handleRegroupContact()));
- contextMenu.addSeparator();
- contextMenu.addAction("Remove", this, SLOT(handleRemoveContact()));
- }
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
- if (group) {
- contextMenu.addAction("Rename", this, SLOT(handleRenameGroup()));
- }
- 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() {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item_);
- assert(contact);
- QMessageBox msgBox;
- msgBox.setWindowTitle("Confirm contact deletion");
- msgBox.setText("Are you sure you want to delete this contact?");
- msgBox.setInformativeText(QString("This will remove the contact '%1' from all groups they may be in.").arg(P2QSTRING(contact->getJID().toString())));
- msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
- msgBox.setDefaultButton(QMessageBox::Yes);
- int ret = msgBox.exec();
- if (ret == QMessageBox::Yes) {
- eventStream_->send(boost::shared_ptr<UIEvent>(new RemoveRosterItemUIEvent(contact->getJID())));
- }
-}
-
-void QtRosterContextMenu::handleRenameContact() {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item_);
- assert(contact);
- bool ok;
- QString newName = QInputDialog::getText(NULL, "Rename contact", "New name for " + P2QSTRING(item_->getDisplayName()), QLineEdit::Normal, P2QSTRING(item_->getDisplayName()), &ok);
- if (ok) {
- eventStream_->send(boost::shared_ptr<UIEvent>(new RenameRosterItemUIEvent(contact->getJID(), Q2PSTRING(newName))));
- }
-}
-
-void QtRosterContextMenu::handleRenameGroup() {
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(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<String> addedGroups;
- std::vector<String> removedGroups;
- addedGroups.push_back(Q2PSTRING(newName));
- removedGroups.push_back(group->getDisplayName());
- foreach (RosterItem* child, group->getChildren()) {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(child);
- assert(contact);
- boost::shared_ptr<RegroupRosterItemUIEvent> regroupItem(new RegroupRosterItemUIEvent(contact->getJID(), addedGroups, removedGroups));
- eventStream_->send(regroupItem);
- }
- }
-}
-
-}
diff --git a/Swift/QtUI/ContextMenus/QtRosterContextMenu.h b/Swift/QtUI/ContextMenus/QtRosterContextMenu.h
deleted file mode 100644
index 0a88a8e..0000000
--- a/Swift/QtUI/ContextMenus/QtRosterContextMenu.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2010 Kevin Smith
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#pragma once
-
-#include <QObject>
-
-#include "Swift/QtUI/ContextMenus/QtContextMenu.h"
-#include "Swift/QtUI/Roster/QtTreeWidget.h"
-#include "Swift/Controllers/UIEvents/UIEventStream.h"
-
-namespace Swift {
- class RosterItem;
- class QtRosterContextMenu : public QObject, public QtContextMenu {
- Q_OBJECT
- public:
- QtRosterContextMenu(UIEventStream* eventStream, QtTreeWidget* treeWidget);
- void show(RosterItem* item);
-
- private slots:
- void handleRemoveContact();
- void handleRenameContact();
- void handleRenameGroup();
- void handleRegroupContact();
-
- private:
- UIEventStream* eventStream_;
- QtTreeWidget* treeWidget_;
- RosterItem* item_;
- };
-}
diff --git a/Swift/QtUI/QtContactEditWindow.cpp b/Swift/QtUI/QtContactEditWindow.cpp
new file mode 100644
index 0000000..6eb4316
--- /dev/null
+++ b/Swift/QtUI/QtContactEditWindow.cpp
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2010 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include "QtContactEditWindow.h"
+
+#include <algorithm>
+
+#include <QScrollArea>
+#include <QBoxLayout>
+#include <QLabel>
+#include <QCheckBox>
+#include <QLineEdit>
+#include <QDialogButtonBox>
+#include <QMessageBox>
+#include <QPushButton>
+
+#include "Swift/QtUI/QtSwiftUtil.h"
+
+namespace Swift {
+
+QtContactEditWindow::QtContactEditWindow() : groups_(NULL) {
+ resize(300,300);
+ setWindowTitle("Edit contact");
+
+ QBoxLayout* layout = new QVBoxLayout(this);
+ setContentsMargins(0,0,0,0);
+
+ jidLabel_ = new QLabel(this);
+ jidLabel_->setAlignment(Qt::AlignHCenter);
+ layout->addWidget(jidLabel_);
+
+ QHBoxLayout* nameLayout = new QHBoxLayout();
+
+ QLabel* label = new QLabel("Name:", this);
+ nameLayout->addWidget(label);
+ name_ = new QLineEdit(this);
+ nameLayout->addWidget(name_);
+ layout->addLayout(nameLayout);
+
+ layout->addWidget(new QLabel("Groups:", this));
+
+ groupsArea_ = new QScrollArea(this);
+ layout->addWidget(groupsArea_);
+ groupsArea_->setWidgetResizable(true);
+ groupsArea_->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+ groupsArea_->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+
+ QHBoxLayout* buttonLayout = new QHBoxLayout();
+ layout->addLayout(buttonLayout);
+ QPushButton* removeButton = new QPushButton("Remove contact", this);
+ connect(removeButton, SIGNAL(clicked()), this, SLOT(handleRemoveContact()));
+ buttonLayout->addWidget(removeButton);
+ QPushButton* okButton = new QPushButton("Ok", this);
+ connect(okButton, SIGNAL(clicked()), this, SLOT(handleUpdateContact()));
+ buttonLayout->addStretch();
+ buttonLayout->addWidget(okButton);
+}
+
+void QtContactEditWindow::setContact(const JID& jid, const String& name, const std::vector<String>& groups, const std::set<String>& allGroups) {
+ jid_ = jid;
+
+ jidLabel_->setText("<b>" + P2QSTRING(jid.toString()) + "</b>");
+ name_->setText(P2QSTRING(name));
+
+ delete groups_;
+ checkBoxes_.clear();
+ groups_ = new QWidget(groupsArea_);
+ groupsArea_->setWidget(groups_);
+ QVBoxLayout* scrollLayout = new QVBoxLayout(groups_);
+
+ foreach (String group, allGroups) {
+ QCheckBox* check = new QCheckBox(groups_);
+ check->setText(P2QSTRING(group));
+ check->setCheckState(Qt::Unchecked);
+ checkBoxes_[group] = check;
+ scrollLayout->addWidget(check);
+ }
+ foreach (String group, groups) {
+ checkBoxes_[group]->setCheckState(Qt::Checked);
+ }
+
+ QHBoxLayout* newGroupLayout = new QHBoxLayout();
+ newGroup_ = new QCheckBox(groups_);
+ newGroup_->setText("New Group:");
+ newGroup_->setCheckState(Qt::Unchecked);
+ newGroupLayout->addWidget(newGroup_);
+ newGroupName_ = new QLineEdit(groups_);
+ newGroupLayout->addWidget(newGroupName_);
+ scrollLayout->addLayout(newGroupLayout);
+
+ scrollLayout->addItem(new QSpacerItem(20, 73, QSizePolicy::Minimum, QSizePolicy::Expanding));
+}
+
+void QtContactEditWindow::setEnabled(bool b) {
+ QWidget::setEnabled(b);
+}
+
+void QtContactEditWindow::show() {
+ QWidget::show();
+ QWidget::activateWindow();
+}
+
+void QtContactEditWindow::hide() {
+ QWidget::hide();
+}
+
+void QtContactEditWindow::handleRemoveContact() {
+ QMessageBox msgBox;
+ msgBox.setWindowTitle("Confirm contact deletion");
+ msgBox.setText("Are you sure you want to delete this contact?");
+ msgBox.setInformativeText(QString("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();
+ }
+}
+
+void QtContactEditWindow::handleUpdateContact() {
+ std::vector<String> groups;
+ foreach(const CheckBoxMap::value_type& group, checkBoxes_) {
+ if (group.second->checkState() == Qt::Checked) {
+ groups.push_back(group.first);
+ }
+ }
+ if (newGroup_->checkState() == Qt::Checked && !newGroupName_->text().isEmpty()) {
+ groups.push_back(Q2PSTRING(newGroupName_->text()));
+ }
+ onChangeContactRequest(Q2PSTRING(name_->text()), groups);
+}
+
+}
diff --git a/Swift/QtUI/QtContactEditWindow.h b/Swift/QtUI/QtContactEditWindow.h
new file mode 100644
index 0000000..a731480
--- /dev/null
+++ b/Swift/QtUI/QtContactEditWindow.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2010 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <map>
+#include <boost/shared_ptr.hpp>
+
+#include <QWidget>
+
+#include <Swift/Controllers/UIInterfaces/ContactEditWindow.h>
+#include <Swiften/Base/String.h>
+#include <Swiften/JID/JID.h>
+
+class QScrollArea;
+class QLabel;
+class QLineEdit;
+class QCheckBox;
+
+namespace Swift {
+ class QtContactEditWindow : public QWidget, public ContactEditWindow {
+ Q_OBJECT
+
+ public:
+ QtContactEditWindow();
+
+ virtual void setContact(const JID& jid, const String& name, const std::vector<String>& groups, const std::set<String>& allGroups);
+
+ void setEnabled(bool);
+ void show();
+ void hide();
+
+ private slots:
+ void handleRemoveContact();
+ void handleUpdateContact();
+
+ private:
+ typedef std::map<String, QCheckBox*> CheckBoxMap;
+ JID jid_;
+ QLabel* jidLabel_;
+ CheckBoxMap checkBoxes_;
+ QLineEdit* name_;
+ QScrollArea* groupsArea_;
+ QWidget* groups_;
+ QCheckBox* newGroup_;
+ QLineEdit* newGroupName_;
+ };
+}
+
diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp
index ccf5a59..63ce32b 100644
--- a/Swift/QtUI/QtMainWindow.cpp
+++ b/Swift/QtUI/QtMainWindow.cpp
@@ -59,8 +59,6 @@ QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventS
contactTabLayout->setContentsMargins(0, 0, 0, 0);
treeWidget_ = new QtTreeWidget(uiEventStream_);
- contextMenu_ = new QtRosterContextMenu(uiEventStream_, treeWidget_);
- treeWidget_->setContextMenu(contextMenu_);
contactTabLayout->addWidget(treeWidget_);
tabs_->addTab(contactsTabWidget_, "&Contacts");
@@ -108,7 +106,6 @@ QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventS
QtMainWindow::~QtMainWindow() {
uiEventStream_->onUIEvent.disconnect(boost::bind(&QtMainWindow::handleUIEvent, this, _1));
- delete contextMenu_;
}
QtEventWindow* QtMainWindow::getEventWindow() {
diff --git a/Swift/QtUI/QtMainWindow.h b/Swift/QtUI/QtMainWindow.h
index 67b89d8..66b0caf 100644
--- a/Swift/QtUI/QtMainWindow.h
+++ b/Swift/QtUI/QtMainWindow.h
@@ -4,8 +4,7 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#ifndef SWIFT_QtMainWindow_H
-#define SWIFT_QtMainWindow_H
+#pragma once
#include <QWidget>
#include <QMenu>
@@ -13,7 +12,6 @@
#include "Swift/QtUI/QtRosterHeader.h"
#include "Swift/QtUI/EventViewer/QtEventWindow.h"
#include "Swift/QtUI/ChatList/QtChatListWindow.h"
-#include "Swift/QtUI/ContextMenus/QtRosterContextMenu.h"
#include <vector>
@@ -73,10 +71,6 @@ namespace Swift {
QtEventWindow* eventWindow_;
QtChatListWindow* chatListWindow_;
UIEventStream* uiEventStream_;
- QtRosterContextMenu* contextMenu_;
bool lastOfflineState_;
};
}
-
-#endif
-
diff --git a/Swift/QtUI/QtSetGroupsDialog.cpp b/Swift/QtUI/QtSetGroupsDialog.cpp
deleted file mode 100644
index d19a55d..0000000
--- a/Swift/QtUI/QtSetGroupsDialog.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (c) 2010 Kevin Smith
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#include "QtSetGroupsDialog.h"
-
-#include <algorithm>
-
-#include <QScrollArea>
-#include <QBoxLayout>
-#include <QLabel>
-#include <QDialogButtonBox>
-
-#include "Swift/QtUI/QtSwiftUtil.h"
-
-namespace Swift {
-
-QtSetGroupsDialog::QtSetGroupsDialog(ContactRosterItem* contact, const QList<QString>& allGroups) : contact_(contact) {
- //resize(300,300);
- setWindowTitle("Edit contact");
- QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
- setContentsMargins(0,0,0,0);
- QScrollArea* scrollArea = new QScrollArea(this);
- layout->addWidget(scrollArea);
- scrollArea->setWidgetResizable(true);
- scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
- scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
- QWidget* scroll = new QWidget(scrollArea);
- scrollArea->setWidget(scroll);
- QVBoxLayout* scrollLayout = new QVBoxLayout(scroll);
- QLabel* label = new QLabel(scroll);
- label->setText("Choose groups for " + P2QSTRING(contact->getDisplayName()) + " (" + P2QSTRING(contact->getJID().toString()) + ")");
- scrollLayout->addWidget(label);
- foreach (QString group, allGroups) {
- QCheckBox* check = new QCheckBox(scroll);
- check->setText(group);
- check->setCheckState(Qt::Unchecked);
- checkBoxes_[Q2PSTRING(group)] = check;
- scrollLayout->addWidget(check);
- }
- foreach (String group, contact->getGroups()) {
- checkBoxes_[group]->setCheckState(Qt::Checked);
- }
-
- QHBoxLayout* newGroupLayout = new QHBoxLayout();
- newGroup_ = new QCheckBox(scroll);
- newGroup_->setText("New Group:");
- newGroup_->setCheckState(Qt::Unchecked);
- newGroupLayout->addWidget(newGroup_);
- newGroupName_ = new QLineEdit(scroll);
- newGroupLayout->addWidget(newGroupName_);
- scrollLayout->addLayout(newGroupLayout);
-
- scrollLayout->addItem(new QSpacerItem(20, 73, QSizePolicy::Minimum, QSizePolicy::Expanding));
-
- QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
- layout->addWidget(buttons);
- connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
- connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
-}
-
-QtSetGroupsDialog::~QtSetGroupsDialog() {
- // TODO Auto-generated destructor stub
-}
-
-typedef std::pair<String, QCheckBox*> CheckStringPair;
-
-boost::shared_ptr<RegroupRosterItemUIEvent> QtSetGroupsDialog::getRegroupEvent() {
- std::vector<String> addedGroups;
- std::vector<String> removedGroups;
- std::vector<String> existingGroups = contact_->getGroups();
- int tickedCount = 0;
- bool wantsContacts = false;
- foreach (CheckStringPair pair, checkBoxes_) {
- bool existing = std::find(existingGroups.begin(), existingGroups.end(), pair.first) != existingGroups.end();
- if (pair.second->checkState() == Qt::Checked) {
- tickedCount++;
- if (pair.first == "Contacts") {
- wantsContacts = true;
- }
- if (!existing && pair.first != "Contacts") {
- addedGroups.push_back(pair.first);
- }
- } else {
- if (existing) {
- removedGroups.push_back(pair.first);
- }
- }
- }
- if (newGroup_->checkState() == Qt::Checked) {
- tickedCount++;
- String name = Q2PSTRING(newGroupName_->text());
- if (std::find(existingGroups.begin(), existingGroups.end(), name) == existingGroups.end()) {
- addedGroups.push_back(name);
- }
- }
- if (tickedCount > 1 && wantsContacts) {
- addedGroups.push_back("Contacts");
- }
- boost::shared_ptr<RegroupRosterItemUIEvent> result(new RegroupRosterItemUIEvent(contact_->getJID(), addedGroups, removedGroups));
- return result;
-}
-
-}
diff --git a/Swift/QtUI/QtSetGroupsDialog.h b/Swift/QtUI/QtSetGroupsDialog.h
deleted file mode 100644
index e8300f5..0000000
--- a/Swift/QtUI/QtSetGroupsDialog.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2010 Kevin Smith
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#pragma once
-
-#include <map>
-
-#include <boost/shared_ptr.hpp>
-
-#include <QDialog>
-#include <QCheckBox>
-#include <QLineEdit>
-#include <QList>
-
-#include "Swiften/Roster/ContactRosterItem.h"
-#include "Swift/Controllers/UIEvents/RegroupRosterItemUIEvent.h"
-
-namespace Swift {
-
-class QtSetGroupsDialog : public QDialog {
- Q_OBJECT
- public:
- QtSetGroupsDialog(ContactRosterItem* contact, const QList<QString>& allGroups);
- virtual ~QtSetGroupsDialog();
- boost::shared_ptr<RegroupRosterItemUIEvent> getRegroupEvent();
- private:
- ContactRosterItem* contact_;
- std::map<String, QCheckBox*> checkBoxes_;
- QCheckBox* newGroup_;
- QLineEdit* newGroupName_;
-};
-
-}
-
diff --git a/Swift/QtUI/QtUIFactory.cpp b/Swift/QtUI/QtUIFactory.cpp
index 35dc4ea..4832205 100644
--- a/Swift/QtUI/QtUIFactory.cpp
+++ b/Swift/QtUI/QtUIFactory.cpp
@@ -22,6 +22,7 @@
#include "MUCSearch/QtMUCSearchWindow.h"
#include "UserSearch/QtUserSearchWindow.h"
#include "QtProfileWindow.h"
+#include "QtContactEditWindow.h"
namespace Swift {
@@ -94,4 +95,9 @@ ProfileWindow* QtUIFactory::createProfileWindow() {
return new QtProfileWindow();
}
+ContactEditWindow* QtUIFactory::createContactEditWindow() {
+ return new QtContactEditWindow();
+}
+
+
}
diff --git a/Swift/QtUI/QtUIFactory.h b/Swift/QtUI/QtUIFactory.h
index 199cebf..aa88fa3 100644
--- a/Swift/QtUI/QtUIFactory.h
+++ b/Swift/QtUI/QtUIFactory.h
@@ -36,6 +36,7 @@ namespace Swift {
virtual UserSearchWindow* createUserSearchWindow(UserSearchWindow::Type type, UIEventStream* eventStream);
virtual JoinMUCWindow* createJoinMUCWindow();
virtual ProfileWindow* createProfileWindow();
+ virtual ContactEditWindow* createContactEditWindow();
private slots:
void handleLoginWindowGeometryChanged();
diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp
index cecb557..3c0b303 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.cpp
+++ b/Swift/QtUI/Roster/QtTreeWidget.cpp
@@ -6,15 +6,19 @@
#include "Roster/QtTreeWidget.h"
+#include <QMenu>
+#include <QContextMenuEvent>
+#include <QInputDialog>
+#include <boost/smart_ptr/make_shared.hpp>
+
#include "Swiften/Base/Platform.h"
#include "Swiften/Roster/ContactRosterItem.h"
#include "Swiften/Roster/GroupRosterItem.h"
#include "Swift/Controllers/UIEvents/UIEventStream.h"
#include "Swift/Controllers/UIEvents/RequestChatUIEvent.h"
-
-#include <qdebug.h>
-#include <QMenu>
-#include <QContextMenuEvent>
+#include "Swift/Controllers/UIEvents/RequestContactEditorUIEvent.h"
+#include "Swift/Controllers/UIEvents/RenameGroupUIEvent.h"
+#include "QtSwiftUtil.h"
namespace Swift {
@@ -25,7 +29,6 @@ QtTreeWidget::QtTreeWidget(UIEventStream* eventStream, QWidget* parent) : QTreeV
delegate_ = new RosterDelegate(this);
setItemDelegate(delegate_);
setHeaderHidden(true);
- contextMenu_ = NULL;
#ifdef SWIFT_PLATFORM_MACOSX
setAlternatingRowColors(true);
#endif
@@ -52,10 +55,6 @@ void QtTreeWidget::setRosterModel(Roster* roster) {
expandAll();
}
-void QtTreeWidget::setContextMenu(QtContextMenu* contextMenu) {
- contextMenu_ = contextMenu;
-}
-
QtTreeWidgetItem* QtTreeWidget::getRoot() {
return treeRoot_;
}
@@ -77,13 +76,29 @@ void QtTreeWidget::handleItemActivated(const QModelIndex& index) {
}
void QtTreeWidget::contextMenuEvent(QContextMenuEvent* event) {
- if (!contextMenu_) {
+ QModelIndex index = indexAt(event->pos());
+ if (!index.isValid()) {
return;
}
- QModelIndex index = indexAt(event->pos());
- RosterItem* item = index.isValid() ? static_cast<RosterItem*>(index.internalPointer()) : NULL;
- if (item) {
- contextMenu_->show(item);
+ RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
+ QMenu contextMenu;
+ if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) {
+ QAction* editContact = contextMenu.addAction("Edit");
+ QAction* result = contextMenu.exec(event->globalPos());
+ if (result == editContact) {
+ eventStream_->send(boost::make_shared<RequestContactEditorUIEvent>(contact->getJID()));
+ }
+ }
+ else if (GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item)) {
+ QAction* renameGroup = contextMenu.addAction("Rename");
+ QAction* result = contextMenu.exec(event->globalPos());
+ if (result == renameGroup) {
+ bool ok;
+ QString newName = QInputDialog::getText(NULL, "Rename group", "New name for " + P2QSTRING(group->getDisplayName()), QLineEdit::Normal, P2QSTRING(group->getDisplayName()), &ok);
+ if (ok) {
+ eventStream_->send(boost::make_shared<RenameGroupUIEvent>(group->getDisplayName(), Q2PSTRING(newName)));
+ }
+ }
}
}
diff --git a/Swift/QtUI/Roster/QtTreeWidget.h b/Swift/QtUI/Roster/QtTreeWidget.h
index 838c453..ff11567 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.h
+++ b/Swift/QtUI/Roster/QtTreeWidget.h
@@ -12,7 +12,6 @@
#include "Swift/QtUI/Roster/QtTreeWidget.h"
#include "Swift/QtUI/Roster/RosterModel.h"
#include "Swift/QtUI/Roster/RosterDelegate.h"
-#include "Swift/QtUI/ContextMenus/QtContextMenu.h"
namespace Swift {
class UIEventStream;
@@ -24,7 +23,6 @@ class QtTreeWidget : public QTreeView{
~QtTreeWidget();
void show();
QtTreeWidgetItem* getRoot();
- void setContextMenu(QtContextMenu* contextMenu);
void setRosterModel(Roster* roster);
Roster* getRoster() {return roster_;}
private slots:
@@ -42,7 +40,6 @@ class QtTreeWidget : public QTreeView{
Roster* roster_;
RosterDelegate* delegate_;
QtTreeWidgetItem* treeRoot_;
- QtContextMenu* contextMenu_;
UIEventStream* eventStream_;
};
diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript
index b16fb7d..d27dc8c 100644
--- a/Swift/QtUI/SConscript
+++ b/Swift/QtUI/SConscript
@@ -90,7 +90,7 @@ sources = [
"QtBookmarkDetailWindow.cpp",
"QtAddBookmarkWindow.cpp",
"QtEditBookmarkWindow.cpp",
- "QtSetGroupsDialog.cpp",
+ "QtContactEditWindow.cpp",
"ChatSnippet.cpp",
"MessageSnippet.cpp",
"SystemMessageSnippet.cpp",
@@ -120,8 +120,6 @@ sources = [
"UserSearch/QtUserSearchWindow.cpp",
"UserSearch/UserSearchModel.cpp",
"UserSearch/UserSearchDelegate.cpp",
- "ContextMenus/QtRosterContextMenu.cpp",
- "ContextMenus/QtContextMenu.cpp",
"QtSubscriptionRequestWindow.cpp",
"QtRosterHeader.cpp",
"QtWebView.cpp",