~charlesk/indicator-transfer/fix-flint-and-clang-warnings

« back to all changes in this revision

Viewing changes to src/transfer.cpp

  • Committer: CI bot
  • Author(s): Charles Kerr
  • Date: 2014-07-07 22:22:21 UTC
  • mfrom: (6.1.9 per-transfer-actions)
  • Revision ID: ps-jenkins@lists.canonical.com-20140707222221-5o6gsim4jnmfy6ry
Create per-transfer actions for simpler state lookup by renderers. Previously this was done as a single action that contained a map of unique transfer ids to states. 
Approved by: Ted Gould, Ted Gould

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/transfer.h>
 
21
 
 
22
#include <cstdio> // std::snprintf()
 
23
 
 
24
namespace unity {
 
25
namespace indicator {
 
26
namespace transfer {
 
27
 
 
28
/***
 
29
****
 
30
***/
 
31
 
 
32
std::string Transfer::next_unique_id()
 
33
{
 
34
  static unsigned int next = 1000;
 
35
  char buf[32];
 
36
  std::snprintf(buf, sizeof(buf), "%u", next);
 
37
  ++next;
 
38
  return buf;
 
39
}
 
40
 
 
41
bool Transfer::can_start() const
 
42
{
 
43
  return state==QUEUED;
 
44
}
 
45
 
 
46
bool Transfer::can_resume() const
 
47
{
 
48
  return state==PAUSED || state==CANCELED || state==ERROR;
 
49
}
 
50
 
 
51
bool Transfer::can_pause() const
 
52
{
 
53
  return state==RUNNING || state==HASHING || state==PROCESSING;
 
54
}
 
55
 
 
56
bool Transfer::can_cancel() const
 
57
{
 
58
  return state!=FINISHED;
 
59
}
 
60
 
 
61
bool Transfer::can_clear() const
 
62
{
 
63
  return state==FINISHED;
 
64
}
 
65
 
 
66
/***
 
67
****
 
68
***/
 
69
 
 
70
} // namespace transfer
 
71
} // namespace indicator
 
72
} // namespace unity