~ubuntu-branches/ubuntu/raring/konversation/raring

« back to all changes in this revision

Viewing changes to .pc/debian-changes-1.3.1-1ubuntu2/src/config/preferences.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-08-11 17:53:27 UTC
  • Revision ID: james.westby@ubuntu.com-20100811175327-vj8gal6554f0cdck
Tags: 1.3.1-1ubuntu2
* Add back correct debian/patches/series file, adds back in
  kubuntu_01_default_channels.diff message-indicator/0001-Adds-
  support-for-Message-Indicator.diff LP: #616422
* Remove obsolete debian/patches/kubuntu/ directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  This program is free software; you can redistribute it and/or self()->modify
 
3
  it under the terms of the GNU General Public License as published by
 
4
  the Free Software Foundation; either version 2 of the License, or
 
5
  (at your option) any later version.
 
6
*/
 
7
 
 
8
/*
 
9
  Copyright (C) 2002 Dario Abatianni <eisfuchs@tigress.com>
 
10
  Copyright (C) 2005 Ismail Donmez <ismail@kde.org>
 
11
  Copyright (C) 2005 Peter Simonsson <psn@linux.se>
 
12
  Copyright (C) 2005 John Tapsell <johnflux@gmail.com>
 
13
  Copyright (C) 2005-2008 Eike Hein <hein@kde.org>
 
14
*/
 
15
 
 
16
#include "config/preferences.h"
 
17
#include "ignore.h"
 
18
#include "highlight.h"
 
19
 
 
20
#include <QFileInfo>
 
21
#include <QHashIterator>
 
22
#include <QHeaderView>
 
23
#include <QTreeView>
 
24
 
 
25
#include <KLocale>
 
26
#include <KUser>
 
27
#include <KStandardDirs>
 
28
 
 
29
struct PreferencesSingleton
 
30
{
 
31
    Preferences prefs;
 
32
};
 
33
 
 
34
K_GLOBAL_STATIC(PreferencesSingleton, s_prefs)
 
35
 
 
36
Preferences *Preferences::self()
 
37
{
 
38
  if ( !s_prefs.exists() ) {
 
39
    s_prefs->prefs.readConfig();
 
40
  }
 
41
 
 
42
  return &s_prefs->prefs;
 
43
}
 
44
 
 
45
 
 
46
Preferences::Preferences()
 
47
{
 
48
    // create default identity
 
49
    mIdentity=new Identity();
 
50
    mIdentity->setName(i18n("Default Identity"));
 
51
    mIdentityList.append(mIdentity);
 
52
 
 
53
    KUser user(KUser::UseRealUserID);
 
54
    mIdentity->setIdent(user.loginName());
 
55
    mIdentity->setRealName(user.property(KUser::FullName).toString());
 
56
 
 
57
    QStringList nickList;
 
58
    nickList.append(user.loginName());
 
59
    nickList.append(user.loginName() + '_');
 
60
    nickList.append(user.loginName() + "__");
 
61
    mIdentity->setNicknameList(nickList);
 
62
 
 
63
    Konversation::ServerGroupSettingsPtr serverGroup(new Konversation::ServerGroupSettings);
 
64
    serverGroup->setName("Ubuntu IRC");
 
65
    Konversation::ServerSettings server;
 
66
    server.setHost("irc.ubuntu.com");
 
67
    server.setPort(8001);
 
68
    serverGroup->addServer(server);
 
69
    serverGroup->setIdentityId(mIdentity->id());
 
70
    Konversation::ChannelSettings channel;
 
71
    channel.setName("#kubuntu");
 
72
    serverGroup->addChannel(channel);
 
73
    serverGroup->setExpanded(false);
 
74
    mServerGroupHash.insert(0, serverGroup);
 
75
    mQuickButtonList = defaultQuickButtonList();
 
76
    mAutoreplaceList = defaultAutoreplaceList();
 
77
}
 
78
 
 
79
Preferences::~Preferences()
 
80
{
 
81
    mIdentityList.clear();
 
82
    qDeleteAll(mIgnoreList);
 
83
    qDeleteAll(mHighlightList);
 
84
}
 
85
const Konversation::ServerGroupHash Preferences::serverGroupHash()
 
86
{
 
87
    return self()->mServerGroupHash;
 
88
}
 
89
 
 
90
const QStringList Preferences::defaultQuickButtonList()
 
