summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
Diffstat (limited to 'Swift')
-rw-r--r--Swift/QtUI/QtMainWindow.cpp6
-rw-r--r--Swift/QtUI/QtMainWindow.h1
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.cpp50
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.h9
4 files changed, 59 insertions, 7 deletions
diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp
index 99cbcf5..ca357e3 100644
--- a/Swift/QtUI/QtMainWindow.cpp
+++ b/Swift/QtUI/QtMainWindow.cpp
@@ -92,6 +92,10 @@ QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventS
addUserAction_ = new QAction(tr("&Add Contact"), this);
connect(addUserAction_, SIGNAL(triggered(bool)), this, SLOT(handleAddUserActionTriggered(bool)));
actionsMenu->addAction(addUserAction_);
+ editUserAction_ = new QAction(tr("&Edit Selected Contact"), this);
+ connect(editUserAction_, SIGNAL(triggered(bool)), treeWidget_, SLOT(handleEditUserActionTriggered(bool)));
+ actionsMenu->addAction(editUserAction_);
+ editUserAction_->setEnabled(false);
chatUserAction_ = new QAction(tr("Start &Chat"), this);
connect(chatUserAction_, SIGNAL(triggered(bool)), this, SLOT(handleChatUserActionTriggered(bool)));
actionsMenu->addAction(chatUserAction_);
@@ -100,6 +104,8 @@ QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventS
connect(signOutAction, SIGNAL(triggered()), SLOT(handleSignOutAction()));
actionsMenu->addAction(signOutAction);
+ connect(treeWidget_, SIGNAL(onSomethingSelectedChanged(bool)), editUserAction_, SLOT(setEnabled(bool)));
+
lastOfflineState_ = false;
uiEventStream_->onUIEvent.connect(boost::bind(&QtMainWindow::handleUIEvent, this, _1));
}
diff --git a/Swift/QtUI/QtMainWindow.h b/Swift/QtUI/QtMainWindow.h
index 0dc9d36..3462bb0 100644
--- a/Swift/QtUI/QtMainWindow.h
+++ b/Swift/QtUI/QtMainWindow.h
@@ -63,6 +63,7 @@ namespace Swift {
QtTreeWidget* treeWidget_;
QtRosterHeader* meView_;
QAction* addUserAction_;
+ QAction* editUserAction_;
QAction* chatUserAction_;
QAction* showOfflineAction_;
QtTabWidget* tabs_;
diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp
index a76dc70..3198ca5 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.cpp
+++ b/Swift/QtUI/Roster/QtTreeWidget.cpp
@@ -66,8 +66,23 @@ void QtTreeWidget::handleClicked(const QModelIndex& index) {
if (item) {
setExpanded(index, !isExpanded(index));
}
+ currentChanged(index, QModelIndex());
}
+void QtTreeWidget::currentChanged(const QModelIndex& current, const QModelIndex& previous) {
+ bool valid = false;
+ if (!editable_ || selectedIndexes().empty() || !selectedIndexes()[0].isValid()) {
+ /* I didn't quite understand why using current didn't seem to work here.*/
+ }
+ else if (current.isValid()) {
+ RosterItem* item = static_cast<RosterItem*>(current.internalPointer());
+ if (dynamic_cast<ContactRosterItem*>(item)) {
+ valid = true;
+ }
+ }
+ onSomethingSelectedChanged(valid);
+ QTreeView::currentChanged(current, previous);
+}
void QtTreeWidget::handleItemActivated(const QModelIndex& index) {
RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
@@ -77,6 +92,23 @@ void QtTreeWidget::handleItemActivated(const QModelIndex& index) {
}
}
+void QtTreeWidget::handleEditUserActionTriggered(bool /*checked*/) {
+ if (!editable_) {
+ return;
+ }
+ if (selectedIndexes().empty()) {
+ return;
+ }
+ QModelIndex index = selectedIndexes()[0];
+ if (!index.isValid()) {
+ return;
+ }
+ RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
+ if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) {
+ eventStream_->send(boost::make_shared<RequestContactEditorUIEvent>(contact->getJID()));
+ }
+}
+
void QtTreeWidget::contextMenuEvent(QContextMenuEvent* event) {
if (!editable_) {
return;
@@ -101,18 +133,22 @@ void QtTreeWidget::contextMenuEvent(QContextMenuEvent* event) {
}
}
else if (GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item)) {
- QAction* renameGroup = contextMenu.addAction(tr("Rename"));
+ QAction* renameGroupAction = contextMenu.addAction(tr("Rename"));
QAction* result = contextMenu.exec(event->globalPos());
- if (result == renameGroup) {
- bool ok;
- QString newName = QInputDialog::getText(NULL, tr("Rename group"), tr("New name for %1").arg(P2QSTRING(group->getDisplayName())), QLineEdit::Normal, P2QSTRING(group->getDisplayName()), &ok);
- if (ok) {
- eventStream_->send(boost::make_shared<RenameGroupUIEvent>(group->getDisplayName(), Q2PSTRING(newName)));
- }
+ if (result == renameGroupAction) {
+ renameGroup(group);
}
}
}
+void QtTreeWidget::renameGroup(GroupRosterItem* group) {
+ bool ok;
+ QString newName = QInputDialog::getText(NULL, tr("Rename group"), tr("New name for %1").arg(P2QSTRING(group->getDisplayName())), QLineEdit::Normal, P2QSTRING(group->getDisplayName()), &ok);
+ if (ok) {
+ eventStream_->send(boost::make_shared<RenameGroupUIEvent>(group->getDisplayName(), Q2PSTRING(newName)));
+ }
+}
+
void QtTreeWidget::handleExpanded(const QModelIndex& index) {
GroupRosterItem* item = dynamic_cast<GroupRosterItem*>(static_cast<RosterItem*>(index.internalPointer()));
if (item) {
diff --git a/Swift/QtUI/Roster/QtTreeWidget.h b/Swift/QtUI/Roster/QtTreeWidget.h
index ce2351b..1ab8c8e 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.h
+++ b/Swift/QtUI/Roster/QtTreeWidget.h
@@ -25,6 +25,12 @@ class QtTreeWidget : public QTreeView{
Roster* getRoster() {return roster_;}
void setEditable(bool b) { editable_ = b; }
+ signals:
+ void onSomethingSelectedChanged(bool);
+
+ public slots:
+ void handleEditUserActionTriggered(bool checked);
+
private slots:
void handleItemActivated(const QModelIndex&);
void handleModelItemExpanded(const QModelIndex&, bool expanded);
@@ -33,8 +39,11 @@ class QtTreeWidget : public QTreeView{
void handleClicked(const QModelIndex&);
protected:
void contextMenuEvent(QContextMenuEvent* event);
+ protected slots:
+ virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous);
private:
+ void renameGroup(GroupRosterItem* group);
void drawBranches(QPainter*, const QRect&, const QModelIndex&) const;
RosterModel* model_;
Roster* roster_;