19 #include <QDBusPendingReply> 
   20 #include <QDBusObjectPath> 
   22 #include <boost/log/sources/record_ostream.hpp> 
   23 #include <boost/log/sources/severity_feature.hpp> 
   36 namespace DownloadManager {
 
   38 using namespace Logging;
 
   40 DownloadManagerPCW::DownloadManagerPCW(
const QDBusConnection& conn,
 
   41                                        const QString& servicePath,
 
   42                                        const QDBusPendingCall& call,
 
   46     : PendingCallWatcher(conn, servicePath, call, parent),
 
   49     auto connected = connect(
this, &QDBusPendingCallWatcher::finished,
 
   50         this, &DownloadManagerPCW::onFinished);
 
   53             "Could not connect to signal &QDBusPendingCallWatcher::finished");
 
   58 DownloadManagerPCW::onFinished(QDBusPendingCallWatcher* watcher) {
 
   59     QDBusPendingReply<QDBusObjectPath> reply = *watcher;
 
   60     auto man = 
static_cast<Manager*
>(parent());
 
   61     if (reply.isError()) {
 
   62         auto dbusErr = reply.error();
 
   64             QString(
"%1 %2").arg(dbusErr.name()).arg(dbusErr.message()));
 
   65         auto err = 
new DBusError(reply.error());
 
   66         auto down = 
new DownloadImpl(_conn, err);
 
   68         emit man->downloadCreated(down);
 
   70         auto path = reply.value();
 
   71         auto down = 
new DownloadImpl(_conn, _servicePath, path);
 
   72         emit man->downloadCreated(down);
 
   75     emit callbackExecuted();
 
   76     watcher->deleteLater();
 
   79 DownloadsListManagerPCW::DownloadsListManagerPCW(
const QDBusConnection& conn,
 
   80                                                  const QString& servicePath,
 
   81                                                  const QDBusPendingCall& call,
 
   85     : PendingCallWatcher(conn, servicePath, call, parent),
 
   88     auto connected = connect(
this, &QDBusPendingCallWatcher::finished,
 
   89         this, &DownloadsListManagerPCW::onFinished);
 
   92             "Could not connect to signal &QDBusPendingCallWatcher::finished");
 
   97 DownloadsListManagerPCW::onFinished(QDBusPendingCallWatcher* watcher) {
 
   98     QDBusPendingReply<QList<QDBusObjectPath> > reply = *watcher;
 
   99     DownloadsListImpl* list;
 
  100     auto man = 
static_cast<Manager*
>(parent());
 
  101     if (reply.isError()) {
 
  102         auto dbusErr = reply.error();
 
  104             QString(
"%1 %2").arg(dbusErr.name()).arg(dbusErr.message()));
 
  105         auto err = 
new DBusError(reply.error());
 
  106         list = 
new DownloadsListImpl(err);
 
  108         emit man->downloadsFound(list);
 
  110         auto paths = reply.value();
 
  111         QList<QSharedPointer<Download> > downloads;
 
  112         list = 
new DownloadsListImpl();
 
  113         foreach(
const QDBusObjectPath& path, paths) {
 
  114             QSharedPointer<Download> down =
 
  115                 QSharedPointer<Download>(
new DownloadImpl(_conn,
 
  116                             _servicePath, path));
 
  117             downloads.append(down);
 
  119         list = 
new DownloadsListImpl(downloads);
 
  120         emit man->downloadsFound(list);
 
  123     emit callbackExecuted();
 
  124     watcher->deleteLater();
 
  127 MetadataDownloadsListManagerPCW::MetadataDownloadsListManagerPCW(
 
  128                                     const QDBusConnection& conn,
 
  129                                     const QString& servicePath,
 
  130                                     const QDBusPendingCall& call,
 
  132                                     const QString& value,
 
  136     : PendingCallWatcher(conn, servicePath, call, parent),
 
  141     auto connected = connect(
this, &QDBusPendingCallWatcher::finished,
 
  142         this, &MetadataDownloadsListManagerPCW::onFinished);
 
  145             "Could not connect to signal &QDBusPendingCallWatcher::finished");
 
  150 MetadataDownloadsListManagerPCW::onFinished(QDBusPendingCallWatcher* watcher) {
 
  151     QDBusPendingReply<QList<QDBusObjectPath> > reply = *watcher;
 
  152     DownloadsListImpl* list;
 
  153     auto man = 
static_cast<Manager*
>(parent());
 
  154     if (reply.isError()) {
 
  155         auto dbusErr = reply.error();
 
  157             QString(
"%1 %2").arg(dbusErr.name()).arg(dbusErr.message()));
 
  158         auto err = 
new DBusError(reply.error());
 
  159         list = 
new DownloadsListImpl(err);
 
  160         _errCb(_key, _value, list);
 
  161         emit man->downloadsWithMetadataFound(_key, _value, list);
 
  163         auto paths = reply.value();
 
  164         QList<QSharedPointer<Download> > downloads;
 
  165         list = 
new DownloadsListImpl();
 
  166         foreach(
const QDBusObjectPath& path, paths) {
 
  167             QSharedPointer<Download> down =
 
  168                 QSharedPointer<Download>(
new DownloadImpl(
 
  169                             _conn, _servicePath, path));
 
  170             downloads.append(down);
 
  172         list = 
new DownloadsListImpl(downloads);
 
  173         emit man->downloadsWithMetadataFound(_key, _value, list);
 
  174         _cb(_key, _value, list);
 
  176     emit callbackExecuted();
 
  177     watcher->deleteLater();
 
  180 GroupManagerPCW::GroupManagerPCW(
const QDBusConnection& conn,
 
  181                                  const QString& servicePath,
 
  182                                  const QDBusPendingCall& call,
 
  186     : PendingCallWatcher(conn, servicePath, call, parent),
 
  189     auto connected = connect(
this, &QDBusPendingCallWatcher::finished,
 
  190         this, &GroupManagerPCW::onFinished);
 
  193             "Could not connect to signal &DownloadPCW::finished");
 
  198 GroupManagerPCW::onFinished(QDBusPendingCallWatcher* watcher) {
 
  199     QDBusPendingReply<QDBusObjectPath> reply = *watcher;
 
  200     auto man = 
static_cast<Manager*
>(parent());
 
  201     if (reply.isError()) {
 
  202         auto dbusErr = reply.error();
 
  204             QString(
"%1 %2").arg(dbusErr.name()).arg(dbusErr.message()));
 
  205         auto err = 
new DBusError(reply.error());
 
  206         auto down = 
new GroupDownload(err);
 
  208         emit man->groupCreated(down);
 
  210         QDBusObjectPath path = reply.value();
 
  211         auto down = 
new GroupDownload(path);
 
  212         emit man->groupCreated(down);
 
  215     emit callbackExecuted();
 
  216     watcher->deleteLater();