1
/*****************************************************************************
2
* This file is part of Kiten, a KDE Japanese Reference Tool *
3
* Copyright (C) 2006 Joseph Kerian <jkerian@gmail.com> *
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. *
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. *
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
*****************************************************************************/
21
#include "dictfilefieldselector.h"
23
#include <KActionSelector>
24
#include <KConfigSkeleton>
29
#include <QListWidget>
31
#include <QStringList>
32
#include <QVBoxLayout>
35
DictFileFieldSelector::DictFileFieldSelector( KConfigSkeleton *config,
36
const QString &dictionaryTypeName, QWidget *parent )
37
: DictionaryPreferenceDialog( parent, dictionaryTypeName )
38
, m_dictName( dictionaryTypeName )
40
QVBoxLayout *newTabLayout = new QVBoxLayout();
43
m_listView = new KActionSelector();
44
m_listView->setAvailableLabel( i18n( "&Available Fields:" ) );
45
newTabLayout->addWidget( m_listView );
47
//Add layout to our widget
48
this->setLayout( newTabLayout );
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" );
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() ) );
72
DictFileFieldSelector::~DictFileFieldSelector()
76
void DictFileFieldSelector::addAvailable( const QStringList &list )
78
m_completeList += list;
82
void DictFileFieldSelector::readFromPrefs()
84
QStringList selectedList;
86
m_config->setCurrentGroup( "dicts_" + m_dictName );
88
QStringList actionList = m_completeList;
89
QString itemName = m_dictName + "__displayFields";
90
KConfigSkeletonItem *item = m_config->findItem( itemName );
93
selectedList = item->property().toStringList();
97
//it's not currently in the preferences list
98
m_config->addItem( new KConfigSkeleton::ItemStringList( "dicts_" + m_dictName
100
, *new QStringList() )
102
m_config->readConfig();
103
selectedList = m_config->findItem( itemName )->property().toStringList();
106
foreach( const QString &it, selectedList)
108
actionList.removeAt( actionList.indexOf( it ) ); //don't just use remove()... will remove all
111
m_listView->availableListWidget()->clear();
112
m_listView->selectedListWidget()->clear();
113
m_listView->availableListWidget()->addItems( actionList );
114
m_listView->selectedListWidget()->addItems( selectedList );
117
void DictFileFieldSelector::setAvailable( const QStringList &list )
119
m_completeList = list;
123
void DictFileFieldSelector::setDefaultList( const QStringList &list )
125
m_defaultList = list;
128
void DictFileFieldSelector::settingChanged()
130
emit widgetChanged();
133
void DictFileFieldSelector::updateSettings()
138
void DictFileFieldSelector::updateWidgets()
143
void DictFileFieldSelector::updateWidgetsDefault()
147
void DictFileFieldSelector::writeToPrefs()
149
m_config->setCurrentGroup( "dicts_" + m_dictName );
151
KConfigSkeletonItem *item;
154
for( int i = 0; i < m_listView->selectedListWidget()->count(); i++ )
156
theList.append( m_listView->selectedListWidget()->item( i )->text() );
159
itemName = m_dictName + "__displayFields";
160
item = m_config->findItem( itemName );
163
item = new KConfigSkeleton::ItemStringList( "dicts_" + m_dictName, itemName, *new QStringList() );
164
m_config->addItem( item, itemName );
166
item->setProperty( theList );
168
m_config->writeConfig();
171
#include "dictfilefieldselector.moc"