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
|
/* mode buttons for ksirc - Robbie Ward <linuxphreak@gmx.co.uk>*/
#include "chanButtons.h"
#include "chanButtons.moc"
#include <klocale.h>
#include <kpopupmenu.h>
#include <knuminput.h>
#include <kstdguiitem.h>
#include <kpushbutton.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qlineedit.h>
#include "ksircprocess.h"
static void makeSquare(QWidget *w)
{
QSize sh = w->sizeHint();
int s = sh.height();
w->setFixedSize(s,s);
}
chanButtons::chanButtons(KSircProcess *proc, QWidget *parent, const char *name)
: QWidget(parent, name),
m_proc(proc)
{
Popupmenu = new KPopupMenu( this );
Popupmenu->insertTitle(i18n("Channel Modes"));
toggleMenu[0] = Popupmenu->insertItem(i18n("i (invite-only)"), this, SLOT(invite()));
toggleMenu[1] = Popupmenu->insertItem(i18n("l (limited users)"), this, SLOT(limited()));
toggleMenu[2] = Popupmenu->insertItem(i18n("k (key to join)"), this, SLOT(key()));
toggleMenu[3] = Popupmenu->insertItem(i18n("s (secret)"), this, SLOT(secret()));
Popupmenu->insertSeparator();
Popupmenu->insertTitle(i18n("User Modes"));
toggleMenu[4] = Popupmenu->insertItem(i18n("i (be invisible)"), this, SLOT(invisible()));
toggleMenu[5] = Popupmenu->insertItem(i18n("w (receive wallops)"), this, SLOT(wallops()));
toggleMenu[6] = Popupmenu->insertItem(i18n("s (get server notices)"), this, SLOT(serverNotices()));
layout = new QHBoxLayout(this);
layout->setSpacing(0);
layout->setMargin(0);
protectButton = new QPushButton(i18n("T"), this);
protectButton->setToggleButton(true);
makeSquare(protectButton);
QToolTip::add(protectButton, i18n("Only op'ed users can change the topic"));
connect(protectButton, SIGNAL(clicked()), this, SLOT(protectMode()));
layout->addWidget(protectButton);
outsideButton = new QPushButton(i18n("N"), this);
outsideButton->setToggleButton(true);
makeSquare(outsideButton);
QToolTip::add(outsideButton, i18n("No outside messages"));
connect(outsideButton, SIGNAL(clicked()), this, SLOT(outsideMode()));
layout->addWidget(outsideButton);
moderateButton = new QPushButton(i18n("M"), this);
moderateButton->setToggleButton(true);
makeSquare(moderateButton);
QToolTip::add(moderateButton, i18n("Only op'ed users and voiced users (+v) can speak"));
connect(moderateButton, SIGNAL(clicked()), this, SLOT(moderateMode()));
layout->addWidget(moderateButton);
menuButton = new QPushButton(i18n("..."), this);
makeSquare(menuButton);
menuButton->setFixedWidth(menuButton->width()*2);
menuButton->setPopup(Popupmenu);
QToolTip::add(menuButton, i18n("More mode commands"));
layout->addWidget(menuButton);
}
void chanButtons::invite()
{
if (Popupmenu->isItemChecked(toggleMenu[0])) {
Popupmenu->setItemChecked(toggleMenu[0], false);
emit mode(QString("-i"), 0);
}
else {
Popupmenu->setItemChecked(toggleMenu[0], true);
emit mode(QString("+i"), 0);
}
}
void chanButtons::limited()
{
chanDialog = new chanbuttonsDialog(chanbuttonsDialog::limited);
chanDialog->exec();
if (chanDialog->sendLimitedUsers() == 0) {
Popupmenu->setItemChecked(toggleMenu[1], false);
emit mode(QString("-l"), 0);
}
else {
Popupmenu->setItemChecked(toggleMenu[1], true);
emit mode(QString("+l %1").arg(chanDialog->sendLimitedUsers()), 0);
}
delete chanDialog;
}
void chanButtons::key()
{
chanDialog = new chanbuttonsDialog(chanbuttonsDialog::key);
if (Popupmenu->isItemChecked(toggleMenu[2])) {
chanDialog->exec();
Popupmenu->setItemChecked(toggleMenu[2], false);
emit mode(QString("-k %1").arg(chanDialog->sendKey()), 0);
}
else {
chanDialog->exec();
Popupmenu->setItemChecked(toggleMenu[2], true);
emit mode(QString("+k %1").arg(chanDialog->sendKey()), 0);
}
delete chanDialog;
}
void chanButtons::secret()
{
if (Popupmenu->isItemChecked(toggleMenu[3])) {
Popupmenu->setItemChecked(toggleMenu[3], false);
emit mode(QString("-s"), 0);
}
else {
Popupmenu->setItemChecked(toggleMenu[3], true);
emit mode(QString("+s"), 0);
}
}
void chanButtons::invisible()
{
if (Popupmenu->isItemChecked(toggleMenu[4])) {
Popupmenu->setItemChecked(toggleMenu[4], false);
emit mode(QString("-i"), 1, m_proc->getNick());
}
else {
Popupmenu->setItemChecked(toggleMenu[4], true);
emit mode(QString("+i"), 1, m_proc->getNick());
}
}
void chanButtons::wallops()
{
if (Popupmenu->isItemChecked(toggleMenu[5])) {
Popupmenu->setItemChecked(toggleMenu[5], false);
emit mode(QString("-w"), 1, m_proc->getNick());
}
else {
Popupmenu->setItemChecked(toggleMenu[5], true);
emit mode(QString("+w"), 1, m_proc->getNick());
}
}
void chanButtons::serverNotices()
{
if (Popupmenu->isItemChecked(toggleMenu[6])) {
Popupmenu->setItemChecked(toggleMenu[6], false);
emit mode(QString("-s"), 1, m_proc->getNick());
}
else {
Popupmenu->setItemChecked(toggleMenu[6], true);
emit mode(QString("+s"), 1, m_proc->getNick());
}
}
void chanButtons::protectMode()
{
if (protectButton->isOn())
emit mode(QString("+t"), 0);
else
emit mode(QString("-t"), 0);
}
void chanButtons::outsideMode()
{
if (outsideButton->isOn())
emit mode(QString("+n"), 0);
else
emit mode(QString("-n"), 0);
}
void chanButtons::moderateMode()
{
if (moderateButton->isOn())
emit mode(QString("+m"), 0);
else
emit mode(QString("-m"), 0);
}
void chanButtons::setButtonsEnabled(bool enabled)
{
// Set all the channel mode entries disabled if non-op else enable them
protectButton->setEnabled(enabled);
outsideButton->setEnabled(enabled);
moderateButton->setEnabled(enabled);
Popupmenu->setItemEnabled(toggleMenu[0], enabled);
Popupmenu->setItemEnabled(toggleMenu[1], enabled);
Popupmenu->setItemEnabled(toggleMenu[2], enabled);
Popupmenu->setItemEnabled(toggleMenu[3], enabled);
}
void chanButtons::setMenuItemMode(int id, bool value)
{
Popupmenu->setItemChecked(toggleMenu[id], value);
}
chanbuttonsDialog::chanbuttonsDialog(const type &modeType, QWidget *parent,
const char *name, bool modal) : KDialog(parent, name, modal)
{
m_sendKey = "";
m_sendLimitedUsers = 0;
resize(190, 82);
setCaption(i18n("Limit Number of Users"));
LimitedLayout = new QVBoxLayout(this);
LimitedLayout->setSpacing(9);
LimitedLayout->setMargin(11);
switch (modeType) {
case limited:
SpinBox = new KIntSpinBox(this);
LimitedLayout->addWidget(SpinBox);
break;
case key:
EditBox = new QLineEdit(this);
LimitedLayout->addWidget(EditBox);
break;
}
Layout = new QHBoxLayout;
Layout->setSpacing(6);
Layout->setMargin(0);
okButton = new KPushButton(KStdGuiItem::ok(), this);
okButton->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1,
okButton->sizePolicy().hasHeightForWidth()));
Layout->addWidget(okButton);
switch (modeType) {
case limited:
connect(okButton, SIGNAL(clicked()), SLOT(limitedUsers()));
break;
case key:
connect(okButton, SIGNAL(clicked()), SLOT(keyString()));
break;
}
Layout->addWidget(okButton);
cancelButton = new KPushButton(KStdGuiItem::cancel(), this);
cancelButton->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1,
cancelButton->sizePolicy().hasHeightForWidth()));
Layout->addWidget(cancelButton);
connect(cancelButton, SIGNAL(clicked()), SLOT(reject()));
LimitedLayout->addLayout(Layout);
QSpacerItem *spacer = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
LimitedLayout->addItem(spacer);
}
void chanbuttonsDialog::keyString()
{
m_sendKey = EditBox->text();
accept();
}
void chanbuttonsDialog::limitedUsers()
{
m_sendLimitedUsers = SpinBox->value();
accept();
}
|