]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgChangesDialog.cc
8be0e0ea122cf128545f7fd82d5e3cfa0a86b263
[duncan/yast2-qt4.git] / src / pkg / YQPkgChangesDialog.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgChangesDialog.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17   Textdomain "packages-qt"
18
19 /-*/
20
21 #define QT3_SUPPORT 1
22
23 #define y2log_component "qt-pkg"
24 #include <ycp/y2log.h>
25
26 #include <qapplication.h>
27 #include <qdesktopwidget.h>
28 #include <q3hbox.h>
29 #include <qlabel.h>
30 #include <qlayout.h>
31 #include <qpushbutton.h>
32 #include <qstyle.h>
33 //Added by qt3to4:
34 #include <q3boxlayout.h>
35
36 #include "YQZypp.h"
37 #include <zypp/ResStatus.h>
38 #include <zypp/ui/UserWantedPackages.h>
39
40 #include "YQPkgChangesDialog.h"
41 #include "YQPkgList.h"
42 #include "QY2LayoutUtils.h"
43 #include "YQi18n.h"
44 #include "YQUI.h"
45
46 using std::set;
47 using std::string;
48
49
50 #define SPACING                 2       // between subwidgets
51 #define MARGIN                  4       // around the widget
52
53
54 YQPkgChangesDialog::YQPkgChangesDialog( QWidget *               parent,
55                                         const QString &         message,
56                                         const QString &         acceptButtonLabel,
57                                         const QString &         rejectButtonLabel )
58     : QDialog( parent )
59 {
60     // Dialog title
61     setCaption( _( "Changed Packages" ) );
62
63     // Enable dialog resizing even without window manager
64     setSizeGripEnabled( true );
65
66     // Limit dialog size to available screen size
67     setMaximumSize( qApp->desktop()->availableGeometry().size() );
68
69     // Layout for the dialog ( can't simply insert a QVBox )
70
71     Q3VBoxLayout * layout = new Q3VBoxLayout( this, MARGIN, SPACING );
72     Q_CHECK_PTR( layout );
73
74
75     // HBox for icon and message
76
77     Q3HBox * hbox = new Q3HBox( this );
78     Q_CHECK_PTR( hbox );
79     layout->addWidget( hbox );
80
81
82     // Icon
83
84     addHSpacing( hbox );
85     QLabel * iconLabel = new QLabel( hbox );
86     Q_CHECK_PTR( iconLabel );
87 #ifdef FIXME
88     iconLabel->setPixmap( QApplication::style().stylePixmap( QStyle::SP_MessageBoxInformation ) );
89 #endif
90     iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); // hor/vert
91     addHSpacing( hbox );
92
93     // Label for the message
94
95     QLabel * label = new QLabel( message, hbox );
96     Q_CHECK_PTR( label );
97     label->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); // hor/vert
98
99
100     // Pkg list
101
102     _pkgList = new YQPkgList( this );
103     Q_CHECK_PTR( _pkgList );
104     _pkgList->setEditable( false );
105
106     layout->addWidget( _pkgList );
107
108
109     // Button box
110
111     hbox = new Q3HBox( this );
112     Q_CHECK_PTR( hbox );
113     hbox->setSpacing( SPACING );
114     hbox->setMargin ( MARGIN  );
115     layout->addWidget( hbox );
116
117     addHStretch( hbox );
118
119
120     // Accept button - usually "OK" or "Continue"
121
122     QPushButton * button = new QPushButton( acceptButtonLabel, hbox );
123     Q_CHECK_PTR( button );
124     button->setDefault( true );
125
126     connect( button,    SIGNAL( clicked() ),
127              this,      SLOT  ( accept()  ) );
128
129     addHStretch( hbox );
130
131
132     if ( ! rejectButtonLabel.isEmpty() )
133     {
134         // Reject button ( if desired ) - usually "Cancel"
135
136         button = new QPushButton( rejectButtonLabel, hbox );
137         Q_CHECK_PTR( button );
138
139         connect( button,        SIGNAL( clicked() ),
140                  this,          SLOT  ( reject()  ) );
141
142         addHStretch( hbox );
143     }
144 }
145
146
147 void
148 YQPkgChangesDialog::filter( bool byAuto, bool byApp, bool byUser )
149 {
150     filter( QRegExp( "" ), byAuto, byApp, byUser );
151 }
152
153
154 void
155 YQPkgChangesDialog::filter( const QRegExp & regexp, bool byAuto, bool byApp, bool byUser )
156 {
157     YQUI::ui()->busyCursor();
158     _pkgList->clear();
159
160     set<string> ignoredNames;
161     
162     if ( ! byUser || ! byApp )
163         ignoredNames = zypp::ui::userWantedPackageNames();
164
165     for ( ZyppPoolIterator it = zyppPkgBegin();
166           it != zyppPkgEnd();
167           ++it )
168     {
169         ZyppSel selectable = *it;
170
171         if ( selectable->toModify() )
172         {
173             zypp::ResStatus::TransactByValue modifiedBy = selectable->modifiedBy();
174
175             if ( ( modifiedBy == zypp::ResStatus::SOLVER     ) && byAuto ||
176                  ( modifiedBy == zypp::ResStatus::APPL_LOW ||
177                    modifiedBy == zypp::ResStatus::APPL_HIGH  ) && byApp  ||
178                  ( modifiedBy == zypp::ResStatus::USER       ) && byUser   )
179             {
180                 if ( regexp.isEmpty() || regexp.search( selectable->name().c_str() ) >= 0 )
181                 {
182                     if ( ! contains( ignoredNames, selectable->name() ) )
183                         _pkgList->addPkgItem( selectable, tryCastToZyppPkg( selectable->theObj() ) );
184                 }
185             }
186         }
187     }
188
189     YQUI::ui()->normalCursor();
190 }
191
192
193 bool
194 YQPkgChangesDialog::isEmpty() const
195 {
196     return _pkgList->topLevelItemCount() == 0;
197 }
198
199
200 QSize
201 YQPkgChangesDialog::sizeHint() const
202 {
203     return limitToScreenSize( this, QDialog::sizeHint() );
204 }
205
206
207 bool
208 YQPkgChangesDialog::showChangesDialog( const QString &  message,
209                                        const QString &  acceptButtonLabel,
210                                        const QString &  rejectButtonLabel,
211                                        bool             showIfListEmpty   )
212 {
213     YQPkgChangesDialog dialog( 0,
214                                message,
215                                acceptButtonLabel,
216                                rejectButtonLabel );
217     dialog.filter();
218
219     if ( dialog.isEmpty() && ! showIfListEmpty )
220         return true;
221
222     dialog.exec();
223
224     return dialog.result() == QDialog::Accepted;
225 }
226
227
228 bool
229 YQPkgChangesDialog::showChangesDialog( const QString &  message,
230                                        const QRegExp &  regexp,
231                                        const QString &  acceptButtonLabel,
232                                        const QString &  rejectButtonLabel,
233                                        bool             showIfListEmpty   )
234 {
235     YQPkgChangesDialog dialog( 0,
236                                message,
237                                acceptButtonLabel,
238                                rejectButtonLabel );
239     dialog.filter( regexp, true, true, true );
240
241     if ( dialog.isEmpty() && ! showIfListEmpty )
242         return true;
243
244     dialog.exec();
245
246     return dialog.result() == QDialog::Accepted;
247 }
248
249
250
251
252 #include "YQPkgChangesDialog.moc"