91
{
 
92
    return QStringList() << "Op,/OP %u%n"
 
93
                         << "DeOp,/DEOP %u%n"
 
94
                         << "WhoIs,/WHOIS %s,%%u%n"
 
95
                         << "Version,/CTCP %s,%%u VERSION%n"
 
96
                         << "Kick,/KICK %u%n"
 
97
                         << "Ban,/BAN %u%n"
 
98
                         << "Part,/PART %c Leaving...%n"
 
99
                         << "Quit,/QUIT Leaving...%n";
 
100
}
 
101
 
 
102
const QStringList Preferences::quickButtonList()
 
103
{
 
104
  return self()->mQuickButtonList;
 
105
}
 
106
 
 
107
void Preferences::setQuickButtonList(const QStringList newList)
 
108
{
 
109
  self()->mQuickButtonList=newList;
 
110
}
 
111
 
 
112
void Preferences::clearQuickButtonList()
 
113
{
 
114
  self()->mQuickButtonList.clear();
 
115
}
 
116
 
 
117
// --------------------------- AutoReplace ---------------------------
 
118
 
 
119
const QList<QStringList> Preferences::defaultAutoreplaceList()
 
120
{
 
121
    QList<QStringList> defaultList;
 
122
    defaultList.append(QStringList() << "1" << "o" << "\\[\\[([^\\s]+)\\]\\]" << "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%1");
 
123
    defaultList.append(QStringList() << "1" << "o" << "(BUG:|bug:)([0-9]+)" << "https://bugs.kde.org/show_bug.cgi?id=%2");
 
124
    defaultList.append(QStringList() << "1" << "o" << "([Dd][Bb][Uu][Gg]:)(\\w+)" << "http://bugs.debian.org/%2");
 
125
    return defaultList;
 
126
}
 
127
 
 
128
const QList<QStringList> Preferences::autoreplaceList()
 
129
{
 
130
  return self()->mAutoreplaceList;
 
131
}
 
132
 
 
133
void Preferences::setAutoreplaceList(const QList<QStringList> newList)
 
134
{
 
135
  self()->mAutoreplaceList=newList;
 
136
}
 
137
 
 
138
void Preferences::clearAutoreplaceList()
 
139
{
 
140
  self()->mAutoreplaceList.clear();
 
141
}
 
142
 
 
143
// --------------------------- AutoReplace ---------------------------
 
144
 
 
145
void Preferences::setServerGroupHash(const Konversation::ServerGroupHash& hash)
 
146
{
 
147
    self()->mServerGroupHash.clear();
 
148
    self()->mServerGroupHash = hash;
 
149
}
 
150
 
 
151
void Preferences::addServerGroup(Konversation::ServerGroupSettingsPtr serverGroup)
 
152
{
 
153
    Konversation::ServerGroupHash hash = self()->mServerGroupHash;
 
154
    hash.insert(serverGroup->id(), serverGroup);
 
155
    self()->mServerGroupHash = hash;
 
156
}
 
157
 
 
158
const Konversation::ServerGroupSettingsPtr Preferences::serverGroupById(int id)
 
159
{
 
160
    return  self()->mServerGroupHash.value(id);
 
161
}
 
162
 
 
163
const QList<Konversation::ServerGroupSettingsPtr> Preferences::serverGroupsByServer(const QString& server)
 
164
{
 
165
    QList<Konversation::ServerGroupSettingsPtr> serverGroups;
 
166
    QHashIterator<int, Konversation::ServerGroupSettingsPtr> it(self()->mServerGroupHash);
 
167
    while(it.hasNext())
 
168
    {
 
169
        it.next();
 
170
        for (int i=0; i != it.value()->serverList().count(); i++)
 
171
        {
 
172
            if(it.value()->serverByIndex(i).host().toLower() == server)
 
173
                serverGroups.append(it.value());
 
174
        }
 
175
    }
 
176
    return serverGroups;
 
177
}
 
178
 
 
179
QList<int> Preferences::serverGroupIdsByName(const QString& serverGroup)
 
180
{
 
181
    QList<int> serverIds;
 
182
    QHashIterator<int, Konversation::ServerGroupSettingsPtr> it(self()->mServerGroupHash);
 
183
    while(it.hasNext())
 
184
    {
 
185
        if(it.next().value()->name().toLower() == serverGroup.toLower())
 
186
            serverIds.append(it.key());
 
187
    }
 
188
    if (serverIds.isEmpty())
 
189
        serverIds.append(-1);
 
190
 
 
191
    return serverIds;
 
192
}
 
