summaryrefslogtreecommitdiff
path: root/src/load_pkgview.cc
blob: 08a65255f9dad55d8f42f1fccc84a907537e9ac6 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// load_pkgview.cc

#include "load_pkgview.h"

#include "aptitude.h"

#include "pkg_item.h"
#include "pkg_columnizer.h"
#include "ui.h"

#include <generic/apt/config_signal.h>
#include <generic/apt/apt.h>

#include <cwidget/generic/util/transcode.h>
#include <cwidget/widgets/table.h>

#include <apt-pkg/error.h>

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

std::list<package_view_item> *load_pkgview(std::string cfggroup)
{
  std::list<package_view_item> *rval=new std::list<package_view_item>;

  for(const Configuration::Item *Curr=aptcfg->Tree(cfggroup.c_str())->Child;
      Curr; Curr=Curr->Next)
    {
      package_view_item tmp;
      Configuration subtree(Curr);

      tmp.widget=NULL;

      tmp.name=Curr->Tag;

      if(!strcasecmp(Curr->Value.c_str(), "mainwidget"))
	{
	  // FIXME: delete the widget here?
	  tmp.type=PACKAGE_VIEW_MAINWIDGET;
	  tmp.columns=NULL;
	}
      else if(!strcasecmp(Curr->Value.c_str(), "description"))
	{
	  tmp.type=PACKAGE_VIEW_DESCRIPTION;
	  tmp.columns=NULL;
	  if(subtree.Exists("PopUpDownKey"))
	    tmp.popupdownkey=subtree.Find("PopUpDownKey");

	  if(subtree.Exists("PopUpdownLinked"))
	    tmp.popupdownlinked=subtree.Find("PopUpdownLinked");
	}
      else if(!strcasecmp(Curr->Value.c_str(), "static"))
	{
	  // FIXME: deleting rval will leak column definitions.
	  tmp.type=PACKAGE_VIEW_STATIC;

	  // Use columnscfg as a reference to a config item if it exists;
	  // otherwise, use columns as a configuration string.
	  if(!subtree.Exists("Columns") && !subtree.Exists("ColumnsCfg"))
	    {
	      _error->Error(_("Couldn't parse layout: No column format specified for static item"));
	      delete rval;
	      return NULL;
	    }

	  // The actual column format.
	  std::string colinf;

	  if(subtree.Exists("ColumnsCfg"))
	    {
	      tmp.columns_cfg_default="";
	      tmp.columns_cfg=subtree.Find("ColumnsCfg");

	      if(tmp.columns_cfg=="HEADER")
		{
		  tmp.columns_cfg=PACKAGE "::UI::Package-Header-Format";
		  tmp.columns_cfg_default=default_pkgheaderdisplay;
		}
	      else if(tmp.columns_cfg=="STATUS")
		{
		  tmp.columns_cfg=PACKAGE "::UI::Package-Status-Format";
		  tmp.columns_cfg_default=default_pkgstatusdisplay;
		}

	      colinf=aptcfg->Find(tmp.columns_cfg,
				  tmp.columns_cfg_default.c_str());
	    }
	  else
	    colinf=subtree.Find("Columns");

	  std::wstring wcolinf;
	  if(!cw::util::transcode(colinf.c_str(), wcolinf))
	    {
	      _error->Error(_("Couldn't parse layout: encoding error in column descriptor"));
	      delete rval;
	      return NULL;
	    }
	  tmp.columns=parse_columns(wcolinf,
				    pkg_item::pkg_columnizer::parse_column_type,
				    pkg_item::pkg_columnizer::defaults);
	  if(!tmp.columns)
	    {
	      delete rval;
	      return NULL;
	    }

	  if(subtree.Exists("PopUpdownKey"))
	    tmp.popupdownkey=subtree.Find("PopUpDownKey");

	  if(subtree.Exists("PopUpdownLinked"))
	    tmp.popupdownlinked=subtree.Find("PopUpdownLinked");
	}
      else
	{
	  _error->Error(_("Couldn't parse layout: unknown view item type \"%s\""), Curr->Value.c_str());
	  delete rval;
	  return NULL;
	}

      if(!subtree.Exists("Row"))
	{
	  _error->Error(_("Couldn't parse layout: no row number specified"));
	  delete rval;
	  return NULL;
	}
      tmp.row=subtree.FindI("Row");

      if(!subtree.Exists("Column"))
	{
	  _error->Error(_("Couldn't parse layout: no row number specified"));
	  delete rval;
	  return NULL;
	}
      tmp.col=subtree.FindI("Column");

      if(!subtree.Exists("Width"))
	{
	  _error->Error(_("Couldn't parse layout: no width specified"));
	  delete rval;
	  return NULL;
	}
      tmp.w=subtree.FindI("Width");

      if(!subtree.Exists("Height"))
	{
	  _error->Error(_("Couldn't parse layout: no height specified"));
	  delete rval;
	  return NULL;
	}
      tmp.h=subtree.FindI("Height");

      tmp.xopts=0;
      tmp.yopts=0;

      if(subtree.FindB("ColExpand", false))
	tmp.xopts |= cw::table::EXPAND;
      if(subtree.FindB("RowExpand", false))
	tmp.yopts |= cw::table::EXPAND;

      if(subtree.FindB("ColShrink", false))
	tmp.xopts |= cw::table::SHRINK;
      if(subtree.FindB("RowShrink", false))
	tmp.yopts |= cw::table::SHRINK;

      if(subtree.Exists("ColAlign"))
	{
	  std::string s=subtree.Find("ColAlign");

	  if(!strcasecmp(s.c_str(), "left"))
	    tmp.xopts|=cw::table::ALIGN_LEFT;
	  else if(!strcasecmp(s.c_str(), "right"))
	    tmp.xopts|=cw::table::ALIGN_RIGHT;
	  else if(!strcasecmp(s.c_str(), "center"))
	    tmp.xopts|=cw::table::ALIGN_CENTER;
	  else
	    {
	      _error->Error(_("Unknown alignment type '%s'"), s.c_str());
	      delete rval;
	      return NULL;
	    }
	}

      if(subtree.Exists("RowAlign"))
	{
	  std::string s=subtree.Find("RowAlign");

	  if(!strcasecmp(s.c_str(), "top"))
	    tmp.yopts|=cw::table::ALIGN_LEFT;
	  else if(!strcasecmp(s.c_str(), "bottom"))
	    tmp.yopts|=cw::table::ALIGN_RIGHT;
	  else if(!strcasecmp(s.c_str(), "center"))
	    tmp.yopts|=cw::table::ALIGN_CENTER;
	  else
	    {
	      _error->Error(_("Unknown alignment type '%s'"), s.c_str());
	      delete rval;
	      return NULL;
	    }
	}

      if(subtree.Exists("Style"))
	{
	  tmp.st=cw::get_style(subtree.Find("Style"));
	}

      tmp.visible=subtree.FindB("Visible", true);

      rval->push_back(tmp);
    }

  return rval;
}