Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / kinfocenter / modules.cpp
blob653c21bfa8ef30f1e03f2af581a1bc798a2887c1
1 /*
2 Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "modules.h"
20 #include "global.h"
21 #include "proxywidget.h"
23 #include <kapplication.h>
24 #include <kdebug.h>
25 #include <kservicegroup.h>
26 #include <k3process.h>
27 #include <klocale.h>
28 #include <kstandarddirs.h>
29 #include <kauthorized.h>
30 #include <kservicetypetrader.h>
31 #include <kcmoduleloader.h>
32 #include <kvbox.h>
34 #include <QLabel>
35 #include <QVBoxLayout>
36 #include <QFrame>
38 #ifdef Q_WS_X11
39 #include <X11/Xlib.h>
40 #include <QX11Info>
41 #include <QX11EmbedWidget>
42 #endif
43 #include <unistd.h>
44 #include <sys/types.h>
46 #include "modules.moc"
48 ConfigModule::ConfigModule(const KService::Ptr &s) :
49 KCModuleInfo(s), _module(0) {
52 ConfigModule::~ConfigModule() {
53 deleteClient();
56 ProxyWidget *ConfigModule::module() {
57 if (_module)
58 return _module;
60 kDebug() << "Finding proxy..." << endl;
62 KCModule *modWidget = 0;
64 modWidget = KCModuleLoader::loadModule(*this,/*KCModuleLoader::None*/(KCModuleLoader::ErrorReporting)NULL);
66 if (modWidget==NULL) {
68 kWarning() << "Unable to load KCM Module" << endl;
69 return NULL;
72 _module = new ProxyWidget(modWidget);
74 return _module;
77 QPixmap ConfigModule::realIcon(KIconLoader::StdSizes size) {
78 //The next line is identical as SmallIcon(module->icon()), but is able to return a isNull() QPixmap
79 QPixmap providedIcon = KIconLoader::global()->loadIcon(icon(), KIconLoader::Small, size, KIconLoader::DefaultState, QStringList(), 0L, true);
80 if (providedIcon.isNull()) {
81 kDebug() << "Icon is null" << icon() << endl;
82 return SmallIcon("computer", size);
85 return providedIcon;
89 void ConfigModule::deleteClient() {
90 kapp->syncX();
92 if (_module)
93 _module->close();
94 _module = NULL;
98 const KAboutData *ConfigModule::aboutData() const {
99 if (!_module)
100 return 0;
101 return _module->aboutData();
104 ConfigModuleList::ConfigModuleList() {
105 foreach(ConfigModule* configModule, *this) {
106 delete configModule;
109 this->clear();
112 bool ConfigModuleList::readDesktopEntries() {
113 KService::List list = KServiceTypeTrader::self()->query("KCModule", "[X-KDE-ParentApp] == 'kinfocenter'");
115 if (list.isEmpty()) {
116 return false;
119 foreach(const KService::Ptr &s, list) {
120 if (s->isType(KST_KService) == false) {
121 continue;
124 if (!KAuthorized::authorizeControlModule(s->menuId())) {
125 continue;
128 ConfigModule *module = new ConfigModule(s);
129 if (module->library().isEmpty()) {
130 delete module;
131 continue;
134 append(module);
138 return true;