~ps-jenkins/indicator-transfer/ubuntu-vivid-proposed

« back to all changes in this revision

Viewing changes to src/view-console.cpp

  • Committer: Charles Kerr
  • Date: 2014-06-17 01:36:16 UTC
  • mto: This revision was merged to the branch mainline in revision 2.
  • Revision ID: charles.kerr@canonical.com-20140617013616-7fcd22wh3hbgaovh
code drop

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2014 Canonical Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authors:
 
17
 *   Charles Kerr <charles.kerr@canonical.com>
 
18
 */
 
19
 
 
20
#include <transfer/controller.h>
 
21
#include <transfer/model.h>
 
22
#include <transfer/view-console.h>
 
23
 
 
24
#include <iostream>
 
25
 
 
26
namespace unity {
 
27
namespace indicator {
 
28
namespace transfer {
 
29
 
 
30
/***
 
31
****
 
32
***/
 
33
 
 
34
ConsoleView::ConsoleView(const std::shared_ptr<Model>& model,
 
35
                         const std::shared_ptr<Controller>& controller)
 
36
{
 
37
  set_model(model);
 
38
  set_controller(controller);
 
39
}
 
40
 
 
41
ConsoleView::~ConsoleView()
 
42
{
 
43
}
 
44
 
 
45
void ConsoleView::set_controller(const std::shared_ptr<Controller>& controller)
 
46
{
 
47
  m_controller = controller;
 
48
}
 
49
 
 
50
static std::string dump_transfer(const std::shared_ptr<Transfer>& transfer)
 
51
{
 
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]",
 
53
                              (int)transfer->state,
 
54
                              transfer->id.c_str(),
 
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,
 
60
                              transfer->progress,
 
61
                              transfer->error_string.c_str(),
 
62
                              transfer->local_path.c_str());
 
63
  std::string ret = tmp;
 
64
  g_free(tmp);
 
65
  return ret;
 
66
}
 
67
 
 
68
void ConsoleView::set_model(const std::shared_ptr<Model>& model)
 
69
{
 
70
  m_connections.clear();
 
71
 
 
72
  if ((m_model = model))
 
73
    {
 
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;
 
76
      }));
 
77
 
 
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;
 
80
      }));
 
81
 
 
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;
 
84
      }));
 
85
    }
 
86
}
 
87
 
 
88
/***
 
89
****
 
90
***/
 
91
 
 
92
} // namespace transfer
 
93
} // namespace indicator
 
94
} // namespace unity