diff options
Diffstat (limited to 'sowatchd/main.cpp')
-rw-r--r-- | sowatchd/main.cpp | 80 |
1 files changed, 23 insertions, 57 deletions
diff --git a/sowatchd/main.cpp b/sowatchd/main.cpp index 22e63a2..29eee28 100644 --- a/sowatchd/main.cpp +++ b/sowatchd/main.cpp @@ -1,10 +1,12 @@ +#include <QtCore/QDebug> #include <QtGui/QApplication> -#include <QtServiceFramework/QServiceManager> -#include <QtServiceFramework/QRemoteServiceRegister> +#include <QtDBus/QDBusConnection> #include <sowatch.h> #include "global.h" -#include "service.h" +#include "allscanner.h" +#include "daemonadaptor.h" +#include "scanneradaptor.h" namespace sowatch { @@ -12,68 +14,32 @@ namespace sowatch } using namespace sowatch; -QTM_USE_NAMESPACE - - -static QString adjustPath(const QString &path) -{ -#ifdef Q_OS_UNIX -#ifdef Q_OS_MAC - if (!QDir::isAbsolutePath(path)) - return QCoreApplication::applicationDirPath() - + QLatin1String("/../Resources/") + path; -#else - QString pathInInstallDir; - const QString applicationDirPath = QCoreApplication::applicationDirPath(); - pathInInstallDir = QString::fromAscii("%1/../%2").arg(applicationDirPath, path); - - if (QFileInfo(pathInInstallDir).exists()) - return pathInInstallDir; -#endif -#endif - return path; -} - -static void unregisterService() -{ - QServiceManager m; - m.removeService("sowatch-service"); -} - -static void registerService() -{ - unregisterService(); - QServiceManager m; - QString path = adjustPath("xml/service.xml"); - if (!m.addService(path)) { - qWarning() << "Cannot register sowatch-service" << m.error() << "from" << path; - } -} int main(int argc, char *argv[]) { - QApplication a(argc, argv); // Some plugins might require a UI. + // Some plugins might require a user interface, so use QApplication instead + // of QCoreApplication + QApplication a(argc, argv); QApplication::setOrganizationDomain("com.javispedro.sowatch"); QApplication::setOrganizationName("sowatch"); QApplication::setApplicationName("sowatchd"); - sowatch::daemon = new Daemon(); - - registerService(); - - QRemoteServiceRegister *serviceRegister = new QRemoteServiceRegister(); - QRemoteServiceRegister::Entry entry = - serviceRegister->createEntry<Service>("sowatch-service", - "com.javispedro.sowatch.service", "1.0"); - entry.setInstantiationType(QRemoteServiceRegister::PrivateInstance); + sowatch::daemon = new Daemon(&a); + new DaemonAdaptor(sowatch::daemon); + AllScanner *scanner = new AllScanner(&a); + new ScannerAdaptor(scanner); - serviceRegister->setQuitOnLastInstanceClosed(false); - serviceRegister->publishEntries("sowatchd"); - - int res = a.exec(); + QDBusConnection connection = QDBusConnection::sessionBus(); + if (!connection.registerService("com.javispedro.sowatchd")) { + qCritical("Could not register D-Bus service"); + } - delete serviceRegister; - delete sowatch::daemon; + if (!connection.registerObject("/com/javispedro/sowatch/allscanner", scanner)) { + qCritical("Could not register scanner object"); + } + if (!connection.registerObject("/com/javispedro/sowatch/daemon", sowatch::daemon)) { + qCritical("Could not register daemon object"); + } - return res; + return a.exec(); } |