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

« back to all changes in this revision

Viewing changes to lib/DictEdict/dictfilefieldselector.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 library is free software; you can redistribute it and/or             *
 
6
 * modify it under the terms of the GNU Library General Public               *
 
7
 * License as published by the Free Software Foundation; either              *
 
8
 * version 2 of the License, or (at your option) any later version.          *
 
9
 *                                                                           *
 
10
 * This library 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 GNU         *
 
13
 * Library General Public License for more details.                          *
 
14
 *                                                                           *
 
15
 * You should have received a copy of the GNU Library General Public License *
 
16
 * along with this library; see the file COPYING.LIB.  If not, write to      *
 
17
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,      *
 
18
 * Boston, MA 02110-1301, USA.                                               *
 
19
 *****************************************************************************/
 
20
 
 
21
#include "dictfilefieldselector.h"
 
22
 
 
23
#include <KActionSelector>
 
24
#include <KConfigSkeleton>
 
25
#include <KLocale>
 
26
 
 
27
#include <QFrame>
 
28
#include <QLayout>
 
29
#include <QListWidget>
 
30
#include <QString>
 
31
#include <QStringList>
 
32
#include <QVBoxLayout>
 
33
#include <QWidget>
 
34
 
 
35
DictFileFieldSelector::DictFileFieldSelector( KConfigSkeleton *config,
 
36
                       const QString &dictionaryTypeName, QWidget *parent )
 
37
: DictionaryPreferenceDialog( parent, dictionaryTypeName )
 
38
, m_dictName( dictionaryTypeName )
 
39
{
 
40
  QVBoxLayout *newTabLayout = new QVBoxLayout();
 
41
 
 
42
  //Make selection box
 
43
  m_listView = new KActionSelector();
 
44
  m_listView->setAvailableLabel( i18n( "&Available Fields:" ) );
 
45
  newTabLayout->addWidget( m_listView );
 
46
 
 
47
  //Add layout to our widget
 
48
  this->setLayout( newTabLayout );
 
49
 
 
50
  //Create Default List
 
51
  m_completeList.append( "--NewLine--" );
 
52
  m_completeList.append( "--NewLine--" );
 
53
  m_completeList.append( "--NewLine--" );
 
54
  m_completeList.append( "Word/Kanji" );
 
55
  m_completeList.append( "Reading" );
 
56
  m_completeList.append( "Meaning" );
 
57
 
 
58
  //Make connections
 
59
  connect( m_listView, SIGNAL( added( QListWidgetItem* ) )
 
60
             , this,   SLOT( settingChanged() ) );
 
61
  connect( m_listView, SIGNAL( removed( QListWidgetItem* ) ),
 
62
               this,   SLOT( settingChanged() ) );
 
63
  connect( m_listView, SIGNAL( movedUp( QListWidgetItem* ) ),
 
64
               this,   SLOT( settingChanged() ) );
 
65
  connect( m_listView, SIGNAL( movedDown( QListWidgetItem* ) ),
 
66
               this,   SLOT( settingChanged() ) );
 
67
 
 
68
  m_config = config;
 
69
  updateWidgets();
 
70
}
 
71
 
 
72
DictFileFieldSelector::~DictFileFieldSelector()
 
73
{
 
74
}
 
75
 
 
76
void DictFileFieldSelector::addAvailable( const QStringList &list )
 
77
{
 
78
  m_completeList += list;
 
79
  updateWidgets();
 
80
}
 
81
 
 
82
void DictFileFieldSelector::readFromPrefs()
 
83
{
 
84
  QStringList selectedList;
 
85
 
 
86
  m_config->setCurrentGroup( "dicts_" + m_dictName );
 
87
 
 
88
  QStringList actionList = m_completeList;
 
89
  QString itemName = m_dictName + "__displayFields";
 
90
  KConfigSkeletonItem *item = m_config->findItem( itemName );
 
91
  if( item != NULL )
 
92
  {
 
93
    selectedList = item->property().toStringList();
 
94
  }
 
95
  else
 
96
  {
 
97
    //it's not currently in the preferences list
 
98
    m_config->addItem(  new KConfigSkeleton::ItemStringList(  "dicts_" + m_dictName
 
99
                                                          , itemName
 
100
                                                          , *new QStringList() )
 
101
                    , itemName );
 
102
    m_config->readConfig();
 
103
    selectedList = m_config->findItem( itemName )->property().toStringList();
 
104
  }
 
105
 
 
106
  foreach( const QString &it, selectedList)
 
107
  {
 
108
    actionList.removeAt( actionList.indexOf( it ) ); //don't just use remove()... will remove all
 
109
  }
 
110
 
 
111
  m_listView->availableListWidget()->clear();
 
112
  m_listView->selectedListWidget()->clear();
 
113
  m_listView->availableListWidget()->addItems( actionList );
 
114
  m_listView->selectedListWidget()->addItems( selectedList );
 
115
}
 
116
 
 
117
void DictFileFieldSelector::setAvailable( const QStringList &list )
 
118
{
 
119
  m_completeList = list;
 
120
  updateWidgets();
 
121
}
 
122
 
 
123
void DictFileFieldSelector::setDefaultList( const QStringList &list )
 
124
{
 
125
  m_defaultList = list;
 
126
}
 
127
 
 
128
void DictFileFieldSelector::settingChanged()
 
129
{
 
130
  emit widgetChanged();
 
131
}
 
132
 
 
133
void DictFileFieldSelector::updateSettings()
 
134
{
 
135
  writeToPrefs();
 
136
}
 
137
 
 
138
void DictFileFieldSelector::updateWidgets()
 
139
{
 
140
  readFromPrefs();
 
141
}
 
142
 
 
143
void DictFileFieldSelector::updateWidgetsDefault()
 
144
{
 
145
}
 
146
 
 
147
void DictFileFieldSelector::writeToPrefs()
 
148
{
 
149
  m_config->setCurrentGroup( "dicts_" + m_dictName );
 
150
  QStringList theList;
 
151
  KConfigSkeletonItem *item;
 
152
  QString itemName;
 
153
 
 
154
  for( int i = 0; i < m_listView->selectedListWidget()->count(); i++ )
 
155
  {
 
156
    theList.append( m_listView->selectedListWidget()->item( i )->text() );
 
157
  }
 
158
 
 
159
  itemName = m_dictName + "__displayFields";
 
160
  item = m_config->findItem( itemName );
 
161
  if( ! item )
 
162
  {
 
163
    item = new KConfigSkeleton::ItemStringList( "dicts_" + m_dictName, itemName, *new QStringList() );
 
164
    m_config->addItem( item, itemName );
 
165
  }
 
166
  item->setProperty( theList );
 
167
 
 
168
  m_config->writeConfig();
 
169
}
 
170
 
 
171
#include "dictfilefieldselector.moc"