~unity-api-team/storage-framework/vivid

« back to all changes in this revision

Viewing changes to src/qt/client/internal/remote_client/LookupHandler.cpp

  • Committer: Michi Henning
  • Date: 2016-07-11 05:44:31 UTC
  • mfrom: (8.10.31 decltype)
  • mto: (8.1.15 devel)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: michi.henning@canonical.com-20160711054431-jj23l6adsm7367b7
Merged decltype branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <unity/storage/qt/client/internal/remote_client/LookupHandler.h>
2
 
 
3
 
#include <unity/storage/qt/client/Exceptions.h>
4
 
#include <unity/storage/qt/client/File.h>
5
 
#include <unity/storage/qt/client/Folder.h>
6
 
#include <unity/storage/qt/client/internal/remote_client/dbusmarshal.h>
7
 
#include <unity/storage/qt/client/internal/remote_client/FileImpl.h>
8
 
#include <unity/storage/qt/client/internal/remote_client/FolderImpl.h>
9
 
 
10
 
#include <cassert>
11
 
 
12
 
using namespace std;
13
 
 
14
 
namespace unity
15
 
{
16
 
namespace storage
17
 
{
18
 
namespace qt
19
 
{
20
 
namespace client
21
 
{
22
 
namespace internal
23
 
{
24
 
namespace remote_client
25
 
{
26
 
 
27
 
LookupHandler::LookupHandler(QDBusPendingReply<QList<storage::internal::ItemMetadata>> const& reply,
28
 
                             weak_ptr<Root> const& root)
29
 
    : watcher_(reply, this)
30
 
    , root_(root.lock())
31
 
{
32
 
    assert(root_);
33
 
    connect(&watcher_, &QDBusPendingCallWatcher::finished, this, &LookupHandler::finished);
34
 
    qf_.reportStarted();
35
 
}
36
 
 
37
 
QFuture<QVector<shared_ptr<Item>>> LookupHandler::future()
38
 
{
39
 
    return qf_.future();
40
 
}
41
 
 
42
 
void LookupHandler::finished(QDBusPendingCallWatcher* call)
43
 
{
44
 
    deleteLater();
45
 
 
46
 
    QDBusPendingReply<QList<storage::internal::ItemMetadata>> reply = *call;
47
 
    if (reply.isError())
48
 
    {
49
 
        qDebug() << reply.error().message();  // TODO, remove this
50
 
        qf_.reportException(StorageException());  // TODO
51
 
        qf_.reportFinished();
52
 
        return;
53
 
    }
54
 
 
55
 
    QVector<Item::SPtr> items;
56
 
    auto metadata = reply.value();
57
 
    for (auto const& md : metadata)
58
 
    {
59
 
        Item::SPtr item;
60
 
        switch (md.type)
61
 
        {
62
 
            case ItemType::file:
63
 
            {
64
 
                item = FileImpl::make_file(md, root_);
65
 
                break;
66
 
            }
67
 
            case ItemType::folder:
68
 
            {
69
 
                item = FolderImpl::make_folder(md, root_);
70
 
                break;
71
 
            }
72
 
            case ItemType::root:
73
 
            {
74
 
                // TODO: log impossible item type here
75
 
                continue;
76
 
                break;
77
 
            }
78
 
            default:
79
 
            {
80
 
                abort();  // LCOV_EXCL_LINE  // Impossible
81
 
            }
82
 
        }
83
 
        items.append(item);
84
 
    }
85
 
    if (items.isEmpty())
86
 
    {
87
 
        qf_.reportException(StorageException());  // TODO
88
 
    }
89
 
    else
90
 
    {
91
 
        qf_.reportResult(items);
92
 
    }
93
 
    qf_.reportFinished();
94
 
}
95
 
 
96
 
}  // namespace remote_client
97
 
}  // namespace internal
98
 
}  // namespace client
99
 
}  // namespace qt
100
 
}  // namespace storage
101
 
}  // namespace unity
102
 
 
103
 
#include "LookupHandler.moc"