summaryrefslogtreecommitdiff
path: root/noncore/settings/packagemanager/installdlg.cpp
Unidiff
Diffstat (limited to 'noncore/settings/packagemanager/installdlg.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/packagemanager/installdlg.cpp84
1 files changed, 60 insertions, 24 deletions
diff --git a/noncore/settings/packagemanager/installdlg.cpp b/noncore/settings/packagemanager/installdlg.cpp
index 781f8f5..494603b 100644
--- a/noncore/settings/packagemanager/installdlg.cpp
+++ b/noncore/settings/packagemanager/installdlg.cpp
@@ -5,133 +5,143 @@
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7_;:, .> :=|. This file is free software; you can 7_;:, .> :=|. This file is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU General Public 9:`=1 )Y*s>-.-- : the terms of the GNU General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11- . .-<_> .<> Foundation; either version 2 of the License, 11- . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This file is distributed in the hope that 14 .i_,=:_. -<s. This file is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General
19..}^=.= = ; Public License for more details. 19..}^=.= = ; Public License for more details.
20++= -. .` .: 20++= -. .` .:
21: = ...= . :.=- You should have received a copy of the GNU 21: = ...= . :.=- You should have received a copy of the GNU
22-. .:....=;==+<; General Public License along with this file; 22-. .:....=;==+<; General Public License along with this file;
23 -_. . . )=. = see the file COPYING. If not, write to the 23 -_. . . )=. = see the file COPYING. If not, write to the
24 -- :-=` Free Software Foundation, Inc., 24 -- :-=` Free Software Foundation, Inc.,
25 59 Temple Place - Suite 330, 25 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27 27
28*/ 28*/
29 29
30#include "installdlg.h" 30#include "installdlg.h"
31 31
32#include <opie2/ofiledialog.h> 32#include <opie2/ofiledialog.h>
33#include <opie2/oprocess.h> 33#include <opie2/oprocess.h>
34 34
35#include <qpe/fileselector.h> 35#include <qpe/fileselector.h>
36#include <qpe/resource.h> 36#include <qpe/resource.h>
37#include <qpe/storage.h> 37#include <qpe/storage.h>
38 38
39#include <qapplication.h> 39#include <qapplication.h>
40#include <qcombobox.h> 40#include <qcombobox.h>
41#include <qfileinfo.h> 41#include <qfileinfo.h>
42#include <qgroupbox.h> 42#include <qgroupbox.h>
43#include <qlabel.h> 43#include <qlabel.h>
44#include <qlayout.h> 44#include <qlayout.h>
45#include <qmap.h> 45#include <qmap.h>
46#include <qmultilineedit.h> 46#include <qmultilineedit.h>
47#include <qpushbutton.h> 47#include <qpushbutton.h>
48 48
49#include <sys/vfs.h> 49#include <sys/vfs.h>
50 50
51#include "opackagemanager.h" 51#include "opackagemanager.h"
52 52
53InstallDlg::InstallDlg( QWidget *parent, OPackageManager *pm, const QString &caption, bool showDestInfo, 53InstallDlg::InstallDlg( QWidget *parent, OPackageManager *pm, const QString &caption,
54 OPackage::Command command1, const QStringList &packages1, 54 OPackage::Command command1, const QStringList &packages1,
55 OPackage::Command command2, const QStringList &packages2, 55 OPackage::Command command2, const QStringList &packages2,
56 OPackage::Command command3, const QStringList &packages3 ) 56 OPackage::Command command3, const QStringList &packages3 )
57 : QWidget( 0x0 ) 57 : QWidget( 0x0 )
58 , m_packman( pm ) 58 , m_packman( pm )
59 , m_installFound( false )
59 , m_numCommands( 0 ) 60 , m_numCommands( 0 )
60 , m_currCommand( 0 ) 61 , m_currCommand( 0 )
61 , m_destItem( 0x0 ) 62 , m_destItem( 0x0 )
62{ 63{
63 // Save command/package list information 64 // Save command/package list information
64 if ( command1 != OPackage::NotDefined ) 65 if ( command1 != OPackage::NotDefined )
65 { 66 {
66 m_command[ m_numCommands ] = command1; 67 m_command[ m_numCommands ] = command1;
67 m_packages[ m_numCommands ] = packages1; 68 m_packages[ m_numCommands ] = packages1;
68 ++m_numCommands; 69 ++m_numCommands;
70
71 if ( command1 == OPackage::Install )
72 m_installFound = true;
69 } 73 }
70 if ( command2 != OPackage::NotDefined ) 74 if ( command2 != OPackage::NotDefined )
71 { 75 {
72 m_command[ m_numCommands ] = command2; 76 m_command[ m_numCommands ] = command2;
73 m_packages[ m_numCommands ] = packages2; 77 m_packages[ m_numCommands ] = packages2;
74 ++m_numCommands; 78 ++m_numCommands;
79
80 if ( command2 == OPackage::Install )
81 m_installFound = true;
75 } 82 }
76 if ( command3 != OPackage::NotDefined ) 83 if ( command3 != OPackage::NotDefined )
77 { 84 {
78 m_command[ m_numCommands ] = command3; 85 m_command[ m_numCommands ] = command3;
79 m_packages[ m_numCommands ] = packages3; 86 m_packages[ m_numCommands ] = packages3;
80 ++m_numCommands; 87 ++m_numCommands;
88
89 if ( command3 == OPackage::Install )
90 m_installFound = true;
81 } 91 }
82 92
83 // Initialize UI 93 // Initialize UI
84 if ( parent ) 94 if ( parent )
85 parent->setCaption( caption ); 95 parent->setCaption( caption );
86 96
87 QGridLayout *layout = new QGridLayout( this, 4, 2, 2, 4 ); 97 QGridLayout *layout = new QGridLayout( this, 4, 2, 2, 4 );
88 98
89 if ( showDestInfo ) 99 if ( m_installFound )
90 { 100 {
91 QLabel *label = new QLabel( tr( "Destination" ), this ); 101 QLabel *label = new QLabel( tr( "Destination" ), this );
92 layout->addWidget( label, 0, 0 ); 102 layout->addWidget( label, 0, 0 );
93 m_destination = new QComboBox( this ); 103 m_destination = new QComboBox( this );
94 m_destination->insertStringList( m_packman->destinations() ); 104 m_destination->insertStringList( m_packman->destinations() );
95 layout->addWidget( m_destination, 0, 1 ); 105 layout->addWidget( m_destination, 0, 1 );
96 connect( m_destination, SIGNAL(highlighted(const QString&)), 106 connect( m_destination, SIGNAL(highlighted(const QString&)),
97 this, SLOT(slotDisplayAvailSpace(const QString&)) ); 107 this, SLOT(slotDisplayAvailSpace(const QString&)) );
98 108
99 label = new QLabel( tr( "Space Avail" ), this ); 109 label = new QLabel( tr( "Space Avail" ), this );
100 layout->addWidget( label, 1, 0 ); 110 layout->addWidget( label, 1, 0 );
101 m_availSpace = new QLabel( this ); 111 m_availSpace = new QLabel( this );
102 layout->addWidget( m_availSpace, 1, 1 ); 112 layout->addWidget( m_availSpace, 1, 1 );
103 113
104 // TODO - select correct destination 114 // TODO - select correct destination
105 slotDisplayAvailSpace( m_destination->currentText() ); 115 slotDisplayAvailSpace( m_destination->currentText() );
106 } 116 }
107 else 117 else
108 { 118 {
109 m_destination = 0x0; 119 m_destination = 0x0;
110 m_availSpace = 0x0; 120 m_availSpace = 0x0;
111 } 121 }
112 122
113 QGroupBox *groupBox = new QGroupBox( 0, Qt::Vertical, tr( "Output" ), this ); 123 QGroupBox *groupBox = new QGroupBox( 0, Qt::Vertical, tr( "Output" ), this );
114 groupBox->layout()->setSpacing( 0 ); 124 groupBox->layout()->setSpacing( 0 );
115 groupBox->layout()->setMargin( 4 ); 125 groupBox->layout()->setMargin( 4 );
116 126
117 QVBoxLayout *groupBoxLayout = new QVBoxLayout( groupBox->layout() ); 127 QVBoxLayout *groupBoxLayout = new QVBoxLayout( groupBox->layout() );
118 m_output = new QMultiLineEdit( groupBox ); 128 m_output = new QMultiLineEdit( groupBox );
119 m_output->setReadOnly( true ); 129 m_output->setReadOnly( true );
120 groupBoxLayout->addWidget( m_output ); 130 groupBoxLayout->addWidget( m_output );
121 layout->addMultiCellWidget( groupBox, 2, 2, 0, 1 ); 131 layout->addMultiCellWidget( groupBox, 2, 2, 0, 1 );
122 132
123 m_btnStart = new QPushButton( Resource::loadPixmap( "packagemanager/apply" ), tr( "Start" ), this ); 133 m_btnStart = new QPushButton( Resource::loadPixmap( "packagemanager/apply" ), tr( "Start" ), this );
124 layout->addWidget( m_btnStart, 3, 0 ); 134 layout->addWidget( m_btnStart, 3, 0 );
125 connect( m_btnStart, SIGNAL(clicked()), this, SLOT(slotBtnStart()) ); 135 connect( m_btnStart, SIGNAL(clicked()), this, SLOT(slotBtnStart()) );
126 136
127 m_btnOptions = new QPushButton( Resource::loadPixmap( "SettingsIcon" ), tr( "Options" ), this ); 137 m_btnOptions = new QPushButton( Resource::loadPixmap( "SettingsIcon" ), tr( "Options" ), this );
128 layout->addWidget( m_btnOptions, 3, 1 ); 138 layout->addWidget( m_btnOptions, 3, 1 );
129 connect( m_btnOptions, SIGNAL( clicked() ), this, SLOT(slotBtnOptions()) ); 139 connect( m_btnOptions, SIGNAL( clicked() ), this, SLOT(slotBtnOptions()) );
130 140
131 // Display packages being acted upon in output widget 141 // Display packages being acted upon in output widget
132 for( int i = 0; i < m_numCommands; i++ ) 142 for( int i = 0; i < m_numCommands; i++ )
133 { 143 {
134 if ( !m_packages[ i ].isEmpty() ) 144 if ( !m_packages[ i ].isEmpty() )
135 { 145 {
136 QString lineStr = tr( "Packages to " ); 146 QString lineStr = tr( "Packages to " );
137 147
@@ -175,154 +185,180 @@ void InstallDlg::slotDisplayAvailSpace( const QString &destination )
175 185
176 // Get destination 186 // Get destination
177 if ( !destination.isNull() ) 187 if ( !destination.isNull() )
178 m_destItem = m_packman->findConfItem( OConfItem::Destination, destination ); 188 m_destItem = m_packman->findConfItem( OConfItem::Destination, destination );
179 189
180 if ( m_destItem ) 190 if ( m_destItem )
181 { 191 {
182 // Calculate available space 192 // Calculate available space
183 struct statfs fs; 193 struct statfs fs;
184 if ( !statfs( m_destItem->value(), &fs ) ) 194 if ( !statfs( m_destItem->value(), &fs ) )
185 { 195 {
186 long mult = fs.f_bsize / 1024; 196 long mult = fs.f_bsize / 1024;
187 long div = 1024 / fs.f_bsize; 197 long div = 1024 / fs.f_bsize;
188 198
189 if ( !mult ) mult = 1; 199 if ( !mult ) mult = 1;
190 if ( !div ) div = 1; 200 if ( !div ) div = 1;
191 long avail = fs.f_bavail * mult / div; 201 long avail = fs.f_bavail * mult / div;
192 202
193 space = tr( "%1 Kb" ).arg( avail ); 203 space = tr( "%1 Kb" ).arg( avail );
194 } 204 }
195 } 205 }
196 206
197 // Display available space 207 // Display available space
198 m_availSpace->setText( space ); 208 m_availSpace->setText( space );
199} 209}
200 210
201void InstallDlg::slotBtnStart() 211void InstallDlg::slotBtnStart()
202{ 212{
203 QString btnText = m_btnStart->text(); 213 QString btnText = m_btnStart->text();
204 if ( btnText == tr( "Abort" ) ) 214 if ( btnText == tr( "Abort" ) )
205 { 215 {
206 // Prevent unexecuted commands from executing 216 // Prevent unexecuted commands from executing
207 m_currCommand = 999; 217 m_currCommand = 999;
208 218
209 // Allow user to close dialog 219 // Allow user to close dialog
210 m_btnStart->setText( tr( "Close" ) ); 220 m_btnStart->setText( tr( "Close" ) );
211 m_btnStart->setIconSet( Resource::loadPixmap( "enter" ) ); 221 m_btnStart->setIconSet( Resource::loadPixmap( "enter" ) );
212 return; 222 return;
213 } 223 }
214 else if ( btnText == tr( "Close" ) ) 224 else if ( btnText == tr( "Close" ) )
215 { 225 {
216 // TODO - force reload of package data 226 // TODO - force reload of package data
217 emit closeInstallDlg(); 227 emit closeInstallDlg();
218 return; 228 return;
219 } 229 }
220 230
221 // Start was clicked, start executing 231 // Start was clicked, start executing
222 QString dest; 232 QString dest;
223 if ( m_destination ) 233 if ( m_installFound )
224 { 234 {
225 dest = m_destination->currentText(); 235 dest = m_destination->currentText();
226 m_destination->setEnabled( false ); 236 m_destination->setEnabled( false );
227 } 237 }
228 238
229 m_btnOptions->setEnabled( false ); 239 m_btnOptions->setEnabled( false );
230 if ( m_numCommands > 1 ) 240 if ( m_numCommands > 1 )
231 { 241 {
232 m_btnStart->setText( tr( "Abort" ) ); 242 m_btnStart->setText( tr( "Abort" ) );
233 m_btnStart->setIconSet( Resource::loadPixmap( "close" ) ); 243 m_btnStart->setIconSet( Resource::loadPixmap( "close" ) );
234 } 244 }
235 else 245 else
236 { 246 {
237 m_btnStart->setEnabled( false ); 247 m_btnStart->setEnabled( false );
238 } 248 }
239 249
250 Opie::Core::OProcess process( this );
240 for ( m_currCommand = 0; m_currCommand < m_numCommands; m_currCommand++ ) 251 for ( m_currCommand = 0; m_currCommand < m_numCommands; m_currCommand++ )
241 { 252 {
242 // Execute next command 253 // Execute next command
243 m_packman->executeCommand( m_command[ m_currCommand ], m_packages[ m_currCommand ], dest, 254 m_packman->executeCommand( m_command[ m_currCommand ], m_packages[ m_currCommand ], dest,
244 this, SLOT(slotOutput(char*)), true ); 255 this, SLOT(slotOutput(char*)), true );
245 }
246 slotProcessDone(0l);
247 256
248 // Get destination 257 // Link/Unlink application if the package was removed from or installed to a destination
249/* 258 // other than root
250 if ( dest == "root" ) 259 if ( ( m_command[ m_currCommand ] == OPackage::Install && dest != "root" ) ||
260 ( m_command[ m_currCommand ] == OPackage::Remove ) )
251 { 261 {
252 slotProcessDone(0l); 262 //m_packman->findPackage( m_packages[ m_currCommand ]->destination() != "root"*/ )
253 return;
254 }
255 263
256 m_destItem = m_packman->findConfItem( OConfItem::Destination, dest ); 264 // Loop through all package names in the command group
257 if ( m_destItem ) 265 for ( QStringList::Iterator it = m_packages[ m_currCommand ].begin();
266 it != m_packages[ m_currCommand ].end();
267 ++it )
258 { 268 {
259 QString path = m_destItem->value(); 269 OPackage *currPackage = m_packman->findPackage( (*it) );
260 Opie::Core::OProcess *process = new Opie::Core::OProcess( this, "ipkg-link process" );
261 connect( process, SIGNAL(processExited(Opie::Core::OProcess*)),
262 this, SLOT(slotProcessDone(Opie::Core::OProcess*)) );
263 270
264 *process << "ipkg-link" << "mount" << path; 271 // Skip package if it is not found or being removed from 'root'
265 if ( !process->start( Opie::Core::OProcess::NotifyOnExit, 272 if ( !currPackage || ( m_command[ m_currCommand ] == OPackage::Remove &&
273 currPackage->destination() == "root" ) )
274 continue;
275
276 // Display feedback to user
277 if ( m_command[ m_currCommand ] == OPackage::Install )
278 m_output->append( tr( QString( "Running ipkg-link to link package '%1'." )
279 .arg( currPackage->name() ) ) );
280 else
281 m_output->append( tr( QString( "Running ipkg-link to remove links for package '%1'." )
282 .arg( currPackage->name() ) ) );
283 m_output->setCursorPosition( m_output->numLines(), 0 );
284
285 // Execute ipkg-link
286 process.clearArguments();
287 process << "ipkg-link"
288 << ( ( m_command[ m_currCommand ] == OPackage::Install ) ? "add" : "remove" )
289 << currPackage->name();
290 if ( !process.start( Opie::Core::OProcess::Block,
266 Opie::Core::OProcess::NoCommunication ) ) 291 Opie::Core::OProcess::NoCommunication ) )
267 slotProcessDone( 0l ); 292 {
268 m_output->append( tr( "Starting ipkg-link to link installed applications." ) ); 293 slotProcessDone( 0x0 );
294 m_output->append( tr( "Unable to run ipkg-link." ) );
269 m_output->setCursorPosition( m_output->numLines(), 0 ); 295 m_output->setCursorPosition( m_output->numLines(), 0 );
296 return;
270 } 297 }
271*/ 298 }
299
300 }
301 }
302
303 slotProcessDone( 0x0 );
272} 304}
273 305
274void InstallDlg::slotProcessDone( Opie::Core::OProcess *proc ) 306void InstallDlg::slotProcessDone( Opie::Core::OProcess *proc )
275{ 307{
276 delete proc; 308 if ( proc )
277 309 {
310 // Display message pnly if linking was done
278 m_output->append( tr( "The package linking is done." ) ); 311 m_output->append( tr( "The package linking is done." ) );
279 m_output->setCursorPosition( m_output->numLines(), 0 ); 312 m_output->setCursorPosition( m_output->numLines(), 0 );
280 313
314 delete proc;
315 }
316
281 // All commands executed, allow user to close dialog 317 // All commands executed, allow user to close dialog
282 m_btnStart->setEnabled( true ); 318 m_btnStart->setEnabled( true );
283 m_btnStart->setText( tr( "Close" ) ); 319 m_btnStart->setText( tr( "Close" ) );
284 m_btnStart->setIconSet( Resource::loadPixmap( "enter" ) ); 320 m_btnStart->setIconSet( Resource::loadPixmap( "enter" ) );
285 321
286 m_btnOptions->setEnabled( true ); 322 m_btnOptions->setEnabled( true );
287 m_btnOptions->setText( tr( "Save output" ) ); 323 m_btnOptions->setText( tr( "Save output" ) );
288 m_btnOptions->setIconSet( Resource::loadPixmap( "save" ) ); 324 m_btnOptions->setIconSet( Resource::loadPixmap( "save" ) );
289} 325}
290 326
291void InstallDlg::slotBtnOptions() 327void InstallDlg::slotBtnOptions()
292{ 328{
293 QString btnText = m_btnOptions->text(); 329 QString btnText = m_btnOptions->text();
294 if ( btnText == tr( "Options" ) ) 330 if ( btnText == tr( "Options" ) )
295 { 331 {
296 // Display configuration dialog (only options tab is enabled) 332 // Display configuration dialog (only options tab is enabled)
297 m_packman->configureDlg( true ); 333 m_packman->configureDlg( true );
298 return; 334 return;
299 } 335 }
300 336
301 // Save output was clicked 337 // Save output was clicked
302 QMap<QString, QStringList> map; 338 QMap<QString, QStringList> map;
303 map.insert( tr( "All" ), QStringList() ); 339 map.insert( tr( "All" ), QStringList() );
304 QStringList text; 340 QStringList text;
305 text << "text/*"; 341 text << "text/*";
306 map.insert(tr( "Text" ), text ); 342 map.insert(tr( "Text" ), text );
307 text << "*"; 343 text << "*";
308 map.insert( tr( "All" ), text ); 344 map.insert( tr( "All" ), text );
309 345
310 QString filename = Opie::Ui::OFileDialog::getSaveFileName( 2, "/", "ipkg-output", map ); 346 QString filename = Opie::Ui::OFileDialog::getSaveFileName( 2, "/", "ipkg-output", map );
311 if( !filename.isEmpty() ) 347 if( !filename.isEmpty() )
312 { 348 {
313 QString currentFileName = QFileInfo( filename ).fileName(); 349 QString currentFileName = QFileInfo( filename ).fileName();
314 DocLnk doc; 350 DocLnk doc;
315 doc.setType( "text/plain" ); 351 doc.setType( "text/plain" );
316 doc.setFile( filename ); 352 doc.setFile( filename );
317 doc.setName( currentFileName ); 353 doc.setName( currentFileName );
318 FileManager fm; 354 FileManager fm;
319 fm.saveFile( doc, m_output->text() ); 355 fm.saveFile( doc, m_output->text() );
320 } 356 }
321} 357}
322 358
323void InstallDlg::slotOutput( char *msg ) 359void InstallDlg::slotOutput( char *msg )
324{ 360{
325 // Allow processing of other events 361 // Allow processing of other events
326 qApp->processEvents(); 362 qApp->processEvents();
327 363
328 QString lineStr = msg; 364 QString lineStr = msg;