blob: b43509e410fd801178f6d8c93cd1ad53c1bceb6b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*
* Copyright 2014 Canonical Ltd.
*
* This file is part of sync-monitor.
*
* sync-monitor is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* contact-service-app is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QDebug>
#include <QTimer>
#include "syncmonitorclient.h"
#define SYNCMONITOR_DBUS_SERVICE_NAME "com.canonical.SyncMonitor"
#define SYNCMONITOR_DBUS_OBJECT_PATH "/com/canonical/SyncMonitor"
#define SYNCMONITOR_DBUS_INTERFACE "com.canonical.SyncMonitor"
SyncMonitorClient::SyncMonitorClient(QObject *parent)
: QObject(parent),
m_iface(0)
{
m_iface = new QDBusInterface(SYNCMONITOR_DBUS_SERVICE_NAME,
SYNCMONITOR_DBUS_OBJECT_PATH,
SYNCMONITOR_DBUS_INTERFACE);
if (m_iface->lastError().isValid()) {
qWarning() << "Fail to connect with sync monitor:" << m_iface->lastError();
return;
}
connect(m_iface, SIGNAL(stateChanged()), SIGNAL(stateChanged()));
connect(m_iface, SIGNAL(enabledServicesChanged()), SIGNAL(enabledServicesChanged()));
m_iface->call("attach");
}
SyncMonitorClient::~SyncMonitorClient()
{
if (m_iface) {
m_iface->call("detach");
delete m_iface;
m_iface = 0;
}
}
QString SyncMonitorClient::state() const
{
if (m_iface) {
return m_iface->property("state").toString();
} else {
return "";
}
}
QStringList SyncMonitorClient::enabledServices() const
{
if (m_iface) {
return m_iface->property("enabledServices").toStringList();
} else {
return QStringList();
}
}
/*!
Start a new sync for specified services
*/
void SyncMonitorClient::sync(const QStringList &services)
{
if (m_iface) {
qDebug() << "starting sync!";
m_iface->call("sync", services);
}
}
/*!
Cancel current sync for specified services
*/
void SyncMonitorClient::cancel(const QStringList &services)
{
if (m_iface) {
m_iface->call("cancel", services);
}
}
/*!
Chek if a specific service is enabled or not
*/
bool SyncMonitorClient::serviceIsEnabled(const QString &service)
{
return enabledServices().contains(service);
}
|