2 Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
3 Copyright (c) 2000 Matthias Elter <elter@kde.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 #include "indexwidget.h"
23 #include "aboutwidget.h"
24 #include "proxywidget.h"
25 #include "moduletreeview.h"
28 #include <kaboutapplicationdialog.h>
29 #include <kactioncollection.h>
30 #include <kbugreport.h>
31 #include <kaboutdata.h>
33 #include <kcomponentdata.h>
35 #include <kiconloader.h>
37 #include <kmessagebox.h>
38 #include <kstandarddirs.h>
39 #include <kstandardaction.h>
40 #include <ktoggleaction.h>
41 #include <kwindowsystem.h>
42 #include <kxmlguifactory.h>
51 #include "toplevel.moc"
53 TopLevel::TopLevel() :
54 KXmlGuiWindow( 0, Qt::WindowContextHelpButtonHint
), _active(NULL
), dummyAbout(NULL
) {
55 setCaption(QString());
59 // initialize the entries
60 _modules
= new ConfigModuleList();
61 _modules
->readDesktopEntries();
63 // create the layout box
64 _splitter
= new QSplitter( Qt::Horizontal
, this );
65 _splitter
->setContentsMargins(0, 0, 0, 0);
68 _indextab
= new IndexWidget(_modules
, this);
69 connect(_indextab
, SIGNAL(moduleActivated(ConfigModule
*)), this, SLOT(activateModule(ConfigModule
*)));
70 connect(_indextab
, SIGNAL(generalActivated()), this, SLOT(activateGeneral()));
71 _splitter
->addWidget(_indextab
);
73 _indextab
->setSizePolicy(QSizePolicy(QSizePolicy::Maximum
, QSizePolicy::Preferred
) );
76 KConfigGroup config
= KConfigGroup(KGlobal::config(), "General");
77 QList
<int> sizes
= config
.readEntry("SplitterSizes", QList
<int>() );
79 _splitter
->setSizes(sizes
);
81 AboutWidget
* aboutWidget
= new AboutWidget( this, _modules
);
82 connect(aboutWidget
, SIGNAL( moduleSelected( ConfigModule
* ) ), _indextab
, SLOT(selectModule(ConfigModule
*)));
84 // set up the right hand side (the docking area)
85 _dock
= new DockContainer(aboutWidget
, _splitter
);
87 // That one does the trick ...
88 _splitter
->setStretchFactor(_splitter
->indexOf(_indextab
), 0);
89 _splitter
->setStretchFactor(_splitter
->indexOf(_dock
), 1);
91 connect(_indextab
, SIGNAL(generalActivated()), _dock
, SLOT(showAboutWidget()));
94 setCentralWidget(_splitter
);
96 // initialize the GUI actions
99 KWindowSystem::setIcons(winId(), KIconLoader::global()->loadIcon(KINFOCENTER_ICON_NAME
, KIconLoader::NoGroup
, 32), KIconLoader::global()->loadIcon("hwinfo", KIconLoader::NoGroup
, 16) );
101 _indextab
->selectGeneral();
104 TopLevel::~TopLevel() {
106 KConfigGroup config
= KConfigGroup(KGlobal::config(), "General");
107 config
.writeEntry("SplitterSizes", _splitter
->sizes());
114 void TopLevel::setupActions() {
115 KStandardAction::quit(this, SLOT(close()), actionCollection());
116 KStandardAction::keyBindings(guiFactory(), SLOT(configureShortcuts()), actionCollection());
118 about_module
= actionCollection()->addAction("help_about_module");
119 about_module
->setText(i18n("About Current Module"));
120 about_module
->setVisible(false);
121 connect(about_module
, SIGNAL(triggered(bool) ), SLOT(aboutModule()));
123 createGUI("kinfocenterui.rc");
125 report_bug
= actionCollection()->action("help_report_bug");
126 report_bug
->setText(i18n("&Report Bug..."));
127 report_bug
->disconnect();
128 connect(report_bug
, SIGNAL(triggered()), SLOT(reportBug()));
131 void TopLevel::activateModule(ConfigModule
*configModule
) {
132 kDebug() << "Activating module..." << endl
;
134 _active
=configModule
;
137 if (!_dock
->dockModule(configModule
)) {
138 kDebug() << "Activating module by docking it." << endl
;
143 kDebug() << "Modifying About Module." << endl
;
145 if (configModule
->aboutData()) {
146 about_module
->setText(i18nc("Help menu->about <modulename>", "About %1", handleAmpersand(configModule
->moduleName())));
147 about_module
->setIcon(configModule
->realIcon(KIconLoader::SizeSmall
));
148 about_module
->setVisible(true);
150 about_module
->setText(i18n("About Current Module"));
151 about_module
->setIcon(KIcon());
152 about_module
->setVisible(false);
155 setCaption(configModule
->moduleName(), false);
157 if (configModule
->moduleName().isEmpty())
158 report_bug
->setText(i18n("&Report Bug..."));
160 report_bug
->setText(i18n("Report Bug on Module %1...", handleAmpersand(configModule
->moduleName())));
163 kDebug() << "Activating module done." << endl
;
166 void TopLevel::deleteDummyAbout() {
171 void TopLevel::reportBug() {
173 bool deleteit
= false;
175 if (!_active
) // report against kinfocenter
176 dummyAbout
= const_cast<KAboutData
*>(KGlobal::mainComponent().aboutData());
178 if (_active
->aboutData())
179 dummyAbout
= const_cast<KAboutData
*>(_active
->aboutData());
181 QString kcmLibrary
= "kcm" + _active
->library();
182 dummyAbout
= new KAboutData(kcmLibrary
.toLatin1(), 0, ki18n(_active
->moduleName().toUtf8()), "2.0");
186 KBugReport
*br
= new KBugReport(this, false, dummyAbout
);
188 connect(br
, SIGNAL(finished()), SLOT(deleteDummyAbout()));
195 void TopLevel::aboutModule() {
196 kDebug() << "About " << _active
->moduleName() << endl
;
198 KAboutApplicationDialog
dlg(_active
->aboutData());
202 QString
TopLevel::handleAmpersand(const QString
& modName
) const {
203 QString modulename
= modName
;
205 if (modulename
.contains( '&')) {
206 for (int i
= modulename
.length(); i
>= 0; --i
)
207 if (modulename
[ i
] == '&')
208 modulename
.insert(i
, "&");
214 void TopLevel::activateGeneral() {
215 kDebug() << "Activating General..." << endl
;
217 about_module
->setText(i18n("About Current Module"));
218 about_module
->setIcon(KIcon());
219 about_module
->setVisible(false);
221 setCaption(i18n("General Information"), false);
223 report_bug
->setText(i18n("&Report Bug..."));