libyui-ncurses-pkg
 
Loading...
Searching...
No Matches
NCPkgTable.h
1/*
2 Copyright (c) 2002-2011 Novell, Inc.
3 Copyright (c) 2020-2021 SUSE LLC
4
5 This library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) version 3.0 of the License. This library
9 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12 License for more details. You should have received a copy of the GNU
13 Lesser General Public License along with this library; if not, write
14 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
15 Floor, Boston, MA 02110-1301 USA
16
17
18 File: NCPkgTable.h
19 Author: Gabriele Strattner <gs@suse.de>
20
21*/
22
23
24#ifndef NCPkgTable_h
25#define NCPkgTable_h
26
27#include <iosfwd>
28#include <string>
29#include <map>
30#include <utility> // for STL std::pair
31
32#include <zypp/ui/Selectable.h>
33
34#include <yui/ncurses/NCPadWidget.h>
35#include <yui/ncurses/NCTablePad.h>
36#include <yui/ncurses/NCTable.h>
37#include <yui/ncurses/NCTableItem.h>
38
39#include "NCPkgStrings.h"
40#include "NCPkgStatusStrategy.h"
41
42
44
50class NCPkgTableTag : public YTableCell
51{
52private:
53
54 ZyppStatus status;
55 ZyppObj dataPointer;
56 // cannot get at it from dataPointer
57 ZyppSel selPointer;
58
59public:
60
61 NCPkgTableTag( ZyppObj pkgPtr,
62 ZyppSel selPtr,
63 ZyppStatus stat = S_NoInst );
64
65 ~NCPkgTableTag() {}
66
67 void setStatus( ZyppStatus stat ) { status = stat; }
68 ZyppStatus getStatus() const { return status; }
69 // returns the corresponding std::string value to given package status
70 std::string statusToString( ZyppStatus stat ) const;
71
72 ZyppObj getDataPointer() const { return dataPointer; }
73 ZyppSel getSelPointer() const { return selPointer; }
74};
75
76
77class NCPkgTableSort : public NCTableSortStrategyBase
78{
79public:
80
81 NCPkgTableSort( const std::vector<std::string> & head )
82 : _header( head )
83 {}
84
85 virtual void sort( YItemIterator itemsBegin,
86 YItemIterator itemsEnd ) override
87 {
88 if ( _header[ sortCol() ] == NCPkgStrings::PkgSize() )
89 {
90 std::sort( itemsBegin, itemsEnd, CompareSize() );
91 }
92 else if ( _header[ sortCol() ] == NCPkgStrings::PkgName() )
93 {
94 std::sort( itemsBegin, itemsEnd, CompareName( sortCol() ) );
95 }
96 else
97 {
98 std::sort( itemsBegin, itemsEnd, Compare( sortCol() ) );
99 }
100
101 if ( reverse() )
102 std::reverse( itemsBegin, itemsEnd );
103 }
104
105private:
106
107 std::vector<std::string> _header;
108
109
113 static std::wstring cellContent( YItem * item, int col )
114 {
115 std::wstring empty;
116
117 if ( ! item )
118 return empty;
119
120 YTableItem * tableItem = dynamic_cast<YTableItem *>( item );
121
122 if ( ! tableItem )
123 return empty;
124
125 YTableCell * tableCell = tableItem->cell( col );
126
127 if ( ! tableCell )
128 return empty;
129
130 return NCstring( tableCell->label() ).str();
131 }
132
133
134 class CompareSize
135 {
136 public:
137 CompareSize()
138 {}
139
140 bool operator() ( YItem * item1, YItem * item2 ) const
141 {
142 YTableItem * tableItem1 = dynamic_cast<YTableItem *>( item1 );
143 YTableItem * tableItem2 = dynamic_cast<YTableItem *>( item2 );
144
145 if ( ! tableItem1 ) return true;
146 if ( ! tableItem2 ) return true;
147
148 const NCPkgTableTag * tag1 = static_cast<const NCPkgTableTag *>( tableItem1->cell(0) );
149 const NCPkgTableTag * tag2 = static_cast<const NCPkgTableTag *>( tableItem2->cell(0) );
150
151 return tag1->getDataPointer()->installSize() <
152 tag2->getDataPointer()->installSize();
153 }
154 };
155
156
157 class CompareName
158 {
159 public:
160 CompareName( int uiCol )
161 : _uiCol( uiCol )
162 {}
163
164 bool operator() ( YItem * item1, YItem * item2 ) const
165 {
166 std::wstring w1 = cellContent( item1, _uiCol );
167 std::wstring w2 = cellContent( item2, _uiCol );
168
169 // It is safe to use collate unaware wscasecmp() here because package names
170 // are 7 bit ASCII only. Better yet, we don't even want this to be sorted
171 // by locale specific rules: "ch" for example would be sorted after "h" in
172 // Czech which in the context of package names (which are English) would be
173 // plain wrong.
174 int result = wcscasecmp( w1.data(), w2.data() );
175
176 return result < 0;
177 }
178
179 private:
180 const int _uiCol;
181 };
182
183
184 class Compare
185 {
186 public:
187 Compare( int uiCol )
188 : _uiCol( uiCol )
189 {}
190
191 bool operator() ( YItem * item1, YItem * item2 ) const
192 {
193 std::wstring w1 = cellContent( item1, _uiCol );
194 std::wstring w2 = cellContent( item2, _uiCol );
195
196 int result = wcscoll ( w1.data(), w2.data() );
197
198 return result < 0;
199 }
200
201 private:
202 const int _uiCol;
203 };
204};
205
206
214class NCPkgTable : public NCTable
215{
216public:
217
218 enum NCPkgTableType
219 {
220 T_Packages,
221 T_Availables,
222 T_Patches,
223 T_Update,
224 T_PatchPkgs,
225 T_Selections,
226 T_Languages,
227 T_MultiVersion,
228 T_Unknown
229 };
230
231 enum NCPkgTableListAction
232 {
233 A_Install,
234 A_Delete,
235 A_Keep,
236 A_UpdateNewer,
237 A_Update,
238 A_Unknown
239 };
240
241 enum NCPkgTableListType
242 {
243 L_Changes,
244 L_Installed,
245 L_Unknown
246 };
247
248 enum NCPkgTableInfoType
249 {
250 I_Descr,
251 I_Technical,
252 I_Versions,
253 I_Files,
254 I_Deps,
255 I_PatchDescr,
256 I_PatchPkgs
257 };
258
259private:
260
261 NCPkgTable & operator=( const NCPkgTable & );
262 NCPkgTable ( const NCPkgTable & );
263
264 NCPackageSelector * packager; // connection to the PackageSelector,
265
266 NCPkgStatusStrategy * statusStrategy; // particular methods to get the status
267
268 NCPkgTableType tableType; // the type (e.g. table of packages, patches)
269 bool haveInstalledVersion; // for T_Packages and T_Update
270
271 // returns the first column of line with 'index' (the tag)
272 NCPkgTableTag * getTag ( const int & index );
273
274 NCPkgTableInfoType visibleInfo;
275
276 std::vector<std::string> header; // the table header
277
278
279public:
280
284 NCPkgTable( YWidget * parent, YTableHeader * tableHeader );
285
286 virtual ~NCPkgTable();
287
288
297 virtual void addLine( ZyppStatus status,
298 const std::vector<std::string> & elements,
299 ZyppObj objPtr,
300 ZyppSel slbPtr );
301
305 void drawList() { sortItems( 1 ); return DrawPad(); }
306
310 virtual void itemsCleared();
311
318 NClabel getCellContents( int index, int colnum );
319
326 virtual NCursesEvent wHandleInput( wint_t key );
327
333 void setPackager( NCPackageSelector * pkg ) { packager = pkg; }
334
344 bool changeStatus( ZyppStatus newstat,
345 const ZyppSel & slbPtr,
346 ZyppObj objPtr,
347 bool singleChange );
348
349 bool changeObjStatus( int key );
350
351 bool changeListObjStatus( NCPkgTableListAction key );
352
353 bool cycleObjStatus();
354
359 bool updateTable();
360
366 ZyppStatus getStatus( int index );
367
368#ifdef FIXME
374 bool SourceInstall( bool install );
375#endif
376
385 bool setTableType( NCPkgTableType type, NCPkgStatusStrategy * strategy )
386 {
387 if ( !strategy )
388 return false;
389
390 delete statusStrategy;
391 statusStrategy = strategy;
392 tableType = type;
393
394 return true;
395 }
396
397 NCPkgTableType getTableType() { return tableType; }
398
404 ZyppObj getDataPointer( int index );
405
411 ZyppSel getSelPointer( int index );
412
417 unsigned int getNumLines() { return myPad()->Lines(); }
418
423 void fillHeader();
424
431 bool createListEntry ( ZyppPkg pkgPtr, ZyppSel slbPtr );
432
438 bool createPatchEntry ( ZyppPatch pkgPtr, ZyppSel slbPtr );
439
445 bool createInfoEntry ( std::string text );
446
451 bool showInformation();
452
457 bool confirmRetracted( ZyppObj pkg, ZyppSel sel );
458
459 void setVisibleInfo( NCPkgTableInfoType info) { visibleInfo = info; }
460
461 NCPkgTableInfoType VisibleInfo() { return visibleInfo; }
462
463 bool fillAvailableList ( ZyppSel slb );
464 bool fillSummaryList ( NCPkgTableListType type );
465
466 void updateInfo( ZyppObj pkgPtr, ZyppSel slbPtr, NCPkgTableInfoType mode );
467
468};
469
471
472#endif // NCPkgTable_h
Definition NCPackageSelector.h:105
Definition NCPkgStatusStrategy.h:35
Definition NCPkgTable.h:51
bool showInformation()
Definition NCPkgTable.cc:710
void drawList()
Definition NCPkgTable.h:305
ZyppStatus getStatus(int index)
Definition NCPkgTable.cc:807
ZyppObj getDataPointer(int index)
Definition NCPkgTable.cc:817
unsigned int getNumLines()
Definition NCPkgTable.h:417
bool confirmRetracted(ZyppObj pkg, ZyppSel sel)
Definition NCPkgTable.cc:1177
void setPackager(NCPackageSelector *pkg)
Definition NCPkgTable.h:333
bool createInfoEntry(std::string text)
Definition NCPkgTable.cc:660
bool setTableType(NCPkgTableType type, NCPkgStatusStrategy *strategy)
Definition NCPkgTable.h:385
bool changeStatus(ZyppStatus newstat, const ZyppSel &slbPtr, ZyppObj objPtr, bool singleChange)
Definition NCPkgTable.cc:153
bool createPatchEntry(ZyppPatch pkgPtr, ZyppSel slbPtr)
Definition NCPkgTable.cc:675
virtual void addLine(ZyppStatus status, const std::vector< std::string > &elements, ZyppObj objPtr, ZyppSel slbPtr)
Definition NCPkgTable.cc:126
virtual NCursesEvent wHandleInput(wint_t key)
Definition NCPkgTable.cc:748
NClabel getCellContents(int index, int colnum)
bool createListEntry(ZyppPkg pkgPtr, ZyppSel slbPtr)
Definition NCPkgTable.cc:495
virtual void itemsCleared()
Definition NCPkgTable.cc:144
ZyppSel getSelPointer(int index)
Definition NCPkgTable.cc:827
bool updateTable()
Definition NCPkgTable.cc:315
void fillHeader()
Definition NCPkgTable.cc:388