2
* Copyright (C) 2016 Canonical, Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Xavi Garcia <xavi.garcia.mena@canonical.com>
18
* Charles Kerr <charles.kerr@canonical.com>
21
#include "util/connection-helper.h"
22
#include "storage-framework/storage_framework_client.h"
23
#include "helper/restore-helper.h"
24
#include "service/app-const.h" // DEKKO_APP_ID
25
#include "service/keeper-task-restore.h"
26
#include "service/keeper-task.h"
27
#include "service/private/keeper-task_p.h"
29
namespace sf = unity::storage::qt::client;
31
class KeeperTaskRestorePrivate : public KeeperTaskPrivate
33
Q_DECLARE_PUBLIC(KeeperTaskRestore)
35
KeeperTaskRestorePrivate(KeeperTask * keeper_task,
36
KeeperTask::TaskData & task_data,
37
QSharedPointer<HelperRegistry> const & helper_registry,
38
QSharedPointer<StorageFrameworkClient> const & storage)
39
: KeeperTaskPrivate(keeper_task, task_data, helper_registry, storage)
43
~KeeperTaskRestorePrivate() = default;
45
QStringList get_helper_urls() const
47
return helper_registry_->get_restore_helper_urls(task_data_.metadata);
52
qDebug() << "Initializing a restore helper";
53
helper_.reset(new RestoreHelper(DEKKO_APP_ID), [](Helper *h){h->deleteLater();}); // TODO change this to a restore helper
54
qDebug() << "Helper " << static_cast<void*>(helper_.data()) << " was created";
57
void ask_for_downloader()
59
qDebug() << "asking storage framework for a socket for reading";
62
task_data_.metadata.get_property(Metadata::FILE_NAME_KEY, file_name);
63
if (file_name.isEmpty())
65
qWarning() << "ERROR: the restore task does not provide a valid file name to read from.";
70
task_data_.metadata.get_property(Metadata::DIR_NAME_KEY, dir_name);
71
if (dir_name.isEmpty())
73
qWarning() << "ERROR: the restore task does not provide a valid directory name.";
77
// extract the dir_name.
78
connections_.connect_future(
79
storage_->get_new_downloader(dir_name, file_name),
80
std::function<void(std::shared_ptr<Downloader> const&)>{
81
[this](std::shared_ptr<Downloader> const& downloader){
82
qDebug() << "Downloader is" << static_cast<void*>(downloader.get());
85
qDebug() << "Helper is " << static_cast<void*>(helper_.data());
86
auto restore_helper = qSharedPointerDynamicCast<RestoreHelper>(helper_);
87
restore_helper->set_downloader(downloader);
88
fd = restore_helper->get_helper_socket();
90
qDebug("emitting task_socket_ready(socket=%d)", fd);
91
Q_EMIT(q_ptr->task_socket_ready(fd));
97
ConnectionHelper connections_;
100
KeeperTaskRestore::KeeperTaskRestore(TaskData & task_data,
101
QSharedPointer<HelperRegistry> const & helper_registry,
102
QSharedPointer<StorageFrameworkClient> const & storage,
104
: KeeperTask(*new KeeperTaskRestorePrivate(this, task_data, helper_registry, storage), parent)
108
KeeperTaskRestore::~KeeperTaskRestore() = default;
110
QStringList KeeperTaskRestore::get_helper_urls() const
112
Q_D(const KeeperTaskRestore);
114
return d->get_helper_urls();
117
void KeeperTaskRestore::init_helper()
119
Q_D(KeeperTaskRestore);
124
void KeeperTaskRestore::ask_for_downloader()
126
Q_D(KeeperTaskRestore);
128
d->ask_for_downloader();