File: offline.cpp

package info (click to toggle)
packagekit-qt 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 376 kB
  • sloc: cpp: 2,539; makefile: 7
file content (187 lines) | stat: -rw-r--r-- 5,291 bytes parent folder | download | duplicates (2)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
 * This file is part of the PackageKitQt project
 * Copyright (C) 2018 Daniel Nicoletti <dantti12@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB. If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */
#include "offline_p.h"

Q_DECLARE_LOGGING_CATEGORY(PACKAGEKITQT_OFFLINE)

using namespace PackageKit;

Offline::Offline(QObject *parent) : QObject(parent)
  , d_ptr(new OfflinePrivate(this))
{
    QDBusConnection::systemBus().connect(PK_NAME,
                                         PK_PATH,
                                         DBUS_PROPERTIES,
                                         QLatin1String("PropertiesChanged"),
                                         this,
                                         SLOT(propertiesChanged(QString,QVariantMap,QStringList)));
}

Offline::~Offline()
{
    delete d_ptr;
}

QVariantMap Offline::preparedUpgrade() const
{
    Q_D(const Offline);
    return d->preparedUpgrade;
}

Offline::Action Offline::triggerAction() const
{
    Q_D(const Offline);
    return d->triggerAction;
}

bool Offline::updatePrepared() const
{
    Q_D(const Offline);
    return d->updatePrepared;
}

bool Offline::updateTriggered() const
{
    Q_D(const Offline);
    return d->updateTriggered;
}

bool Offline::upgradePrepared() const
{
    Q_D(const Offline);
    return d->upgradePrepared;
}

bool Offline::upgradeTriggered() const
{
    Q_D(const Offline);
    return d->upgradeTriggered;
}

QDBusPendingReply<> Offline::trigger(Action action)
{
    Q_D(Offline);

    QString actionStr;
    switch(action) {
    case ActionPowerOff:
        actionStr = QStringLiteral("power-off");
        break;
    case ActionReboot:
        actionStr = QStringLiteral("reboot");
        break;
    case ActionUnset:
        break;
    };
    Q_ASSERT(!actionStr.isEmpty());

    return d->iface.Trigger(actionStr);
}

QDBusPendingReply<> Offline::triggerUpgrade(Action action)
{
    Q_D(Offline);

    QString actionStr;
    switch(action) {
    case ActionPowerOff:
        actionStr = QStringLiteral("power-off");
        break;
    case ActionReboot:
        actionStr = QStringLiteral("reboot");
        break;
    case ActionUnset:
        break;
    };
    Q_ASSERT(!actionStr.isEmpty());

    return d->iface.TriggerUpgrade(actionStr);
}

QDBusPendingReply<> Offline::cancel()
{
    Q_D(Offline);
    return d->iface.Cancel();
}

QDBusPendingReply<> Offline::clearResults()
{
    Q_D(Offline);
    return d->iface.ClearResults();
}

void Offline::getPrepared()
{
    Q_D(Offline);
    QDBusPendingReply<QStringList> reply = d->iface.GetPrepared();
    auto watcher = new QDBusPendingCallWatcher(reply, this);
    connect(watcher, &QDBusPendingCallWatcher::finished, this, [=] (QDBusPendingCallWatcher *call) {
        QDBusPendingReply<QStringList> reply = *call;
        QStringList pkgids;
        if (!reply.isError()) {
            pkgids = reply.argumentAt<0>();
        } else {
            qCWarning(PACKAGEKITQT_OFFLINE) << "Failed to GetPrepared" << reply.error();
        }
        Q_EMIT preparedUpdates(pkgids);
        call->deleteLater();
    });
}

void OfflinePrivate::updateProperties(const QVariantMap &properties)
{
    Q_Q(Offline);

    QVariantMap::ConstIterator it = properties.constBegin();
    while (it != properties.constEnd()) {
        const QString &property = it.key();
        const QVariant &value = it.value();
        if (property == QLatin1String("PreparedUpgrade")) {
            preparedUpgrade = value.toMap();;
        } else if (property == QLatin1String("TriggerAction")) {
            const QString actionStr = value.toString();
            if (actionStr == QLatin1String("power-off")) {
                triggerAction = Offline::ActionPowerOff;
            } else if (actionStr == QLatin1String("reboot")) {
                triggerAction = Offline::ActionReboot;
            } else {
                triggerAction = Offline::ActionUnset;
            }
        } else if (property == QLatin1String("UpdatePrepared")) {
            updatePrepared = value.toBool();
        } else if (property == QLatin1String("UpdateTriggered")) {
            updateTriggered = value.toBool();
        } else if (property == QLatin1String("UpgradePrepared")) {
            upgradePrepared = value.toBool();
        } else if (property == QLatin1String("UpgradeTriggered")) {
            upgradeTriggered = value.toBool();
        } else {
            qCWarning(PACKAGEKITQT_OFFLINE) << "Unknown property:" << property << value;
        }

        ++it;
    }

    if (!properties.isEmpty()) {
        q->changed();
    }
}

#include "moc_offline.cpp"