summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/networkpkgmgr.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/noncore/settings/aqpkg/networkpkgmgr.cpp b/noncore/settings/aqpkg/networkpkgmgr.cpp
index dee834e..ccce401 100644
--- a/noncore/settings/aqpkg/networkpkgmgr.cpp
+++ b/noncore/settings/aqpkg/networkpkgmgr.cpp
@@ -1,662 +1,675 @@
1/*************************************************************************** 1/***************************************************************************
2 networkpkgmgr.cpp - description 2 networkpkgmgr.cpp - description
3 ------------------- 3 -------------------
4 begin : Mon Aug 26 13:32:30 BST 2002 4 begin : Mon Aug 26 13:32:30 BST 2002
5 copyright : (C) 2002 by Andy Qua 5 copyright : (C) 2002 by Andy Qua
6 email : andy.qua@blueyonder.co.uk 6 email : andy.qua@blueyonder.co.uk
7 ***************************************************************************/ 7 ***************************************************************************/
8 8
9/*************************************************************************** 9/***************************************************************************
10 * * 10 * *
11 * This program is free software; you can redistribute it and/or modify * 11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or * 13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. * 14 * (at your option) any later version. *
15 * * 15 * *
16 ***************************************************************************/ 16 ***************************************************************************/
17 17
18#include <fstream> 18#include <fstream>
19#include <iostream> 19#include <iostream>
20using namespace std; 20using namespace std;
21 21
22#include <unistd.h> 22#include <unistd.h>
23#include <stdlib.h> 23#include <stdlib.h>
24#include <linux/limits.h> 24#include <linux/limits.h>
25 25
26#ifdef QWS 26#ifdef QWS
27#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
28#include <qpe/qcopenvelope_qws.h> 28#include <qpe/qcopenvelope_qws.h>
29#include <qpe/config.h> 29#include <qpe/config.h>
30#else 30#else
31#include <qapplication.h> 31#include <qapplication.h>
32#endif 32#endif
33#include <qlabel.h> 33#include <qlabel.h>
34#include <qfile.h> 34#include <qfile.h>
35#include <qmessagebox.h> 35#include <qmessagebox.h>
36 36
37#include "datamgr.h" 37#include "datamgr.h"
38#include "networkpkgmgr.h" 38#include "networkpkgmgr.h"
39#include "installdlgimpl.h" 39#include "installdlgimpl.h"
40#include "ipkg.h" 40#include "ipkg.h"
41#include "inputdlg.h" 41#include "inputdlg.h"
42#include "letterpushbutton.h" 42#include "letterpushbutton.h"
43 43
44#include "global.h" 44#include "global.h"
45 45
46extern int compareVersions( const char *v1, const char *v2 ); 46extern int compareVersions( const char *v1, const char *v2 );
47 47
48NetworkPackageManager::NetworkPackageManager( DataManager *dataManager, QWidget *parent, const char *name) 48NetworkPackageManager::NetworkPackageManager( DataManager *dataManager, QWidget *parent, const char *name)
49 : QWidget(parent, name) 49 : QWidget(parent, name)
50{ 50{
51 dataMgr = dataManager; 51 dataMgr = dataManager;
52 52
53#ifdef QWS 53#ifdef QWS
54 // read download directory from config file 54 // read download directory from config file
55 Config cfg( "aqpkg" ); 55 Config cfg( "aqpkg" );
56 cfg.setGroup( "settings" ); 56 cfg.setGroup( "settings" );
57 currentlySelectedServer = cfg.readEntry( "selectedServer", "local" ); 57 currentlySelectedServer = cfg.readEntry( "selectedServer", "local" );
58 showJumpTo = cfg.readBoolEntry( "showJumpTo", "true" ); 58 showJumpTo = cfg.readBoolEntry( "showJumpTo", "true" );
59#endif 59#endif
60 60
61 61
62 initGui(); 62 initGui();
63 setupConnections(); 63 setupConnections();
64 64
65 updateData(); 65 updateData();
66// progressDlg = 0; 66// progressDlg = 0;
67// timerId = startTimer( 100 ); 67// timerId = startTimer( 100 );
68} 68}
69 69
70NetworkPackageManager::~NetworkPackageManager() 70NetworkPackageManager::~NetworkPackageManager()
71{ 71{
72} 72}
73 73
74void NetworkPackageManager :: timerEvent ( QTimerEvent * ) 74void NetworkPackageManager :: timerEvent ( QTimerEvent * )
75{ 75{
76 killTimer( timerId ); 76 killTimer( timerId );
77 77
78// showProgressDialog(); 78// showProgressDialog();
79 // Add server names to listbox 79 // Add server names to listbox
80 updateData(); 80 updateData();
81 81
82// progressDlg->hide(); 82// progressDlg->hide();
83} 83}
84 84
85void NetworkPackageManager :: updateData() 85void NetworkPackageManager :: updateData()
86{ 86{
87 serversList->clear(); 87 serversList->clear();
88 packagesList->clear(); 88 packagesList->clear();
89 89
90 90
91 vector<Server>::iterator it; 91 vector<Server>::iterator it;
92 int activeItem = -1; 92 int activeItem = -1;
93 int i; 93 int i;
94 for ( i = 0, it = dataMgr->getServerList().begin() ; it != dataMgr->getServerList().end() ; ++it, ++i ) 94 for ( i = 0, it = dataMgr->getServerList().begin() ; it != dataMgr->getServerList().end() ; ++it, ++i )
95 { 95 {
96 if ( !it->isServerActive() ) 96 if ( !it->isServerActive() )
97 { 97 {
98 i--; 98 i--;
99 continue; 99 continue;
100 } 100 }
101 serversList->insertItem( it->getServerName() ); 101 serversList->insertItem( it->getServerName() );
102 if ( it->getServerName() == currentlySelectedServer ) 102 if ( it->getServerName() == currentlySelectedServer )
103 activeItem = i; 103 activeItem = i;
104 } 104 }
105 105
106 // set selected server to be active server 106 // set selected server to be active server
107 if ( activeItem != -1 ) 107 if ( activeItem != -1 )
108 serversList->setCurrentItem( activeItem ); 108 serversList->setCurrentItem( activeItem );
109 serverSelected( 0 ); 109 serverSelected( 0 );
110} 110}
111 111
112void NetworkPackageManager :: selectLocalPackage( const QString &pkg ) 112void NetworkPackageManager :: selectLocalPackage( const QString &pkg )
113{ 113{
114 // First select local server 114 // First select local server
115 for ( int i = 0 ; i < serversList->count() ; ++i ) 115 for ( int i = 0 ; i < serversList->count() ; ++i )
116 { 116 {
117 if ( serversList->text( i ) == LOCAL_IPKGS ) 117 if ( serversList->text( i ) == LOCAL_IPKGS )
118 { 118 {
119 serversList->setCurrentItem( i ); 119 serversList->setCurrentItem( i );
120 break; 120 break;
121 } 121 }
122 } 122 }
123 serverSelected( 0 ); 123 serverSelected( 0 );
124 124
125 // Now set the check box of the selected package 125 // Now set the check box of the selected package
126 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); 126 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild();
127 item != 0 ; 127 item != 0 ;
128 item = (QCheckListItem *)item->nextSibling() ) 128 item = (QCheckListItem *)item->nextSibling() )
129 { 129 {
130 if ( item->text().startsWith( pkg ) ) 130 if ( item->text().startsWith( pkg ) )
131 { 131 {
132 item->setOn( true ); 132 item->setOn( true );
133 break; 133 break;
134 } 134 }
135 } 135 }
136} 136}
137 137
138 138
139void NetworkPackageManager :: initGui() 139void NetworkPackageManager :: initGui()
140{ 140{
141 QLabel *l = new QLabel( "Servers", this ); 141 QLabel *l = new QLabel( "Servers", this );
142 serversList = new QComboBox( this ); 142 serversList = new QComboBox( this );
143 packagesList = new QListView( this ); 143 packagesList = new QListView( this );
144 update = new QPushButton( "Refresh List", this ); 144 update = new QPushButton( "Refresh List", this );
145 download = new QPushButton( "Download", this ); 145 download = new QPushButton( "Download", this );
146 upgrade = new QPushButton( "Upgrade", this ); 146 upgrade = new QPushButton( "Upgrade", this );
147 apply = new QPushButton( "Apply", this ); 147 apply = new QPushButton( "Apply", this );
148 148
149 QVBoxLayout *vbox = new QVBoxLayout( this, 0, -1, "VBox" ); 149 QVBoxLayout *vbox = new QVBoxLayout( this, 0, -1, "VBox" );
150 QHBoxLayout *hbox1 = new QHBoxLayout( vbox, -1, "HBox1" ); 150 QHBoxLayout *hbox1 = new QHBoxLayout( vbox, -1, "HBox1" );
151 hbox1->addWidget( l ); 151 hbox1->addWidget( l );
152 hbox1->addWidget( serversList ); 152 hbox1->addWidget( serversList );
153 153
154 QHBoxLayout *hbox3 = new QHBoxLayout( vbox, -1, "HBox1" ); 154 QHBoxLayout *hbox3 = new QHBoxLayout( vbox, -1, "HBox1" );
155 QHBoxLayout *hbox4 = new QHBoxLayout( vbox, -1, "HBox1" ); 155 QHBoxLayout *hbox4 = new QHBoxLayout( vbox, -1, "HBox1" );
156 156
157 157
158 if ( showJumpTo ) 158 if ( showJumpTo )
159 { 159 {
160 char text[2]; 160 char text[2];
161 text[1] = '\0'; 161 text[1] = '\0';
162 for ( int i = 0 ; i < 26 ; ++i ) 162 for ( int i = 0 ; i < 26 ; ++i )
163 { 163 {
164 text[0] = 'A' + i; 164 text[0] = 'A' + i;
165 LetterPushButton *b = new LetterPushButton( text, this ); 165 LetterPushButton *b = new LetterPushButton( text, this );
166 connect( b, SIGNAL( released( QString ) ), this, SLOT( letterPushed( QString ) ) ); 166 connect( b, SIGNAL( released( QString ) ), this, SLOT( letterPushed( QString ) ) );
167 if ( i < 13 ) 167 if ( i < 13 )
168 hbox3->addWidget( b ); 168 hbox3->addWidget( b );
169 else 169 else
170 hbox4->addWidget( b ); 170 hbox4->addWidget( b );
171 } 171 }
172 } 172 }
173 173
174 vbox->addWidget( packagesList ); 174 vbox->addWidget( packagesList );
175 packagesList->addColumn( "Packages" ); 175 packagesList->addColumn( "Packages" );
176 176
177 QHBoxLayout *hbox2 = new QHBoxLayout( vbox, -1, "HBox2" ); 177 QHBoxLayout *hbox2 = new QHBoxLayout( vbox, -1, "HBox2" );
178 hbox2->addWidget( update ); 178 hbox2->addWidget( update );
179 hbox2->addWidget( download ); 179 hbox2->addWidget( download );
180 hbox2->addWidget( upgrade ); 180 hbox2->addWidget( upgrade );
181 hbox2->addWidget( apply ); 181 hbox2->addWidget( apply );
182} 182}
183 183
184void NetworkPackageManager :: setupConnections() 184void NetworkPackageManager :: setupConnections()
185{ 185{
186 connect( serversList, SIGNAL(activated( int )), this, SLOT(serverSelected( int ))); 186 connect( serversList, SIGNAL(activated( int )), this, SLOT(serverSelected( int )));
187 connect( apply, SIGNAL(released()), this, SLOT(applyChanges()) ); 187 connect( apply, SIGNAL(released()), this, SLOT(applyChanges()) );
188 connect( download, SIGNAL(released()), this, SLOT(downloadPackage()) ); 188 connect( download, SIGNAL(released()), this, SLOT(downloadPackage()) );
189 connect( upgrade, SIGNAL( released()), this, SLOT(upgradePackages()) ); 189 connect( upgrade, SIGNAL( released()), this, SLOT(upgradePackages()) );
190 connect( update, SIGNAL(released()), this, SLOT(updateServer()) ); 190 connect( update, SIGNAL(released()), this, SLOT(updateServer()) );
191} 191}
192 192
193void NetworkPackageManager :: showProgressDialog( char *initialText ) 193void NetworkPackageManager :: showProgressDialog( char *initialText )
194{ 194{
195 if ( !progressDlg ) 195 if ( !progressDlg )
196 progressDlg = new ProgressDlg( this, "Progress", false ); 196 progressDlg = new ProgressDlg( this, "Progress", false );
197 progressDlg->setText( initialText ); 197 progressDlg->setText( initialText );
198 progressDlg->show(); 198 progressDlg->show();
199} 199}
200 200
201 201
202void NetworkPackageManager :: serverSelected( int ) 202void NetworkPackageManager :: serverSelected( int )
203{ 203{
204 packagesList->clear(); 204 packagesList->clear();
205 205
206 // display packages 206 // display packages
207 QString serverName = serversList->currentText(); 207 QString serverName = serversList->currentText();
208 currentlySelectedServer = serverName; 208 currentlySelectedServer = serverName;
209 209
210#ifdef QWS 210#ifdef QWS
211 // read download directory from config file 211 // read download directory from config file
212 Config cfg( "aqpkg" ); 212 Config cfg( "aqpkg" );
213 cfg.setGroup( "settings" ); 213 cfg.setGroup( "settings" );
214 cfg.writeEntry( "selectedServer", currentlySelectedServer ); 214 cfg.writeEntry( "selectedServer", currentlySelectedServer );
215#endif 215#endif
216 216
217 Server *s = dataMgr->getServer( serverName ); 217 Server *s = dataMgr->getServer( serverName );
218 218
219 vector<Package> &list = s->getPackageList(); 219 vector<Package> &list = s->getPackageList();
220 vector<Package>::iterator it; 220 vector<Package>::iterator it;
221 for ( it = list.begin() ; it != list.end() ; ++it ) 221 for ( it = list.begin() ; it != list.end() ; ++it )
222 { 222 {
223 223
224 QString text = ""; 224 QString text = "";
225 225
226 // If the local server, only display installed packages 226 // If the local server, only display installed packages
227 if ( serverName == LOCAL_SERVER && !it->isInstalled() ) 227 if ( serverName == LOCAL_SERVER && !it->isInstalled() )
228 continue; 228 continue;
229 229
230 text += it->getPackageName(); 230 text += it->getPackageName();
231 if ( it->isInstalled() ) 231 if ( it->isInstalled() )
232 { 232 {
233 text += " (installed)"; 233 text += " (installed)";
234 234
235 // If a different version of package is available, postfix it with an * 235 // If a different version of package is available, postfix it with an *
236 if ( it->getVersion() != it->getInstalledVersion() ) 236 if ( it->getVersion() != it->getInstalledVersion() )
237 { 237 {
238 238
239 if ( compareVersions( it->getInstalledVersion(), it->getVersion() ) == 1 ) 239 if ( compareVersions( it->getInstalledVersion(), it->getVersion() ) == 1 )
240 text += "*"; 240 text += "*";
241 } 241 }
242 } 242 }
243 243
244 QCheckListItem *item = new QCheckListItem( packagesList, text, QCheckListItem::CheckBox ); 244 QCheckListItem *item = new QCheckListItem( packagesList, text, QCheckListItem::CheckBox );
245 245
246 if ( it->isInstalled() ) 246 if ( it->isInstalled() )
247 { 247 {
248 QString destName = ""; 248 QString destName = "";
249 if ( it->getLocalPackage() ) 249 if ( it->getLocalPackage() )
250 { 250 {
251 if ( it->getLocalPackage()->getInstalledTo() ) 251 if ( it->getLocalPackage()->getInstalledTo() )
252 destName = it->getLocalPackage()->getInstalledTo()->getDestinationName(); 252 destName = it->getLocalPackage()->getInstalledTo()->getDestinationName();
253 } 253 }
254 else 254 else
255 { 255 {
256 if ( it->getInstalledTo() ) 256 if ( it->getInstalledTo() )
257 destName = it->getInstalledTo()->getDestinationName(); 257 destName = it->getInstalledTo()->getDestinationName();
258 } 258 }
259 if ( destName != "" ) 259 if ( destName != "" )
260 new QCheckListItem( item, QString( "Installed To - " ) + destName ); 260 new QCheckListItem( item, QString( "Installed To - " ) + destName );
261 } 261 }
262 262
263 if ( !it->isPackageStoredLocally() ) 263 if ( !it->isPackageStoredLocally() )
264 new QCheckListItem( item, QString( "Description - " ) + it->getDescription() ); 264 new QCheckListItem( item, QString( "Description - " ) + it->getDescription() );
265 else 265 else
266 new QCheckListItem( item, QString( "Filename - " ) + it->getFilename() ); 266 new QCheckListItem( item, QString( "Filename - " ) + it->getFilename() );
267 267
268 if ( serverName == LOCAL_SERVER ) 268 if ( serverName == LOCAL_SERVER )
269 { 269 {
270 new QCheckListItem( item, QString( "V. Installed - " ) + it->getVersion() ); 270 new QCheckListItem( item, QString( "V. Installed - " ) + it->getVersion() );
271 } 271 }
272 else 272 else
273 { 273 {
274 new QCheckListItem( item, QString( "V. Available - " ) + it->getVersion() ); 274 new QCheckListItem( item, QString( "V. Available - " ) + it->getVersion() );
275 if ( it->getLocalPackage() ) 275 if ( it->getLocalPackage() )
276 { 276 {
277 if ( it->isInstalled() ) 277 if ( it->isInstalled() )
278 new QCheckListItem( item, QString( "V. Installed - " ) + it->getInstalledVersion() ); 278 new QCheckListItem( item, QString( "V. Installed - " ) + it->getInstalledVersion() );
279 } 279 }
280 } 280 }
281 packagesList->insertItem( item ); 281 packagesList->insertItem( item );
282 } 282 }
283 283
284 // If the local server or the local ipkgs server disable the download button 284 // If the local server or the local ipkgs server disable the download button
285 if ( serverName == LOCAL_SERVER ) 285 if ( serverName == LOCAL_SERVER )
286 { 286 {
287 upgrade->setEnabled( false ); 287 upgrade->setEnabled( false );
288 download->setText( "Download" ); 288 download->setText( "Download" );
289 download->setEnabled( false ); 289 download->setEnabled( false );
290 } 290 }
291 else if ( serverName == LOCAL_IPKGS ) 291 else if ( serverName == LOCAL_IPKGS )
292 { 292 {
293 upgrade->setEnabled( false ); 293 upgrade->setEnabled( false );
294 download->setEnabled( true ); 294 download->setEnabled( true );
295 download->setText( "Remove" ); 295 download->setText( "Remove" );
296 } 296 }
297 else 297 else
298 { 298 {
299 upgrade->setEnabled( true ); 299 upgrade->setEnabled( true );
300 download->setEnabled( true ); 300 download->setEnabled( true );
301 download->setText( "Download" ); 301 download->setText( "Download" );
302 } 302 }
303} 303}
304 304
305void NetworkPackageManager :: updateServer() 305void NetworkPackageManager :: updateServer()
306{ 306{
307 QString serverName = serversList->currentText(); 307 QString serverName = serversList->currentText();
308 308
309 // Update the current server 309 // Update the current server
310 // Display dialog 310 // Display dialog
311// ProgressDlg *progDlg = new ProgressDlg( this ); 311// ProgressDlg *progDlg = new ProgressDlg( this );
312// QString status = "Updating package lists..."; 312// QString status = "Updating package lists...";
313// progDlg->show(); 313// progDlg->show();
314// progDlg->setText( status ); 314// progDlg->setText( status );
315 315
316 // Disable buttons to stop silly people clicking lots on them :) 316 // Disable buttons to stop silly people clicking lots on them :)
317 317
318 // First, write out ipkg_conf file so that ipkg can use it 318 // First, write out ipkg_conf file so that ipkg can use it
319 dataMgr->writeOutIpkgConf(); 319 dataMgr->writeOutIpkgConf();
320 320
321 Ipkg ipkg; 321 Ipkg ipkg;
322 ipkg.setOption( "update" ); 322 ipkg.setOption( "update" );
323 323
324 InstallDlgImpl dlg( &ipkg, "Refreshing server package lists", this, "Upgrade", true ); 324 InstallDlgImpl dlg( &ipkg, "Refreshing server package lists", this, "Upgrade", true );
325 dlg.showDlg(); 325 dlg.showDlg();
326 326
327 // Reload data 327 // Reload data
328 dataMgr->reloadServerData(); 328 dataMgr->reloadServerData();
329 serverSelected(-1); 329 serverSelected(-1);
330// delete progDlg; 330// delete progDlg;
331} 331}
332 332
333void NetworkPackageManager :: upgradePackages() 333void NetworkPackageManager :: upgradePackages()
334{ 334{
335 // We're gonna do an upgrade of all packages 335 // We're gonna do an upgrade of all packages
336 // First warn user that this isn't recommended 336 // First warn user that this isn't recommended
337 QString text = "WARNING: Upgrading while\nOpie/Qtopia is running\nis NOT recommended!\n\nAre you sure?\n"; 337 QString text = "WARNING: Upgrading while\nOpie/Qtopia is running\nis NOT recommended!\n\nAre you sure?\n";
338 QMessageBox warn("Warning", text, QMessageBox::Warning, 338 QMessageBox warn("Warning", text, QMessageBox::Warning,
339 QMessageBox::Yes, 339 QMessageBox::Yes,
340 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default , 340 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default ,
341 0, this ); 341 0, this );
342 warn.adjustSize(); 342 warn.adjustSize();
343 343
344 if ( warn.exec() == QMessageBox::Yes ) 344 if ( warn.exec() == QMessageBox::Yes )
345 { 345 {
346 // First, write out ipkg_conf file so that ipkg can use it 346 // First, write out ipkg_conf file so that ipkg can use it
347 dataMgr->writeOutIpkgConf(); 347 dataMgr->writeOutIpkgConf();
348 348
349 // Now run upgrade 349 // Now run upgrade
350 Ipkg ipkg; 350 Ipkg ipkg;
351 ipkg.setOption( "upgrade" ); 351 ipkg.setOption( "upgrade" );
352 352
353 InstallDlgImpl dlg( &ipkg, "Upgrading installed packages", this, "Upgrade", true ); 353 InstallDlgImpl dlg( &ipkg, "Upgrading installed packages", this, "Upgrade", true );
354 dlg.showDlg(); 354 dlg.showDlg();
355 355
356 // Reload data 356 // Reload data
357 dataMgr->reloadServerData(); 357 dataMgr->reloadServerData();
358 serverSelected(-1); 358 serverSelected(-1);
359 } 359 }
360} 360}
361 361
362 362
363void NetworkPackageManager :: downloadPackage() 363void NetworkPackageManager :: downloadPackage()
364{ 364{
365 bool doUpdate = true;
365 if ( download->text() == "Download" ) 366 if ( download->text() == "Download" )
366 { 367 {
367 // First, write out ipkg_conf file so that ipkg can use it 368 // First, write out ipkg_conf file so that ipkg can use it
368 dataMgr->writeOutIpkgConf(); 369 dataMgr->writeOutIpkgConf();
369 370
370 // Display dialog to user asking where to download the files to 371 // Display dialog to user asking where to download the files to
371 bool ok = FALSE; 372 bool ok = FALSE;
372 QString dir = ""; 373 QString dir = "";
373#ifdef QWS 374#ifdef QWS
374 // read download directory from config file 375 // read download directory from config file
375 Config cfg( "aqpkg" ); 376 Config cfg( "aqpkg" );
376 cfg.setGroup( "settings" ); 377 cfg.setGroup( "settings" );
377 dir = cfg.readEntry( "downloadDir", "/home/root/Documents/application/ipkg" ); 378 dir = cfg.readEntry( "downloadDir", "/home/root/Documents/application/ipkg" );
378#endif 379#endif
379 380
380 QString text = InputDialog::getText( tr( "Download to where" ), tr( "Enter path to download to" ), dir, &ok, this ); 381 QString text = InputDialog::getText( tr( "Download to where" ), tr( "Enter path to download to" ), dir, &ok, this );
381 if ( ok && !text.isEmpty() ) 382 if ( ok && !text.isEmpty() )
382 dir = text; // user entered something and pressed ok 383 dir = text; // user entered something and pressed ok
383 else 384 else
384 return; // user entered nothing or pressed cancel 385 return; // user entered nothing or pressed cancel
385 386
386#ifdef QWS 387#ifdef QWS
387 // Store download directory in config file 388 // Store download directory in config file
388 cfg.writeEntry( "downloadDir", dir ); 389 cfg.writeEntry( "downloadDir", dir );
389#endif 390#endif
390 391
391 // Get starting directory 392 // Get starting directory
392 char initDir[PATH_MAX]; 393 char initDir[PATH_MAX];
393 getcwd( initDir, PATH_MAX ); 394 getcwd( initDir, PATH_MAX );
394 395
395 // Download each package 396 // Download each package
396 Ipkg ipkg; 397 Ipkg ipkg;
397 connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); 398 connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &)));
398 399
399 ipkg.setOption( "download" ); 400 ipkg.setOption( "download" );
400 ipkg.setRuntimeDirectory( dir ); 401 ipkg.setRuntimeDirectory( dir );
401 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); 402 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild();
402 item != 0 ; 403 item != 0 ;
403 item = (QCheckListItem *)item->nextSibling() ) 404 item = (QCheckListItem *)item->nextSibling() )
404 { 405 {
405 if ( item->isOn() ) 406 if ( item->isOn() )
406 { 407 {
407 QString name = item->text(); 408 QString name = item->text();
408 int pos = name.find( "*" ); 409 int pos = name.find( "*" );
409 name.truncate( pos ); 410 name.truncate( pos );
410 411
411 // if (there is a (installed), remove it 412 // if (there is a (installed), remove it
412 pos = name.find( "(installed)" ); 413 pos = name.find( "(installed)" );
413 if ( pos > 0 ) 414 if ( pos > 0 )
414 name.truncate( pos - 1 ); 415 name.truncate( pos - 1 );
415 416
416 ipkg.setPackage( name ); 417 ipkg.setPackage( name );
417 ipkg.runIpkg( ); 418 ipkg.runIpkg( );
418 } 419 }
419 } 420 }
420 } 421 }
421 else if ( download->text() == "Remove" ) 422 else if ( download->text() == "Remove" )
422 { 423 {
424 doUpdate = false;
423 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); 425 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild();
424 item != 0 ; 426 item != 0 ;
425 item = (QCheckListItem *)item->nextSibling() ) 427 item = (QCheckListItem *)item->nextSibling() )
426 { 428 {
427 if ( item->isOn() ) 429 if ( item->isOn() )
428 { 430 {
429 QString name = item->text(); 431 QString name = item->text();
430 int pos = name.find( "*" ); 432 int pos = name.find( "*" );
431 name.truncate( pos ); 433 name.truncate( pos );
432 434
433 // if (there is a (installed), remove it 435 // if (there is a (installed), remove it
434 pos = name.find( "(installed)" ); 436 pos = name.find( "(installed)" );
435 if ( pos > 0 ) 437 if ( pos > 0 )
436 name.truncate( pos - 1 ); 438 name.truncate( pos - 1 );
437 439
438 Package *p = dataMgr->getServer( serversList->currentText() )->getPackage( name ); 440 Package *p = dataMgr->getServer( serversList->currentText() )->getPackage( name );
439 QFile f( p->getFilename() ); 441
440 f.remove(); 442 QString msgtext;
443 msgtext.sprintf( "Are you sure you wish to delete\n%s?", (const char *)p->getPackageName() );
444 if ( QMessageBox::information( this, "Are you sure?",
445 msgtext, "No", "Yes" ) == 1 )
446 {
447 doUpdate = true;
448 QFile f( p->getFilename() );
449 f.remove();
450 }
441 } 451 }
442 } 452 }
443 } 453 }
444 454
445 dataMgr->reloadServerData(); 455 if ( doUpdate )
446 serverSelected( -1 ); 456 {
457 dataMgr->reloadServerData();
458 serverSelected( -1 );
459 }
447} 460}
448 461
449 462
450void NetworkPackageManager :: applyChanges() 463void NetworkPackageManager :: applyChanges()
451{ 464{
452 stickyOption = ""; 465 stickyOption = "";
453 466
454 // First, write out ipkg_conf file so that ipkg can use it 467 // First, write out ipkg_conf file so that ipkg can use it
455 dataMgr->writeOutIpkgConf(); 468 dataMgr->writeOutIpkgConf();
456 469
457 // Now for each selected item 470 // Now for each selected item
458 // deal with it 471 // deal with it
459 472
460 vector<InstallData> workingPackages; 473 vector<InstallData> workingPackages;
461 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); 474 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild();
462 item != 0 ; 475 item != 0 ;
463 item = (QCheckListItem *)item->nextSibling() ) 476 item = (QCheckListItem *)item->nextSibling() )
464 { 477 {
465 if ( item->isOn() ) 478 if ( item->isOn() )
466 { 479 {
467 InstallData data = dealWithItem( item ); 480 InstallData data = dealWithItem( item );
468 workingPackages.push_back( data ); 481 workingPackages.push_back( data );
469 } 482 }
470 } 483 }
471 484
472 if ( workingPackages.size() == 0 ) 485 if ( workingPackages.size() == 0 )
473 { 486 {
474 // Nothing to do 487 // Nothing to do
475 QMessageBox::information( this, "Nothing to do", 488 QMessageBox::information( this, "Nothing to do",
476 "No packages selected", "OK" ); 489 "No packages selected", "OK" );
477 490
478 return; 491 return;
479 } 492 }
480 493
481 // do the stuff 494 // do the stuff
482 InstallDlgImpl dlg( workingPackages, dataMgr, this, "Install", true ); 495 InstallDlgImpl dlg( workingPackages, dataMgr, this, "Install", true );
483 dlg.showDlg(); 496 dlg.showDlg();
484 497
485 // Reload data 498 // Reload data
486 dataMgr->reloadServerData(); 499 dataMgr->reloadServerData();
487 serverSelected(-1); 500 serverSelected(-1);
488 501
489#ifdef QWS 502#ifdef QWS
490 // Finally let the main system update itself 503 // Finally let the main system update itself
491 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 504 QCopEnvelope e("QPE/System", "linkChanged(QString)");
492 QString lf = QString::null; 505 QString lf = QString::null;
493 e << lf; 506 e << lf;
494#endif 507#endif
495} 508}
496 509
497// decide what to do - either remove, upgrade or install 510// decide what to do - either remove, upgrade or install
498// Current rules: 511// Current rules:
499// If not installed - install 512// If not installed - install
500// If installed and different version available - upgrade 513// If installed and different version available - upgrade
501// If installed and version up to date - remove 514// If installed and version up to date - remove
502InstallData NetworkPackageManager :: dealWithItem( QCheckListItem *item ) 515InstallData NetworkPackageManager :: dealWithItem( QCheckListItem *item )
503{ 516{
504 QString name = item->text(); 517 QString name = item->text();
505 int pos = name.find( "*" ); 518 int pos = name.find( "*" );
506 name.truncate( pos ); 519 name.truncate( pos );
507 520
508 // if (there is a (installed), remove it 521 // if (there is a (installed), remove it
509 pos = name.find( "(installed)" ); 522 pos = name.find( "(installed)" );
510 if ( pos > 0 ) 523 if ( pos > 0 )
511 name.truncate( pos - 1 ); 524 name.truncate( pos - 1 );
512 525
513 // Get package 526 // Get package
514 Server *s = dataMgr->getServer( serversList->currentText() ); 527 Server *s = dataMgr->getServer( serversList->currentText() );
515 Package *p = s->getPackage( name ); 528 Package *p = s->getPackage( name );
516 529
517 // If the package has a filename then it is a local file 530 // If the package has a filename then it is a local file
518 if ( p->isPackageStoredLocally() ) 531 if ( p->isPackageStoredLocally() )
519 name = p->getFilename(); 532 name = p->getFilename();
520 533
521 QString option; 534 QString option;
522 QString dest = "root"; 535 QString dest = "root";
523 if ( !p->isInstalled() ) 536 if ( !p->isInstalled() )
524 { 537 {
525 InstallData item; 538 InstallData item;
526 item.option = "I"; 539 item.option = "I";
527 item.packageName = name; 540 item.packageName = name;
528 return item; 541 return item;
529 } 542 }
530 else 543 else
531 { 544 {
532 InstallData item; 545 InstallData item;
533 item.option = "D"; 546 item.option = "D";
534 if ( !p->isPackageStoredLocally() ) 547 if ( !p->isPackageStoredLocally() )
535 item.packageName = p->getInstalledPackageName(); 548 item.packageName = p->getInstalledPackageName();
536 else 549 else
537 item.packageName = name; 550 item.packageName = name;
538 551
539 if ( p->getInstalledTo() ) 552 if ( p->getInstalledTo() )
540 { 553 {
541 item.destination = p->getInstalledTo(); 554 item.destination = p->getInstalledTo();
542 cout << "dest - " << p->getInstalledTo()->getDestinationName() << endl; 555 cout << "dest - " << p->getInstalledTo()->getDestinationName() << endl;
543 cout << "dest - " << p->getInstalledTo()->getDestinationPath() << endl; 556 cout << "dest - " << p->getInstalledTo()->getDestinationPath() << endl;
544 } 557 }
545 else 558 else
546 { 559 {
547 item.destination = p->getLocalPackage()->getInstalledTo(); 560 item.destination = p->getLocalPackage()->getInstalledTo();
548 } 561 }
549 562
550 // Now see if version is newer or not 563 // Now see if version is newer or not
551 int val = compareVersions( p->getInstalledVersion(), p->getVersion() ); 564 int val = compareVersions( p->getInstalledVersion(), p->getVersion() );
552 565
553 // If the version requested is older and user selected a local ipk file, then reinstall the file 566 // If the version requested is older and user selected a local ipk file, then reinstall the file
554 if ( p->isPackageStoredLocally() && val == -1 ) 567 if ( p->isPackageStoredLocally() && val == -1 )
555 val = 0; 568 val = 0;
556 569
557 if ( val == -2 ) 570 if ( val == -2 )
558 { 571 {
559 // Error - should handle 572 // Error - should handle
560 } 573 }
561 else if ( val == -1 ) 574 else if ( val == -1 )
562 { 575 {
563 // Version available is older - remove only 576 // Version available is older - remove only
564 item.option = "D"; 577 item.option = "D";
565 } 578 }
566 else 579 else
567 { 580 {
568 QString caption; 581 QString caption;
569 QString text; 582 QString text;
570 QString secondButton; 583 QString secondButton;
571 QString secondOption; 584 QString secondOption;
572 if ( val == 0 ) 585 if ( val == 0 )
573 { 586 {
574 // Version available is the same - option to remove or reinstall 587 // Version available is the same - option to remove or reinstall
575 caption = "Do you wish to remove or reinstall\n%s?"; 588 caption = "Do you wish to remove or reinstall\n%s?";
576 text = "Remove or ReInstall"; 589 text = "Remove or ReInstall";
577 secondButton = "ReInstall"; 590 secondButton = "ReInstall";
578 secondOption = "R"; 591 secondOption = "R";
579 } 592 }
580 else if ( val == 1 ) 593 else if ( val == 1 )
581 { 594 {
582 // Version available is newer - option to remove or upgrade 595 // Version available is newer - option to remove or upgrade
583 caption = "Do you wish to remove or upgrade\n%s?"; 596 caption = "Do you wish to remove or upgrade\n%s?";
584 text = "Remove or Upgrade"; 597 text = "Remove or Upgrade";
585 secondButton = "Upgrade"; 598 secondButton = "Upgrade";
586 secondOption = "U"; 599 secondOption = "U";
587 } 600 }
588 601
589 // Sticky option not implemented yet, but will eventually allow 602 // Sticky option not implemented yet, but will eventually allow
590 // the user to say something like 'remove all' 603 // the user to say something like 'remove all'
591 if ( stickyOption == "" ) 604 if ( stickyOption == "" )
592 { 605 {
593 QString msgtext; 606 QString msgtext;
594 msgtext.sprintf( caption, (const char *)name ); 607 msgtext.sprintf( caption, (const char *)name );
595 switch( QMessageBox::information( this, text, 608 switch( QMessageBox::information( this, text,
596 msgtext, "Remove", secondButton ) ) 609 msgtext, "Remove", secondButton ) )
597 { 610 {
598 case 0: // Try again or Enter 611 case 0: // Try again or Enter
599 // option 0 = Remove 612 // option 0 = Remove
600 item.option = "D"; 613 item.option = "D";
601 break; 614 break;
602 case 1: // Quit or Escape 615 case 1: // Quit or Escape
603 item.option = secondOption; 616 item.option = secondOption;
604 break; 617 break;
605 } 618 }
606 } 619 }
607 else 620 else
608 { 621 {
609// item.option = stickyOption; 622// item.option = stickyOption;
610 } 623 }
611 } 624 }
612 625
613 626
614 // Check if we are reinstalling the same version 627 // Check if we are reinstalling the same version
615 if ( item.option != "R" ) 628 if ( item.option != "R" )
616 item.recreateLinks = true; 629 item.recreateLinks = true;
617 else 630 else
618 item.recreateLinks = false; 631 item.recreateLinks = false;
619 632
620 // User hit cancel (on dlg - assume remove) 633 // User hit cancel (on dlg - assume remove)
621 return item; 634 return item;
622 } 635 }
623} 636}
624 637
625void NetworkPackageManager :: displayText( const QString &t ) 638void NetworkPackageManager :: displayText( const QString &t )
626{ 639{
627 cout << t << endl; 640 cout << t << endl;
628} 641}
629 642
630 643
631void NetworkPackageManager :: letterPushed( QString t ) 644void NetworkPackageManager :: letterPushed( QString t )
632{ 645{
633 QCheckListItem *top = (QCheckListItem *)packagesList->firstChild(); 646 QCheckListItem *top = (QCheckListItem *)packagesList->firstChild();
634 QCheckListItem *start = (QCheckListItem *)packagesList->currentItem(); 647 QCheckListItem *start = (QCheckListItem *)packagesList->currentItem();
635 if ( packagesList->firstChild() == 0 ) 648 if ( packagesList->firstChild() == 0 )
636 return; 649 return;
637 650
638 QCheckListItem *item; 651 QCheckListItem *item;
639 if ( start == 0 ) 652 if ( start == 0 )
640 { 653 {
641 item = (QCheckListItem *)packagesList->firstChild(); 654 item = (QCheckListItem *)packagesList->firstChild();
642 start = top; 655 start = top;
643 } 656 }
644 else 657 else
645 item = (QCheckListItem *)start->nextSibling(); 658 item = (QCheckListItem *)start->nextSibling();
646 659
647 if ( item == 0 ) 660 if ( item == 0 )
648 item = (QCheckListItem *)packagesList->firstChild(); 661 item = (QCheckListItem *)packagesList->firstChild();
649 do 662 do
650 { 663 {
651 if ( item->text().lower().startsWith( t.lower() ) ) 664 if ( item->text().lower().startsWith( t.lower() ) )
652 { 665 {
653 packagesList->setSelected( item, true ); 666 packagesList->setSelected( item, true );
654 packagesList->ensureItemVisible( item ); 667 packagesList->ensureItemVisible( item );
655 break; 668 break;
656 } 669 }
657 670
658 item = (QCheckListItem *)item->nextSibling(); 671 item = (QCheckListItem *)item->nextSibling();
659 if ( !item ) 672 if ( !item )
660 item = (QCheckListItem *)packagesList->firstChild(); 673 item = (QCheckListItem *)packagesList->firstChild();
661 } while ( item != start); 674 } while ( item != start);
662} 675}