193
 
 
194
bool Preferences::isServerGroup(const QString& server)
 
195
{
 
196
    QHashIterator<int, Konversation::ServerGroupSettingsPtr> it(self()->mServerGroupHash);
 
197
    while(it.hasNext())
 
198
    {
 
199
        if(it.next().value()->name().toLower() == server.toLower())
 
200
            return true;
 
201
    }
 
202
    return false;
 
203
}
 
204
 
 
205
void Preferences::removeServerGroup(int id)
 
206
{
 
207
    self()->mServerGroupHash.remove(id);
 
208
}
 
209
 
 
210
 
 
211
const QList<Highlight*> Preferences::highlightList()
 
212
{
 
213
    return self()->mHighlightList;
 
214
}
 
215
 
 
216
void Preferences::setHighlightList(QList<Highlight*> newList)
 
217
{
 
218
    qDeleteAll(self()->mHighlightList);
 
219
    self()->mHighlightList.clear();
 
220
    self()->mHighlightList=newList;
 
221
}
 
222
 
 
223
void Preferences::addHighlight(const QString& newHighlight,
 
224
bool regExp,
 
225
const QColor &newColor,
 
226
const QString& sound,
 
227
const QString& autoText)
 
228
{
 
229
    self()->mHighlightList.append(new Highlight(newHighlight,regExp,newColor,KUrl(sound),autoText));
 
230
}
 
231
 
 
232
void Preferences::setIgnoreList(QList<Ignore*> newList)
 
233
{
 
234
    clearIgnoreList();
 
235
    self()->mIgnoreList=newList;
 
236
}
 
237
 
 
238
void Preferences::addIgnore(const QString &newIgnore)
 
239
{
 
240
    QStringList ignore = newIgnore.split(',');
 
241
    removeIgnore(ignore[0]);
 
242
    self()->mIgnoreList.append(new Ignore(ignore[0],ignore[1].toInt()));
 
243
}
 
244
 
 
245
bool Preferences::removeIgnore(const QString &oldIgnore)
 
246
{
 
247
    foreach (Ignore *ignore, self()->mIgnoreList)
 
248
    {
 
249
        if (ignore->getName().toLower() == oldIgnore.toLower())
 
250
        {
 
251
            self()->mIgnoreList.removeOne(ignore);
 
252
            delete ignore;
 
253
            return true;
 
254
        }
 
255
    }
 
256
 
 
257
    return false;
 
258
}
 
259
 
 
260
bool Preferences::isIgnored(const QString &nickname)
 
261
{
 
262
    foreach (Ignore *ignore, self()->mIgnoreList)
 
263
    {
 
264
        if (ignore->getName().section('!',0,0).toLower()==nickname.toLower())
 
265
        {
 
266
            return true;
 
267
        }
 
268
    }
 
269
 
 
270
    return false;
 
271
}
 
272
 
 
273
void Preferences::setNotifyList(const QMap<int, QStringList> &newList)
 
274
{ self()->mNotifyList=newList; }
 
275
 
 
276
const QMap<int, QStringList> Preferences::notifyList() { return self()->mNotifyList; }
 
277
 
 
278
const QStringList Preferences::notifyListByGroupId(int serverGroupId)
 
279
{
 
280
  if (serverGroupId && self()->mNotifyList.find(serverGroupId) != self()->mNotifyList.end())
 
281
        return self()->mNotifyList.value(serverGroupId);
 
282
  else
 
283
        return QStringList();
 
284
}
 
285
 
 
286
const QString Preferences::notifyStringByGroupId(int serverGroupId)
 
287
{
 
288
    return notifyListByGroupId(serverGroupId).join(" ");
 
289
}
 
290
 
 
291
bool Preferences::addNotify(int serverGroupId, const QString& newPattern)
 
292
{
 
293
    if (!self()->mNotifyList[serverGroupId].contains(newPattern))
 
294
    {
 
295
        QStringList nicknameList = self()->mNotifyList[serverGroupId];
 
296
        nicknameList.append(newPattern);
 
297
        self()->mNotifyList[serverGroupId] = nicknameList;
 
298
        return true;
 
299
    }
 
300
    return false;
 
301
}
 
302
 
 
303
bool Preferences::removeNotify(int serverGroupId, const QString& pattern)
 
