~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to databaseserver/pollthread.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-06-18 21:58:46 UTC
  • mfrom: (1.2.29 upstream) (3.2.13 sid)
  • Revision ID: james.westby@ubuntu.com-20100618215846-c95bk5aoysmu786d
Tags: 2:1.3.0-0ubuntu1
* Merge with Debian unstable, remaining changes:
  - Export .pot name and copy to plugins in debian/rules
  - Enable Nepomuk support in Digikam
    - Add shared-desktop-ontologies to build depends
* New upstream release:
  - Remove digikam-1.2.0-kde232628.patch fixed by upstream
  - Add mysql-server-5.1 to buil-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================
 
2
 *
 
3
 * This file is a part of digiKam project
 
4
 * http://www.digikam.org
 
5
 *
 
6
 * Date        : 2010-01-08
 
7
 * Description : polling thread checks if there are digikam
 
8
 *               components registered on DBus
 
9
 *
 
10
 * Copyright (C) 2009-2010 by Holger Foerster <Hamsi2k at freenet dot de>
 
11
 *
 
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)
 
16
 * any later version.
 
17
 *
 
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.
 
22
 *
 
23
 * ============================================================ */
 
24
 
 
25
#include "pollthread.moc"
 
26
 
 
27
// Qt includes
 
28
 
 
29
#include <QString>
 
30
#include <QtGlobal>
 
31
#include <QFile>
 
32
#include <QFileInfo>
 
33
#include <QDateTime>
 
34
#include <QDir>
 
35
#include <QProcess>
 
36
#include <QSqlDatabase>
 
37
#include <QSqlQuery>
 
38
#include <QSqlError>
 
39
#include <QDBusConnection>
 
40
#include <QDBusConnectionInterface>
 
41
#include <QDBusReply>
 
42
#include <QThread>
 
43
#include <QSystemSemaphore>
 
44
 
 
45
// KDE includes
 
46
 
 
47
#include <kdebug.h>
 
48
#include <kstandarddirs.h>
 
49
 
 
50
namespace Digikam
 
51
{
 
52
 
 
53
PollThread::PollThread(QObject* parent)
 
54
          : QThread(parent), stop(false), waitTime(10)
 
55
{
 
56
}
 
57
 
 
58
void PollThread::run()
 
59
{
 
60
    do
 
61
    {
 
62
        kDebug() << "Waiting "<< waitTime <<" seconds...stop: ["<< stop <<"]";
 
63
        sleep(waitTime);
 
64
    }
 
65
    while( !stop && checkDigikamInstancesRunning() );
 
66
 
 
67
    kDebug() << "Shutting down database server";
 
68
    emit done();
 
69
}
 
70
 
 
71
bool PollThread::checkDigikamInstancesRunning()
 
72
{
 
73
   QSystemSemaphore sem("DigikamDBSrvAccess", 1, QSystemSemaphore::Open);
 
74
   sem.acquire();
 
75
   QDBusConnectionInterface *interface = QDBusConnection::sessionBus().interface();
 
76
   QDBusReply<QStringList> reply = interface->registeredServiceNames();
 
77
 
 
78
   if (reply.isValid())
 
79
   {
 
80
       QStringList serviceNames = reply.value();
 
81
       QLatin1String digikamService("org.kde.digikam-");
 
82
       QLatin1String digikamKioService("org.kde.digikam.KIO-");
 
83
       foreach (const QString &service, serviceNames)
 
84
       {
 
85
           if (service.startsWith(digikamService) || service.startsWith(digikamKioService))
 
86
           {
 
87
               kDebug() << "At least service ["<< service <<"] is using the database server";
 
88
               // At least one digikam/kio service was found
 
89
               sem.release(1);
 
90
               return true;
 
91
           }
 
92
       }
 
93
   }
 
94
   sem.release(1);
 
95
   return false;
 
96
}
 
97
 
 
98
} // namespace Digikam