summaryrefslogtreecommitdiff
blob: 15d2da44ea2c5667d4654437309edbd1c8af42d4 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
commit 3614141a6e94ea1820dd731f2bb37f33371a4fcb
Author: Justin Karneges <justin@affinix.com>
Date:   Thu Aug 6 20:45:40 2009 -0700

    020-psi-muc-kickban-reasons.diff from psi+, with adjustment

diff --git a/options/default.xml b/options/default.xml
index 988589e..74021f2 100644
--- a/options/default.xml
+++ b/options/default.xml
@@ -51,6 +51,7 @@
 				<jids type="QStringList" />
 				<maximum comment="The maximum number of recently joined rooms that should be remembered" type="int">10</maximum>
 			</recent-joins>
+			<reasons type="QStringList" />
 		</muc> 
 		<pgp comment="PGP encryption options">
 			<enable comment="Enable PGP globally" type="bool">true</enable>
diff --git a/src/gcuserview.cpp b/src/gcuserview.cpp
index 810feb2..8962425 100644
--- a/src/gcuserview.cpp
+++ b/src/gcuserview.cpp
@@ -335,10 +335,34 @@ void GCUserView::qlv_contextMenuRequested(Q3ListViewItem *i, const QPoint &pos,
 	pm->insertItem(IconsetFactory::icon("psi/sendMessage").icon(), tr("Send &Message"), 0);
 	pm->insertItem(IconsetFactory::icon("psi/start-chat").icon(), tr("Open &Chat Window"), 1);
 	pm->insertSeparator();
-	pm->insertItem(tr("&Kick"),10);
-	pm->setItemEnabled(10, MUCManager::canKick(c->s.mucItem(),lvi->s.mucItem()));
-	pm->insertItem(tr("&Ban"),11);
-	pm->setItemEnabled(11, MUCManager::canBan(c->s.mucItem(),lvi->s.mucItem()));
+
+	// Kick and Ban submenus
+	QStringList reasons = PsiOptions::instance()->getOption("options.muc.reasons").toStringList();
+	int cntReasons=reasons.count();
+	if (cntReasons>99) cntReasons=99; // Only first 99 reasons
+	
+	Q3PopupMenu *kickMenu = new Q3PopupMenu(pm);
+	kickMenu->insertItem(tr("No reason"),10);
+	kickMenu->insertItem(tr("Custom reason"),100);
+	kickMenu->insertSeparator();
+	bool canKick=MUCManager::canKick(c->s.mucItem(),lvi->s.mucItem());
+	for (int i=0; i<cntReasons; ++i)
+		kickMenu->insertItem(reasons[i], 101+i);
+	kickMenu->setEnabled(canKick);
+	
+	Q3PopupMenu *banMenu = new Q3PopupMenu(pm);
+        banMenu->insertItem(tr("No reason"),11);
+	banMenu->insertItem(tr("Custom reason"),200);
+	banMenu->insertSeparator();
+	bool canBan=MUCManager::canBan(c->s.mucItem(),lvi->s.mucItem());
+	for (int i=0; i<cntReasons; ++i)
+		banMenu->insertItem(reasons[i], 201+i);
+	banMenu->setEnabled(canBan);
+
+	pm->insertItem(tr("&Kick"), kickMenu);
+	pm->setItemEnabled(10, canKick);
+	pm->insertItem(tr("&Ban"), banMenu);
+	pm->setItemEnabled(11, canBan);
 
 	Q3PopupMenu* rm = new Q3PopupMenu(pm);
 	rm->insertItem(tr("Visitor"),12);
@@ -372,7 +396,7 @@ void GCUserView::qlv_contextMenuRequested(Q3ListViewItem *i, const QPoint &pos,
 	pm->insertItem(tr("Check &Status"), 2);
 	pm->insertItem(IconsetFactory::icon("psi/vCard").icon(), tr("User &Info"), 3);
 	int x = pm->exec(pos);
-	bool enabled = pm->isItemEnabled(x) || rm->isItemEnabled(x);
+	bool enabled = pm->isItemEnabled(x) || rm->isItemEnabled(x) || kickMenu->isItemEnabled(x) || banMenu->isItemEnabled(x);
 	delete pm;
 
 	if(x == -1 || !enabled || lvi.isNull())
diff --git a/src/groupchatdlg.cpp b/src/groupchatdlg.cpp
index 1397af3..baed25b 100644
--- a/src/groupchatdlg.cpp
+++ b/src/groupchatdlg.cpp
@@ -76,6 +76,7 @@
 #include "psicontactlist.h"
 #include "accountlabel.h"
 #include "gcuserview.h"
+#include "mucreasonseditor.h"
 #include "mcmdmanager.h"
 
 #include "mcmdsimplesite.h"
@@ -1712,6 +1713,32 @@ void GCMainDlg::lv_action(const QString &nick, const Status &s, int x)
 		if (contact->s.mucItem().role() != MUCItem::Moderator)
 			d->mucManager->setRole(nick, MUCItem::Moderator);
 	}
+	else if(x >= 100 && x<300) {
+		// Kick || Ban with reason
+		QString reason;
+		QStringList reasons = PsiOptions::instance()->getOption("options.muc.reasons").toStringList();
+		if (x==100 || x==200) {
+			// Show custom reason dialog
+			MUCReasonsEditor *editor=new MUCReasonsEditor(this);
+			if (editor->exec())
+				reason=editor->reason();
+			delete editor;
+		} else {
+			int idx = (x<200) ? x-101 : x-201;
+			if (idx<reasons.count())
+				reason=reasons[idx];
+		}
+		if (!reason.isEmpty()) {
+			if (x<200)
+				d->mucManager->kick(nick, reason);
+			else {
+				GCUserViewItem *contact = (GCUserViewItem*) ui_.lv_users->findEntry(nick);
+				if (!contact) return;
+				d->mucManager->ban(contact->s.mucItem().jid(), reason);
+			}
+		}
+
+	}
 	/*else if(x == 15) {
 		GCUserViewItem *contact = (GCUserViewItem*) ui_.lv_users->findEntry(nick);
 		if (contact->s.mucItem().affiliation() != MUCItem::NoAffiliation)
diff --git a/src/mucreasonseditor.cpp b/src/mucreasonseditor.cpp
new file mode 100644
index 0000000..54117ba
--- /dev/null
+++ b/src/mucreasonseditor.cpp
@@ -0,0 +1,44 @@
+#include "mucreasonseditor.h"
+#include "common.h"
+#include "psioptions.h"
+
+
+MUCReasonsEditor::MUCReasonsEditor(QWidget* parent)
+	: QDialog(parent)
+{
+	ui_.setupUi(this);
+	ui_.lstReasons->addItems(PsiOptions::instance()->getOption("options.muc.reasons").toStringList());
+}
+
+MUCReasonsEditor::~MUCReasonsEditor()
+{	
+}
+
+void MUCReasonsEditor::accept()
+{
+	QStringList reasons;
+	int cnt=ui_.lstReasons->count();
+	for (int i=0; i<cnt; ++i)
+		reasons.append(ui_.lstReasons->item(i)->text());
+	PsiOptions::instance()->setOption("options.muc.reasons", reasons);
+	reason_=ui_.txtReason->text();
+	QDialog::accept();
+}
+
+void MUCReasonsEditor::on_btnAdd_clicked()
+{
+	reason_=ui_.txtReason->text().trimmed();
+	if (reason_.isEmpty())
+		return;
+	ui_.lstReasons->addItem(reason_);
+}
+
+void MUCReasonsEditor::on_btnRemove_clicked()
+{
+	int idx=ui_.lstReasons->currentRow();
+	if (idx>=0) {
+		QListWidgetItem *item =ui_.lstReasons->takeItem(idx);
+		if (item) delete item;
+	}
+}
+
diff --git a/src/mucreasonseditor.h b/src/mucreasonseditor.h
new file mode 100644
index 0000000..765fb2e
--- /dev/null
+++ b/src/mucreasonseditor.h
@@ -0,0 +1,25 @@
+#ifndef MUCREASONSEDITOR_H
+#define MUCREASONSEDITOR_H
+
+#include <QDialog>
+
+#include "ui_mucreasonseditor.h"
+
+class MUCReasonsEditor: public QDialog
+{
+	Q_OBJECT
+public:
+	MUCReasonsEditor(QWidget* parent = 0);
+	~MUCReasonsEditor();
+	QString reason() const { return reason_; }
+private:
+	Ui::MUCReasonsEditor ui_;
+	QString reason_;
+private slots:
+	void on_btnAdd_clicked();
+	void on_btnRemove_clicked();
+protected slots:
+	void accept();
+};
+
+#endif
diff --git a/src/mucreasonseditor.ui b/src/mucreasonseditor.ui
new file mode 100644
index 0000000..b1d9b8a
--- /dev/null
+++ b/src/mucreasonseditor.ui
@@ -0,0 +1,151 @@
+<ui version="4.0" >
+ <class>MUCReasonsEditor</class>
+ <widget class="QDialog" name="MUCReasonsEditor" >
+  <property name="geometry" >
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle" >
+   <string>Reason editor</string>
+  </property>
+  <layout class="QVBoxLayout" >
+   <property name="margin" >
+    <number>9</number>
+   </property>
+   <property name="spacing" >
+    <number>6</number>
+   </property>
+   <item>
+    <widget class="QGroupBox" name="groupBox" >
+     <property name="title" >
+      <string>Reasons</string>
+     </property>
+     <layout class="QVBoxLayout" >
+      <property name="margin" >
+       <number>9</number>
+      </property>
+      <property name="spacing" >
+       <number>6</number>
+      </property>
+      <item>
+       <widget class="QLineEdit" name="txtReason" >
+        <property name="text" >
+         <string/>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QListWidget" name="lstReasons" />
+      </item>
+      <item>
+       <layout class="QHBoxLayout" >
+        <property name="margin" >
+         <number>0</number>
+        </property>
+        <property name="spacing" >
+         <number>6</number>
+        </property>
+        <item>
+         <widget class="QPushButton" name="btnAdd" >
+          <property name="text" >
+           <string>Add</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QPushButton" name="btnRemove" >
+          <property name="text" >
+           <string>Remove</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" >
+     <property name="margin" >
+      <number>0</number>
+     </property>
+     <property name="spacing" >
+      <number>6</number>
+     </property>
+     <item>
+      <spacer>
+       <property name="orientation" >
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" >
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QPushButton" name="btnOk" >
+       <property name="text" >
+        <string>Ok</string>
+       </property>
+       <property name="autoDefault" >
+        <bool>false</bool>
+       </property>
+       <property name="default" >
+        <bool>true</bool>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="btnCancel" >
+       <property name="text" >
+        <string>Cancel</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>btnOk</sender>
+   <signal>clicked()</signal>
+   <receiver>MUCReasonsEditor</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>265</x>
+     <y>271</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>-2</x>
+     <y>287</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>btnCancel</sender>
+   <signal>clicked()</signal>
+   <receiver>MUCReasonsEditor</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>341</x>
+     <y>283</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>81</x>
+     <y>272</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
diff --git a/src/src.pri b/src/src.pri
index 2487038..1562bab 100644
--- a/src/src.pri
+++ b/src/src.pri
@@ -190,6 +190,7 @@ HEADERS += \
 	$$PWD/mucaffiliationsmodel.h \
 	$$PWD/mucaffiliationsproxymodel.h \
 	$$PWD/mucaffiliationsview.h \
+	$$PWD/mucreasonseditor.h \
 	$$PWD/rosteritemexchangetask.h \
 	$$PWD/mood.h \
 	$$PWD/moodcatalog.h \
@@ -308,6 +309,7 @@ SOURCES += \
 	$$PWD/mucaffiliationsmodel.cpp \
 	$$PWD/mucaffiliationsproxymodel.cpp \
 	$$PWD/mucaffiliationsview.cpp \
+	$$PWD/mucreasonseditor.cpp \
 	$$PWD/rosteritemexchangetask.cpp \
 	$$PWD/mood.cpp \
 	$$PWD/moodcatalog.cpp \
@@ -411,6 +413,7 @@ INTERFACES += \
 	$$PWD/optioneditor.ui \
 	$$PWD/passphrase.ui \
 	$$PWD/mucconfig.ui \
+	$$PWD/mucreasonseditor.ui \
 	$$PWD/xmlconsole.ui \
 	$$PWD/disco.ui \
 	$$PWD/tip.ui \