summaryrefslogtreecommitdiff
path: root/src/pkg_columnizer.h
blob: b676db108598e095fa062077cb8135e430ca9947 (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
// pkg_columnizer.h  -*-c++-*-
//
//  Copyright 1999-2002, 2004-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.
//

#ifndef PKG_COLUMNIZER_H
#define PKG_COLUMNIZER_H

#include "pkg_item.h"
#include <cwidget/config/column_definition.h>

/** \brief pkg_columnizer class and associated data
 *
 * 
 *  The rather hefty pkg_columnizer class and associated data (eg, info about
 *  column sizes) lives here.
 * 
 *  \file pkg_columnizer.h
 */

class pkg_item::pkg_columnizer : public cwidget::config::column_generator
{
  class pkg_genheaders;

  pkgCache::PkgIterator pkg;
  pkgCache::VerIterator visible_ver;

  static cwidget::config::column_definition_list *columns;

  int basex;

  // Set up the translated format widths.
  static void init_formatting();
protected:
  const pkgCache::PkgIterator &get_pkg() {return pkg;}
  const pkgCache::VerIterator &get_visible_ver() {return visible_ver;}
public:
  static cwidget::column_disposition setup_column(const pkgCache::PkgIterator &pkg,
						  const pkgCache::VerIterator &ver,
						  int basex,
						  int type);
  virtual cwidget::column_disposition setup_column(int type);

  static const cwidget::config::column_definition_list &get_columns()
  {
    setup_columns();
    return *columns;
  }

  enum types {name, installed_size, debsize, stateflag, actionflag,
	      description, currver, candver, longstate, longaction,
	      maintainer, priority, shortpriority, section, revdepcount,
	      autoset, tagged, archive, sizechange,

              progname, progver, brokencount, diskusage, downloadsize,
	      pin_priority, hostname, trust_state, numtypes};
  static cwidget::config::column_type_defaults defaults[numtypes];
  static const char *column_names[numtypes];

  static const char *default_pkgdisplay;
  // The default values for the package column formatting.

  static int parse_column_type(char id);

  static void setup_columns(bool force_update=false);
  // This reads and sets up the necessary information about how to format the
  // display of packages.
  static std::wstring format_column_names(unsigned int width);
  // Returns a string which can serve as a header for the column-name
  // information for a screen of the given width.

  int get_basex() {return basex;}

  pkg_columnizer(const pkgCache::PkgIterator &_pkg,
		 const pkgCache::VerIterator &_visible_ver,
		 const cwidget::config::column_definition_list &_columns,
		 int _basex)
    : column_generator(_columns),
      pkg(_pkg),
      visible_ver(_visible_ver),
      basex(_basex)
  {
  }

};

#endif