~ubuntu-branches/debian/stretch/apper/stretch

« back to all changes in this revision

Viewing changes to declarative-plugins/DBusUpdaterInterface.cpp

  • Committer: Package Import Robot
  • Author(s): Matthias Klumpp
  • Date: 2013-07-30 12:34:46 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130730123446-cgzujaj03pc61drn
Tags: 0.8.1-1
* New upstream release: 0.8.1
* Depend on software-properties-kde instead of suggesting it (Closes: #696583)
* Add patch to make AppStream loading more failsafe

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2008-2011 Daniel Nicoletti                              *
 
3
 *   dantti12@gmail.com                                                    *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 *   This program is distributed in the hope that it will be useful,       *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
13
 *   GNU General Public License for more details.                          *
 
14
 *                                                                         *
 
15
 *   You should have received a copy of the GNU General Public License     *
 
16
 *   along with this program; if not, write to the                         *
 
17
 *   Free Software Foundation, Inc.,                                       *
 
18
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 
19
 ***************************************************************************/
 
20
 
 
21
#include "DBusUpdaterInterface.h"
 
22
 
 
23
#include "apperupdatericonadaptor.h"
 
24
 
 
25
#include <QtDBus/QDBusConnection>
 
26
 
 
27
#include <KDebug>
 
28
 
 
29
DBusUpdaterInterface::DBusUpdaterInterface(QObject *parent) :
 
30
    QObject(parent),
 
31
    m_registered(false)
 
32
{
 
33
    (void) new ApperUpdaterIconAdaptor(this);
 
34
}
 
35
 
 
36
DBusUpdaterInterface::~DBusUpdaterInterface()
 
37
{
 
38
    if (m_registered) {
 
39
        unregisterService();
 
40
    }
 
41
}
 
42
 
 
43
bool DBusUpdaterInterface::isRegistered() const
 
44
{
 
45
    return m_registered;
 
46
}
 
47
 
 
48
void DBusUpdaterInterface::ReviewUpdates()
 
49
{
 
50
    emit reviewUpdates();
 
51
}
 
52
 
 
53
void DBusUpdaterInterface::registerService()
 
54
{
 
55
    kDebug();
 
56
    QDBusServiceWatcher *watcher = qobject_cast<QDBusServiceWatcher*>(sender());
 
57
    if (!m_registered && !QDBusConnection::sessionBus().registerService(QLatin1String("org.kde.ApperUpdaterIcon"))) {
 
58
        kDebug() << "unable to register service to dbus";
 
59
        if (!watcher) {
 
60
            // in case registration fails due to another user or application running
 
61
            // keep an eye on it so we can register when available
 
62
            watcher = new QDBusServiceWatcher(QLatin1String("org.kde.ApperUpdaterIcon"),
 
63
                                              QDBusConnection::systemBus(),
 
64
                                              QDBusServiceWatcher::WatchForUnregistration,
 
65
                                              this);
 
66
            connect(watcher, SIGNAL(serviceUnregistered(QString)), this, SLOT(registerService()));
 
67
        }
 
68
        m_registered = false;
 
69
        emit registeredChanged();
 
70
    } else {
 
71
        if (!QDBusConnection::sessionBus().registerObject("/", this)) {
 
72
            kDebug() << "unable to register service interface to dbus";
 
73
            return;
 
74
        }
 
75
 
 
76
        m_registered = true;
 
77
        emit registeredChanged();
 
78
    }
 
79
}
 
80
 
 
81
void DBusUpdaterInterface::unregisterService()
 
82
{
 
83
    // We need to unregister the service since
 
84
    // plasma-desktop won't exit
 
85
    if (QDBusConnection::sessionBus().unregisterService(QLatin1String("org.kde.ApperUpdaterIcon"))) {
 
86
        m_registered = false;
 
87
        emit registeredChanged();
 
88
    } else {
 
89
        kDebug() << "unable to unregister service to dbus";
 
90
    }
 
91
}