~ubuntu-branches/ubuntu/quantal/kiten/quantal-proposed

« back to all changes in this revision

Viewing changes to app/configsortingpage.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2011-07-10 11:23:47 UTC
  • Revision ID: james.westby@ubuntu.com-20110710112347-ykfhtvam3kgssspo
Tags: upstream-4.6.90+repack
ImportĀ upstreamĀ versionĀ 4.6.90+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 * This file is part of Kiten, a KDE Japanese Reference Tool...              *
 
3
 * Copyright (C) 2006 Joseph Kerian <jkerian@gmail.com>                      *
 
4
 *                                                                           *
 
5
 * This program is free software; you can redistribute it and/or modify      *
 
6
 * it under the terms of the GNU General Public License as published by      *
 
7
 * the Free Software Foundation; either version 2 of the License, or         *
 
8
 * (at your option) any later version.                                       *
 
9
 *                                                                           *
 
10
 * This program is distributed in the hope that it will be useful,           *
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
 
13
 * GNU General Public License for more details.                              *
 
14
 *                                                                           *
 
15
 * You should have received a copy of the GNU General Public License         *
 
16
 * along with this program; if not, write to the Free Software               *
 
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 *
 
18
 * USA                                                                       *
 
19
 *****************************************************************************/
 
20
 
 
21
#include "configsortingpage.h"
 
22
 
 
23
#include <QCheckBox>
 
24
#include <QListWidget>
 
25
#include <QMap>
 
26
#include <QStringList>
 
27
 
 
28
#include "dictionarymanager.h"
 
29
 
 
30
#include "kitenconfig.h"
 
31
 
 
32
ConfigSortingPage::ConfigSortingPage(  QWidget *parent
 
33
                                     , KitenConfigSkeleton *config
 
34
                                     ,Qt::WFlags f )
 
35
: QWidget( parent, f )
 
36
, _config( config )
 
37
{
 
38
  setupUi( this );
 
39
  _dictNames = DictionaryManager::listDictFileTypes();
 
40
 
 
41
  //Setup the relationship between the checkbox and the dictionary sortlist
 
42
  connect( kcfg_dictionary_enable, SIGNAL( clicked( bool ) ),
 
43
                 dictionary_order,   SLOT( setEnabled( bool ) ) );
 
44
  dictionary_order->setEnabled( _config->dictionary_enable() == "true" );
 
45
 
 
46
  _fields.append( "Word/Kanji" );
 
47
  _fields.append( "Meaning" );
 
48
  _fields.append( "Reading" );
 
49
  QList<QString> fieldListMap = DictionaryManager::generateExtendedFieldsList().keys();
 
50
  _fields += fieldListMap;
 
51
 
 
52
  //Make the connections to alert the main dialog when things change
 
53
  connect( dictionary_order, SIGNAL( added( QListWidgetItem* ) ),
 
54
                       this, SIGNAL( widgetChanged() ) );
 
55
  connect( dictionary_order, SIGNAL( removed( QListWidgetItem* ) ),
 
56
                       this, SIGNAL( widgetChanged() ) );
 
57
  connect( dictionary_order, SIGNAL( movedUp( QListWidgetItem* ) ),
 
58
                       this, SIGNAL( widgetChanged() ) );
 
59
  connect( dictionary_order, SIGNAL( movedDown( QListWidgetItem* ) ),
 
60
                       this, SIGNAL( widgetChanged() ) );
 
61
 
 
62
  connect( field_order, SIGNAL( added ( QListWidgetItem* ) ),
 
63
                  this, SIGNAL( widgetChanged() ) );
 
64
  connect( field_order, SIGNAL( removed( QListWidgetItem* ) ),
 
65
                  this, SIGNAL( widgetChanged() ) );
 
66
  connect( field_order, SIGNAL( movedUp( QListWidgetItem* ) ),
 
67
                  this, SIGNAL( widgetChanged() ) );
 
68
  connect( field_order, SIGNAL( movedDown( QListWidgetItem* ) ),
 
69
                  this, SIGNAL( widgetChanged() ) );
 
70
}
 
71
 
 
72
//Read from preferences and set widgets
 
73
void ConfigSortingPage::updateWidgets()
 
74
{
 
75
  QStringList selectedDicts  = _config->dictionary_sortlist();
 
76
  QStringList selectedFields = _config->field_sortlist();
 
77
 
 
78
  QStringList availDicts  = _dictNames;
 
79
  QStringList availFields = _fields;
 
80
 
 
81
  foreach( const QString &dict, selectedDicts )
 
82
  {
 
83
    availDicts.removeAll( dict );
 
84
  }
 
85
 
 
86
  foreach( const QString &field, selectedFields )
 
87
  {
 
88
    availDicts.removeAll( field );
 
89
  }
 
90
 
 
91
  dictionary_order->availableListWidget()->clear();
 
92
  dictionary_order->availableListWidget()->addItems(availDicts);
 
93
  dictionary_order->selectedListWidget()->clear();
 
94
  dictionary_order->selectedListWidget()->addItems(selectedDicts);
 
95
 
 
96
  field_order->availableListWidget()->clear();
 
97
  field_order->availableListWidget()->addItems(availFields);
 
98
  field_order->selectedListWidget()->clear();
 
99
  field_order->selectedListWidget()->addItems(selectedFields);
 
100
}
 
101
 
 
102
void ConfigSortingPage::updateSettings()
 
103
{
 
104
  QStringList list;
 
105
  for( int i = 0; i < dictionary_order->selectedListWidget()->count(); i++ )
 
106
  {
 
107
    list.append( dictionary_order->selectedListWidget()->item( i )->text() );
 
108
  }
 
109
  _config->setDictionary_sortlist( list );
 
110
 
 
111
  list.clear();
 
112
  for( int i = 0; i < field_order->selectedListWidget()->count(); i++ )
 
113
  {
 
114
    list.append( field_order->selectedListWidget()->item( i )->text() );
 
115
  }
 
116
  _config->setField_sortlist( list );
 
117
}
 
118
 
 
119
void ConfigSortingPage::updateWidgetsDefault()
 
120
{
 
121
  //No Default?
 
122
}
 
123
 
 
124
bool ConfigSortingPage::isDefault()
 
125
{
 
126
  return true;
 
127
}
 
128
 
 
129
bool ConfigSortingPage::hasChanged()
 
130
{
 
131
  return false;
 
132
}
 
133
 
 
134
#include "configsortingpage.moc"