41 #define YUILogComponent "ncurses-pkg" 44 #include <boost/format.hpp> 46 #include "NCPkgFilterPattern.h" 49 #include "NCLayoutBox.h" 50 #include "NCSpacing.h" 51 #include "NCPkgStrings.h" 52 #include "NCPkgTable.h" 53 #include "NCPkgStatusStrategy.h" 54 #include <zypp/sat/LocaleSupport.h> 60 #define LOCALE Y2PM::getPreferredLocale() 73 bool operator() (std::pair<std::string, std::string> p1, std::pair<std::string, std::string> p2)
75 if( p1.second != p2.second )
76 return p1.second < p2.second;
78 return ( p1.first < p2.first );
89 NCPkgFilterPattern::NCPkgFilterPattern( YWidget *parent, YTableHeader *header,
NCPackageSelector * pkg )
93 createLayout( parent );
106 NCPkgFilterPattern::~NCPkgFilterPattern()
119 void NCPkgFilterPattern::createLayout( YWidget *parent )
122 setPackager( packager );
127 setTableType( NCPkgTable::T_Selections, strat );
140 int index = getCurrentItem();
141 ZyppObj objPtr = getDataPointer( index );
145 std::set<std::string> packages;
146 ZyppPattern patPtr = tryCastToZyppPattern (objPtr);
153 yuiMilestone() <<
"Show packages belonging to selected pattern: " << getCurrentLine() << endl;
154 NCPkgTable * packageList = packager->PackageList();
158 yuiError() <<
"Widget is not a valid NCPkgTable widget" << endl;
163 zypp::Pattern::Contents related ( patPtr->contents() );
164 for ( zypp::Pattern::Contents::Selectable_iterator it = related.selectableBegin();
165 it != related.selectableEnd();
168 ZyppPkg zyppPkg = tryCastToZyppPkg( (*it)->theObj() );
172 if ( (*it)->installedSize() > 0 )
179 packager->FilterDescription()->setText ( showDescription( objPtr ) );
181 std::ostringstream s;
183 s << boost::format( _(
"%d of %d package installed",
"%d of %d packages installed", total )) % installed % total;
185 packager->PatternLabel()->setLabel ( s.str() );
187 packageList->setCurrentItem( 0 );
202 std::string NCPkgFilterPattern::getCurrentLine( )
207 int index = getCurrentItem();
208 ZyppObj selPtr = getDataPointer(index);
210 return ( selPtr?selPtr->summary(LOCALE):
"" );
212 std::string NCPkgFilterPattern::showDescription( ZyppObj objPtr )
214 ZyppPattern patPtr = tryCastToZyppPattern (objPtr);
215 return patPtr->description();
228 NCursesEvent ret = NCursesEvent::none;
241 ret = NCursesEvent::handled;
250 showPatternPackages( );
258 bool orderPattern( ZyppSel slb1, ZyppSel slb2 )
260 ZyppPattern ptr1 = tryCastToZyppPattern (slb1->theObj());
261 ZyppPattern ptr2 = tryCastToZyppPattern (slb2->theObj());
262 if ( !ptr1 || !ptr2 )
266 if( ptr1->order() != ptr2->order() )
267 return ( ptr1->order() < ptr2->order() );
269 return ( ptr1->name() < ptr2->name() );
284 ZyppPoolIterator i, b, e;
285 std::map<std::string, std::list<ZyppSel> > patterns;
286 std::map<std::string, std::list<ZyppSel> >::iterator mapIt;
288 for ( i = zyppPatternsBegin () ; i != zyppPatternsEnd (); ++i )
290 ZyppObj resPtr = (*i)->theObj();
293 ZyppPattern patPtr = tryCastToZyppPattern (resPtr);
294 show = patPtr && patPtr->userVisible ();
298 std::string cat = patPtr->category();
305 std::map <std::string, std::list<ZyppSel> >::iterator item = patterns.find(cat);
306 if( item == patterns.end())
308 std::list <ZyppSel> slbList;
309 slbList.push_back( (*i) );
310 yuiMilestone() <<
"New category added: " << cat << endl;
311 patterns.insert( make_pair (cat,slbList) );
315 (*item).second.push_back( (*i));
318 yuiMilestone() << resPtr->kind () <<
": " << resPtr->name()
319 <<
", initial status: " << (*i)->status() <<
", order: " << patPtr->order() << endl;
323 std::set < std::pair <std::string, std::string>,
paircmp > pat_index;
324 std::set < std::pair <std::string, std::string>,
paircmp >::iterator indexIt;
327 for ( mapIt = patterns.begin(); mapIt != patterns.end(); ++mapIt )
329 std::string name = (*mapIt).first;
331 (*mapIt).second.sort( orderPattern );
332 std::list<ZyppSel>::iterator it = (*mapIt).second.begin();
334 ZyppPattern pat = tryCastToZyppPattern ((*it)->theObj());
338 yuiDebug() <<
"Lowest #: "<< pat->order() << endl;
340 pat_index.insert( make_pair( name, pat->order()) );
345 std::list<ZyppSel>::iterator listIt;
346 std::vector<std::string> pkgLine;
349 for( indexIt = pat_index.begin(); indexIt != pat_index.end(); ++indexIt)
351 std::string name = (*indexIt).first;
352 std::list<ZyppSel> slbList = patterns[name];
354 for ( listIt = slbList.begin(); listIt != slbList.end(); ++listIt )
356 ZyppObj resPtr = (*listIt)->theObj();
359 pkgLine.push_back( resPtr->summary(LOCALE) );
361 addLine( (*listIt)->status(),
virtual NCursesEvent wHandleInput(wint_t key)
Handles the events concerning the package table (e.g.
bool showInformation()
Show the corresponding information (e.g.
bool fillPatternList()
Fills the std::list with the available selections (and the status info)
void showPatternPackages()
Shows the popup with the add ons (package categories).
bool createListEntry(ZyppPkg pkgPtr, ZyppSel slbPtr)
Creates a line in the package table.
virtual void itemsCleared()
Clears the package list.
void drawList()
Draws the package list (has to be called after the loop with addLine() calls)
virtual NCursesEvent wHandleInput(wint_t ch)
Handles the events concerning the package table (e.g.