Skip to content

Commit e64723a

Browse files
committed
Make Offline::getResults return a wrapper object
This is required to transform qulongulong's into Transaction::Role and Transaction::Error enums. Using these enums directly in QDBusPendingReply<> requires registering them with qDBusRegisterMetaType().
1 parent 7c0825a commit e64723a

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

src/offline.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,51 @@ Q_DECLARE_LOGGING_CATEGORY(PACKAGEKITQT_OFFLINE)
2323

2424
using namespace PackageKit;
2525

26+
Offline::Results::Results(const QDBusPendingCall &call)
27+
: m_reply(call)
28+
{
29+
}
30+
31+
bool Offline::Results::isError() const
32+
{
33+
return m_reply.isError();
34+
}
35+
36+
void Offline::Results::waitForFinished()
37+
{
38+
m_reply.waitForFinished();
39+
}
40+
41+
bool Offline::Results::success() const
42+
{
43+
return m_reply.argumentAt<0>();
44+
}
45+
46+
QStringList Offline::Results::packageIds() const
47+
{
48+
return m_reply.argumentAt<1>();
49+
}
50+
51+
Transaction::Role Offline::Results::role() const
52+
{
53+
return static_cast<Transaction::Role>(m_reply.argumentAt<2>());
54+
}
55+
56+
qulonglong Offline::Results::timeFinished() const
57+
{
58+
return m_reply.argumentAt<3>();
59+
}
60+
61+
Transaction::Error Offline::Results::error() const
62+
{
63+
return static_cast<Transaction::Error>(m_reply.argumentAt<4>());
64+
}
65+
66+
QString Offline::Results::errorDescription() const
67+
{
68+
return m_reply.argumentAt<5>();
69+
}
70+
2671
Offline::Offline(QObject *parent) : QObject(parent)
2772
, d_ptr(new OfflinePrivate(this))
2873
{
@@ -131,7 +176,7 @@ QDBusPendingReply<> Offline::triggerUpgrade(Action action)
131176
return QDBusConnection::systemBus().asyncCall(msg, 24 * 60 * 1000 * 1000);
132177
}
133178

134-
QDBusPendingReply<bool, QStringList, Transaction::Role, qint64, Transaction::Error, QString> Offline::getResults()
179+
Offline::Results Offline::getResults()
135180
{
136181
// Manually invoke dbus because the qdbusxml2cpp does not allow
137182
// setting the ALLOW_INTERACTIVE_AUTHORIZATION flag

src/offline.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@ class PACKAGEKITQT_LIBRARY Offline : public QObject
4848
};
4949
Q_ENUM(Action)
5050

51+
/**
52+
* Wrapper class representing the returning value of getResults()
53+
*/
54+
class Results
55+
{
56+
friend class Offline;
57+
public:
58+
Results(const QDBusPendingCall &call);
59+
60+
bool isError() const;
61+
void waitForFinished();
62+
63+
bool success() const;
64+
QStringList packageIds() const;
65+
Transaction::Role role() const;
66+
qulonglong timeFinished() const;
67+
Transaction::Error error() const;
68+
QString errorDescription() const;
69+
private:
70+
QDBusPendingReply<bool, QStringList, quint32, qulonglong, quint32, QString> m_reply;
71+
};
72+
5173
~Offline();
5274

5375
Q_PROPERTY(QVariantMap preparedUpgrade READ preparedUpgrade NOTIFY changed)
@@ -104,7 +126,7 @@ class PACKAGEKITQT_LIBRARY Offline : public QObject
104126
/**
105127
* Returns the information about the last offline action performed.
106128
*/
107-
QDBusPendingReply<bool, QStringList, Transaction::Role, qint64, Transaction::Error, QString> getResults();
129+
Results getResults();
108130

109131
/**
110132
* Cancels the offline update so the next boot procceeds as normal.

0 commit comments

Comments
 (0)