~ubuntu-branches/ubuntu/trusty/kvirc/trusty-proposed

« back to all changes in this revision

Viewing changes to src/kvirc/ui/kvi_modeeditor.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//=============================================================================
2
 
//
3
 
//   File : kvi_modeeditor.cpp
4
 
//   Creation date : Sat Apr 14 2001 13:52:11 by Szymon Stefanek
5
 
//
6
 
//   This file is part of the KVirc irc client distribution
7
 
//   Copyright (C) 2001-2008 Szymon Stefanek (pragma at kvirc dot net)
8
 
//
9
 
//   This program is FREE software. You can redistribute it and/or
10
 
//   modify it under the terms of the GNU General Public License
11
 
//   as published by the Free Software Foundation; either version 2
12
 
//   of the License, or (at your opinion) any later version.
13
 
//
14
 
//   This program is distributed in the HOPE that it will be USEFUL,
15
 
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
 
//   See the GNU General Public License for more details.
18
 
//
19
 
//   You should have received a copy of the GNU General Public License
20
 
//   along with this program. If not, write to the Free Software Foundation,
21
 
//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
 
//
23
 
//=============================================================================
24
 
 
25
 
#include "kvi_modeeditor.h"
26
 
#include "kvi_iconmanager.h"
27
 
#include "kvi_locale.h"
28
 
#include "kvi_qstring.h"
29
 
#include "kvi_console.h"
30
 
#include "kvi_ircconnection.h"
31
 
#include "kvi_ircconnectionserverinfo.h"
32
 
#include "kvi_channel.h"
33
 
#include "kvi_ircconnectionuserinfo.h"
34
 
#include "kvi_toolwindows_container.h"
35
 
 
36
 
#include <QScrollArea>
37
 
#include <QLayout>
38
 
#include <QLabel>
39
 
 
40
 
 
41
 
//////////////////////////////////////////////////////////////////////
42
 
// class KviModeEditor
43
 
//
44
 
//////////////////////////////////////////////////////////////////////
45
 
 
46
 
//static char checkable_modes_table[KVI_NUM_CHECKABLE_MODES] = { 'p','s','t','n','m','i'};
47
 
 
48
 
KviModeEditor::KviModeEditor(QWidget * par,KviWindowToolPageButton* button,const char *,KviConsole * c,const QString &mode,const QString &key,const QString &limit)
49
 
: KviWindowToolWidget(par,button)
50
 
{
51
 
        m_szMode = mode;
52
 
        m_szKey = key;
53
 
        m_szLimit = limit;
54
 
        bool isEnabled=1;
55
 
 
56
 
        QObject * w = parent();
57
 
        while(w)
58
 
        {
59
 
                if(w->inherits("KviChannel"))
60
 
                {
61
 
                        KviChannel *chan = ((KviChannel *)w);
62
 
                        if(!( chan->isMeHalfOp() || chan->isMeOp() || chan->isMeChanOwner() || chan->isMeChanAdmin() || chan->connection()->userInfo()->hasUserMode('o') || chan->connection()->userInfo()->hasUserMode('O') ) )  isEnabled=0;
63
 
                        break;
64
 
                }
65
 
                w = w->parent();
66
 
        }
67
 
 
68
 
        QGridLayout *pMasterLayout = new QGridLayout(this);
69
 
 
70
 
        setFocusPolicy(Qt::ClickFocus);
71
 
 
72
 
        QScrollArea * pScrollArea = new QScrollArea(this);
73
 
        pScrollArea->viewport()->setBackgroundRole(QPalette::Background);
74
 
        pMasterLayout->addWidget(pScrollArea,0,0);
75
 
 
76
 
        pMasterLayout->setRowStretch(1,1);
77
 
        QPushButton * b;
78
 
        if(isEnabled) b = new QPushButton(__tr2qs("&Apply"),this);
79
 
        else b = new QPushButton(__tr2qs("Close"),this);
80
 
 
81
 
        pMasterLayout->addWidget(b,1,0);
82
 
        connect(b,SIGNAL(clicked()),this,SLOT(commit()));
83
 
 
84
 
        QWidget * pBackground = new QWidget(pScrollArea->viewport());
85
 
 
86
 
        QGridLayout *g = new QGridLayout(pBackground);
87
 
 
88
 
        QLabel * l = new QLabel("",pBackground);
89
 
        l->setPixmap(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_MODE)));
90
 
        g->addWidget(l,0,0);
91
 
 
92
 
        l = new QLabel(__tr2qs("Channel Modes"),pBackground);
93
 
 
94
 
        g->addWidget(l,0,1,1,1);
95
 
 
96
 
        QFrame * f = new QFrame(pBackground);
97
 
        f->setFrameStyle(QFrame::HLine | QFrame::Sunken);
98
 
        g->addWidget(f,1,0,1,3);
99
 
 
100
 
        int i = 1;
101
 
        QString tmp;
102
 
 
103
 
        m_pCheckBoxes = new KviPointerList<QCheckBox>;
