summaryrefslogtreecommitdiff
path: root/src/download_screen.h
blob: 10eb5fe18bd23e6a7274b37cdc97f928b3c3b47b (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
// download_screen.h  (this is -*-c++-*- )
//
//  Copyright 1999-2001, 2003-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.
//
//  This acts as a progress meter for a download.

#ifndef DOWNLOAD_SCREEN_H
#define DOWNLOAD_SCREEN_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <apt-pkg/acquire.h>
#ifdef HAVE_HASH_MAP
#include <hash_map>
#else
#ifdef HAVE_EXT_HASH_MAP
#include <ext/hash_map>
#else
// Fallback to the non-hashing map class
#include <map>
#define hash_map map
#endif
#endif

#include <cwidget/widgets/table.h>
#include <cwidget/widgets/tree.h>
#include <cwidget/widgets/subtree.h>

class download_item;

#if defined(HAVE_HASH_MAP) || defined(HAVE_EXT_HASH_MAP)
namespace HASH_NAMESPACE {
  template <>
  struct hash<void *>
  {
    size_t operator()(void * __x) const { return (size_t) __x; }
  };
}
#endif

class download_tree:public cwidget::widgets::subtree_generic
{
public:
  download_tree():cwidget::widgets::subtree_generic(true) {}

  void paint(cwidget::widgets::tree *win, int y, bool hierarchical, const cwidget::style &style)
  {cwidget::widgets::subtree_generic::paint(win, y, hierarchical, L"ERROR: SHOULD NOT APPEAR");}
  const wchar_t * tag() {return L"download tree";}
  const wchar_t * label() {return L"download tree";}
};

class download_screen:public cwidget::widgets::tree, public pkgAcquireStatus
{
  typedef HASH_NAMESPACE::hash_map<void *, download_item *> downloadmap;
  downloadmap active_items;
  // Makes it easy to find a currently downloading item when we get a hit
  // for it.

  cwidget::widgets::widget *prev;
  // The screen that was being displayed before we started running the
  // download.

  bool finished;
  // If this is true, the status bar will be displayed as usual (as opposed to
  // being a progress meter)

  bool cancelled;
  // True if the user cancelled the download.

  download_tree *contents;

  download_item *get_itm(pkgAcquire::ItemDesc &itmdesc)
  {
    downloadmap::iterator found=active_items.find(itmdesc.Owner);
    eassert(found!=active_items.end());

    return found->second;
  }

protected:
  bool handle_key(const cwidget::key &k);

public:
  download_screen():prev(NULL),finished(false),cancelled(false) {contents=new download_tree; set_root(contents);}

  bool MediaChange(string media, string drive);
  void IMSHit(pkgAcquire::ItemDesc &itmdesc);
  void Fetch(pkgAcquire::ItemDesc &itmdesc);
  void Done(pkgAcquire::ItemDesc &itmdesc);
  void Fail(pkgAcquire::ItemDesc &itmdesc);
  bool Pulse(pkgAcquire *Owner);
  void Start();
  void Stop();

  bool get_cursorvisible() {return false;}

  //void paint_status();

  virtual ~download_screen();
};

#endif