libyui-ncurses-pkg  2.43.4.1
 All Classes Functions
NCPkgTable.h
1 /****************************************************************************
2 |
3 | Copyright (c) [2002-2011] Novell, Inc.
4 | All Rights Reserved.
5 |
6 | This program is free software; you can redistribute it and/or
7 | modify it under the terms of version 2 of the GNU General Public License as
8 | published by the Free Software Foundation.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program; if not, contact Novell, Inc.
17 |
18 | To contact Novell about this file by physical or electronic mail,
19 | you may find current contact information at www.novell.com
20 |
21 |***************************************************************************/
22 
23 
24 /*---------------------------------------------------------------------\
25 | |
26 | __ __ ____ _____ ____ |
27 | \ \ / /_ _/ ___|_ _|___ \ |
28 | \ V / _` \___ \ | | __) | |
29 | | | (_| |___) || | / __/ |
30 | |_|\__,_|____/ |_| |_____| |
31 | |
32 | core system |
33 | (C) SuSE GmbH |
34 \----------------------------------------------------------------------/
35 
36  File: NCPkgTable.h
37 
38  Author: Gabriele Strattner <gs@suse.de>
39 
40 /-*/
41 #ifndef NCPkgTable_h
42 #define NCPkgTable_h
43 
44 #include <iosfwd>
45 
46 #include "NCPadWidget.h"
47 #include "NCTablePad.h"
48 #include "NCTable.h"
49 #include "NCPkgStrings.h"
50 
51 #include <map>
52 #include <string>
53 #include <utility> // for STL std::pair
54 
55 #include <zypp/ui/Selectable.h>
56 
57 #include "NCPkgStatusStrategy.h"
58 
59 
60 class NCPackageSelector;
61 
62 /**
63  * This class is used for the first column of the package table
64  * which contains the status information of the package (installed,
65  * not installed, to be deleted and so on).
66  *
67  **/
68 class NCPkgTableTag : public YTableCell {
69 
70  private:
71 
72  ZyppStatus status;
73  ZyppObj dataPointer;
74  // cannot get at it from dataPointer
75  ZyppSel selPointer;
76 
77  public:
78 
79  NCPkgTableTag( ZyppObj pkgPtr,
80  ZyppSel selPtr,
81  ZyppStatus stat = S_NoInst );
82 
83  ~NCPkgTableTag() {}
84 
85  void setStatus( ZyppStatus stat ) { status = stat; }
86  ZyppStatus getStatus() const { return status; }
87  // returns the corresponding std::string value to given package status
88  std::string statusToString( ZyppStatus stat ) const;
89 
90  ZyppObj getDataPointer() const { return dataPointer; }
91  ZyppSel getSelPointer() const { return selPointer; }
92 };
93 
94 
95 class NCPkgTableSort : public NCTableSortStrategyBase {
96 
97 public:
98 
99  NCPkgTableSort( const std::vector<std::string> & head )
100  : _header ( head )
101  { }
102 
103  virtual void sort (
104  std::vector<NCTableLine *>::iterator itemsBegin,
105  std::vector<NCTableLine *>::iterator itemsEnd,
106  int uiColumn
107  )
108  {
109  if ( _header[ uiColumn ] == NCPkgStrings::PkgSize() )
110  {
111  std::sort( itemsBegin, itemsEnd, CompareSize() );
112  }
113  else
114  {
115  std::sort( itemsBegin, itemsEnd, Compare( uiColumn ) );
116  }
117  }
118 
119 private:
120  std::vector<std::string> _header;
121 
122  class CompareSize
123  {
124  public:
125  CompareSize ( )
126  {}
127 
128  bool operator() ( NCTableLine * first,
129  NCTableLine * second
130  ) const
131  {
132  YTableItem *firstItem = dynamic_cast<YTableItem*> (first->origItem() );
133  YTableItem *secondItem = dynamic_cast<YTableItem*> (second->origItem() );
134  NCPkgTableTag *firstTag = static_cast<NCPkgTableTag *>( firstItem->cell(0) );
135  NCPkgTableTag *secondTag = static_cast<NCPkgTableTag *>( secondItem->cell(0) );
136 
137  return firstTag->getDataPointer()->installSize() <
138  secondTag->getDataPointer()->installSize();
139  }
140 
141  };
142 
143  class Compare
144  {
145  public:
146  Compare ( int uiCol)
147  : _uiCol (uiCol)
148  {}
149 
150  bool operator() ( NCTableLine * first,
151  NCTableLine * second
152  ) const
153  {
154  std::wstring w1 = first->GetCol( _uiCol )->Label().getText().begin()->str();
155  std::wstring w2 = second->GetCol( _uiCol )->Label().getText().begin()->str();
156  int result = wcscoll ( w1.data(), w2.data() );
157 
158  if ( result < 0 )
159  return true;
160  else
161  return false;
162  }
163  private:
164  int _uiCol;
165  };
166 };
167 
168 /**
169  * The package table class. Provides methods to fill the table,
170  * set the status info and so on.
171  * Has a connection to the PackageSelector which is used to do
172  * changes which affect other widgets.
173  *
174  **/
175 class NCPkgTable : public NCTable {
176 
177 public:
178  enum NCPkgTableType {
179  T_Packages,
180  T_Availables,
181  T_Patches,
182  T_Update,
183  T_PatchPkgs,
184  T_Selections,
185  T_Languages,
186  T_MultiVersion,
187  T_Unknown
188  };
189 
190  enum NCPkgTableListAction {
191  A_Install,
192  A_Delete,
193  A_Keep,
194  A_UpdateNewer,
195  A_Update,
196  A_Unknown
197  };
198 
199  enum NCPkgTableListType {
200  L_Changes,
201  L_Installed,
202  L_Unknown
203  };
204 
205  enum NCPkgTableInfoType {
206  I_Descr,
207  I_Technical,
208  I_Versions,
209  I_Files,
210  I_Deps,
211  I_PatchDescr,
212  I_PatchPkgs,
213  I_PatchPkgsVersions
214  };
215 
216 private:
217 
218  NCPkgTable & operator=( const NCPkgTable & );
219  NCPkgTable ( const NCPkgTable & );
220 
221  NCPackageSelector * packager; // connection to the PackageSelector,
222 
223  NCPkgStatusStrategy * statusStrategy; // particular methods to get the status
224 
225  NCPkgTableType tableType; // the type (e.g. table of packages, patches)
226  bool haveInstalledVersion; // for T_Packages and T_Update
227 
228  // returns the first column of line with 'index' (the tag)
229  NCPkgTableTag * getTag ( const int & index );
230 
231  NCPkgTableInfoType visibleInfo;
232 
233  std::vector<std::string> header; // the table header
234 
235 protected:
236 
237 
238 public:
239 
240  /**
241  * Constructor
242  */
243  NCPkgTable( YWidget * parent, YTableHeader * tableHeader );
244 
245  virtual ~NCPkgTable();
246 
247 
248  /**
249  * This method is called to add a line to the package list.
250  * @param status The package status (first column of the table)
251  * @param elements A std::vector<std::string> containing the package data
252  * @param objPtr The pointer to the packagemanager object
253  * @param objPtr The pointer to the selectable object
254  * @return void
255  */
256  virtual void addLine( ZyppStatus status,
257  const std::vector<std::string> & elements,
258  ZyppObj objPtr,
259  ZyppSel slbPtr );
260 
261  /**
262  * Draws the package list (has to be called after the loop with addLine() calls)
263  */
264  void drawList( ) { myPad()->setOrder(1); return DrawPad(); }
265 
266  /**
267  * Clears the package list
268  */
269  virtual void itemsCleared();
270 
271  /**
272  * Changes the contents of a certain cell in table
273  * @param index The table line
274  * @param column The column
275  * @param newtext The new text
276  * @eturn void
277  */
278  virtual void cellChanged( int index, int colnum, const std::string & newtext );
279 
280  /**
281  * Returns the contents of a certain cell in table
282  * @param index The table line
283  * @param column The column
284  * @eturn NClabel
285  */
286  NClabel getCellContents( int index, int colnum );
287 
288  /**
289  * Handles the events concerning the package table (e.g. scroll the list,
290  * change the package status, ...)
291  * @param key The key which is pressed
292  * @return NCursesEvent
293  */
294  virtual NCursesEvent wHandleInput( wint_t key );
295 
296  /**
297  * Sets the member variable PackageSelector *packager
298  * @param pkg The PackageSelector pointer
299  * @return void
300  */
301  void setPackager( NCPackageSelector * pkg ) { packager = pkg; }
302 
303  /**
304  * Informs the package manager about the status change of
305  * the currently selected package and updates the states
306  * of all packages in the list
307  * @param newstat The new status
308  * @param slbPtr The pointer to the object to change
309  * @param objPtr is candidatePtr or what the user selected instead of it.
310  * @return bool
311  */
312  bool changeStatus( ZyppStatus newstat,
313  const ZyppSel & slbPtr,
314  ZyppObj objPtr,
315  bool singleChange );
316 
317  bool changeObjStatus( int key );
318 
319  bool changeListObjStatus( NCPkgTableListAction key );
320 
321  bool toggleObjStatus( );
322 
323  /**
324  * Set the status information if status has changed
325  * @return bool
326  */
327  bool updateTable();
328 
329  /**
330  * Gets the currently displayed package status.
331  * @param index The index in package table (the line)
332  * @return ZyppStatus
333  */
334  ZyppStatus getStatus( int index );
335 
336 #ifdef FIXME
337  /**
338  * Toggles the installation of the source package.
339  * @param install
340  * @return bool
341  */
342  bool SourceInstall( bool install );
343 #endif
344 
345  /**
346  * Sets the type of the table and the status strategy (which means call particular methods
347  * to set/get the status for different zypp::ResObjects (zypp::Patch, zypp::Package or available zypp::Package)
348  * @param type The type (see enum NCPkgTableType)
349  * @param strategy The certain strategy (available strategies see NCPkgStatusStrategy.h).
350  * Has to be allocated with new - is deleted by NCPkgTable.
351  * @return bool
352  */
353  bool setTableType( NCPkgTableType type, NCPkgStatusStrategy * strategy ) {
354  if ( !strategy )
355  return false;
356 
357  delete statusStrategy;
358  statusStrategy = strategy;
359  tableType = type;
360 
361  return true;
362  }
363 
364  NCPkgTableType getTableType() { return tableType; }
365 
366  /**
367  * Gets the data pointer of a certain package.
368  * @param index The index in package table (the line)
369  * @return ZyppObj
370  */
371  ZyppObj getDataPointer( int index );
372 
373  /**
374  * Gets the selectable pointer of a certain package.
375  * @param index The index in package table (the line)
376  * @return ZyppSel
377  */
378  ZyppSel getSelPointer( int index );
379 
380  /**
381  * Returns the number of lines in the table (the table size)
382  * @return unsigned int
383  */
384  unsigned int getNumLines( ) { return myPad()->Lines(); }
385 
386  /**
387  * Fills the header of the table
388  * @return void
389  */
390  void fillHeader( );
391 
392  /**
393  * Creates a line in the package table.
394  * @param pkgPtr The package pointer
395  * @param slbPtr The selectable pointer
396  * @return bool
397  */
398  bool createListEntry ( ZyppPkg pkgPtr, ZyppSel slbPtr );
399 
400  /**
401  * Creates a line in the YOU patch table.
402  * @param pkgPtr The YOU patch pointer
403  * @return bool
404  */
405  bool createPatchEntry ( ZyppPatch pkgPtr, ZyppSel slbPtr );
406 
407  /**
408  * Creates a line in the table shwing an info text.
409  * @param text The information
410  * @return bool
411  */
412  bool createInfoEntry ( std::string text );
413 
414  /**
415  * Show the corresponding information (e.g. the package description).
416  * @return bool
417  */
418  bool showInformation ( );
419 
420  void setVisibleInfo( NCPkgTableInfoType info) { visibleInfo = info; }
421 
422  NCPkgTableInfoType VisibleInfo() { return visibleInfo ; }
423 
424  bool fillAvailableList ( ZyppSel slb );
425  bool fillSummaryList ( NCPkgTableListType type );
426 
427  void updateInfo( ZyppObj pkgPtr, ZyppSel slbPtr, NCPkgTableInfoType mode );
428 
429 };
430 
431 ///////////////////////////////////////////////////////////////////
432 
433 #endif // NCPkgTable_h