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
|
// download_item.cc
//
// Copyright 1999, 2004-2005 Daniel Burrows
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; see the file COPYING. If not, write to
// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
#include "aptitude.h"
#include "download_item.h"
#include <apt-pkg/acquire-worker.h>
#include <apt-pkg/strutl.h>
#include <vscreen/transcode.h>
#include <vscreen/vs_tree.h>
style download_item::get_normal_style()
{
switch(item.Owner->Status)
{
case pkgAcquire::Item::StatIdle:
return vs_treeitem::get_normal_style()+style_attrs_on(A_DIM);
case pkgAcquire::Item::StatFetching:
return vs_treeitem::get_normal_style();
case pkgAcquire::Item::StatDone:
if(!hit)
return vs_treeitem::get_normal_style()+get_style("Progress");
else
return vs_treeitem::get_normal_style()+get_style("DownloadHit");
case pkgAcquire::Item::StatError:
return vs_treeitem::get_normal_style()+get_style("Error");
case pkgAcquire::Item::StatAuthError:
return vs_treeitem::get_normal_style()+get_style("Error");
default:
eassert(0);
}
}
void download_item::paint(vs_tree *win, int y, bool hierarchical,
const style &st)
// A little confusing -- basically, there are two branches: either we display
// a progress bar, or we don't. If we don't, I can just display it as usual
// (note, though, that I don't yet indent it according to the depth..); if we
// do, a rather specialized set of code is called and then returns. (that's
// the confusing bit :) )
{
string output=((item.Owner->Status==pkgAcquire::Item::StatFetching)?item.ShortDesc:item.Description)+": ";
int width,height;
win->getmaxyx(height,width);
const style progress_style=st+get_style("DownloadProgress");
const style normal_style=st+get_normal_style();
int barsize=width;
switch(item.Owner->Status)
{
case pkgAcquire::Item::StatIdle:
output+=_(" [Working]");
break;
case pkgAcquire::Item::StatFetching:
if(worker==NULL)
output+=_(" [Working]");
else
{
eassert(worker->CurrentItem->Owner==item.Owner);
if(worker->TotalSize>0)
{
char intbuf[50]; // Waay more than enough.
barsize=(width*worker->CurrentSize)/worker->TotalSize;
win->apply_style(progress_style);
if(barsize>width)
barsize=width;
win->apply_style(get_normal_style());
sprintf(intbuf,
"%sB/%sB",
SizeToStr(worker->CurrentSize).c_str(),
SizeToStr(worker->TotalSize).c_str());
output+=string(" [ ")+intbuf+" ]";
}
else
output+=_(" [Working]");
}
break;
case pkgAcquire::Item::StatDone:
output+=hit?_("[Hit]"):_("[Downloaded]");
break;
case pkgAcquire::Item::StatError:
output+=item.Owner->ErrorText;
break;
case pkgAcquire::Item::StatAuthError:
output+=item.Owner->ErrorText;
break;
}
win->show_string_as_progbar(0, y, transcode(output),
progress_style, normal_style,
barsize, width);
}
|