1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
/**
This file is part of Kiten, a KDE Japanese Reference Tool...
Copyright (C) 2005 Paul Temple <paul.temple@gmx.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
**/
#include <kdebug.h>
#include <klistview.h>
#include <kfiledialog.h>
#include <tqpushbutton.h>
#include <tqstringlist.h>
#include "configdictionaries.moc"
ConfigDictionaries::ConfigDictionaries(TQWidget *parent, const char* name, WFlags f) :
ConfigDictionariesBase(parent, name, f)
{
changed = false;
config = Config::self();
connect(delSelEdictButton, TQT_SIGNAL(clicked()), TQT_SLOT(slotDelSelEdict()));
connect(addEdictButton, TQT_SIGNAL(clicked()), TQT_SLOT(slotAddEdict()));
connect(delSelKanjidicButton, TQT_SIGNAL(clicked()), TQT_SLOT(slotDelSelKanjidic()));
connect(addKanjidicButton, TQT_SIGNAL(clicked()), TQT_SLOT(slotAddKanjidic()));
}
void ConfigDictionaries::updateWidgets()
{
readDictionaries();
}
void ConfigDictionaries::updateWidgetsDefault()
{
// no default for custom edict list or
// should we really delete all items in the list?
}
void ConfigDictionaries::updateSettings()
{
writeDictionaries();
}
bool ConfigDictionaries::hasChanged()
{
return changed;
}
bool ConfigDictionaries::isDefault()
{
// no default for custom edict list or
// should we really delete all items in the list?
return true;
}
void ConfigDictionaries::readDictionaries()
{
readDictionaryList("edict");
readDictionaryList("kanjidic");
}
void ConfigDictionaries::writeDictionaries()
{
writeDictionaryList("edict");
writeDictionaryList("kanjidic");
changed = false;
}
void ConfigDictionaries::readDictionaryList(const TQString& group)
{
KListView* list;
TQStringList names;
if (group == "edict")
{
list = edictList;
names = config->edict__NAMES();
}
else //if (group == "kanjidic")
{
list = kanjidicList;
names = config->kanjidic__NAMES();
}
TQStringList::Iterator it;
for (it = names.begin(); it != names.end(); ++it)
{
TQString name = group + "_" + *it;
if (!config->findItem(name))
config->addItem(new KConfigSkeleton::ItemString(group, *it, *new TQString()), name);
}
config->readConfig();
list->clear();
for (it = names.begin(); it != names.end(); ++it)
(void) new TQListViewItem(list, *it, config->findItem(group + "_" + *it)->property().asString());
}
void ConfigDictionaries::writeDictionaryList(const TQString& group)
{
KListView* list;
if (group == "edict")
list = edictList;
else //if (group == "kanjidic")
list = kanjidicList;
TQStringList names;
TQListViewItemIterator it(list);
for (; it.current(); ++it )
{
names.append(it.current()->text(0));
TQString name = group + "_" + it.current()->text(0);
KConfigSkeletonItem* item = config->findItem(name);
if (!item)
{
item = new KConfigSkeleton::ItemString(group, it.current()->text(0), *new TQString());
config->addItem(item, name);
}
item->setProperty(it.current()->text(1));
}
if (group == "edict")
config->setEdict__NAMES(names);
else //if (group == "kanjidic")
config->setKanjidic__NAMES(names);
config->writeConfig();
}
void ConfigDictionaries::slotAddEdict() { add(edictList); }
void ConfigDictionaries::slotDelSelEdict() { delSel(edictList); }
void ConfigDictionaries::slotAddKanjidic() { add(kanjidicList); }
void ConfigDictionaries::slotDelSelKanjidic() { delSel(kanjidicList); }
void ConfigDictionaries::add(KListView* list)
{
TQListViewItem *item = list->firstChild();
TQString filename = KFileDialog::getOpenFileName(item? TQFileInfo(item->text(1)).dirPath(true).append("/") : TQString::null);
TQString name = TQFileInfo(filename).fileName();
(void) new TQListViewItem(list, name, filename);
changed = true;
emit widgetChanged();
}
void ConfigDictionaries::delSel(KListView* list)
{
TQListViewItem *file = list->selectedItem();
if (!file)
return;
delete file;
changed = true;
emit widgetChanged();
}
|