• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KUtils

  • kutils
kcmoduleproxy.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 Copyright (C) 2004 Frans Englich <frans.englich@telia.com>
3 Copyright (C) 2003 Matthias Kretz <kretz@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
8
9 This library 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 GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include "kcmoduleproxy.h"
21#include "kcmoduleproxy_p.h"
22
23#include <QtGui/QApplication>
24#include <QtGui/QCursor>
25#include <QtCore/QDataStream>
26#include <QtGui/QKeyEvent>
27#include <QtCore/QFileInfo>
28#include <QtGui/QFrame>
29#include <QtGui/QLabel>
30#include <QtGui/QLayout>
31#include <QtCore/QPoint>
32
33#include <QtGui/QImage>
34
35#include <QtDBus/QtDBus>
36
37#include <kaboutdata.h>
38#include <kcmodule.h>
39#include <kcmoduleinfo.h>
40
41#include <kdebug.h>
42#include <kdialog.h>
43#include <klocale.h>
44#include <kservice.h>
45#include <kstandarddirs.h>
46#include <kuser.h>
47
48#include <kvbox.h>
49
50#include <kcmoduleloader.h>
51
52#include "kcolorscheme.h"
53
54#include "ksettingswidgetadaptor.h"
55
56/*
57 TODO:
58
59 - Two Layout problems in runAsRoot:
60 * lblBusy doesn't show
61 * d->kcm/d->rootInfo doesn't get it right when the user
62 presses cancel in the kdesu dialog
63
64 - Resizing horizontally is contrained; minimum size is set somewhere.
65 It appears to be somehow derived from the module's size.
66
67 - Prettify: set icon in KCMultiDialog.
68
69 */
70/***************************************************************/
71KCModule* KCModuleProxy::realModule() const
72{
73 Q_D(const KCModuleProxy);
74 /*
75 * Note, don't call any function that calls realModule() since
76 * that leads to an infinite loop.
77 */
78
79 /* Already loaded */
80 if( !d->kcm )
81 {
82 QApplication::setOverrideCursor( Qt::WaitCursor );
83 const_cast<KCModuleProxyPrivate *>(d)->loadModule();
84 QApplication::restoreOverrideCursor();
85 }
86 return d->kcm;
87}
88
89void KCModuleProxyPrivate::loadModule()
90{
91 if( !topLayout )
92 {
93 topLayout = new QVBoxLayout( parent );
94 topLayout->setMargin( 0 );
95
96 QString name = modInfo.handle();
97 name.replace("-", "_"); //hyphen is not allowed in dbus, only [A-Z][a-z][0-9]_
98 dbusPath = QLatin1String("/internal/KSettingsWidget/") + name;
99 dbusService = QLatin1String("org.kde.internal.KSettingsWidget_") + name;
100 }
101
102 if( QDBusConnection::sessionBus().registerService( dbusService ) || bogusOccupier )
103 { /* We got the name we requested, because no one was before us,
104 * or, it was an random application which had picked that name */
105 kDebug(711) << "Module not already loaded, loading module " << modInfo.moduleName() << " from library " << modInfo.library() << " using symbol " << modInfo.handle();
106
107 kcm = KCModuleLoader::loadModule( modInfo, KCModuleLoader::Inline, parent, args );
108
109 QObject::connect(kcm, SIGNAL(changed(bool)), parent, SLOT(_k_moduleChanged(bool)));
110 QObject::connect(kcm, SIGNAL(destroyed()), parent, SLOT(_k_moduleDestroyed()));
111 QObject::connect( kcm, SIGNAL(quickHelpChanged()), parent, SIGNAL(quickHelpChanged()) );
112 parent->setWhatsThis( kcm->quickHelp() );
113
114 if ( kcm->layout() ) {
115 kcm->layout()->setMargin( 0 );
116 }
117 topLayout->addWidget( kcm );
118 if( !modInfo.handle().isEmpty() )
119 QDBusConnection::sessionBus().registerObject(dbusPath, new KSettingsWidgetAdaptor(parent), QDBusConnection::ExportAllSlots);
120
121 if ( !rootInfo && /* If it's not already done */
122 kcm->useRootOnlyMessage() && /* kcm wants root message */
123 !KUser().isSuperUser() ) /* Not necessary if we're root */
124 {
125 /*rootInfo = new QLabel( parent );
126 topLayout->insertWidget( 0, rootInfo );
127
128 QPalette palette = rootInfo->palette();
129 KStatefulBrush stbrush(KColorScheme::Window, KColorScheme::NeutralBackground);
130 qDebug() << stbrush.brush(rootInfo);
131 palette.setBrush(QPalette::Window, stbrush.brush(rootInfo));
132 rootInfo->setPalette(palette);
133 rootInfo->setAutoFillBackground(true);
134
135 const QString message = kcm->rootOnlyMessage();
136 if( message.isEmpty() )
137 rootInfo->setText( i18n(
138 "<b>Changes in this section require root access.</b><br />"
139 "On applying your changes you will have to supply your root "
140 "password." ) );
141 else
142 rootInfo->setText(message);
143
144 rootInfo->setWhatsThis( i18n(
145 "This section requires special permissions, probably "
146 "for system-wide changes; therefore, it is "
147 "required that you provide the root password to be "
148 "able to change the module's properties. If "
149 "you cannot provide the password, the changes of the "
150 "module cannot be saved " ) );*/
151 }
152 }
153 else
154 {
155 kDebug(711) << "Module already loaded, loading KCMError";
156
157 /* Figure out the name of where the module is already loaded */
158 QDBusInterface proxy( dbusService, dbusPath, "org.kde.internal.KSettingsWidget" );
159 QDBusReply<QString> reply = proxy.call("applicationName");
160
161 if( reply.isValid() )
162 {
163 QObject::connect( QDBusConnection::sessionBus().interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)),
164 parent, SLOT(_k_ownerChanged(QString,QString,QString)));
165 kcm = KCModuleLoader::reportError( KCModuleLoader::Inline,
166 i18nc( "Argument is application name", "This configuration section is "
167 "already opened in %1" , reply.value() ), " ", parent );
168 topLayout->addWidget( kcm );
169 }
170 else
171 {
172 kDebug(711) << "Calling KCModuleProxy's DBus interface for fetching the name failed.";
173 bogusOccupier = true;
174 loadModule();
175 }
176 }
177}
178
179void KCModuleProxyPrivate::_k_ownerChanged(const QString &service, const QString &oldOwner, const QString &)
180{
181 if (service == dbusService && !oldOwner.isEmpty()) {
182 // Violence: Get rid of KCMError & CO, so that
183 // realModule() attempts to reload the module
184 delete kcm;
185 kcm = 0;
186 Q_Q(KCModuleProxy);
187 q->realModule();
188
189 Q_ASSERT(kcm);
190 kcm->show();
191 }
192}
193
194void KCModuleProxy::showEvent( QShowEvent * ev )
195{
196 Q_D(KCModuleProxy);
197
198 ( void )realModule();
199
200 /* We have no kcm, if we're in root mode */
201 if( d->kcm ) {
202 d->kcm->showEvent(ev);
203 }
204
205 QWidget::showEvent( ev );
206
207}
208
209KCModuleProxy::~KCModuleProxy()
210{
211 deleteClient();
212 KCModuleLoader::unloadModule(moduleInfo());
213
214 delete d_ptr;
215}
216
217void KCModuleProxy::deleteClient()
218{
219 Q_D(KCModuleProxy);
220 delete d->kcm;
221 d->kcm = 0;
222
223 qApp->syncX();
224}
225
226void KCModuleProxyPrivate::_k_moduleChanged(bool c)
227{
228 if(changed == c) {
229 return;
230 }
231
232 Q_Q(KCModuleProxy);
233 changed = c;
234 emit q->changed(c);
235 emit q->changed(q);
236}
237
238void KCModuleProxyPrivate::_k_moduleDestroyed()
239{
240 kcm = 0;
241}
242
243KCModuleProxy::KCModuleProxy( const KService::Ptr& service, QWidget * parent,
244 const QStringList& args )
245 : QWidget(parent), d_ptr(new KCModuleProxyPrivate(this, KCModuleInfo(service), args))
246{
247 d_ptr->q_ptr = this;
248}
249
250KCModuleProxy::KCModuleProxy( const KCModuleInfo& info, QWidget * parent,
251 const QStringList& args )
252 : QWidget(parent), d_ptr(new KCModuleProxyPrivate(this, info, args))
253{
254 d_ptr->q_ptr = this;
255}
256
257KCModuleProxy::KCModuleProxy( const QString& serviceName, QWidget * parent,
258 const QStringList& args )
259 : QWidget(parent), d_ptr(new KCModuleProxyPrivate(this, KCModuleInfo(serviceName), args))
260{
261 d_ptr->q_ptr = this;
262}
263
264
265void KCModuleProxy::load()
266{
267 Q_D(KCModuleProxy);
268 if( realModule() )
269 {
270 d->kcm->load();
271 d->_k_moduleChanged(false);
272 }
273}
274
275void KCModuleProxy::save()
276{
277 Q_D(KCModuleProxy);
278 if( d->changed && realModule() )
279 {
280 d->kcm->save();
281 d->_k_moduleChanged(false);
282 }
283}
284
285void KCModuleProxy::defaults()
286{
287 Q_D(KCModuleProxy);
288 if( realModule() )
289 d->kcm->defaults();
290}
291
292QString KCModuleProxy::quickHelp() const
293{
294 return realModule() ? realModule()->quickHelp() : QString();
295}
296
297const KAboutData * KCModuleProxy::aboutData() const
298{
299 return realModule() ? realModule()->aboutData() : 0;
300}
301
302KCModule::Buttons KCModuleProxy::buttons() const
303{
304 if( realModule() )
305 return realModule()->buttons();
306 return KCModule::Buttons( KCModule::Help | KCModule::Default | KCModule::Apply );
307}
308
309QString KCModuleProxy::rootOnlyMessage() const
310{
311 return realModule() ? realModule()->rootOnlyMessage() : QString();
312}
313
314bool KCModuleProxy::useRootOnlyMessage() const
315{
316 return realModule() ? realModule()->useRootOnlyMessage() : true;
317}
318
319KComponentData KCModuleProxy::componentData() const
320{
321 return realModule() ? realModule()->componentData() : KComponentData();
322}
323
324bool KCModuleProxy::changed() const
325{
326 Q_D(const KCModuleProxy);
327 return d->changed;
328}
329
330KCModuleInfo KCModuleProxy::moduleInfo() const
331{
332 Q_D(const KCModuleProxy);
333 return d->modInfo;
334}
335
336QString KCModuleProxy::dbusService() const
337{
338 Q_D(const KCModuleProxy);
339 return d->dbusService;
340}
341
342QString KCModuleProxy::dbusPath() const
343{
344 Q_D(const KCModuleProxy);
345 return d->dbusPath;
346}
347
348QSize KCModuleProxy::minimumSizeHint() const
349{
350 return QWidget::minimumSizeHint();
351}
352
353//X void KCModuleProxy::emitQuickHelpChanged()
354//X {
355//X emit quickHelpChanged();
356//X }
357
358/***************************************************************/
359#include "kcmoduleproxy.moc"
360
361// vim: ts=4
KAboutData
KCModuleInfo
A class that provides information about a KCModule.
Definition: kcmoduleinfo.h:48
KCModuleInfo::library
QString library() const
Definition: kcmoduleinfo.cpp:171
KCModuleInfo::moduleName
QString moduleName() const
Definition: kcmoduleinfo.cpp:151
KCModuleInfo::handle
QString handle() const
Definition: kcmoduleinfo.cpp:184
KCModuleProxyPrivate
Definition: kcmoduleproxy_p.h:29
KCModuleProxyPrivate::q_ptr
KCModuleProxy * q_ptr
Definition: kcmoduleproxy_p.h:73
KCModuleProxyPrivate::topLayout
QVBoxLayout * topLayout
Definition: kcmoduleproxy_p.h:65
KCModuleProxyPrivate::bogusOccupier
bool bogusOccupier
Definition: kcmoduleproxy_p.h:71
KCModuleProxyPrivate::args
QStringList args
Definition: kcmoduleproxy_p.h:63
KCModuleProxyPrivate::kcm
KCModule * kcm
Definition: kcmoduleproxy_p.h:64
KCModuleProxyPrivate::dbusPath
QString dbusPath
Definition: kcmoduleproxy_p.h:68
KCModuleProxyPrivate::rootInfo
QLabel * rootInfo
Definition: kcmoduleproxy_p.h:66
KCModuleProxyPrivate::_k_moduleDestroyed
void _k_moduleDestroyed()
Zeroes d->kcm.
Definition: kcmoduleproxy.cpp:238
KCModuleProxyPrivate::changed
bool changed
Definition: kcmoduleproxy_p.h:70
KCModuleProxyPrivate::parent
KCModuleProxy * parent
Definition: kcmoduleproxy_p.h:72
KCModuleProxyPrivate::_k_moduleChanged
void _k_moduleChanged(bool)
Makes sure the proper variables is set and signals are emitted.
Definition: kcmoduleproxy.cpp:226
KCModuleProxyPrivate::dbusService
QString dbusService
Definition: kcmoduleproxy_p.h:67
KCModuleProxyPrivate::loadModule
void loadModule()
Definition: kcmoduleproxy.cpp:89
KCModuleProxyPrivate::_k_ownerChanged
void _k_ownerChanged(const QString &service, const QString &oldOwner, const QString &newOwner)
Gets called by DCOP when an application closes.
Definition: kcmoduleproxy.cpp:179
KCModuleProxyPrivate::modInfo
KCModuleInfo modInfo
Definition: kcmoduleproxy_p.h:69
KCModuleProxy
Encapsulates a KCModule for embedding.
Definition: kcmoduleproxy.h:68
KCModuleProxy::realModule
KCModule * realModule() const
Access to the actual module.
Definition: kcmoduleproxy.cpp:71
KCModuleProxy::moduleInfo
KCModuleInfo moduleInfo() const
Definition: kcmoduleproxy.cpp:330
KCModuleProxy::changed
bool changed() const
Definition: kcmoduleproxy.cpp:324
KCModuleProxy::quickHelp
QString quickHelp() const
Definition: kcmoduleproxy.cpp:292
KCModuleProxy::dbusService
QString dbusService() const
Returns the DBUS Service name.
Definition: kcmoduleproxy.cpp:336
KCModuleProxy::KCModuleProxy
KCModuleProxy(const KCModuleInfo &info, QWidget *parent=0, const QStringList &args=QStringList())
Constructs a KCModuleProxy from a KCModuleInfo class.
Definition: kcmoduleproxy.cpp:250
KCModuleProxy::d_ptr
KCModuleProxyPrivate *const d_ptr
Definition: kcmoduleproxy.h:253
KCModuleProxy::buttons
KCModule::Buttons buttons() const
Definition: kcmoduleproxy.cpp:302
KCModuleProxy::componentData
KComponentData componentData() const
Returns the embedded KCModule's KComponentData.
Definition: kcmoduleproxy.cpp:319
KCModuleProxy::deleteClient
void deleteClient()
Calling this, results in deleting the contained module, and unregistering from DCOP.
Definition: kcmoduleproxy.cpp:217
KCModuleProxy::defaults
void defaults()
Calling it will cause the contained module to load its default values.
Definition: kcmoduleproxy.cpp:285
KCModuleProxy::save
void save()
Calling it will cause the contained module to run its save() routine.
Definition: kcmoduleproxy.cpp:275
KCModuleProxy::showEvent
void showEvent(QShowEvent *)
Reimplemented for internal purposes.
Definition: kcmoduleproxy.cpp:194
KCModuleProxy::aboutData
const KAboutData * aboutData() const
Definition: kcmoduleproxy.cpp:297
KCModuleProxy::rootOnlyMessage
QString rootOnlyMessage() const
Definition: kcmoduleproxy.cpp:309
KCModuleProxy::dbusPath
QString dbusPath() const
Returns the DBUS Path.
Definition: kcmoduleproxy.cpp:342
KCModuleProxy::load
void load()
Calling it will cause the contained module to run its load() routine.
Definition: kcmoduleproxy.cpp:265
KCModuleProxy::~KCModuleProxy
~KCModuleProxy()
Default destructor.
Definition: kcmoduleproxy.cpp:209
KCModuleProxy::minimumSizeHint
QSize minimumSizeHint() const
Returns the recommended minimum size for the widget.
Definition: kcmoduleproxy.cpp:348
KCModuleProxy::useRootOnlyMessage
bool useRootOnlyMessage() const
Definition: kcmoduleproxy.cpp:314
KCModule
KCModule::useRootOnlyMessage
bool useRootOnlyMessage() const
KCModule::rootOnlyMessage
QString rootOnlyMessage() const
KCModule::quickHelp
virtual QString quickHelp() const
KCModule::Apply
Apply
KCModule::Help
Help
KCModule::Default
Default
KCModule::showEvent
virtual void showEvent(QShowEvent *ev)
KCModule::componentData
KComponentData componentData() const
KCModule::aboutData
virtual const KAboutData * aboutData() const
KCModule::buttons
Buttons buttons() const
KComponentData
KSettingsWidgetAdaptor
Definition: ksettingswidgetadaptor.h:30
KSharedPtr< KService >
KUser
QWidget
kDebug
#define kDebug
kaboutdata.h
kcmodule.h
kcmoduleinfo.h
kcmoduleloader.h
kcmoduleproxy.h
kcmoduleproxy_p.h
kcolorscheme.h
kdebug.h
kdialog.h
klocale.h
i18nc
QString i18nc(const char *ctxt, const char *text)
kservice.h
ksettingswidgetadaptor.h
kstandarddirs.h
kuser.h
kvbox.h
KCModuleLoader::loadModule
KCModule * loadModule(const KCModuleInfo &module, ErrorReporting report, QWidget *parent=0, const QStringList &args=QStringList())
Loads a KCModule.
Definition: kcmoduleloader.cpp:65
KCModuleLoader::unloadModule
void unloadModule(const KCModuleInfo &mod)
Unloads the module's library.
Definition: kcmoduleloader.cpp:139
KCModuleLoader::reportError
KCModule * reportError(ErrorReporting report, const QString &text, const QString &details, QWidget *parent)
Returns a KCModule containing the messages report and text.
Definition: kcmoduleloader.cpp:161
KCModuleLoader::Inline
@ Inline
the error report is shown instead of the KCModule that should have * been loaded
Definition: kcmoduleloader.h:57
name
const char * name(StandardAction id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KUtils

Skip menu "KUtils"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal