fix logic
[personal-kdelibs.git] / kdecore / util / kdedmodule.cpp
blobcbc6ef8cece8c32ad8402eed31f35617d7d965af
1 //! vim: ts=3 sw=3
2 /*
3 This file is part of the KDE libraries
5 Copyright (c) 2001 Waldo Bastian <bastian@kde.org>
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
24 #include "kdedmodule.h"
26 #include "kdebug.h"
27 #include <QtCore/QTimer>
28 #include <QtDBus/QtDBus>
32 class KDEDModulePrivate
34 public:
35 QString moduleName;
38 KDEDModule::KDEDModule(QObject* parent)
39 : QObject(parent), d(new KDEDModulePrivate)
43 KDEDModule::~KDEDModule()
45 emit moduleDeleted(this);
46 delete d;
49 void KDEDModule::setModuleName( const QString& name )
51 d->moduleName = name;
52 QDBusObjectPath realPath( QString("/modules/") + d->moduleName);
54 if (realPath.path().isEmpty())
56 kError() << "The kded module name '" << name << "' is invalid!";
57 return;
61 QDBusConnection::RegisterOptions regOptions;
63 if (this->metaObject()->indexOfClassInfo("D-Bus Interface")!=-1)
65 // 1. There are kded modules that don't have a dbus interface.
66 // 2. qt 4.4.3 crashes when trying to emit signals on class without
67 // Q_CLASSINFO("D-Bus Interface", "<your interface>") but
68 // ExportSignal set.
69 // We try to solve that for now with just registering Properties and
70 // Adaptors. But we should investigate where the sense is in registering
71 // the module at all. Just for autoload? Is there a better solution?
72 regOptions = QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors;
74 else
76 // Full functional module. Register everything.
77 regOptions = QDBusConnection::ExportScriptableSlots
78 | QDBusConnection::ExportScriptableProperties
79 | QDBusConnection::ExportAdaptors;
80 kDebug() << "Registration of kded module " << d->moduleName << "without dbus interface.";
83 if (!QDBusConnection::sessionBus().registerObject(realPath.path(), this, regOptions))
85 // Happens for khotkeys but the module works. Need some time to investigate.
86 kDebug() << "registerObject() returned false for " << d->moduleName;
88 else
90 kDebug() << "registerObject() successful for " << d->moduleName;
91 emit moduleRegistered(realPath);
96 QString KDEDModule::moduleName() const
98 return d->moduleName;
101 #include "kdedmodule.moc"