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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
|
/*
Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
Copyright (c) 2000 Matthias Elter <elter@kde.org>
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 <tdeapplication.h>
#include <kstandarddirs.h>
#include <tdeconfig.h>
#include <kbugreport.h>
#include <tdeaboutapplication.h>
#include <tdemessagebox.h>
#include <kinstance.h>
#include <tdeaction.h>
#include <twin.h>
#include <kiconloader.h>
#include <klineedit.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqpushbutton.h>
#include <tqtabwidget.h>
#include <tqtooltip.h>
#include <tqwhatsthis.h>
#include "indexwidget.h"
#include "searchwidget.h"
#include "helpwidget.h"
#include "aboutwidget.h"
#include "proxywidget.h"
#include "moduletreeview.h"
#include <stdio.h>
#include "toplevel.h"
#include "toplevel.moc"
TopLevel::TopLevel(const char* name)
: TDEMainWindow( 0, name, (WFlags)WStyle_ContextHelp )
, _active(0), dummyAbout(0)
{
setCaption(TQString::null);
report_bug = 0;
// read settings
TDEConfig *config = TDEGlobal::config();
config->setGroup("Index");
TQString viewmode = config->readEntry("ViewMode", "Tree");
if (viewmode == "Tree")
KCGlobal::setViewMode(Tree);
else
KCGlobal::setViewMode(Icon);
TQString size = config->readEntry("IconSize", "Medium");
if (size == "Small")
KCGlobal::setIconSize(TDEIcon::SizeSmall);
else if (size == "Large")
KCGlobal::setIconSize(TDEIcon::SizeLarge);
else if (size == "Huge")
KCGlobal::setIconSize(TDEIcon::SizeHuge);
else
KCGlobal::setIconSize(TDEIcon::SizeMedium);
// initialize the entries
_modules = new ConfigModuleList();
_modules->readDesktopEntries();
for ( ConfigModule* m = _modules->first(); m; m = _modules->next() ) {
connect( m, TQT_SIGNAL( handbookRequest() ), this, TQT_SLOT( slotHandbookRequest() ) );
connect( m, TQT_SIGNAL( helpRequest() ), this, TQT_SLOT( slotHelpRequest() ) );
}
// create the layout box
_splitter = new TQSplitter( TQt::Horizontal, this );
TQFrame* leftFrame = new TQFrame ( _splitter );
TQBoxLayout *leftFrameLayout = new TQVBoxLayout( leftFrame );
TQFrame* mSearchFrame = new TQFrame( leftFrame );
leftFrameLayout->addWidget( mSearchFrame );
TQBoxLayout *searchLayout = new TQHBoxLayout( mSearchFrame );
searchLayout->setSpacing( KDialog::spacingHint() );
searchLayout->setMargin( 6 );
TQPushButton *clearButton = new TQPushButton( mSearchFrame );
clearButton->setIconSet( TDEApplication::reverseLayout() ?
SmallIconSet( "clear_left" ) : SmallIconSet("locationbar_erase") );
searchLayout->addWidget( clearButton );
TQToolTip::add( clearButton, i18n("Clear search") );
TQLabel *label = new TQLabel(i18n("Search:"), mSearchFrame );
searchLayout->addWidget( label );
KLineEdit *searchEdit = new KLineEdit( mSearchFrame );
clearButton->setFixedHeight( searchEdit->height() );
connect( clearButton, TQT_SIGNAL( clicked() ), searchEdit, TQT_SLOT( clear() ) );
label->setBuddy( searchEdit );
searchLayout->addWidget( searchEdit );
connect( searchEdit, TQT_SIGNAL( textChanged( const TQString & ) ),
TQT_SLOT( slotSearchChanged(const TQString &) ) );
// create the left hand side under search
_stack = new TQWidgetStack( leftFrame );
leftFrameLayout->addWidget( _stack );
// index tab
_index = new IndexWidget(_modules, this);
connect(_index, TQT_SIGNAL(moduleActivated(ConfigModule*)),
this, TQT_SLOT(activateModule(ConfigModule*)));
_stack->addWidget( _index );
connect(_index, TQT_SIGNAL(categorySelected(TQListViewItem*)),
this, TQT_SLOT(categorySelected(TQListViewItem*)));
// search tab
_search = new SearchWidget(this);
_search->populateKeywordList(_modules);
connect(_search, TQT_SIGNAL(moduleSelected(ConfigModule *)),
this, TQT_SLOT(activateModule(ConfigModule *)));
_stack->addWidget( _search );
// set up the right hand side (the docking area)
_dock = new DockContainer( _splitter );
// help widget
_help = new HelpWidget(_dock);
_stack->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Expanding ) );
// Restore sizes
config->setGroup("General");
TQValueList<int> sizes = config->readIntListEntry( "SplitterSizes" );
if (!sizes.isEmpty())
_splitter->setSizes(sizes);
// That one does the trick ...
_splitter->setResizeMode( leftFrame, TQSplitter::KeepSize );
connect(_dock, TQT_SIGNAL(newModule(const TQString&, const TQString&, const TQString&)),
this, TQT_SLOT(newModule(const TQString&, const TQString&, const TQString&)));
connect(_dock, TQT_SIGNAL(changedModule(ConfigModule*)),
TQT_SLOT(changedModule(ConfigModule*)));
// set the main view
setCentralWidget( _splitter );
// initialize the GUI actions
setupActions();
// activate defaults
if (KCGlobal::viewMode() == Tree) {
activateTreeView();
tree_view->setChecked(true);
}
else {
activateIconView();
icon_view->setChecked(true);
}
// insert the about widget
if (KCGlobal::isInfoCenter())
{
AboutWidget *aw = new AboutWidget( this, 0, _index->firstTreeViewItem());
connect( aw, TQT_SIGNAL( moduleSelected( ConfigModule * ) ),
TQT_SLOT( activateModule( ConfigModule * ) ) );
_dock->setBaseWidget( aw );
KWin::setIcons( winId(),
TDEGlobal::iconLoader()->loadIcon("hwinfo", TDEIcon::NoGroup, 32 ),
TDEGlobal::iconLoader()->loadIcon("hwinfo", TDEIcon::NoGroup, 16 ) );
}
else
{
AboutWidget *aw = new AboutWidget(this);
connect( aw, TQT_SIGNAL( moduleSelected( ConfigModule * ) ),
TQT_SLOT( activateModule( ConfigModule * ) ) );
_dock->setBaseWidget(aw);
}
}
TopLevel::~TopLevel()
{
TDEConfig *config = TDEGlobal::config();
config->setGroup("Index");
if (KCGlobal::viewMode() == Tree)
config->writeEntry("ViewMode", "Tree");
else
config->writeEntry("ViewMode", "Icon");
switch (KCGlobal::iconSize())
{
case TDEIcon::SizeSmall:
config->writeEntry("IconSize", "Small");
break;
case TDEIcon::SizeLarge:
config->writeEntry("IconSize", "Large");
break;
case TDEIcon::SizeHuge:
config->writeEntry("IconSize", "Huge");
break;
default:
config->writeEntry("IconSize", "Medium");
break;
}
config->setGroup("General");
config->writeEntry("SplitterSizes", _splitter->sizes());
config->sync();
delete _modules;
}
bool TopLevel::queryClose()
{
return _dock->dockModule(0);
}
void TopLevel::setupActions()
{
KStdAction::quit(this, TQT_SLOT(close()), actionCollection());
KStdAction::keyBindings(guiFactory(), TQT_SLOT(configureShortcuts()),
actionCollection());
icon_view = new TDERadioAction
(i18n("&Icon View"), 0, this, TQT_SLOT(activateIconView()),
actionCollection(), "activate_iconview");
icon_view->setExclusiveGroup( "viewmode" );
tree_view = new TDERadioAction
(i18n("&Tree View"), 0, this, TQT_SLOT(activateTreeView()),
actionCollection(), "activate_treeview");
tree_view->setExclusiveGroup( "viewmode" );
icon_small = new TDERadioAction
(i18n("&Small"), 0, this, TQT_SLOT(activateSmallIcons()),
actionCollection(), "activate_smallicons");
icon_small->setExclusiveGroup( "iconsize" );
icon_medium = new TDERadioAction
(i18n("&Medium"), 0, this, TQT_SLOT(activateMediumIcons()),
actionCollection(), "activate_mediumicons");
icon_medium->setExclusiveGroup( "iconsize" );
icon_large = new TDERadioAction
(i18n("&Large"), 0, this, TQT_SLOT(activateLargeIcons()),
actionCollection(), "activate_largeicons");
icon_large->setExclusiveGroup( "iconsize" );
icon_huge = new TDERadioAction
(i18n("&Huge"), 0, this, TQT_SLOT(activateHugeIcons()),
actionCollection(), "activate_hugeicons");
icon_huge->setExclusiveGroup( "iconsize" );
about_module = new TDEAction(i18n("About Current Module"), 0, this, TQT_SLOT(aboutModule()), actionCollection(), "help_about_module");
about_module->setEnabled(false);
createGUI("kcontrolui.rc");
report_bug = actionCollection()->action("help_report_bug");
report_bug->setText(i18n("&Report Bug..."));
report_bug->disconnect();
connect(report_bug, TQT_SIGNAL(activated()), TQT_SLOT(reportBug()));
}
void TopLevel::activateIconView()
{
KCGlobal::setViewMode(Icon);
_index->activateView(Icon);
icon_small->setEnabled(true);
icon_medium->setEnabled(true);
icon_large->setEnabled(true);
icon_huge->setEnabled(true);
switch(KCGlobal::iconSize())
{
case TDEIcon::SizeSmall:
icon_small->setChecked(true);
break;
case TDEIcon::SizeLarge:
icon_large->setChecked(true);
break;
case TDEIcon::SizeHuge:
icon_huge->setChecked(true);
break;
default:
icon_medium->setChecked(true);
break;
}
}
void TopLevel::activateTreeView()
{
KCGlobal::setViewMode(Tree);
_index->activateView(Tree);
icon_small->setEnabled(false);
icon_medium->setEnabled(false);
icon_large->setEnabled(false);
icon_huge->setEnabled(false);
}
void TopLevel::activateSmallIcons()
{
KCGlobal::setIconSize(TDEIcon::SizeSmall);
_index->reload();
}
void TopLevel::activateMediumIcons()
{
KCGlobal::setIconSize(TDEIcon::SizeMedium);
_index->reload();
}
void TopLevel::activateLargeIcons()
{
KCGlobal::setIconSize(TDEIcon::SizeLarge);
_index->reload();
}
void TopLevel::activateHugeIcons()
{
KCGlobal::setIconSize(TDEIcon::SizeHuge);
_index->reload();
}
void TopLevel::newModule(const TQString &name, const TQString& docPath, const TQString &quickhelp)
{
setCaption(name, false);
_help->setText( docPath, quickhelp );
if (!report_bug) return;
if(name.isEmpty())
report_bug->setText(i18n("&Report Bug..."));
else
report_bug->setText(i18n("Report Bug on Module %1...").arg( handleAmpersand( name)));
}
void TopLevel::changedModule(ConfigModule *changed)
{
if (!changed)
return;
setCaption(changed->moduleName(), changed->isChanged() );
}
void TopLevel::categorySelected(TQListViewItem *category)
{
if (_active)
{
if (_active->isChanged())
{
int res = KMessageBox::warningYesNoCancel(this, _active ?
i18n("There are unsaved changes in the active module.\n"
"Do you want to apply the changes before running "
"the new module or discard the changes?") :
i18n("There are unsaved changes in the active module.\n"
"Do you want to apply the changes before exiting "
"the Control Center or discard the changes?"),
i18n("Unsaved Changes"),
KStdGuiItem::apply(),
KStdGuiItem::discard());
if (res == KMessageBox::Yes)
_active->module()->applyClicked();
else if (res == KMessageBox::Cancel)
return;
}
}
_dock->removeModule();
about_module->setText( i18n( "About Current Module" ) );
about_module->setIconSet( TQIconSet() );
about_module->setEnabled( false );
// insert the about widget
TQListViewItem *firstItem = category->firstChild();
TQString caption = static_cast<ModuleTreeItem*>(category)->caption();
TQString icon = static_cast<ModuleTreeItem*>(category)->icon();
if( _dock->baseWidget()->isA( "AboutWidget" ) )
{
static_cast<AboutWidget *>( _dock->baseWidget() )->setCategory( firstItem, icon, caption);
}
else
{
AboutWidget *aw = new AboutWidget( this, 0, firstItem, caption );
connect( aw, TQT_SIGNAL( moduleSelected( ConfigModule * ) ),
TQT_SLOT( activateModule( ConfigModule * ) ) );
_dock->setBaseWidget( aw );
}
}
void TopLevel::activateModule(ConfigModule *mod)
{
if ( _dock->module() == mod )
return;
// tell the index to display the module
_index->makeVisible(mod);
// tell the index to mark this module as loaded
_index->makeSelected(mod);
// dock it
if (!_dock->dockModule(mod))
{
if ( _dock->module() )
{
_index->makeVisible(_active);
_index->makeSelected(_active);
}
return;
}
_active=mod;
if (mod->aboutData())
{
about_module->setText(i18n("Help menu->about <modulename>", "About %1").arg(
handleAmpersand( mod->moduleName())));
about_module->setIcon(mod->icon());
about_module->setEnabled(true);
}
else
{
about_module->setText(i18n("About Current Module"));
about_module->setIconSet(TQIconSet());
about_module->setEnabled(false);
}
}
void TopLevel::deleteDummyAbout()
{
delete dummyAbout;
dummyAbout = 0;
}
void TopLevel::slotSearchChanged(const TQString& search)
{
if (search.isEmpty())
_stack->raiseWidget(_index);
else
{
_stack->raiseWidget(_search);
_search->searchTextChanged(search);
}
}
void TopLevel::slotHelpRequest()
{
_help->display(_help->text(), TQCursor::pos ( ), _dock);
}
void TopLevel::slotHandbookRequest()
{
_help->handbookRequest();
}
void TopLevel::reportBug()
{
// this assumes the user only opens one bug report at a time
static char buffer[128];
dummyAbout = 0;
bool deleteit = false;
if (!_active) // report against kcontrol
dummyAbout = const_cast<TDEAboutData*>(TDEGlobal::instance()->aboutData());
else
{
if (_active->aboutData())
dummyAbout = const_cast<TDEAboutData*>(_active->aboutData());
else
{
snprintf(buffer, sizeof(buffer), "kcm%s", _active->library().latin1());
dummyAbout = new TDEAboutData(buffer, _active->moduleName().utf8(), "2.0");
deleteit = true;
}
}
KBugReport *br = new KBugReport(this, false, dummyAbout);
if (deleteit)
connect(br, TQT_SIGNAL(finished()), TQT_SLOT(deleteDummyAbout()));
else
dummyAbout = 0;
br->show();
}
void TopLevel::aboutModule()
{
TDEAboutApplication dlg(_active->aboutData());
dlg.exec();
}
TQString TopLevel::handleAmpersand( TQString modulename ) const
{
if( modulename.contains( '&' )) // double it
{
for( int i = modulename.length();
i >= 0;
--i )
if( modulename[ i ] == '&' )
modulename.insert( i, "&" );
}
return modulename;
}
|