summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/Roster/QtTreeWidget.cpp')
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.cpp50
1 files changed, 43 insertions, 7 deletions
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) {