20 #include <QDBusPendingReply>
21 #include <QDBusObjectPath>
22 #include <glog/logging.h>
32 namespace DownloadManager {
34 DownloadManagerPCW::DownloadManagerPCW(
const QDBusConnection& conn,
35 const QString& servicePath,
36 const QDBusPendingCall& call,
40 : PendingCallWatcher(conn, servicePath, call, parent),
43 CHECK(connect(
this, &QDBusPendingCallWatcher::finished,
44 this, &DownloadManagerPCW::onFinished))
45 <<
"Could not connect to signal";
49 DownloadManagerPCW::onFinished(QDBusPendingCallWatcher* watcher) {
50 QDBusPendingReply<QDBusObjectPath> reply = *watcher;
51 auto man =
static_cast<Manager*
>(parent());
52 if (reply.isError()) {
53 qDebug() <<
"ERROR" << reply.error() << reply.error().type();
55 auto err =
new DBusError(reply.error());
56 auto down =
new DownloadImpl(_conn, err);
58 emit man->downloadCreated(down);
60 qDebug() <<
"Success!";
61 auto path = reply.value();
62 auto down =
new DownloadImpl(_conn, _servicePath, path);
63 emit man->downloadCreated(down);
66 emit callbackExecuted();
67 watcher->deleteLater();
70 DownloadsListManagerPCW::DownloadsListManagerPCW(
const QDBusConnection& conn,
71 const QString& servicePath,
72 const QDBusPendingCall& call,
76 : PendingCallWatcher(conn, servicePath, call, parent),
79 connect(
this, &QDBusPendingCallWatcher::finished,
80 this, &DownloadsListManagerPCW::onFinished);
84 DownloadsListManagerPCW::onFinished(QDBusPendingCallWatcher* watcher) {
85 QDBusPendingReply<QList<QDBusObjectPath> > reply = *watcher;
86 DownloadsListImpl* list;
87 auto man =
static_cast<Manager*
>(parent());
88 if (reply.isError()) {
89 qDebug() <<
"ERROR" << reply.error() << reply.error().type();
91 auto err =
new DBusError(reply.error());
92 list =
new DownloadsListImpl(err);
94 emit man->downloadsFound(list);
96 qDebug() <<
"Success!";
97 auto paths = reply.value();
98 QList<QSharedPointer<Download> > downloads;
99 list =
new DownloadsListImpl();
100 foreach(
const QDBusObjectPath& path, paths) {
101 QSharedPointer<Download> down =
102 QSharedPointer<Download>(
new DownloadImpl(_conn,
103 _servicePath, path));
104 downloads.append(down);
106 list =
new DownloadsListImpl(downloads);
107 emit man->downloadsFound(list);
110 emit callbackExecuted();
111 watcher->deleteLater();
114 MetadataDownloadsListManagerPCW::MetadataDownloadsListManagerPCW(
115 const QDBusConnection& conn,
116 const QString& servicePath,
117 const QDBusPendingCall& call,
119 const QString& value,
123 : PendingCallWatcher(conn, servicePath, call, parent),
128 connect(
this, &QDBusPendingCallWatcher::finished,
129 this, &MetadataDownloadsListManagerPCW::onFinished);
133 MetadataDownloadsListManagerPCW::onFinished(QDBusPendingCallWatcher* watcher) {
134 QDBusPendingReply<QList<QDBusObjectPath> > reply = *watcher;
135 DownloadsListImpl* list;
136 auto man =
static_cast<Manager*
>(parent());
137 if (reply.isError()) {
138 qDebug() <<
"ERROR" << reply.error() << reply.error().type();
140 auto err =
new DBusError(reply.error());
141 list =
new DownloadsListImpl(err);
142 _errCb(_key, _value, list);
143 emit man->downloadsWithMetadataFound(_key, _value, list);
145 qDebug() <<
"Success!";
146 auto paths = reply.value();
147 QList<QSharedPointer<Download> > downloads;
148 list =
new DownloadsListImpl();
149 foreach(
const QDBusObjectPath& path, paths) {
150 QSharedPointer<Download> down =
151 QSharedPointer<Download>(
new DownloadImpl(
152 _conn, _servicePath, path));
153 downloads.append(down);
155 list =
new DownloadsListImpl(downloads);
156 emit man->downloadsWithMetadataFound(_key, _value, list);
157 _cb(_key, _value, list);
159 emit callbackExecuted();
160 watcher->deleteLater();
163 GroupManagerPCW::GroupManagerPCW(
const QDBusConnection& conn,
164 const QString& servicePath,
165 const QDBusPendingCall& call,
169 : PendingCallWatcher(conn, servicePath, call, parent),
172 CHECK(connect(
this, &QDBusPendingCallWatcher::finished,
173 this, &GroupManagerPCW::onFinished))
174 <<
"Could not connect to signal";
178 GroupManagerPCW::onFinished(QDBusPendingCallWatcher* watcher) {
179 QDBusPendingReply<QDBusObjectPath> reply = *watcher;
180 auto man =
static_cast<Manager*
>(parent());
181 if (reply.isError()) {
183 auto err =
new DBusError(reply.error());
184 auto down =
new GroupDownload(err);
186 emit man->groupCreated(down);
188 QDBusObjectPath path = reply.value();
189 auto down =
new GroupDownload(path);
190 emit man->groupCreated(down);
193 emit callbackExecuted();
194 watcher->deleteLater();
std::function< void(Download *)> DownloadCb
std::function< void(const QString &, const QString &, DownloadsList *)> MetadataDownloadsListCb
std::function< void(GroupDownload *)> GroupCb
std::function< void(DownloadsList *)> DownloadsListCb