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

« back to all changes in this revision

Viewing changes to src/actions-live.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/actions-live.h>
21
 
 
22
 
namespace unity {
23
 
namespace indicator {
24
 
namespace transfer {
25
 
 
26
 
/****
27
 
*****
28
 
****/
29
 
 
30
 
LiveActions::LiveActions(std::shared_ptr<Transfers>& transfers):
31
 
    m_transfers{transfers}
32
 
{
33
 
}
34
 
 
35
 
LiveActions::~LiveActions()
36
 
{
37
 
}
38
 
 
39
 
std::shared_ptr<Transfer> LiveActions::find_transfer_by_id(const Transfer::Id& id) const
40
 
{
41
 
    for (const auto& transfer : m_transfers->get())
42
 
        if (transfer->id() == id)
43
 
            return transfer;
44
 
 
45
 
    return std::shared_ptr<Transfer>();
46
 
}
47
 
 
48
 
void
49
 
LiveActions::pause_all()
50
 
{
51
 
    for (const auto& transfer : m_transfers->get())
52
 
        transfer->pause();
53
 
}
54
 
 
55
 
void
56
 
LiveActions::resume_all()
57
 
{
58
 
    for (const auto& transfer : m_transfers->get())
59
 
        transfer->resume();
60
 
}
61
 
 
62
 
void
63
 
LiveActions::clear_all()
64
 
{
65
 
    for (const auto& transfer : m_transfers->get())
66
 
        transfer->clear();
67
 
}
68
 
 
69
 
void
70
 
LiveActions::activate(const Transfer::Id& id)
71
 
{
72
 
    auto transfer = find_transfer_by_id(id);
73
 
    g_return_if_fail(transfer);
74
 
 
75
 
    switch(transfer->state().get())
76
 
    {
77
 
        case Transfer::STARTING:
78
 
        case Transfer::RUNNING:
79
 
            transfer->pause();
80
 
            break;
81
 
 
82
 
        case Transfer::CANCELING:
83
 
            transfer->clear();
84
 
            break;
85
 
 
86
 
        case Transfer::PAUSED:
87
 
        case Transfer::FAILED:
88
 
            transfer->resume();
89
 
            break;
90
 
 
91
 
        case Transfer::DONE:
92
 
            transfer->open();
93
 
            break;
94
 
    }
95
 
}
96
 
 
97
 
void
98
 
LiveActions::pause(const Transfer::Id& id)
99
 
{
100
 
    auto transfer = find_transfer_by_id(id);
101
 
    g_return_if_fail(transfer);
102
 
    transfer->pause();
103
 
}
104
 
 
105
 
void
106
 
LiveActions::cancel(const Transfer::Id& id)
107
 
{
108
 
    auto transfer = find_transfer_by_id(id);
109
 
    g_return_if_fail(transfer);
110
 
    transfer->cancel();
111
 
}
112
 
 
113
 
void
114
 
LiveActions::resume(const Transfer::Id& id)
115
 
{
116
 
    auto transfer = find_transfer_by_id(id);
117
 
    g_return_if_fail(transfer);
118
 
    transfer->resume();
119
 
}
120
 
 
121
 
/****
122
 
*****
123
 
****/
124
 
 
125
 
} // namespace transfer
126
 
} // namespace indicator
127
 
} // namespace unity
128