summaryrefslogtreecommitdiff
path: root/src/ui_download_manager.cc
blob: 1db73c410a34b5403516a7ec20206a78b0001124 (plain)
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
// ui_download_manager.cc
//
//   Copyright (C) 2005, 2007 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 "ui_download_manager.h"

#include "aptitude.h"
#include "ui.h"
#include "progress.h"

#include <generic/apt/apt.h>
#include <generic/apt/download_manager.h>
#include <generic/apt/download_signal_log.h>

#include <sigc++/functors/mem_fun.h>

#include <cwidget/widgets/widget.h> // For cw::widget_ref

namespace cw = cwidget;
namespace cwidget
{
  using namespace widgets;
}

ui_download_manager::ui_download_manager(download_manager *_manager,
					 bool force_noninvasive,
					 bool list_update,
					 bool hide_preview,
					 const std::string &title,
					 const std::string &longtitle,
					 const std::string &tablabel)
  : manager(_manager),
    t(NULL)
{
  std::pair<download_signal_log *, cw::widget_ref> progpair =
    gen_download_progress(force_noninvasive, list_update,
			  title, longtitle, tablabel,
			  cw::util::arg(sigc::mem_fun(abort_state,
						      &aborter::abort)));

  log             = progpair.first;
  download_status = progpair.second;
  st              = new background_status(log);

  ui_start_download(hide_preview);
}

ui_download_manager::~ui_download_manager()
{
  log->Complete();

  delete manager;

  ui_stop_download();

  abort_state.abort();

  delete t;
  delete log;
  delete st;
}

void ui_download_manager::done(download_thread *, pkgAcquire::RunResult res)
{
  progress_ref p = gen_progress_bar();

  download_manager::result run_res = download_manager::failure;

  if(!abort_state.get_aborted())
    run_res = manager->finish(res, *p.unsafe_get_ref());

  apt_load_cache(p.unsafe_get_ref(), true);

  p->destroy();

  delete t;
  t = NULL;

  if(run_res == download_manager::do_again && !abort_state.get_aborted())
    (new download_thread(manager,
			 sigc::mem_fun(this,
				       &ui_download_manager::done)))->start();
  else
    {
      download_complete(run_res == download_manager::success);
      delete this;
    }
}

void ui_download_manager::start()
{
  progress_ref p = gen_progress_bar();

  bool ok = manager->prepare(*p.unsafe_get_ref(), *st, log);

  p->destroy();

  if(ok)
    (new download_thread(manager,
			 sigc::mem_fun(this,
				       &ui_download_manager::done)))->start();
  else
    delete this;
}