2
* Copyright 2014 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
* Charles Kerr <charles.kerr@canonical.com>
20
#include <transfer/controller.h>
21
#include <transfer/model.h>
22
#include <transfer/view-console.h>
34
ConsoleView::ConsoleView(const std::shared_ptr<Model>& model,
35
const std::shared_ptr<Controller>& controller)
38
set_controller(controller);
41
ConsoleView::~ConsoleView()
45
void ConsoleView::set_controller(const std::shared_ptr<Controller>& controller)
47
m_controller = controller;
50
static std::string dump_transfer(const std::shared_ptr<Transfer>& transfer)
52
auto tmp = g_strdup_printf ("state [%d] id [%s] title[%s] app_icon[%s] time_started[%zu] seconds_left[%d] speed[%f KiB/s] progress[%f] error_string[%s] local_path[%s]",
55
transfer->title.c_str(),
56
transfer->app_icon.c_str(),
57
(size_t)transfer->time_started,
58
transfer->seconds_left,
59
transfer->speed_bps/1024.0,
61
transfer->error_string.c_str(),
62
transfer->local_path.c_str());
63
std::string ret = tmp;
68
void ConsoleView::set_model(const std::shared_ptr<Model>& model)
70
m_connections.clear();
72
if ((m_model = model))
74
m_connections.insert(m_model->added().connect([this](const Transfer::Id& id){
75
std::cerr << "view added: " << dump_transfer(m_model->get(id)) << std::endl;
78
m_connections.insert(m_model->changed().connect([this](const Transfer::Id& id){
79
std::cerr << "view changed: " << dump_transfer(m_model->get(id)) << std::endl;
82
m_connections.insert(m_model->removed().connect([this](const Transfer::Id& id){
83
std::cerr << "view removing: " << dump_transfer(m_model->get(id)) << std::endl;
92
} // namespace transfer
93
} // namespace indicator