14
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Didier Roche <didier.roche@canonical.com>
17
* Diego Sarmentero <diego.sarmentero@canonical.com>
21
21
#include "update.h"
22
#include <QStringList>
23
#include <apt-pkg/debversion.h>
27
// FIXME: need to do this better including #include "../../src/i18n.h"
30
QString _(const char *text)
32
return QString::fromUtf8(dgettext(0, text));
25
namespace UpdatePlugin {
35
27
Update::Update(QObject *parent) :
39
m_currentBuildNumber(-1),
40
m_systemBusConnection (QDBusConnection::systemBus()),
41
m_SystemServiceIface ("com.canonical.SystemImage",
43
"com.canonical.SystemImage",
44
m_systemBusConnection)
47
connect(&m_SystemServiceIface, SIGNAL(UpdateAvailableStatus(bool, bool, QString, int, QString, QString)),
48
this, SLOT(ProcessAvailableStatus(bool, bool, QString, int, QString, QString)));
49
// signals to forward directly to QML
50
connect(&m_SystemServiceIface, SIGNAL(UpdateProgress(int, double)),
51
this, SIGNAL(updateProgress(int, double)));
52
connect(&m_SystemServiceIface, SIGNAL(UpdatePaused(int)),
53
this, SIGNAL(updatePaused(int)));
54
connect(&m_SystemServiceIface, SIGNAL(UpdateDownloaded()),
55
this, SIGNAL(updateDownloaded()));
56
connect(&m_SystemServiceIface, SIGNAL(UpdateFailed(int, QString)),
57
this, SIGNAL(updateFailed(int, QString)));
58
connect(&m_SystemServiceIface, SIGNAL(SettingChanged(QString, QString)),
59
this, SLOT(ProcessSettingChanged(QString, QString)));
61
this->CheckForUpdate();
68
void Update::CheckForUpdate() {
69
m_SystemServiceIface.asyncCall("CheckForUpdate");
72
void Update::DownloadUpdate() {
73
m_SystemServiceIface.asyncCall("DownloadUpdate");
76
QString Update::ApplyUpdate() {
77
QDBusReply<QString> reply = m_SystemServiceIface.call("ApplyUpdate");
80
return _("Can't apply the current update (can't contact service)");
83
QString Update::CancelUpdate() {
84
QDBusReply<QString> reply = m_SystemServiceIface.call("CancelUpdate");
87
return _("Can't cancel current request (can't contact service)");
90
QString Update::PauseDownload() {
91
QDBusReply<QString> reply = m_SystemServiceIface.call("PauseDownload");
94
return _("Can't pause current request (can't contact service)");
97
QString Update::InfoMessage() {
101
void Update::SetInfoMessage(QString infoMessage) {
102
m_infoMessage = infoMessage;
103
Q_EMIT infoMessageChanged();
106
int Update::currentBuildNumber() {
107
if (m_currentBuildNumber != -1)
108
return m_currentBuildNumber;
110
QDBusReply<int> reply = m_SystemServiceIface.call("Info");
112
m_currentBuildNumber = reply.value();
114
return m_currentBuildNumber;
117
int Update::DownloadMode() {
118
if (m_downloadMode != -1)
119
return m_downloadMode;
121
QDBusReply<QString> reply = m_SystemServiceIface.call("GetSetting", "auto_download");
122
int default_mode = 1;
123
if (reply.isValid()) {
126
result = reply.value().toInt(&ok);
128
m_downloadMode = result;
130
m_downloadMode = default_mode;
133
m_downloadMode = default_mode;
134
return m_downloadMode;
137
void Update::SetDownloadMode(int value) {
138
if (m_downloadMode == value)
141
m_downloadMode = value;
142
m_SystemServiceIface.asyncCall("SetSetting", "auto_download", QString::number(value));
145
void Update::ProcessSettingChanged(QString key, QString newvalue) {
146
if(key == "auto_download") {
149
newintValue = newvalue.toInt(&ok);
151
m_downloadMode = newintValue;
152
Q_EMIT downloadModeChanged();
157
QString Update::TranslateFromBackend(QString msg) {
158
// TODO: load in the backend context .mo file
162
void Update::ProcessAvailableStatus(bool isAvailable, bool downloading, QString availableVersion, int updateSize, QString lastUpdateDate, QString errorReason)
164
//TODO: bind with the real description once we can listen to the signal
165
QStringList descriptions;
166
descriptions.append("Description for update1");
167
descriptions.append("Description for update2");
168
descriptions.append("Description for update3");
170
Q_EMIT updateAvailableStatus(isAvailable, downloading, availableVersion, updateSize, lastUpdateDate, descriptions, errorReason);
30
m_download_progress(0),
38
m_systemUpdate(false),
41
m_update_ready(false),
50
void Update::initializeApplication(QString packagename, QString title,
53
m_packagename = packagename;
55
m_local_version = version;
58
void Update::setRemoteVersion(QString& version)
60
m_remote_version = version;
62
int result = debVS.CmpVersion(m_local_version.toUtf8().data(),
63
m_remote_version.toUtf8().data());
65
m_update = result < 0;
68
void Update::setError(QString error)
71
if (!m_error.isEmpty()) {
72
Q_EMIT errorChanged();
76
void Update::setSystemUpdate(bool isSystem)
78
m_systemUpdate = isSystem;
79
Q_EMIT systemUpdateChanged();
82
void Update::setUpdateState(bool state)
84
m_update_state = state;
85
Q_EMIT updatesStateChanged();
88
void Update::setUpdateReady(bool ready)
90
m_update_ready = ready;
91
Q_EMIT updatesReadyChanged();
94
void Update::setSelected(bool value)
97
Q_EMIT selectedChanged();
100
void Update::setBinaryFilesize(int size)
102
m_binary_filesize = size;
103
Q_EMIT binaryFilesizeChanged();
106
void Update::setIconUrl(QString icon) {
108
Q_EMIT iconUrlChanged();
111
void Update::setLastUpdateDate(const QString date)
113
m_lastUpdateDate = date;
114
Q_EMIT lastUpdateDateChanged();
117
void Update::setDownloadProgress(int progress)
119
m_download_progress = progress;
120
Q_EMIT downloadProgressChanged();