blob: cfda6fe73594af02e1e17eeb9d328fdabed3c020 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
#include "download.h"
#include <string>
#include "config.h"
#include "pbcontroller.h"
namespace podboat {
/*
* the Download class represents a single download entry in podboat.
* It manages the filename, the URL, the current state, the progress, etc.
*/
Download::Download(PbController* c)
: download_status(DlStatus::QUEUED)
, cursize(0.0)
, totalsize(0.0)
, curkbps(0.0)
, offs(0)
, ctrl(c)
{
}
Download::~Download() {}
const std::string Download::filename() const
{
return fn;
}
const std::string Download::basename() const
{
std::string::size_type start = fn.rfind('/');
if (start != std::string::npos) {
return fn.substr(start+1);
}
return fn;
}
const std::string Download::url() const
{
return url_;
}
void Download::set_filename(const std::string& str)
{
fn = str;
}
double Download::percents_finished() const
{
if (totalsize < 1) {
return 0.0;
} else {
return (100 * (offs + cursize)) / (offs + totalsize);
}
}
const std::string Download::status_text() const
{
switch (download_status) {
case DlStatus::QUEUED:
return _s("queued");
case DlStatus::DOWNLOADING:
return _s("downloading");
case DlStatus::CANCELLED:
return _s("cancelled");
case DlStatus::DELETED:
return _s("deleted");
case DlStatus::FINISHED:
return _s("finished");
case DlStatus::FAILED:
return _s("failed");
case DlStatus::ALREADY_DOWNLOADED:
return _s("incomplete");
case DlStatus::READY:
return _s("ready");
case DlStatus::PLAYED:
return _s("played");
default:
return _s("unknown (bug).");
}
}
void Download::set_url(const std::string& u)
{
url_ = u;
}
void Download::set_progress(double downloaded, double total)
{
if (downloaded > cursize)
ctrl->set_view_update_necessary(true);
cursize = downloaded;
totalsize = total;
}
void Download::set_status(DlStatus dls)
{
if (download_status != dls) {
ctrl->set_view_update_necessary(true);
}
download_status = dls;
}
void Download::set_kbps(double k)
{
curkbps = k;
}
double Download::kbps() const
{
return curkbps;
}
void Download::set_offset(unsigned long offset)
{
offs = offset;
}
} // namespace podboat
|