libyui-qt-pkg  2.44.7
 All Classes Functions Variables Enumerations
YQPkgList.cc
1 /**************************************************************************
2 Copyright (C) 2000 - 2010 Novell, Inc.
3 All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
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 along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 **************************************************************************/
20 
21 
22 /*---------------------------------------------------------------------\
23 | |
24 | __ __ ____ _____ ____ |
25 | \ \ / /_ _/ ___|_ _|___ \ |
26 | \ V / _` \___ \ | | __) | |
27 | | | (_| |___) || | / __/ |
28 | |_|\__,_|____/ |_| |_____| |
29 | |
30 | core system |
31 | (C) SuSE GmbH |
32 \----------------------------------------------------------------------/
33 
34  File: YQPkgList.cc
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38  Textdomain "qt-pkg"
39 
40 /-*/
41 
42 
43 
44 #include <algorithm>
45 using std::max;
46 
47 #define YUILogComponent "qt-pkg"
48 #include "YUILog.h"
49 #include <QPixmap>
50 #include <QAction>
51 #include <QMenu>
52 #include <QMessageBox>
53 #include <QFile>
54 #include <QTreeView>
55 #include <QDebug>
56 #include <QHeaderView>
57 #include <QFontMetrics>
58 
59 #include "utf8.h"
60 
61 #include "YQPkgList.h"
62 #include "YQUI.h"
63 #include "YQi18n.h"
64 #include "YQIconPool.h"
65 #include "YQApplication.h"
66 
67 #define SINGLE_VERSION_COL 1
68 
69 
70 YQPkgList::YQPkgList( QWidget * parent )
71  : YQPkgObjList( parent )
72 {
73  _srpmStatusCol = -42;
74 
76 
77  int numCol = 0;
78  QStringList headers;
79  QString versionHeaderText;
80  QString instVersionHeaderText;
81 
82 
83  headers << ""; _statusCol = numCol++;
84  headers << _( "Package" ); _nameCol = numCol++;
85  headers << _( "Summary" ); _summaryCol = numCol++;
86 
87  if ( haveInstalledPkgs() )
88  {
89 #if SINGLE_VERSION_COL
90  versionHeaderText = _("Installed (Available)");
91  headers << versionHeaderText; _instVersionCol = numCol++;
92  _versionCol = _instVersionCol;
93 #else
94  versionHeaderText = _( "Avail. Ver." );
95  headers << versionHeaderText; _versionCol = numCol++;
96 
97  instVersionHeaderText = _( "Inst. Ver." );
98  headers << instVersionHeaderText; _instVersionCol = numCol++;
99 #endif
100  }
101  else
102  {
103  versionHeaderText = _( "Version" );
104  headers << versionHeaderText; _versionCol = numCol++;
105  }
106 
107  // headers << _( "Source" ); _srpmStatusCol = numCol++;
108  headers << _( "Size" ); _sizeCol = numCol++;
109 
110  setHeaderLabels( headers );
111 
112  header()->setSortIndicatorShown( true );
113  header()->setSectionsClickable( true );
114 
115  sortByColumn( statusCol(), Qt::AscendingOrder );
116  setAllColumnsShowFocus( true );
117  setIconSize( QSize( 22, 16 ) );
118 
119  header()->setSectionResizeMode( QHeaderView::Interactive );
120 
121  /* NOTE: resizeEvent() is automatically triggered afterwards => sets initial column widths */
122 
123  createActions();
125 
126  connect ( header(), SIGNAL( sectionClicked (int) ),
127  this, SLOT( sortByColumn (int) ) );
128 
129 }
130 
131 
133 {
134  // NOP
135 }
136 
137 
138 void YQPkgList::addPkgItem( ZyppSel selectable,
139  ZyppPkg zyppPkg )
140 {
141  addPkgItem( selectable, zyppPkg, false );
142 }
143 
144 
145 void YQPkgList::addPkgItemDimmed( ZyppSel selectable,
146  ZyppPkg zyppPkg )
147 {
148  addPkgItem( selectable, zyppPkg, true );
149 }
150 
151 
152 void
153 YQPkgList::addPkgItem( ZyppSel selectable,
154  ZyppPkg zyppPkg,
155  bool dimmed )
156 {
157  scrollToTop();
158  scheduleDelayedItemsLayout();
159 
160  if ( ! selectable )
161  {
162  yuiError() << "NULL zypp::ui::Selectable!" << std::endl;
163  return;
164  }
165 
166  YQPkgListItem * item = new YQPkgListItem( this, selectable, zyppPkg );
167  Q_CHECK_PTR( item );
168 
169  updateOptimalColumnWidthValues(selectable, zyppPkg);
171 
172  item->setDimmed( dimmed );
173  applyExcludeRules( item );
174 }
175 
176 
177 bool
179 {
180  for ( ZyppPoolIterator it = zyppPkgBegin();
181  it != zyppPkgEnd();
182  ++it )
183  {
184  if ( (*it)->installedObj() )
185  return true;
186  }
187 
188  return false;
189 }
190 
191 
192 void
194  QTreeWidgetItem * listViewItem,
195  int col,
196  const QPoint & pos )
197 {
198  if ( col == srpmStatusCol() )
199  {
200  YQPkgListItem * item = dynamic_cast<YQPkgListItem *> (listViewItem);
201 
202  if ( item )
203  {
204  if ( button == Qt::LeftButton )
205  {
206  if ( editable() && item->editable() )
207  item->toggleSourceRpmStatus();
208  return;
209  }
210  else if ( button == Qt::RightButton )
211  {
212  if ( editable() && item->editable() )
213  {
214  updateActions( item );
215 
216  if ( _sourceRpmContextMenu )
217  _sourceRpmContextMenu->popup( pos );
218  }
219 
220  return;
221  }
222  }
223  }
224 
225  YQPkgObjList::pkgObjClicked( button, listViewItem, col, pos );
226 }
227 
228 
229 QSize
231 {
232  return QSize( 600, 350 );
233 }
234 
235 
236 void
238 {
239  _sourceRpmContextMenu = new QMenu( this );
240 
241  _sourceRpmContextMenu->addAction(actionInstallSourceRpm);
242  _sourceRpmContextMenu->addAction(actionDontInstallSourceRpm);
243 
244  QMenu * submenu = new QMenu( _sourceRpmContextMenu );
245  Q_CHECK_PTR( submenu );
246  QAction *action = _sourceRpmContextMenu->addMenu( submenu );
247  action->setText(_( "&All in This List" ));
248 
249  submenu->addAction(actionInstallListSourceRpms);
250  submenu->addAction(actionDontInstallListSourceRpms);
251 }
252 
253 
254 void
255 YQPkgList::setInstallCurrentSourceRpm( bool installSourceRpm,
256  bool selectNextItem )
257 {
258 #if FIXME
259  QTreeWidgetItem * listViewItem = selectedItem();
260 
261  if ( ! listViewItem )
262  return;
263 
264  YQPkgListItem * item = dynamic_cast<YQPkgListItem *> (listViewItem);
265 
266  if ( item )
267  {
268  item->setInstallSourceRpm( installSourceRpm );
269 
270  if ( selectNextItem && item->nextSibling() )
271  {
272  item->setSelected( false ); // doesn't emit signals
273  setSelected( item->nextSibling(), true ); // emits signals
274  }
275  }
276 #endif
277 }
278 
279 
280 void
281 YQPkgList::setInstallListSourceRpms( bool installSourceRpm )
282 {
283  if ( ! _editable )
284  return;
285 
286 #if FIXME
287  QTreeWidgetItem * listViewItem = firstChild();
288 
289  while ( listViewItem )
290  {
291  YQPkgListItem * item = dynamic_cast<YQPkgListItem *> (listViewItem);
292 
293  if ( item && item->editable() )
294  {
295  item->setInstallSourceRpm( installSourceRpm );
296  }
297 
298  listViewItem = listViewItem->nextSibling();
299  }
300 #endif
301 }
302 
303 
304 void
306 {
307  _optimalColWidth_statusIcon = 0;
308  _optimalColWidth_name = 0;
309  _optimalColWidth_summary = 0;
310  _optimalColWidth_version = 0;
311  _optimalColWidth_instVersion = 0;
312  _optimalColWidth_size = 0;
313 }
314 
315 
316 void
317 YQPkgList::updateOptimalColumnWidthValues(ZyppSel selectable, ZyppPkg zyppPkg)
318 {
319  QString qstr;
320  int qstr_width = 0;
321  QFontMetrics fm( this->font() );
322  const ZyppObj candidate = selectable->candidateObj();
323  const ZyppObj installed = selectable->installedObj();
324  // Status icon:
325  _optimalColWidth_statusIcon = 28;
326  // Name:
327  qstr = QString::fromUtf8( zyppPkg->name().c_str() );
328  qstr_width = fm.boundingRect( qstr ).width() + 8;
329  if (qstr_width > _optimalColWidth_name)
330  _optimalColWidth_name = qstr_width;
331  // Summary:
332  qstr = QString::fromUtf8( zyppPkg->summary().c_str() );
333  qstr_width = fm.boundingRect( qstr ).width() + 8;
334  if (qstr_width > _optimalColWidth_summary)
335  _optimalColWidth_summary = qstr_width;
336  // Version(s):
337  if ( instVersionCol() == versionCol() ) // combined column, version string
338  {
339  if (installed)
340  qstr = QString::fromUtf8( installed->edition().c_str() );
341  else
342  qstr.clear();
343  if (candidate && (!installed || (candidate->edition() != installed->edition())))
344  {
345  if (installed)
346  qstr += " ";
347  qstr += "(" + QString::fromUtf8( candidate->edition().c_str() ) + ")";
348  }
349  qstr_width = fm.boundingRect( qstr ).width() + 8;
350  if (qstr_width > _optimalColWidth_version)
351  _optimalColWidth_version = qstr_width;
352  }
353  else // separate columns, version strings
354  {
355  if (candidate)
356  {
357  qstr = QString::fromUtf8( candidate->edition().c_str() );
358  qstr_width = fm.boundingRect( qstr ).width() + 8;
359  if (qstr_width > _optimalColWidth_version)
360  _optimalColWidth_version = qstr_width;
361  }
362  if (installed)
363  {
364  qstr = QString::fromUtf8( installed->edition().c_str() );
365  qstr_width = fm.boundingRect( qstr ).width() + 8;
366  if (qstr_width > _optimalColWidth_instVersion)
367  _optimalColWidth_instVersion = qstr_width;
368  }
369  }
370  // Size:
371  qstr = QString::fromUtf8( zyppPkg->installSize().asString().c_str() );
372  qstr_width = fm.boundingRect( qstr ).width() + 8;
373  if (qstr_width > _optimalColWidth_size)
374  _optimalColWidth_size = qstr_width;
375 }
376 
377 
378 void
380 {
381  int visibleSpace = 0;
382  int optimalWidthsSum = 0; // Sum of all optimal (sized-to-content-) column width values
383  int numOptCol = 4; // Nr. of columns for distribution of remaining space
384  int statusIconColWidth = _optimalColWidth_statusIcon;
385 
386  if (statusIconColWidth == 0)
387  statusIconColWidth = 28;
388  optimalWidthsSum = _optimalColWidth_statusIcon + _optimalColWidth_name + _optimalColWidth_summary + _optimalColWidth_version + _optimalColWidth_size;
389  if ( instVersionCol() != versionCol() )
390  {
391  optimalWidthsSum += _optimalColWidth_instVersion;
392  numOptCol++;
393  }
394  // CHECK IF WE HAVE LESS VISIBLE SPACE THAN WE NEED:
395  visibleSpace = this->viewport()->width();
396  if (visibleSpace < 0) return;
397  if (optimalWidthsSum >= visibleSpace) // THERE IS NOT ENOUGH VISIBLE SPACE TO SHOW ALL CLOUMNS WITH OPTIMAL WIDTHS
398  {
399  /* ONLY REDUCE WIDTH OF THE "summary"-COLUMN BEYOND OPTIMAL WIDTH
400  * IF THIS IS NOT ENOUGH, WE WILL GET A HORIZONTAL SCROLL BAR */
401  int reducedSummaryWidth = visibleSpace - optimalWidthsSum + _optimalColWidth_summary;
402  if (reducedSummaryWidth < 100)
403  reducedSummaryWidth = 100;
404  // Set new column widths:
405  this->setColumnWidth( statusCol(), statusIconColWidth );
406  this->setColumnWidth( nameCol(), _optimalColWidth_name );
407  this->setColumnWidth( summaryCol(), reducedSummaryWidth);
408  this->setColumnWidth( versionCol(), _optimalColWidth_version );
409  if ( instVersionCol() != versionCol() )
410  this->setColumnWidth( instVersionCol(), _optimalColWidth_instVersion );
411  this->setColumnWidth( sizeCol(), _optimalColWidth_size);
412  }
413  else // THERE IS ENOUGH VISIBLE SPACE
414  {
415  // DISTRIBUTE REMAINING VISIBLE SPACE TO ALL COLUMNS (except the satusIcon-column):
416  // Calculate additional column widths:
417  int addSpace = (visibleSpace - optimalWidthsSum) / numOptCol;
418  int addSpaceR = (visibleSpace - optimalWidthsSum) % numOptCol;
419  // Set new column widths:
420  this->setColumnWidth( statusCol(), statusIconColWidth );
421  this->setColumnWidth( nameCol(), _optimalColWidth_name + addSpace );
422  this->setColumnWidth( summaryCol(), _optimalColWidth_summary + addSpace );
423  this->setColumnWidth( versionCol(), _optimalColWidth_version + addSpace );
424  if ( instVersionCol() != versionCol() )
425  this->setColumnWidth( instVersionCol(), _optimalColWidth_instVersion + addSpace );
426  this->setColumnWidth( sizeCol(), _optimalColWidth_size + addSpace + addSpaceR );
427  }
428 }
429 
430 
431 void
433 {
437 }
438 
439 
440 void
442 {
443  int col = sortColumn();
444  Qt::SortOrder order = header()->sortIndicatorOrder();
445  sortByColumn(col, order);
446 }
447 
448 
449 void
450 YQPkgList::resizeEvent(QResizeEvent *event)
451 {
452  if (event->size().width() != event->oldSize().width())
454  /* NOTE: avoids column width optimization when the size changes
455  because the horizontal scroll bar appeares/disappeares */
456  event->accept();
457 }
458 
459 
460 void
462 {
463  _notInstalledContextMenu = new QMenu( this );
464  Q_CHECK_PTR( _notInstalledContextMenu );
465 
466  _notInstalledContextMenu->addAction(actionSetCurrentInstall);
467  _notInstalledContextMenu->addAction(actionSetCurrentDontInstall);
468  _notInstalledContextMenu->addAction(actionSetCurrentTaboo);
469  _notInstalledContextMenu->addAction(actionShowCurrentSolverInfo);
470 
471  addAllInListSubMenu( _notInstalledContextMenu );
472 
473  _notInstalledContextMenu->addSeparator();
474  _notInstalledContextMenu->addAction( _( "Export This List to &Text File..." ),
475  this, SLOT( askExportList() ) );
476 }
477 
478 
479 void
481 {
482  _installedContextMenu = new QMenu( this );
483  Q_CHECK_PTR( _installedContextMenu );
484 
485  _installedContextMenu->addAction(actionSetCurrentKeepInstalled);
486  _installedContextMenu->addAction(actionSetCurrentDelete);
487  _installedContextMenu->addAction(actionSetCurrentUpdate);
488  _installedContextMenu->addAction(actionSetCurrentUpdateForce);
489  _installedContextMenu->addAction(actionSetCurrentProtected);
490  _installedContextMenu->addAction(actionShowCurrentSolverInfo);
491 
492  addAllInListSubMenu( _installedContextMenu );
493 
494  _installedContextMenu->addSeparator();
495  _installedContextMenu->addAction( _( "Export This List to &Text File..." ),
496  this, SLOT( askExportList() ) );
497 }
498 
499 
500 QMenu *
502 {
503  QMenu * submenu = new QMenu( menu );
504  Q_CHECK_PTR( submenu );
505 
506  submenu->addAction(actionSetListInstall);
507  submenu->addAction(actionSetListDontInstall);
508  submenu->addAction(actionSetListKeepInstalled);
509  submenu->addAction(actionSetListDelete);
510  submenu->addAction(actionSetListDelete);
511  submenu->addAction(actionSetListUpdate);
512  submenu->addAction(actionSetListUpdateForce);
513  submenu->addAction(actionSetListTaboo);
514  submenu->addAction(actionSetListProtected);
515 
516  QAction *action = menu->addMenu( submenu );
517  action->setText(_( "&All in This List" ));
518 
519  return submenu;
520 }
521 
522 
523 void
525 {
526  actionInstallSourceRpm = createAction( _( "&Install Source" ),
527  statusIcon( S_Install, true ),
528  statusIcon( S_Install, false ) );
529 
530  actionDontInstallSourceRpm = createAction( _( "Do &Not Install Source" ),
531  statusIcon( S_NoInst, true ),
532  statusIcon( S_NoInst, false ) );
533 
534  actionInstallListSourceRpms = createAction( _( "&Install All Available Sources" ),
535  statusIcon( S_Install, true ),
536  statusIcon( S_Install, false ),
537  QString::null, // key
538  true ); // enabled
539 
540  actionDontInstallListSourceRpms = createAction( _( "Do &Not Install Any Sources" ),
541  statusIcon( S_NoInst, true ),
542  statusIcon( S_NoInst, false ),
543  QString::null, // key
544  true ); // enabled
545 
546  connect( actionInstallSourceRpm, &QAction::triggered,
547  this, static_cast<void (YQPkgList::*)()>(&YQPkgList::setInstallCurrentSourceRpm) );
548  connect( actionDontInstallSourceRpm, &QAction::triggered,
549  this, &YQPkgList::setDontInstallCurrentSourceRpm );
550  connect( actionInstallListSourceRpms, &QAction::triggered,
551  this, static_cast<void (YQPkgList::*)()>(&YQPkgList::setInstallListSourceRpms) );
552  connect( actionDontInstallListSourceRpms, &QAction::triggered,
553  this, &YQPkgList::setDontInstallListSourceRpms );
554 }
555 
556 
557 void
559 {
560  YQPkgObjList::updateActions( pkgObjListItem );
561 
562  YQPkgListItem * item = dynamic_cast<YQPkgListItem *> (pkgObjListItem);
563 
564  if ( item )
565  {
566  actionInstallSourceRpm->setEnabled( item->hasSourceRpm() );
567  actionDontInstallSourceRpm->setEnabled( item->hasSourceRpm() );
568  }
569  else
570  {
571  actionInstallSourceRpm->setEnabled( false );
572  actionDontInstallSourceRpm->setEnabled( false );
573  }
574 }
575 
576 
577 void
579 {
580  QString filename = YQApplication::askForSaveFileName( "pkglist.txt", // startsWith
581  "*.txt", // filter
582  _( "Export Package List" ) );
583  if ( ! filename.isEmpty() )
584  exportList( filename, true );
585 }
586 
587 
588 void
589 YQPkgList::exportList( const QString filename, bool interactive ) const
590 {
591  // Open file
592 
593  QFile file(filename);
594  file.open(QIODevice::WriteOnly);
595 
596  if ( file.error() != QFile::NoError )
597  {
598  yuiError() << "Can't open file " << filename << std::endl;
599 
600  if ( interactive )
601  {
602  // Post error popup.
603 
604  QMessageBox::warning( 0, // parent
605  _( "Error" ), // caption
606  _( "Cannot open file %1" ).arg( filename ),
607  QMessageBox::Ok | QMessageBox::Default, // button0
608  QMessageBox::NoButton, // button1
609  QMessageBox::NoButton ); // button2
610  }
611  return;
612  }
613 
614 
615  //
616  // Write header
617  //
618 
619  // Format the header line with QString::sprintf() because plain stdio
620  // fprintf() is not UTF-8 aware - it will count multi-byte characters
621  // wrong, so the formatting will be broken.
622 
623  QString header;
624  header.sprintf( "# %-18s %-30s | %-40s | %-25s | %10s\n\n",
625  (const char *) _( "Status" ).toUtf8(),
626  (const char *) _( "Package" ).toUtf8(),
627  (const char *) _( "Summary" ).toUtf8(),
628  (const char *) _( "Installed (Available)" ).toUtf8(),
629  (const char *) _( "Size" ).toUtf8()
630  );
631  file.write(header.toUtf8());
632 
633 
634  // Write all items
635 
636  QTreeWidgetItemIterator it((QTreeWidget*) this);
637 
638  while (*it)
639  {
640  const QTreeWidgetItem* item(*it);
641  const YQPkgListItem * pkg = dynamic_cast<const YQPkgListItem *> (item);
642 
643  if ( pkg )
644  {
645  QString version = pkg->text( versionCol() );
646  if ( version.isEmpty() ) version = "---";
647 
648  QString summary = pkg->text( summaryCol() );
649  if ( summary.isEmpty() ) summary = "---";
650  if ( summary.size() > 40 )
651  {
652  summary.truncate(40-3);
653  summary += "...";
654  }
655 
656  QString status = "[" + statusText( pkg->status() ) + "]";
657  QString format;
658  format.sprintf("%-20s %-30s | %-40s | %-25s | %10s\n",
659  (const char*) status.toUtf8(),
660  (const char*) pkg->text( nameCol() ).toUtf8(),
661  (const char*) summary.toUtf8(),
662  (const char*) version.toUtf8(),
663  (const char*) pkg->text( sizeCol() ).toUtf8()
664  );
665  file.write(format.toUtf8());
666  }
667  ++it;
668  }
669 
670  // Clean up
671 
672  if ( file.isOpen() )
673  file.close();
674 }
675 
676 
677 int
678 YQPkgList::globalSetPkgStatus( ZyppStatus newStatus, bool force, bool countOnly )
679 {
680  YQUI::ui()->busyCursor();
681  int changedCount = 0;
682 
683  for ( ZyppPoolIterator it = zyppPkgBegin();
684  it != zyppPkgEnd();
685  ++it )
686  {
687  ZyppSel selectable = *it;
688  ZyppStatus oldStatus = selectable->status();
689 
690  if ( newStatus != oldStatus )
691  {
692  bool doChange = false;
693 
694  switch ( newStatus )
695  {
696  case S_KeepInstalled:
697  case S_Del:
698  case S_AutoDel:
699  case S_Protected:
700  doChange = !selectable->installedEmpty();
701  break;
702 
703  case S_Update:
704  case S_AutoUpdate:
705 
706  if ( force )
707  {
708  doChange = !selectable->installedEmpty();
709  }
710  else // don't force - update only if useful (if candidate is newer)
711  {
712  const ZyppObj candidate = selectable->candidateObj();
713  const ZyppObj installed = selectable->installedObj();
714 
715  if ( candidate && installed )
716  {
717  doChange = ( installed->edition() < candidate->edition() );
718  }
719  }
720  break;
721 
722  case S_Install:
723  case S_AutoInstall:
724  case S_NoInst:
725  case S_Taboo:
726  doChange = selectable->installedEmpty();
727  break;
728  }
729 
730  if ( doChange )
731  {
732  if ( ! countOnly && oldStatus != S_Protected )
733  selectable->setStatus( newStatus );
734 
735  changedCount++;
736  // yuiMilestone() << "Updating " << selectable->name() << std::endl;
737  }
738  }
739  }
740 
741  if ( changedCount > 0 && ! countOnly )
742  {
743  emit updateItemStates();
744  emit updatePackages();
745  emit statusChanged();
746  }
747 
748  YQUI::ui()->normalCursor();
749 
750  return changedCount;
751 }
752 
753 
754 
755 
756 
757 
759  ZyppSel selectable,
760  ZyppPkg zyppPkg )
761  : YQPkgObjListItem( pkgList, selectable, zyppPkg )
762  , _pkgList( pkgList )
763  , _zyppPkg( zyppPkg )
764  , _dimmed( false )
765 {
766  if ( ! _zyppPkg )
767  _zyppPkg = tryCastToZyppPkg( selectable->theObj() );
768 
770 
771  setTextAlignment( sizeCol(), Qt::AlignRight );
772 }
773 
774 
776 {
777  // NOP
778 }
779 
780 
781 void
783 {
786 }
787 
788 
789 bool
791 {
792  if ( ! selectable() )
793  return false;
794 
795 #ifdef FIXME
796  return selectable()->providesSources();
797 #else
798  return false;
799 #endif
800 }
801 
802 
803 bool
805 {
806  if ( ! selectable() )
807  return false;
808 
809 #ifdef FIXME
810  if ( ! selectable()->providesSources() )
811  return false;
812 
813  return selectable()->source_install();
814 #else
815  return false;
816 #endif
817 }
818 
819 
820 void
822 {
823  if ( srpmStatusCol() < 0 )
824  return;
825 
826  QPixmap icon;
827 
828  if ( hasSourceRpm() )
829  {
830 
831  if ( editable() && _pkgObjList->editable() )
832  {
833  icon = installSourceRpm() ?
834  YQIconPool::pkgInstall() :
835  YQIconPool::pkgNoInst();
836  }
837  else
838  {
839  icon = installSourceRpm() ?
840  YQIconPool::disabledPkgInstall() :
841  YQIconPool::disabledPkgNoInst();
842  }
843  }
844  setData( srpmStatusCol(), Qt::DecorationRole, icon );
845 }
846 
847 
848 void
849 YQPkgListItem::setInstallSourceRpm( bool installSourceRpm )
850 {
851  if ( hasSourceRpm() )
852  {
853 #ifdef FIXME
854  if ( selectable() )
855  selectable()->set_source_install( installSourceRpm );
856 #endif
857  }
858 
860 }
861 
862 
863 void
865 {
867 }
868 
869 
870 QString
872 {
873  QString text;
874  QString name = _zyppObj->name().c_str();
875 
876  if ( col == statusCol() )
877  {
878  text = YQPkgObjListItem::toolTip( col );
879  }
880  else if ( col == srpmStatusCol() )
881  {
882  text = name + "\n\n";
883 
884  if ( hasSourceRpm() )
885  {
886  text += installSourceRpm() ?
887  _( "Install Sources" ) :
888  _( "Do Not Install Sources" );
889  }
890  else
891  {
892  text += _( "No Sources Available" );
893  }
894  }
895  else
896  {
897  text = name + "\n\n";
898 
899  QString installed;
900  QString candidate;
901 
902  if ( !selectable()->installedEmpty() )
903  {
904  installed = selectable()->installedObj()->edition().asString().c_str();
905  installed += "-";
906  installed += selectable()->installedObj()->arch().asString().c_str();
907  installed = _( "Installed Version: %1" ).arg( installed );
908  }
909 
910  if ( selectable()->hasCandidateObj() )
911  {
912  candidate = selectable()->candidateObj()->edition().asString().c_str();
913  candidate += "-";
914  candidate += selectable()->candidateObj()->arch().asString().c_str();
915  }
916 
917  if ( !selectable()->installedEmpty() )
918  {
919  text += installed + "\n";
920 
921  if ( selectable()->hasCandidateObj() )
922  {
923  // Translators: This is the relation between two versions of one package
924  // if both versions are the same, e.g., both "1.2.3-42", "1.2.3-42"
925  QString relation = _( "same" );
926 
927  if ( _candidateIsNewer ) relation = _( "newer" );
928  if ( _installedIsNewer ) relation = _( "older" );
929 
930  // Translators: %1 is the version, %2 is one of "newer", "older", "same"
931  text += _( "Available Version: %1 (%2)" ).arg( candidate ).arg( relation );
932  }
933  else
934  {
935  text += _( "Not available for installation" );
936  }
937  }
938  else // not installed
939  {
940  text += candidate;
941  }
942  }
943 
944  return text;
945 }
946 
947 
948 
949 bool YQPkgListItem::operator< ( const QTreeWidgetItem & otherListViewItem ) const
950 {
951  const YQPkgListItem * other = dynamic_cast<const YQPkgListItem *> (&otherListViewItem);
952 
953  int col = treeWidget()->sortColumn();
954  if ( col == srpmStatusCol() )
955  {
956  if ( other )
957  {
958  int thisPoints = ( this->hasSourceRpm() ? 1 : 0 ) + ( this->installSourceRpm() ? 1 : 0 );
959  int otherPoints = ( other->hasSourceRpm() ? 1 : 0 ) + ( other->installSourceRpm() ? 1 : 0 );
960 
961  // Intentionally inverting order: Pkgs with source RPMs are more interesting than without.
962  return ( thisPoints < otherPoints );
963  }
964  }
965 
966  // Fallback: Use parent class method
967  return YQPkgObjListItem::operator<( otherListViewItem );
968 }
969 
970 #include "YQPkgList.moc"
ZyppSel selectable() const
Returns the original selectable within the package manager backend.
Definition: YQPkgObjList.h:466
Abstract base class to display a list of zypp::ResObjects.
Definition: YQPkgObjList.h:68
void statusChanged()
Emitted when the status of a zypp::ResObject is changed.
void addPkgItem(ZyppSel selectable, ZyppPkg zyppPkg)
Add a pkg to the list.
Definition: YQPkgList.cc:138
int globalSetPkgStatus(ZyppStatus newStatus, bool force, bool countOnly)
Set the status of all packages in the pool to a new value.
Definition: YQPkgList.cc:678
void toggleSourceRpmStatus()
Cycle the source package status to the next valid value.
Definition: YQPkgList.cc:864
virtual QPixmap statusIcon(ZyppStatus status, bool enabled=true, bool bySelection=false)
Returns the suitable icon for a zypp::ResObject status - the regular icon if 'enabled' is 'true' or t...
virtual void createInstalledContextMenu()
Create the context menu for installed items.
Definition: YQPkgList.cc:480
void resetOptimalColumnWidthValues()
Resets the optimal column width values.
Definition: YQPkgList.cc:305
virtual void pkgObjClicked(int button, QTreeWidgetItem *item, int col, const QPoint &pos)
Dispatcher slot for mouse click: Take care of source RPM status.
Definition: YQPkgList.cc:193
virtual bool operator<(const QTreeWidgetItem &other) const
sorting function
Definition: YQPkgList.cc:949
YQPkgListItem(YQPkgList *pkgList, ZyppSel selectable, ZyppPkg zyppPkg)
Constructor.
Definition: YQPkgList.cc:758
virtual void updateActions(YQPkgObjListItem *item)
Update the internal actions: What actions are available for 'item'?
Definition: YQPkgList.cc:558
static bool haveInstalledPkgs()
Returns 'true' if there are any installed packages.
Definition: YQPkgList.cc:178
virtual void updateData()
Update this item's data completely.
virtual void clear()
Reimplemented from QY2ListView: Emit currentItemChanged() signal after clearing the list...
void optimizeColumnWidths()
Optimizes the column widths depending on content and the available horizontal space.
Definition: YQPkgList.cc:379
void addPkgItemDimmed(ZyppSel selectable, ZyppPkg zyppPkg)
Add a pkg to the list, but display it dimmed (grey text foreground rather than normal black)...
Definition: YQPkgList.cc:145
QAction * createAction(ZyppStatus status, const QString &key=QString::null, bool enabled=false)
Create an action based on a zypp::ResObject status - automatically retrieve the corresponding status ...
virtual void pkgObjClicked(int button, QTreeWidgetItem *item, int col, const QPoint &pos)
Dispatcher slot for mouse click: cycle status depending on column.
virtual void updateActions(YQPkgObjListItem *item=0)
Update the internal actions for the currently selected item ( if any ).
bool editable() const
Return whether or not items in this list are generally editable, i.e.
Definition: YQPkgObjList.h:110
bool hasSourceRpm() const
Returns whether or not a source RPM is available for this package.
Definition: YQPkgList.cc:790
void updatePackages()
Emitted when it's time to update displayed package information, e.g., package states.
virtual QSize sizeHint() const
Reimplemented from QListView / QWidget: Reserve a reasonable amount of space.
Definition: YQPkgList.cc:230
virtual bool operator<(const QTreeWidgetItem &other) const
sorting function
Display a list of zypp::Package objects.
Definition: YQPkgList.h:54
virtual void updateData()
Update this item's data completely.
Definition: YQPkgList.cc:782
virtual void createNotInstalledContextMenu()
Create the context menu for items that are not installed.
Definition: YQPkgList.cc:461
void setSourceRpmIcon()
Set the suitable icon for the source RPM status.
Definition: YQPkgList.cc:821
void resort()
Sort the tree widget again according to the column selected and its current sort order.
Definition: YQPkgList.cc:441
YQPkgList(QWidget *parent)
Constructor.
Definition: YQPkgList.cc:70
void exportList(const QString filename, bool interactive) const
Save the pkg list to a file.
Definition: YQPkgList.cc:589
void clear()
Clears the tree-widgets content, resets the optimal column width values.
Definition: YQPkgList.cc:432
void setDimmed(bool d=true)
Set the 'dimmed' flag.
Definition: YQPkgList.h:356
void applyExcludeRules()
Apply all exclude rules of this list to all items, including those that are currently excluded...
virtual QString statusText(ZyppStatus status) const
Returns a short (one line) descriptive text for a zypp::ResObject status.
void askExportList() const
Ask for a file name and save the current pkg list to file.
Definition: YQPkgList.cc:578
virtual QString toolTip(int column)
Returns a tool tip text for a specific column of this item.
Definition: YQPkgList.cc:871
void updateOptimalColumnWidthValues(ZyppSel selectable, ZyppPkg zyppPkg)
Set and save optimal column widths depending on content only There is currently no way to get the opt...
Definition: YQPkgList.cc:317
virtual QMenu * addAllInListSubMenu(QMenu *menu)
Add a submenu "All in this list..." to 'menu'.
Definition: YQPkgList.cc:501
void setInstallSourceRpm(bool installSourceRpm)
Set the source RPM status.
Definition: YQPkgList.cc:849
void createActions()
Create ( additional ) actions for the context menus.
Definition: YQPkgList.cc:524
virtual QString toolTip(int column)
Returns a tool tip text for a specific column of this item.
void createSourceRpmContextMenu()
Create context menu for source RPMs.
Definition: YQPkgList.cc:237
bool installSourceRpm() const
Returns the source RPM package status: Should the source RPM be installed?
Definition: YQPkgList.cc:804
virtual ZyppStatus status() const
Returns the (binary RPM) package status.
void resizeEvent(QResizeEvent *event)
Handler for resize events.
Definition: YQPkgList.cc:450
virtual ~YQPkgListItem()
Destructor.
Definition: YQPkgList.cc:775
virtual ~YQPkgList()
Destructor.
Definition: YQPkgList.cc:132
bool editable() const
Return whether or not this items is editable, i.e.
Definition: YQPkgObjList.h:478