304
{
 
305
    if (self()->mNotifyList.find(serverGroupId) != self()->mNotifyList.end())
 
306
    {
 
307
        QStringList nicknameList = self()->mNotifyList[serverGroupId];
 
308
        nicknameList.removeAll(pattern); //FIXME: what semantics do you really want here?
 
309
        if (nicknameList.isEmpty())
 
310
            self()->mNotifyList.remove(serverGroupId);
 
311
        else
 
312
            self()->mNotifyList[serverGroupId] = nicknameList;
 
313
        return true;
 
314
    }
 
315
    return false;
 
316
}
 
317
 
 
318
bool Preferences::isNotify(int serverGroupId, const QString& pattern)
 
319
{
 
320
    if (self()->mNotifyList.find(serverGroupId) != self()->mNotifyList.end())
 
321
    {
 
322
        QStringList nicknameList = self()->mNotifyList[serverGroupId];
 
323
 
 
324
        if (nicknameList.contains(pattern)) return true;
 
325
    }
 
326
    return false;
 
327
}
 
328
 
 
329
bool Preferences::hasNotifyList(int serverGroupId)
 
330
{
 
331
    if (self()->mNotifyList.find(serverGroupId) != self()->mNotifyList.end())
 
332
        return true;
 
333
    else
 
334
        return false;
 
335
}
 
336
 
 
337
// Default identity functions
 
338
void Preferences::addIdentity(IdentityPtr identity) { self()->mIdentityList.append(identity); }
 
339
void Preferences::removeIdentity(IdentityPtr identity) { self()->mIdentityList.removeOne(identity); }
 
340
 
 
341
void Preferences::clearIdentityList()
 
342
{
 
343
    self()->mIdentityList.clear();
 
344
}
 
345
 
 
346
const IdentityList Preferences::identityList() { return self()->mIdentityList; }
 
347
 
 
348
void Preferences::setIdentityList(const IdentityList& list)
 
349
{
 
350
    self()->mIdentityList.clear();
 
351
    self()->mIdentityList = list;
 
352
}
 
353
 
 
354
const IdentityPtr Preferences::identityByName(const QString& name)
 
355
{
 
356
    QList<IdentityPtr> identities = identityList();
 
357
    QList<IdentityPtr>::iterator it = identities.begin();
 
358
 
 
359
    while(it != identities.end())
 
360
    {
 
361
        if((*it)->getName() == name)
 
362
        {
 
363
            return (*it);
 
364
        }
 
365
 
 
366
        ++it;
 
367
    }
 
368
 
 
369
    // no self()->matching identity found, return default identity
 
370
    return identities.first();
 
371
}
 
372
 
 
373
const IdentityPtr Preferences::identityById(int id)
 
374
{
 
375
    QList<IdentityPtr> identList = identityList();
 
376
    for(QList<IdentityPtr>::iterator it = identList.begin(); it != identList.end(); ++it)
 
377
    {
 
378
        if((*it)->id() == id)
 
379
        {
 
380
            return (*it);
 
381
        }
 
382
    }
 
383
 
 
384
    return identList.first();
 
385
}
 
386
 
 
387
QStringList Preferences::defaultAliasList()
 
388
{
 
389
    // Auto-alias scripts
 
390
    const QStringList scripts = KGlobal::dirs()->findAllResources("data","konversation/scripts/*");
 
391
    QFileInfo* fileInfo = new QFileInfo();
 
392
    QStringList aliasList;
 
393
    QString newAlias;
 
394
 
 
395
    for (QStringList::ConstIterator it = scripts.constBegin(); it != scripts.constEnd(); ++it)
 
396
    {
 
397
        fileInfo->setFile(*it);
 
398
        if (fileInfo->isExecutable())
 
399
        {
 
400
            newAlias = (*it).section('/',-1)+' '+"/exec "+(*it).section('/', -1 );
 
401
            aliasList.append(newAlias);
 
402
 
 
403
            // FIXME: Historically, defaultAliasList() is primarily used to dynamically
 
404
            // compile a list of installed scripts and generate appropriate aliases for
 
405
            // them. It's not only used when the alias preferences are reset or initia-
 
406
            // lized, but also on application start. The following crudely adds two
 
407
            // aliases when the 'media' script is found, to provide easy access to its
 
408
            // capability to differentiate  between audio and video media. This method
 
409
            // needs at the very least to be split up in two, or scripts may in the
 
410
            // future determine what aliases they want to add.
 
411
            if ((*it).section('/',-1) == "media")
 
412
            {
 
413
                aliasList.append("audio /exec media audio");
 
414
                aliasList.append("video /exec media video");
 
415
            }
 
416
        }
 
417
    }
 
418
 
 
419
    delete fileInfo;
 
420
 
 
421
    return aliasList;
 
422
}
 
