summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/networkpkgmgr.cpp8
-rw-r--r--noncore/settings/aqpkg/package.cpp17
-rw-r--r--noncore/settings/aqpkg/package.h3
-rw-r--r--noncore/settings/aqpkg/server.cpp12
4 files changed, 31 insertions, 9 deletions
diff --git a/noncore/settings/aqpkg/networkpkgmgr.cpp b/noncore/settings/aqpkg/networkpkgmgr.cpp
index 3aee7bd..d84fb4b 100644
--- a/noncore/settings/aqpkg/networkpkgmgr.cpp
+++ b/noncore/settings/aqpkg/networkpkgmgr.cpp
@@ -1,563 +1,569 @@
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
46NetworkPackageManager::NetworkPackageManager( DataManager *dataManager, QWidget *parent, const char *name) 46NetworkPackageManager::NetworkPackageManager( DataManager *dataManager, QWidget *parent, const char *name)
47 : QWidget(parent, name) 47 : QWidget(parent, name)
48{ 48{
49 dataMgr = dataManager; 49 dataMgr = dataManager;
50 50
51#ifdef QWS 51#ifdef QWS
52 // read download directory from config file 52 // read download directory from config file
53 Config cfg( "aqpkg" ); 53 Config cfg( "aqpkg" );
54 cfg.setGroup( "settings" ); 54 cfg.setGroup( "settings" );
55 currentlySelectedServer = cfg.readEntry( "selectedServer", "local" ); 55 currentlySelectedServer = cfg.readEntry( "selectedServer", "local" );
56 showJumpTo = cfg.readBoolEntry( "showJumpTo", "true" ); 56 showJumpTo = cfg.readBoolEntry( "showJumpTo", "true" );
57#endif 57#endif
58 58
59 59
60 initGui(); 60 initGui();
61 setupConnections(); 61 setupConnections();
62 62
63 progressDlg = 0; 63 progressDlg = 0;
64 timerId = startTimer( 100 ); 64 timerId = startTimer( 100 );
65} 65}
66 66
67NetworkPackageManager::~NetworkPackageManager() 67NetworkPackageManager::~NetworkPackageManager()
68{ 68{
69} 69}
70 70
71void NetworkPackageManager :: timerEvent ( QTimerEvent * ) 71void NetworkPackageManager :: timerEvent ( QTimerEvent * )
72{ 72{
73 killTimer( timerId ); 73 killTimer( timerId );
74 74
75// showProgressDialog(); 75// showProgressDialog();
76 // Add server names to listbox 76 // Add server names to listbox
77 updateData(); 77 updateData();
78 78
79// progressDlg->hide(); 79// progressDlg->hide();
80} 80}
81 81
82void NetworkPackageManager :: updateData() 82void NetworkPackageManager :: updateData()
83{ 83{
84 serversList->clear(); 84 serversList->clear();
85 packagesList->clear(); 85 packagesList->clear();
86 86
87 87
88 vector<Server>::iterator it; 88 vector<Server>::iterator it;
89 int activeItem = -1; 89 int activeItem = -1;
90 int i; 90 int i;
91 for ( i = 0, it = dataMgr->getServerList().begin() ; it != dataMgr->getServerList().end() ; ++it, ++i ) 91 for ( i = 0, it = dataMgr->getServerList().begin() ; it != dataMgr->getServerList().end() ; ++it, ++i )
92 { 92 {
93 if ( !it->isServerActive() ) 93 if ( !it->isServerActive() )
94 { 94 {
95 i--; 95 i--;
96 continue; 96 continue;
97 } 97 }
98 serversList->insertItem( it->getServerName() ); 98 serversList->insertItem( it->getServerName() );
99 if ( it->getServerName() == currentlySelectedServer ) 99 if ( it->getServerName() == currentlySelectedServer )
100 activeItem = i; 100 activeItem = i;
101 } 101 }
102 102
103 // set selected server to be active server 103 // set selected server to be active server
104 if ( activeItem != -1 ) 104 if ( activeItem != -1 )
105 serversList->setCurrentItem( activeItem ); 105 serversList->setCurrentItem( activeItem );
106 serverSelected( 0 ); 106 serverSelected( 0 );
107} 107}
108 108
109 109
110void NetworkPackageManager :: initGui() 110void NetworkPackageManager :: initGui()
111{ 111{
112 QLabel *l = new QLabel( "Servers", this ); 112 QLabel *l = new QLabel( "Servers", this );
113 serversList = new QComboBox( this ); 113 serversList = new QComboBox( this );
114 packagesList = new QListView( this ); 114 packagesList = new QListView( this );
115 update = new QPushButton( "Refresh List", this ); 115 update = new QPushButton( "Refresh List", this );
116 download = new QPushButton( "Download", this ); 116 download = new QPushButton( "Download", this );
117 upgrade = new QPushButton( "Upgrade", this ); 117 upgrade = new QPushButton( "Upgrade", this );
118 apply = new QPushButton( "Apply", this ); 118 apply = new QPushButton( "Apply", this );
119 119
120 QVBoxLayout *vbox = new QVBoxLayout( this, 0, -1, "VBox" ); 120 QVBoxLayout *vbox = new QVBoxLayout( this, 0, -1, "VBox" );
121 QHBoxLayout *hbox1 = new QHBoxLayout( vbox, -1, "HBox1" ); 121 QHBoxLayout *hbox1 = new QHBoxLayout( vbox, -1, "HBox1" );
122 hbox1->addWidget( l ); 122 hbox1->addWidget( l );
123 hbox1->addWidget( serversList ); 123 hbox1->addWidget( serversList );
124 124
125 QHBoxLayout *hbox3 = new QHBoxLayout( vbox, -1, "HBox1" ); 125 QHBoxLayout *hbox3 = new QHBoxLayout( vbox, -1, "HBox1" );
126 QHBoxLayout *hbox4 = new QHBoxLayout( vbox, -1, "HBox1" ); 126 QHBoxLayout *hbox4 = new QHBoxLayout( vbox, -1, "HBox1" );
127 127
128 128
129 if ( showJumpTo ) 129 if ( showJumpTo )
130 { 130 {
131 char text[2]; 131 char text[2];
132 text[1] = '\0'; 132 text[1] = '\0';
133 for ( int i = 0 ; i < 26 ; ++i ) 133 for ( int i = 0 ; i < 26 ; ++i )
134 { 134 {
135 text[0] = 'A' + i; 135 text[0] = 'A' + i;
136 LetterPushButton *b = new LetterPushButton( text, this ); 136 LetterPushButton *b = new LetterPushButton( text, this );
137 connect( b, SIGNAL( released( QString ) ), this, SLOT( letterPushed( QString ) ) ); 137 connect( b, SIGNAL( released( QString ) ), this, SLOT( letterPushed( QString ) ) );
138 if ( i < 16 ) 138 if ( i < 16 )
139 hbox3->addWidget( b ); 139 hbox3->addWidget( b );
140 else 140 else
141 hbox4->addWidget( b ); 141 hbox4->addWidget( b );
142 } 142 }
143 } 143 }
144 144
145 vbox->addWidget( packagesList ); 145 vbox->addWidget( packagesList );
146 packagesList->addColumn( "Packages" ); 146 packagesList->addColumn( "Packages" );
147 147
148 QHBoxLayout *hbox2 = new QHBoxLayout( vbox, -1, "HBox2" ); 148 QHBoxLayout *hbox2 = new QHBoxLayout( vbox, -1, "HBox2" );
149 hbox2->addWidget( update ); 149 hbox2->addWidget( update );
150 hbox2->addWidget( download ); 150 hbox2->addWidget( download );
151 hbox2->addWidget( upgrade ); 151 hbox2->addWidget( upgrade );
152 hbox2->addWidget( apply ); 152 hbox2->addWidget( apply );
153} 153}
154 154
155void NetworkPackageManager :: setupConnections() 155void NetworkPackageManager :: setupConnections()
156{ 156{
157 connect( serversList, SIGNAL(activated( int )), this, SLOT(serverSelected( int ))); 157 connect( serversList, SIGNAL(activated( int )), this, SLOT(serverSelected( int )));
158 connect( apply, SIGNAL(released()), this, SLOT(applyChanges()) ); 158 connect( apply, SIGNAL(released()), this, SLOT(applyChanges()) );
159 connect( download, SIGNAL(released()), this, SLOT(downloadPackage()) ); 159 connect( download, SIGNAL(released()), this, SLOT(downloadPackage()) );
160 connect( upgrade, SIGNAL( released()), this, SLOT(upgradePackages()) ); 160 connect( upgrade, SIGNAL( released()), this, SLOT(upgradePackages()) );
161 connect( update, SIGNAL(released()), this, SLOT(updateServer()) ); 161 connect( update, SIGNAL(released()), this, SLOT(updateServer()) );
162} 162}
163 163
164void NetworkPackageManager :: showProgressDialog( char *initialText ) 164void NetworkPackageManager :: showProgressDialog( char *initialText )
165{ 165{
166 if ( !progressDlg ) 166 if ( !progressDlg )
167 progressDlg = new ProgressDlg( this, "Progress", false ); 167 progressDlg = new ProgressDlg( this, "Progress", false );
168 progressDlg->setText( initialText ); 168 progressDlg->setText( initialText );
169 progressDlg->show(); 169 progressDlg->show();
170} 170}
171 171
172 172
173void NetworkPackageManager :: serverSelected( int ) 173void NetworkPackageManager :: serverSelected( int )
174{ 174{
175 packagesList->clear(); 175 packagesList->clear();
176 176
177 // display packages 177 // display packages
178 QString serverName = serversList->currentText(); 178 QString serverName = serversList->currentText();
179 currentlySelectedServer = serverName; 179 currentlySelectedServer = serverName;
180 180
181#ifdef QWS 181#ifdef QWS
182 // read download directory from config file 182 // read download directory from config file
183 Config cfg( "aqpkg" ); 183 Config cfg( "aqpkg" );
184 cfg.setGroup( "settings" ); 184 cfg.setGroup( "settings" );
185 cfg.writeEntry( "selectedServer", currentlySelectedServer ); 185 cfg.writeEntry( "selectedServer", currentlySelectedServer );
186#endif 186#endif
187 187
188 Server *s = dataMgr->getServer( serverName ); 188 Server *s = dataMgr->getServer( serverName );
189// dataMgr->setActiveServer( serverName ); 189// dataMgr->setActiveServer( serverName );
190 190
191 vector<Package> &list = s->getPackageList(); 191 vector<Package> &list = s->getPackageList();
192 vector<Package>::iterator it; 192 vector<Package>::iterator it;
193 for ( it = list.begin() ; it != list.end() ; ++it ) 193 for ( it = list.begin() ; it != list.end() ; ++it )
194 { 194 {
195 QString text = ""; 195 QString text = "";
196 196
197 // If the local server, only display installed packages 197 // If the local server, only display installed packages
198 if ( serverName == LOCAL_SERVER && !it->isInstalled() ) 198 if ( serverName == LOCAL_SERVER && !it->isInstalled() )
199 continue; 199 continue;
200 200
201 text += it->getPackageName(); 201 text += it->getPackageName();
202 if ( it->isInstalled() ) 202 if ( it->isInstalled() )
203 { 203 {
204 text += " (installed)"; 204 text += " (installed)";
205 205
206 // If a different version of package is available, postfix it with an * 206 // If a different version of package is available, postfix it with an *
207 if ( it->getVersion() != it->getInstalledVersion() ) 207 if ( it->getVersion() != it->getInstalledVersion() )
208 text += "*"; 208 text += "*";
209 } 209 }
210 210
211 QCheckListItem *item = new QCheckListItem( packagesList, text, QCheckListItem::CheckBox ); 211 QCheckListItem *item = new QCheckListItem( packagesList, text, QCheckListItem::CheckBox );
212 212
213 if ( it->isInstalled() ) 213 if ( it->isInstalled() )
214 { 214 {
215 QString destName = ""; 215 QString destName = "";
216 if ( it->getLocalPackage() ) 216 if ( it->getLocalPackage() )
217 { 217 {
218 if ( it->getLocalPackage()->getInstalledTo() ) 218 if ( it->getLocalPackage()->getInstalledTo() )
219 destName = it->getLocalPackage()->getInstalledTo()->getDestinationName(); 219 destName = it->getLocalPackage()->getInstalledTo()->getDestinationName();
220 } 220 }
221 else 221 else
222 { 222 {
223 if ( it->getInstalledTo() ) 223 if ( it->getInstalledTo() )
224 destName = it->getInstalledTo()->getDestinationName(); 224 destName = it->getInstalledTo()->getDestinationName();
225 } 225 }
226 if ( destName != "" ) 226 if ( destName != "" )
227 new QCheckListItem( item, QString( "Installed To - " ) + destName ); 227 new QCheckListItem( item, QString( "Installed To - " ) + destName );
228 } 228 }
229 229
230 if ( !it->isPackageStoredLocally() ) 230 if ( !it->isPackageStoredLocally() )
231 new QCheckListItem( item, QString( "Description - " ) + it->getDescription() ); 231 new QCheckListItem( item, QString( "Description - " ) + it->getDescription() );
232 else 232 else
233 new QCheckListItem( item, QString( "Filename - " ) + it->getFilename() ); 233 new QCheckListItem( item, QString( "Filename - " ) + it->getFilename() );
234 234
235 new QCheckListItem( item, QString( "V. Available - " ) + it->getVersion() ); 235 new QCheckListItem( item, QString( "V. Available - " ) + it->getVersion() );
236 if ( it->getLocalPackage() ) 236 if ( it->getLocalPackage() )
237 { 237 {
238 if ( it->isInstalled() ) 238 if ( it->isInstalled() )
239 new QCheckListItem( item, QString( "V. Installed - " ) + it->getInstalledVersion() ); 239 new QCheckListItem( item, QString( "V. Installed - " ) + it->getInstalledVersion() );
240 } 240 }
241 packagesList->insertItem( item ); 241 packagesList->insertItem( item );
242 } 242 }
243 243
244 // If the local server or the local ipkgs server disable the download button 244 // If the local server or the local ipkgs server disable the download button
245 if ( serverName == LOCAL_SERVER ) 245 if ( serverName == LOCAL_SERVER )
246 { 246 {
247 upgrade->setEnabled( false ); 247 upgrade->setEnabled( false );
248 download->setText( "Download" ); 248 download->setText( "Download" );
249 download->setEnabled( false ); 249 download->setEnabled( false );
250 } 250 }
251 else if ( serverName == LOCAL_IPKGS ) 251 else if ( serverName == LOCAL_IPKGS )
252 { 252 {
253 upgrade->setEnabled( false ); 253 upgrade->setEnabled( false );
254 download->setEnabled( true ); 254 download->setEnabled( true );
255 download->setText( "Remove" ); 255 download->setText( "Remove" );
256 } 256 }
257 else 257 else
258 { 258 {
259 upgrade->setEnabled( true ); 259 upgrade->setEnabled( true );
260 download->setEnabled( true ); 260 download->setEnabled( true );
261 download->setText( "Download" ); 261 download->setText( "Download" );
262 } 262 }
263} 263}
264 264
265void NetworkPackageManager :: updateServer() 265void NetworkPackageManager :: updateServer()
266{ 266{
267 QString serverName = serversList->currentText(); 267 QString serverName = serversList->currentText();
268 268
269 // Update the current server 269 // Update the current server
270 // Display dialog 270 // Display dialog
271 ProgressDlg *dlg = new ProgressDlg( this ); 271 ProgressDlg *dlg = new ProgressDlg( this );
272 QString status = "Updating package lists..."; 272 QString status = "Updating package lists...";
273 dlg->show(); 273 dlg->show();
274 dlg->setText( status ); 274 dlg->setText( status );
275 275
276 // Disable buttons to stop silly people clicking lots on them :) 276 // Disable buttons to stop silly people clicking lots on them :)
277 277
278 // First, write out ipkg_conf file so that ipkg can use it 278 // First, write out ipkg_conf file so that ipkg can use it
279 dataMgr->writeOutIpkgConf(); 279 dataMgr->writeOutIpkgConf();
280 280
281 QString option = "update"; 281 QString option = "update";
282 QString dummy = ""; 282 QString dummy = "";
283 Ipkg ipkg; 283 Ipkg ipkg;
284 connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); 284 connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &)));
285 ipkg.setOption( option ); 285 ipkg.setOption( option );
286 286
287 ipkg.runIpkg( ); 287 ipkg.runIpkg( );
288 288
289 // Reload data 289 // Reload data
290 dataMgr->reloadServerData( serversList->currentText() ); 290 dataMgr->reloadServerData( serversList->currentText() );
291 serverSelected(-1); 291 serverSelected(-1);
292 delete dlg; 292 delete dlg;
293} 293}
294 294
295void NetworkPackageManager :: upgradePackages() 295void NetworkPackageManager :: upgradePackages()
296{ 296{
297 // We're gonna do an upgrade of all packages 297 // We're gonna do an upgrade of all packages
298 // First warn user that this isn't recommended 298 // First warn user that this isn't recommended
299 QString text = "WARNING: Upgrading while\nOpie/Qtopia is running\nis NOT recommended!\n\nAre you sure?\n"; 299 QString text = "WARNING: Upgrading while\nOpie/Qtopia is running\nis NOT recommended!\n\nAre you sure?\n";
300 QMessageBox warn("Warning", text, QMessageBox::Warning, 300 QMessageBox warn("Warning", text, QMessageBox::Warning,
301 QMessageBox::Yes, 301 QMessageBox::Yes,
302 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default , 302 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default ,
303 0, this ); 303 0, this );
304 warn.adjustSize(); 304 warn.adjustSize();
305 305
306 if ( warn.exec() == QMessageBox::Yes ) 306 if ( warn.exec() == QMessageBox::Yes )
307 { 307 {
308 // First, write out ipkg_conf file so that ipkg can use it 308 // First, write out ipkg_conf file so that ipkg can use it
309 dataMgr->writeOutIpkgConf(); 309 dataMgr->writeOutIpkgConf();
310 310
311 // Now run upgrade 311 // Now run upgrade
312 InstallDlgImpl dlg( this, "Upgrade", true ); 312 InstallDlgImpl dlg( this, "Upgrade", true );
313 dlg.showDlg(); 313 dlg.showDlg();
314 314
315 // Reload data 315 // Reload data
316 dataMgr->reloadServerData( LOCAL_SERVER ); 316 dataMgr->reloadServerData( LOCAL_SERVER );
317 317
318 dataMgr->reloadServerData( serversList->currentText() ); 318 dataMgr->reloadServerData( serversList->currentText() );
319 serverSelected(-1); 319 serverSelected(-1);
320 } 320 }
321} 321}
322 322
323 323
324void NetworkPackageManager :: downloadPackage() 324void NetworkPackageManager :: downloadPackage()
325{ 325{
326 if ( download->text() == "Download" ) 326 if ( download->text() == "Download" )
327 { 327 {
328 // First, write out ipkg_conf file so that ipkg can use it 328 // First, write out ipkg_conf file so that ipkg can use it
329 dataMgr->writeOutIpkgConf(); 329 dataMgr->writeOutIpkgConf();
330 330
331 // Display dialog to user asking where to download the files to 331 // Display dialog to user asking where to download the files to
332 bool ok = FALSE; 332 bool ok = FALSE;
333 QString dir = ""; 333 QString dir = "";
334#ifdef QWS 334#ifdef QWS
335 // read download directory from config file 335 // read download directory from config file
336 Config cfg( "aqpkg" ); 336 Config cfg( "aqpkg" );
337 cfg.setGroup( "settings" ); 337 cfg.setGroup( "settings" );
338 dir = cfg.readEntry( "downloadDir", "/home/root/Documents/application/ipkg" ); 338 dir = cfg.readEntry( "downloadDir", "/home/root/Documents/application/ipkg" );
339#endif 339#endif
340 340
341 QString text = InputDialog::getText( tr( "Download to where" ), tr( "Enter path to download to" ), dir, &ok, this ); 341 QString text = InputDialog::getText( tr( "Download to where" ), tr( "Enter path to download to" ), dir, &ok, this );
342 if ( ok && !text.isEmpty() ) 342 if ( ok && !text.isEmpty() )
343 dir = text; // user entered something and pressed ok 343 dir = text; // user entered something and pressed ok
344 else 344 else
345 return; // user entered nothing or pressed cancel 345 return; // user entered nothing or pressed cancel
346 346
347#ifdef QWS 347#ifdef QWS
348 // Store download directory in config file 348 // Store download directory in config file
349 cfg.writeEntry( "downloadDir", dir ); 349 cfg.writeEntry( "downloadDir", dir );
350#endif 350#endif
351 351
352 // Get starting directory 352 // Get starting directory
353 char initDir[PATH_MAX]; 353 char initDir[PATH_MAX];
354 getcwd( initDir, PATH_MAX ); 354 getcwd( initDir, PATH_MAX );
355 355
356 // Download each package 356 // Download each package
357 Ipkg ipkg; 357 Ipkg ipkg;
358 connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); 358 connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &)));
359 359
360 ipkg.setOption( "download" ); 360 ipkg.setOption( "download" );
361 ipkg.setRuntimeDirectory( dir ); 361 ipkg.setRuntimeDirectory( dir );
362 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); 362 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild();
363 item != 0 ; 363 item != 0 ;
364 item = (QCheckListItem *)item->nextSibling() ) 364 item = (QCheckListItem *)item->nextSibling() )
365 { 365 {
366 if ( item->isOn() ) 366 if ( item->isOn() )
367 { 367 {
368 QString name = item->text(); 368 QString name = item->text();
369 int pos = name.find( "*" ); 369 int pos = name.find( "*" );
370 name.truncate( pos ); 370 name.truncate( pos );
371 371
372 // if (there is a (installed), remove it 372 // if (there is a (installed), remove it
373 pos = name.find( "(installed)" ); 373 pos = name.find( "(installed)" );
374 if ( pos > 0 ) 374 if ( pos > 0 )
375 name.truncate( pos - 1 ); 375 name.truncate( pos - 1 );
376 376
377 ipkg.setPackage( name ); 377 ipkg.setPackage( name );
378 ipkg.runIpkg( ); 378 ipkg.runIpkg( );
379 } 379 }
380 } 380 }
381 } 381 }
382 else if ( download->text() == "Remove" ) 382 else if ( download->text() == "Remove" )
383 { 383 {
384 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); 384 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild();
385 item != 0 ; 385 item != 0 ;
386 item = (QCheckListItem *)item->nextSibling() ) 386 item = (QCheckListItem *)item->nextSibling() )
387 { 387 {
388 if ( item->isOn() ) 388 if ( item->isOn() )
389 { 389 {
390 QString name = item->text(); 390 QString name = item->text();
391 int pos = name.find( "*" ); 391 int pos = name.find( "*" );
392 name.truncate( pos ); 392 name.truncate( pos );
393 393
394 // if (there is a (installed), remove it 394 // if (there is a (installed), remove it
395 pos = name.find( "(installed)" ); 395 pos = name.find( "(installed)" );
396 if ( pos > 0 ) 396 if ( pos > 0 )
397 name.truncate( pos - 1 ); 397 name.truncate( pos - 1 );
398 398
399 Package *p = dataMgr->getServer( serversList->currentText() )->getPackage( name ); 399 Package *p = dataMgr->getServer( serversList->currentText() )->getPackage( name );
400 QFile f( p->getFilename() ); 400 QFile f( p->getFilename() );
401 f.remove(); 401 f.remove();
402 } 402 }
403 } 403 }
404 } 404 }
405 405
406 dataMgr->reloadServerData( LOCAL_IPKGS ); 406 dataMgr->reloadServerData( LOCAL_IPKGS );
407 serverSelected( -1 ); 407 serverSelected( -1 );
408} 408}
409 409
410 410
411void NetworkPackageManager :: applyChanges() 411void NetworkPackageManager :: applyChanges()
412{ 412{
413 stickyOption = ""; 413 stickyOption = "";
414 414
415 // First, write out ipkg_conf file so that ipkg can use it 415 // First, write out ipkg_conf file so that ipkg can use it
416 dataMgr->writeOutIpkgConf(); 416 dataMgr->writeOutIpkgConf();
417 417
418 // Now for each selected item 418 // Now for each selected item
419 // deal with it 419 // deal with it
420 420
421 vector<InstallData> workingPackages; 421 vector<InstallData> workingPackages;
422 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); 422 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild();
423 item != 0 ; 423 item != 0 ;
424 item = (QCheckListItem *)item->nextSibling() ) 424 item = (QCheckListItem *)item->nextSibling() )
425 { 425 {
426 if ( item->isOn() ) 426 if ( item->isOn() )
427 { 427 {
428 InstallData data = dealWithItem( item ); 428 InstallData data = dealWithItem( item );
429 workingPackages.push_back( data ); 429 workingPackages.push_back( data );
430 } 430 }
431 } 431 }
432 432
433 // do the stuff 433 // do the stuff
434 InstallDlgImpl dlg( workingPackages, dataMgr, this, "Install", true ); 434 InstallDlgImpl dlg( workingPackages, dataMgr, this, "Install", true );
435 dlg.showDlg(); 435 dlg.showDlg();
436 436
437 // Reload data 437 // Reload data
438 dataMgr->reloadServerData( LOCAL_SERVER ); 438 dataMgr->reloadServerData( LOCAL_SERVER );
439 439
440 dataMgr->reloadServerData( serversList->currentText() ); 440 dataMgr->reloadServerData( serversList->currentText() );
441 serverSelected(-1); 441 serverSelected(-1);
442 442
443#ifdef QWS 443#ifdef QWS
444 // Finally let the main system update itself 444 // Finally let the main system update itself
445 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 445 QCopEnvelope e("QPE/System", "linkChanged(QString)");
446 QString lf = QString::null; 446 QString lf = QString::null;
447 e << lf; 447 e << lf;
448#endif 448#endif
449} 449}
450 450
451// decide what to do - either remove, upgrade or install 451// decide what to do - either remove, upgrade or install
452// Current rules: 452// Current rules:
453// If not installed - install 453// If not installed - install
454// If installed and different version available - upgrade 454// If installed and different version available - upgrade
455// If installed and version up to date - remove 455// If installed and version up to date - remove
456InstallData NetworkPackageManager :: dealWithItem( QCheckListItem *item ) 456InstallData NetworkPackageManager :: dealWithItem( QCheckListItem *item )
457{ 457{
458 QString name = item->text(); 458 QString name = item->text();
459 int pos = name.find( "*" ); 459 int pos = name.find( "*" );
460 name.truncate( pos ); 460 name.truncate( pos );
461 461
462 // if (there is a (installed), remove it 462 // if (there is a (installed), remove it
463 pos = name.find( "(installed)" ); 463 pos = name.find( "(installed)" );
464 if ( pos > 0 ) 464 if ( pos > 0 )
465 name.truncate( pos - 1 ); 465 name.truncate( pos - 1 );
466 466
467 // Get package 467 // Get package
468 Server *s = dataMgr->getServer( serversList->currentText() ); 468 Server *s = dataMgr->getServer( serversList->currentText() );
469 Package *p = s->getPackage( name ); 469 Package *p = s->getPackage( name );
470 470
471 // If the package has a filename then it is a local file 471 // If the package has a filename then it is a local file
472 if ( p->isPackageStoredLocally() ) 472 if ( p->isPackageStoredLocally() )
473 name = p->getFilename(); 473 name = p->getFilename();
474 QString option; 474 QString option;
475 QString dest = "root"; 475 QString dest = "root";
476 if ( !p->isInstalled() ) 476 if ( !p->isInstalled() )
477 { 477 {
478 InstallData item; 478 InstallData item;
479 item.option = "I"; 479 item.option = "I";
480 item.packageName = name; 480 item.packageName = name;
481 return item; 481 return item;
482 } 482 }
483 else 483 else
484 { 484 {
485 InstallData item; 485 InstallData item;
486 item.option = "D"; 486 item.option = "D";
487 item.packageName = name; 487 item.packageName = p->getInstalledPackageName();
488 if ( p->getInstalledTo() ) 488 if ( p->getInstalledTo() )
489 {
489 item.destination = p->getInstalledTo(); 490 item.destination = p->getInstalledTo();
491 cout << "dest - " << p->getInstalledTo()->getDestinationName() << endl;
492 cout << "dest - " << p->getInstalledTo()->getDestinationPath() << endl;
493 }
490 else 494 else
495 {
491 item.destination = p->getLocalPackage()->getInstalledTo(); 496 item.destination = p->getLocalPackage()->getInstalledTo();
497 }
492 498
493 // Sticky option not implemented yet, but will eventually allow 499 // Sticky option not implemented yet, but will eventually allow
494 // the user to say something like 'remove all' 500 // the user to say something like 'remove all'
495 if ( stickyOption == "" ) 501 if ( stickyOption == "" )
496 { 502 {
497 QString msgtext; 503 QString msgtext;
498 msgtext.sprintf( "Do you wish to remove or reinstall\n%s?", (const char *)name ); 504 msgtext.sprintf( "Do you wish to remove or reinstall\n%s?", (const char *)name );
499 switch( QMessageBox::information( this, "Remove or ReInstall", 505 switch( QMessageBox::information( this, "Remove or ReInstall",
500 msgtext, "Remove", "ReInstall" ) ) 506 msgtext, "Remove", "ReInstall" ) )
501 { 507 {
502 case 0: // Try again or Enter 508 case 0: // Try again or Enter
503 item.option = "D"; 509 item.option = "D";
504 break; 510 break;
505 case 1: // Quit or Escape 511 case 1: // Quit or Escape
506 item.option = "U"; 512 item.option = "U";
507 break; 513 break;
508 } 514 }
509 } 515 }
510 else 516 else
511 { 517 {
512// item.option = stickyOption; 518// item.option = stickyOption;
513 } 519 }
514 520
515 // Check if we are reinstalling the same version 521 // Check if we are reinstalling the same version
516 if ( p->getVersion() != p->getInstalledVersion() ) 522 if ( p->getVersion() != p->getInstalledVersion() )
517 item.recreateLinks = true; 523 item.recreateLinks = true;
518 else 524 else
519 item.recreateLinks = false; 525 item.recreateLinks = false;
520 526
521 // User hit cancel (on dlg - assume remove) 527 // User hit cancel (on dlg - assume remove)
522 return item; 528 return item;
523 } 529 }
524} 530}
525 531
526void NetworkPackageManager :: displayText( const QString &t ) 532void NetworkPackageManager :: displayText( const QString &t )
527{ 533{
528 cout << t << endl; 534 cout << t << endl;
529} 535}
530 536
531 537
532void NetworkPackageManager :: letterPushed( QString t ) 538void NetworkPackageManager :: letterPushed( QString t )
533{ 539{
534 QCheckListItem *top = (QCheckListItem *)packagesList->firstChild(); 540 QCheckListItem *top = (QCheckListItem *)packagesList->firstChild();
535 QCheckListItem *start = (QCheckListItem *)packagesList->currentItem(); 541 QCheckListItem *start = (QCheckListItem *)packagesList->currentItem();
536 if ( packagesList->firstChild() == 0 ) 542 if ( packagesList->firstChild() == 0 )
537 return; 543 return;
538 544
539 QCheckListItem *item; 545 QCheckListItem *item;
540 if ( start == 0 ) 546 if ( start == 0 )
541 { 547 {
542 item = (QCheckListItem *)packagesList->firstChild(); 548 item = (QCheckListItem *)packagesList->firstChild();
543 start = top; 549 start = top;
544 } 550 }
545 else 551 else
546 item = (QCheckListItem *)start->nextSibling(); 552 item = (QCheckListItem *)start->nextSibling();
547 553
548 if ( item == 0 ) 554 if ( item == 0 )
549 item = (QCheckListItem *)packagesList->firstChild(); 555 item = (QCheckListItem *)packagesList->firstChild();
550 do 556 do
551 { 557 {
552 if ( item->text().lower().startsWith( t.lower() ) ) 558 if ( item->text().lower().startsWith( t.lower() ) )
553 { 559 {
554 packagesList->setSelected( item, true ); 560 packagesList->setSelected( item, true );
555 packagesList->ensureItemVisible( item ); 561 packagesList->ensureItemVisible( item );
556 break; 562 break;
557 } 563 }
558 564
559 item = (QCheckListItem *)item->nextSibling(); 565 item = (QCheckListItem *)item->nextSibling();
560 if ( !item ) 566 if ( !item )
561 item = (QCheckListItem *)packagesList->firstChild(); 567 item = (QCheckListItem *)packagesList->firstChild();
562 } while ( item != start); 568 } while ( item != start);
563} 569}
diff --git a/noncore/settings/aqpkg/package.cpp b/noncore/settings/aqpkg/package.cpp
index 48b6934..fd75450 100644
--- a/noncore/settings/aqpkg/package.cpp
+++ b/noncore/settings/aqpkg/package.cpp
@@ -1,109 +1,124 @@
1/*************************************************************************** 1/***************************************************************************
2 package.cpp - description 2 package.cpp - description
3 ------------------- 3 -------------------
4 begin : Mon Aug 26 2002 4 begin : Mon Aug 26 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 "package.h" 18#include "package.h"
19#include "global.h" 19#include "global.h"
20 20
21Package::Package( QString &name ) 21Package::Package( QString &name )
22{ 22{
23 packageName = name; 23 packageName = name;
24 localPackage = 0; 24 localPackage = 0;
25 installed = false; 25 installed = false;
26 packageStoredLocally = false; 26 packageStoredLocally = false;
27 installedToRoot = false; 27 installedToRoot = false;
28 installed = false;
29 installedTo = 0;
28} 30}
29 31
30Package::Package( char *name ) 32Package::Package( char *name )
31{ 33{
32 packageName = name; 34 packageName = name;
33 localPackage = 0; 35 localPackage = 0;
36 installed = false;
37 packageStoredLocally = false;
38 installedToRoot = false;
39 installed = false;
40 installedTo = 0;
34} 41}
35 42
36Package::~Package() 43Package::~Package()
37{ 44{
38} 45}
39 46
40QString Package :: toString() 47QString Package :: toString()
41{ 48{
42 QString ret = "Package - " + getPackageName() + 49 QString ret = "Package - " + getPackageName() +
43 "\n version - " + getVersion(); 50 "\n version - " + getVersion();
44 51
45 if ( localPackage ) 52 if ( localPackage )
46 ret += "\n inst version - " + localPackage->getVersion(); 53 ret += "\n inst version - " + localPackage->getVersion();
47 54
48 55
49 return ret; 56 return ret;
50} 57}
51 58
52void Package :: setStatus( QString &s ) 59void Package :: setStatus( QString &s )
53{ 60{
54 status = s; 61 status = s;
55 62
56 if ( status.find( "installed" ) != -1 ) 63 if ( status.find( "installed" ) != -1 )
57 installed = true; 64 installed = true;
58} 65}
59 66
60void Package :: setLocalPackage( Package *p ) 67void Package :: setLocalPackage( Package *p )
61{ 68{
62 localPackage = p; 69 localPackage = p;
63 70
64 if ( localPackage ) 71 if ( localPackage )
65 if ( localPackage->getVersion() != getVersion() ) 72 if ( localPackage->getVersion() != getVersion() )
66 differentVersionAvailable = true; 73 differentVersionAvailable = true;
67 else 74 else
68 differentVersionAvailable = false; 75 differentVersionAvailable = false;
69} 76}
70 77
71void Package :: setVersion( QString &v ) 78void Package :: setVersion( QString &v )
72{ 79{
73 version = v; 80 version = v;
74 81
75 if ( localPackage ) 82 if ( localPackage )
76 if ( localPackage->getVersion() != getVersion() ) 83 if ( localPackage->getVersion() != getVersion() )
77 differentVersionAvailable = true; 84 differentVersionAvailable = true;
78 else 85 else
79 differentVersionAvailable = false; 86 differentVersionAvailable = false;
80} 87}
81 88
82void Package :: setPackageName( QString &name ) 89void Package :: setPackageName( QString &name )
83{ 90{
84 packageName = name; 91 packageName = name;
85} 92}
86 93
87void Package :: setDescription( QString &d ) 94void Package :: setDescription( QString &d )
88{ 95{
89 description = d; 96 description = d;
90} 97}
91 98
92void Package :: setFilename( QString &f ) 99void Package :: setFilename( QString &f )
93{ 100{
94 filename = f; 101 filename = f;
95} 102}
96 103
97 104
98QString Package :: getInstalledVersion() 105QString Package :: getInstalledVersion()
99{ 106{
100 if ( localPackage ) 107 if ( localPackage )
101 return localPackage->getVersion(); 108 return localPackage->getVersion();
102 else 109 else
103 return getVersion(); 110 return getVersion();
104} 111}
105 112
113QString Package :: getInstalledPackageName()
114{
115 if ( localPackage )
116 return localPackage->getPackageName();
117 else
118 return getPackageName();
119}
120
106bool Package :: isInstalled() 121bool Package :: isInstalled()
107{ 122{
108 return installed || ( localPackage && localPackage->isInstalled() ); 123 return installed || ( localPackage && localPackage->isInstalled() );
109} 124}
diff --git a/noncore/settings/aqpkg/package.h b/noncore/settings/aqpkg/package.h
index 8ba5a6a..2f2a165 100644
--- a/noncore/settings/aqpkg/package.h
+++ b/noncore/settings/aqpkg/package.h
@@ -1,79 +1,80 @@
1/*************************************************************************** 1/***************************************************************************
2 package.h - description 2 package.h - description
3 ------------------- 3 -------------------
4 begin : Mon Aug 26 2002 4 begin : Mon Aug 26 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#ifndef PACKAGE_H 18#ifndef PACKAGE_H
19#define PACKAGE_H 19#define PACKAGE_H
20 20
21#include <stdlib.h> 21#include <stdlib.h>
22 22
23/** 23/**
24 *@author Andy Qua 24 *@author Andy Qua
25 */ 25 */
26 26
27#include <qstring.h> 27#include <qstring.h>
28#include "destination.h" 28#include "destination.h"
29 29
30class Package 30class Package
31{ 31{
32public: 32public:
33 Package( QString &name ); 33 Package( QString &name );
34 Package( char *name ); 34 Package( char *name );
35 ~Package(); 35 ~Package();
36 36
37 void setLocalPackage( Package *p ); 37 void setLocalPackage( Package *p );
38 void setPackageName( QString &name ); 38 void setPackageName( QString &name );
39 void setVersion( QString &v ); 39 void setVersion( QString &v );
40 void setStatus( QString &s ); 40 void setStatus( QString &s );
41 void setDescription( QString &d ); 41 void setDescription( QString &d );
42 void setFilename( QString &f ); 42 void setFilename( QString &f );
43 void setPackageStoredLocally( bool local ){ packageStoredLocally = local; } 43 void setPackageStoredLocally( bool local ){ packageStoredLocally = local; }
44 void setInstalledToRoot( bool root ) { installedToRoot = root; } 44 void setInstalledToRoot( bool root ) { installedToRoot = root; }
45 void setInstalledTo( Destination *d ) { installedTo = d; } 45 void setInstalledTo( Destination *d ) { installedTo = d; }
46 46
47 Package *getLocalPackage() { return localPackage; } 47 Package *getLocalPackage() { return localPackage; }
48 QString getPackageName() { return packageName; } 48 QString getPackageName() { return packageName; }
49 QString getVersion() { return version; } 49 QString getVersion() { return version; }
50 QString getStatus() { return status; } 50 QString getStatus() { return status; }
51 QString getDescription() { return description; } 51 QString getDescription() { return description; }
52 QString getFilename() { return filename; } 52 QString getFilename() { return filename; }
53 53
54 bool isInstalled(); 54 bool isInstalled();
55 bool isPackageStoredLocally(){ return packageStoredLocally; } 55 bool isPackageStoredLocally(){ return packageStoredLocally; }
56 bool isInstalledToRoot() { return installedToRoot; } 56 bool isInstalledToRoot() { return installedToRoot; }
57 QString getInstalledVersion(); 57 QString getInstalledVersion();
58 QString getInstalledPackageName();
58 Destination *getInstalledTo() { return installedTo; } 59 Destination *getInstalledTo() { return installedTo; }
59 60
60 QString toString(); 61 QString toString();
61 62
62 63
63private: 64private:
64 Package *localPackage; 65 Package *localPackage;
65 66
66 QString packageName; 67 QString packageName;
67 QString version; 68 QString version;
68 QString status; 69 QString status;
69 QString description; 70 QString description;
70 QString filename; 71 QString filename;
71 bool packageStoredLocally; 72 bool packageStoredLocally;
72 bool installedToRoot; 73 bool installedToRoot;
73 bool installed; 74 bool installed;
74 bool differentVersionAvailable; 75 bool differentVersionAvailable;
75 76
76 Destination *installedTo; 77 Destination *installedTo;
77}; 78};
78 79
79#endif 80#endif
diff --git a/noncore/settings/aqpkg/server.cpp b/noncore/settings/aqpkg/server.cpp
index 7d103a2..8bca892 100644
--- a/noncore/settings/aqpkg/server.cpp
+++ b/noncore/settings/aqpkg/server.cpp
@@ -1,273 +1,273 @@
1/*************************************************************************** 1/***************************************************************************
2 server.cpp - description 2 server.cpp - description
3 ------------------- 3 -------------------
4 begin : Mon Aug 26 2002 4 begin : Mon Aug 26 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 description : This class holds details about a server 7 description : This class holds details about a server
8 : e.g. all the packages that contained on the server 8 : e.g. all the packages that contained on the server
9 : the installation status 9 : the installation status
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * * 13 * *
14 * This program is free software; you can redistribute it and/or modify * 14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by * 15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or * 16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. * 17 * (at your option) any later version. *
18 * * 18 * *
19 ***************************************************************************/ 19 ***************************************************************************/
20 20
21 21
22#include <stdio.h> 22#include <stdio.h>
23#include <string.h> 23#include <string.h>
24#include <stdlib.h> 24#include <stdlib.h>
25 25
26#include <iostream> 26#include <iostream>
27#include <fstream> 27#include <fstream>
28using namespace std; 28using namespace std;
29 29
30#include "server.h" 30#include "server.h"
31 31
32#ifdef QWS 32#ifdef QWS
33#include <qpe/global.h> 33#include <qpe/global.h>
34#include <qpe/applnk.h> 34#include <qpe/applnk.h>
35#include <qlist.h> 35#include <qlist.h>
36#endif 36#endif
37 37
38#include "utils.h" 38#include "utils.h"
39 39
40#include "global.h" 40#include "global.h"
41 41
42Server :: Server( const char *name, const char *url ) 42Server :: Server( const char *name, const char *url )
43{ 43{
44 serverName = name; 44 serverName = name;
45 serverUrl = url; 45 serverUrl = url;
46 packageFile = IPKG_DIR; 46 packageFile = IPKG_DIR;
47 packageFile += "lists/" + serverName; 47 packageFile += "lists/" + serverName;
48} 48}
49 49
50Server :: ~Server() 50Server :: ~Server()
51{ 51{
52 cleanUp(); 52 cleanUp();
53} 53}
54 54
55void Server :: cleanUp() 55void Server :: cleanUp()
56{ 56{
57 packageList.clear(); 57 packageList.clear();
58} 58}
59 59
60void Server :: readStatusFile( vector<Destination> &destList ) 60void Server :: readStatusFile( vector<Destination> &destList )
61{ 61{
62 cleanUp(); 62 cleanUp();
63 63
64 vector<Destination>::iterator dit; 64 vector<Destination>::iterator dit;
65 bool rootRead = false; 65 bool rootRead = false;
66 for ( dit = destList.begin() ; dit != destList.end() ; ++dit ) 66 for ( dit = destList.begin() ; dit != destList.end() ; ++dit )
67 { 67 {
68 bool installingToRoot = false; 68 bool installingToRoot = false;
69 69
70 QString path = dit->getDestinationPath(); 70 QString path = dit->getDestinationPath();
71 if ( path.right( 1 ) != "/" ) 71 if ( path.right( 1 ) != "/" )
72 path += "/"; 72 path += "/";
73 73
74 if ( path == "/" ) 74 if ( path == "/" )
75 { 75 {
76 rootRead = true; 76 rootRead = true;
77 installingToRoot = true; 77 installingToRoot = true;
78 } 78 }
79 79
80 packageFile = path + "usr/lib/ipkg/status"; 80 packageFile = path + "usr/lib/ipkg/status";
81 readPackageFile( 0, false, installingToRoot, dit ); 81 readPackageFile( 0, false, installingToRoot, dit );
82 } 82 }
83 83
84 // Ensure that the root status file is read 84 // Ensure that the root status file is read
85 if ( !rootRead ) 85 if ( !rootRead )
86 { 86 {
87 cout << "Reading status file " << "/usr/lib/ipkg/status" << endl; 87 cout << "Reading status file " << "/usr/lib/ipkg/status" << endl;
88 packageFile = "/usr/lib/ipkg/status"; 88 packageFile = "/usr/lib/ipkg/status";
89 readPackageFile( 0, false, true ); 89 readPackageFile( 0, false, true );
90 } 90 }
91} 91}
92 92
93void Server :: readLocalIpks( Server *local ) 93void Server :: readLocalIpks( Server *local )
94{ 94{
95 cleanUp(); 95 cleanUp();
96 96
97#ifdef QWS 97#ifdef QWS
98 // First, get any local IPKGs in the documents area 98 // First, get any local IPKGs in the documents area
99 // Only applicable to Qtopie/Opie 99 // Only applicable to Qtopie/Opie
100 100
101 DocLnkSet files; 101 DocLnkSet files;
102 Global::findDocuments( &files, "application/ipkg" ); 102 Global::findDocuments( &files, "application/ipkg" );
103 103
104 // Now add the items to the list 104 // Now add the items to the list
105 QListIterator<DocLnk> it( files.children() ); 105 QListIterator<DocLnk> it( files.children() );
106 106
107 for ( ; it.current() ; ++it ) 107 for ( ; it.current() ; ++it )
108 { 108 {
109 // OK, we have a local IPK file, I think the standard naming conventions 109 // OK, we have a local IPK file, I think the standard naming conventions
110 // for these are packagename_version_arm.ipk 110 // for these are packagename_version_arm.ipk
111 QString file = (*it)->file(); 111 QString file = (*it)->file();
112 112
113 QString packageName = Utils::getPackageNameFromIpkFilename( file ); 113 QString packageName = Utils::getPackageNameFromIpkFilename( file );
114 QString ver = Utils::getPackageVersionFromIpkFilename( file ); 114 QString ver = Utils::getPackageVersionFromIpkFilename( file );
115 packageList.push_back( Package( packageName ) ); 115 packageList.push_back( Package( packageName ) );
116 packageList.back().setVersion( ver ); 116 packageList.back().setVersion( ver );
117 packageList.back().setFilename( file ); 117 packageList.back().setFilename( file );
118 packageList.back().setPackageStoredLocally( true ); 118 packageList.back().setPackageStoredLocally( true );
119 119
120 } 120 }
121#else 121#else
122 QString names[] = { "advancedfm_0.9.1-20020811_arm.ipk", "libopie_0.9.1-20020811_arm.ipk", "libopieobex_0.9.1-20020811.1_arm.ipk", "opie-addressbook_0.9.1-20020811_arm.ipk" }; 122 QString names[] = { "advancedfm_0.9.1-20020811_arm.ipk", "libopie_0.9.1-20020811_arm.ipk", "libopieobex_0.9.1-20020811.1_arm.ipk", "opie-addressbook_0.9.1-20020811_arm.ipk" };
123 for ( int i = 0 ; i < 4 ; ++i ) 123 for ( int i = 0 ; i < 4 ; ++i )
124 { 124 {
125 // OK, we have a local IPK file, I think the standard naming conventions 125 // OK, we have a local IPK file, I think the standard naming conventions
126 // for these are packagename_version_arm.ipk 126 // for these are packagename_version_arm.ipk
127 QString file = names[i]; 127 QString file = names[i];
128 int p = file.find( "_" ); 128 int p = file.find( "_" );
129 QString tmp = file.mid( 0, p ); 129 QString tmp = file.mid( 0, p );
130 packageList.push_back( Package( tmp ) ); 130 packageList.push_back( Package( tmp ) );
131 int p2 = file.find( "_", p+1 ); 131 int p2 = file.find( "_", p+1 );
132 tmp = file.mid( p+1, p2-(p+1) ); 132 tmp = file.mid( p+1, p2-(p+1) );
133 packageList.back().setVersion( tmp ); 133 packageList.back().setVersion( tmp );
134 packageList.back().setPackageStoredLocally( true ); 134 packageList.back().setPackageStoredLocally( true );
135 } 135 }
136#endif 136#endif
137 137
138 // build local packages 138 // build local packages
139 buildLocalPackages( local ); 139 buildLocalPackages( local );
140} 140}
141 141
142void Server :: readPackageFile( Server *local, bool clearAll, bool installingToRoot, Destination *dest ) 142void Server :: readPackageFile( Server *local, bool clearAll, bool installingToRoot, Destination *dest )
143{ 143{
144 ifstream in( packageFile ); 144 ifstream in( packageFile );
145 if ( !in.is_open() ) 145 if ( !in.is_open() )
146 return; 146 return;
147 147
148 char line[1001]; 148 char line[1001];
149 char k[21]; 149 char k[21];
150 char v[1001]; 150 char v[1001];
151 QString key; 151 QString key;
152 QString value; 152 QString value;
153 153
154 if ( clearAll ) 154 if ( clearAll )
155 cleanUp(); 155 cleanUp();
156 Package *currPackage = 0; 156 Package *currPackage = 0;
157 157
158 bool newPackage = true; 158 bool newPackage = true;
159 do 159 do
160 { 160 {
161 in.getline( line, 1000 ); 161 in.getline( line, 1000 );
162 if ( in.eof() ) 162 if ( in.eof() )
163 continue; 163 continue;
164 164
165 k[0] = '\0'; 165 k[0] = '\0';
166 v[0] = '\0'; 166 v[0] = '\0';
167 167
168 sscanf( line, "%[^:]: %[^\n]", k, v ); 168 sscanf( line, "%[^:]: %[^\n]", k, v );
169 key = k; 169 key = k;
170 value = v; 170 value = v;
171 key = key.stripWhiteSpace(); 171 key = key.stripWhiteSpace();
172 value = value.stripWhiteSpace(); 172 value = value.stripWhiteSpace();
173 if ( key == "Package" && newPackage ) 173 if ( key == "Package" && newPackage )
174 { 174 {
175 newPackage = false; 175 newPackage = false;
176 176
177 currPackage = getPackage( value ); 177 currPackage = getPackage( value );
178 if ( !currPackage ) 178 if ( !currPackage )
179 { 179 {
180 packageList.push_back( Package( value ) ); 180 packageList.push_back( Package( value ) );
181 currPackage = &(packageList.back()); 181 currPackage = &(packageList.back());
182 currPackage->setInstalledTo( dest ); 182 currPackage->setInstalledTo( dest );
183 183
184 if ( installingToRoot ) 184 if ( installingToRoot )
185 currPackage->setInstalledToRoot( true ); 185 currPackage->setInstalledToRoot( true );
186 } 186 }
187 else 187 else
188 { 188 {
189 if (currPackage->getStatus().find( "deinstall" ) != -1 ) 189 if (currPackage->getStatus().find( "deinstall" ) != -1 )
190 currPackage->setInstalledTo( dest ); 190 currPackage->setInstalledTo( dest );
191 } 191 }
192 } 192 }
193 else if ( key == "Version" ) 193 else if ( key == "Version" )
194 { 194 {
195 if ( currPackage ) 195 if ( currPackage )
196 currPackage->setVersion( value ); 196 currPackage->setVersion( value );
197 } 197 }
198 else if ( key == "Status" ) 198 else if ( key == "Status" )
199 { 199 {
200 if ( currPackage ) 200 if ( currPackage )
201 currPackage->setStatus( value ); 201 currPackage->setStatus( value );
202 } 202 }
203 else if ( key == "Description" ) 203 else if ( key == "Description" )
204 { 204 {
205 if ( currPackage ) 205 if ( currPackage )
206 currPackage->setDescription( value ); 206 currPackage->setDescription( value );
207 } 207 }
208 else if ( key == "Filename" ) 208 else if ( key == "Filename" )
209 { 209 {
210 if ( currPackage ) 210 if ( currPackage )
211 currPackage->setFilename( value ); 211 currPackage->setFilename( value );
212 } 212 }
213 else if ( key == "" ) 213 else if ( key == "" )
214 { 214 {
215 newPackage = true; 215 newPackage = true;
216 } 216 }
217 } while ( !in.eof() ); 217 } while ( !in.eof() );
218 218
219 in.close(); 219 in.close();
220 220
221 // build local packages 221 // build local packages
222 buildLocalPackages( local ); 222 buildLocalPackages( local );
223} 223}
224 224
225void Server :: buildLocalPackages( Server *local ) 225void Server :: buildLocalPackages( Server *local )
226{ 226{
227 for ( unsigned int i = 0 ; i < packageList.size() ; ++i ) 227 for ( unsigned int i = 0 ; i < packageList.size() ; ++i )
228 { 228 {
229 QString name = packageList[i].getPackageName(); 229 QString name = packageList[i].getPackageName();
230 if ( local ) 230 if ( local )
231 packageList[i].setLocalPackage( local->getPackage( name ) ); 231 packageList[i].setLocalPackage( local->getPackage( name ) );
232 else 232 else
233 packageList[i].setLocalPackage( 0 ); 233 packageList[i].setLocalPackage( 0 );
234 } 234 }
235 235
236} 236}
237 237
238Package *Server :: getPackage( QString &name ) 238Package *Server :: getPackage( QString &name )
239{ 239{
240 return getPackage( (const char *)name ); 240 return getPackage( (const char *)name );
241} 241}
242 242
243Package *Server :: getPackage( const char *name ) 243Package *Server :: getPackage( const char *name )
244{ 244{
245 Package *ret = 0; 245 Package *ret = 0;
246 246
247 for ( unsigned int i = 0 ; i < packageList.size() && ret == 0; ++i ) 247 for ( unsigned int i = 0 ; i < packageList.size() && ret == 0; ++i )
248 { 248 {
249 if ( packageList[i].getPackageName() == name ) 249 if ( packageList[i].getPackageName() == name )
250 ret = &packageList[i]; 250 ret = &packageList[i];
251 } 251 }
252 252
253 return ret; 253 return ret;
254} 254}
255 255
256QString Server :: toString() 256QString Server :: toString()
257{ 257{
258 QString ret = "Server\n name - " + serverName + 258 QString ret = "Server\n name - " + serverName +
259 "\n url - " + serverUrl + 259 "\n url - " + serverUrl +
260 "\n"; 260 "\n";
261 261
262 for ( unsigned int i = 0 ; i < packageList.size() ; ++i ) 262 for ( unsigned int i = 0 ; i < packageList.size() ; ++i )
263 ret += "\n " + packageList[i].toString(); 263 ret += "\n " + packageList[i].toString();
264 264
265 265
266 return ret; 266 return ret;
267} 267}
268 268
269vector<Package> &Server::getPackageList() 269vector<Package> &Server::getPackageList()
270{ 270{
271 return packageList; 271 return packageList;
272} 272}
273 273