Diffstat (limited to 'noncore/settings/packagemanager/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/packagemanager/mainwindow.cpp | 667 |
1 files changed, 667 insertions, 0 deletions
diff --git a/noncore/settings/packagemanager/mainwindow.cpp b/noncore/settings/packagemanager/mainwindow.cpp new file mode 100644 index 0000000..311b5fc --- a/dev/null +++ b/noncore/settings/packagemanager/mainwindow.cpp | |||
@@ -0,0 +1,667 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | |||
4 | =. Copyright (c) 2003 Dan Williams <drw@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This file is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This file is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
19 | ..}^=.= = ; Public License for more details. | ||
20 | ++= -. .` .: | ||
21 | : = ...= . :.=- You should have received a copy of the GNU | ||
22 | -. .:....=;==+<; General Public License along with this file; | ||
23 | -_. . . )=. = see the file COPYING. If not, write to the | ||
24 | -- :-=` Free Software Foundation, Inc., | ||
25 | 59 Temple Place - Suite 330, | ||
26 | Boston, MA 02111-1307, USA. | ||
27 | |||
28 | */ | ||
29 | |||
30 | #include <qaction.h> | ||
31 | #include <qlayout.h> | ||
32 | #include <qlineedit.h> | ||
33 | #include <qmenubar.h> | ||
34 | #include <qmessagebox.h> | ||
35 | #include <qpopupmenu.h> | ||
36 | #include <qtimer.h> | ||
37 | #include <qtoolbar.h> | ||
38 | #include <qwhatsthis.h> | ||
39 | |||
40 | #include <qpe/qpeapplication.h> | ||
41 | #include <qpe/resource.h> | ||
42 | |||
43 | #include "mainwindow.h" | ||
44 | #include "installdlg.h" | ||
45 | #include "filterdlg.h" | ||
46 | #include "promptdlg.h" | ||
47 | |||
48 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags fl ) | ||
49 | : QMainWindow( parent, name, fl || WStyle_ContextHelp ) | ||
50 | , m_config( "packman" ) | ||
51 | , m_packman( &m_config, this ) | ||
52 | , m_menuBar( this ) | ||
53 | , m_toolBar( this ) | ||
54 | , m_findBar( this ) | ||
55 | , m_widgetStack( this ) | ||
56 | , m_packageList( this ) | ||
57 | , m_statusWidget( this ) | ||
58 | , m_statusText( &m_statusWidget ) | ||
59 | , m_statusBar( &m_statusWidget ) | ||
60 | , m_iconUpdated( Resource::loadPixmap( "packagemanager/updated" ) ) | ||
61 | , m_iconInstalled( Resource::loadPixmap( "installed" ) ) | ||
62 | , m_iconNull( m_iconUpdated.size() ) | ||
63 | , m_filterName( QString::null ) | ||
64 | , m_filterServer( QString::null ) | ||
65 | , m_filterDest( QString::null ) | ||
66 | , m_filterStatus( OPackageManager::NotDefined ) | ||
67 | , m_filterCategory( QString::null ) | ||
68 | |||
69 | { | ||
70 | // setCaption( tr( "Package Manager" ) ); | ||
71 | |||
72 | m_iconNull.fill( colorGroup().base() ); | ||
73 | |||
74 | connect( &m_widgetStack, SIGNAL(aboutToShow(QWidget*)), this, SLOT(slotWidgetStackShow(QWidget*)) ); | ||
75 | |||
76 | // Initialize widget stack, package list and status widget | ||
77 | initStatusWidget(); | ||
78 | initPackageList(); | ||
79 | |||
80 | m_widgetStack.addWidget( &m_statusWidget, 2 ); | ||
81 | m_widgetStack.addWidget( &m_packageList, 1 ); | ||
82 | setCentralWidget( &m_widgetStack ); | ||
83 | |||
84 | // Initialize remaining user interface items | ||
85 | initUI(); | ||
86 | |||
87 | // Initialize package information | ||
88 | QTimer::singleShot( 100, this, SLOT( initPackageInfo() ) ); | ||
89 | } | ||
90 | |||
91 | void MainWindow::closeEvent( QCloseEvent *event ) | ||
92 | { | ||
93 | // Close app only if either the package or status widgets are currently active | ||
94 | bool close = m_widgetStack.visibleWidget() == &m_packageList || | ||
95 | m_widgetStack.visibleWidget() == &m_statusWidget; | ||
96 | if ( close ) | ||
97 | { | ||
98 | // TODO - write out application configuration settings | ||
99 | |||
100 | // Write out package manager configuration settings | ||
101 | m_packman.saveSettings(); | ||
102 | event->accept(); | ||
103 | } | ||
104 | else | ||
105 | { | ||
106 | delete m_widgetStack.visibleWidget(); | ||
107 | m_widgetStack.raiseWidget( &m_packageList ); | ||
108 | event->ignore(); | ||
109 | } | ||
110 | } | ||
111 | |||
112 | void MainWindow::initPackageList() | ||
113 | { | ||
114 | m_packageList.addColumn( tr( "Packages" ) ); | ||
115 | QWhatsThis::add( &m_packageList, tr( "This is a listing of all packages.\n\nA blue dot next to the package name indicates that the package is currently installed.\n\nA blue dot with a star indicates that a newer version of the package is available from the server feed.\n\nClick inside the box at the left to select a package." ) ); | ||
116 | QPEApplication::setStylusOperation( m_packageList.viewport(), QPEApplication::RightOnHold ); | ||
117 | } | ||
118 | |||
119 | void MainWindow::initStatusWidget() | ||
120 | { | ||
121 | QVBoxLayout *layout = new QVBoxLayout( &m_statusWidget, 4, 4 ); | ||
122 | |||
123 | m_statusText.setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); | ||
124 | layout->addWidget( &m_statusText ); | ||
125 | |||
126 | connect( &m_packman, SIGNAL(initStatus(int)), this, SLOT(slotInitStatusBar(int)) ); | ||
127 | connect( &m_packman, SIGNAL(statusText(const QString &)), this, SLOT(slotStatusText(const QString &)) ); | ||
128 | connect( &m_packman, SIGNAL(statusBar(int)), this, SLOT(slotStatusBar(int)) ); | ||
129 | |||
130 | layout->addWidget( &m_statusBar ); | ||
131 | } | ||
132 | |||
133 | void MainWindow::initUI() | ||
134 | { | ||
135 | // Build menu and tool bars | ||
136 | setToolBarsMovable( false ); | ||
137 | |||
138 | m_menuBar.setHorizontalStretchable( true ); | ||
139 | QMenuBar *mb = new QMenuBar( &m_menuBar ); | ||
140 | mb->setMargin( 0 ); | ||
141 | |||
142 | // Find toolbar | ||
143 | addToolBar( &m_findBar, QMainWindow::Top, true ); | ||
144 | m_findBar.setHorizontalStretchable( true ); | ||
145 | m_findEdit = new QLineEdit( &m_findBar ); | ||
146 | QWhatsThis::add( m_findEdit, tr( "Type the text to search for here." ) ); | ||
147 | m_findBar.setStretchableWidget( m_findEdit ); | ||
148 | connect( m_findEdit, SIGNAL(textChanged(const QString &)), this, SLOT(slotFindChanged(const QString &)) ); | ||
149 | |||
150 | // Packages menu | ||
151 | QPopupMenu *popup = new QPopupMenu( this ); | ||
152 | |||
153 | QAction *a = new QAction( tr( "Update lists" ), Resource::loadPixmap( "packagemanager/update" ), QString::null, 0, this, 0 ); | ||
154 | a->setWhatsThis( tr( "Click here to update package lists from servers." ) ); | ||
155 | connect( a, SIGNAL(activated()), this, SLOT(slotUpdate()) ); | ||
156 | a->addTo( popup ); | ||
157 | a->addTo( &m_toolBar ); | ||
158 | |||
159 | QAction *actionUpgrade = new QAction( tr( "Upgrade" ), Resource::loadPixmap( "packagemanager/upgrade" ), QString::null, 0, this, 0 ); | ||
160 | actionUpgrade->setWhatsThis( tr( "Click here to upgrade all installed packages if a newer version is available." ) ); | ||
161 | connect( actionUpgrade, SIGNAL(activated()), this, SLOT(slotUpgrade()) ); | ||
162 | actionUpgrade->addTo( popup ); | ||
163 | actionUpgrade->addTo( &m_toolBar ); | ||
164 | |||
165 | // Ipkg implementation does not seem to work currently? (not working in aqpkg either) | ||
166 | /* | ||
167 | QPixmap iconDownload = Resource::loadPixmap( "packagemanager/download" ); | ||
168 | QPixmap iconRemove = Resource::loadPixmap( "packagemanager/remove" ); | ||
169 | QAction *actionDownload = new QAction( tr( "Download" ), iconDownload, QString::null, 0, this, 0 ); | ||
170 | actionDownload->setWhatsThis( tr( "Click here to download the currently selected package(s)." ) ); | ||
171 | connect( actionDownload, SIGNAL(activated()), this, SLOT(slotDownload()) ); | ||
172 | actionDownload->addTo( popup ); | ||
173 | actionDownload->addTo( &m_toolBar ); | ||
174 | */ | ||
175 | |||
176 | a = new QAction( tr( "Apply changes" ), Resource::loadPixmap( "packagemanager/apply" ), QString::null, 0, this, 0 ); | ||
177 | a->setWhatsThis( tr( "Click here to install, remove or upgrade currently selected package(s)." ) ); | ||
178 | connect( a, SIGNAL(activated()), this, SLOT(slotApply()) ); | ||
179 | a->addTo( popup ); | ||
180 | a->addTo( &m_toolBar ); | ||
181 | |||
182 | popup->insertSeparator(); | ||
183 | |||
184 | a = new QAction( tr( "Configure" ), Resource::loadPixmap( "SettingsIcon" ), QString::null, 0, this, 0 ); | ||
185 | a->setWhatsThis( tr( "Click here to configure this application." ) ); | ||
186 | connect( a, SIGNAL(activated()), this, SLOT(slotConfigure()) ); | ||
187 | a->addTo( popup ); | ||
188 | mb->insertItem( tr( "Actions" ), popup ); | ||
189 | |||
190 | // View menu | ||
191 | popup = new QPopupMenu( this ); | ||
192 | |||
193 | m_actionShowNotInstalled = new QAction( tr( "Show packages not installed" ), QString::null, 0, this, 0 ); | ||
194 | m_actionShowNotInstalled->setToggleAction( true ); | ||
195 | m_actionShowNotInstalled->setWhatsThis( tr( "Click here to show packages available which have not been installed." ) ); | ||
196 | connect( m_actionShowNotInstalled, SIGNAL(activated()), this, SLOT(slotShowNotInstalled()) ); | ||
197 | m_actionShowNotInstalled->addTo( popup ); | ||
198 | |||
199 | m_actionShowInstalled = new QAction( tr( "Show installed packages" ), QString::null, 0, this, 0 ); | ||
200 | m_actionShowInstalled->setToggleAction( true ); | ||
201 | m_actionShowInstalled->setWhatsThis( tr( "Click here to show packages currently installed on this device." ) ); | ||
202 | connect( m_actionShowInstalled, SIGNAL(activated()), this, SLOT(slotShowInstalled()) ); | ||
203 | m_actionShowInstalled->addTo( popup ); | ||
204 | |||
205 | m_actionShowUpdated = new QAction( tr( "Show updated packages" ), QString::null, 0, this, 0 ); | ||
206 | m_actionShowUpdated->setToggleAction( true ); | ||
207 | m_actionShowUpdated->setWhatsThis( tr( "Click here to show packages currently installed on this device which have a newer version available." ) ); | ||
208 | connect( m_actionShowUpdated, SIGNAL(activated()), this, SLOT(slotShowUpdated()) ); | ||
209 | m_actionShowUpdated->addTo( popup ); | ||
210 | |||
211 | popup->insertSeparator(); | ||
212 | |||
213 | a = new QAction( tr( "Configure filter" ), QString::null, 0, this, 0 ); | ||
214 | a->setWhatsThis( tr( "Click here to change package filter criteria." ) ); | ||
215 | connect( a, SIGNAL(activated()), this, SLOT(slotFilterChange()) ); | ||
216 | a->addTo( popup ); | ||
217 | |||
218 | m_actionFilter = new QAction( tr( "Filter" ), Resource::loadPixmap( "packagemanager/filter" ), | ||
219 | QString::null, 0, this, 0 ); | ||
220 | m_actionFilter->setToggleAction( true ); | ||
221 | m_actionFilter->setWhatsThis( tr( "Click here to apply current filter." ) ); | ||
222 | connect( m_actionFilter, SIGNAL(toggled(bool)), this, SLOT(slotFilter(bool)) ); | ||
223 | m_actionFilter->addTo( popup ); | ||
224 | |||
225 | popup->insertSeparator(); | ||
226 | |||
227 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); | ||
228 | a->setWhatsThis( tr( "Click here to search for text in package names." ) ); | ||
229 | connect( a, SIGNAL(activated()), this, SLOT(slotFindShowToolbar()) ); | ||
230 | a->addTo( popup ); | ||
231 | |||
232 | m_actionFindNext = new QAction( tr( "Find next" ), Resource::loadIconSet( "next" ), QString::null, 0, this, 0 ); | ||
233 | m_actionFindNext->setEnabled( false ); | ||
234 | m_actionFindNext->setWhatsThis( tr( "Click here to find the next package name containing the text you are searching for." ) ); | ||
235 | connect( m_actionFindNext, SIGNAL(activated()), this, SLOT(slotFindNext()) ); | ||
236 | m_actionFindNext->addTo( popup ); | ||
237 | m_actionFindNext->addTo( &m_findBar ); | ||
238 | |||
239 | mb->insertItem( tr( "View" ), popup ); | ||
240 | |||
241 | // Finish find toolbar creation | ||
242 | a = new QAction( QString::null, Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | ||
243 | a->setWhatsThis( tr( "Click here to hide the find toolbar." ) ); | ||
244 | connect( a, SIGNAL(activated()), this, SLOT(slotFindHideToolbar()) ); | ||
245 | a->addTo( &m_findBar ); | ||
246 | m_findBar.hide(); | ||
247 | } | ||
248 | |||
249 | void MainWindow::loadPackageList( OPackageList *packages, bool clearList ) | ||
250 | { | ||
251 | if ( clearList ) | ||
252 | m_packageList.clear(); | ||
253 | |||
254 | if ( packages ) | ||
255 | { | ||
256 | for ( OPackageListIterator packageIt( *packages ); packageIt.current(); ++packageIt ) | ||
257 | { | ||
258 | OPackage *package = packageIt.current(); | ||
259 | QCheckListItem *item = new QCheckListItem( &m_packageList, package->name(), | ||
260 | QCheckListItem::CheckBox ); | ||
261 | m_packageList.insertItem( item ); | ||
262 | |||
263 | // If a different version of package is available, show update available icon | ||
264 | // Otherwise, show installed icon | ||
265 | if ( !package->versionInstalled().isNull() ) | ||
266 | { | ||
267 | if ( m_packman.compareVersions( package->version(), package->versionInstalled() ) == 1 ) | ||
268 | item->setPixmap( 0, m_iconUpdated ); | ||
269 | else | ||
270 | item->setPixmap( 0, m_iconInstalled ); | ||
271 | } | ||
272 | else | ||
273 | item->setPixmap( 0, m_iconNull ); | ||
274 | } | ||
275 | } | ||
276 | } | ||
277 | |||
278 | void MainWindow::searchForPackage( const QString &text ) | ||
279 | { | ||
280 | if ( !text.isEmpty() ) | ||
281 | { | ||
282 | // look through package list for text startng at current position | ||
283 | QCheckListItem *start = static_cast<QCheckListItem *>(m_packageList.currentItem()); | ||
284 | if ( start == 0 ) | ||
285 | start = static_cast<QCheckListItem *>(m_packageList.firstChild()); | ||
286 | |||
287 | // for ( QCheckListItem *item = static_cast<QCheckListItem *>(start->nextSibling()); item != 0 ; | ||
288 | for ( QCheckListItem *item = static_cast<QCheckListItem *>(start); item != 0 ; | ||
289 | item = static_cast<QCheckListItem *>(item->nextSibling()) ) | ||
290 | { | ||
291 | if ( item->text().lower().find( text ) != -1 ) | ||
292 | { | ||
293 | m_packageList.ensureItemVisible( item ); | ||
294 | m_packageList.setCurrentItem( item ); | ||
295 | break; | ||
296 | } | ||
297 | } | ||
298 | } | ||
299 | } | ||
300 | |||
301 | void MainWindow::initPackageInfo() | ||
302 | { | ||
303 | m_widgetStack.raiseWidget( &m_statusWidget ); | ||
304 | |||
305 | // Load package list | ||
306 | m_packman.loadAvailablePackages(); | ||
307 | m_packman.loadInstalledPackages(); | ||
308 | |||
309 | OPackageList *packageList = m_packman.packages(); | ||
310 | if ( packageList ) | ||
311 | { | ||
312 | loadPackageList( packageList, true ); | ||
313 | delete packageList; | ||
314 | } | ||
315 | |||
316 | m_widgetStack.raiseWidget( &m_packageList ); | ||
317 | } | ||
318 | |||
319 | void MainWindow::slotWidgetStackShow( QWidget *widget ) | ||
320 | { | ||
321 | if ( widget == &m_packageList ) | ||
322 | { | ||
323 | setCaption( tr( "Package Manager" ) ); | ||
324 | |||
325 | m_menuBar.show(); | ||
326 | m_toolBar.show(); | ||
327 | } | ||
328 | else | ||
329 | { | ||
330 | m_menuBar.hide(); | ||
331 | m_toolBar.hide(); | ||
332 | } | ||
333 | } | ||
334 | |||
335 | void MainWindow::slotInitStatusBar( int numSteps ) | ||
336 | { | ||
337 | m_statusBar.setTotalSteps( numSteps ); | ||
338 | } | ||
339 | |||
340 | void MainWindow::slotStatusText( const QString &status ) | ||
341 | { | ||
342 | m_statusText.setText( status ); | ||
343 | } | ||
344 | |||
345 | void MainWindow::slotStatusBar( int currStep ) | ||
346 | { | ||
347 | m_statusBar.setProgress( currStep ); | ||
348 | } | ||
349 | |||
350 | void MainWindow::slotUpdate() | ||
351 | { | ||
352 | // Create package manager output widget | ||
353 | InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Update package information" ), false, | ||
354 | OPackage::Update ); | ||
355 | connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseInstallDlg()) ); | ||
356 | |||
357 | // Display widget | ||
358 | m_widgetStack.addWidget( dlg, 3 ); | ||
359 | m_widgetStack.raiseWidget( dlg ); | ||
360 | } | ||
361 | |||
362 | void MainWindow::slotUpgrade() | ||
363 | { | ||
364 | // Create package manager output widget | ||
365 | InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Upgrade installed packages" ), false, | ||
366 | OPackage::Upgrade ); | ||
367 | connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseInstallDlg()) ); | ||
368 | |||
369 | // Display widget | ||
370 | m_widgetStack.addWidget( dlg, 3 ); | ||
371 | m_widgetStack.raiseWidget( dlg ); | ||
372 | } | ||
373 | |||
374 | // Ipkg implementation does not seem to work currently? (not working in aqpkg either) | ||
375 | /* | ||
376 | void MainWindow::slotDownload() | ||
377 | { | ||
378 | // Retrieve list of packages selected for download (if any) | ||
379 | QStringList *workingPackages = new QStringList(); | ||
380 | |||
381 | for ( QCheckListItem *item = static_cast<QCheckListItem *>(m_packageList.firstChild()); | ||
382 | item != 0 ; | ||
383 | item = static_cast<QCheckListItem *>(item->nextSibling()) ) | ||
384 | { | ||
385 | if ( item->isOn() ) | ||
386 | workingPackages->append( item->text() ); | ||
387 | } | ||
388 | |||
389 | if ( workingPackages->isEmpty() ) | ||
390 | { | ||
391 | // No packages were selected, prompt for URL of package to download | ||
392 | } | ||
393 | else | ||
394 | { | ||
395 | // Download selected packages | ||
396 | m_config.setGroup( "settings" ); | ||
397 | QString workingDir = m_config.readEntry( "DownloadDir", "/tmp" ); | ||
398 | |||
399 | // QString text = InputDialog::getText( tr( "Download to where" ), tr( "Enter path to download to" ), workingDir, &ok, this ); | ||
400 | // if ( ok && !text.isEmpty() ) | ||
401 | // workingDir = text; // user entered something and pressed ok | ||
402 | // else | ||
403 | // return; // user entered nothing or pressed cancel | ||
404 | |||
405 | // // Store download directory in config file | ||
406 | // m_config.writeEntry( "DownloadDir", workingDir ); | ||
407 | |||
408 | // Get starting directory | ||
409 | // char initDir[PATH_MAX]; | ||
410 | // getcwd( initDir, PATH_MAX ); | ||
411 | |||
412 | // Download packages | ||
413 | |||
414 | } | ||
415 | |||
416 | // Create package manager output widget | ||
417 | InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Download packages" ), false, | ||
418 | OPackage::Download, workingPackages ); | ||
419 | connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseInstallDlg()) ); | ||
420 | |||
421 | // Display widget | ||
422 | m_widgetStack.addWidget( dlg, 3 ); | ||
423 | m_widgetStack.raiseWidget( dlg ); | ||
424 | } | ||
425 | */ | ||
426 | |||
427 | void MainWindow::slotApply() | ||
428 | { | ||
429 | QStringList *removeList = 0x0; | ||
430 | QStringList *installList = 0x0; | ||
431 | QStringList *upgradeList = 0x0; | ||
432 | |||
433 | for ( QCheckListItem *item = static_cast<QCheckListItem *>(m_packageList.firstChild()); | ||
434 | item != 0 ; | ||
435 | item = static_cast<QCheckListItem *>(item->nextSibling()) ) | ||
436 | { | ||
437 | if ( item->isOn() ) | ||
438 | { | ||
439 | OPackage *package = m_packman.findPackage( item->text() ); | ||
440 | if ( package ) | ||
441 | { | ||
442 | if ( !package->versionInstalled().isNull() ) | ||
443 | { | ||
444 | if ( m_packman.compareVersions( package->version(), package->versionInstalled() ) == 1 ) | ||
445 | { | ||
446 | // Remove/upgrade package | ||
447 | int answer = PromptDlg::ask( tr( "Remove or upgrade" ), | ||
448 | tr( QString( "Do you wish to remove or upgrade\n%1?" ).arg( item->text() ) ), | ||
449 | tr( "Remove" ), tr( "Upgrade" ), this ); | ||
450 | if ( answer == 1 ) // Remove | ||
451 | { | ||
452 | if ( !removeList ) | ||
453 | removeList = new QStringList(); | ||
454 | removeList->append( item->text() ); | ||
455 | } | ||
456 | else if ( answer == 2 ) // Upgrade | ||
457 | { | ||
458 | if ( !upgradeList ) | ||
459 | upgradeList = new QStringList(); | ||
460 | upgradeList->append( item->text() ); | ||
461 | } | ||
462 | } | ||
463 | else | ||
464 | { | ||
465 | // Remove/reinstall package | ||
466 | int answer = PromptDlg::ask( tr( "Remove or reinstall" ), | ||
467 | tr( QString( "Do you wish to remove or reinstall\n%1?" ).arg( item->text() ) ), | ||
468 | tr( "Remove" ), tr( "Reinstall" ), this ); | ||
469 | if ( answer == 1 ) // Remove | ||
470 | { | ||
471 | if ( !removeList ) | ||
472 | removeList = new QStringList(); | ||
473 | removeList->append( item->text() ); | ||
474 | } | ||
475 | else if ( answer == 2 ) // Reinstall | ||
476 | { | ||
477 | if ( !installList ) | ||
478 | installList = new QStringList(); | ||
479 | installList->append( item->text() ); | ||
480 | } | ||
481 | } | ||
482 | } | ||
483 | else | ||
484 | { | ||
485 | // Install package | ||
486 | if ( !installList ) | ||
487 | installList = new QStringList(); | ||
488 | installList->append( item->text() ); | ||
489 | } | ||
490 | } | ||
491 | } | ||
492 | } | ||
493 | |||
494 | // If nothing is selected, display message and exit | ||
495 | if ( !removeList && !installList && !upgradeList ) | ||
496 | { | ||
497 | QMessageBox::information( this, tr( "Nothing to do" ), tr( "No packages selected" ), tr( "OK" ) ); | ||
498 | return; | ||
499 | } | ||
500 | |||
501 | // Send command only if there are packages to process | ||
502 | OPackage::Command removeCmd = OPackage::NotDefined; | ||
503 | if ( removeList && !removeList->isEmpty() ) | ||
504 | removeCmd = OPackage::Remove; | ||
505 | OPackage::Command installCmd = OPackage::NotDefined; | ||
506 | if ( installList && !installList->isEmpty() ) | ||
507 | installCmd = OPackage::Install; | ||
508 | OPackage::Command upgradeCmd = OPackage::NotDefined; | ||
509 | if ( upgradeList && !upgradeList->isEmpty() ) | ||
510 | upgradeCmd = OPackage::Upgrade; | ||
511 | |||
512 | // Create package manager output widget | ||
513 | InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Apply changes" ), true, | ||
514 | removeCmd, removeList, | ||
515 | installCmd, installList, | ||
516 | upgradeCmd, upgradeList ); | ||
517 | connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseInstallDlg()) ); | ||
518 | |||
519 | // Display widget | ||
520 | m_widgetStack.addWidget( dlg, 3 ); | ||
521 | m_widgetStack.raiseWidget( dlg ); | ||
522 | } | ||
523 | |||
524 | void MainWindow::slotCloseInstallDlg() | ||
525 | { | ||
526 | // Close install dialog | ||
527 | delete m_widgetStack.visibleWidget(); | ||
528 | |||
529 | // Reload package list | ||
530 | initPackageInfo(); | ||
531 | } | ||
532 | |||
533 | void MainWindow::slotConfigure() | ||
534 | { | ||
535 | if ( m_packman.configureDlg( false ) ) | ||
536 | { | ||
537 | if ( PromptDlg::ask( tr( "Config updated" ), | ||
538 | tr( "The configuration has been updated. Do you want to update server and package information now?" ), | ||
539 | tr( "Yes" ), tr( "No" ), this ) == 1 ) | ||
540 | { | ||
541 | // Update package list and reload package info | ||
542 | slotUpdate(); | ||
543 | } | ||
544 | } | ||
545 | } | ||
546 | |||
547 | void MainWindow::slotShowNotInstalled() | ||
548 | { | ||
549 | OPackageList *packageList; | ||
550 | if ( m_actionShowNotInstalled->isOn() ) | ||
551 | { | ||
552 | m_actionShowInstalled->setOn( false ); | ||
553 | m_actionShowUpdated->setOn( false ); | ||
554 | packageList = m_packman.filterPackages( QString::null, QString::null, QString::null, | ||
555 | OPackageManager::NotInstalled, QString::null ); | ||
556 | } | ||
557 | else | ||
558 | packageList = m_packman.packages(); | ||
559 | |||
560 | if ( packageList ) | ||
561 | { | ||
562 | loadPackageList( packageList, true ); | ||
563 | delete packageList; | ||
564 | } | ||
565 | } | ||
566 | |||
567 | void MainWindow::slotShowInstalled() | ||
568 | { | ||
569 | OPackageList *packageList; | ||
570 | if ( m_actionShowInstalled->isOn() ) | ||
571 | { | ||
572 | m_actionShowNotInstalled->setOn( false ); | ||
573 | m_actionShowUpdated->setOn( false ); | ||
574 | packageList = m_packman.filterPackages( QString::null, QString::null, QString::null, | ||
575 | OPackageManager::Installed, QString::null ); | ||
576 | } | ||
577 | else | ||
578 | packageList = m_packman.packages(); | ||
579 | |||
580 | if ( packageList ) | ||
581 | { | ||
582 | loadPackageList( packageList, true ); | ||
583 | delete packageList; | ||
584 | } | ||
585 | } | ||
586 | |||
587 | void MainWindow::slotShowUpdated() | ||
588 | { | ||
589 | OPackageList *packageList; | ||
590 | if ( m_actionShowUpdated->isOn() ) | ||
591 | { | ||
592 | m_actionShowInstalled->setOn( false ); | ||
593 | m_actionShowNotInstalled->setOn( false ); | ||
594 | packageList = m_packman.filterPackages( QString::null, QString::null, QString::null, | ||
595 | OPackageManager::Updated, QString::null ); | ||
596 | } | ||
597 | else | ||
598 | packageList = m_packman.packages(); | ||
599 | |||
600 | if ( packageList ) | ||
601 | { | ||
602 | loadPackageList( packageList, true ); | ||
603 | delete packageList; | ||
604 | } | ||
605 | } | ||
606 | |||
607 | void MainWindow::slotFilterChange() | ||
608 | { | ||
609 | FilterDlg dlg( this, &m_packman, m_filterName, m_filterServer, m_filterDest, m_filterStatus, | ||
610 | m_filterCategory ); | ||
611 | if ( dlg.exec() == QDialog::Accepted ) | ||
612 | { | ||
613 | m_filterName = dlg.name(); | ||
614 | m_filterServer = dlg.server(); | ||
615 | m_filterDest = dlg.destination(); | ||
616 | m_filterStatus = dlg.status(); | ||
617 | m_filterCategory = dlg.category(); | ||
618 | m_actionFilter->setOn( true ); | ||
619 | slotFilter( true ); | ||
620 | } | ||
621 | else | ||
622 | { | ||
623 | m_actionFilter->setOn( false ); | ||
624 | slotFilter( false ); | ||
625 | } | ||
626 | } | ||
627 | |||
628 | void MainWindow::slotFilter( bool isOn ) | ||
629 | { | ||
630 | OPackageList *packageList; | ||
631 | if ( isOn ) | ||
632 | { | ||
633 | packageList = m_packman.filterPackages( m_filterName, m_filterServer, m_filterDest, | ||
634 | m_filterStatus, m_filterCategory ); | ||
635 | } | ||
636 | else | ||
637 | packageList = m_packman.packages(); | ||
638 | |||
639 | if ( packageList ) | ||
640 | { | ||
641 | loadPackageList( packageList, true ); | ||
642 | delete packageList; | ||
643 | } | ||
644 | } | ||
645 | |||
646 | void MainWindow::slotFindShowToolbar() | ||
647 | { | ||
648 | m_findBar.show(); | ||
649 | m_findEdit->setFocus(); | ||
650 | } | ||
651 | |||
652 | void MainWindow::slotFindHideToolbar() | ||
653 | { | ||
654 | m_findBar.hide(); | ||
655 | } | ||
656 | |||
657 | void MainWindow::slotFindChanged( const QString &findText ) | ||
658 | { | ||
659 | |||
660 | m_actionFindNext->setEnabled( !findText.isEmpty() ); | ||
661 | searchForPackage( findText ); | ||
662 | } | ||
663 | |||
664 | void MainWindow::slotFindNext() | ||
665 | { | ||
666 | searchForPackage( m_findEdit->text() ); | ||
667 | } | ||