423
 
 
424
 
 
425
const QString Preferences::realName() { return self()->mIdentityList[0]->getRealName(); }
 
426
void Preferences::setRealName(const QString &name) { self()->mIdentityList[0]->setRealName(name); }
 
427
 
 
428
const QString Preferences::ident() { return self()->mIdentityList[0]->getIdent(); }
 
429
void Preferences::setIdent(const QString &ident) { self()->mIdentityList[0]->setIdent(ident); }
 
430
 
 
431
const QString Preferences::partReason() { return self()->mIdentityList[0]->getPartReason(); }
 
432
void Preferences::setPartReason(const QString &newReason) { self()->mIdentityList[0]->setPartReason(newReason); }
 
433
 
 
434
const QString Preferences::kickReason() { return self()->mIdentityList[0]->getKickReason(); }
 
435
void Preferences::setKickReason(const QString &newReason) { self()->mIdentityList[0]->setKickReason(newReason); }
 
436
 
 
437
bool Preferences::showAwayMessage() { return self()->mIdentityList[0]->getShowAwayMessage(); }
 
438
void Preferences::setShowAwayMessage(bool state) { self()->mIdentityList[0]->setShowAwayMessage(state); }
 
439
 
 
440
const QString Preferences::awayMessage() { return self()->mIdentityList[0]->getAwayMessage(); }
 
441
void Preferences::setAwayMessage(const QString &newMessage) { self()->mIdentityList[0]->setAwayMessage(newMessage); }
 
442
const QString Preferences::unAwayMessage() { return self()->mIdentityList[0]->getReturnMessage(); }
 
443
void Preferences::setUnAwayMessage(const QString &newMessage) { self()->mIdentityList[0]->setReturnMessage(newMessage); }
 
444
 
 
445
void Preferences::clearIgnoreList() { qDeleteAll(self()->mIgnoreList); self()->mIgnoreList.clear(); }
 
446
const QList<Ignore*> Preferences::ignoreList() { return self()->mIgnoreList; }
 
447
 
 
448
const QString Preferences::nickname(int index) { return self()->mIdentityList[0]->getNickname(index); }
 
449
const QStringList Preferences::nicknameList() { return self()->mIdentityList[0]->getNicknameList(); }
 
450
void Preferences::setNickname(int index,const QString &newName) { self()->mIdentityList[0]->setNickname(index,newName); }
 
451
void Preferences::setNicknameList(const QStringList &newList) { self()->mIdentityList[0]->setNicknameList(newList); }
 
452
 
 
453
void Preferences::setShowTrayIcon(bool state)
 
454
{
 
455
    self()->PreferencesBase::setShowTrayIcon(state);
 
456
    emit self()->updateTrayIcon();
 
457
}
 
458
 
 
459
void Preferences::setTrayNotify(bool state)
 
460
{
 
461
    self()->PreferencesBase::setTrayNotify(state);
 
462
    emit self()->updateTrayIcon();
 
463
}
 
464
 
 
465
 
 
466
void Preferences::setAutoUserhost(bool state)
 
467
{
 
468
    self()->PreferencesBase::setAutoUserhost(state);
 
469
}
 
470
 
 
471
bool Preferences::dialogFlag(const QString& flagName)
 
472
{
 
473
    KConfigGroup config(KGlobal::config()->group("Notification self()->Messages"));
 
474
 
 
475
    if (!config.readEntry(flagName).isEmpty())
 
476
        return false;
 
477
    else
 
478
        return true;
 
479
}
 
480
 
 
481
void Preferences::setDialogFlag(const QString& flagName,bool state)
 
482
{
 
483
    KConfigGroup config(KGlobal::config()->group("Notification self()->Messages"));
 
484
 
 
485
    if (state)
 
486
        config.deleteEntry(flagName);
 
487
    else
 
488
    {
 
489
        if (config.readEntry(flagName).isEmpty())
 
490
            config.writeEntry(flagName,"no");
 
491
    }
 
492
 
 
493
    config.sync();
 
494
}
 
495
 
 
496
 
 
497
// Channel Encodings
 
498
const QString Preferences::channelEncoding(const QString& server,const QString& channel)
 