104
 
        m_pCheckBoxes->setAutoDelete(false);
105
 
 
106
 
 
107
 
        // first che basic checkable modes pstnmi
108
 
        QString szModes = "pstnmi";
109
 
 
110
 
        while(!szModes.isEmpty())
111
 
        {
112
 
                QChar ccc = szModes[0];
113
 
                szModes.remove(0,1);
114
 
 
115
 
                KviQString::sprintf(tmp,"%c: %Q",ccc.unicode(),&(c->connection()->serverInfo()->getChannelModeDescription(ccc)));
116
 
                QCheckBox * cb = new QCheckBox(tmp,pBackground);
117
 
                cb->setEnabled(isEnabled);
118
 
                m_pCheckBoxes->append(cb);
119
 
                cb->setChecked(m_szMode.contains((char)ccc.unicode()));
120
 
                i++;
121
 
                g->addWidget(cb,i,0,1,3);
122
 
        }
123
 
 
124
 
        KviQString::sprintf(tmp,"l: %Q",&(c->connection()->serverInfo()->getChannelModeDescription('l')));
125
 
        m_pLimitBox = new QCheckBox(tmp,pBackground);
126
 
        m_pLimitBox->setEnabled(isEnabled);
127
 
        i++;
128
 
        g->addWidget(m_pLimitBox,i,0,1,3);
129
 
        connect(m_pLimitBox,SIGNAL(toggled(bool)),this,SLOT(limitBoxToggled(bool)));
130
 
        m_pLimitEdit = new QLineEdit(pBackground);
131
 
        m_pLimitEdit->setEnabled(isEnabled);
132
 
        i++;
133
 
        g->addWidget(m_pLimitEdit,i,1,1,2);
134
 
        if(!m_szLimit.isEmpty())
135
 
        {
136
 
                m_pLimitBox->setChecked(true);
137
 
                m_pLimitEdit->setText(m_szLimit);
138
 
        } else {
139
 
                m_pLimitEdit->setEnabled(false);
140
 
        }
141
 
 
142
 
        KviQString::sprintf(tmp,"k: %Q",&(c->connection()->serverInfo()->getChannelModeDescription('k')));
143
 
        m_pKeyBox = new QCheckBox(tmp,pBackground);
144
 
        m_pKeyBox->setEnabled(isEnabled);
145
 
        i++;
146
 
 
147
 
        g->addWidget(m_pKeyBox,i,0,1,3);
148
 
        connect(m_pKeyBox,SIGNAL(toggled(bool)),this,SLOT(keyBoxToggled(bool)));
149
 
        m_pKeyEdit = new QLineEdit(pBackground);
150
 
        m_pKeyEdit->setEnabled(isEnabled);
151
 
        i++;
152
 
        g->addWidget(m_pKeyEdit,i,1,1,2);
153
 
        if(!m_szKey.isEmpty())
154
 
        {
155
 
                m_pKeyBox->setChecked(true);
156
 
                m_pKeyEdit->setText(m_szKey);
157
 
        } else {
158
 
                m_pKeyEdit->setEnabled(false);
159
 
        }
160
 
 
161
 
        if(c->connection())
162
 
        {
163
 
                if(c->connection()->serverInfo())
164
 
                        szModes = c->connection()->serverInfo()->supportedChannelModes();
165
 
        }
166
 
 
167
 
        int idx = szModes.lastIndexOf(',');
168
 
        if(idx != -1)szModes.remove(0,idx+1);
169
 
 
170
 
        szModes.replace("p","");
171
 
        szModes.replace("s","");
172
 
        szModes.replace("t","");
173
 
        szModes.replace("n","");
174
 
        szModes.replace("m","");
175
 
        szModes.replace("i","");
176
 
        szModes.replace(",","");
177
 
        szModes.replace("b","");
178
 
        szModes.replace("k","");
179
 
        szModes.replace("l","");
180
 
 
181
 
        while(!szModes.isEmpty())
182
 
        {
183
 
                QChar ccc = szModes[0];
184
 
                szModes.remove(0,1);
185
 
 
186
 
                KviQString::sprintf(tmp,"%c: %Q",(char)ccc.unicode(),&(c->connection()->serverInfo()->getChannelModeDescription(ccc)));
187
 
                QCheckBox * cb = new QCheckBox(tmp,pBackground);
188
 
                cb->setEnabled(isEnabled);
189
 
                m_pCheckBoxes->append(cb);
190
 
                cb->setChecked(m_szMode.contains((char)ccc.unicode()));
191
 
                i++;
192
 
                g->addWidget(cb,i,0,1,3);
193
 
        }
194
 
 
195
 
        i++;
196
 
 
197
 
        g->setRowStretch(i,1);
198
 
        g->setColumnStretch(2,1);
199
 
 
200
 
        pScrollArea->setWidget(pBackground);
201
 
}
202
 
 
203
 
KviModeEditor::~KviModeEditor()
204
 
