~ken-vandine/indicator-transfer/ual_api_change

« back to all changes in this revision

Viewing changes to src/controller.cpp

  • Committer: CI Train Bot
  • Author(s): Renato Araujo Oliveira Filho
  • Date: 2015-08-19 19:17:06 UTC
  • mfrom: (29.6.11 add-plugins-fix-model-clear)
  • Revision ID: ci-train-bot@canonical.com-20150819191706-k1jnor3lh4n26zax
Added 'clear' function into the Source interface.
Call 'Source.clear' in the 'Controller.clear_all' function.
Does not keep a separated copy of source model inside of the Controller class.
Changed the return of 'Source.get_model()' to const.
Update unit tests.
Approved by: Charles Kerr, PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
****
28
28
***/
29
29
 
30
 
Controller::Controller(const std::shared_ptr<MutableModel>& model,
31
 
                       const std::shared_ptr<Source>& source):
32
 
  m_model(model),
 
30
Controller::Controller(const std::shared_ptr<Source>& source):
33
31
  m_source(source)
34
32
{
35
33
}
40
38
 
41
39
void Controller::pause_all()
42
40
{
43
 
  for(const auto& id : m_model->get_ids())
 
41
  for(const auto& id : get_ids())
44
42
    pause(id);
45
43
}
46
44
 
47
45
void Controller::resume_all()
48
46
{
49
 
  for(const auto& id : m_model->get_ids())
 
47
  for(const auto& id : get_ids())
50
48
    resume(id);
51
49
}
52
50
 
53
51
void Controller::clear_all()
54
52
{
55
 
  for (const auto& transfer : m_model->get_all())
56
 
    if (transfer->can_clear())
57
 
      m_model->remove(transfer->id);
 
53
  for (const auto& id : get_ids())
 
54
    clear(id);
58
55
}
59
56
 
60
57
void Controller::tap(const Transfer::Id& id)
61
58
{
62
 
  const auto transfer = m_model->get(id);
 
59
  const auto transfer = get(id);
63
60
  g_return_if_fail (transfer);
64
61
 
65
62
  if (transfer->can_start())
75
72
 
76
73
void Controller::pause(const Transfer::Id& id)
77
74
{
78
 
  const auto& transfer = m_model->get(id);
 
75
  const auto& transfer = get(id);
79
76
  if (transfer && transfer->can_pause())
80
77
    m_source->pause(id);
81
78
}
82
79
 
83
80
void Controller::cancel(const Transfer::Id& id)
84
81
{
85
 
  const auto& transfer = m_model->get(id);
 
82
  const auto& transfer = get(id);
86
83
  if (transfer && transfer->can_cancel())
87
84
    m_source->cancel(id);
88
85
}
89
86
 
 
87
void Controller::clear(const Transfer::Id& id)
 
88
{
 
89
  const auto& transfer = get(id);
 
90
  if (transfer && transfer->can_clear())
 
91
    m_source->clear(id);
 
92
}
 
93
 
90
94
void Controller::resume(const Transfer::Id& id)
91
95
{
92
 
  const auto& transfer = m_model->get(id);
 
96
  const auto& transfer = get(id);
93
97
  if (transfer && transfer->can_resume())
94
98
    m_source->resume(id);
95
99
}
96
100
 
97
101
void Controller::start(const Transfer::Id& id)
98
102
{
99
 
  const auto& transfer = m_model->get(id);
 
103
  const auto& transfer = get(id);
100
104
  if (transfer && transfer->can_start())
101
105
    m_source->start(id);
102
106
}
108
112
 
109
113
void Controller::open_app(const Transfer::Id& id)
110
114
{
111
 
  m_source->open_app(id);
 
115
    m_source->open_app(id);
 
116
}
 
117
 
 
118
int Controller::size() const
 
119
{
 
120
    return m_source->get_model()->size();
 
121
}
 
122
 
 
123
int Controller::count(const Transfer::Id& id) const
 
124
{
 
125
    return m_source->get_model()->count(id);
 
126
}
 
127
 
 
128
const std::shared_ptr<const MutableModel> Controller::get_model()
 
129
{
 
130
    return m_source->get_model();
 
131
}
 
132
 
 
133
std::set<Transfer::Id> Controller::get_ids() const
 
134
{
 
135
    return m_source->get_model()->get_ids();
 
136
}
 
137
 
 
138
std::shared_ptr<Transfer> Controller::get(const Transfer::Id& id) const
 
139
{
 
140
    return m_source->get_model()->get(id);
112
141
}
113
142
 
114
143
/***