499
{
 
500
    //check all matching server's encodings
 
501
    //TODO when we rewrite dbus, allow for multiple encodings to be returned
 
502
    //for true 'duplicity compatibility'
 
503
    QList<int> serverIds = serverGroupIdsByName(server);
 
504
    QString codec;
 
505
    if(serverIds.count() > 1)
 
506
    {
 
507
        for (int i=0; i < serverIds.count(); i++)
 
508
        {
 
509
            codec = channelEncoding(serverIds.at(i),channel);
 
510
            if(!codec.isEmpty())
 
511
                return codec;
 
512
        }
 
513
        return QString();
 
514
    }
 
515
    else
 
516
        return channelEncoding(serverIds.first(),channel);
 
517
}
 
518
 
 
519
const QString Preferences::channelEncoding(int serverGroupId,const QString& channel)
 
520
{
 
521
    if(self()->mChannelEncodingsMap.contains(serverGroupId))
 
522
        if(self()->mChannelEncodingsMap[serverGroupId].contains(channel.toLower()))
 
523
            return self()->mChannelEncodingsMap[serverGroupId][channel.toLower()];
 
524
    return QString();
 
525
}
 
526
 
 
527
void Preferences::setChannelEncoding(const QString& server,const QString& channel,const QString& encoding)
 
528
{
 
529
    //set channel encoding for ALL matching servergroups
 
530
    QList<int> serverIds = serverGroupIdsByName(server);
 
531
    if(serverIds.count() > 1)
 
532
    {
 
533
        for(int i=0; i < serverIds.count(); i++)
 
534
            setChannelEncoding(serverIds.at(i),channel,encoding);
 
535
    }
 
536
    else
 
537
        setChannelEncoding(serverIds.first(),channel,encoding);
 
538
}
 
539
 
 
540
void Preferences::setChannelEncoding(int serverGroupId,const QString& channel,const QString& encoding)
 
541
{
 
542
    self()->mChannelEncodingsMap[serverGroupId][channel.toLower()]=encoding;
 
543
}
 
544
 
 
545
const QList<int> Preferences::channelEncodingsServerGroupIdList()
 
546
{
 
547
    return self()->mChannelEncodingsMap.keys();
 
548
}
 
549
 
 
550
const QStringList Preferences::channelEncodingsChannelList(int serverGroupId)
 
551
{
 
552
    return self()->mChannelEncodingsMap[serverGroupId].keys();
 
553
}
 
554
 
 
555
const QString Preferences::defaultNicknameSortingOrder()
 
556
{
 
557
  return "qpohv-";
 
558
}
 
559
 
 
560
// override to add %u if needed
 
561
QString Preferences::webBrowserCmd()
 
562
{
 
563
  // add %u to command if it's not in there
 
564
  QString cmd=self()->mWebBrowserCmd;
 
565
  if (!cmd.contains("%u"))
 
566
      cmd += " %u";
 
567
  return cmd;
 
568
}
 
569
 
 
570
void Preferences::saveColumnState(QTreeView *treeView, QString name)
 
571
{
 
572
    KConfigGroup group(KGlobal::config(), name);
 
573
 
 
574
    QList<int> columnWidths;
 
575
    for (int i = 0; i < treeView->header()->count(); ++i)
 
576
        columnWidths.append(treeView->columnWidth(i));
 
577
    // save column widths
 
578
    group.writeEntry("ColumnWidths", columnWidths);
 
579
    group.writeEntry("ColumnSorted", treeView->header()->sortIndicatorSection());
 
580
    group.writeEntry("ColumnSortDescending", treeView->header()->sortIndicatorOrder() == Qt::DescendingOrder ? true : false );
 
581
}
 
582
 
 
583
void Preferences::restoreColumnState(QTreeView *treeView, QString name)
 
584
{
 
585
    KConfigGroup group(KGlobal::config(), name);
 
586
 
 
587
    QList<int> columnWidths = group.readEntry("ColumnWidths", QList<int>());
 
588
    for (int i = 0; i < columnWidths.count(); ++i)
 
589
        if (columnWidths.at(i))
 
590
            treeView->setColumnWidth(i, columnWidths.at(i));
 
591
 
 
592
    if (group.readEntry("ColumnSortDescending", false))
 
593
        treeView->header()->setSortIndicator(group.readEntry("ColumnSorted", 0), Qt::DescendingOrder);
 
594
    else
 
595
        treeView->header()->setSortIndicator(group.readEntry("ColumnSorted", 0), Qt::AscendingOrder);
 
596
}
 
597
 
 
598
#include "preferences.moc"