summaryrefslogtreecommitdiffstats
blob: 4d7a543109eac71985c69512e0518c1e3b4c43cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * Copyright (c) 2011-2014 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */


#include <Swift/QtUI/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 <Swift/QtUI/QtSwiftUtil.h>

namespace Swift {

QtOccupantListWidget::QtOccupantListWidget(UIEventStream* eventStream, SettingsProvider* settings, MessageTarget privateMessageTarget, QWidget* parent) : QtTreeWidget(eventStream, settings, privateMessageTarget, 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());
	ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
	if (contact) {
		onSomethingSelectedChanged(contact);
		QMenu contextMenu;
		if (availableOccupantActions_.empty()) {
			QAction* noAction = contextMenu.addAction(tr("No actions for this user"));
			noAction->setEnabled(false);
			contextMenu.exec(event->globalPos());
		}
		else {
			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;
					case ChatWindow::Ban: text = tr("Kick and ban user"); break;
					case ChatWindow::MakeModerator: text = tr("Make moderator"); break;
					case ChatWindow::MakeParticipant: text = tr("Make participant"); break;
					case ChatWindow::MakeVisitor: text = tr("Remove voice"); break;
					case ChatWindow::AddContact: text = tr("Add to contacts"); break;
					case ChatWindow::ShowProfile: text = tr("Show profile"); break;
				}
				QAction* action = contextMenu.addAction(text);
				actions[action] = availableAction;
			}
			QAction* result = contextMenu.exec(event->globalPos());
			if (result) {
				onOccupantActionSelected(actions[result], contact);
			}
		}
	}
}

}