42 #define YUILogComponent "qt-pkg" 45 #include <QApplication> 46 #include <QDesktopWidget> 47 #include <QHBoxLayout> 49 #include <QPushButton> 54 #include <QTreeWidget> 55 #include <QMessageBox> 57 #include <zypp/parser/HistoryLogReader.h> 58 #include <zypp/Date.h> 59 #include <zypp/Edition.h> 61 #include <boost/ref.hpp> 63 #include "YQPkgHistoryDialog.h" 64 #include "YQPkgList.h" 65 #include "QY2LayoutUtils.h" 68 #include "YQIconPool.h" 72 #define SPACING 2 // between subwidgets 73 #define MARGIN 4 // around the widget 75 #define FILENAME "/var/log/zypp/history" 83 setWindowTitle( _(
"Package History" ) );
86 setSizeGripEnabled(
true );
90 QVBoxLayout * layout =
new QVBoxLayout();
91 Q_CHECK_PTR( layout );
93 layout->setMargin(MARGIN);
94 layout->setSpacing(SPACING);
96 setMinimumSize (300,400);
98 QLabel * label =
new QLabel ( _(
"Show History (/var/log/zypp/history)" ),
this );
99 label->setFixedHeight (label->sizeHint ().height ());
100 layout->addWidget (label);
103 QSplitter * splitter =
new QSplitter( Qt::Horizontal,
this );
104 Q_CHECK_PTR( splitter );
105 layout->addWidget( splitter );
108 _dates =
new QTreeWidget (splitter);
109 _dates->setColumnCount (1);
110 _dates->setHeaderLabels ( QStringList( _(
"Date") ) );
112 _actions =
new QTreeWidget (splitter);
113 _actions->setColumnCount (2);
114 _actions->setHeaderLabels ( QStringList( _(
"Action") ) << _(
"Version/URL") );
115 _actions->setColumnWidth (0, 200);
117 splitter->setStretchFactor (0, 1);
118 splitter->setStretchFactor (1, 2);
122 QHBoxLayout * hbox =
new QHBoxLayout();
124 hbox->setSpacing( SPACING );
125 hbox->setMargin ( MARGIN );
126 layout->addLayout( hbox );
131 QPushButton * button =
new QPushButton( _(
"&Close" ),
this );
132 Q_CHECK_PTR( button );
133 hbox->addWidget(button);
134 button->setDefault(
true );
136 connect( button, SIGNAL( clicked() ),
137 this, SLOT ( accept() ) );
139 connect( _dates, SIGNAL( itemSelectionChanged () ),
140 this, SLOT ( moveToDate () ) );
142 connect( _actions, SIGNAL( itemSelectionChanged() ),
143 this, SLOT ( moveToAction () ) );
151 QRect available = qApp->desktop()->availableGeometry( (QWidget *)
this );
152 QSize size = QDialog::sizeHint();
153 size = size.boundedTo( QSize( available.width(), available.height() ) );
166 QPixmap actionIcon (zypp::HistoryActionID
id)
168 switch (
id.toEnum ()) {
169 case zypp::HistoryActionID::INSTALL_e :
return YQIconPool::pkgInstall ();
170 case zypp::HistoryActionID::REMOVE_e :
return YQIconPool::pkgDel ();
171 case zypp::HistoryActionID::REPO_REMOVE_e :
return YQIconPool::treeMinus ();
172 case zypp::HistoryActionID::REPO_ADD_e :
return YQIconPool::treePlus ();
173 default:
return QPixmap ();
181 QTreeWidget* actions, * dates;
183 QTreeWidgetItem* date_start;
185 bool operator()(
const zypp::HistoryLogData::Ptr & item_ptr )
187 QString d = fromUTF8( item_ptr->date().form(
"%e %B %Y"));
191 date_start =
new QTreeWidgetItem (actions, QStringList(d));
192 date_start->setExpanded (
true);
193 actions-> insertTopLevelItem ( 0, date_start );
194 dates-> insertTopLevelItem ( 0,
new QTreeWidgetItem (dates, QStringList(d)));
198 if ( item_ptr->action() == zypp::HistoryActionID::INSTALL_e )
200 zypp::HistoryLogDataInstall* item = static_cast <zypp::HistoryLogDataInstall *> (item_ptr.get());
202 columns << fromUTF8(item->name());
203 columns << fromUTF8(item->edition().version());
205 if ( item_ptr->action() == zypp::HistoryActionID::REMOVE_e )
207 zypp::HistoryLogDataRemove* item = static_cast <zypp::HistoryLogDataRemove *> (item_ptr.get());
209 columns << fromUTF8(item->name());
210 columns << fromUTF8(item->edition().version());
212 if ( item_ptr->action() == zypp::HistoryActionID::REPO_ADD_e )
214 zypp::HistoryLogDataRepoAdd* item = static_cast <zypp::HistoryLogDataRepoAdd *> (item_ptr.get());
216 columns << fromUTF8(item->alias());
217 columns << fromUTF8(item->url().asString());
219 if ( item_ptr->action() == zypp::HistoryActionID::REPO_REMOVE_e )
221 zypp::HistoryLogDataRepoRemove* item = static_cast <zypp::HistoryLogDataRepoRemove *> (item_ptr.get());
223 columns << fromUTF8(item->alias());
225 if ( item_ptr->action() == zypp::HistoryActionID::REPO_CHANGE_ALIAS_e )
227 zypp::HistoryLogDataRepoAliasChange* item = static_cast <zypp::HistoryLogDataRepoAliasChange *> (item_ptr.get());
229 columns << fromUTF8(item->oldAlias()) +
" -> " + fromUTF8(item->newAlias());
231 if ( item_ptr->action() == zypp::HistoryActionID::REPO_CHANGE_URL_e )
233 zypp::HistoryLogDataRepoUrlChange* item = static_cast <zypp::HistoryLogDataRepoUrlChange *> (item_ptr.get());
235 columns << fromUTF8(item->alias());
236 columns << fromUTF8(item->newUrl().asString());
239 QTreeWidgetItem *action =
new QTreeWidgetItem (date_start, columns);
240 action->setIcon (0,actionIcon (item_ptr->action()) );
247 YQPkgHistoryDialog::initialize()
251 ic.actions = _actions;
253 zypp::parser::HistoryLogReader reader(FILENAME, zypp::parser::HistoryLogReader::Options(), boost::ref(ic));
259 catch (
const zypp::Exception & exception)
261 yuiWarning() <<
"CAUGHT zypp exception: " << exception.asUserHistory() << endl;
268 QString heading = _(
"Unable to read history" );
270 if ( heading.length() < 25 )
273 blanks.fill(
' ', 50 - heading.length() );
277 msgBox.setText( heading );
278 msgBox.setIcon( QMessageBox::Warning );
279 msgBox.setInformativeText( fromUTF8( exception.asUserHistory() ) );
286 YQPkgHistoryDialog::moveToDate ()
288 if (signalsBlocked() )
return;
289 QString item = _dates->selectedItems().first()->text(0);
290 QList<QTreeWidgetItem *> items = _actions->findItems (item, Qt::MatchExactly, 0);
292 if( items.size () > 0 )
295 _actions->expandItem (items.first());
296 _actions->setCurrentItem (items.first());
297 _actions->scrollToItem( items.first(), QAbstractItemView::PositionAtTop );
303 YQPkgHistoryDialog::moveToAction ()
305 if (signalsBlocked() )
return;
306 QTreeWidgetItem* item = _actions->selectedItems().first();
310 item = item->parent ();
312 QList<QTreeWidgetItem *> items = _dates->findItems (item->text(0), Qt::MatchExactly | Qt::MatchRecursive, 0);
314 if( items.size () > 0 )
317 _dates->setCurrentItem (items.first());
Pkg status and History as a standalone popup dialog.
virtual QSize sizeHint() const
Returns the preferred size.
static void showHistoryDialog(QWidget *parent=0)
Static convenience method: Post a History dialog for pkg 'pkgName'.
YQPkgHistoryDialog(QWidget *parent)
Constructor: Creates a History dialog for all packages that match 'pkgName'.