summaryrefslogtreecommitdiff
path: root/sowatchd/main.cpp
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2011-10-17 20:54:22 +0200
committerJavier S. Pedro <maemo@javispedro.com>2011-10-17 20:54:22 +0200
commite8781ec2d43ec3f7f905e20fc76b1910e83ee0c8 (patch)
tree34a842fb825ecc14454ff044fc6af92e29b4ae10 /sowatchd/main.cpp
parente42e7dca8df8d1e4966545894e2dde228f19b6f0 (diff)
downloadsowatch-e8781ec2d43ec3f7f905e20fc76b1910e83ee0c8.tar.gz
sowatch-e8781ec2d43ec3f7f905e20fc76b1910e83ee0c8.zip
Major change: sowatchd is now a QtM service
Diffstat (limited to 'sowatchd/main.cpp')
-rw-r--r--sowatchd/main.cpp69
1 files changed, 64 insertions, 5 deletions
diff --git a/sowatchd/main.cpp b/sowatchd/main.cpp
index 0d7abb9..22e63a2 100644
--- a/sowatchd/main.cpp
+++ b/sowatchd/main.cpp
@@ -1,20 +1,79 @@
#include <QtGui/QApplication>
+#include <QtServiceFramework/QServiceManager>
+#include <QtServiceFramework/QRemoteServiceRegister>
#include <sowatch.h>
-#include "daemon.h"
+#include "global.h"
+#include "service.h"
+
+namespace sowatch
+{
+ Daemon* daemon;
+}
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 Daemon* d;
+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);
+ QApplication a(argc, argv); // Some plugins might require a UI.
QApplication::setOrganizationDomain("com.javispedro.sowatch");
QApplication::setOrganizationName("sowatch");
QApplication::setApplicationName("sowatchd");
- d = new Daemon();
+ 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);
+
+ serviceRegister->setQuitOnLastInstanceClosed(false);
+ serviceRegister->publishEntries("sowatchd");
+
+ int res = a.exec();
+
+ delete serviceRegister;
+ delete sowatch::daemon;
- return a.exec();
+ return res;
}