47 #define YUILogComponent "qt-pkg" 52 #include <QMessageBox> 56 #include <QHeaderView> 57 #include <QFontMetrics> 61 #include "YQPkgList.h" 64 #include "YQIconPool.h" 65 #include "YQApplication.h" 67 #define SINGLE_VERSION_COL 1 68 #define STATUS_ICON_SIZE 16 69 #define STATUS_COL_WIDTH 28 81 QString versionHeaderText;
82 QString instVersionHeaderText;
85 headers <<
""; _statusCol = numCol++;
86 headers << _(
"Package" ); _nameCol = numCol++;
87 headers << _(
"Summary" ); _summaryCol = numCol++;
91 #if SINGLE_VERSION_COL 92 versionHeaderText = _(
"Installed (Available)");
93 headers << versionHeaderText; _instVersionCol = numCol++;
94 _versionCol = _instVersionCol;
96 versionHeaderText = _(
"Avail. Ver." );
97 headers << versionHeaderText; _versionCol = numCol++;
99 instVersionHeaderText = _(
"Inst. Ver." );
100 headers << instVersionHeaderText; _instVersionCol = numCol++;
105 versionHeaderText = _(
"Version" );
106 headers << versionHeaderText; _versionCol = numCol++;
110 headers << _(
"Size" ); _sizeCol = numCol++;
112 setHeaderLabels( headers );
114 header()->setSortIndicatorShown(
true );
115 header()->setSectionsClickable(
true );
117 sortByColumn( statusCol(), Qt::AscendingOrder );
118 setAllColumnsShowFocus(
true );
119 setIconSize( QSize( STATUS_ICON_SIZE, STATUS_ICON_SIZE ) );
121 header()->setSectionResizeMode( QHeaderView::Interactive );
128 connect ( header(), SIGNAL( sectionClicked (
int) ),
129 this, SLOT( sortByColumn (
int) ) );
160 scheduleDelayedItemsLayout();
164 yuiError() <<
"NULL zypp::ui::Selectable!" << std::endl;
182 for ( ZyppPoolIterator it = zyppPkgBegin();
186 if ( (*it)->installedObj() )
196 QTreeWidgetItem * listViewItem,
200 if ( col == srpmStatusCol() )
206 if ( button == Qt::LeftButton )
212 else if ( button == Qt::RightButton )
218 if ( _sourceRpmContextMenu )
219 _sourceRpmContextMenu->popup( pos );
234 return QSize( 600, 350 );
241 _sourceRpmContextMenu =
new QMenu(
this );
243 _sourceRpmContextMenu->addAction(actionInstallSourceRpm);
244 _sourceRpmContextMenu->addAction(actionDontInstallSourceRpm);
246 QMenu * submenu =
new QMenu( _sourceRpmContextMenu );
247 Q_CHECK_PTR( submenu );
248 QAction *action = _sourceRpmContextMenu->addMenu( submenu );
249 action->setText(_(
"&All in This List" ));
251 submenu->addAction(actionInstallListSourceRpms);
252 submenu->addAction(actionDontInstallListSourceRpms);
257 YQPkgList::setInstallCurrentSourceRpm(
bool installSourceRpm,
258 bool selectNextItem )
261 QTreeWidgetItem * listViewItem = selectedItem();
263 if ( ! listViewItem )
274 item->setSelected(
false );
275 setSelected( item->nextSibling(), true );
283 YQPkgList::setInstallListSourceRpms(
bool installSourceRpm )
289 QTreeWidgetItem * listViewItem = firstChild();
291 while ( listViewItem )
300 listViewItem = listViewItem->nextSibling();
309 _optimalColWidth_statusIcon = 0;
310 _optimalColWidth_name = 0;
311 _optimalColWidth_summary = 0;
312 _optimalColWidth_version = 0;
313 _optimalColWidth_instVersion = 0;
314 _optimalColWidth_size = 0;
323 QFontMetrics fm( this->font() );
324 const ZyppObj candidate = selectable->candidateObj();
325 const ZyppObj installed = selectable->installedObj();
327 _optimalColWidth_statusIcon = STATUS_COL_WIDTH;
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;
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;
339 if ( instVersionCol() == versionCol() )
342 qstr = QString::fromUtf8( installed->edition().c_str() );
345 if (candidate && (!installed || (candidate->edition() != installed->edition())))
349 qstr +=
"(" + QString::fromUtf8( candidate->edition().c_str() ) +
")";
351 qstr_width = fm.boundingRect( qstr ).width() + ( STATUS_ICON_SIZE / 2 );
352 if (qstr_width > _optimalColWidth_version)
353 _optimalColWidth_version = qstr_width;
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;
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;
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;
383 int visibleSpace = 0;
384 int optimalWidthsSum = 0;
386 int statusIconColWidth = _optimalColWidth_statusIcon;
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() )
393 optimalWidthsSum += _optimalColWidth_instVersion;
397 visibleSpace = this->viewport()->width();
398 if (visibleSpace < 0)
return;
399 if (optimalWidthsSum >= visibleSpace)
403 int reducedSummaryWidth = visibleSpace - optimalWidthsSum + _optimalColWidth_summary;
404 if (reducedSummaryWidth < 100)
405 reducedSummaryWidth = 100;
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);
419 int addSpace = (visibleSpace - optimalWidthsSum) / numOptCol;
420 int addSpaceR = (visibleSpace - optimalWidthsSum) % numOptCol;
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 );
445 int col = sortColumn();
446 Qt::SortOrder order = header()->sortIndicatorOrder();
447 sortByColumn(col, order);
454 if (event->size().width() !=
event->oldSize().width())
465 _notInstalledContextMenu =
new QMenu(
this );
466 Q_CHECK_PTR( _notInstalledContextMenu );
468 _notInstalledContextMenu->addAction(actionSetCurrentInstall);
469 _notInstalledContextMenu->addAction(actionSetCurrentDontInstall);
470 _notInstalledContextMenu->addAction(actionSetCurrentTaboo);
474 _notInstalledContextMenu->addSeparator();
475 _notInstalledContextMenu->addAction( _(
"Export This List to &Text File..." ),
483 _installedContextMenu =
new QMenu(
this );
484 Q_CHECK_PTR( _installedContextMenu );
486 _installedContextMenu->addAction(actionSetCurrentKeepInstalled);
487 _installedContextMenu->addAction(actionSetCurrentDelete);
488 _installedContextMenu->addAction(actionSetCurrentUpdate);
489 _installedContextMenu->addAction(actionSetCurrentUpdateForce);
490 _installedContextMenu->addAction(actionSetCurrentProtected);
494 _installedContextMenu->addSeparator();
495 _installedContextMenu->addAction( _(
"Export This List to &Text File..." ),
503 QMenu * submenu =
new QMenu( menu );
504 Q_CHECK_PTR( submenu );
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);
516 QAction *action = menu->addMenu( submenu );
517 action->setText(_(
"&All in This List" ));
526 actionInstallSourceRpm =
createAction( _(
"&Install Source" ),
530 actionDontInstallSourceRpm =
createAction( _(
"Do &Not Install Source" ),
534 actionInstallListSourceRpms =
createAction( _(
"&Install All Available Sources" ),
540 actionDontInstallListSourceRpms =
createAction( _(
"Do &Not Install Any Sources" ),
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 );
566 actionInstallSourceRpm->setEnabled( item->
hasSourceRpm() );
567 actionDontInstallSourceRpm->setEnabled( item->
hasSourceRpm() );
571 actionInstallSourceRpm->setEnabled(
false );
572 actionDontInstallSourceRpm->setEnabled(
false );
580 QString filename = YQApplication::askForSaveFileName(
"pkglist.txt",
582 _(
"Export Package List" ) );
583 if ( ! filename.isEmpty() )
593 QFile file(filename);
594 file.open(QIODevice::WriteOnly);
596 if ( file.error() != QFile::NoError )
598 yuiError() <<
"Can't open file " << filename << std::endl;
604 QMessageBox::warning( 0,
606 _(
"Cannot open file %1" ).arg( filename ),
607 QMessageBox::Ok | QMessageBox::Default,
608 QMessageBox::NoButton,
609 QMessageBox::NoButton );
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()
631 file.write(header.toUtf8());
636 QTreeWidgetItemIterator it((QTreeWidget*)
this);
640 const QTreeWidgetItem* item(*it);
645 QString version = pkg->text( versionCol() );
646 if ( version.isEmpty() ) version =
"---";
648 QString summary = pkg->text( summaryCol() );
649 if ( summary.isEmpty() ) summary =
"---";
650 if ( summary.size() > 40 )
652 summary.truncate(40-3);
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()
665 file.write(format.toUtf8());
680 YQUI::ui()->busyCursor();
681 int changedCount = 0;
683 for ( ZyppPoolIterator it = zyppPkgBegin();
687 ZyppSel selectable = *it;
688 ZyppStatus oldStatus = selectable->status();
690 if ( newStatus != oldStatus )
692 bool doChange =
false;
696 case S_KeepInstalled:
700 doChange = !selectable->installedEmpty();
708 doChange = !selectable->installedEmpty();
712 const ZyppObj candidate = selectable->candidateObj();
713 const ZyppObj installed = selectable->installedObj();
715 if ( candidate && installed )
717 doChange = ( installed->edition() < candidate->edition() );
726 doChange = selectable->installedEmpty();
732 if ( ! countOnly && oldStatus != S_Protected )
733 selectable->setStatus( newStatus );
741 if ( changedCount > 0 && ! countOnly )
743 emit updateItemStates();
748 YQUI::ui()->normalCursor();
762 , _pkgList( pkgList )
763 , _zyppPkg( zyppPkg )
767 _zyppPkg = tryCastToZyppPkg(
selectable->theObj() );
771 setTextAlignment( sizeCol(), Qt::AlignRight );
823 if ( srpmStatusCol() < 0 )
834 YQIconPool::pkgInstall() :
835 YQIconPool::pkgNoInst();
840 YQIconPool::disabledPkgInstall() :
841 YQIconPool::disabledPkgNoInst();
844 setData( srpmStatusCol(), Qt::DecorationRole, icon );
874 QString name = _zyppObj->name().c_str();
876 if ( col == statusCol() )
880 else if ( col == srpmStatusCol() )
882 text = name +
"\n\n";
887 _(
"Install Sources" ) :
888 _(
"Do Not Install Sources" );
892 text += _(
"No Sources Available" );
897 text = name +
"\n\n";
904 installed =
selectable()->installedObj()->edition().asString().c_str();
906 installed +=
selectable()->installedObj()->arch().asString().c_str();
907 installed = _(
"Installed Version: %1" ).arg( installed );
912 candidate =
selectable()->candidateObj()->edition().asString().c_str();
914 candidate +=
selectable()->candidateObj()->arch().asString().c_str();
919 text += installed +
"\n";
925 QString relation = _(
"same" );
927 if ( _candidateIsNewer ) relation = _(
"newer" );
928 if ( _installedIsNewer ) relation = _(
"older" );
931 text += _(
"Available Version: %1 (%2)" ).arg( candidate ).arg( relation );
935 text += _(
"Not available for installation" );
953 int col = treeWidget()->sortColumn();
954 if ( col == srpmStatusCol() )
962 return ( thisPoints < otherPoints );
void exportList(const QString filename, bool interactive) const
Save the pkg list to a file.
Abstract base class to display a list of zypp::ResObjects.
void statusChanged()
Emitted when the status of a zypp::ResObject is changed.
void addPkgItem(ZyppSel selectable, ZyppPkg zyppPkg)
Add a pkg to the list.
int globalSetPkgStatus(ZyppStatus newStatus, bool force, bool countOnly)
Set the status of all packages in the pool to a new value.
void toggleSourceRpmStatus()
Cycle the source package status to the next valid value.
virtual QSize sizeHint() const
Reimplemented from QListView / QWidget: Reserve a reasonable amount of space.
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.
virtual bool operator<(const QTreeWidgetItem &other) const
sorting function
void resetOptimalColumnWidthValues()
Resets the optimal column width values.
virtual void pkgObjClicked(int button, QTreeWidgetItem *item, int col, const QPoint &pos)
Dispatcher slot for mouse click: Take care of source RPM status.
YQPkgListItem(YQPkgList *pkgList, ZyppSel selectable, ZyppPkg zyppPkg)
Constructor.
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 'item'?
static bool haveInstalledPkgs()
Returns 'true' if there are any installed packages.
bool hasSourceRpm() const
Returns whether or not a source RPM is available for this package.
virtual void updateData()
Update this item's data completely.
virtual bool operator<(const QTreeWidgetItem &other) const
sorting function
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.
void addPkgItemDimmed(ZyppSel selectable, ZyppPkg zyppPkg)
Add a pkg to the list, but display it dimmed (grey text foreground rather than normal black)...
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.
bool editable() const
Return whether or not this items is editable, i.e.
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's time to update displayed package information, e.g., package states.
Display a list of zypp::Package objects.
virtual void updateData()
Update this item's data completely.
virtual ZyppStatus status() const
Returns the (binary RPM) package status.
virtual void createNotInstalledContextMenu()
Create the context menu for items that are not installed.
void setSourceRpmIcon()
Set the suitable icon for the source RPM status.
void resort()
Sort the tree widget again according to the column selected and its current sort order.
YQPkgList(QWidget *parent)
Constructor.
bool editable() const
Return whether or not items in this list are generally editable, i.e.
void clear()
Clears the tree-widgets content, resets the optimal column width values.
void setDimmed(bool d=true)
Set the 'dimmed' flag.
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?
ZyppSel selectable() const
Returns the original selectable within the package manager backend.
virtual QString toolTip(int column)
Returns a tool tip text for a specific column of this item.
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...
virtual QMenu * addAllInListSubMenu(QMenu *menu)
Add a submenu "All in this list..." to 'menu'.
void setInstallSourceRpm(bool installSourceRpm)
Set the source RPM status.
void createActions()
Create ( additional ) actions for the context menus.
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.
void askExportList() const
Ask for a file name and save the current pkg list to file.
void resizeEvent(QResizeEvent *event)
Handler for resize events.
virtual ~YQPkgListItem()
Destructor.
virtual ~YQPkgList()
Destructor.