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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
|
/*
This program is free software; you can redistribute it and/or self()->modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
*/
/*
Copyright (C) 2002 Dario Abatianni <eisfuchs@tigress.com>
Copyright (C) 2005 Ismail Donmez <ismail@kde.org>
Copyright (C) 2005 Peter Simonsson <psn@linux.se>
Copyright (C) 2005 John Tapsell <johnflux@gmail.com>
Copyright (C) 2005-2008 Eike Hein <hein@kde.org>
*/
#include "config/preferences.h"
#include "identity.h"
#include "ignore.h"
#include "highlight.h"
#include "commit.h"
#include "version.h"
#include <ktoolbar.h>
#include <kstandarddirs.h>
#include <kstaticdeleter.h>
#include <kdebug.h>
#include <kapplication.h>
#include <kconfig.h>
#include <klocale.h>
#include <kurl.h>
#include <kuser.h>
#include <tqpalette.h>
#include <tqregexp.h>
#include <tqfileinfo.h>
Preferences *Preferences::mSelf = 0;
static KStaticDeleter<Preferences> staticPreferencesDeleter;
Preferences *Preferences::self()
{
if ( !mSelf ) {
staticPreferencesDeleter.setObject( mSelf, new Preferences() );
mSelf->readConfig();
}
return mSelf;
}
Preferences::Preferences()
{
mSelf = this;
// create default identity
mIdentity=new Identity();
mIdentity->setName(i18n("Default Identity"));
addIdentity(mIdentity);
mIgnoreList.setAutoDelete(true);
KUser user(KUser::UseRealUserID);
mIdentity->setIdent(user.loginName());
mIdentity->setRealName(user.fullName());
TQStringList nickList;
nickList.append(user.loginName());
nickList.append(user.loginName() + '_');
nickList.append(user.loginName() + "__");
mIdentity->setNicknameList(nickList);
Konversation::ServerGroupSettingsPtr serverGroup = new Konversation::ServerGroupSettings;
serverGroup->setName("Ubuntu IRC");
Konversation::ServerSettings server;
server.setHost("irc.ubuntu.com");
server.setPort(8001);
serverGroup->addServer(server);
serverGroup->setIdentityId(mIdentity->id());
Konversation::ChannelSettings channel;
channel.setName("#kubuntu");
serverGroup->addChannel(channel);
serverGroup->setExpanded(false);
addServerGroup(serverGroup);
setQuickButtonList(defaultQuickButtonList());
setAutoreplaceList(defaultAutoreplaceList());
}
Preferences::~Preferences()
{
mIdentityList.clear();
if ( mSelf == this )
staticPreferencesDeleter.setObject( mSelf, 0, false );
}
const Konversation::ServerGroupList Preferences::serverGroupList()
{
return self()->mServerGroupList;
}
const TQStringList Preferences::defaultQuickButtonList()
{
return TQStringList() << "Op,/OP %u%n"
<< "DeOp,/DEOP %u%n"
<< "WhoIs,/WHOIS %s,%%u%n"
<< "Version,/CTCP %s,%%u VERSION%n"
<< "Kick,/KICK %u%n"
<< "Ban,/BAN %u%n"
<< "Part,/PART %c Leaving...%n"
<< "Quit,/QUIT Leaving...%n";
}
const TQStringList Preferences::quickButtonList()
{
return self()->mQuickButtonList;
}
void Preferences::setQuickButtonList(const TQStringList newList)
{
self()->mQuickButtonList=newList;
}
void Preferences::clearQuickButtonList()
{
self()->mQuickButtonList.clear();
}
// --------------------------- AutoReplace ---------------------------
const TQStringList Preferences::defaultAutoreplaceList()
{
return TQStringList() << "1,o,\\[\\[([^\\s]+)\\]\\],http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%1"
<< "1,o,([Dd][Bb][Uu][Gg]:)(\\w+),http://bugs.debian.org/%2"
<< "1,o,(BUG:|bug:)([0-9]+),http://bugs.kde.org/show_bug.cgi?id=%2";
}
const TQStringList Preferences::autoreplaceList()
{
return self()->mAutoreplaceList;
}
void Preferences::setAutoreplaceList(const TQStringList newList)
{
self()->mAutoreplaceList=newList;
}
void Preferences::clearAutoreplaceList()
{
self()->mAutoreplaceList.clear();
}
// --------------------------- AutoReplace ---------------------------
void Preferences::setServerGroupList(const Konversation::ServerGroupList& list)
{
self()->mServerGroupList.clear();
self()->mServerGroupList = list;
Konversation::ServerGroupList::iterator it;
}
void Preferences::addServerGroup(Konversation::ServerGroupSettingsPtr serverGroup)
{
self()->mServerGroupList.append(serverGroup);
}
const Konversation::ServerGroupSettingsPtr Preferences::serverGroupById(int id)
{
if (!self()->mServerGroupList.count())
{
return 0;
}
Konversation::ServerGroupList::iterator it;
for (it = self()->mServerGroupList.begin(); it != self()->mServerGroupList.end(); ++it)
{
if ((*it)->id() == id)
{
return (*it);
}
}
return 0;
}
const Konversation::ServerGroupSettingsPtr Preferences::serverGroupByServer(const TQString& server)
{
if (!self()->mServerGroupList.count())
{
return 0;
}
Konversation::ServerGroupList::iterator it;
for (it = self()->mServerGroupList.begin(); it != self()->mServerGroupList.end(); ++it)
{
for (uint i = 0; i != (*it)->serverList().count(); i++)
{
if ((*it)->serverByIndex(i).host().lower() == server)
{
return (*it);
}
}
}
return 0;
}
int Preferences::serverGroupIdByName(const TQString& serverGroup)
{
Konversation::ServerGroupList::iterator it;
for (it = self()->mServerGroupList.begin(); it != self()->mServerGroupList.end(); ++it)
{
if((*it)->name().lower() == serverGroup.lower())
{
return (*it)->id();
}
}
return -1;
}
bool Preferences::isServerGroup(const TQString& server)
{
Konversation::ServerGroupList::iterator it;
for(it = self()->mServerGroupList.begin(); it != self()->mServerGroupList.end(); ++it)
{
if((*it)->name().lower() == server.lower())
{
return true;
}
}
return false;
}
void Preferences::removeServerGroup(int id)
{
if (!self()->mServerGroupList.count())
{
return;
}
Konversation::ServerGroupList::iterator it;
for (it = self()->mServerGroupList.begin(); it != self()->mServerGroupList.end(); ++it)
{
if ((*it)->id() == id)
{
self()->mServerGroupList.remove(it);
return;
}
}
}
const TQPtrList<Highlight> Preferences::highlightList()
{
return self()->mHighlightList;
}
void Preferences::setHighlightList(TQPtrList<Highlight> newList)
{
self()->mHighlightList.clear();
self()->mHighlightList=newList;
}
void Preferences::addHighlight(const TQString& newHighlight,
bool regExp,
const TQColor &newColor,
const TQString& sound,
const TQString& autoText)
{
self()->mHighlightList.append(new Highlight(newHighlight,regExp,newColor,KURL(sound),autoText));
}
void Preferences::setIgnoreList(TQPtrList<Ignore> newList)
{
self()->mIgnoreList.clear();
self()->mIgnoreList=newList;
}
void Preferences::addIgnore(const TQString &newIgnore)
{
TQStringList ignore = TQStringList::split(',',newIgnore);
removeIgnore(ignore[0]);
self()->mIgnoreList.append(new Ignore(ignore[0],ignore[1].toInt()));
}
bool Preferences::removeIgnore(const TQString &oldIgnore)
{
TQPtrListIterator<Ignore> ignoreList( self()->mIgnoreList );
while (ignoreList.current())
{
if (ignoreList.current()->getName().lower()==oldIgnore.lower())
{
self()->mIgnoreList.remove(ignoreList.current());
return true;
}
++ignoreList;
}
return false;
}
bool Preferences::isIgnored(const TQString &nickname)
{
TQPtrListIterator<Ignore> ignoreList( self()->mIgnoreList );
while (ignoreList.current())
{
if (ignoreList.current()->getName().section('!',0,0).lower()==nickname.lower())
{
return true;
}
++ignoreList;
}
return false;
}
void Preferences::setNotifyList(const TQMap<int, TQStringList> &newList)
{ self()->mNotifyList=newList; }
const TQMap<int, TQStringList> Preferences::notifyList() { return self()->mNotifyList; }
const TQStringList Preferences::notifyListByGroupName(const TQString& groupName)
{
int id=serverGroupIdByName(groupName);
if (id && self()->mNotifyList.find(id) != self()->mNotifyList.end())
return self()->mNotifyList[id];
else
return TQStringList();
}
const TQString Preferences::notifyStringByGroupName(const TQString& groupName)
{
return notifyListByGroupName(groupName).join(" ");
}
bool Preferences::addNotify(int serverGroupId, const TQString& newPattern)
{
if (!self()->mNotifyList[serverGroupId].contains(newPattern))
{
TQStringList nicknameList = self()->mNotifyList[serverGroupId];
nicknameList.append(newPattern);
self()->mNotifyList[serverGroupId] = nicknameList;
return true;
}
return false;
}
bool Preferences::removeNotify(const TQString& groupName, const TQString& pattern)
{
int id=serverGroupIdByName(groupName);
if(!id) return false;
if (self()->mNotifyList.find(id) != self()->mNotifyList.end())
{
TQStringList nicknameList = self()->mNotifyList[id];
nicknameList.remove(pattern);
if (nicknameList.isEmpty())
self()->mNotifyList.remove(id);
else
self()->mNotifyList[id] = nicknameList;
return true;
}
return false;
}
bool Preferences::isNotify(int serverGroupId, const TQString& pattern)
{
if (self()->mNotifyList.find(serverGroupId) != self()->mNotifyList.end())
{
TQStringList nicknameList = self()->mNotifyList[serverGroupId];
if (nicknameList.contains(pattern)) return true;
}
return false;
}
bool Preferences::hasNotifyList(int serverGroupId)
{
if (self()->mNotifyList.find(serverGroupId) != self()->mNotifyList.end())
return true;
else
return false;
}
// Default identity functions
void Preferences::addIdentity(IdentityPtr identity) { self()->mIdentityList.append(identity); }
void Preferences::removeIdentity(IdentityPtr identity) { self()->mIdentityList.remove(identity); }
void Preferences::clearIdentityList()
{
self()->mIdentityList.clear();
}
const IdentityList Preferences::identityList() { return self()->mIdentityList; }
void Preferences::setIdentityList(const IdentityList& list)
{
self()->mIdentityList.clear();
self()->mIdentityList = list;
}
const IdentityPtr Preferences::identityByName(const TQString& name)
{
TQValueList<IdentityPtr> identities = identityList();
TQValueList<IdentityPtr>::iterator it = identities.begin();
while(it != identities.end())
{
if((*it)->getName() == name)
{
return (*it);
}
++it;
}
// no self()->matching identity found, return default identity
return identities.first();
}
const IdentityPtr Preferences::identityById(int id)
{
TQValueList<IdentityPtr> identList = identityList();
for(TQValueList<IdentityPtr>::iterator it = identList.begin(); it != identList.end(); ++it)
{
if((*it)->id() == id)
{
return (*it);
}
}
return identList.first();
}
TQStringList Preferences::defaultAliasList()
{
// Auto-alias scripts
TQStringList scripts = KGlobal::dirs()->findAllResources("data","konversation/scripts/*");
TQFileInfo* fileInfo = new TQFileInfo();
TQStringList aliasList;
TQString newAlias;
for (TQStringList::ConstIterator it = scripts.begin(); it != scripts.end(); ++it)
{
fileInfo->setFile(*it);
if (fileInfo->isExecutable())
{
newAlias = (*it).section('/',-1)+' '+"/exec "+(*it).section('/', -1 );
aliasList.append(newAlias);
// FIXME: Historically, defaultAliasList() is primarily used to dynamically
// compile a list of installed scripts and generate appropriate aliases for
// them. It's not only used when the alias preferences are reset or initia-
// lized, but also on application start. The following crudely adds two
// aliases when the 'media' script is found, to provide easy access to its
// capability to differentiate between audio and video media. This method
// needs at the very least to be split up in two, or scripts may in the
// future determine what aliases they want to add.
if ((*it).section('/',-1) == "media")
{
aliasList.append("audio /exec media audio");
aliasList.append("video /exec media video");
}
}
}
delete fileInfo;
return aliasList;
}
const TQString Preferences::realName() { return self()->mIdentityList[0]->getRealName(); }
void Preferences::setRealName(const TQString &name) { self()->mIdentityList[0]->setRealName(name); }
const TQString Preferences::ident() { return self()->mIdentityList[0]->getIdent(); }
void Preferences::setIdent(const TQString &ident) { self()->mIdentityList[0]->setIdent(ident); }
const TQString Preferences::partReason() { return self()->mIdentityList[0]->getPartReason(); }
void Preferences::setPartReason(const TQString &newReason) { self()->mIdentityList[0]->setPartReason(newReason); }
const TQString Preferences::kickReason() { return self()->mIdentityList[0]->getKickReason(); }
void Preferences::setKickReason(const TQString &newReason) { self()->mIdentityList[0]->setKickReason(newReason); }
bool Preferences::showAwayMessage() { return self()->mIdentityList[0]->getShowAwayMessage(); }
void Preferences::setShowAwayMessage(bool state) { self()->mIdentityList[0]->setShowAwayMessage(state); }
const TQString Preferences::awayMessage() { return self()->mIdentityList[0]->getAwayMessage(); }
void Preferences::setAwayMessage(const TQString &newMessage) { self()->mIdentityList[0]->setAwayMessage(newMessage); }
const TQString Preferences::unAwayMessage() { return self()->mIdentityList[0]->getReturnMessage(); }
void Preferences::setUnAwayMessage(const TQString &newMessage) { self()->mIdentityList[0]->setReturnMessage(newMessage); }
void Preferences::clearIgnoreList() { self()->mIgnoreList.clear(); }
const TQPtrList<Ignore> Preferences::ignoreList() { return self()->mIgnoreList; }
const TQString Preferences::nickname(int index) { return self()->mIdentityList[0]->getNickname(index); }
const TQStringList Preferences::nicknameList() { return self()->mIdentityList[0]->getNicknameList(); }
void Preferences::setNickname(int index,const TQString &newName) { self()->mIdentityList[0]->setNickname(index,newName); }
void Preferences::setNicknameList(const TQStringList &newList) { self()->mIdentityList[0]->setNicknameList(newList); }
void Preferences::setShowTrayIcon(bool state)
{
PreferencesBase::setShowTrayIcon(state);
emit self()->updateTrayIcon();
}
void Preferences::setTrayNotify(bool state)
{
PreferencesBase::setTrayNotify(state);
emit self()->updateTrayIcon();
}
void Preferences::setAutoUserhost(bool state)
{
PreferencesBase::setAutoUserhost(state);
}
bool Preferences::dialogFlag(const TQString& flagName)
{
KConfig* config=KApplication::kApplication()->config();
config->setGroup("Notification self()->Messages");
if( !config->readEntry(flagName).isEmpty() )
return false;
else
return true;
}
void Preferences::setDialogFlag(const TQString& flagName,bool state)
{
KConfig* config=KApplication::kApplication()->config();
config->setGroup("Notification self()->Messages");
if(state)
config->deleteEntry(flagName);
else
{
if ( config->readEntry(flagName).isEmpty() )
config->writeEntry(flagName,"no");
}
config->sync();
}
// Channel Encodings
const TQString Preferences::channelEncoding(const TQString& server,const TQString& channel)
{
return channelEncoding(serverGroupIdByName(server),channel);
}
const TQString Preferences::channelEncoding(int serverGroupId,const TQString& channel)
{
if(self()->mChannelEncodingsMap.contains(serverGroupId))
if(self()->mChannelEncodingsMap[serverGroupId].contains(channel.lower()))
return self()->mChannelEncodingsMap[serverGroupId][channel.lower()];
return TQString();
}
void Preferences::setChannelEncoding(const TQString& server,const TQString& channel,const TQString& encoding)
{
setChannelEncoding(serverGroupIdByName(server),channel,encoding);
}
void Preferences::setChannelEncoding(int serverGroupId,const TQString& channel,const TQString& encoding)
{
self()->mChannelEncodingsMap[serverGroupId][channel.lower()]=encoding;
}
const TQValueList<int> Preferences::channelEncodingsServerGroupIdList()
{
return self()->mChannelEncodingsMap.keys();
}
const TQStringList Preferences::channelEncodingsChannelList(int serverGroupId)
{
return self()->mChannelEncodingsMap[serverGroupId].keys();
}
const TQString Preferences::defaultNicknameSortingOrder()
{
return "qpohv-";
}
// override to add %u if needed
TQString Preferences::webBrowserCmd()
{
// add %u to command if it's not in there
TQString cmd=self()->mWebBrowserCmd;
if(cmd.find("%u")==-1) cmd+=" %u";
return cmd;
}
#include "preferences.moc"
|