libyui-ncurses-pkg  2.48.2
 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  };
214 
215 private:
216 
217  NCPkgTable & operator=( const NCPkgTable & );
218  NCPkgTable ( const NCPkgTable & );
219 
220  NCPackageSelector * packager; // connection to the PackageSelector,
221 
222  NCPkgStatusStrategy * statusStrategy; // particular methods to get the status
223 
224  NCPkgTableType tableType; // the type (e.g. table of packages, patches)
225  bool haveInstalledVersion; // for T_Packages and T_Update
226 
227  // returns the first column of line with 'index' (the tag)
228  NCPkgTableTag * getTag ( const int & index );
229 
230  NCPkgTableInfoType visibleInfo;
231 
232  std::vector<std::string> header; // the table header
233 
234 protected:
235 
236 
237 public:
238 
239  /**
240  * Constructor
241  */
242  NCPkgTable( YWidget * parent, YTableHeader * tableHeader );
243 
244  virtual ~NCPkgTable();
245 
246 
247  /**
248  * This method is called to add a line to the package list.
249  * @param status The package status (first column of the table)
250  * @param elements A std::vector<std::string> containing the package data
251  * @param objPtr The pointer to the packagemanager object
252  * @param objPtr The pointer to the selectable object
253  * @return void
254  */
255  virtual void addLine( ZyppStatus status,
256  const std::vector<std::string> & elements,
257  ZyppObj objPtr,
258  ZyppSel slbPtr );
259 
260  /**
261  * Draws the package list (has to be called after the loop with addLine() calls)
262  */
263  void drawList( ) { myPad()->setOrder(1); return DrawPad(); }
264 
265  /**
266  * Clears the package list
267  */
268  virtual void itemsCleared();
269 
270  /**
271  * Changes the contents of a certain cell in table
272  * @param index The table line
273  * @param column The column
274  * @param newtext The new text
275  * @eturn void
276  */
277  virtual void cellChanged( int index, int colnum, const std::string & newtext );
278 
279  /**
280  * Returns the contents of a certain cell in table
281  * @param index The table line
282  * @param column The column
283  * @eturn NClabel
284  */
285  NClabel getCellContents( int index, int colnum );
286 
287  /**
288  * Handles the events concerning the package table (e.g. scroll the list,
289  * change the package status, ...)
290  * @param key The key which is pressed
291  * @return NCursesEvent
292  */
293  virtual NCursesEvent wHandleInput( wint_t key );
294 
295  /**
296  * Sets the member variable PackageSelector *packager
297  * @param pkg The PackageSelector pointer
298  * @return void
299  */
300  void setPackager( NCPackageSelector * pkg ) { packager = pkg; }
301 
302  /**
303  * Informs the package manager about the status change of
304  * the currently selected package and updates the states
305  * of all packages in the list
306  * @param newstat The new status
307  * @param slbPtr The pointer to the object to change
308  * @param objPtr is candidatePtr or what the user selected instead of it.
309  * @return bool
310  */
311  bool changeStatus( ZyppStatus newstat,
312  const ZyppSel & slbPtr,
313  ZyppObj objPtr,
314  bool singleChange );
315 
316  bool changeObjStatus( int key );
317 
318  bool changeListObjStatus( NCPkgTableListAction key );
319 
320  bool toggleObjStatus( );
321 
322  /**
323  * Set the status information if status has changed
324  * @return bool
325  */
326  bool updateTable();
327 
328  /**
329  * Gets the currently displayed package status.
330  * @param index The index in package table (the line)
331  * @return ZyppStatus
332  */
333  ZyppStatus getStatus( int index );
334 
335 #ifdef FIXME
336  /**
337  * Toggles the installation of the source package.
338  * @param install
339  * @return bool
340  */
341  bool SourceInstall( bool install );
342 #endif
343 
344  /**
345  * Sets the type of the table and the status strategy (which means call particular methods
346  * to set/get the status for different zypp::ResObjects (zypp::Patch, zypp::Package or available zypp::Package)
347  * @param type The type (see enum NCPkgTableType)
348  * @param strategy The certain strategy (available strategies see NCPkgStatusStrategy.h).
349  * Has to be allocated with new - is deleted by NCPkgTable.
350  * @return bool
351  */
352  bool setTableType( NCPkgTableType type, NCPkgStatusStrategy * strategy ) {
353  if ( !strategy )
354  return false;
355 
356  delete statusStrategy;
357  statusStrategy = strategy;
358  tableType = type;
359 
360  return true;
361  }
362 
363  NCPkgTableType getTableType() { return tableType; }
364 
365  /**
366  * Gets the data pointer of a certain package.
367  * @param index The index in package table (the line)
368  * @return ZyppObj
369  */
370  ZyppObj getDataPointer( int index );
371 
372  /**
373  * Gets the selectable pointer of a certain package.
374  * @param index The index in package table (the line)
375  * @return ZyppSel
376  */
377  ZyppSel getSelPointer( int index );
378 
379  /**
380  * Returns the number of lines in the table (the table size)
381  * @return unsigned int
382  */
383  unsigned int getNumLines( ) { return myPad()->Lines(); }
384 
385  /**
386  * Fills the header of the table
387  * @return void
388  */
389  void fillHeader( );
390 
391  /**
392  * Creates a line in the package table.
393  * @param pkgPtr The package pointer
394  * @param slbPtr The selectable pointer
395  * @return bool
396  */
397  bool createListEntry ( ZyppPkg pkgPtr, ZyppSel slbPtr );
398 
399  /**
400  * Creates a line in the YOU patch table.
401  * @param pkgPtr The YOU patch pointer
402  * @return bool
403  */
404  bool createPatchEntry ( ZyppPatch pkgPtr, ZyppSel slbPtr );
405 
406  /**
407  * Creates a line in the table shwing an info text.
408  * @param text The information
409  * @return bool
410  */
411  bool createInfoEntry ( std::string text );
412 
413  /**
414  * Show the corresponding information (e.g. the package description).
415  * @return bool
416  */
417  bool showInformation ( );
418 
419  void setVisibleInfo( NCPkgTableInfoType info) { visibleInfo = info; }
420 
421  NCPkgTableInfoType VisibleInfo() { return visibleInfo ; }
422 
423  bool fillAvailableList ( ZyppSel slb );
424  bool fillSummaryList ( NCPkgTableListType type );
425 
426  void updateInfo( ZyppObj pkgPtr, ZyppSel slbPtr, NCPkgTableInfoType mode );
427 
428 };
429 
430 ///////////////////////////////////////////////////////////////////
431 
432 #endif // NCPkgTable_h
virtual NCursesEvent wHandleInput(wint_t key)
Handles the events concerning the package table (e.g.
Definition: NCPkgTable.cc:800
bool showInformation()
Show the corresponding information (e.g.
Definition: NCPkgTable.cc:762
bool createPatchEntry(ZyppPatch pkgPtr, ZyppSel slbPtr)
Creates a line in the YOU patch table.
Definition: NCPkgTable.cc:723
virtual void cellChanged(int index, int colnum, const std::string &newtext)
Changes the contents of a certain cell in table.
Definition: NCPkgTable.cc:198
The package table class.
Definition: NCPkgTable.h:175
virtual void addLine(ZyppStatus status, const std::vector< std::string > &elements, ZyppObj objPtr, ZyppSel slbPtr)
This method is called to add a line to the package list.
Definition: NCPkgTable.cc:156
ZyppObj getDataPointer(int index)
Gets the data pointer of a certain package.
Definition: NCPkgTable.cc:874
void fillHeader()
Fills the header of the table.
Definition: NCPkgTable.cc:448
bool createListEntry(ZyppPkg pkgPtr, ZyppSel slbPtr)
Creates a line in the package table.
Definition: NCPkgTable.cc:550
This class is used for the first column of the package table which contains the status information of...
Definition: NCPkgTable.h:68
bool createInfoEntry(std::string text)
Creates a line in the table shwing an info text.
Definition: NCPkgTable.cc:704
ZyppStatus getStatus(int index)
Gets the currently displayed package status.
Definition: NCPkgTable.cc:864
ZyppSel getSelPointer(int index)
Gets the selectable pointer of a certain package.
Definition: NCPkgTable.cc:884
bool updateTable()
Set the status information if status has changed.
Definition: NCPkgTable.cc:369
bool setTableType(NCPkgTableType type, NCPkgStatusStrategy *strategy)
Sets the type of the table and the status strategy (which means call particular methods to set/get th...
Definition: NCPkgTable.h:352
unsigned int getNumLines()
Returns the number of lines in the table (the table size)
Definition: NCPkgTable.h:383
virtual void itemsCleared()
Clears the package list.
Definition: NCPkgTable.cc:184
NClabel getCellContents(int index, int colnum)
Returns the contents of a certain cell in table.
void drawList()
Draws the package list (has to be called after the loop with addLine() calls)
Definition: NCPkgTable.h:263
void setPackager(NCPackageSelector *pkg)
Sets the member variable PackageSelector *packager.
Definition: NCPkgTable.h:300
bool changeStatus(ZyppStatus newstat, const ZyppSel &slbPtr, ZyppObj objPtr, bool singleChange)
Informs the package manager about the status change of the currently selected package and updates the...
Definition: NCPkgTable.cc:212