• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.5 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 /***************************************************************/
71 KCModule* 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 
89 void KCModuleProxyPrivate::loadModule()
90 {
91  if( !topLayout )
92  {
93  topLayout = new QVBoxLayout( parent );
94  topLayout->setMargin( 0 );
95 
96  QString name = modInfo.handle();
97  dbusPath = QLatin1String("/internal/KSettingsWidget/") + name;
98  dbusService = QLatin1String("org.kde.internal.KSettingsWidget-") + name;
99  }
100 
101  if( QDBusConnection::sessionBus().registerService( dbusService ) || bogusOccupier )
102  { /* We got the name we requested, because no one was before us,
103  * or, it was an random application which had picked that name */
104  kDebug(711) << "Module not already loaded, loading module " << modInfo.moduleName() << " from library " << modInfo.library() << " using symbol " << modInfo.handle();
105 
106  kcm = KCModuleLoader::loadModule( modInfo, KCModuleLoader::Inline, parent, args );
107 
108  QObject::connect(kcm, SIGNAL(changed(bool)), parent, SLOT(_k_moduleChanged(bool)));
109  QObject::connect(kcm, SIGNAL(destroyed()), parent, SLOT(_k_moduleDestroyed()));
110  QObject::connect( kcm, SIGNAL(quickHelpChanged()), parent, SIGNAL(quickHelpChanged()) );
111  parent->setWhatsThis( kcm->quickHelp() );
112 
113  if ( kcm->layout() ) {
114  kcm->layout()->setMargin( 0 );
115  }
116  topLayout->addWidget( kcm );
117  if( !modInfo.handle().isEmpty() )
118  QDBusConnection::sessionBus().registerObject(dbusPath, new KSettingsWidgetAdaptor(parent), QDBusConnection::ExportAllSlots);
119 
120  if ( !rootInfo && /* If it's not already done */
121  kcm->useRootOnlyMessage() && /* kcm wants root message */
122  !KUser().isSuperUser() ) /* Not necessary if we're root */
123  {
124  /*rootInfo = new QLabel( parent );
125  topLayout->insertWidget( 0, rootInfo );
126 
127  QPalette palette = rootInfo->palette();
128  KStatefulBrush stbrush(KColorScheme::Window, KColorScheme::NeutralBackground);
129  qDebug() << stbrush.brush(rootInfo);
130  palette.setBrush(QPalette::Window, stbrush.brush(rootInfo));
131  rootInfo->setPalette(palette);
132  rootInfo->setAutoFillBackground(true);
133 
134  const QString message = kcm->rootOnlyMessage();
135  if( message.isEmpty() )
136  rootInfo->setText( i18n(
137  "<b>Changes in this section require root access.</b><br />"
138  "On applying your changes you will have to supply your root "
139  "password." ) );
140  else
141  rootInfo->setText(message);
142 
143  rootInfo->setWhatsThis( i18n(
144  "This section requires special permissions, probably "
145  "for system-wide changes; therefore, it is "
146  "required that you provide the root password to be "
147  "able to change the module's properties. If "
148  "you cannot provide the password, the changes of the "
149  "module cannot be saved " ) );*/
150  }
151  }
152  else
153  {
154  kDebug(711) << "Module already loaded, loading KCMError";
155 
156  /* Figure out the name of where the module is already loaded */
157  QDBusInterface proxy( dbusService, dbusPath, "org.kde.internal.KSettingsWidget" );
158  QDBusReply<QString> reply = proxy.call("applicationName");
159 
160  if( reply.isValid() )
161  {
162  QObject::connect( QDBusConnection::sessionBus().interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)),
163  parent, SLOT(_k_ownerChanged(QString,QString,QString)));
164  kcm = KCModuleLoader::reportError( KCModuleLoader::Inline,
165  i18nc( "Argument is application name", "This configuration section is "
166  "already opened in %1" , reply.value() ), " ", parent );
167  topLayout->addWidget( kcm );
168  }
169  else
170  {
171  kDebug(711) << "Calling KCModuleProxy's DBus interface for fetching the name failed.";
172  bogusOccupier = true;
173  loadModule();
174  }
175  }
176 }
177 
178 void KCModuleProxyPrivate::_k_ownerChanged(const QString &service, const QString &oldOwner, const QString &)
179 {
180  if (service == dbusService && !oldOwner.isEmpty()) {
181  // Violence: Get rid of KCMError & CO, so that
182  // realModule() attempts to reload the module
183  delete kcm;
184  kcm = 0;
185  Q_Q(KCModuleProxy);
186  q->realModule();
187 
188  Q_ASSERT(kcm);
189  kcm->show();
190  }
191 }
192 
193 void KCModuleProxy::showEvent( QShowEvent * ev )
194 {
195  Q_D(KCModuleProxy);
196 
197  ( void )realModule();
198 
199  /* We have no kcm, if we're in root mode */
200  if( d->kcm ) {
201  d->kcm->showEvent(ev);
202  }
203 
204  QWidget::showEvent( ev );
205 
206 }
207 
208 KCModuleProxy::~KCModuleProxy()
209 {
210  deleteClient();
211  KCModuleLoader::unloadModule(moduleInfo());
212 
213  delete d_ptr;
214 }
215 
216 void KCModuleProxy::deleteClient()
217 {
218  Q_D(KCModuleProxy);
219  delete d->kcm;
220  d->kcm = 0;
221 
222  qApp->syncX();
223 }
224 
225 void KCModuleProxyPrivate::_k_moduleChanged(bool c)
226 {
227  if(changed == c) {
228  return;
229  }
230 
231  Q_Q(KCModuleProxy);
232  changed = c;
233  emit q->changed(c);
234  emit q->changed(q);
235 }
236 
237 void KCModuleProxyPrivate::_k_moduleDestroyed()
238 {
239  kcm = 0;
240 }
241 
242 KCModuleProxy::KCModuleProxy( const KService::Ptr& service, QWidget * parent,
243  const QStringList& args )
244  : QWidget(parent), d_ptr(new KCModuleProxyPrivate(this, KCModuleInfo(service), args))
245 {
246  d_ptr->q_ptr = this;
247 }
248 
249 KCModuleProxy::KCModuleProxy( const KCModuleInfo& info, QWidget * parent,
250  const QStringList& args )
251  : QWidget(parent), d_ptr(new KCModuleProxyPrivate(this, info, args))
252 {
253  d_ptr->q_ptr = this;
254 }
255 
256 KCModuleProxy::KCModuleProxy( const QString& serviceName, QWidget * parent,
257  const QStringList& args )
258  : QWidget(parent), d_ptr(new KCModuleProxyPrivate(this, KCModuleInfo(serviceName), args))
259 {
260  d_ptr->q_ptr = this;
261 }
262 
263 
264 void KCModuleProxy::load()
265 {
266  Q_D(KCModuleProxy);
267  if( realModule() )
268  {
269  d->kcm->load();
270  d->_k_moduleChanged(false);
271  }
272 }
273 
274 void KCModuleProxy::save()
275 {
276  Q_D(KCModuleProxy);
277  if( d->changed && realModule() )
278  {
279  d->kcm->save();
280  d->_k_moduleChanged(false);
281  }
282 }
283 
284 void KCModuleProxy::defaults()
285 {
286  Q_D(KCModuleProxy);
287  if( realModule() )
288  d->kcm->defaults();
289 }
290 
291 QString KCModuleProxy::quickHelp() const
292 {
293  return realModule() ? realModule()->quickHelp() : QString();
294 }
295 
296 const KAboutData * KCModuleProxy::aboutData() const
297 {
298  return realModule() ? realModule()->aboutData() : 0;
299 }
300 
301 KCModule::Buttons KCModuleProxy::buttons() const
302 {
303  if( realModule() )
304  return realModule()->buttons();
305  return KCModule::Buttons( KCModule::Help | KCModule::Default | KCModule::Apply );
306 }
307 
308 QString KCModuleProxy::rootOnlyMessage() const
309 {
310  return realModule() ? realModule()->rootOnlyMessage() : QString();
311 }
312 
313 bool KCModuleProxy::useRootOnlyMessage() const
314 {
315  return realModule() ? realModule()->useRootOnlyMessage() : true;
316 }
317 
318 KComponentData KCModuleProxy::componentData() const
319 {
320  return realModule() ? realModule()->componentData() : KComponentData();
321 }
322 
323 bool KCModuleProxy::changed() const
324 {
325  Q_D(const KCModuleProxy);
326  return d->changed;
327 }
328 
329 KCModuleInfo KCModuleProxy::moduleInfo() const
330 {
331  Q_D(const KCModuleProxy);
332  return d->modInfo;
333 }
334 
335 QString KCModuleProxy::dbusService() const
336 {
337  Q_D(const KCModuleProxy);
338  return d->dbusService;
339 }
340 
341 QString KCModuleProxy::dbusPath() const
342 {
343  Q_D(const KCModuleProxy);
344  return d->dbusPath;
345 }
346 
347 QSize KCModuleProxy::minimumSizeHint() const
348 {
349  return QWidget::minimumSizeHint();
350 }
351 
352 //X void KCModuleProxy::emitQuickHelpChanged()
353 //X {
354 //X emit quickHelpChanged();
355 //X }
356 
357 /***************************************************************/
358 #include "kcmoduleproxy.moc"
359 
360 // vim: ts=4
KCModuleProxyPrivate::changed
bool changed
Definition: kcmoduleproxy_p.h:70
KCModuleLoader::unloadModule
void unloadModule(const KCModuleInfo &mod)
Unloads the module&#39;s library.
Definition: kcmoduleloader.cpp:139
kdialog.h
KCModuleProxyPrivate::dbusService
QString dbusService
Definition: kcmoduleproxy_p.h:67
KSharedPtr< KService >
KCModuleProxyPrivate::bogusOccupier
bool bogusOccupier
Definition: kcmoduleproxy_p.h:71
kuser.h
KCModule::useRootOnlyMessage
bool useRootOnlyMessage() const
KCModuleProxy::changed
bool changed() const
Definition: kcmoduleproxy.cpp:323
KCModuleProxy::rootOnlyMessage
QString rootOnlyMessage() const
Definition: kcmoduleproxy.cpp:308
kdebug.h
kcmoduleproxy.h
kcmodule.h
QWidget
KCModule::rootOnlyMessage
QString rootOnlyMessage() const
name
const char * name(StandardAction id)
KCModuleProxyPrivate::dbusPath
QString dbusPath
Definition: kcmoduleproxy_p.h:68
QString
KCModule::componentData
KComponentData componentData() const
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
klocale.h
KSettingsWidgetAdaptor
Definition: ksettingswidgetadaptor.h:29
KCModuleProxy::~KCModuleProxy
~KCModuleProxy()
Default destructor.
Definition: kcmoduleproxy.cpp:208
kcmoduleproxy_p.h
i18nc
QString i18nc(const char *ctxt, const char *text)
KUser
KCModuleProxyPrivate::loadModule
void loadModule()
Definition: kcmoduleproxy.cpp:89
KCModule::Default
KCModuleProxy::KCModuleProxy
KCModuleProxy(const KCModuleInfo &info, QWidget *parent=0, const QStringList &args=QStringList())
Constructs a KCModuleProxy from a KCModuleInfo class.
Definition: kcmoduleproxy.cpp:249
KCModuleProxyPrivate::args
QStringList args
Definition: kcmoduleproxy_p.h:63
KCModuleProxy::deleteClient
void deleteClient()
Calling this, results in deleting the contained module, and unregistering from DCOP.
Definition: kcmoduleproxy.cpp:216
KCModule::showEvent
virtual void showEvent(QShowEvent *ev)
KCModuleProxy::dbusPath
QString dbusPath() const
Returns the DBUS Path.
Definition: kcmoduleproxy.cpp:341
KCModuleProxy::load
void load()
Calling it will cause the contained module to run its load() routine.
Definition: kcmoduleproxy.cpp:264
KCModuleProxyPrivate::_k_moduleDestroyed
void _k_moduleDestroyed()
Zeroes d-&gt;kcm.
Definition: kcmoduleproxy.cpp:237
KCModuleProxyPrivate::q_ptr
KCModuleProxy * q_ptr
Definition: kcmoduleproxy_p.h:73
KCModuleProxy::showEvent
void showEvent(QShowEvent *)
Reimplemented for internal purposes.
Definition: kcmoduleproxy.cpp:193
QStringList
KCModule::Help
KCModuleProxy::moduleInfo
KCModuleInfo moduleInfo() const
Definition: kcmoduleproxy.cpp:329
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:178
KCModuleProxyPrivate::parent
KCModuleProxy * parent
Definition: kcmoduleproxy_p.h:72
KAboutData
kvbox.h
KCModuleProxyPrivate::kcm
KCModule * kcm
Definition: kcmoduleproxy_p.h:64
KCModuleProxy::aboutData
const KAboutData * aboutData() const
Definition: kcmoduleproxy.cpp:296
ksettingswidgetadaptor.h
kservice.h
KCModuleInfo::library
QString library() const
Definition: kcmoduleinfo.cpp:171
KCModuleProxy::componentData
KComponentData componentData() const
Returns the embedded KCModule&#39;s KComponentData.
Definition: kcmoduleproxy.cpp:318
KCModuleProxy::defaults
void defaults()
Calling it will cause the contained module to load its default values.
Definition: kcmoduleproxy.cpp:284
KCModuleInfo
A class that provides information about a KCModule.
Definition: kcmoduleinfo.h:47
KCModuleProxyPrivate::modInfo
KCModuleInfo modInfo
Definition: kcmoduleproxy_p.h:69
KCModule::aboutData
virtual const KAboutData * aboutData() const
kcmoduleloader.h
KCModuleProxy::useRootOnlyMessage
bool useRootOnlyMessage() const
Definition: kcmoduleproxy.cpp:313
KCModule::buttons
Buttons buttons() const
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
KCModuleProxy::buttons
KCModule::Buttons buttons() const
Definition: kcmoduleproxy.cpp:301
kstandarddirs.h
KCModuleProxyPrivate::rootInfo
QLabel * rootInfo
Definition: kcmoduleproxy_p.h:66
KUser::isSuperUser
bool isSuperUser() const
KCModuleProxy
Encapsulates a KCModule for embedding.
Definition: kcmoduleproxy.h:67
KCModuleProxy::quickHelp
QString quickHelp() const
Definition: kcmoduleproxy.cpp:291
KCModuleProxy::d_ptr
KCModuleProxyPrivate *const d_ptr
Definition: kcmoduleproxy.h:253
QSize
KCModuleLoader::Inline
the error report is shown instead of the KCModule that should have * been loaded
Definition: kcmoduleloader.h:57
KCModuleProxyPrivate
Definition: kcmoduleproxy_p.h:28
kaboutdata.h
KCModuleProxy::minimumSizeHint
QSize minimumSizeHint() const
Returns the recommended minimum size for the widget.
Definition: kcmoduleproxy.cpp:347
KCModuleProxy::save
void save()
Calling it will cause the contained module to run its save() routine.
Definition: kcmoduleproxy.cpp:274
kcmoduleinfo.h
KCModuleProxyPrivate::_k_moduleChanged
void _k_moduleChanged(bool)
Makes sure the proper variables is set and signals are emitted.
Definition: kcmoduleproxy.cpp:225
KCModuleProxy::dbusService
QString dbusService() const
Returns the DBUS Service name.
Definition: kcmoduleproxy.cpp:335
KCModuleProxy::realModule
KCModule * realModule() const
Access to the actual module.
Definition: kcmoduleproxy.cpp:71
kcolorscheme.h
KCModule
KCModuleLoader::loadModule
KCModule * loadModule(const KCModuleInfo &module, ErrorReporting report, QWidget *parent=0, const QStringList &args=QStringList())
Loads a KCModule.
Definition: kcmoduleloader.cpp:65
KComponentData
KCModule::quickHelp
virtual QString quickHelp() const
KCModuleInfo::moduleName
QString moduleName() const
Definition: kcmoduleinfo.cpp:151
KCModuleInfo::handle
QString handle() const
Definition: kcmoduleinfo.cpp:184
KCModuleProxyPrivate::topLayout
QVBoxLayout * topLayout
Definition: kcmoduleproxy_p.h:65
KCModule::Apply
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue May 6 2014 16:56:21 by doxygen 1.8.5 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.10.5 API Reference

Skip menu "kdelibs-4.10.5 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