-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an Offline class to interface with PackageKit's Offline interface
- Loading branch information
Showing
10 changed files
with
416 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "Offline.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,8 @@ | |
|
||
namespace PackageKit { | ||
|
||
class Offline; | ||
|
||
/** | ||
* \class Daemon daemon.h Daemon | ||
* \author Adrien Bustany \e <[email protected]> | ||
|
@@ -92,17 +94,6 @@ class PACKAGEKITQT_LIBRARY Daemon : public QObject | |
}; | ||
Q_ENUM(Authorize) | ||
|
||
/** | ||
* Actions to trigger | ||
* | ||
* \sa offlineTrigger() | ||
*/ | ||
enum OfflineAction { | ||
OfflineActionPowerOff, /** < powers off the computer after applying offline updates */ | ||
OfflineActionReboot /** < reboots the computer after applying offline updates */ | ||
}; | ||
Q_ENUM(OfflineAction) | ||
|
||
/** | ||
* \brief Returns an instance of the Daemon | ||
* | ||
|
@@ -268,6 +259,12 @@ class PACKAGEKITQT_LIBRARY Daemon : public QObject | |
*/ | ||
static QDBusPendingReply<> suggestDaemonQuit(); | ||
|
||
/** | ||
* Returns a class representing PackageKit offline interface, as with the Daemon | ||
* class this will only have valid properties if isRunning() is true | ||
*/ | ||
Offline *offline() const; | ||
|
||
/** | ||
* Returns the package name from the \p packageID | ||
*/ | ||
|
@@ -809,13 +806,6 @@ class PACKAGEKITQT_LIBRARY Daemon : public QObject | |
*/ | ||
static Transaction *whatProvides(const QString &search, Transaction::Filters filters = Transaction::FilterNone); | ||
|
||
/** | ||
* Triggers the offline update for the next boot | ||
* | ||
* @p action is the action to take when finished applying updates | ||
*/ | ||
static QDBusPendingReply<> offlineTrigger(OfflineAction action); | ||
|
||
Q_SIGNALS: | ||
void isRunningChanged(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
/* | ||
* This file is part of the PackageKitQt project | ||
* Copyright (C) 2018 Daniel Nicoletti <[email protected]> | ||
* | ||
* 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" |
Oops, something went wrong.