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 79 QString versionHeaderText;
80 QString instVersionHeaderText;
83 headers <<
""; _statusCol = numCol++;
84 headers << _(
"Package" ); _nameCol = numCol++;
85 headers << _(
"Summary" ); _summaryCol = numCol++;
89 #if SINGLE_VERSION_COL 90 versionHeaderText = _(
"Installed (Available)");
91 headers << versionHeaderText; _instVersionCol = numCol++;
92 _versionCol = _instVersionCol;
94 versionHeaderText = _(
"Avail. Ver." );
95 headers << versionHeaderText; _versionCol = numCol++;
97 instVersionHeaderText = _(
"Inst. Ver." );
98 headers << instVersionHeaderText; _instVersionCol = numCol++;
103 versionHeaderText = _(
"Version" );
104 headers << versionHeaderText; _versionCol = numCol++;
108 headers << _(
"Size" ); _sizeCol = numCol++;
110 setHeaderLabels( headers );
112 header()->setSortIndicatorShown(
true );
113 header()->setSectionsClickable(
true );
115 sortByColumn( statusCol(), Qt::AscendingOrder );
116 setAllColumnsShowFocus(
true );
117 setIconSize( QSize( 22, 16 ) );
119 header()->setSectionResizeMode( QHeaderView::Interactive );
126 connect ( header(), SIGNAL( sectionClicked (
int) ),
127 this, SLOT( sortByColumn (
int) ) );
158 scheduleDelayedItemsLayout();
162 yuiError() <<
"NULL zypp::ui::Selectable!" << std::endl;
180 for ( ZyppPoolIterator it = zyppPkgBegin();
184 if ( (*it)->installedObj() )
194 QTreeWidgetItem * listViewItem,
198 if ( col == srpmStatusCol() )
204 if ( button == Qt::LeftButton )
210 else if ( button == Qt::RightButton )
216 if ( _sourceRpmContextMenu )
217 _sourceRpmContextMenu->popup( pos );
232 return QSize( 600, 350 );
239 _sourceRpmContextMenu =
new QMenu(
this );
241 _sourceRpmContextMenu->addAction(actionInstallSourceRpm);
242 _sourceRpmContextMenu->addAction(actionDontInstallSourceRpm);
244 QMenu * submenu =
new QMenu( _sourceRpmContextMenu );
245 Q_CHECK_PTR( submenu );
246 QAction *action = _sourceRpmContextMenu->addMenu( submenu );
247 action->setText(_(
"&All in This List" ));
249 submenu->addAction(actionInstallListSourceRpms);
250 submenu->addAction(actionDontInstallListSourceRpms);
255 YQPkgList::setInstallCurrentSourceRpm(
bool installSourceRpm,
256 bool selectNextItem )
259 QTreeWidgetItem * listViewItem = selectedItem();
261 if ( ! listViewItem )
272 item->setSelected(
false );
273 setSelected( item->nextSibling(), true );
281 YQPkgList::setInstallListSourceRpms(
bool installSourceRpm )
287 QTreeWidgetItem * listViewItem = firstChild();
289 while ( listViewItem )
298 listViewItem = listViewItem->nextSibling();
307 _optimalColWidth_statusIcon = 0;
308 _optimalColWidth_name = 0;
309 _optimalColWidth_summary = 0;
310 _optimalColWidth_version = 0;
311 _optimalColWidth_instVersion = 0;
312 _optimalColWidth_size = 0;
321 QFontMetrics fm( this->font() );
322 const ZyppObj candidate = selectable->candidateObj();
323 const ZyppObj installed = selectable->installedObj();
325 _optimalColWidth_statusIcon = 28;
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;
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;
337 if ( instVersionCol() == versionCol() )
340 qstr = QString::fromUtf8( installed->edition().c_str() );
343 if (candidate && (!installed || (candidate->edition() != installed->edition())))
347 qstr +=
"(" + QString::fromUtf8( candidate->edition().c_str() ) +
")";
349 qstr_width = fm.boundingRect( qstr ).width() + 8;
350 if (qstr_width > _optimalColWidth_version)
351 _optimalColWidth_version = qstr_width;
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;
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;
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;
381 int visibleSpace = 0;
382 int optimalWidthsSum = 0;
384 int statusIconColWidth = _optimalColWidth_statusIcon;
386 if (statusIconColWidth == 0)
387 statusIconColWidth = 28;
388 optimalWidthsSum = _optimalColWidth_statusIcon + _optimalColWidth_name + _optimalColWidth_summary + _optimalColWidth_version + _optimalColWidth_size;
389 if ( instVersionCol() != versionCol() )
391 optimalWidthsSum += _optimalColWidth_instVersion;
395 visibleSpace = this->viewport()->width();
396 if (visibleSpace < 0)
return;
397 if (optimalWidthsSum >= visibleSpace)
401 int reducedSummaryWidth = visibleSpace - optimalWidthsSum + _optimalColWidth_summary;
402 if (reducedSummaryWidth < 100)
403 reducedSummaryWidth = 100;
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);
417 int addSpace = (visibleSpace - optimalWidthsSum) / numOptCol;
418 int addSpaceR = (visibleSpace - optimalWidthsSum) % numOptCol;
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 );
443 int col = sortColumn();
444 Qt::SortOrder order = header()->sortIndicatorOrder();
445 sortByColumn(col, order);
452 if (event->size().width() !=
event->oldSize().width())
463 _notInstalledContextMenu =
new QMenu(
this );
464 Q_CHECK_PTR( _notInstalledContextMenu );
466 _notInstalledContextMenu->addAction(actionSetCurrentInstall);
467 _notInstalledContextMenu->addAction(actionSetCurrentDontInstall);
468 _notInstalledContextMenu->addAction(actionSetCurrentTaboo);
469 _notInstalledContextMenu->addAction(actionShowCurrentSolverInfo);
473 _notInstalledContextMenu->addSeparator();
474 _notInstalledContextMenu->addAction( _(
"Export This List to &Text File..." ),
482 _installedContextMenu =
new QMenu(
this );
483 Q_CHECK_PTR( _installedContextMenu );
485 _installedContextMenu->addAction(actionSetCurrentKeepInstalled);
486 _installedContextMenu->addAction(actionSetCurrentDelete);
487 _installedContextMenu->addAction(actionSetCurrentUpdate);
488 _installedContextMenu->addAction(actionSetCurrentUpdateForce);
489 _installedContextMenu->addAction(actionSetCurrentProtected);
490 _installedContextMenu->addAction(actionShowCurrentSolverInfo);
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 );
970 #include "YQPkgList.moc" 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.