2
* Copyright (C) 2016 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
* Authors: Michi Henning <michi.henning@canonical.com>
19
#include <unity/storage/qt/client/internal/remote_client/RuntimeImpl.h>
21
#include <unity/storage/qt/client/Account.h>
22
#include <unity/storage/qt/client/Exceptions.h>
23
#include <unity/storage/qt/client/internal/make_future.h>
24
#include <unity/storage/qt/client/internal/remote_client/AccountImpl.h>
25
#include <unity/storage/qt/client/internal/remote_client/dbusmarshal.h>
27
#include <QDBusMetaType>
29
// TODO: Hack until we can use the registry instead
30
#include <OnlineAccounts/Account>
32
#pragma GCC diagnostic push
33
#pragma GCC diagnostic ignored "-Wold-style-cast"
35
#pragma GCC diagnostic pop
54
namespace remote_client
57
RuntimeImpl::RuntimeImpl(QDBusConnection const& bus)
60
if (!conn_.isConnected())
62
throw LocalCommsException("Runtime: cannot connect to session bus"); // LCOV_EXCL_LINE
64
qDBusRegisterMetaType<unity::storage::internal::ItemMetadata>();
65
qDBusRegisterMetaType<QList<unity::storage::internal::ItemMetadata>>();
68
RuntimeImpl::~RuntimeImpl()
75
catch (std::exception const&)
77
qCritical() << "shutdown error"; // TODO, log the error properly
82
void RuntimeImpl::shutdown()
84
if (destroyed_.exchange(true))
88
conn_.disconnectFromBus(conn_.name());
91
QFuture<QVector<Account::SPtr>> RuntimeImpl::accounts()
95
manager_.reset(new OnlineAccounts::Manager("", conn_));
96
connect(manager_.get(), &OnlineAccounts::Manager::ready, this, &RuntimeImpl::manager_ready);
97
connect(&timer_, &QTimer::timeout, this, &RuntimeImpl::timeout);
98
timer_.setSingleShot(true);
106
QDBusConnection& RuntimeImpl::connection()
111
void RuntimeImpl::manager_ready()
116
QVector<Account::SPtr> accounts;
117
for (auto const& a : manager_->availableAccounts("google-drive-scope"))
119
qDebug() << "got account:" << a->displayName() << a->serviceId() << a->id();
120
auto impl = new AccountImpl(public_instance_, a->id(), "", a->serviceId(), a->displayName());
121
Account::SPtr acc(new Account(impl));
122
impl->set_public_instance(acc);
123
accounts.append(acc);
125
accounts_ = accounts;
126
make_ready_future(qf_, accounts);
128
catch (StorageException const& e)
130
make_exceptional_future(qf_, e);
134
void RuntimeImpl::timeout()
136
make_exceptional_future(qf_, ResourceException("timeout error")); // TODO
139
} // namespace local_client
140
} // namespace internal
141
} // namespace client
143
} // namespace storage