• 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
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Jul 23 2013 20:39:39 by doxygen 1.8.1.1 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