Fix status message sending.
[kdenetwork.git] / kdict / options.cpp
blob0b724e951e021537765a63ec9a691fd76b752107
1 /* -------------------------------------------------------------
3 options.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 GlobalData manages all global data of Kdict
14 OptionsDialog the "Preferences" dialog
16 DbSetsDialog dialog for editing the user defined database sets
18 ------------------------------------------------------------- */
20 #include <qcheckbox.h>
21 #include <qpushbutton.h>
22 #include <qradiobutton.h>
23 #include <qlayout.h>
24 #include <qlabel.h>
25 #include <qcombobox.h>
26 #include <q3buttongroup.h>
27 #include <qpainter.h>
28 //Added by qt3to4:
29 #include <QGridLayout>
30 #include <QKeyEvent>
31 #include <QVBoxLayout>
33 #include <kcolordialog.h>
34 #include <kconfig.h>
35 #include <klocale.h>
36 #include <knumvalidator.h>
37 #include <knuminput.h>
38 #include <klineedit.h>
39 #include <kcharsets.h>
40 #include <kfontdialog.h>
41 #include <kiconloader.h>
43 #include "options.h"
46 //********* DictOptions ******************************************
49 void GlobalData::read()
51 KConfig *config=KGlobal::config();
53 // general...
54 config->setGroup("General");
55 defineClipboard = config->readEntry("Lookup_Clipboard",false);
56 headLayout = config->readNumEntry("Heading_Layout",0);
57 if ((headLayout > 2)||(headLayout < 0))
58 headLayout = 0;
59 saveHistory = config->readEntry("Save_History",true);
60 maxHistEntrys = config->readNumEntry("Max_History_Entrys",500);
61 if ((maxHistEntrys < 10)||(maxHistEntrys >5000))
62 maxHistEntrys = 200;
63 maxBrowseListEntrys = config->readNumEntry("Max_Browse_Entrys",15);
64 if ((maxBrowseListEntrys < 1)||(maxBrowseListEntrys > 50))
65 maxBrowseListEntrys = 15;
66 maxDefinitions = config->readNumEntry("Max_Definitions",2000);
67 if ((maxDefinitions < 100)||(maxDefinitions > 10000))
68 maxDefinitions = 2000;
70 //colors
71 config->setGroup("Colors");
72 useCustomColors=config->readEntry("customColors", false);
74 QColor defCol=KGlobalSettings::textColor();
75 c_olors[Ctext]=config->readColorEntry("textColor",&defCol);
76 c_olorNames[Ctext]=i18n("Text");
78 defCol=KGlobalSettings::baseColor();
79 c_olors[Cbackground]=config->readColorEntry("backgroundColor",&defCol);
80 c_olorNames[Cbackground]=i18n("Background");
82 defCol=KGlobalSettings::highlightedTextColor();
83 c_olors[CheadingsText]=config->readColorEntry("headingsTextColor",&defCol);
84 c_olorNames[CheadingsText]=i18n("Heading Text");
86 defCol=KGlobalSettings::highlightColor();
87 c_olors[CheadingsBackground]=config->readColorEntry("headingsBackgroundColor",&defCol);
88 c_olorNames[CheadingsBackground]=i18n("Heading Background");
90 defCol=KGlobalSettings::linkColor();
91 c_olors[Clinks]=config->readColorEntry("linksColor",&defCol);
92 c_olorNames[Clinks]=i18n("Link");
94 defCol=KGlobalSettings::visitedLinkColor();
95 c_olors[CvisitedLinks]=config->readColorEntry("linksColor",&defCol);
96 c_olorNames[CvisitedLinks]=i18n("Followed Link");
98 //fonts
99 config->setGroup("Fonts");
100 useCustomFonts=config->readEntry("customFonts", false);
102 QFont defFont=KGlobalSettings::generalFont();
103 f_onts[Ftext]=config->readFontEntry("textFont",&defFont);
104 f_ontNames[Ftext]=i18n("Text");
106 defFont.setBold( true );
107 defFont.setPointSize(defFont.pointSize()+2);
108 f_onts[Fheadings]=config->readFontEntry("headingsFont",&defFont);
109 f_ontNames[Fheadings]=i18n("Headings");
111 // geometry...
112 config->setGroup("Geometry");
113 QSize invalid(-1,-1);
114 optSize = config->readSizeEntry("Opt_Size",&invalid);
115 setsSize = config->readSizeEntry("Sets_Size",&invalid);
116 matchSize = config->readSizeEntry("Match_Size",&invalid);
117 showMatchList = config->readEntry("Show_MatchList",false);
118 splitterSizes = config->readIntListEntry("Splitter_Sizes");
120 config->setGroup("Query Combo");
121 queryComboCompletionMode = (KGlobalSettings::Completion)config->readNumEntry("Completion_mode",
122 KGlobalSettings::completionMode());
124 config->setGroup("Query_History");
125 queryHistory = config->readListEntry("History");
127 config->setGroup("DictServer");
128 server = config->readEntry("Server", "dict.org");
129 port = config->readNumEntry("Port", 2628);
130 if (port < 0)
131 port = 2628;
132 timeout = config->readNumEntry("Timeout",60);
133 if (timeout < 0)
134 timeout = 60;
135 pipeSize = config->readNumEntry("Pipe_Size",256);
136 if (pipeSize < 0)
137 pipeSize = 256;
138 idleHold = config->readNumEntry("Idle_Hold",30);
139 if (idleHold < 0)
140 idleHold = 30;
141 encoding=config->readEntry("encoding", "utf8");
142 authEnabled = config->readEntry("Auth_Enabled",false);
143 user = config->readEntry("User");
144 secret = encryptStr(config->readEntry("Secret"));
145 serverDatabases = config->readListEntry("Server_Databases");
146 currentDatabase = config->readNumEntry("Current_Database",0);
147 strategies = config->readListEntry("Strategies");
148 if (strategies.isEmpty()) {
149 strategies.append(i18n("Spell Check"));
150 strategies.append(i18n("Exact"));
151 strategies.append(i18n("Prefix"));
152 } else {
153 strategies.remove(strategies.begin());
154 strategies.prepend(i18n("Spell Check"));
157 currentStrategy = config->readNumEntry("Current_Strategy",0);
158 if (currentStrategy >= strategies.count())
159 currentStrategy = 0;
161 config->setGroup("Database_Sets");
162 databaseSets.setAutoDelete(true);
163 int num = config->readNumEntry("Num_Sets",0);
164 QStringList* temp;
165 QString strNum;
166 while (num > 0) {
167 temp = new QStringList();
168 strNum.setNum(num);
169 *temp = config->readListEntry(strNum);
170 if (!temp->isEmpty()) {
171 databaseSets.prepend(temp);
172 num--;
173 } else {
174 delete temp;
175 num = 0; // stop reading...
178 databases = serverDatabases;
179 for (int i = databaseSets.count()-1;i>=0;i--)
180 databases.prepend(databaseSets.at(i)->first());
181 databases.prepend(i18n("All Databases"));
182 if (currentDatabase >= databases.count())
183 currentDatabase = 0;
187 void GlobalData::write()
189 KConfig *config=KGlobal::config();
191 config->setGroup("General");
192 config->writeEntry("Lookup_Clipboard",defineClipboard);
193 config->writeEntry("Heading_Layout",headLayout);
194 config->writeEntry("Save_History",saveHistory);
195 config->writeEntry("Max_History_Entrys",maxHistEntrys);
196 config->writeEntry("Max_Browse_Entrys",maxBrowseListEntrys);
197 config->writeEntry("Max_Definitions",maxDefinitions);
199 config->setGroup("Colors");
200 config->writeEntry("customColors",useCustomColors);
201 config->writeEntry("textColor", c_olors[Ctext]);
202 config->writeEntry("backgroundColor", c_olors[Cbackground]);
203 config->writeEntry("headingsTextColor", c_olors[CheadingsText]);
204 config->writeEntry("headingsBackgroundColor", c_olors[CheadingsBackground]);
205 config->writeEntry("linksColor", c_olors[Clinks]);
206 config->writeEntry("visitedLinksColor", c_olors[CvisitedLinks]);
208 config->setGroup("Fonts");
209 config->writeEntry("customFonts", useCustomFonts);
210 config->writeEntry("textFont", f_onts[Ftext]);
211 config->writeEntry("headingsFont", f_onts[Fheadings]);
213 config->setGroup("Geometry");
214 config->writeEntry("Opt_Size",optSize);
215 config->writeEntry("Sets_Size",setsSize);
216 config->writeEntry("Match_Size",matchSize);
217 config->writeEntry("Show_MatchList",showMatchList);
218 config->writeEntry("Splitter_Sizes",splitterSizes);
220 config->setGroup("Query Combo");
221 config->writeEntry("Completion_mode", (int)queryComboCompletionMode);
223 config->setGroup("Query_History");
224 QStringList copy;
225 if (saveHistory)
226 copy = queryHistory;
227 config->writeEntry("History",copy);
229 config->setGroup("DictServer");
230 config->writeEntry("Server", server);
231 config->writeEntry("Port", port);
232 config->writeEntry("Timeout",timeout);
233 config->writeEntry("Pipe_Size",pipeSize);
234 config->writeEntry("Idle_Hold",idleHold);
235 config->writeEntry("encoding", encoding);
236 config->writeEntry("Auth_Enabled",authEnabled);
237 config->writeEntry("User", user);
238 config->writeEntry("Secret", encryptStr(secret));
239 config->writeEntry("Server_Databases",serverDatabases);
240 config->writeEntry("Current_Database",currentDatabase);
241 config->writeEntry("Strategies",strategies);
242 config->writeEntry("Current_Strategy",currentStrategy);
244 config->setGroup("Database_Sets");
245 config->writeEntry("Num_Sets",databaseSets.count());
246 QString strNum;
247 for (unsigned int i = 0;i<databaseSets.count();i++)
248 config->writeEntry(strNum.setNum(i+1),*databaseSets.at(i));
252 QColor GlobalData::defaultColor(int i)
254 switch(i) {
255 case Ctext:
256 return KGlobalSettings::textColor();
257 break;
259 case Cbackground:
260 return KGlobalSettings::baseColor();
261 break;
263 case CheadingsText:
264 return KGlobalSettings::highlightedTextColor();
265 break;
267 case CheadingsBackground:
268 return KGlobalSettings::highlightColor();
269 break;
271 case Clinks:
272 return KGlobalSettings::linkColor();
273 break;
275 case CvisitedLinks:
276 return KGlobalSettings::visitedLinkColor();
277 break;
281 return KGlobalSettings::baseColor();
285 QColor GlobalData::textColor()
287 if(useCustomColors)
288 return c_olors[Ctext];
289 else
290 return defaultColor(Ctext);
294 QColor GlobalData::backgroundColor()
296 if(useCustomColors)
297 return c_olors[Cbackground];
298 else
299 return defaultColor(Cbackground);
303 QColor GlobalData::headingsTextColor()
305 if(useCustomColors)
306 return c_olors[CheadingsText];
307 else
308 return defaultColor(CheadingsText);
312 QColor GlobalData::headingsBackgroundColor()
314 if(useCustomColors)
315 return c_olors[CheadingsBackground];
316 else
317 return defaultColor(CheadingsBackground);
321 QColor GlobalData::linksColor()
323 if(useCustomColors)
324 return c_olors[Clinks];
325 else
326 return defaultColor(Clinks);
330 QColor GlobalData::visitedLinksColor()
332 if(useCustomColors)
333 return c_olors[CvisitedLinks];
334 else
335 return defaultColor(CvisitedLinks);
339 QFont GlobalData::defaultFont(int i)
341 QFont font = KGlobalSettings::generalFont();
343 if (font.pointSize() < 5)
344 font.setPointSize(12);
346 if (i==Fheadings)
347 font.setPointSize(font.pointSize()+5);
349 return font;
353 QFont GlobalData::textFont()
355 if(useCustomFonts)
356 return f_onts[Ftext];
357 else
358 return defaultFont(Ftext);
362 QFont GlobalData::headingsFont()
364 if(useCustomFonts)
365 return f_onts[Fheadings];
366 else
367 return defaultFont(Fheadings);
371 // simple password scrambling...
372 QString GlobalData::encryptStr(const QString& aStr)
374 uint i,val,len = aStr.length();
375 QString result;
377 for (i=0; i<len; i++)
379 val = aStr[i].toLatin1() - ' ';
380 val = (255-' ') - val;
381 result += (char)(val + ' ');
384 return result;
388 //********* OptionsDialog::DialogListBox *****************************
391 OptionsDialog::DialogListBox::DialogListBox(bool alwaysIgnore, QWidget * parent, const char * name)
392 : Q3ListBox(parent, name), a_lwaysIgnore(alwaysIgnore)
397 OptionsDialog::DialogListBox::~DialogListBox()
402 void OptionsDialog::DialogListBox::keyPressEvent(QKeyEvent *e)
404 if ((a_lwaysIgnore || !(hasFocus()&&isVisible()))&&((e->key()==Qt::Key_Enter)||(e->key()==Qt::Key_Return)))
405 e->ignore();
406 else
407 Q3ListBox::keyPressEvent(e);
411 //********* OptionsDialog::ColorListItem *****************************
414 OptionsDialog::ColorListItem::ColorListItem( const QString &text, const QColor &color )
415 : Q3ListBoxText(text), mColor( color )
420 OptionsDialog::ColorListItem::~ColorListItem()
425 void OptionsDialog::ColorListItem::paint( QPainter *p )
427 QFontMetrics fm = p->fontMetrics();
428 int h = fm.height();
430 p->drawText( 30+3*2, fm.ascent() + fm.leading()/2, text() );
432 p->setPen( Qt::black );
433 p->drawRect( 3, 1, 30, h-1 );
434 p->fillRect( 4, 2, 28, h-3, mColor );
438 int OptionsDialog::ColorListItem::height(const Q3ListBox *lb ) const
440 return( lb->fontMetrics().lineSpacing()+1 );
444 int OptionsDialog::ColorListItem::width(const Q3ListBox *lb ) const
446 return( 30 + lb->fontMetrics().width( text() ) + 6 );
450 //********* OptionsDialog::FontListItem *****************************
453 OptionsDialog::FontListItem::FontListItem( const QString &name, const QFont &font )
454 : Q3ListBoxText(name), f_ont(font)
456 fontInfo = QString("[%1 %2]").arg(f_ont.family()).arg(f_ont.pointSize());
460 OptionsDialog::FontListItem::~FontListItem()
465 void OptionsDialog::FontListItem::setFont(const QFont &font)
467 f_ont = font;
468 fontInfo = QString("[%1 %2]").arg(f_ont.family()).arg(f_ont.pointSize());
472 void OptionsDialog::FontListItem::paint( QPainter *p )
474 QFont fnt = p->font();
475 fnt.setWeight(QFont::Bold);
476 p->setFont(fnt);
477 int fontInfoWidth = p->fontMetrics().width(fontInfo);
478 int h = p->fontMetrics().ascent() + p->fontMetrics().leading()/2;
479 p->drawText(2, h, fontInfo );
480 fnt.setWeight(QFont::Normal);
481 p->setFont(fnt);
482 p->drawText(5 + fontInfoWidth, h, text() );
486 int OptionsDialog::FontListItem::width(const Q3ListBox *lb ) const
488 return( lb->fontMetrics().width(fontInfo) + lb->fontMetrics().width(text()) + 20 );
492 //********* OptionsDialog ******************************************
495 OptionsDialog::OptionsDialog(QWidget *parent, const char *name)
496 : KDialogBase(IconList, i18n("Configure"), Help|Default|Ok|Apply|Cancel, Ok, parent, name, false, true)
499 //******** Server ************************************
500 serverTab = addPage(i18n("Server"),i18n("DICT Server Configuration"), BarIcon("network", K3Icon::SizeMedium ));
501 QGridLayout* grid = new QGridLayout(serverTab);
502 grid->setSpacing(spacingHint());
503 grid->setMargin(0);
505 w_server = new KLineEdit(serverTab);
506 w_server->setText(global->server);
507 QLabel *l = new QLabel(w_server, i18n("Host&name:"), serverTab);
508 grid->addWidget(l,0,0);
509 grid->addMultiCellWidget(w_server,0,0,1,2);
510 connect( w_server, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
512 w_port = new KLineEdit(serverTab);
513 w_port->setValidator(new KIntValidator(0,65536,this));
514 w_port->setText(QString::number(global->port));
515 l = new QLabel(w_port, i18n("&Port:"), serverTab);
516 grid->addWidget(l,1,0);
517 grid->addWidget(w_port,1,1);
518 connect( w_port, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
520 w_idleHold = new KIntSpinBox(0,300,5,0,serverTab);
521 w_idleHold->setSuffix(i18n(" sec"));
522 w_idleHold->setValue(global->idleHold);
523 l = new QLabel(w_idleHold, i18n("Hold conn&ection for:"), serverTab);
524 grid->addWidget(l,2,0);
525 grid->addWidget(w_idleHold,2,1);
526 connect( w_idleHold, SIGNAL( valueChanged(int) ), this, SLOT( slotChanged() ) );
528 w_timeout = new KIntSpinBox(5,600,5,5,serverTab);
529 w_timeout->setSuffix(i18n(" sec"));
530 w_timeout->setValue(global->timeout);
531 l = new QLabel(w_timeout, i18n("T&imeout:"), serverTab);
532 grid->addWidget(l,3,0);
533 grid->addWidget(w_timeout,3,1);
534 connect( w_timeout, SIGNAL( valueChanged(int) ), this, SLOT( slotChanged() ) );
536 w_pipesize = new KIntSpinBox(100,5000,2,2,serverTab);
537 w_pipesize->setSuffix(i18n(" bytes"));
538 w_pipesize->setValue(global->pipeSize);
539 l = new QLabel(w_pipesize, i18n("Command &buffer:"), serverTab);
540 grid->addWidget(l,4,0);
541 grid->addWidget(w_pipesize,4,1);
542 connect( w_pipesize, SIGNAL( valueChanged(int) ), this, SLOT( slotChanged() ) );
544 QStringList encodingNames = KGlobal::charsets()->descriptiveEncodingNames();
545 int i=0,x=0;
546 for ( QStringList::Iterator it = encodingNames.begin(); it != encodingNames.end(); ++it ) {
547 if (KGlobal::charsets()->encodingForName(*it)==global->encoding) {
548 x = i;
549 break;
551 i++;
553 w_encoding = new QComboBox(serverTab);
554 w_encoding->insertStringList(encodingNames);
555 w_encoding->setCurrentItem(x);
556 l = new QLabel(w_encoding, i18n("Encod&ing:"), serverTab);
557 grid->addWidget(l,5,0);
558 grid->addMultiCellWidget(w_encoding,5,5,1,2);
559 connect( w_encoding, SIGNAL( activated(int) ), this, SLOT( slotChanged() ) );
561 w_auth = new QCheckBox(i18n("Server requires a&uthentication"),serverTab);
562 w_auth->setChecked(global->authEnabled);
563 grid->addMultiCellWidget(w_auth,6,6,0,2);
564 connect( w_auth, SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) );
565 connect(w_auth,SIGNAL(toggled(bool)),SLOT(slotAuthRequiredToggled(bool)));
567 w_user = new KLineEdit(serverTab);
568 w_user->setText(global->user);
569 l_user = new QLabel(w_user, i18n("U&ser:"),serverTab);
570 grid->addWidget(l_user,7,0);
571 grid->addMultiCellWidget(w_user,7,7,1,2);
572 connect( w_user, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
574 w_secret = new KLineEdit(serverTab);
575 w_secret->setEchoMode(QLineEdit::Password);
576 w_secret->setText(global->secret);
577 l_secret = new QLabel(w_secret, i18n("Pass&word:"), serverTab);
578 grid->addWidget(l_secret,8,0);
579 grid->addMultiCellWidget(w_secret,8,8,1,2);
580 connect( w_secret, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
582 slotAuthRequiredToggled( w_auth->isChecked() );
584 grid->setColStretch(1,2);
585 grid->setColStretch(2,2);
587 //************ Appearance ***************************
588 appTab = addPage(i18n("Appearance"),i18n("Customize Visual Appearance"), BarIcon("appearance", K3Icon::SizeMedium ));
590 QGridLayout *topL=new QGridLayout(appTab);
591 topL->setSpacing(spacingHint());
592 topL->setMargin(0);
594 //color-list
595 c_List = new DialogListBox(false, appTab);
596 topL->addMultiCellWidget(c_List,1,3,0,1);
597 connect(c_List, SIGNAL(selected(Q3ListBoxItem*)),SLOT(slotColItemSelected(Q3ListBoxItem*)));
598 connect(c_List, SIGNAL(selectionChanged()), SLOT(slotColSelectionChanged()));
600 c_olorCB = new QCheckBox(i18n("&Use custom colors"),appTab);
601 topL->addWidget(c_olorCB,0,0);
602 connect(c_olorCB, SIGNAL(toggled(bool)), this, SLOT(slotColCheckBoxToggled(bool)));
603 connect(c_olorCB, SIGNAL(toggled(bool) ), this, SLOT( slotChanged()));
605 c_olChngBtn=new QPushButton(i18n("Cha&nge..."), appTab);
606 connect(c_olChngBtn, SIGNAL(clicked()), SLOT(slotColChangeBtnClicked()));
607 topL->addWidget(c_olChngBtn,1,2);
609 c_olDefBtn=new QPushButton(i18n("Default&s"), appTab);
610 connect(c_olDefBtn, SIGNAL(clicked()), SLOT(slotColDefaultBtnClicked()));
611 topL->addWidget(c_olDefBtn,2,2);
612 connect(c_olDefBtn, SIGNAL(clicked()), SLOT(slotChanged()));
614 //font-list
615 f_List = new DialogListBox(false, appTab);
616 topL->addMultiCellWidget(f_List,5,7,0,1);
617 connect(f_List, SIGNAL(selected(Q3ListBoxItem*)),SLOT(slotFontItemSelected(Q3ListBoxItem*)));
618 connect(f_List, SIGNAL(selectionChanged()),SLOT(slotFontSelectionChanged()));
620 f_ontCB = new QCheckBox(i18n("Use custom &fonts"),appTab);
621 topL->addWidget(f_ontCB,4,0);
622 connect(f_ontCB, SIGNAL(toggled(bool)), SLOT(slotFontCheckBoxToggled(bool)));
623 connect(f_ontCB, SIGNAL(toggled(bool)), SLOT(slotChanged()));
625 f_ntChngBtn=new QPushButton(i18n("Chang&e..."), appTab);
626 connect(f_ntChngBtn, SIGNAL(clicked()), SLOT(slotFontChangeBtnClicked()));
627 topL->addWidget(f_ntChngBtn,5,2);
629 f_ntDefBtn=new QPushButton(i18n("Defaul&ts"), appTab);
630 connect(f_ntDefBtn, SIGNAL(clicked()), SLOT(slotFontDefaultBtnClicked()));
631 topL->addWidget(f_ntDefBtn,6,2);
632 connect(f_ntDefBtn, SIGNAL(clicked()), SLOT(slotChanged()));
634 topL->setColStretch(1,2);
635 topL->setColStretch(2,0);
636 topL->setRowStretch(3,1);
637 topL->setRowStretch(7,1);
638 topL->setResizeMode(QLayout::Minimum);
640 //init
641 c_olorCB->setChecked(global->useCustomColors);
642 slotColCheckBoxToggled(global->useCustomColors);
643 for(int i=0; i<global->colorCount(); i++)
644 c_List->insertItem(new ColorListItem(global->colorName(i), global->color(i)));
646 f_ontCB->setChecked(global->useCustomFonts);
647 slotFontCheckBoxToggled(global->useCustomFonts);
648 for(int i=0; i<global->fontCount(); i++)
649 f_List->insertItem(new FontListItem(global->fontName(i), global->font(i)));
651 //************ Layout ***************************
652 layoutTab = addPage(i18n("Layout"),i18n("Customize Output Format"), BarIcon("text_left", K3Icon::SizeMedium ));
654 QVBoxLayout *vbox = new QVBoxLayout(layoutTab);
655 vbox->setSpacing(spacingHint());
656 vbox->setMargin(0);
658 Q3ButtonGroup *bGroup = new Q3ButtonGroup(i18n("Headings"),layoutTab);
659 QVBoxLayout *bvbox = new QVBoxLayout(bGroup);
660 bvbox->setSpacing(5);
661 bvbox->setMargin(8);
663 bvbox->addSpacing(fontMetrics().lineSpacing()-4);
664 w_layout[0] = new QRadioButton(i18n("O&ne heading for each database"),bGroup);
665 w_layout[0]->setChecked(global->headLayout == 0);
666 bvbox->addWidget(w_layout[0],1);
667 w_layout[1] = new QRadioButton(i18n("A&s above, with separators between the definitions"),bGroup);
668 w_layout[1]->setChecked(global->headLayout == 1);
669 bvbox->addWidget(w_layout[1],1);
670 w_layout[2] = new QRadioButton(i18n("A separate heading for &each definition"),bGroup);
671 w_layout[2]->setChecked(global->headLayout == 2);
672 bvbox->addWidget(w_layout[2],1);
673 connect(w_layout[0], SIGNAL(toggled(bool)), SLOT(slotChanged()));
674 connect(w_layout[1], SIGNAL(toggled(bool)), SLOT(slotChanged()));
675 connect(w_layout[2], SIGNAL(toggled(bool)), SLOT(slotChanged()));
677 vbox->addWidget(bGroup,0);
678 vbox->addStretch(1);
680 //************ Other ***************************
681 otherTab = addPage(i18n("Miscellaneous"),i18n("Various Settings"), BarIcon("misc", K3Icon::SizeMedium ));
683 vbox = new QVBoxLayout(otherTab);
684 vbox->setSpacing(spacingHint());
685 vbox->setMargin(0);
687 Q3GroupBox *group = new Q3GroupBox(i18n("Limits"),otherTab);
689 grid = new QGridLayout(group);
690 grid->setSpacing(5);
691 grid->setMargin(8);
692 grid->addRowSpacing(0, fontMetrics().lineSpacing()-4);
694 w_MaxDefinitions = new KIntSpinBox(100,10000,100,100,group);
695 w_MaxDefinitions->setValue(global->maxDefinitions);
696 l = new QLabel(w_MaxDefinitions, i18n("De&finitions:"), group);
697 grid->addWidget(l,1,0);
698 grid->addWidget(w_MaxDefinitions,1,1);
699 connect(w_MaxDefinitions, SIGNAL(valueChanged(int)), SLOT(slotChanged()));
701 w_Maxbrowse = new KIntSpinBox(1,100,1,1,group);
702 w_Maxbrowse->setValue(global->maxBrowseListEntrys);
703 l = new QLabel(w_Maxbrowse, i18n("Cached &results:"), group);
704 grid->addWidget(l,2,0);
705 grid->addWidget(w_Maxbrowse,2,1);
706 connect(w_Maxbrowse, SIGNAL(valueChanged(int)), SLOT(slotChanged()));
708 w_Maxhist = new KIntSpinBox(10,5000,10,10,group);
709 w_Maxhist->setValue(global->maxHistEntrys);
710 l = new QLabel(w_Maxhist, i18n("Hi&story entries:"), group);
711 grid->addWidget(l,3,0);
712 grid->addWidget(w_Maxhist,3,1);
713 connect(w_Maxhist, SIGNAL(valueChanged(int)), SLOT(slotChanged()));
715 grid->setColStretch(1,1);
717 vbox->addWidget(group,0);
719 group = new Q3GroupBox(i18n("Other"),otherTab);
721 QVBoxLayout *vbox2 = new QVBoxLayout(group);
722 vbox2->setSpacing(5);
723 vbox2->setMargin(8);
725 vbox2->addSpacing(fontMetrics().lineSpacing()-4);
727 w_Savehist = new QCheckBox(i18n("Sa&ve history on exit"),group);
728 w_Savehist->setChecked(global->saveHistory);
729 vbox2->addWidget(w_Savehist,0);
730 connect(w_Savehist, SIGNAL(toggled(bool)), SLOT(slotChanged()));
732 w_Clipboard = new QCheckBox(i18n("D&efine selected text on start"),group);
733 w_Clipboard->setChecked(global->defineClipboard);
734 vbox2->addWidget(w_Clipboard,1);
735 connect(w_Clipboard, SIGNAL(toggled(bool)), SLOT(slotChanged()));
737 vbox->addWidget(group,0);
738 vbox->addStretch(2);
740 setHelp("preferences");
742 if (global->optSize.isValid())
743 resize(global->optSize);
744 else
745 resize(300,200);
746 enableButton( Apply, false );
747 configChanged = false;
751 OptionsDialog::~OptionsDialog()
753 global->optSize = size();
757 void OptionsDialog::slotApply()
759 global->server = w_server->text();
760 global->port = w_port->text().toInt();
761 global->timeout = w_timeout->value();
762 global->idleHold = w_idleHold->value();
763 global->pipeSize = w_pipesize->value();
764 global->encoding = KGlobal::charsets()->encodingForName(w_encoding->currentText());
765 global->authEnabled = w_auth->isChecked();
766 global->user = w_user->text();
767 global->secret = w_secret->text();
768 global->useCustomColors=c_olorCB->isChecked();
769 for(int i=0; i<global->colorCount(); i++)
770 global->c_olors[i] = (static_cast<ColorListItem*>(c_List->item(i)))->color();
772 global->useCustomFonts=f_ontCB->isChecked();
773 for(int i=0; i<global->fontCount(); i++)
774 global->f_onts[i] = (static_cast<FontListItem*>(f_List->item(i)))->font();
775 if (w_layout[0]->isChecked())
776 global->headLayout = 0;
777 else
778 if (w_layout[1]->isChecked())
779 global->headLayout = 1;
780 else
781 global->headLayout = 2;
782 global->maxDefinitions = w_MaxDefinitions->value();
783 global->maxBrowseListEntrys = w_Maxbrowse->value();
784 global->maxHistEntrys = w_Maxhist->value();
785 global->defineClipboard = w_Clipboard->isChecked();
786 global->saveHistory = w_Savehist->isChecked();
787 emit(optionsChanged());
788 enableButton( Apply, false );
789 configChanged = false;
793 void OptionsDialog::slotOk()
795 if( configChanged )
796 slotApply();
797 KDialogBase::slotOk();
801 void OptionsDialog::slotDefault()
803 QStringList encodingNames;
804 int i=0,x=0;
806 switch(activePageIndex()) {
807 case 0:
808 w_server->setText("dict.org");
809 w_port->setText("2628");
810 w_idleHold->setValue(30);
811 w_timeout->setValue(60);
812 w_pipesize->setValue(256);
813 encodingNames = KGlobal::charsets()->descriptiveEncodingNames();
814 for ( QStringList::Iterator it = encodingNames.begin(); it != encodingNames.end(); ++it ) {
815 if (KGlobal::charsets()->encodingForName(*it)=="utf8")
816 x = i;
817 i++;
819 w_encoding->setCurrentItem(x);
820 w_auth->setChecked(false);
821 w_user->clear();
822 w_user->setEnabled(false);
823 w_secret->clear();
824 w_secret->setEnabled(false);
825 break;
826 case 1:
827 c_olorCB->setChecked(false);
828 slotColCheckBoxToggled(false);
829 slotColDefaultBtnClicked();
830 f_ontCB->setChecked(false);
831 slotFontCheckBoxToggled(false);
832 slotFontDefaultBtnClicked();
833 break;
834 case 2:
835 w_layout[0]->setChecked(true);
836 break;
837 case 3:
838 w_MaxDefinitions->setValue(2000);
839 w_Maxbrowse->setValue(15);
840 w_Maxhist->setValue(500);
841 w_Savehist->setChecked(true);
842 w_Clipboard->setChecked(false);
847 void OptionsDialog::slotAuthRequiredToggled( bool enable )
849 l_user->setEnabled( enable );
850 l_secret->setEnabled( enable );
851 w_user->setEnabled( enable );
852 w_secret->setEnabled( enable );
856 void OptionsDialog::slotColCheckBoxToggled(bool b)
858 c_List->setEnabled(b);
859 c_olDefBtn->setEnabled(b);
860 c_olChngBtn->setEnabled(b && (c_List->currentItem()!=-1));
861 if (b) c_List->setFocus();
865 // show color dialog for the entry
866 void OptionsDialog::slotColItemSelected(Q3ListBoxItem *it)
868 if (it) {
869 ColorListItem *colorItem = static_cast<ColorListItem*>(it);
870 QColor col = colorItem->color();
871 int result = KColorDialog::getColor(col,this);
873 if (result == KColorDialog::Accepted) {
874 colorItem->setColor(col);
875 c_List->triggerUpdate(false);
876 slotChanged();
882 void OptionsDialog::slotColDefaultBtnClicked()
884 ColorListItem *colorItem;
885 for(int i=0; i < global->colorCount(); i++) {
886 colorItem=static_cast<ColorListItem*>(c_List->item(i));
887 colorItem->setColor(global->defaultColor(i));
889 c_List->triggerUpdate(true);
890 c_List->repaint(true);
894 void OptionsDialog::slotColChangeBtnClicked()
896 if(c_List->currentItem()!=-1)
897 slotColItemSelected(c_List->item(c_List->currentItem()));
901 void OptionsDialog::slotColSelectionChanged()
903 c_olChngBtn->setEnabled(c_List->currentItem()!=-1);
907 void OptionsDialog::slotFontCheckBoxToggled(bool b)
909 f_List->setEnabled(b);
910 f_ntDefBtn->setEnabled(b);
911 f_ntChngBtn->setEnabled(b && (f_List->currentItem()!=-1));
912 if (b) f_List->setFocus();
916 // show font dialog for the entry
917 void OptionsDialog::slotFontItemSelected(Q3ListBoxItem *it)
919 if (it) {
920 FontListItem *fontItem = static_cast<FontListItem*>(it);
921 QFont font = fontItem->font();
922 int result = KFontDialog::getFont(font,false,this);
924 if (result == KFontDialog::Accepted) {
925 fontItem->setFont(font);
926 f_List->triggerUpdate(false);
927 slotChanged();
933 void OptionsDialog::slotFontDefaultBtnClicked()
935 FontListItem *fontItem;
936 for(int i=0; i < global->fontCount(); i++) {
937 fontItem=static_cast<FontListItem*>(f_List->item(i));
938 fontItem->setFont(global->defaultFont(i));
940 f_List->triggerUpdate(false);
944 void OptionsDialog::slotFontChangeBtnClicked()
946 if(f_List->currentItem()!=-1)
947 slotFontItemSelected(f_List->item(f_List->currentItem()));
951 void OptionsDialog::slotFontSelectionChanged()
953 f_ntChngBtn->setEnabled(f_List->currentItem()!=-1);
956 void OptionsDialog::slotChanged()
958 enableButton( Apply, true );
959 configChanged = true;
963 //--------------------------------
965 #include "options.moc"