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

« back to all changes in this revision

Viewing changes to app/configdictionaryselector.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) 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>                 *
 
6
 *                                                                           *
 
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.                                       *
 
11
 *                                                                           *
 
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.                              *
 
16
 *                                                                           *
 
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 *
 
20
 * USA                                                                       *
 
21
 *****************************************************************************/
 
22
 
 
23
#include "configdictionaryselector.h"
 
24
 
 
25
#include <KConfigSkeleton>
 
26
#include <KDebug>
 
27
#include <KFileDialog>
 
28
 
 
29
#include <QStringList>
 
30
#include <QTableWidget>
 
31
 
 
32
ConfigDictionarySelector::ConfigDictionarySelector( const QString &dictionaryName,
 
33
  QWidget *parent, KConfigSkeleton *config,Qt::WFlags f )
 
34
{
 
35
  setupUi( this );
 
36
  _dictName = dictionaryName;
 
37
  _config = config;
 
38
 
 
39
  connect( addButton, SIGNAL( clicked() ), this, SLOT( addDictSlot() ) );
 
40
  connect( delButton, SIGNAL( clicked() ), this, SLOT( deleteDictSlot() ) );
 
41
  __useGlobal->setObjectName( QString( "kcfg_" + _dictName + "__useGlobal" ) );
 
42
}
 
43
 
 
44
//Read from preferences to the active list
 
45
void ConfigDictionarySelector::updateWidgets()
 
46
{
 
47
  QStringList names;
 
48
 
 
49
  _config->setCurrentGroup( "dicts_" + _dictName );
 
50
  KConfigSkeletonItem *item = _config->findItem( _dictName + "__NAMES" );
 
51
  if( item != NULL )
 
52
  {
 
53
    names = item->property().toStringList();
 
54
  }
 
55
 
 
56
  foreach( const QString &it, names )
 
57
  {
 
58
    QString name = _dictName + '_' + it;
 
59
    if ( ! _config->findItem( name ) )
 
60
    {
 
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
 
63
    }
 
64
  }
 
65
 
 
66
  _config->readConfig();
 
67
  fileList->clear();
 
68
 
 
69
  foreach( const QString &it, names )
 
70
  {
 
71
    QStringList newRow( it );
 
72
    newRow << _config->findItem( _dictName + '_' + it )->property().toString();
 
73
    (void) new QTreeWidgetItem( fileList, newRow );
 
74
  }
 
75
}
 
76
 
 
77
void ConfigDictionarySelector::updateSettings()
 
78
{
 
79
  QStringList names;
 
80
 
 
81
  KConfigGroup group = _config->config()->group( "dicts_" + _dictName.toLower() );
 
82
 
 
83
  for( int i = 0; i < fileList->topLevelItemCount(); i++ )
 
84
  {
 
85
    QTreeWidgetItem *it = fileList->topLevelItem( i );
 
86
    QString dictionaryName = it->text( 0 );
 
87
    QString dictionaryPath = it->text( 1 );
 
88
    names.append( dictionaryName );
 
89
 
 
90
    if ( ! group.hasKey( dictionaryName ) )
 
91
    {
 
92
      KConfigSkeletonItem *item = new KConfigSkeleton::ItemPath( group.name()
 
93
                                                , dictionaryName, *new QString() );
 
94
      _config->addItem( item, dictionaryName );
 
95
    }
 
96
    group.writeEntry( dictionaryName, dictionaryPath );
 
97
  }
 
98
 
 
99
  //This feels distinctly hackish to me... :(
 
100
  _config->findItem( _dictName + "__NAMES" )->setProperty( names );
 
101
  _config->writeConfig();
 
102
}
 
103
 
 
104
void ConfigDictionarySelector::updateWidgetsDefault()
 
105
{
 
106
  // no default for custom edict list or
 
107
  // should we really delete all items in the list?
 
108
}
 
109
 
 
110
bool ConfigDictionarySelector::isDefault()
 
111
{
 
112
  // no default for custom edict list or
 
113
  // should we really delete all items in the list?
 
114
  return true;
 
115
}
 
116
 
 
117
bool ConfigDictionarySelector::hasChanged()
 
118
{
 
119
  return false;
 
120
}
 
121
 
 
122
void ConfigDictionarySelector::addDictSlot()
 
123
{
 
124
  QTreeWidgetItem *item = fileList->topLevelItem( 0 );
 
125
 
 
126
  QString filename = KFileDialog::getOpenFileName(
 
127
                  item ? QFileInfo( item->text( 1 ) ).absolutePath().append( "/" )
 
128
                  : QString() );
 
129
  QString name = QFileInfo( filename ).fileName();
 
130
  if( filename.isNull() )
 
131
    return;
 
132
 
 
133
  QStringList newRow( name );
 
134
  newRow << filename;
 
135
  (void) new QTreeWidgetItem( fileList, newRow );
 
136
 
 
137
  emit widgetChanged();
 
138
}
 
139
 
 
140
void ConfigDictionarySelector::deleteDictSlot()
 
141
{
 
142
  foreach( QTreeWidgetItem *file, fileList->selectedItems() )
 
143
  {
 
144
    if ( ! file )
 
145
    {
 
146
      return;
 
147
    }
 
148
 
 
149
    delete file;
 
150
 
 
151
    emit widgetChanged();
 
152
  }
 
153
}
 
154
 
 
155
#include "configdictionaryselector.moc"