1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : polling thread checks if there are digikam
8
* components registered on DBus
10
* Copyright (C) 2009-2010 by Holger Foerster <Hamsi2k at freenet dot de>
12
* This program is free software; you can redistribute it
13
* and/or modify it under the terms of the GNU General
14
* Public License as published by the Free Software Foundation;
15
* either version 2, or (at your option)
18
* This program is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
23
* ============================================================ */
25
#include "pollthread.moc"
36
#include <QSqlDatabase>
39
#include <QDBusConnection>
40
#include <QDBusConnectionInterface>
43
#include <QSystemSemaphore>
48
#include <kstandarddirs.h>
53
PollThread::PollThread(QObject* parent)
54
: QThread(parent), stop(false), waitTime(10)
58
void PollThread::run()
62
kDebug() << "Waiting "<< waitTime <<" seconds...stop: ["<< stop <<"]";
65
while( !stop && checkDigikamInstancesRunning() );
67
kDebug() << "Shutting down database server";
71
bool PollThread::checkDigikamInstancesRunning()
73
QSystemSemaphore sem("DigikamDBSrvAccess", 1, QSystemSemaphore::Open);
75
QDBusConnectionInterface *interface = QDBusConnection::sessionBus().interface();
76
QDBusReply<QStringList> reply = interface->registeredServiceNames();
80
QStringList serviceNames = reply.value();
81
QLatin1String digikamService("org.kde.digikam-");
82
QLatin1String digikamKioService("org.kde.digikam.KIO-");
83
foreach (const QString &service, serviceNames)
85
if (service.startsWith(digikamService) || service.startsWith(digikamKioService))
87
kDebug() << "At least service ["<< service <<"] is using the database server";
88
// At least one digikam/kio service was found
98
} // namespace Digikam