libyui-qt-pkg  2.47.5
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 #define STATUS_ICON_SIZE 16
69 #define STATUS_COL_WIDTH 28
70 
71 
72 YQPkgList::YQPkgList( QWidget * parent )
73  : YQPkgObjList( parent )
74 {
75  _srpmStatusCol = -42;
76 
78 
79  int numCol = 0;
80  QStringList headers;
81  QString versionHeaderText;
82  QString instVersionHeaderText;
83 
84 
85  headers << ""; _statusCol = numCol++;
86  headers << _( "Package" ); _nameCol = numCol++;
87  headers << _( "Summary" ); _summaryCol = numCol++;
88 
89  if ( haveInstalledPkgs() )
90  {
91 #if SINGLE_VERSION_COL
92  versionHeaderText = _("Installed (Available)");
93  headers << versionHeaderText; _instVersionCol = numCol++;
94  _versionCol = _instVersionCol;
95 #else
96  versionHeaderText = _( "Avail. Ver." );
97  headers << versionHeaderText; _versionCol = numCol++;
98 
99  instVersionHeaderText = _( "Inst. Ver." );
100  headers << instVersionHeaderText; _instVersionCol = numCol++;
101 #endif
102  }
103  else
104  {
105  versionHeaderText = _( "Version" );
106  headers << versionHeaderText; _versionCol = numCol++;
107  }
108 
109  // headers << _( "Source" ); _srpmStatusCol = numCol++;
110  headers << _( "Size" ); _sizeCol = numCol++;
111 
112  setHeaderLabels( headers );
113 
114  header()->setSortIndicatorShown( true );
115  header()->setSectionsClickable( true );
116 
117  sortByColumn( statusCol(), Qt::AscendingOrder );
118  setAllColumnsShowFocus( true );
119  setIconSize( QSize( STATUS_ICON_SIZE, STATUS_ICON_SIZE ) );
120 
121  header()->setSectionResizeMode( QHeaderView::Interactive );
122 
123  /* NOTE: resizeEvent() is automatically triggered afterwards => sets initial column widths */
124 
125  createActions();
127 
128  connect ( header(), SIGNAL( sectionClicked (int) ),
129  this, SLOT( sortByColumn (int) ) );
130 
131 }
132 
133 
135 {
136  // NOP
137 }
138 
139 
140 void YQPkgList::addPkgItem( ZyppSel selectable,
141  ZyppPkg zyppPkg )
142 {
143  addPkgItem( selectable, zyppPkg, false );
144 }
145 
146 
147 void YQPkgList::addPkgItemDimmed( ZyppSel selectable,
148  ZyppPkg zyppPkg )
149 {
150  addPkgItem( selectable, zyppPkg, true );
151 }
152 
153 
154 void
155 YQPkgList::addPkgItem( ZyppSel selectable,
156  ZyppPkg zyppPkg,
157  bool dimmed )
158 {
159  scrollToTop();
160  scheduleDelayedItemsLayout();
161 
162  if ( ! selectable )
163  {
164  yuiError() << "NULL zypp::ui::Selectable!" << std::endl;
165  return;
166  }
167 
168  YQPkgListItem * item = new YQPkgListItem( this, selectable, zyppPkg );
169  Q_CHECK_PTR( item );
170 
171  updateOptimalColumnWidthValues(selectable, zyppPkg);
173 
174  item->setDimmed( dimmed );
175  applyExcludeRules( item );
176 }
177 
178 
179 bool
181 {
182  for ( ZyppPoolIterator it = zyppPkgBegin();
183  it != zyppPkgEnd();
184  ++it )
185  {
186  if ( (*it)->installedObj() )
187  return true;
188  }
189 
190  return false;
191 }
192 
193 
194 void
196  QTreeWidgetItem * listViewItem,
197  int col,
198  const QPoint & pos )
199 {
200  if ( col == srpmStatusCol() )
201  {
202  YQPkgListItem * item = dynamic_cast<YQPkgListItem *> (listViewItem);
203 
204  if ( item )
205  {
206  if ( button == Qt::LeftButton )
207  {
208  if ( editable() && item->editable() )
209  item->toggleSourceRpmStatus();
210  return;
211  }
212  else if ( button == Qt::RightButton )
213  {
214  if ( editable() && item->editable() )
215  {
216  updateActions( item );
217 
218  if ( _sourceRpmContextMenu )
219  _sourceRpmContextMenu->popup( pos );
220  }
221 
222  return;
223  }
224  }
225  }
226 
227  YQPkgObjList::pkgObjClicked( button, listViewItem, col, pos );
228 }
229 
230 
231 QSize
233 {
234  return QSize( 600, 350 );
235 }
236 
237 
238 void
240 {
241  _sourceRpmContextMenu = new QMenu( this );
242 
243  _sourceRpmContextMenu->addAction(actionInstallSourceRpm);
244  _sourceRpmContextMenu->addAction(actionDontInstallSourceRpm);
245 
246  QMenu * submenu = new QMenu( _sourceRpmContextMenu );
247  Q_CHECK_PTR( submenu );
248  QAction *action = _sourceRpmContextMenu->addMenu( submenu );
249  action->setText(_( "&All in This List" ));
250 
251  submenu->addAction(actionInstallListSourceRpms);
252  submenu->addAction(actionDontInstallListSourceRpms);
253 }
254 
255 
256 void
257 YQPkgList::setInstallCurrentSourceRpm( bool installSourceRpm,
258  bool selectNextItem )
259 {
260 #if FIXME
261  QTreeWidgetItem * listViewItem = selectedItem();
262 
263  if ( ! listViewItem )
264  return;
265 
266  YQPkgListItem * item = dynamic_cast<YQPkgListItem *> (listViewItem);
267 
268  if ( item )
269  {
270  item->setInstallSourceRpm( installSourceRpm );
271 
272  if ( selectNextItem && item->nextSibling() )
273  {
274  item->setSelected( false ); // doesn't emit signals
275  setSelected( item->nextSibling(), true ); // emits signals
276  }
277  }
278 #endif
279 }
280 
281 
282 void
283 YQPkgList::setInstallListSourceRpms( bool installSourceRpm )
284 {
285  if ( ! _editable )
286  return;
287 
288 #if FIXME
289  QTreeWidgetItem * listViewItem = firstChild();
290 
291  while ( listViewItem )
292  {
293  YQPkgListItem * item = dynamic_cast<YQPkgListItem *> (listViewItem);
294 
295  if ( item && item->editable() )
296  {
297  item->setInstallSourceRpm( installSourceRpm );
298  }
299 
300  listViewItem = listViewItem->nextSibling();
301  }
302 #endif
303 }
304 
305 
306 void
308 {
309  _optimalColWidth_statusIcon = 0;
310  _optimalColWidth_name = 0;
311  _optimalColWidth_summary = 0;
312  _optimalColWidth_version = 0;
313  _optimalColWidth_instVersion = 0;
314  _optimalColWidth_size = 0;
315 }
316 
317 
318 void
319 YQPkgList::updateOptimalColumnWidthValues(ZyppSel selectable, ZyppPkg zyppPkg)
320 {
321  QString qstr;
322  int qstr_width = 0;
323  QFontMetrics fm( this->font() );
324  const ZyppObj candidate = selectable->candidateObj();
325  const ZyppObj installed = selectable->installedObj();
326  // Status icon:
327  _optimalColWidth_statusIcon = STATUS_COL_WIDTH;
328  // Name:
329  qstr = QString::fromUtf8( zyppPkg->name().c_str() );
330  qstr_width = fm.boundingRect( qstr ).width() + ( STATUS_ICON_SIZE / 2 );
331  if (qstr_width > _optimalColWidth_name)
332  _optimalColWidth_name = qstr_width;
333  // Summary:
334  qstr = QString::fromUtf8( zyppPkg->summary().c_str() );
335  qstr_width = fm.boundingRect( qstr ).width() + ( STATUS_ICON_SIZE / 2 );
336  if (qstr_width > _optimalColWidth_summary)
337  _optimalColWidth_summary = qstr_width;
338  // Version(s):
339  if ( instVersionCol() == versionCol() ) // combined column, version string
340  {
341  if (installed)
342  qstr = QString::fromUtf8( installed->edition().c_str() );
343  else
344  qstr.clear();
345  if (candidate && (!installed || (candidate->edition() != installed->edition())))
346  {
347  if (installed)
348  qstr += " ";
349  qstr += "(" + QString::fromUtf8( candidate->edition().c_str() ) + ")";
350  }
351  qstr_width = fm.boundingRect( qstr ).width() + ( STATUS_ICON_SIZE / 2 );
352  if (qstr_width > _optimalColWidth_version)
353  _optimalColWidth_version = qstr_width;
354  }
355  else // separate columns, version strings
356  {
357  if (candidate)
358  {
359  qstr = QString::fromUtf8( candidate->edition().c_str() );
360  qstr_width = fm.boundingRect( qstr ).width() + ( STATUS_ICON_SIZE / 2 );
361  if (qstr_width > _optimalColWidth_version)
362  _optimalColWidth_version = qstr_width;
363  }
364  if (installed)
365  {
366  qstr = QString::fromUtf8( installed->edition().c_str() );
367  qstr_width = fm.boundingRect( qstr ).width() + ( STATUS_ICON_SIZE / 2 );
368  if (qstr_width > _optimalColWidth_instVersion)
369  _optimalColWidth_instVersion = qstr_width;
370  }
371  }
372  // Size:
373  qstr = QString::fromUtf8( zyppPkg->installSize().asString().c_str() );
374  qstr_width = fm.boundingRect( qstr ).width() + ( STATUS_ICON_SIZE / 2 );
375  if (qstr_width > _optimalColWidth_size)
376  _optimalColWidth_size = qstr_width;
377 }
378 
379 
380 void
382 {
383  int visibleSpace = 0;
384  int optimalWidthsSum = 0; // Sum of all optimal (sized-to-content-) column width values
385  int numOptCol = 4; // Nr. of columns for distribution of remaining space
386  int statusIconColWidth = _optimalColWidth_statusIcon;
387 
388  if (statusIconColWidth == 0)
389  statusIconColWidth = STATUS_COL_WIDTH;
390  optimalWidthsSum = _optimalColWidth_statusIcon + _optimalColWidth_name + _optimalColWidth_summary + _optimalColWidth_version + _optimalColWidth_size;
391  if ( instVersionCol() != versionCol() )
392  {
393  optimalWidthsSum += _optimalColWidth_instVersion;
394  numOptCol++;
395  }
396  // CHECK IF WE HAVE LESS VISIBLE SPACE THAN WE NEED:
397  visibleSpace = this->viewport()->width();
398  if (visibleSpace < 0) return;
399  if (optimalWidthsSum >= visibleSpace) // THERE IS NOT ENOUGH VISIBLE SPACE TO SHOW ALL CLOUMNS WITH OPTIMAL WIDTHS
400  {
401  /* ONLY REDUCE WIDTH OF THE "summary"-COLUMN BEYOND OPTIMAL WIDTH
402  * IF THIS IS NOT ENOUGH, WE WILL GET A HORIZONTAL SCROLL BAR */
403  int reducedSummaryWidth = visibleSpace - optimalWidthsSum + _optimalColWidth_summary;
404  if (reducedSummaryWidth < 100)
405  reducedSummaryWidth = 100;
406  // Set new column widths:
407  this->setColumnWidth( statusCol(), statusIconColWidth );
408  this->setColumnWidth( nameCol(), _optimalColWidth_name );
409  this->setColumnWidth( summaryCol(), reducedSummaryWidth);
410  this->setColumnWidth( versionCol(), _optimalColWidth_version );
411  if ( instVersionCol() != versionCol() )
412  this->setColumnWidth( instVersionCol(), _optimalColWidth_instVersion );
413  this->setColumnWidth( sizeCol(), _optimalColWidth_size);
414  }
415  else // THERE IS ENOUGH VISIBLE SPACE
416  {
417  // DISTRIBUTE REMAINING VISIBLE SPACE TO ALL COLUMNS (except the satusIcon-column):
418  // Calculate additional column widths:
419  int addSpace = (visibleSpace - optimalWidthsSum) / numOptCol;
420  int addSpaceR = (visibleSpace - optimalWidthsSum) % numOptCol;
421  // Set new column widths:
422  this->setColumnWidth( statusCol(), statusIconColWidth );
423  this->setColumnWidth( nameCol(), _optimalColWidth_name + addSpace );
424  this->setColumnWidth( summaryCol(), _optimalColWidth_summary + addSpace );
425  this->setColumnWidth( versionCol(), _optimalColWidth_version + addSpace );
426  if ( instVersionCol() != versionCol() )
427  this->setColumnWidth( instVersionCol(), _optimalColWidth_instVersion + addSpace );
428  this->setColumnWidth( sizeCol(), _optimalColWidth_size + addSpace + addSpaceR );
429  }
430 }
431 
432 
433 void
435 {
439 }
440 
441 
442 void
444 {
445  int col = sortColumn();
446  Qt::SortOrder order = header()->sortIndicatorOrder();
447  sortByColumn(col, order);
448 }
449 
450 
451 void
452 YQPkgList::resizeEvent(QResizeEvent *event)
453 {
454  if (event->size().width() != event->oldSize().width())
456  /* NOTE: avoids column width optimization when the size changes
457  because the horizontal scroll bar appeares/disappeares */
458  event->accept();
459 }
460 
461 
462 void
464 {
465  _notInstalledContextMenu = new QMenu( this );
466  Q_CHECK_PTR( _notInstalledContextMenu );
467 
468  _notInstalledContextMenu->addAction(actionSetCurrentInstall);
469  _notInstalledContextMenu->addAction(actionSetCurrentDontInstall);
470  _notInstalledContextMenu->addAction(actionSetCurrentTaboo);
471 
472  addAllInListSubMenu( _notInstalledContextMenu );
473 
474  _notInstalledContextMenu->addSeparator();
475  _notInstalledContextMenu->addAction( _( "Export This List to &Text File..." ),
476  this, SLOT( askExportList() ) );
477 }
478 
479 
480 void
482 {
483  _installedContextMenu = new QMenu( this );
484  Q_CHECK_PTR( _installedContextMenu );
485 
486  _installedContextMenu->addAction(actionSetCurrentKeepInstalled);
487  _installedContextMenu->addAction(actionSetCurrentDelete);
488  _installedContextMenu->addAction(actionSetCurrentUpdate);
489  _installedContextMenu->addAction(actionSetCurrentUpdateForce);
490  _installedContextMenu->addAction(actionSetCurrentProtected);
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(), // 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(), // 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::arg() because stdio fprintf() is
620  // not UTF-8 aware - it will count multi-byte characters wrong, so the
621  // formatting will be broken.
622 
623  QString header = QString( "# %1 %2 | %3 | %4 | 5\n\n" )
624  .arg( _( "Status" ), -18 )
625  .arg( _( "Package" ), -30 )
626  .arg( _( "Summary" ), -40 )
627  .arg( _( "Installed (Available)" ), -25 )
628  .arg( _( "Size" ), 10 );
629 
630  file.write( header.toUtf8() );
631 
632 
633  // Write all items
634 
635  QTreeWidgetItemIterator it((QTreeWidget*) this);
636 
637  while (*it)
638  {
639  const QTreeWidgetItem* item(*it);
640  const YQPkgListItem * pkg = dynamic_cast<const YQPkgListItem *> (item);
641 
642  if ( pkg )
643  {
644  QString version = pkg->text( versionCol() );
645  if ( version.isEmpty() ) version = "---";
646 
647  QString summary = pkg->text( summaryCol() );
648  if ( summary.isEmpty() ) summary = "---";
649  if ( summary.size() > 40 )
650  {
651  summary.truncate(40-3);
652  summary += "...";
653  }
654 
655  QString status = "[" + statusText( pkg->status() ) + "]";
656 
657  QString line = QString( "%1 %2 | %3 | %4 | %5\n" )
658  .arg( status, -20 )
659  .arg( pkg->text( nameCol() ), -30 )
660  .arg( summary, -40 )
661  .arg( version, -25 )
662  .arg( pkg->text( sizeCol() ), 10 );
663 
664  file.write( line.toUtf8() );
665  }
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 
void exportList(const QString filename, bool interactive) const
Save the pkg list to a file.
Definition: YQPkgList.cc:589
Abstract base class to display a list of zypp::ResObjects.
Definition: YQPkgObjList.h:66
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:140
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 QSize sizeHint() const
Reimplemented from QListView / QWidget: Reserve a reasonable amount of space.
Definition: YQPkgList.cc:232
virtual QPixmap statusIcon(ZyppStatus status, bool enabled=true, bool bySelection=false)
Returns the suitable icon for a zypp::ResObject status - the regular icon if &#39;enabled&#39; is &#39;true&#39; or t...
virtual void createInstalledContextMenu()
Create the context menu for installed items.
Definition: YQPkgList.cc:481
virtual bool operator<(const QTreeWidgetItem &other) const
sorting function
void resetOptimalColumnWidthValues()
Resets the optimal column width values.
Definition: YQPkgList.cc:307
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:195
YQPkgListItem(YQPkgList *pkgList, ZyppSel selectable, ZyppPkg zyppPkg)
Constructor.
Definition: YQPkgList.cc:758
virtual QString statusText(ZyppStatus status) const
Returns a short (one line) descriptive text for a zypp::ResObject status.
virtual void updateActions(YQPkgObjListItem *item)
Update the internal actions: What actions are available for &#39;item&#39;?
Definition: YQPkgList.cc:558
static bool haveInstalledPkgs()
Returns &#39;true&#39; if there are any installed packages.
Definition: YQPkgList.cc:180
bool hasSourceRpm() const
Returns whether or not a source RPM is available for this package.
Definition: YQPkgList.cc:790
virtual void updateData()
Update this item&#39;s data completely.
virtual bool operator<(const QTreeWidgetItem &other) const
sorting function
Definition: YQPkgList.cc:949
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:381
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:147
virtual void pkgObjClicked(int button, QTreeWidgetItem *item, int col, const QPoint &pos)
Dispatcher slot for mouse click: cycle status depending on column.
bool editable() const
Return whether or not this items is editable, i.e.
Definition: YQPkgObjList.h:464
virtual void updateActions(YQPkgObjListItem *item=0)
Update the internal actions for the currently selected item ( if any ).
void selectNextItem()
Select the next item, i.e.
void updatePackages()
Emitted when it&#39;s time to update displayed package information, e.g., package states.
Display a list of zypp::Package objects.
Definition: YQPkgList.h:54
virtual void updateData()
Update this item&#39;s data completely.
Definition: YQPkgList.cc:782
virtual ZyppStatus status() const
Returns the (binary RPM) package status.
virtual void createNotInstalledContextMenu()
Create the context menu for items that are not installed.
Definition: YQPkgList.cc:463
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:443
YQPkgList(QWidget *parent)
Constructor.
Definition: YQPkgList.cc:72
bool editable() const
Return whether or not items in this list are generally editable, i.e.
Definition: YQPkgObjList.h:108
void clear()
Clears the tree-widgets content, resets the optimal column width values.
Definition: YQPkgList.cc:434
void setDimmed(bool d=true)
Set the &#39;dimmed&#39; flag.
Definition: YQPkgList.h:356
void applyExcludeRules()
Apply all exclude rules of this list to all items, including those that are currently excluded...
bool installSourceRpm() const
Returns the source RPM package status: Should the source RPM be installed?
Definition: YQPkgList.cc:804
ZyppSel selectable() const
Returns the original selectable within the package manager backend.
Definition: YQPkgObjList.h:452
virtual QString toolTip(int column)
Returns a tool tip text for a specific column of this item.
Definition: YQPkgList.cc:871
QAction * createAction(ZyppStatus status, const QString &key=QString(), bool enabled=false)
Create an action based on a zypp::ResObject status - automatically retrieve the corresponding status ...
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:319
virtual QMenu * addAllInListSubMenu(QMenu *menu)
Add a submenu "All in this list..." to &#39;menu&#39;.
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:239
void askExportList() const
Ask for a file name and save the current pkg list to file.
Definition: YQPkgList.cc:578
void resizeEvent(QResizeEvent *event)
Handler for resize events.
Definition: YQPkgList.cc:452
virtual ~YQPkgListItem()
Destructor.
Definition: YQPkgList.cc:775
virtual ~YQPkgList()
Destructor.
Definition: YQPkgList.cc:134