summaryrefslogtreecommitdiffstats
path: root/katapult/katapult/katapultconfigdlg.cpp
blob: 2ca0fb700dadb02e2f49cec0cdfd1996438d167e (plain)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/***************************************************************************
 *   Copyright (C) 2005 by Joe Ferris                                      *
 *   jferris@optimistictech.com                                            *
 *                                                                         *
 *   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 <tdeactionselector.h>
#include <tdeconfig.h>
#include <tdeapplication.h>
#include <kcombobox.h>
#include <tdelocale.h>

#include <tqframe.h>
#include <tqlayout.h>
#include <tqslider.h>
#include <tqcheckbox.h>
#include <tqstringlist.h>
#include <tqradiobutton.h>
 
#include "katapultconfigdlg.h"
#include "katapultsettings.h"
#include "katapultcatalog.h"
#include "katapultdisplay.h"

#include "confgeneral.h"
#include "confcatalogs.h"
#include "confdisplay.h"

KatapultConfigDlg::KatapultConfigDlg(KatapultSettings *settings)
 : KDialogBase(TreeList, "Configure", Ok|Cancel|Help, Ok)
{
	this->settings = settings;
	setTreeListAutoResize(TRUE);

	// general settings	
	TQFrame *fConfGeneral = addPage(TQString("Katapult"), i18n("General Settings"));
	general = new ConfGeneral(fConfGeneral);
	(new TQVBoxLayout(fConfGeneral, 0, KDialog::spacingHint()))->addWidget(general);
	
	general->hideDelay->setValue(settings->hideDelay());
	general->autoExec->setChecked(settings->isAutoExecute());
	general->noResultsDelay->setValue(settings->noResultsDelay());
	general->systrayIcon->setChecked(settings->systrayIcon());
	switch(settings->noResultsAction()) {
		case KatapultSettings::NR_DoNothing:	general->nrDoNothing->setChecked(TRUE);		break;
		case KatapultSettings::NR_HideDisplay:	general->nrHideDisplay->setChecked(TRUE);	break;
		default:				general->nrClearQuery->setChecked(TRUE);	break;
	}
	connect(general->nrDoNothing, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(nrDoNothingToggled(bool)));
	general->noResultsDelay->setEnabled(!general->nrDoNothing->isChecked());
	
	// catalog settings
	TQFrame *fConfCatalogs = addPage(i18n("Catalogs"), i18n("Enabled Catalogs"));
	catalogConf = new ConfCatalogs(fConfCatalogs);
	(new TQVBoxLayout(fConfCatalogs, 0, KDialog::spacingHint()))->addWidget(catalogConf);
	
	catalogConf->catalogs->selectedListBox()->insertStringList(settings->activeCatalogNames());
	catalogConf->catalogs->availableListBox()->insertStringList(settings->inactiveCatalogNames());
	
	catalogPages.setAutoDelete(TRUE);
	TQDict<KatapultCatalog> catalogs;
	catalogs = settings->activeCatalogs();
	TQDictIterator<KatapultCatalog> it(catalogs);
	KatapultCatalog *catalog;
	while((catalog = it.current()) != 0)
	{
		TQString catalogName = it.currentKey();
		addCatalogPage(catalogName, catalog);
		++it;
	}
	
	// display settings
	TQFrame *fConfDisplay = addPage(i18n("Display"), i18n("Display"));
	display = new ConfDisplay(fConfDisplay);
	(new TQVBoxLayout(fConfDisplay, 0, KDialog::spacingHint()))->addWidget(display);
	new TQVBoxLayout((TQWidget *) display->displaySettings, 0, KDialog::spacingHint());
	
	TQStringList displays = settings->displayNames();
	display->displayName->insertStringList(displays);
	display->displayName->setCurrentItem(settings->displayNumber());
	displayConfig = 0;
	addDisplaySettings();
	
	unfoldTreeList(TRUE);
	
	// connect signals	
	connect(catalogConf->catalogs, TQT_SIGNAL(added(TQListBoxItem *)), this, TQT_SLOT(activateCatalog(TQListBoxItem* )));
	connect(catalogConf->catalogs, TQT_SIGNAL(removed(TQListBoxItem *)), this, TQT_SLOT(deactivateCatalog(TQListBoxItem* )));
	connect(display->displayName, TQT_SIGNAL(activated(int)), this, TQT_SLOT(activateDisplay(int)));
	connect(this, TQT_SIGNAL(okClicked()), this, TQT_SLOT(saveSettings()));
}

KatapultConfigDlg::~KatapultConfigDlg()
{
}

void KatapultConfigDlg::nrDoNothingToggled(bool on)
{
	general->noResultsDelay->setEnabled(!on);
}

void KatapultConfigDlg::saveSettings()
{
	settings->setHideDelay(general->hideDelay->value());
	settings->setAutoExecute(general->autoExec->isChecked());
	settings->setNoResultsDelay(general->noResultsDelay->value());
	settings->setSystrayIcon(general->systrayIcon->isChecked());
	if (general->nrDoNothing->isChecked()) {
		settings->setNoResultsAction(KatapultSettings::NR_DoNothing);
	} else if (general->nrHideDisplay->isChecked()) {
		settings->setNoResultsAction(KatapultSettings::NR_HideDisplay);
	} else {
		settings->setNoResultsAction(KatapultSettings::NR_ClearQuery);
	}
}

void KatapultConfigDlg::activateCatalog(TQListBoxItem *i)
{
	settings->activateCatalog(i->text());
	KatapultCatalog *catalog = settings->catalog(i->text());
	if(catalog != 0)
		addCatalogPage(i->text(), catalog);
}

void KatapultConfigDlg::deactivateCatalog(TQListBoxItem *i)
{
	catalogPages.remove(i->text());
	settings->deactivateCatalog(i->text());
}

void KatapultConfigDlg::activateDisplay(int index)
{
	settings->setDisplayName(settings->displayIds()[index]);
	addDisplaySettings();
}

void KatapultConfigDlg::addCatalogPage(TQString name, KatapultCatalog *catalog)
{
	TQWidget *catalogConfig = catalog->configure();
	if(catalogConfig != 0)
	{
		TQStringList path;
		path << i18n("Catalogs") << name;
		TQFrame *fCatalog = addPage(path, name);
		catalogConfig->reparent(fCatalog, TQPoint(0, 0));
		(new TQVBoxLayout(fCatalog, 0, KDialog::spacingHint()))->addWidget(catalogConfig);
		catalogPages.insert(name, fCatalog);
	}
}

void KatapultConfigDlg::addDisplaySettings()
{
	if(displayConfig != 0)
	{
		delete displayConfig;
		displayConfig = 0;
	}
	displayConfig = settings->display()->configure();
	if(displayConfig != 0)
	{
		displayConfig->reparent((TQWidget *) display->displaySettings, TQPoint(0, 0));
		display->displaySettings->layout()->add(displayConfig);
		displayConfig->show();
	}
}

#include "katapultconfigdlg.moc"