2
* Copyright © 2013 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Thomas Voß <thomas.voss@canonical.com>
19
#include "ContentServiceInterface.h"
21
#include <com/ubuntu/content/hub.h>
22
#include <com/ubuntu/content/import_export_handler.h>
23
#include <com/ubuntu/content/peer.h>
24
#include <com/ubuntu/content/scope.h>
25
#include <com/ubuntu/content/store.h>
26
#include <com/ubuntu/content/type.h>
28
#include <QStandardPaths>
32
namespace cuc = com::ubuntu::content;
34
struct cuc::Hub::Private
36
Private(QObject* parent) : service(
37
new com::ubuntu::content::Service(
38
"com.ubuntu.content.Service",
40
QDBusConnection::sessionBus(),
45
com::ubuntu::content::Service* service;
48
cuc::Hub::Hub(QObject* parent) : QObject(parent), d{new cuc::Hub::Private{this}}
56
cuc::Hub* cuc::Hub::Client::instance()
58
static cuc::Hub* hub = new cuc::Hub(nullptr);
62
void cuc::Hub::register_import_export_handler(cuc::ImportExportHandler*)
66
const cuc::Store* cuc::Hub::store_for_scope_and_type(cuc::Scope scope, cuc::Type type)
68
static const std::map<std::pair<cuc::Scope, cuc::Type>, cuc::Store*> lut =
70
{{cuc::system, cuc::Type::Known::pictures()}, new cuc::Store{"/content/Pictures", this}},
71
{{cuc::system, cuc::Type::Known::music()}, new cuc::Store{"/content/Music", this}},
72
{{cuc::system, cuc::Type::Known::documents()}, new cuc::Store{"/content/Documents", this}},
73
{{cuc::user, cuc::Type::Known::pictures()}, new cuc::Store{QStandardPaths::writableLocation(QStandardPaths::PicturesLocation), this}},
74
{{cuc::user, cuc::Type::Known::music()}, new cuc::Store{QStandardPaths::writableLocation(QStandardPaths::MusicLocation), this}},
75
{{cuc::user, cuc::Type::Known::documents()}, new cuc::Store{QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), this}},
76
{{cuc::app, cuc::Type::Known::pictures()}, new cuc::Store{QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/Pictures", this}},
77
{{cuc::app, cuc::Type::Known::music()}, new cuc::Store{QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/Music", this}},
78
{{cuc::app, cuc::Type::Known::documents()}, new cuc::Store{QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/Documents", this}},
81
auto it = lut.find(std::make_pair(scope, type));
89
cuc::Peer cuc::Hub::default_peer_for_type(cuc::Type t)
91
auto reply = d->service->DefaultPeerForType(t.id());
92
reply.waitForFinished();
95
return cuc::Peer::unknown();
97
return cuc::Peer(reply.value(), this);
100
QVector<cuc::Peer> cuc::Hub::known_peers_for_type(cuc::Type t)
102
QVector<cuc::Peer> result;
104
auto reply = d->service->KnownPeersForType(t.id());
105
reply.waitForFinished();
110
auto ids = reply.value();
112
Q_FOREACH(const QString& id, ids)
114
result << cuc::Peer(id, this);
120
cuc::Transfer* cuc::Hub::create_import_for_type_from_peer(cuc::Type, cuc::Peer)
125
void cuc::Hub::quit()