libyui-qt-pkg  2.42.13
 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()->setClickable( true );
114 
115  sortByColumn( statusCol(), Qt::AscendingOrder );
116  setAllColumnsShowFocus( true );
117  setIconSize( QSize( 22, 16 ) );
118 
119  header()->setResizeMode( 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, SIGNAL( activated() ), this, SLOT( setInstallCurrentSourceRpm() ) );
547  connect( actionDontInstallSourceRpm, SIGNAL( activated() ), this, SLOT( setDontInstallCurrentSourceRpm() ) );
548 
549  connect( actionInstallListSourceRpms, SIGNAL( activated() ), this, SLOT( setInstallListSourceRpms() ) );
550  connect( actionDontInstallListSourceRpms, SIGNAL( activated() ), this, SLOT( setDontInstallListSourceRpms() ) );
551 }
552 
553 
554 void
556 {
557  YQPkgObjList::updateActions( pkgObjListItem );
558 
559  YQPkgListItem * item = dynamic_cast<YQPkgListItem *> (pkgObjListItem);
560 
561  if ( item )
562  {
563  actionInstallSourceRpm->setEnabled( item->hasSourceRpm() );
564  actionDontInstallSourceRpm->setEnabled( item->hasSourceRpm() );
565  }
566  else
567  {
568  actionInstallSourceRpm->setEnabled( false );
569  actionDontInstallSourceRpm->setEnabled( false );
570  }
571 }
572 
573 
574 void
576 {
577  QString filename = YQApplication::askForSaveFileName( "pkglist.txt", // startsWith
578  "*.txt", // filter
579  _( "Export Package List" ) );
580  if ( ! filename.isEmpty() )
581  exportList( filename, true );
582 }
583 
584 
585 void
586 YQPkgList::exportList( const QString filename, bool interactive ) const
587 {
588  // Open file
589 
590  QFile file(filename);
591  file.open(QIODevice::WriteOnly);
592 
593  if ( file.error() != QFile::NoError )
594  {
595  yuiError() << "Can't open file " << filename << std::endl;
596 
597  if ( interactive )
598  {
599  // Post error popup.
600 
601  QMessageBox::warning( 0, // parent
602  _( "Error" ), // caption
603  _( "Cannot open file %1" ).arg( filename ),
604  QMessageBox::Ok | QMessageBox::Default, // button0
605  QMessageBox::NoButton, // button1
606  QMessageBox::NoButton ); // button2
607  }
608  return;
609  }
610 
611 
612  //
613  // Write header
614  //
615 
616  // Format the header line with QString::sprintf() because plain stdio
617  // fprintf() is not UTF-8 aware - it will count multi-byte characters
618  // wrong, so the formatting will be broken.
619 
620  QString header;
621  header.sprintf( "# %-18s %-30s | %-40s | %-25s | %10s\n\n",
622  (const char *) _( "Status" ).toUtf8(),
623  (const char *) _( "Package" ).toUtf8(),
624  (const char *) _( "Summary" ).toUtf8(),
625  (const char *) _( "Installed (Available)" ).toUtf8(),
626  (const char *) _( "Size" ).toUtf8()
627  );
628  file.write(header.toUtf8());
629 
630 
631  // Write all items
632 
633  QTreeWidgetItemIterator it((QTreeWidget*) this);
634 
635  while (*it)
636  {
637  const QTreeWidgetItem* item(*it);
638  const YQPkgListItem * pkg = dynamic_cast<const YQPkgListItem *> (item);
639 
640  if ( pkg )
641  {
642  QString version = pkg->text( versionCol() );
643  if ( version.isEmpty() ) version = "---";
644 
645  QString summary = pkg->text( summaryCol() );
646  if ( summary.isEmpty() ) summary = "---";
647  if ( summary.size() > 40 )
648  {
649  summary.truncate(40-3);
650  summary += "...";
651  }
652 
653  QString status = "[" + statusText( pkg->status() ) + "]";
654  QString format;
655  format.sprintf("%-20s %-30s | %-40s | %-25s | %10s\n",
656  (const char*) status.toUtf8(),
657  (const char*) pkg->text( nameCol() ).toUtf8(),
658  (const char*) summary.toUtf8(),
659  (const char*) version.toUtf8(),
660  (const char*) pkg->text( sizeCol() ).toUtf8()
661  );
662  file.write(format.toUtf8());
663  }
664  ++it;
665  }
666 
667  // Clean up
668 
669  if ( file.isOpen() )
670  file.close();
671 }
672 
673 
674 int
675 YQPkgList::globalSetPkgStatus( ZyppStatus newStatus, bool force, bool countOnly )
676 {
677  YQUI::ui()->busyCursor();
678  int changedCount = 0;
679 
680  for ( ZyppPoolIterator it = zyppPkgBegin();
681  it != zyppPkgEnd();
682  ++it )
683  {
684  ZyppSel selectable = *it;
685  ZyppStatus oldStatus = selectable->status();
686 
687  if ( newStatus != oldStatus )
688  {
689  bool doChange = false;
690 
691  switch ( newStatus )
692  {
693  case S_KeepInstalled:
694  case S_Del:
695  case S_AutoDel:
696  case S_Protected:
697  doChange = !selectable->installedEmpty();
698  break;
699 
700  case S_Update:
701  case S_AutoUpdate:
702 
703  if ( force )
704  {
705  doChange = !selectable->installedEmpty();
706  }
707  else // don't force - update only if useful (if candidate is newer)
708  {
709  const ZyppObj candidate = selectable->candidateObj();
710  const ZyppObj installed = selectable->installedObj();
711 
712  if ( candidate && installed )
713  {
714  doChange = ( installed->edition() < candidate->edition() );
715  }
716  }
717  break;
718 
719  case S_Install:
720  case S_AutoInstall:
721  case S_NoInst:
722  case S_Taboo:
723  doChange = selectable->installedEmpty();
724  break;
725  }
726 
727  if ( doChange )
728  {
729  if ( ! countOnly && oldStatus != S_Protected )
730  selectable->setStatus( newStatus );
731 
732  changedCount++;
733  // yuiMilestone() << "Updating " << selectable->name() << std::endl;
734  }
735  }
736  }
737 
738  if ( changedCount > 0 && ! countOnly )
739  {
740  emit updateItemStates();
741  emit updatePackages();
742  emit statusChanged();
743  }
744 
745  YQUI::ui()->normalCursor();
746 
747  return changedCount;
748 }
749 
750 
751 
752 
753 
754 
756  ZyppSel selectable,
757  ZyppPkg zyppPkg )
758  : YQPkgObjListItem( pkgList, selectable, zyppPkg )
759  , _pkgList( pkgList )
760  , _zyppPkg( zyppPkg )
761  , _dimmed( false )
762 {
763  if ( ! _zyppPkg )
764  _zyppPkg = tryCastToZyppPkg( selectable->theObj() );
765 
767 
768  setTextAlignment( sizeCol(), Qt::AlignRight );
769 }
770 
771 
773 {
774  // NOP
775 }
776 
777 
778 void
780 {
783 }
784 
785 
786 bool
788 {
789  if ( ! selectable() )
790  return false;
791 
792 #ifdef FIXME
793  return selectable()->providesSources();
794 #else
795  return false;
796 #endif
797 }
798 
799 
800 bool
802 {
803  if ( ! selectable() )
804  return false;
805 
806 #ifdef FIXME
807  if ( ! selectable()->providesSources() )
808  return false;
809 
810  return selectable()->source_install();
811 #else
812  return false;
813 #endif
814 }
815 
816 
817 void
819 {
820  if ( srpmStatusCol() < 0 )
821  return;
822 
823  QPixmap icon;
824 
825  if ( hasSourceRpm() )
826  {
827 
828  if ( editable() && _pkgObjList->editable() )
829  {
830  icon = installSourceRpm() ?
831  YQIconPool::pkgInstall() :
832  YQIconPool::pkgNoInst();
833  }
834  else
835  {
836  icon = installSourceRpm() ?
837  YQIconPool::disabledPkgInstall() :
838  YQIconPool::disabledPkgNoInst();
839  }
840  }
841  setData( srpmStatusCol(), Qt::DecorationRole, icon );
842 }
843 
844 
845 void
846 YQPkgListItem::setInstallSourceRpm( bool installSourceRpm )
847 {
848  if ( hasSourceRpm() )
849  {
850 #ifdef FIXME
851  if ( selectable() )
852  selectable()->set_source_install( installSourceRpm );
853 #endif
854  }
855 
857 }
858 
859 
860 void
862 {
864 }
865 
866 
867 QString
869 {
870  QString text;
871  QString name = _zyppObj->name().c_str();
872 
873  if ( col == statusCol() )
874  {
875  text = YQPkgObjListItem::toolTip( col );
876  }
877  else if ( col == srpmStatusCol() )
878  {
879  text = name + "\n\n";
880 
881  if ( hasSourceRpm() )
882  {
883  text += installSourceRpm() ?
884  _( "Install Sources" ) :
885  _( "Do Not Install Sources" );
886  }
887  else
888  {
889  text += _( "No Sources Available" );
890  }
891  }
892  else
893  {
894  text = name + "\n\n";
895 
896  QString installed;
897  QString candidate;
898 
899  if ( !selectable()->installedEmpty() )
900  {
901  installed = selectable()->installedObj()->edition().asString().c_str();
902  installed += "-";
903  installed += selectable()->installedObj()->arch().asString().c_str();
904  installed = _( "Installed Version: %1" ).arg( installed );
905  }
906 
907  if ( selectable()->hasCandidateObj() )
908  {
909  candidate = selectable()->candidateObj()->edition().asString().c_str();
910  candidate += "-";
911  candidate += selectable()->candidateObj()->arch().asString().c_str();
912  }
913 
914  if ( !selectable()->installedEmpty() )
915  {
916  text += installed + "\n";
917 
918  if ( selectable()->hasCandidateObj() )
919  {
920  // Translators: This is the relation between two versions of one package
921  // if both versions are the same, e.g., both "1.2.3-42", "1.2.3-42"
922  QString relation = _( "same" );
923 
924  if ( _candidateIsNewer ) relation = _( "newer" );
925  if ( _installedIsNewer ) relation = _( "older" );
926 
927  // Translators: %1 is the version, %2 is one of "newer", "older", "same"
928  text += _( "Available Version: %1 (%2)" ).arg( candidate ).arg( relation );
929  }
930  else
931  {
932  text += _( "Not available for installation" );
933  }
934  }
935  else // not installed
936  {
937  text += candidate;
938  }
939  }
940 
941  return text;
942 }
943 
944 
945 
946 bool YQPkgListItem::operator< ( const QTreeWidgetItem & otherListViewItem ) const
947 {
948  const YQPkgListItem * other = dynamic_cast<const YQPkgListItem *> (&otherListViewItem);
949 
950  int col = treeWidget()->sortColumn();
951  if ( col == srpmStatusCol() )
952  {
953  if ( other )
954  {
955  int thisPoints = ( this->hasSourceRpm() ? 1 : 0 ) + ( this->installSourceRpm() ? 1 : 0 );
956  int otherPoints = ( other->hasSourceRpm() ? 1 : 0 ) + ( other->installSourceRpm() ? 1 : 0 );
957 
958  // Intentionally inverting order: Pkgs with source RPMs are more interesting than without.
959  return ( thisPoints < otherPoints );
960  }
961  }
962 
963  // Fallback: Use parent class method
964  return YQPkgObjListItem::operator<( otherListViewItem );
965 }
966 
967 #if 0
968 void
969 YQPkgListItem::paintCell( QPainter * painter,
970  const QColorGroup & colorGroup,
971  int column,
972  int width,
973  int alignment )
974 {
975 #if FIXME
976  if ( isDimmed() && ! YQUI::ui()->usingVisionImpairedPalette() )
977  {
978  QColorGroup cg = colorGroup;
979  cg.setColor( QColorGroup::Text, QColor( 0xA0, 0xA0, 0xA0 ) );
980 
981  QTreeWidgetItem::paintCell( painter, cg, column, width, alignment );
982  }
983  else
984  {
985  if ( installedIsNewer() )
986  {
987  QColorGroup cg = colorGroup;
988 
989  if ( ! YQUI::ui()->usingVisionImpairedPalette() )
990  {
991  if ( column == instVersionCol() )
992  cg.setColor( QColorGroup::Base, QColor( 0xFF, 0x30, 0x30 ) ); // Background
993  else
994  cg.setColor( QColorGroup::Text, QColor( 0xFF, 0, 0 ) ); // Foreground
995  }
996 
997  QTreeWidgetItem::paintCell( painter, cg, column, width, alignment );
998  }
999  else if ( candidateIsNewer() )
1000  {
1001  QColorGroup cg = colorGroup;
1002 
1003  if ( ! YQUI::ui()->usingVisionImpairedPalette() )
1004  {
1005  cg.setColor( QColorGroup::Text, QColor( 0, 0, 0xC0 ) ); // Foreground
1006 
1007  if ( column == versionCol() )
1008  cg.setColor( QColorGroup::Base, QColor( 0xF0, 0xF0, 0xF0 ) ); // Background
1009  }
1010 
1011  QTreeWidgetItem::paintCell( painter, cg, column, width, alignment );
1012  }
1013  else
1014  {
1015  QTreeWidgetItem::paintCell( painter, colorGroup, column, width, alignment );
1016  }
1017  }
1018 #endif
1019 }
1020 #endif
1021 
1022 
1023 #include "YQPkgList.moc"
ZyppSel selectable() const
Definition: YQPkgObjList.h:466
Abstract base class to display a list of zypp::ResObjects. Handles most generic stuff like setting st...
Definition: YQPkgObjList.h:68
void statusChanged()
void addPkgItem(ZyppSel selectable, ZyppPkg zyppPkg)
Definition: YQPkgList.cc:138
int globalSetPkgStatus(ZyppStatus newStatus, bool force, bool countOnly)
Definition: YQPkgList.cc:675
void toggleSourceRpmStatus()
Definition: YQPkgList.cc:861
virtual QPixmap statusIcon(ZyppStatus status, bool enabled=true, bool bySelection=false)
virtual void createInstalledContextMenu()
Definition: YQPkgList.cc:480
void resetOptimalColumnWidthValues()
Definition: YQPkgList.cc:305
virtual void pkgObjClicked(int button, QTreeWidgetItem *item, int col, const QPoint &pos)
Definition: YQPkgList.cc:193
virtual bool operator<(const QTreeWidgetItem &other) const
Definition: YQPkgList.cc:946
YQPkgListItem(YQPkgList *pkgList, ZyppSel selectable, ZyppPkg zyppPkg)
Definition: YQPkgList.cc:755
virtual void updateActions(YQPkgObjListItem *item)
Definition: YQPkgList.cc:555
static bool haveInstalledPkgs()
Definition: YQPkgList.cc:178
bool isDimmed() const
Definition: YQPkgList.h:351
bool candidateIsNewer() const
Definition: YQPkgObjList.h:526
virtual void updateData()
virtual void clear()
void optimizeColumnWidths()
Definition: YQPkgList.cc:379
void addPkgItemDimmed(ZyppSel selectable, ZyppPkg zyppPkg)
Definition: YQPkgList.cc:145
QAction * createAction(ZyppStatus status, const QString &key=QString::null, bool enabled=false)
virtual void pkgObjClicked(int button, QTreeWidgetItem *item, int col, const QPoint &pos)
virtual void updateActions(YQPkgObjListItem *item=0)
bool editable() const
Definition: YQPkgObjList.h:110
bool hasSourceRpm() const
Definition: YQPkgList.cc:787
void updatePackages()
virtual QSize sizeHint() const
Definition: YQPkgList.cc:230
virtual bool operator<(const QTreeWidgetItem &other) const
Display a list of zypp::Package objects.
Definition: YQPkgList.h:54
virtual void updateData()
Definition: YQPkgList.cc:779
virtual void createNotInstalledContextMenu()
Definition: YQPkgList.cc:461
void setSourceRpmIcon()
Definition: YQPkgList.cc:818
void resort()
Definition: YQPkgList.cc:441
YQPkgList(QWidget *parent)
Definition: YQPkgList.cc:70
void exportList(const QString filename, bool interactive) const
Definition: YQPkgList.cc:586
void clear()
Definition: YQPkgList.cc:432
void setDimmed(bool d=true)
Definition: YQPkgList.h:356
void applyExcludeRules()
virtual QString statusText(ZyppStatus status) const
void askExportList() const
Definition: YQPkgList.cc:575
virtual QString toolTip(int column)
Definition: YQPkgList.cc:868
void updateOptimalColumnWidthValues(ZyppSel selectable, ZyppPkg zyppPkg)
Definition: YQPkgList.cc:317
virtual QMenu * addAllInListSubMenu(QMenu *menu)
Definition: YQPkgList.cc:501
bool installedIsNewer() const
Definition: YQPkgObjList.h:531
void setInstallSourceRpm(bool installSourceRpm)
Definition: YQPkgList.cc:846
void createActions()
Definition: YQPkgList.cc:524
virtual QString toolTip(int column)
void createSourceRpmContextMenu()
Definition: YQPkgList.cc:237
bool installSourceRpm() const
Definition: YQPkgList.cc:801
virtual ZyppStatus status() const
void resizeEvent(QResizeEvent *event)
Definition: YQPkgList.cc:450
virtual ~YQPkgListItem()
Definition: YQPkgList.cc:772
virtual ~YQPkgList()
Definition: YQPkgList.cc:132
bool editable() const
Definition: YQPkgObjList.h:478