summaryrefslogtreecommitdiffstats
path: root/konversation/src/nicklistbehavior_preferences.cpp
blob: 8bb3bdebf58d4be93be08b2e26b91f00ba9d363d (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
/*
  This program is free software; you can redistribute it and/or 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) 2006 Dario Abatianni <eisfuchs@tigress.com>
  Copyright (C) 2006 John Tapsell <johnflux@gmail.com>
  Copyright (C) 2006 Eike Hein <hein@kde.org>
*/

#include "nicklistbehavior_preferences.h"
#include "valuelistviewitem.h"
#include "config/preferences.h"

#include <qheader.h>

#include <kapplication.h>
#include <klocale.h>


NicklistBehavior_Config::NicklistBehavior_Config(QWidget *parent, const char *name)
 : NicklistBehavior_ConfigUI(parent, name)
{
  // get page widget and populate listview
  loadSettings();

  // make items react to drag & drop
  sortOrder->setSorting(-1,false);
  sortOrder->header()->setMovingEnabled(false);

  connect(sortOrder,SIGNAL (moved()),this,SIGNAL (modified()) );
}

NicklistBehavior_Config::~NicklistBehavior_Config()
{
}

void NicklistBehavior_Config::restorePageToDefaults()
{
  setNickList(Preferences::defaultNicknameSortingOrder());
}

void NicklistBehavior_Config::loadSettings()
{
  // get sorting order string from preferences
  setNickList(Preferences::sortOrder());
  m_oldSortingOrder=currentSortingOrder();
}

void NicklistBehavior_Config::setNickList(const QString &sortingOrder)
{
  sortOrder->clear();
  // loop through the sorting order string, insert the matching descriptions in reverse order
  // to keep the correct sorting
  for(unsigned int index=sortingOrder.length();index!=0;index--)
  {
    // get next mode char
    QChar mode=sortingOrder[index-1];
    // find appropriate description
    if(mode=='-') new KListViewItem(sortOrder,mode,i18n("Normal Users"));
    if(mode=='v') new KListViewItem(sortOrder,mode,i18n("Voice (+v)"));
    if(mode=='h') new KListViewItem(sortOrder,mode,i18n("Halfops (+h)"));
    if(mode=='o') new KListViewItem(sortOrder,mode,i18n("Operators (+o)"));
    if(mode=='p') new KListViewItem(sortOrder,mode,i18n("Channel Admins (+p)"));
    if(mode=='q') new KListViewItem(sortOrder,mode,i18n("Channel Owners (+q)"));
  }
}

QString NicklistBehavior_Config::currentSortingOrder()
{
  // get the uppermost entry of the sorting list
  QListViewItem* item=sortOrder->firstChild();
  // prepare the new sorting order string
  QString currentSortingOrder;
  // iterate through all items of the listview
  while(item)
  {
    // add mode char to the sorting order string
    currentSortingOrder+=item->text(0);
    // go to next item in the listview
    item=item->itemBelow();
  } // while

  return currentSortingOrder;
}

// save settings permanently
void NicklistBehavior_Config::saveSettings()
{
  // get the current sorting order
  QString newSortingOrder=currentSortingOrder();

  // update sorting order on in-memory preferences
  Preferences::setSortOrder(newSortingOrder);

  // save current sorting order as a reference to hasChanged()
  m_oldSortingOrder=currentSortingOrder();
}

bool NicklistBehavior_Config::hasChanged()
{
  return(m_oldSortingOrder!=currentSortingOrder());
}

#include "nicklistbehavior_preferences.moc"