Now the systrayicon change it's color when a download is in progress. I simply change...
[kdenetwork.git] / kdict / sets.cpp
blob0a252cecdb778e7e2d7147012edea1b9fa97ac88
1 /* -------------------------------------------------------------
3 sets.cpp (part of The KDE Dictionary Client)
5 Copyright (C) 2000-2001 Christian Gebauer <gebauer@kde.org>
7 This file is distributed under the Artistic License.
8 See LICENSE for details.
10 -------------------------------------------------------------
12 DbSetsDialog dialog for editing the user defined database sets
14 ------------------------------------------------------------- */
16 #include <qpushbutton.h>
17 #include <qlayout.h>
18 #include <qlabel.h>
19 #include <qcombobox.h>
21 #include <kiconloader.h>
22 #include <kseparator.h>
23 #include <klocale.h>
25 #include "options.h"
26 #include "sets.h"
29 //********* DbSetsDialog ******************************************
32 DbSetsDialog::DbSetsDialog(QWidget *parent, const char *name)
33 : KDialogBase(Plain, i18n("Database Sets"),Close | Help, Close, parent, name, false, true)
35 QFrame* page=plainPage();
37 QStringList sets;
38 for(unsigned int i=1;i<global->databaseSets.count()+1;i++)
39 sets.append(global->databases[i]);
41 QVBoxLayout * topLayout = new QVBoxLayout(page, 0, 0);
43 QHBoxLayout * subLayout1 = new QHBoxLayout(5);
44 topLayout->addLayout(subLayout1,0);
46 w_set = new QComboBox(true,page);
47 w_set->setFixedHeight(w_set->sizeHint().height());
48 w_set->setInsertionPolicy (QComboBox::NoInsertion);
49 w_set->insertStringList(sets);
50 connect(w_set, SIGNAL(activated(int)),this, SLOT(activateSet(int)));
51 QLabel *l = new QLabel(w_set, i18n("&Set:"),page);
52 l->setMinimumSize(l->sizeHint());
53 subLayout1->addWidget(l,0);
54 subLayout1->addWidget(w_set,1);
56 subLayout1->addSpacing(8);
58 w_save = new QPushButton(i18n("S&ave"),page);
59 connect(w_save,SIGNAL(clicked()),this, SLOT(transferSet()));
60 subLayout1->addWidget(w_save,0);
62 QPushButton *btn = new QPushButton(i18n("&New"),page);
63 btn->setMinimumSize(btn->sizeHint());
64 connect(btn, SIGNAL(clicked()),this, SLOT(newPressed()));
65 subLayout1->addWidget(btn,0);
67 w_delete = new QPushButton(i18n("&Delete"),page);
68 w_delete->setMinimumSize(w_delete->sizeHint());
69 connect(w_delete, SIGNAL(clicked()),this, SLOT(deletePressed()));
70 subLayout1->addWidget(w_delete,0);
72 topLayout->addSpacing(8);
74 KSeparator *sep = new KSeparator(page);
75 topLayout->addWidget(sep,0);
77 topLayout->addSpacing(8);
79 QGridLayout * subLayout2 = new QGridLayout(7,3,6);
80 topLayout->addLayout(subLayout2,1);
82 w_leftBox = new QListBox(page);
83 connect(w_leftBox, SIGNAL(selected(int)),this, SLOT(leftSelected(int)));
84 connect(w_leftBox, SIGNAL(highlighted(int)),this, SLOT(leftHighlighted(int)));
85 QLabel *leftLabel = new QLabel(w_leftBox, i18n("S&elected databases:"),page);
86 leftLabel->setMinimumSize(leftLabel->sizeHint());
87 subLayout2->addWidget(leftLabel,0,0);
88 subLayout2->addMultiCellWidget(w_leftBox,1,6,0,0);
90 w_allLeft = new QPushButton(page);
91 w_allLeft->setIconSet(BarIconSet("2leftarrow"));
92 connect(w_allLeft, SIGNAL(clicked()),this, SLOT(allLeftPressed()));
93 subLayout2->addWidget(w_allLeft,2,1);
95 w_left = new QPushButton(page);
96 w_left->setIconSet(BarIconSet("1leftarrow"));
97 connect(w_left, SIGNAL(clicked()),this, SLOT(leftPressed()));
98 subLayout2->addWidget(w_left,3,1);
100 w_right = new QPushButton(page);
101 w_right->setIconSet(BarIconSet("1rightarrow"));
102 connect(w_right, SIGNAL(clicked()),this, SLOT(rightPressed()));
103 subLayout2->addWidget(w_right,4,1);
105 w_allRight = new QPushButton(page);
106 w_allRight->setIconSet(BarIconSet("2rightarrow"));
107 connect(w_allRight, SIGNAL(clicked()),this, SLOT(allRightPressed()));
108 subLayout2->addWidget(w_allRight,5,1);
110 w_rightBox = new QListBox(page);
111 connect(w_rightBox, SIGNAL(selected(int)),this, SLOT(rightSelected(int)));
112 connect(w_rightBox, SIGNAL(highlighted(int)),this, SLOT(rightHighlighted(int)));
113 QLabel *rightLabel = new QLabel(w_rightBox, i18n("A&vailable databases:"),page);
114 rightLabel->setMinimumSize(rightLabel->sizeHint());
115 subLayout2->addWidget(rightLabel,0,2);
116 subLayout2->addMultiCellWidget(w_rightBox,1,6,2,2);
118 subLayout2->setRowStretch(1,1);
119 subLayout2->setRowStretch(6,1);
120 subLayout2->setColStretch(0,1);
121 subLayout2->setColStretch(2,1);
123 setHelp("database-sets");
125 if (global->setsSize.isValid())
126 resize(global->setsSize);
127 else
128 resize(300,200);
130 if ((global->currentDatabase>=1)&&(global->currentDatabase<=global->databaseSets.count()))
131 activateSet(global->currentDatabase-1);
132 else
133 activateSet(0);
134 w_set->setFocus();
138 void DbSetsDialog::hideEvent(QHideEvent *)
140 global->setsSize = size();
141 emit(dialogClosed());
145 void DbSetsDialog::newPressed()
147 QStringList *temp = new QStringList;
148 temp->append(i18n("New Set"));
149 global->databaseSets.append(temp);
150 global->databases.insert(global->databases.at(global->databaseSets.count()),i18n("New Set"));
151 if (global->currentDatabase >= global->databaseSets.count())
152 global->currentDatabase++;
154 QStringList sets; // reread sets, because w_sets internal list is not correct in all cases
155 for(unsigned int i=1;i<global->databaseSets.count()+1;i++)
156 sets.append(global->databases[i]);
157 w_set->clear();
158 w_set->insertStringList(sets);
159 emit(setsChanged());
160 activateSet(global->databaseSets.count()-1);
161 w_set->setFocus();
165 void DbSetsDialog::deletePressed()
167 int pos = w_set->currentItem();
168 if (pos>=0) {
169 global->databaseSets.remove(global->databaseSets.at(pos));
170 global->databases.remove(global->databases.at(pos+1));
171 if ((int)global->currentDatabase >= pos+1)
172 global->currentDatabase--;
173 w_set->removeItem(pos);
174 if (pos >= w_set->count())
175 pos--;
176 emit(setsChanged());
177 activateSet(pos);
178 w_set->setFocus();
183 void DbSetsDialog::allLeftPressed()
185 while (w_rightBox->count()) {
186 w_leftBox->insertItem(w_rightBox->text(0));
187 w_rightBox->removeItem(0);
189 w_leftBox->sort();
190 checkButtons();
194 void DbSetsDialog::leftPressed()
196 int pos = w_rightBox->currentItem();
197 if (pos>=0) {
198 w_leftBox->insertItem(w_rightBox->text(pos));
199 w_leftBox->sort();
200 w_rightBox->removeItem(pos);
201 if (pos >= (int)w_rightBox->count())
202 pos--;
203 if (pos>=0)
204 w_rightBox->setCurrentItem(pos);
205 checkButtons();
210 void DbSetsDialog::rightPressed()
212 int pos = w_leftBox->currentItem();
213 if (pos>=0) {
214 w_rightBox->insertItem(w_leftBox->text(pos));
215 w_rightBox->sort();
216 w_leftBox->removeItem(pos);
217 if (pos >= (int)w_leftBox->count())
218 pos--;
219 if (pos>=0)
220 w_leftBox->setCurrentItem(pos);
221 checkButtons();
226 void DbSetsDialog::allRightPressed()
228 while (w_leftBox->count()) {
229 w_rightBox->insertItem(w_leftBox->text(0));
230 w_leftBox->removeItem(0);
232 w_rightBox->sort();
233 checkButtons();
237 void DbSetsDialog::closePressed()
239 accept();
240 global->setsSize = size();
241 emit(dialogClosed());
245 void DbSetsDialog::transferSet()
247 global->databaseSets.at(w_set->currentItem())->clear();
248 global->databaseSets.at(w_set->currentItem())->append(w_set->currentText());
249 for (unsigned int i = 0;i<w_leftBox->count();i++)
250 global->databaseSets.at(w_set->currentItem())->append(w_leftBox->text(i));
251 global->databases.remove(global->databases.at(w_set->currentItem()+1));
252 global->databases.insert(global->databases.at(w_set->currentItem()+1),w_set->currentText());
253 w_set->changeItem(w_set->currentText(),w_set->currentItem());
254 emit(setsChanged());
258 void DbSetsDialog::activateSet(int num)
260 w_leftBox->clear();
261 w_rightBox->clear();
263 if ((num < 0)||(num>=(int)global->databaseSets.count())) {
264 w_set->clearEdit();
265 w_delete->setEnabled(false);
266 w_save->setEnabled(false);
267 w_rightBox->repaint(true); // Workaround for repaint-bug
268 w_leftBox->repaint(true); // Workaround for repaint-bug
269 } else {
270 w_set->setCurrentItem(num);
271 for (unsigned int i=0;i<global->serverDatabases.count();i++)
272 if (global->databaseSets.at(num)->findIndex(global->serverDatabases[i])>0)
273 w_leftBox->insertItem(global->serverDatabases[i]);
274 else
275 w_rightBox->insertItem(global->serverDatabases[i]);
276 w_leftBox->sort();
277 w_rightBox->sort();
278 w_delete->setEnabled(true);
279 w_save->setEnabled(true);
280 if (w_rightBox->count()==0)
281 w_rightBox->repaint(true); // Workaround for repaint-bug
282 if (w_leftBox->count()==0)
283 w_leftBox->repaint(true); // Workaround for repaint-bug
284 w_leftBox->clearSelection();
285 w_leftBox->centerCurrentItem();
286 w_rightBox->clearSelection();
287 w_rightBox->centerCurrentItem();
289 checkButtons();
293 void DbSetsDialog::leftSelected(int)
295 rightPressed();
299 void DbSetsDialog::rightSelected(int)
301 leftPressed();
305 void DbSetsDialog::leftHighlighted(int)
307 w_right->setEnabled(true);
311 void DbSetsDialog::rightHighlighted(int)
313 w_left->setEnabled(true);
316 void DbSetsDialog::checkButtons()
318 w_allLeft->setEnabled((w_rightBox->count()>0));
319 w_allRight->setEnabled((w_leftBox->count()>0));
320 w_right->setEnabled((w_leftBox->currentItem()>=0));
321 w_left->setEnabled((w_rightBox->currentItem()>=0));
324 //--------------------------------
326 #include "sets.moc"