summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/Roster')
-rw-r--r--Swift/QtUI/Roster/QtOccupantListWidget.cpp53
-rw-r--r--Swift/QtUI/Roster/QtOccupantListWidget.h7
-rw-r--r--Swift/QtUI/Roster/QtRosterWidget.cpp16
-rw-r--r--Swift/QtUI/Roster/QtRosterWidget.h5
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.cpp15
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.h4
6 files changed, 52 insertions, 48 deletions
diff --git a/Swift/QtUI/Roster/QtOccupantListWidget.cpp b/Swift/QtUI/Roster/QtOccupantListWidget.cpp
index 2f992bf..cbda0f1 100644
--- a/Swift/QtUI/Roster/QtOccupantListWidget.cpp
+++ b/Swift/QtUI/Roster/QtOccupantListWidget.cpp
@@ -3,57 +3,58 @@
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include "Roster/QtOccupantListWidget.h"
#include <QContextMenuEvent>
#include <QMenu>
+#include <QAction>
#include <QInputDialog>
#include "Swift/Controllers/Roster/ContactRosterItem.h"
#include "Swift/Controllers/Roster/GroupRosterItem.h"
#include "Swift/Controllers/UIEvents/UIEventStream.h"
#include "QtSwiftUtil.h"
namespace Swift {
QtOccupantListWidget::QtOccupantListWidget(UIEventStream* eventStream, QWidget* parent) : QtTreeWidget(eventStream, parent) {
}
QtOccupantListWidget::~QtOccupantListWidget() {
}
+void QtOccupantListWidget::setAvailableOccupantActions(const std::vector<ChatWindow::OccupantAction>& actions) {
+ availableOccupantActions_ = actions;
+}
+
void QtOccupantListWidget::contextMenuEvent(QContextMenuEvent* event) {
-// QModelIndex index = indexAt(event->pos());
-// if (!index.isValid()) {
-// return;
-// }
-// RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
-// QMenu contextMenu;
-// if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(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<RequestContactEditorUIEvent>(contact->getJID()));
-// }
-// else if (result == removeContact) {
-// if (QtContactEditWindow::confirmContactDeletion(contact->getJID())) {
-// eventStream_->send(boost::make_shared<RemoveRosterItemUIEvent>(contact->getJID()));
-// }
-// }
-// }
-// else if (GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item)) {
-// QAction* renameGroupAction = contextMenu.addAction(tr("Rename"));
-// QAction* result = contextMenu.exec(event->globalPos());
-// if (result == renameGroupAction) {
-// renameGroup(group);
-// }
-// }
+ QModelIndex index = indexAt(event->pos());
+ if (!index.isValid()) {
+ return;
+ }
+ RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ if (contact) {
+ QMenu contextMenu;
+ std::map<QAction*, ChatWindow::OccupantAction> actions;
+ foreach (ChatWindow::OccupantAction availableAction, availableOccupantActions_) {
+ QString text = "Error: missing string";
+ switch (availableAction) {
+ case ChatWindow::Kick: text = tr("Kick user"); break;
+ }
+ QAction* action = contextMenu.addAction(text);
+ actions[action] = availableAction;
+ }
+ QAction* result = contextMenu.exec(event->globalPos());
+ if (result) {
+ onOccupantActionSelected(actions[result], contact);
+ }
+ }
}
}
diff --git a/Swift/QtUI/Roster/QtOccupantListWidget.h b/Swift/QtUI/Roster/QtOccupantListWidget.h
index 5444210..ef29c00 100644
--- a/Swift/QtUI/Roster/QtOccupantListWidget.h
+++ b/Swift/QtUI/Roster/QtOccupantListWidget.h
@@ -2,22 +2,29 @@
* Copyright (c) 2011 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#pragma once
#include "Swift/QtUI/Roster/QtTreeWidget.h"
+#include "Swiften/Base/boost_bsignals.h"
+#include "Swift/Controllers/UIInterfaces/ChatWindow.h"
+
namespace Swift {
class QtOccupantListWidget : public QtTreeWidget {
Q_OBJECT
public:
QtOccupantListWidget(UIEventStream* eventStream, QWidget* parent = 0);
virtual ~QtOccupantListWidget();
+ void setAvailableOccupantActions(const std::vector<ChatWindow::OccupantAction>& actions);
+ boost::signal<void (ChatWindow::OccupantAction, ContactRosterItem*)> onOccupantActionSelected;
protected:
void contextMenuEvent(QContextMenuEvent* event);
+ private:
+ std::vector<ChatWindow::OccupantAction> availableOccupantActions_;
};
}
diff --git a/Swift/QtUI/Roster/QtRosterWidget.cpp b/Swift/QtUI/Roster/QtRosterWidget.cpp
index 79d7f67..923f977 100644
--- a/Swift/QtUI/Roster/QtRosterWidget.cpp
+++ b/Swift/QtUI/Roster/QtRosterWidget.cpp
@@ -75,26 +75,10 @@ void QtRosterWidget::contextMenuEvent(QContextMenuEvent* event) {
void QtRosterWidget::renameGroup(GroupRosterItem* group) {
bool ok;
QString newName = QInputDialog::getText(NULL, tr("Rename group"), tr("Enter a new name for group '%1':").arg(P2QSTRING(group->getDisplayName())), QLineEdit::Normal, P2QSTRING(group->getDisplayName()), &ok);
if (ok) {
eventStream_->send(boost::make_shared<RenameGroupUIEvent>(group->getDisplayName(), Q2PSTRING(newName)));
}
}
-void QtRosterWidget::currentChanged(const QModelIndex& current, const QModelIndex& previous) {
- bool valid = false;
- QModelIndexList selectedIndexList = getSelectedIndexes();
- if (selectedIndexList.empty() || !selectedIndexList[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);
-}
-
}
diff --git a/Swift/QtUI/Roster/QtRosterWidget.h b/Swift/QtUI/Roster/QtRosterWidget.h
index 7781e07..f870237 100644
--- a/Swift/QtUI/Roster/QtRosterWidget.h
+++ b/Swift/QtUI/Roster/QtRosterWidget.h
@@ -3,28 +3,23 @@
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#pragma once
#include "Swift/QtUI/Roster/QtTreeWidget.h"
namespace Swift {
-
class QtRosterWidget : public QtTreeWidget {
Q_OBJECT
public:
QtRosterWidget(UIEventStream* eventStream, QWidget* parent = 0);
virtual ~QtRosterWidget();
public slots:
void handleEditUserActionTriggered(bool checked);
- signals:
- void onSomethingSelectedChanged(bool);
protected:
void contextMenuEvent(QContextMenuEvent* event);
- protected slots:
- virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous);
private:
void renameGroup(GroupRosterItem* group);
};
}
diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp
index 7de4028..96a078b 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.cpp
+++ b/Swift/QtUI/Roster/QtTreeWidget.cpp
@@ -75,18 +75,33 @@ QModelIndexList QtTreeWidget::getSelectedIndexes() const {
if (ranges.at(i).left() == 0 && ranges.at(i).right() == right) {
for (int r = ranges.at(i).top(); r <= ranges.at(i).bottom(); ++r) {
selectedIndexList.append(ranges.at(i).model()->index(r, 0, parent));
}
}
}
return selectedIndexList;
}
+void QtTreeWidget::currentChanged(const QModelIndex& current, const QModelIndex& previous) {
+ RosterItem* item = NULL;
+ QModelIndexList selectedIndexList = getSelectedIndexes();
+ if (selectedIndexList.empty() || !selectedIndexList[0].isValid()) {
+ /* I didn't quite understand why using current didn't seem to work here.*/
+ }
+ else if (current.isValid()) {
+ item = static_cast<RosterItem*>(current.internalPointer());
+ item = dynamic_cast<ContactRosterItem*>(item);
+ }
+ onSomethingSelectedChanged(item);
+ QTreeView::currentChanged(current, previous);
+}
+
+
void QtTreeWidget::handleItemActivated(const QModelIndex& index) {
RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
if (contact) {
eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(contact->getJID())));
}
}
void QtTreeWidget::handleExpanded(const QModelIndex& index) {
diff --git a/Swift/QtUI/Roster/QtTreeWidget.h b/Swift/QtUI/Roster/QtTreeWidget.h
index c45a1cd..1ad56d6 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.h
+++ b/Swift/QtUI/Roster/QtTreeWidget.h
@@ -17,31 +17,33 @@ class UIEventStream;
class QtTreeWidget : public QTreeView{
Q_OBJECT
public:
QtTreeWidget(UIEventStream* eventStream, QWidget* parent = 0);
~QtTreeWidget();
void show();
QtTreeWidgetItem* getRoot();
void setRosterModel(Roster* roster);
Roster* getRoster() {return roster_;}
+ boost::signal<void (RosterItem*)> onSomethingSelectedChanged;
private slots:
void handleItemActivated(const QModelIndex&);
void handleModelItemExpanded(const QModelIndex&, bool expanded);
void handleExpanded(const QModelIndex&);
void handleCollapsed(const QModelIndex&);
void handleClicked(const QModelIndex&);
protected:
QModelIndexList getSelectedIndexes() const;
private:
void drawBranches(QPainter*, const QRect&, const QModelIndex&) const;
-
+ protected slots:
+ virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous);
protected:
UIEventStream* eventStream_;
private:
RosterModel* model_;
Roster* roster_;
RosterDelegate* delegate_;
QtTreeWidgetItem* treeRoot_;
};