libyui-qt-pkg  2.42.5
 All Classes Functions Variables Enumerations
YQPkgChangesDialog.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: YQPkgChangesDialog.cc
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38  Textdomain "qt-pkg"
39 
40 /-*/
41 
42 #define YUILogComponent "qt-pkg"
43 #include "YUILog.h"
44 
45 #include <QApplication>
46 #include <QDesktopWidget>
47 #include <QLabel>
48 #include <QLayout>
49 #include <QPushButton>
50 #include <QStyle>
51 #include <QBoxLayout>
52 
53 #include "YQZypp.h"
54 #include <zypp/ResStatus.h>
55 #include <zypp/VendorSupportOptions.h>
56 #include <zypp/ui/UserWantedPackages.h>
57 
58 #include "YQPkgChangesDialog.h"
59 #include "YQPkgList.h"
60 #include "QY2LayoutUtils.h"
61 #include "YQi18n.h"
62 #include "YQUI.h"
63 
64 using std::set;
65 using std::endl;
66 using std::string;
67 
69  const QString & message,
70  const QString & acceptButtonLabel,
71  const QString & rejectButtonLabel )
72  : QDialog( parent )
73  , _filter(0)
74 {
75  // Dialog title
76  setWindowTitle( _( "Changed Packages" ) );
77 
78  // Enable dialog resizing even without window manager
79  setSizeGripEnabled( true );
80 
81  // Limit dialog size to available screen size
82  setMaximumSize( qApp->desktop()->availableGeometry().size() );
83 
84  // Layout for the dialog ( can't simply insert a QVBox )
85 
86  QVBoxLayout * layout = new QVBoxLayout();
87  Q_CHECK_PTR( layout );
88  setLayout(layout);
89 
90  QHBoxLayout * hbox = new QHBoxLayout();
91  Q_CHECK_PTR( hbox );
92  layout->addLayout( hbox );
93 
94 
95  // Icon
96 
97  QLabel * iconLabel = new QLabel( this );
98  Q_CHECK_PTR( iconLabel );
99  hbox->addWidget(iconLabel);
100 #ifdef FIXME
101  iconLabel->setPixmap( QApplication::style().stylePixmap( QStyle::SP_MessageBoxInformation ) );
102 #endif
103  iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); // hor/vert
104 
105  // Label for the message
106  QLabel * label = new QLabel( message, this );
107  Q_CHECK_PTR( label );
108  hbox->addWidget(label);
109  label->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); // hor/vert
110 
111  _filter = new QComboBox(this);
112 
113  // add the items.
114  _filter->addItem(_("All"), QVariant::fromValue(Filters(FilterAll)));
115  _filter->addItem(_("Selected by the user"), QVariant::fromValue(Filters(FilterUser)));
116  _filter->addItem(_("Automatic Changes"), QVariant::fromValue(Filters(FilterAutomatic)));
117 
118  _filter->setCurrentIndex(0);
119 
120  layout->addWidget(_filter);
121  connect( _filter, SIGNAL(currentIndexChanged(int)),
122  SLOT(slotFilterChanged(int)));
123 
124  // Pkg list
125 
126  _pkgList = new YQPkgList( this );
127  Q_CHECK_PTR( _pkgList );
128  _pkgList->setEditable( false );
129 
130  layout->addWidget( _pkgList );
131 
132 
133  // Button box
134 
135  hbox = new QHBoxLayout();
136  Q_CHECK_PTR( hbox );
137  layout->addLayout( hbox );
138 
139  hbox->addStretch();
140 
141  // Accept button - usually "OK" or "Continue"
142  QPushButton * button = new QPushButton( acceptButtonLabel, this );
143  Q_CHECK_PTR( button );
144  hbox->addWidget( button );
145  button->setDefault( true );
146 
147  connect( button, SIGNAL( clicked() ),
148  this, SLOT ( accept() ) );
149 
150  hbox->addStretch();
151 
152  if ( ! rejectButtonLabel.isEmpty() )
153  {
154  // Reject button ( if desired ) - usually "Cancel"
155 
156  button = new QPushButton( rejectButtonLabel, this );
157  Q_CHECK_PTR( button );
158  hbox->addWidget(button);
159  connect( button, SIGNAL( clicked() ),
160  this, SLOT ( reject() ) );
161 
162  hbox->addStretch();
163  }
164 }
165 
166 void
168 {
169  filter( QRegExp( "" ), f );
170 }
171 
172 void
174 {
175  yuiMilestone() << "filter index changed to: " << index << endl;
176  QVariant v = _filter->itemData(index);
177 
178  if ( v.isValid() && v.canConvert<Filters>() )
179  {
180  Filters f = v.value<Filters>();
181  filter(f);
182  }
183  else
184  {
185  yuiError() << "Can't find filter for index " << index << endl;
186  }
187 
188 }
189 
190 void
192 {
193  setFilter(QRegExp(""), f);
194 }
195 
196 void
197 YQPkgChangesDialog::setFilter( const QRegExp &regexp, Filters f )
198 {
199  yuiMilestone() << "filter changed to: " << f << endl;
200 
201  int index = -1;
202  for ( int k = 0; k < _filter->count(); ++k )
203  {
204  QVariant v = _filter->itemData(k);
205  if ( v.isValid() && v.canConvert<Filters>() )
206  {
207 
208  Filters setf = v.value<Filters>();
209  if ( setf == f )
210  index = k;
211  }
212  }
213 
214  if ( index != -1 )
215  {
216  // so we dont get called again
217  _filter->blockSignals(true);
218  // try to set the widget
219  _filter->setCurrentIndex(f);
220  _filter->blockSignals(false);
221  filter(regexp, f);
222  }
223  else
224  {
225  yuiError() << "Can't find index for filter " << f << endl;
226  }
227 }
228 
229 
230 void
231 YQPkgChangesDialog::filter( const QRegExp & regexp, Filters f )
232 {
233  YQUI::ui()->busyCursor();
234  _pkgList->clear();
235 
236  bool byAuto = f.testFlag(FilterAutomatic);
237  bool byUser = f.testFlag(FilterUser);
238  bool byApp = f.testFlag(FilterUser);
239 
240  int discard_regex = 0;
241  int discard_ignored = 0;
242  int discard_extra = 0;
243  int discard_notmodified = 0;
244  int discard_whomodified = 0;
245 
246  set<string> ignoredNames;
247 
248  if ( ! byUser || ! byApp )
249  ignoredNames = zypp::ui::userWantedPackageNames();
250 
251  for ( ZyppPoolIterator it = zyppPkgBegin();
252  it != zyppPkgEnd();
253  ++it )
254  {
255  ZyppSel selectable = *it;
256 
257  if ( selectable->toModify() )
258  {
259  zypp::ResStatus::TransactByValue modifiedBy = selectable->modifiedBy();
260 
261  if ( ( ( modifiedBy == zypp::ResStatus::SOLVER ) && byAuto ) ||
262  ( ( modifiedBy == zypp::ResStatus::APPL_LOW ||
263  modifiedBy == zypp::ResStatus::APPL_HIGH ) && byApp ) ||
264  ( ( modifiedBy == zypp::ResStatus::USER ) && byUser ) )
265  {
266  if ( regexp.isEmpty()
267  || regexp.indexIn( selectable->name().c_str() ) >= 0 )
268  {
269  if ( ! contains( ignoredNames, selectable->name() ) )
270  {
271  ZyppPkg pkg = tryCastToZyppPkg( selectable->theObj() );
272  if ( extraFilter( selectable, pkg ) )
273  _pkgList->addPkgItem( selectable, pkg );
274  else
275  discard_extra++;
276  }
277  else
278  { discard_ignored++; }
279  }
280  else
281  { discard_regex++; }
282  }
283  else
284  { discard_whomodified++; }
285 
286  }
287  else
288  { discard_notmodified++; }
289 
290  }
291 
292  yuiMilestone() << "Filter result summary: " << endl;
293  yuiMilestone() << "Discarded by extra filter: " << discard_extra << endl;
294  yuiMilestone() << "Discarded by ignored: " << discard_ignored << endl;
295  yuiMilestone() << "Discarded by regex: " << discard_regex << endl;
296  yuiMilestone() << "Discarded because not modified: " << discard_notmodified << endl;
297  yuiMilestone() << "Discarded by who modified: " << discard_whomodified << endl;
298  YQUI::ui()->normalCursor();
299 }
300 
301 bool
302 YQPkgChangesDialog::extraFilter( ZyppSel sel, ZyppPkg pkg )
303 {
304  return true;
305 }
306 
307 bool
309 {
310  return _pkgList->topLevelItemCount() == 0;
311 }
312 
313 
314 QSize
316 {
317  return limitToScreenSize( this, QDialog::sizeHint() );
318 }
319 
320 
321 bool
323  const QString & message,
324  const QString & acceptButtonLabel,
325  const QString & rejectButtonLabel,
326  Filters f,
327  Options o )
328 {
329  YQPkgChangesDialog dialog( parent,
330  message,
331  acceptButtonLabel,
332  rejectButtonLabel );
333 
334  dialog.setFilter(f);
335 
336  if ( dialog.isEmpty() && o.testFlag(OptionAutoAcceptIfEmpty) )
337  {
338  yuiMilestone() << "No items to show in changes dialog, accepting it automatically" << endl;
339  return true;
340  }
341 
342 
343  dialog.exec();
344 
345  return dialog.result() == QDialog::Accepted;
346 }
347 
348 
349 bool
351  const QString & message,
352  const QRegExp & regexp,
353  const QString & acceptButtonLabel,
354  const QString & rejectButtonLabel,
355  Filters f,
356  Options o )
357 {
358  YQPkgChangesDialog dialog( parent,
359  message,
360  acceptButtonLabel,
361  rejectButtonLabel );
362  dialog.setFilter(regexp,f);
363 
364  if ( dialog.isEmpty() && o.testFlag(OptionAutoAcceptIfEmpty) )
365  {
366  yuiMilestone() << "No items to show in dialog, accepting it automatically" << endl;
367  return true;
368  }
369 
370  dialog.exec();
371 
372  return dialog.result() == QDialog::Accepted;
373 }
374 
376  const QString & message,
377  const QString & acceptButtonLabel,
378  const QString & rejectButtonLabel )
379  : YQPkgChangesDialog( parent, message, acceptButtonLabel, rejectButtonLabel )
380 {
381 }
382 
383 bool YQPkgUnsupportedPackagesDialog::extraFilter( ZyppSel sel, ZyppPkg pkg )
384 {
385  if (!pkg || !sel)
386  return false;
387 
388  yuiDebug() << "UNSUPPORTED PKG: " << pkg << endl;
389  return pkg->maybeUnsupported() && sel->toInstall();
390 }
391 
392 bool
394  const QString & message,
395  const QString & acceptButtonLabel,
396  const QString & rejectButtonLabel,
397  Filters f,
398  Options o )
399 {
400  YQPkgUnsupportedPackagesDialog dialog( parent,
401  message,
402  acceptButtonLabel,
403  rejectButtonLabel );
404 
405  dialog.setFilter(f);
406 
407  if ( dialog.isEmpty() && o.testFlag(OptionAutoAcceptIfEmpty) )
408  {
409  yuiMilestone() << "No items to show in unsupported packages dialog, accepting it automatically" << endl;
410  return true;
411  }
412 
413  dialog.exec();
414 
415  return dialog.result() == QDialog::Accepted;
416 }
417 
418 
419 #include "YQPkgChangesDialog.moc"