1
/*****************************************************************************
2
* This file is part of Kiten, a KDE Japanese Reference Tool... *
3
* Copyright (C) 2005 Paul Temple <paul.temple@gmx.net> *
4
* Copyright (C) 2006 Joseph Kerian <jkerian@gmail.com> *
5
* Copyright (C) 2006 Eric Kjeldergaard <kjelderg@gmail.com> *
7
* This program is free software; you can redistribute it and/or modify *
8
* it under the terms of the GNU General Public License as published by *
9
* the Free Software Foundation; either version 2 of the License, or *
10
* (at your option) any later version. *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program; if not, write to the Free Software *
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 *
21
*****************************************************************************/
23
#include "configdictionaryselector.h"
25
#include <KConfigSkeleton>
27
#include <KFileDialog>
29
#include <QStringList>
30
#include <QTableWidget>
32
ConfigDictionarySelector::ConfigDictionarySelector( const QString &dictionaryName,
33
QWidget *parent, KConfigSkeleton *config,Qt::WFlags f )
36
_dictName = dictionaryName;
39
connect( addButton, SIGNAL( clicked() ), this, SLOT( addDictSlot() ) );
40
connect( delButton, SIGNAL( clicked() ), this, SLOT( deleteDictSlot() ) );
41
__useGlobal->setObjectName( QString( "kcfg_" + _dictName + "__useGlobal" ) );
44
//Read from preferences to the active list
45
void ConfigDictionarySelector::updateWidgets()
49
_config->setCurrentGroup( "dicts_" + _dictName );
50
KConfigSkeletonItem *item = _config->findItem( _dictName + "__NAMES" );
53
names = item->property().toStringList();
56
foreach( const QString &it, names )
58
QString name = _dictName + '_' + it;
59
if ( ! _config->findItem( name ) )
61
_config->addItem( new KConfigSkeleton::ItemString( _dictName, it, *new QString() ), name );
62
//Don't touch the *new QString()... that's a reference for a reason... stupid KDE
66
_config->readConfig();
69
foreach( const QString &it, names )
71
QStringList newRow( it );
72
newRow << _config->findItem( _dictName + '_' + it )->property().toString();
73
(void) new QTreeWidgetItem( fileList, newRow );
77
void ConfigDictionarySelector::updateSettings()
81
KConfigGroup group = _config->config()->group( "dicts_" + _dictName.toLower() );
83
for( int i = 0; i < fileList->topLevelItemCount(); i++ )
85
QTreeWidgetItem *it = fileList->topLevelItem( i );
86
QString dictionaryName = it->text( 0 );
87
QString dictionaryPath = it->text( 1 );
88
names.append( dictionaryName );
90
if ( ! group.hasKey( dictionaryName ) )
92
KConfigSkeletonItem *item = new KConfigSkeleton::ItemPath( group.name()
93
, dictionaryName, *new QString() );
94
_config->addItem( item, dictionaryName );
96
group.writeEntry( dictionaryName, dictionaryPath );
99
//This feels distinctly hackish to me... :(
100
_config->findItem( _dictName + "__NAMES" )->setProperty( names );
101
_config->writeConfig();
104
void ConfigDictionarySelector::updateWidgetsDefault()
106
// no default for custom edict list or
107
// should we really delete all items in the list?
110
bool ConfigDictionarySelector::isDefault()
112
// no default for custom edict list or
113
// should we really delete all items in the list?
117
bool ConfigDictionarySelector::hasChanged()
122
void ConfigDictionarySelector::addDictSlot()
124
QTreeWidgetItem *item = fileList->topLevelItem( 0 );
126
QString filename = KFileDialog::getOpenFileName(
127
item ? QFileInfo( item->text( 1 ) ).absolutePath().append( "/" )
129
QString name = QFileInfo( filename ).fileName();
130
if( filename.isNull() )
133
QStringList newRow( name );
135
(void) new QTreeWidgetItem( fileList, newRow );
137
emit widgetChanged();
140
void ConfigDictionarySelector::deleteDictSlot()
142
foreach( QTreeWidgetItem *file, fileList->selectedItems() )
151
emit widgetChanged();
155
#include "configdictionaryselector.moc"