{
205
 
        delete m_pCheckBoxes;
206
 
}
207
 
 
208
 
void KviModeEditor::limitBoxToggled(bool bChecked)
209
 
{
210
 
        m_pLimitEdit->setEnabled(bChecked);
211
 
}
212
 
 
213
 
void KviModeEditor::keyBoxToggled(bool bChecked)
214
 
{
215
 
        m_pKeyEdit->setEnabled(bChecked);
216
 
}
217
 
 
218
 
void KviModeEditor::commit()
219
 
{
220
 
        KviStr szPlusModes;
221
 
        KviStr szMinusModes;
222
 
 
223
 
        if(!m_szKey.isEmpty())
224
 
        {
225
 
                // had a key before
226
 
                if(m_pKeyBox->isChecked())
227
 
                {
228
 
                        // still have it
229
 
                        QString tmp = m_pKeyEdit->text().trimmed();
230
 
                        if(!tmp.isEmpty())
231
 
                        {
232
 
                                if(tmp != m_szKey)
233
 
                                {
234
 
                                        // not the same key!
235
 
                                        // set the new one
236
 
                                        KviStr mode(KviStr::Format,"-k %s",m_szKey.toUtf8().data()); // FIXME: assuming utf8 is wrong here!
237
 
                                        emit setMode(mode.ptr());
238
 
                                        mode.sprintf("+k %s",tmp.toUtf8().data());
239
 
                                        emit setMode(mode.ptr());
240
 
                                }
241
 
                        }
242
 
                } else {
243
 
                        // no key now! reset
244
 
                        KviStr mode(KviStr::Format,"-k %s",m_szKey.toUtf8().data());
245
 
                        emit setMode(mode.ptr());
246
 
                }
247
 
        } else {
248
 
                // there was no key before
249
 
                if(m_pKeyBox->isChecked())
250
 
                {
251
 
                        QString tmp = m_pKeyEdit->text().trimmed();
252
 
                        if(!tmp.isEmpty())
253
 
                        {
254
 
                                // new key to be set
255
 
                                KviStr mode(KviStr::Format,"+k %s",tmp.toUtf8().data());
256
 
                                emit setMode(mode.ptr());
257
 
                        }
258
 
                }
259
 
        }
260
 
 
261
 
        if(!m_szLimit.isEmpty())
262
 
        {
263
 
                // had a limit before
264
 
                if(m_pLimitBox->isChecked())
265
 
                {
266
 
                        // still have it
267
 
                        QString tmp = m_pLimitEdit->text().trimmed();
268
 
                        bool bOk;
269
 
                        unsigned int uLimit = tmp.toUInt(&bOk);
270
 
                        if(bOk)
271
 
                        {
272
 
                                if(m_szLimit != tmp)
273
 
                                {
274
 
                                        // not the same limit!
275
 
                                        KviStr mode(KviStr::Format,"+l %u",uLimit);
276
 
                                        emit setMode(mode.ptr());
277
 
                                }
278
 
                        }
279
 
                } else {
280
 
                        // no limit now! reset
281
 
                        szMinusModes.append('l');
282
 
                }
283
 
        } else {
284
 
                // there was no limit before
285
 
                if(m_pLimitBox->isChecked())
286
 
                {
287
 
                        QString tmp = m_pLimitEdit->text().trimmed();
288
 
                        bool bOk;
289
 
                        unsigned int uLimit = tmp.toUInt(&bOk);
290
 
                        if(bOk)
291
 
                        {
292
 
                                // new limit to be set
293
 
                                KviStr mode(KviStr::Format,"+l %u",uLimit);
294
 
                                emit setMode(mode.ptr());
295
 
                        }
296
 
                }
297
 
        }
298
 
 
299
 
 
300
 
        for(QCheckBox * cb = m_pCheckBoxes->first();cb;cb = m_pCheckBoxes->next())
301
 
        {
302
 
                QString sz = cb->text();
303
 
                sz.replace("&","");
304
 
                if(sz.length() > 0)
305
 
                {
306
 
                        QChar ccc = sz[0];
307
 
                        if(cb->isChecked())
308
 
                        {
309
 
                                if(!m_szMode.contains((char)ccc.unicode()))szPlusModes.append((char)ccc.unicode());
310
 
                        } else {
311
 
                                if(m_szMode.contains((char)ccc.unicode()))szMinusModes.append((char)ccc.unicode());
312
 
                        }
313
 
                }
314
 
        }
315
 
 
316
 
        KviStr szModes;
317
 
 
318
 
        if(szMinusModes.hasData())szModes.sprintf("-%s",szMinusModes.ptr());
319
 
        if(szPlusModes.hasData())szModes.append(KviStr::Format,"+%s",szPlusModes.ptr());
320
 
        if(szModes.hasData())emit setMode(szModes.ptr());
321
 
 
322
 
        emit done();
323
 
}
324
 
 
325
 
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
326
 
#include "kvi_modeeditor.moc"
327
 
#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES