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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
/**
* This file is part of the System Settings package
* Copyright (C) 2005 Benjamin C Meyer (ben+systempreferences at meyerhome dot 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 library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "mainwindow.h"
#include <kstdaction.h>
#include <tqwhatsthis.h>
#include <tqlabel.h>
#include <tqvbox.h>
#include <kaction.h>
#include <tqtoolbutton.h>
#include <klocale.h>
#include <kservicegroup.h>
#include <tqlayout.h>
#include <tqwidgetstack.h>
#include <tqtimer.h>
#include <kiconloader.h>
#include <kcmoduleloader.h>
#include <kdialogbase.h>
#include <kiconviewsearchline.h>
#include <kapplication.h>
#include <kaboutapplication.h>
#include <kdebug.h>
#include <kcmoduleproxy.h>
#include <kbugreport.h>
#include <kmenubar.h>
#include <kactionclasses.h>
#include <ktoolbarbutton.h>
#include <tqtabbar.h>
#include "kcmsearch.h"
#include "modulesview.h"
#include "moduleiconitem.h"
#include "kcmodulemenu.h"
#include "kcmultiwidget.h"
MainWindow::MainWindow(bool embed, const TQString & menuFile,
TQWidget *tqparent, const char *name) :
KMainWindow(tqparent,name), menu(NULL), embeddedWindows(embed),
groupWidget(NULL), selectedPage(0), dummyAbout(NULL) {
// Load the menu structure in from disk.
menu = new KCModuleMenu( menuFile );
moduleTabs = new KTabWidget(this, "moduletabs",
TQTabWidget::Top|TQTabWidget::Rounded);
buildMainWidget();
buildActions();
setupGUI(ToolBar|Save|Create,TQString());
widgetChange();
}
MainWindow::~MainWindow()
{
delete moduleTabs;
delete windowStack;
delete menu;
delete dummyAbout;
}
void MainWindow::buildMainWidget()
{
windowStack = new TQWidgetStack( this, "widgetstack" );
// Top level pages.
TQValueList<MenuItem> subMenus = menu->menuList();
TQValueList<MenuItem>::iterator it;
KCScrollView *modulesScroller;
moduleTabs->show();
for ( it = subMenus.begin(); it != subMenus.end(); ++it ) {
if( (*it).menu ) {
modulesScroller = new KCScrollView(moduleTabs);
ModulesView *modulesView = new ModulesView( menu, (*it).subMenu, modulesScroller->viewport(), "modulesView" );
modulesViewList.append(modulesView);
connect(modulesView, TQT_SIGNAL(itemSelected(TQIconViewItem* )), TQT_TQOBJECT(this), TQT_SLOT(slotItemSelected(TQIconViewItem*)));
modulesScroller->addChild(modulesView);
moduleTabs->addTab(modulesScroller, (*it).caption);
overviewPages.append(modulesScroller);
}
}
windowStack->addWidget(moduleTabs);
windowStack->raiseWidget(moduleTabs);
setCentralWidget(windowStack);
}
void MainWindow::buildActions()
{
KStdAction::quit(TQT_TQOBJECT(this), TQT_SLOT( close() ), actionCollection());
resetModule = new KAction(i18n("Undo Changes"), 0, TQT_TQOBJECT(this),
TQT_SLOT(showAllModules()), actionCollection(), "resetModule" );
resetModule->setEnabled(false);
defaultModule = new KAction(i18n("Reset to Defaults"), 0, TQT_TQOBJECT(this),
TQT_SLOT(showAllModules()), actionCollection(), "defaultModule" );
defaultModule->setEnabled(false);
if( embeddedWindows ) {
showAllAction = new KAction(i18n("Overview"), TQApplication::reverseLayout() ? "forward" : "back", 0, TQT_TQOBJECT(this),
TQT_SLOT(showAllModules()), actionCollection(), "showAll" );
showAllAction->setEnabled(false);
}
aboutModuleAction = new KAction(i18n("About Current Module"), 0, TQT_TQOBJECT(this), TQT_SLOT(aboutCurrentModule()), actionCollection(), "help_about_module");
resetModuleHelp();
// Search
TQHBox *hbox = new TQHBox(0);
hbox->setMaximumWidth( 400 );
KcmSearch* search = new KcmSearch(&modulesViewList, hbox, "search");
hbox->setStretchFactor(search,1);
connect(search, TQT_SIGNAL(searchHits(const TQString &, int *, int)), TQT_TQOBJECT(this), TQT_SLOT(slotSearchHits(const TQString &, int *, int)));
TQVBox *vbox = new TQVBox(hbox);
generalHitLabel = new TQLabel(vbox);
vbox->setStretchFactor(generalHitLabel,1);
advancedHitLabel = new TQLabel(vbox);
vbox->setStretchFactor(advancedHitLabel,1);
hbox->setStretchFactor(vbox,1);
// "Search:" label
TQLabel *searchLabel = new TQLabel( this, "SearchLabel");
searchLabel->setText( i18n("&Search:") );
searchLabel->setFont(KGlobalSettings::toolBarFont());
searchLabel->setMargin(2);
searchText = new KWidgetAction( searchLabel, i18n("&Search:"), Key_F6, 0, 0, actionCollection(), "searchText" );
searchLabel->setBuddy( search );
// The search box.
searchAction = new KWidgetAction( hbox, i18n( "Search System Settings" ), 0,
0, 0, actionCollection(), "search" );
searchAction->setShortcutConfigurable( false );
searchAction->setAutoSized( true );
TQWhatsThis::add( search, i18n( "Search Bar<p>Enter a search term." ) );
// The Clear search box button.
KToolBarButton *clearWidget = new KToolBarButton(TQApplication::reverseLayout() ? "clear_left" : "locationbar_erase",
0, this);
searchClear = new KWidgetAction( clearWidget, TQString(""), CTRL+Key_L, TQT_TQOBJECT(search), TQT_SLOT(clear()),
actionCollection(), "searchReset");
connect(clearWidget, TQT_SIGNAL(clicked()), searchClear, TQT_SLOT(activate()));
searchClear->setWhatsThis( i18n( "Reset Search\n"
"Resets the search so that "
"all items are shown again." ) );
// Top level pages.
TQValueList<MenuItem> subMenus = menu->menuList();
TQValueList<MenuItem>::iterator it;
for ( it = subMenus.begin(); it != subMenus.end(); ++it ) {
if( (*it).menu ) {
KServiceGroup::Ptr group = KServiceGroup::group( (*it).subMenu );
if ( !group ){
kdDebug() << "Invalid Group \"" << (*it).subMenu << "\". Check your installation."<< endl;
continue;
}
KRadioAction *newAction = new KRadioAction( group->caption(), group->icon(), KShortcut(), TQT_TQOBJECT(this),
TQT_SLOT(slotTopPage()), actionCollection(), group->relPath() );
pageActions.append(newAction);
kdDebug() << "relpath is :" << group->relPath() << endl;
}
}
pageActions.at(0)->setChecked(true);
}
void MainWindow::aboutCurrentModule()
{
if(!groupWidget)
return;
KCModuleProxy* module = groupWidget->currentModule();
if( module && module->aboutData() ){
KAboutApplication dlg( module->aboutData() );
dlg.exec();
}
}
void MainWindow::groupModulesFinished()
{
showAllModules();
}
void MainWindow::showAllModules()
{
windowStack->raiseWidget(moduleTabs);
// Reset the widget for normal all widget viewing
groupWidget = 0;
widgetChange();
if( embeddedWindows ) {
showAllAction->setEnabled(false);
}
aboutModuleAction->setEnabled(false);
searchText->setEnabled(true);
searchClear->setEnabled(true);
searchAction->setEnabled(true);
KRadioAction *currentRadioAction;
for ( currentRadioAction = pageActions.first(); currentRadioAction; currentRadioAction = pageActions.next()) {
currentRadioAction->setEnabled(true);
}
resetModuleHelp();
}
void MainWindow::slotItemSelected( TQIconViewItem *item ){
ModuleIconItem *mItem = (ModuleIconItem *)item;
if( !mItem )
return;
groupWidget = moduleItemToWidgetDict.find(mItem);
scrollView = moduleItemToScrollerDict.find(mItem);
if(groupWidget==0) {
TQValueList<KCModuleInfo> list = mItem->modules;
KDialogBase::DialogType type = KDialogBase::IconList;
if(list.count() == 1) {
type=KDialogBase::Plain;
}
scrollView = new KCScrollView(windowStack);
groupWidget = new KCMultiWidget(type, scrollView->viewport(), "moduleswidget");
scrollView->addChild(groupWidget);
windowStack->addWidget(scrollView);
moduleItemToScrollerDict.insert(mItem,scrollView);
moduleItemToWidgetDict.insert(mItem,groupWidget);
connect(groupWidget, TQT_SIGNAL(aboutToShow( KCModuleProxy * )), TQT_TQOBJECT(this), TQT_SLOT(updateModuleHelp( KCModuleProxy * )));
connect(groupWidget, TQT_SIGNAL(aboutToShowPage( TQWidget* )), TQT_TQOBJECT(this), TQT_SLOT(widgetChange()));
connect(groupWidget, TQT_SIGNAL(finished()), TQT_TQOBJECT(this), TQT_SLOT(groupModulesFinished()));
connect(groupWidget, TQT_SIGNAL(close()), TQT_TQOBJECT(this), TQT_SLOT(showAllModules()));
TQValueList<KCModuleInfo>::iterator it;
for ( it = list.begin(); it != list.end(); ++it ){
qDebug("adding %s %s", (*it).moduleName().latin1(), (*it).fileName().latin1());
groupWidget->addModule( *it );
}
groupWidget->reparent(scrollView->viewport(), 0, TQPoint());
scrollView->reparent(windowStack, 0, TQPoint());
}
if( embeddedWindows ) {
windowStack->raiseWidget( scrollView );
setCaption( mItem->text() );
showAllAction->setEnabled(true);
searchText->setEnabled(false);
searchClear->setEnabled(false);
searchAction->setEnabled(false);
KRadioAction *currentRadioAction;
for ( currentRadioAction = pageActions.first(); currentRadioAction; currentRadioAction = pageActions.next()) {
currentRadioAction->setEnabled(false);
}
} else {
scrollView->show();
}
groupWidget->show();
// We resize and expand the window if neccessary, but only once the window has been updated.
// Some modules seem to dynamically change thier size. The new size is only available
// once the dialog is updated. :-/ -SBE
TQTimer::singleShot(0,this,TQT_SLOT(timerResize()));
}
void MainWindow::timerResize() {
TQSize currentSize = size();
TQSize newSize = currentSize.expandedTo(tqsizeHint());
// Avoid resizing if possible.
if(newSize!=currentSize) {
resize(newSize);
}
}
void MainWindow::updateModuleHelp( KCModuleProxy *currentModule ) {
if ( currentModule->aboutData() ) {
aboutModuleAction->setText(i18n("Help menu->about <modulename>", "About %1").tqarg(
currentModule->moduleInfo().moduleName().replace("&","&&")));
aboutModuleAction->setIcon(currentModule->moduleInfo().icon());
aboutModuleAction->setEnabled(true);
}
else {
resetModuleHelp();
}
}
void MainWindow::resetModuleHelp() {
aboutModuleAction->setText(i18n("About Current Module"));
aboutModuleAction->setIconSet(TQIconSet());
aboutModuleAction->setEnabled(false);
}
void MainWindow::widgetChange() {
TQString name;
if( groupWidget && groupWidget->currentModule()) {
name = groupWidget->currentModule()->moduleInfo().moduleName();
}
if( !groupWidget ) {
setCaption( "" );
ModulesView *modulesView;
for( modulesView = modulesViewList.first(); modulesView; modulesView = modulesViewList.next()) {
modulesView->clearSelection();
}
}
}
void MainWindow::slotTopPage() {
KRadioAction *clickedRadioAction = (KRadioAction *)sender();
selectedPage = pageActions.find(clickedRadioAction);
KRadioAction *currentRadioAction;
for ( currentRadioAction = pageActions.first(); currentRadioAction; currentRadioAction = pageActions.next()) {
currentRadioAction->setChecked(currentRadioAction==clickedRadioAction);
}
windowStack->raiseWidget(overviewPages.at(selectedPage));
}
void MainWindow::slotSearchHits(const TQString &query, int *hitList, int length) {
if(query=="") {
generalHitLabel->setText("");
advancedHitLabel->setText("");
} else {
if(length>=1) {
generalHitLabel->setText(i18n("%1 hit in General","%1 hits in General",hitList[0]).tqarg(hitList[0]));
}
if(length>=2) {
advancedHitLabel->setText(i18n("%1 hit in Advanced","%1 hits in Advanced",hitList[1]).tqarg(hitList[1]));
}
}
}
#include "mainwindow.moc"
|