~ps-jenkins/sync-monitor/utopic-proposed

« back to all changes in this revision

Viewing changes to Ubuntu/SyncMonitor/syncmonitor-qml.cpp

  • Committer: CI bot
  • Author(s): Renato Araujo Oliveira Filho
  • Date: 2014-05-02 17:07:42 UTC
  • mfrom: (24.2.3 sync-monitor-qml)
  • Revision ID: ps-jenkins@lists.canonical.com-20140502170742-pz0pd5lct37g57jl
Created QML bindings to access the sync monitor information. Fixes: 1311125

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2014 Canonical Ltd.
 
3
 *
 
4
 * This file is part of sync-monitor.
 
5
 *
 
6
 * sync-monitor is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; version 3.
 
9
 *
 
10
 * contact-service-app 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, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#include <QDebug>
 
20
 
 
21
#include "syncmonitor-qml.h"
 
22
 
 
23
#define SYNCMONITOR_DBUS_SERVICE_NAME   "com.canonical.SyncMonitor"
 
24
#define SYNCMONITOR_DBUS_OBJECT_PATH    "/com/canonical/SyncMonitor"
 
25
#define SYNCMONITOR_DBUS_INTERFACE      "com.canonical.SyncMonitor"
 
26
 
 
27
 
 
28
/*!
 
29
    \qmltype SyncMonitor
 
30
    \inqmlmodule Ubuntu.SyncMonitor 0.1
 
31
    \brief The SyncMonitor is a helper class to get access to SyncMonitor Daemon
 
32
 
 
33
    \b{This component is under heavy development.}
 
34
 
 
35
    Example:
 
36
    \qml
 
37
    Item {
 
38
        SyncMonitor {
 
39
            id: syncMonitor
 
40
        }
 
41
        Button {
 
42
            text: "sync"
 
43
            onClick: syncMonitor.sync(["calendar", ["contacts"])
 
44
        }
 
45
    }
 
46
    \endqml
 
47
*/
 
48
 
 
49
SyncMonitorQml::SyncMonitorQml(QObject *parent)
 
50
    : QObject(parent),
 
51
      m_iface(0)
 
52
{
 
53
}
 
54
 
 
55
SyncMonitorQml::~SyncMonitorQml()
 
56
{
 
57
    if (m_iface) {
 
58
        delete m_iface;
 
59
        m_iface = 0;
 
60
    }
 
61
}
 
62
 
 
63
 
 
64
 
 
65
/*!
 
66
  Specifies the current sync monitor state
 
67
 
 
68
  \list
 
69
  \li "idle"         - Service is in idle state
 
70
  \li "syncing"      - Service is running a sync
 
71
  \endlist
 
72
 
 
73
  \qmlproperty string state
 
74
*/
 
75
QString SyncMonitorQml::state() const
 
76
{
 
77
    if (m_iface) {
 
78
        return m_iface->property("state").toString();
 
79
    } else {
 
80
        return "";
 
81
    }
 
82
}
 
83
 
 
84
/*!
 
85
  Specifies the enabled services to sync
 
86
 
 
87
  \qmlproperty list enabledServices
 
88
*/
 
89
QStringList SyncMonitorQml::enabledServices() const
 
90
{
 
91
    if (m_iface) {
 
92
        return m_iface->property("enabledServices").toStringList();
 
93
    } else {
 
94
        return QStringList();
 
95
    }
 
96
}
 
97
 
 
98
void SyncMonitorQml::classBegin()
 
99
{
 
100
}
 
101
 
 
102
void SyncMonitorQml::componentComplete()
 
103
{
 
104
    m_iface = new QDBusInterface(SYNCMONITOR_DBUS_SERVICE_NAME,
 
105
                                 SYNCMONITOR_DBUS_OBJECT_PATH,
 
106
                                 SYNCMONITOR_DBUS_INTERFACE);
 
107
    if (m_iface->lastError().isValid()) {
 
108
        qWarning() << "Fail to connect with sync monitor:" << m_iface->lastError();
 
109
        return;
 
110
    }
 
111
 
 
112
    connect(m_iface, SIGNAL(stateChanged()), SIGNAL(stateChanged()));
 
113
    connect(m_iface, SIGNAL(enabledServicesChanged()), SIGNAL(enabledServicesChanged()));
 
114
    Q_EMIT stateChanged();
 
115
    Q_EMIT enabledServicesChanged();
 
116
}
 
117
 
 
118
/*!
 
119
  Start a new sync for specified services
 
120
*/
 
121
void SyncMonitorQml::sync(const QStringList &services)
 
122
{
 
123
    if (m_iface) {
 
124
        m_iface->call("sync", services);
 
125
    }
 
126
}
 
127
 
 
128
/*!
 
129
  Cancel current sync for specified services
 
130
*/
 
131
void SyncMonitorQml::cancel(const QStringList &services)
 
132
{
 
133
    if (m_iface) {
 
134
        m_iface->call("cancel", services);
 
135
    }
 
136
}
 
137
 
 
138
/*!
 
139
  Chek if a specific service is enabled or not
 
140
*/
 
141
bool SyncMonitorQml::serviceIsEnabled(const QString &service)
 
142
{
 
143
    return enabledServices().contains(service);
 
144
}