summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/networkpkgmgr.cpp3
-rw-r--r--noncore/settings/aqpkg/server.cpp1
2 files changed, 3 insertions, 1 deletions
diff --git a/noncore/settings/aqpkg/networkpkgmgr.cpp b/noncore/settings/aqpkg/networkpkgmgr.cpp
index 0814121..cf94628 100644
--- a/noncore/settings/aqpkg/networkpkgmgr.cpp
+++ b/noncore/settings/aqpkg/networkpkgmgr.cpp
@@ -1,855 +1,856 @@
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#include "categoryfilterimpl.h" 43#include "categoryfilterimpl.h"
44 44
45#include "global.h" 45#include "global.h"
46 46
47extern int compareVersions( const char *v1, const char *v2 ); 47extern int compareVersions( const char *v1, const char *v2 );
48 48
49NetworkPackageManager::NetworkPackageManager( DataManager *dataManager, QWidget *parent, const char *name) 49NetworkPackageManager::NetworkPackageManager( DataManager *dataManager, QWidget *parent, const char *name)
50 : QWidget(parent, name) 50 : QWidget(parent, name)
51{ 51{
52 dataMgr = dataManager; 52 dataMgr = dataManager;
53 53
54#ifdef QWS 54#ifdef QWS
55 // read download directory from config file 55 // read download directory from config file
56 Config cfg( "aqpkg" ); 56 Config cfg( "aqpkg" );
57 cfg.setGroup( "settings" ); 57 cfg.setGroup( "settings" );
58 currentlySelectedServer = cfg.readEntry( "selectedServer", "local" ); 58 currentlySelectedServer = cfg.readEntry( "selectedServer", "local" );
59 showJumpTo = cfg.readBoolEntry( "showJumpTo", "true" ); 59 showJumpTo = cfg.readBoolEntry( "showJumpTo", "true" );
60 60
61#endif 61#endif
62 62
63 showUninstalledPkgs = false; 63 showUninstalledPkgs = false;
64 showInstalledPkgs = false; 64 showInstalledPkgs = false;
65 showUpgradedPkgs = false; 65 showUpgradedPkgs = false;
66 categoryFilterEnabled = false; 66 categoryFilterEnabled = false;
67 67
68 initGui(); 68 initGui();
69 setupConnections(); 69 setupConnections();
70 70
71 updateData(); 71 updateData();
72} 72}
73 73
74NetworkPackageManager::~NetworkPackageManager() 74NetworkPackageManager::~NetworkPackageManager()
75{ 75{
76} 76}
77 77
78void NetworkPackageManager :: timerEvent ( QTimerEvent * ) 78void NetworkPackageManager :: timerEvent ( QTimerEvent * )
79{ 79{
80 killTimer( timerId ); 80 killTimer( timerId );
81 81
82 // Add server names to listbox 82 // Add server names to listbox
83 updateData(); 83 updateData();
84} 84}
85 85
86void NetworkPackageManager :: updateData() 86void NetworkPackageManager :: updateData()
87{ 87{
88 serversList->clear(); 88 serversList->clear();
89 packagesList->clear(); 89 packagesList->clear();
90 90
91 91
92 vector<Server>::iterator it; 92 vector<Server>::iterator it;
93 int activeItem = -1; 93 int activeItem = -1;
94 int i; 94 int i;
95 for ( i = 0, it = dataMgr->getServerList().begin() ; it != dataMgr->getServerList().end() ; ++it, ++i ) 95 for ( i = 0, it = dataMgr->getServerList().begin() ; it != dataMgr->getServerList().end() ; ++it, ++i )
96 { 96 {
97 cout << "Adding " << it->getServerName() << " to combobox" << endl;
97 if ( !it->isServerActive() ) 98 if ( !it->isServerActive() )
98 { 99 {
99 i--; 100 i--;
100 continue; 101 continue;
101 } 102 }
102 serversList->insertItem( it->getServerName() ); 103 serversList->insertItem( it->getServerName() );
103 if ( it->getServerName() == currentlySelectedServer ) 104 if ( it->getServerName() == currentlySelectedServer )
104 activeItem = i; 105 activeItem = i;
105 } 106 }
106 107
107 // set selected server to be active server 108 // set selected server to be active server
108 if ( activeItem != -1 ) 109 if ( activeItem != -1 )
109 serversList->setCurrentItem( activeItem ); 110 serversList->setCurrentItem( activeItem );
110 serverSelected( 0 ); 111 serverSelected( 0 );
111} 112}
112 113
113void NetworkPackageManager :: selectLocalPackage( const QString &pkg ) 114void NetworkPackageManager :: selectLocalPackage( const QString &pkg )
114{ 115{
115 // First select local server 116 // First select local server
116 for ( int i = 0 ; i < serversList->count() ; ++i ) 117 for ( int i = 0 ; i < serversList->count() ; ++i )
117 { 118 {
118 if ( serversList->text( i ) == LOCAL_IPKGS ) 119 if ( serversList->text( i ) == LOCAL_IPKGS )
119 { 120 {
120 serversList->setCurrentItem( i ); 121 serversList->setCurrentItem( i );
121 break; 122 break;
122 } 123 }
123 } 124 }
124 serverSelected( 0 ); 125 serverSelected( 0 );
125 126
126 // Now set the check box of the selected package 127 // Now set the check box of the selected package
127 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); 128 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild();
128 item != 0 ; 129 item != 0 ;
129 item = (QCheckListItem *)item->nextSibling() ) 130 item = (QCheckListItem *)item->nextSibling() )
130 { 131 {
131 if ( item->text().startsWith( pkg ) ) 132 if ( item->text().startsWith( pkg ) )
132 { 133 {
133 item->setOn( true ); 134 item->setOn( true );
134 break; 135 break;
135 } 136 }
136 } 137 }
137} 138}
138 139
139 140
140void NetworkPackageManager :: initGui() 141void NetworkPackageManager :: initGui()
141{ 142{
142 QLabel *l = new QLabel( "Servers", this ); 143 QLabel *l = new QLabel( "Servers", this );
143 serversList = new QComboBox( this ); 144 serversList = new QComboBox( this );
144 packagesList = new QListView( this ); 145 packagesList = new QListView( this );
145 update = new QPushButton( "Refresh Lists", this ); 146 update = new QPushButton( "Refresh Lists", this );
146 download = new QPushButton( "Download", this ); 147 download = new QPushButton( "Download", this );
147 upgrade = new QPushButton( "Upgrade", this ); 148 upgrade = new QPushButton( "Upgrade", this );
148 apply = new QPushButton( "Apply", this ); 149 apply = new QPushButton( "Apply", this );
149 150
150 QVBoxLayout *vbox = new QVBoxLayout( this, 0, -1, "VBox" ); 151 QVBoxLayout *vbox = new QVBoxLayout( this, 0, -1, "VBox" );
151 QHBoxLayout *hbox1 = new QHBoxLayout( vbox, -1, "HBox1" ); 152 QHBoxLayout *hbox1 = new QHBoxLayout( vbox, -1, "HBox1" );
152 hbox1->addWidget( l ); 153 hbox1->addWidget( l );
153 hbox1->addWidget( serversList ); 154 hbox1->addWidget( serversList );
154 155
155 QHBoxLayout *hbox3 = new QHBoxLayout( vbox, -1, "HBox1" ); 156 QHBoxLayout *hbox3 = new QHBoxLayout( vbox, -1, "HBox1" );
156 QHBoxLayout *hbox4 = new QHBoxLayout( vbox, -1, "HBox1" ); 157 QHBoxLayout *hbox4 = new QHBoxLayout( vbox, -1, "HBox1" );
157 158
158 159
159 if ( showJumpTo ) 160 if ( showJumpTo )
160 { 161 {
161 char text[2]; 162 char text[2];
162 text[1] = '\0'; 163 text[1] = '\0';
163 for ( int i = 0 ; i < 26 ; ++i ) 164 for ( int i = 0 ; i < 26 ; ++i )
164 { 165 {
165 text[0] = 'A' + i; 166 text[0] = 'A' + i;
166 LetterPushButton *b = new LetterPushButton( text, this ); 167 LetterPushButton *b = new LetterPushButton( text, this );
167 connect( b, SIGNAL( released( QString ) ), this, SLOT( letterPushed( QString ) ) ); 168 connect( b, SIGNAL( released( QString ) ), this, SLOT( letterPushed( QString ) ) );
168 if ( i < 13 ) 169 if ( i < 13 )
169 hbox3->addWidget( b ); 170 hbox3->addWidget( b );
170 else 171 else
171 hbox4->addWidget( b ); 172 hbox4->addWidget( b );
172 } 173 }
173 } 174 }
174 175
175 vbox->addWidget( packagesList ); 176 vbox->addWidget( packagesList );
176 packagesList->addColumn( "Packages" ); 177 packagesList->addColumn( "Packages" );
177 178
178 QHBoxLayout *hbox2 = new QHBoxLayout( vbox, -1, "HBox2" ); 179 QHBoxLayout *hbox2 = new QHBoxLayout( vbox, -1, "HBox2" );
179 hbox2->addWidget( update ); 180 hbox2->addWidget( update );
180 hbox2->addWidget( download ); 181 hbox2->addWidget( download );
181 hbox2->addWidget( upgrade ); 182 hbox2->addWidget( upgrade );
182 hbox2->addWidget( apply ); 183 hbox2->addWidget( apply );
183} 184}
184 185
185void NetworkPackageManager :: setupConnections() 186void NetworkPackageManager :: setupConnections()
186{ 187{
187 connect( serversList, SIGNAL(activated( int )), this, SLOT(serverSelected( int ))); 188 connect( serversList, SIGNAL(activated( int )), this, SLOT(serverSelected( int )));
188 connect( apply, SIGNAL(released()), this, SLOT(applyChanges()) ); 189 connect( apply, SIGNAL(released()), this, SLOT(applyChanges()) );
189 connect( download, SIGNAL(released()), this, SLOT(downloadPackage()) ); 190 connect( download, SIGNAL(released()), this, SLOT(downloadPackage()) );
190 connect( upgrade, SIGNAL( released()), this, SLOT(upgradePackages()) ); 191 connect( upgrade, SIGNAL( released()), this, SLOT(upgradePackages()) );
191 connect( update, SIGNAL(released()), this, SLOT(updateServer()) ); 192 connect( update, SIGNAL(released()), this, SLOT(updateServer()) );
192} 193}
193 194
194void NetworkPackageManager :: showProgressDialog( char *initialText ) 195void NetworkPackageManager :: showProgressDialog( char *initialText )
195{ 196{
196 if ( !progressDlg ) 197 if ( !progressDlg )
197 progressDlg = new ProgressDlg( this, "Progress", false ); 198 progressDlg = new ProgressDlg( this, "Progress", false );
198 progressDlg->setText( initialText ); 199 progressDlg->setText( initialText );
199 progressDlg->show(); 200 progressDlg->show();
200} 201}
201 202
202 203
203void NetworkPackageManager :: serverSelected( int ) 204void NetworkPackageManager :: serverSelected( int )
204{ 205{
205 packagesList->clear(); 206 packagesList->clear();
206 207
207 // display packages 208 // display packages
208 QString serverName = serversList->currentText(); 209 QString serverName = serversList->currentText();
209 currentlySelectedServer = serverName; 210 currentlySelectedServer = serverName;
210 211
211#ifdef QWS 212#ifdef QWS
212 // read download directory from config file 213 // read download directory from config file
213 Config cfg( "aqpkg" ); 214 Config cfg( "aqpkg" );
214 cfg.setGroup( "settings" ); 215 cfg.setGroup( "settings" );
215 cfg.writeEntry( "selectedServer", currentlySelectedServer ); 216 cfg.writeEntry( "selectedServer", currentlySelectedServer );
216#endif 217#endif
217 218
218 Server *s = dataMgr->getServer( serverName ); 219 Server *s = dataMgr->getServer( serverName );
219 220
220 vector<Package> &list = s->getPackageList(); 221 vector<Package> &list = s->getPackageList();
221 vector<Package>::iterator it; 222 vector<Package>::iterator it;
222 for ( it = list.begin() ; it != list.end() ; ++it ) 223 for ( it = list.begin() ; it != list.end() ; ++it )
223 { 224 {
224 225
225 QString text = ""; 226 QString text = "";
226 227
227 // Apply show only uninstalled packages filter 228 // Apply show only uninstalled packages filter
228 if ( showUninstalledPkgs && it->isInstalled() ) 229 if ( showUninstalledPkgs && it->isInstalled() )
229 continue; 230 continue;
230 231
231 // Apply show only installed packages filter 232 // Apply show only installed packages filter
232 if ( showInstalledPkgs && !it->isInstalled() ) 233 if ( showInstalledPkgs && !it->isInstalled() )
233 continue; 234 continue;
234 235
235 // Apply show only new installed packages filter 236 // Apply show only new installed packages filter
236 if ( showUpgradedPkgs ) 237 if ( showUpgradedPkgs )
237 { 238 {
238 if ( !it->isInstalled() || 239 if ( !it->isInstalled() ||
239 compareVersions( it->getInstalledVersion(), it->getVersion() ) != 1 ) 240 compareVersions( it->getInstalledVersion(), it->getVersion() ) != 1 )
240 continue; 241 continue;
241 } 242 }
242 243
243 // Apply the section filter 244 // Apply the section filter
244 if ( categoryFilterEnabled && categoryFilter != "" ) 245 if ( categoryFilterEnabled && categoryFilter != "" )
245 { 246 {
246 if ( it->getSection() == "" || categoryFilter.find( it->getSection().lower() ) == -1 ) 247 if ( it->getSection() == "" || categoryFilter.find( it->getSection().lower() ) == -1 )
247 continue; 248 continue;
248 } 249 }
249 250
250 // If the local server, only display installed packages 251 // If the local server, only display installed packages
251 if ( serverName == LOCAL_SERVER && !it->isInstalled() ) 252 if ( serverName == LOCAL_SERVER && !it->isInstalled() )
252 continue; 253 continue;
253 254
254 255
255 text += it->getPackageName(); 256 text += it->getPackageName();
256 if ( it->isInstalled() ) 257 if ( it->isInstalled() )
257 { 258 {
258 text += " (installed)"; 259 text += " (installed)";
259 260
260 // If a different version of package is available, postfix it with an * 261 // If a different version of package is available, postfix it with an *
261 if ( it->getVersion() != it->getInstalledVersion() ) 262 if ( it->getVersion() != it->getInstalledVersion() )
262 { 263 {
263 264
264 if ( compareVersions( it->getInstalledVersion(), it->getVersion() ) == 1 ) 265 if ( compareVersions( it->getInstalledVersion(), it->getVersion() ) == 1 )
265 text += "*"; 266 text += "*";
266 } 267 }
267 } 268 }
268 269
269 QCheckListItem *item = new QCheckListItem( packagesList, text, QCheckListItem::CheckBox ); 270 QCheckListItem *item = new QCheckListItem( packagesList, text, QCheckListItem::CheckBox );
270 271
271 if ( it->isInstalled() ) 272 if ( it->isInstalled() )
272 { 273 {
273 QString destName = ""; 274 QString destName = "";
274 if ( it->getLocalPackage() ) 275 if ( it->getLocalPackage() )
275 { 276 {
276 if ( it->getLocalPackage()->getInstalledTo() ) 277 if ( it->getLocalPackage()->getInstalledTo() )
277 destName = it->getLocalPackage()->getInstalledTo()->getDestinationName(); 278 destName = it->getLocalPackage()->getInstalledTo()->getDestinationName();
278 } 279 }
279 else 280 else
280 { 281 {
281 if ( it->getInstalledTo() ) 282 if ( it->getInstalledTo() )
282 destName = it->getInstalledTo()->getDestinationName(); 283 destName = it->getInstalledTo()->getDestinationName();
283 } 284 }
284 if ( destName != "" ) 285 if ( destName != "" )
285 new QCheckListItem( item, QString( "Installed To - " ) + destName ); 286 new QCheckListItem( item, QString( "Installed To - " ) + destName );
286 } 287 }
287 288
288 if ( !it->isPackageStoredLocally() ) 289 if ( !it->isPackageStoredLocally() )
289 new QCheckListItem( item, QString( "Description - " ) + it->getDescription() ); 290 new QCheckListItem( item, QString( "Description - " ) + it->getDescription() );
290 else 291 else
291 new QCheckListItem( item, QString( "Filename - " ) + it->getFilename() ); 292 new QCheckListItem( item, QString( "Filename - " ) + it->getFilename() );
292 293
293 if ( serverName == LOCAL_SERVER ) 294 if ( serverName == LOCAL_SERVER )
294 { 295 {
295 new QCheckListItem( item, QString( "V. Installed - " ) + it->getVersion() ); 296 new QCheckListItem( item, QString( "V. Installed - " ) + it->getVersion() );
296 } 297 }
297 else 298 else
298 { 299 {
299 new QCheckListItem( item, QString( "V. Available - " ) + it->getVersion() ); 300 new QCheckListItem( item, QString( "V. Available - " ) + it->getVersion() );
300 if ( it->getLocalPackage() ) 301 if ( it->getLocalPackage() )
301 { 302 {
302 if ( it->isInstalled() ) 303 if ( it->isInstalled() )
303 new QCheckListItem( item, QString( "V. Installed - " ) + it->getInstalledVersion() ); 304 new QCheckListItem( item, QString( "V. Installed - " ) + it->getInstalledVersion() );
304 } 305 }
305 } 306 }
306 307
307 new QCheckListItem( item, QString( "Size - " ) + it->getPackageSize() ); 308 new QCheckListItem( item, QString( "Size - " ) + it->getPackageSize() );
308 new QCheckListItem( item, QString( "Section - " ) + it->getSection() ); 309 new QCheckListItem( item, QString( "Section - " ) + it->getSection() );
309 packagesList->insertItem( item ); 310 packagesList->insertItem( item );
310 } 311 }
311 312
312 // If the local server or the local ipkgs server disable the download button 313 // If the local server or the local ipkgs server disable the download button
313 if ( serverName == LOCAL_SERVER ) 314 if ( serverName == LOCAL_SERVER )
314 { 315 {
315 upgrade->setEnabled( false ); 316 upgrade->setEnabled( false );
316 download->setText( "Download" ); 317 download->setText( "Download" );
317 download->setEnabled( true ); 318 download->setEnabled( true );
318 } 319 }
319 else if ( serverName == LOCAL_IPKGS ) 320 else if ( serverName == LOCAL_IPKGS )
320 { 321 {
321 upgrade->setEnabled( false ); 322 upgrade->setEnabled( false );
322 download->setEnabled( true ); 323 download->setEnabled( true );
323 download->setText( "Remove" ); 324 download->setText( "Remove" );
324 } 325 }
325 else 326 else
326 { 327 {
327 upgrade->setEnabled( true ); 328 upgrade->setEnabled( true );
328 download->setEnabled( true ); 329 download->setEnabled( true );
329 download->setText( "Download" ); 330 download->setText( "Download" );
330 } 331 }
331} 332}
332 333
333void NetworkPackageManager :: updateServer() 334void NetworkPackageManager :: updateServer()
334{ 335{
335 QString serverName = serversList->currentText(); 336 QString serverName = serversList->currentText();
336 337
337 // Update the current server 338 // Update the current server
338 // Display dialog 339 // Display dialog
339 340
340 // Disable buttons to stop silly people clicking lots on them :) 341 // Disable buttons to stop silly people clicking lots on them :)
341 342
342 // First, write out ipkg_conf file so that ipkg can use it 343 // First, write out ipkg_conf file so that ipkg can use it
343 dataMgr->writeOutIpkgConf(); 344 dataMgr->writeOutIpkgConf();
344 345
345 Ipkg ipkg; 346 Ipkg ipkg;
346 ipkg.setOption( "update" ); 347 ipkg.setOption( "update" );
347 348
348 InstallDlgImpl dlg( &ipkg, "Refreshing server package lists", this, "Upgrade", true ); 349 InstallDlgImpl dlg( &ipkg, "Refreshing server package lists", this, "Upgrade", true );
349 dlg.showDlg(); 350 dlg.showDlg();
350 351
351 // Reload data 352 // Reload data
352 dataMgr->reloadServerData(); 353 dataMgr->reloadServerData();
353 serverSelected(-1); 354 serverSelected(-1);
354// delete progDlg; 355// delete progDlg;
355} 356}
356 357
357void NetworkPackageManager :: upgradePackages() 358void NetworkPackageManager :: upgradePackages()
358{ 359{
359 // We're gonna do an upgrade of all packages 360 // We're gonna do an upgrade of all packages
360 // First warn user that this isn't recommended 361 // First warn user that this isn't recommended
361 QString text = "WARNING: Upgrading while\nOpie/Qtopia is running\nis NOT recommended!\n\nAre you sure?\n"; 362 QString text = "WARNING: Upgrading while\nOpie/Qtopia is running\nis NOT recommended!\n\nAre you sure?\n";
362 QMessageBox warn("Warning", text, QMessageBox::Warning, 363 QMessageBox warn("Warning", text, QMessageBox::Warning,
363 QMessageBox::Yes, 364 QMessageBox::Yes,
364 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default , 365 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default ,
365 0, this ); 366 0, this );
366 warn.adjustSize(); 367 warn.adjustSize();
367 368
368 if ( warn.exec() == QMessageBox::Yes ) 369 if ( warn.exec() == QMessageBox::Yes )
369 { 370 {
370 // First, write out ipkg_conf file so that ipkg can use it 371 // First, write out ipkg_conf file so that ipkg can use it
371 dataMgr->writeOutIpkgConf(); 372 dataMgr->writeOutIpkgConf();
372 373
373 // Now run upgrade 374 // Now run upgrade
374 Ipkg ipkg; 375 Ipkg ipkg;
375 ipkg.setOption( "upgrade" ); 376 ipkg.setOption( "upgrade" );
376 377
377 InstallDlgImpl dlg( &ipkg, "Upgrading installed packages", this, "Upgrade", true ); 378 InstallDlgImpl dlg( &ipkg, "Upgrading installed packages", this, "Upgrade", true );
378 dlg.showDlg(); 379 dlg.showDlg();
379 380
380 // Reload data 381 // Reload data
381 dataMgr->reloadServerData(); 382 dataMgr->reloadServerData();
382 serverSelected(-1); 383 serverSelected(-1);
383 } 384 }
384} 385}
385 386
386 387
387void NetworkPackageManager :: downloadPackage() 388void NetworkPackageManager :: downloadPackage()
388{ 389{
389 bool doUpdate = true; 390 bool doUpdate = true;
390 if ( download->text() == "Download" ) 391 if ( download->text() == "Download" )
391 { 392 {
392 // See if any packages are selected 393 // See if any packages are selected
393 bool found = false; 394 bool found = false;
394 if ( serversList->currentText() != LOCAL_SERVER ) 395 if ( serversList->currentText() != LOCAL_SERVER )
395 { 396 {
396 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); 397 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild();
397 item != 0 && !found; 398 item != 0 && !found;
398 item = (QCheckListItem *)item->nextSibling() ) 399 item = (QCheckListItem *)item->nextSibling() )
399 { 400 {
400 if ( item->isOn() ) 401 if ( item->isOn() )
401 found = true; 402 found = true;
402 } 403 }
403 } 404 }
404 405
405 // If user selected some packages then download the and store the locally 406 // If user selected some packages then download the and store the locally
406 // otherwise, display dialog asking user what package to download from an http server 407 // otherwise, display dialog asking user what package to download from an http server
407 // and whether to install it 408 // and whether to install it
408 if ( found ) 409 if ( found )
409 downloadSelectedPackages(); 410 downloadSelectedPackages();
410 else 411 else
411 downloadRemotePackage(); 412 downloadRemotePackage();
412 413
413 } 414 }
414 else if ( download->text() == "Remove" ) 415 else if ( download->text() == "Remove" )
415 { 416 {
416 doUpdate = false; 417 doUpdate = false;
417 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); 418 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild();
418 item != 0 ; 419 item != 0 ;
419 item = (QCheckListItem *)item->nextSibling() ) 420 item = (QCheckListItem *)item->nextSibling() )
420 { 421 {
421 if ( item->isOn() ) 422 if ( item->isOn() )
422 { 423 {
423 QString name = item->text(); 424 QString name = item->text();
424 int pos = name.find( "*" ); 425 int pos = name.find( "*" );
425 name.truncate( pos ); 426 name.truncate( pos );
426 427
427 // if (there is a (installed), remove it 428 // if (there is a (installed), remove it
428 pos = name.find( "(installed)" ); 429 pos = name.find( "(installed)" );
429 if ( pos > 0 ) 430 if ( pos > 0 )
430 name.truncate( pos - 1 ); 431 name.truncate( pos - 1 );
431 432
432 Package *p = dataMgr->getServer( serversList->currentText() )->getPackage( name ); 433 Package *p = dataMgr->getServer( serversList->currentText() )->getPackage( name );
433 434
434 QString msgtext; 435 QString msgtext;
435 msgtext.sprintf( "Are you sure you wish to delete\n%s?", (const char *)p->getPackageName() ); 436 msgtext.sprintf( "Are you sure you wish to delete\n%s?", (const char *)p->getPackageName() );
436 if ( QMessageBox::information( this, "Are you sure?", 437 if ( QMessageBox::information( this, "Are you sure?",
437 msgtext, "No", "Yes" ) == 1 ) 438 msgtext, "No", "Yes" ) == 1 )
438 { 439 {
439 doUpdate = true; 440 doUpdate = true;
440 QFile f( p->getFilename() ); 441 QFile f( p->getFilename() );
441 f.remove(); 442 f.remove();
442 } 443 }
443 } 444 }
444 } 445 }
445 } 446 }
446 447
447 if ( doUpdate ) 448 if ( doUpdate )
448 { 449 {
449 dataMgr->reloadServerData(); 450 dataMgr->reloadServerData();
450 serverSelected( -1 ); 451 serverSelected( -1 );
451 } 452 }
452} 453}
453 454
454void NetworkPackageManager :: downloadSelectedPackages() 455void NetworkPackageManager :: downloadSelectedPackages()
455{ 456{
456 // First, write out ipkg_conf file so that ipkg can use it 457 // First, write out ipkg_conf file so that ipkg can use it
457 dataMgr->writeOutIpkgConf(); 458 dataMgr->writeOutIpkgConf();
458 459
459 // Display dialog to user asking where to download the files to 460 // Display dialog to user asking where to download the files to
460 bool ok = FALSE; 461 bool ok = FALSE;
461 QString dir = ""; 462 QString dir = "";
462#ifdef QWS 463#ifdef QWS
463 // read download directory from config file 464 // read download directory from config file
464 Config cfg( "aqpkg" ); 465 Config cfg( "aqpkg" );
465 cfg.setGroup( "settings" ); 466 cfg.setGroup( "settings" );
466 dir = cfg.readEntry( "downloadDir", "/home/root/Documents/application/ipkg" ); 467 dir = cfg.readEntry( "downloadDir", "/home/root/Documents/application/ipkg" );
467#endif 468#endif
468 469
469 QString text = InputDialog::getText( tr( "Download to where" ), tr( "Enter path to download to" ), dir, &ok, this ); 470 QString text = InputDialog::getText( tr( "Download to where" ), tr( "Enter path to download to" ), dir, &ok, this );
470 if ( ok && !text.isEmpty() ) 471 if ( ok && !text.isEmpty() )
471 dir = text; // user entered something and pressed ok 472 dir = text; // user entered something and pressed ok
472 else 473 else
473 return; // user entered nothing or pressed cancel 474 return; // user entered nothing or pressed cancel
474 475
475#ifdef QWS 476#ifdef QWS
476 // Store download directory in config file 477 // Store download directory in config file
477 cfg.writeEntry( "downloadDir", dir ); 478 cfg.writeEntry( "downloadDir", dir );
478#endif 479#endif
479 480
480 // Get starting directory 481 // Get starting directory
481 char initDir[PATH_MAX]; 482 char initDir[PATH_MAX];
482 getcwd( initDir, PATH_MAX ); 483 getcwd( initDir, PATH_MAX );
483 484
484 // Download each package 485 // Download each package
485 Ipkg ipkg; 486 Ipkg ipkg;
486 connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); 487 connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &)));
487 488
488 ipkg.setOption( "download" ); 489 ipkg.setOption( "download" );
489 ipkg.setRuntimeDirectory( dir ); 490 ipkg.setRuntimeDirectory( dir );
490 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); 491 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild();
491 item != 0 ; 492 item != 0 ;
492 item = (QCheckListItem *)item->nextSibling() ) 493 item = (QCheckListItem *)item->nextSibling() )
493 { 494 {
494 if ( item->isOn() ) 495 if ( item->isOn() )
495 { 496 {
496 QString name = item->text(); 497 QString name = item->text();
497 int pos = name.find( "*" ); 498 int pos = name.find( "*" );
498 name.truncate( pos ); 499 name.truncate( pos );
499 500
500 // if (there is a (installed), remove it 501 // if (there is a (installed), remove it
501 pos = name.find( "(installed)" ); 502 pos = name.find( "(installed)" );
502 if ( pos > 0 ) 503 if ( pos > 0 )
503 name.truncate( pos - 1 ); 504 name.truncate( pos - 1 );
504 505
505 ipkg.setPackage( name ); 506 ipkg.setPackage( name );
506 ipkg.runIpkg( ); 507 ipkg.runIpkg( );
507 } 508 }
508 } 509 }
509} 510}
510 511
511void NetworkPackageManager :: downloadRemotePackage() 512void NetworkPackageManager :: downloadRemotePackage()
512{ 513{
513 // Display dialog 514 // Display dialog
514 bool ok; 515 bool ok;
515 QString package = InputDialog::getText( "Install Remote Package", tr( "Enter package location" ), "http://", &ok, this ); 516 QString package = InputDialog::getText( "Install Remote Package", tr( "Enter package location" ), "http://", &ok, this );
516 if ( !ok || package.isEmpty() ) 517 if ( !ok || package.isEmpty() )
517 return; 518 return;
518// DownloadRemoteDlgImpl dlg( this, "Install", true ); 519// DownloadRemoteDlgImpl dlg( this, "Install", true );
519// if ( dlg.exec() == QDialog::Rejected ) 520// if ( dlg.exec() == QDialog::Rejected )
520// return; 521// return;
521 522
522 // grab details from dialog 523 // grab details from dialog
523// QString package = dlg.getPackageLocation(); 524// QString package = dlg.getPackageLocation();
524 525
525 InstallData item; 526 InstallData item;
526 item.option = "I"; 527 item.option = "I";
527 item.packageName = package; 528 item.packageName = package;
528 vector<InstallData> workingPackages; 529 vector<InstallData> workingPackages;
529 workingPackages.push_back( item ); 530 workingPackages.push_back( item );
530 531
531 InstallDlgImpl dlg2( workingPackages, dataMgr, this, "Install", true ); 532 InstallDlgImpl dlg2( workingPackages, dataMgr, this, "Install", true );
532 dlg2.showDlg(); 533 dlg2.showDlg();
533 534
534 // Reload data 535 // Reload data
535 dataMgr->reloadServerData(); 536 dataMgr->reloadServerData();
536 serverSelected(-1); 537 serverSelected(-1);
537 538
538#ifdef QWS 539#ifdef QWS
539 // Finally let the main system update itself 540 // Finally let the main system update itself
540 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 541 QCopEnvelope e("QPE/System", "linkChanged(QString)");
541 QString lf = QString::null; 542 QString lf = QString::null;
542 e << lf; 543 e << lf;
543#endif 544#endif
544} 545}
545 546
546 547
547void NetworkPackageManager :: applyChanges() 548void NetworkPackageManager :: applyChanges()
548{ 549{
549 stickyOption = ""; 550 stickyOption = "";
550 551
551 // First, write out ipkg_conf file so that ipkg can use it 552 // First, write out ipkg_conf file so that ipkg can use it
552 dataMgr->writeOutIpkgConf(); 553 dataMgr->writeOutIpkgConf();
553 554
554 // Now for each selected item 555 // Now for each selected item
555 // deal with it 556 // deal with it
556 557
557 vector<InstallData> workingPackages; 558 vector<InstallData> workingPackages;
558 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); 559 for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild();
559 item != 0 ; 560 item != 0 ;
560 item = (QCheckListItem *)item->nextSibling() ) 561 item = (QCheckListItem *)item->nextSibling() )
561 { 562 {
562 if ( item->isOn() ) 563 if ( item->isOn() )
563 { 564 {
564 InstallData data = dealWithItem( item ); 565 InstallData data = dealWithItem( item );
565 workingPackages.push_back( data ); 566 workingPackages.push_back( data );
566 } 567 }
567 } 568 }
568 569
569 if ( workingPackages.size() == 0 ) 570 if ( workingPackages.size() == 0 )
570 { 571 {
571 // Nothing to do 572 // Nothing to do
572 QMessageBox::information( this, "Nothing to do", 573 QMessageBox::information( this, "Nothing to do",
573 "No packages selected", "OK" ); 574 "No packages selected", "OK" );
574 575
575 return; 576 return;
576 } 577 }
577 578
578 // do the stuff 579 // do the stuff
579 InstallDlgImpl dlg( workingPackages, dataMgr, this, "Install", true ); 580 InstallDlgImpl dlg( workingPackages, dataMgr, this, "Install", true );
580 dlg.showDlg(); 581 dlg.showDlg();
581 582
582 // Reload data 583 // Reload data
583 dataMgr->reloadServerData(); 584 dataMgr->reloadServerData();
584 serverSelected(-1); 585 serverSelected(-1);
585 586
586#ifdef QWS 587#ifdef QWS
587 // Finally let the main system update itself 588 // Finally let the main system update itself
588 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 589 QCopEnvelope e("QPE/System", "linkChanged(QString)");
589 QString lf = QString::null; 590 QString lf = QString::null;
590 e << lf; 591 e << lf;
591#endif 592#endif
592} 593}
593 594
594// decide what to do - either remove, upgrade or install 595// decide what to do - either remove, upgrade or install
595// Current rules: 596// Current rules:
596// If not installed - install 597// If not installed - install
597// If installed and different version available - upgrade 598// If installed and different version available - upgrade
598// If installed and version up to date - remove 599// If installed and version up to date - remove
599InstallData NetworkPackageManager :: dealWithItem( QCheckListItem *item ) 600InstallData NetworkPackageManager :: dealWithItem( QCheckListItem *item )
600{ 601{
601 QString name = item->text(); 602 QString name = item->text();
602 int pos = name.find( "*" ); 603 int pos = name.find( "*" );
603 name.truncate( pos ); 604 name.truncate( pos );
604 605
605 // if (there is a (installed), remove it 606 // if (there is a (installed), remove it
606 pos = name.find( "(installed)" ); 607 pos = name.find( "(installed)" );
607 if ( pos > 0 ) 608 if ( pos > 0 )
608 name.truncate( pos - 1 ); 609 name.truncate( pos - 1 );
609 610
610 // Get package 611 // Get package
611 Server *s = dataMgr->getServer( serversList->currentText() ); 612 Server *s = dataMgr->getServer( serversList->currentText() );
612 Package *p = s->getPackage( name ); 613 Package *p = s->getPackage( name );
613 614
614 // If the package has a filename then it is a local file 615 // If the package has a filename then it is a local file
615 if ( p->isPackageStoredLocally() ) 616 if ( p->isPackageStoredLocally() )
616 name = p->getFilename(); 617 name = p->getFilename();
617 618
618 QString option; 619 QString option;
619 QString dest = "root"; 620 QString dest = "root";
620 if ( !p->isInstalled() ) 621 if ( !p->isInstalled() )
621 { 622 {
622 InstallData item; 623 InstallData item;
623 item.option = "I"; 624 item.option = "I";
624 item.packageName = name; 625 item.packageName = name;
625 return item; 626 return item;
626 } 627 }
627 else 628 else
628 { 629 {
629 InstallData item; 630 InstallData item;
630 item.option = "D"; 631 item.option = "D";
631 if ( !p->isPackageStoredLocally() ) 632 if ( !p->isPackageStoredLocally() )
632 item.packageName = p->getInstalledPackageName(); 633 item.packageName = p->getInstalledPackageName();
633 else 634 else
634 item.packageName = name; 635 item.packageName = name;
635 636
636 if ( p->getInstalledTo() ) 637 if ( p->getInstalledTo() )
637 { 638 {
638 item.destination = p->getInstalledTo(); 639 item.destination = p->getInstalledTo();
639 cout << "dest - " << p->getInstalledTo()->getDestinationName() << endl; 640 cout << "dest - " << p->getInstalledTo()->getDestinationName() << endl;
640 cout << "dest - " << p->getInstalledTo()->getDestinationPath() << endl; 641 cout << "dest - " << p->getInstalledTo()->getDestinationPath() << endl;
641 } 642 }
642 else 643 else
643 { 644 {
644 item.destination = p->getLocalPackage()->getInstalledTo(); 645 item.destination = p->getLocalPackage()->getInstalledTo();
645 } 646 }
646 647
647 // Now see if version is newer or not 648 // Now see if version is newer or not
648 int val = compareVersions( p->getInstalledVersion(), p->getVersion() ); 649 int val = compareVersions( p->getInstalledVersion(), p->getVersion() );
649 650
650 // If the version requested is older and user selected a local ipk file, then reinstall the file 651 // If the version requested is older and user selected a local ipk file, then reinstall the file
651 if ( p->isPackageStoredLocally() && val == -1 ) 652 if ( p->isPackageStoredLocally() && val == -1 )
652 val = 0; 653 val = 0;
653 654
654 if ( val == -2 ) 655 if ( val == -2 )
655 { 656 {
656 // Error - should handle 657 // Error - should handle
657 } 658 }
658 else if ( val == -1 ) 659 else if ( val == -1 )
659 { 660 {
660 // Version available is older - remove only 661 // Version available is older - remove only
661 item.option = "D"; 662 item.option = "D";
662 } 663 }
663 else 664 else
664 { 665 {
665 QString caption; 666 QString caption;
666 QString text; 667 QString text;
667 QString secondButton; 668 QString secondButton;
668 QString secondOption; 669 QString secondOption;
669 if ( val == 0 ) 670 if ( val == 0 )
670 { 671 {
671 // Version available is the same - option to remove or reinstall 672 // Version available is the same - option to remove or reinstall
672 caption = "Do you wish to remove or reinstall\n%s?"; 673 caption = "Do you wish to remove or reinstall\n%s?";
673 text = "Remove or ReInstall"; 674 text = "Remove or ReInstall";
674 secondButton = "ReInstall"; 675 secondButton = "ReInstall";
675 secondOption = "R"; 676 secondOption = "R";
676 } 677 }
677 else if ( val == 1 ) 678 else if ( val == 1 )
678 { 679 {
679 // Version available is newer - option to remove or upgrade 680 // Version available is newer - option to remove or upgrade
680 caption = "Do you wish to remove or upgrade\n%s?"; 681 caption = "Do you wish to remove or upgrade\n%s?";
681 text = "Remove or Upgrade"; 682 text = "Remove or Upgrade";
682 secondButton = "Upgrade"; 683 secondButton = "Upgrade";
683 secondOption = "U"; 684 secondOption = "U";
684 } 685 }
685 686
686 // Sticky option not implemented yet, but will eventually allow 687 // Sticky option not implemented yet, but will eventually allow
687 // the user to say something like 'remove all' 688 // the user to say something like 'remove all'
688 if ( stickyOption == "" ) 689 if ( stickyOption == "" )
689 { 690 {
690 QString msgtext; 691 QString msgtext;
691 msgtext.sprintf( caption, (const char *)name ); 692 msgtext.sprintf( caption, (const char *)name );
692 switch( QMessageBox::information( this, text, 693 switch( QMessageBox::information( this, text,
693 msgtext, "Remove", secondButton ) ) 694 msgtext, "Remove", secondButton ) )
694 { 695 {
695 case 0: // Try again or Enter 696 case 0: // Try again or Enter
696 // option 0 = Remove 697 // option 0 = Remove
697 item.option = "D"; 698 item.option = "D";
698 break; 699 break;
699 case 1: // Quit or Escape 700 case 1: // Quit or Escape
700 item.option = secondOption; 701 item.option = secondOption;
701 break; 702 break;
702 } 703 }
703 } 704 }
704 else 705 else
705 { 706 {
706// item.option = stickyOption; 707// item.option = stickyOption;
707 } 708 }
708 } 709 }
709 710
710 711
711 // Check if we are reinstalling the same version 712 // Check if we are reinstalling the same version
712 if ( item.option != "R" ) 713 if ( item.option != "R" )
713 item.recreateLinks = true; 714 item.recreateLinks = true;
714 else 715 else
715 item.recreateLinks = false; 716 item.recreateLinks = false;
716 717
717 // User hit cancel (on dlg - assume remove) 718 // User hit cancel (on dlg - assume remove)
718 return item; 719 return item;
719 } 720 }
720} 721}
721 722
722void NetworkPackageManager :: displayText( const QString &t ) 723void NetworkPackageManager :: displayText( const QString &t )
723{ 724{
724 cout << t << endl; 725 cout << t << endl;
725} 726}
726 727
727 728
728void NetworkPackageManager :: letterPushed( QString t ) 729void NetworkPackageManager :: letterPushed( QString t )
729{ 730{
730 QCheckListItem *top = (QCheckListItem *)packagesList->firstChild(); 731 QCheckListItem *top = (QCheckListItem *)packagesList->firstChild();
731 QCheckListItem *start = (QCheckListItem *)packagesList->currentItem(); 732 QCheckListItem *start = (QCheckListItem *)packagesList->currentItem();
732 if ( packagesList->firstChild() == 0 ) 733 if ( packagesList->firstChild() == 0 )
733 return; 734 return;
734 735
735 QCheckListItem *item; 736 QCheckListItem *item;
736 if ( start == 0 ) 737 if ( start == 0 )
737 { 738 {
738 item = (QCheckListItem *)packagesList->firstChild(); 739 item = (QCheckListItem *)packagesList->firstChild();
739 start = top; 740 start = top;
740 } 741 }
741 else 742 else
742 item = (QCheckListItem *)start->nextSibling(); 743 item = (QCheckListItem *)start->nextSibling();
743 744
744 if ( item == 0 ) 745 if ( item == 0 )
745 item = (QCheckListItem *)packagesList->firstChild(); 746 item = (QCheckListItem *)packagesList->firstChild();
746 do 747 do
747 { 748 {
748 if ( item->text().lower().startsWith( t.lower() ) ) 749 if ( item->text().lower().startsWith( t.lower() ) )
749 { 750 {
750 packagesList->setSelected( item, true ); 751 packagesList->setSelected( item, true );
751 packagesList->ensureItemVisible( item ); 752 packagesList->ensureItemVisible( item );
752 break; 753 break;
753 } 754 }
754 755
755 item = (QCheckListItem *)item->nextSibling(); 756 item = (QCheckListItem *)item->nextSibling();
756 if ( !item ) 757 if ( !item )
757 item = (QCheckListItem *)packagesList->firstChild(); 758 item = (QCheckListItem *)packagesList->firstChild();
758 } while ( item != start); 759 } while ( item != start);
759} 760}
760 761
761 762
762void NetworkPackageManager :: searchForPackage( bool findNext ) 763void NetworkPackageManager :: searchForPackage( bool findNext )
763{ 764{
764 bool ok = false; 765 bool ok = false;
765 if ( !findNext || lastSearchText.isEmpty() ) 766 if ( !findNext || lastSearchText.isEmpty() )
766 lastSearchText = InputDialog::getText( "Search for package", "Enter package to search for", lastSearchText, &ok, this ).lower(); 767 lastSearchText = InputDialog::getText( "Search for package", "Enter package to search for", lastSearchText, &ok, this ).lower();
767 else 768 else
768 ok = true; 769 ok = true;
769 770
770 if ( ok && !lastSearchText.isEmpty() ) 771 if ( ok && !lastSearchText.isEmpty() )
771 { 772 {
772 cout << "searching for " << lastSearchText << endl; 773 cout << "searching for " << lastSearchText << endl;
773 // look through package list for text startng at current position 774 // look through package list for text startng at current position
774 vector<InstallData> workingPackages; 775 vector<InstallData> workingPackages;
775 QCheckListItem *start = (QCheckListItem *)packagesList->currentItem(); 776 QCheckListItem *start = (QCheckListItem *)packagesList->currentItem();
776 if ( start != 0 ) 777 if ( start != 0 )
777 start = (QCheckListItem *)start->nextSibling(); 778 start = (QCheckListItem *)start->nextSibling();
778 779
779 if ( start == 0 ) 780 if ( start == 0 )
780 start = (QCheckListItem *)packagesList->firstChild(); 781 start = (QCheckListItem *)packagesList->firstChild();
781 782
782 for ( QCheckListItem *item = start; item != 0 ; 783 for ( QCheckListItem *item = start; item != 0 ;
783 item = (QCheckListItem *)item->nextSibling() ) 784 item = (QCheckListItem *)item->nextSibling() )
784 { 785 {
785 cout << "checking " << item->text().lower() << endl; 786 cout << "checking " << item->text().lower() << endl;
786 if ( item->text().lower().find( lastSearchText ) != -1 ) 787 if ( item->text().lower().find( lastSearchText ) != -1 )
787 { 788 {
788 cout << "matched " << item->text() << endl; 789 cout << "matched " << item->text() << endl;
789 packagesList->ensureItemVisible( item ); 790 packagesList->ensureItemVisible( item );
790 packagesList->setCurrentItem( item ); 791 packagesList->setCurrentItem( item );
791 break; 792 break;
792 } 793 }
793 } 794 }
794 } 795 }
795} 796}
796 797
797void NetworkPackageManager :: showOnlyUninstalledPackages( bool val ) 798void NetworkPackageManager :: showOnlyUninstalledPackages( bool val )
798{ 799{
799 showUninstalledPkgs = val; 800 showUninstalledPkgs = val;
800 serverSelected( -1 ); 801 serverSelected( -1 );
801} 802}
802 803
803void NetworkPackageManager :: showOnlyInstalledPackages( bool val ) 804void NetworkPackageManager :: showOnlyInstalledPackages( bool val )
804{ 805{
805 showInstalledPkgs = val; 806 showInstalledPkgs = val;
806 serverSelected( -1 ); 807 serverSelected( -1 );
807} 808}
808 809
809void NetworkPackageManager :: showUpgradedPackages( bool val ) 810void NetworkPackageManager :: showUpgradedPackages( bool val )
810{ 811{
811 showUpgradedPkgs = val; 812 showUpgradedPkgs = val;
812 serverSelected( -1 ); 813 serverSelected( -1 );
813} 814}
814 815
815bool NetworkPackageManager :: filterByCategory( bool val ) 816bool NetworkPackageManager :: filterByCategory( bool val )
816{ 817{
817 if ( val ) 818 if ( val )
818 { 819 {
819 if ( categoryFilter == "" ) 820 if ( categoryFilter == "" )
820 { 821 {
821 if ( !setFilterCategory() ) 822 if ( !setFilterCategory() )
822 return false; 823 return false;
823 } 824 }
824 825
825 categoryFilterEnabled = true; 826 categoryFilterEnabled = true;
826 serverSelected( -1 ); 827 serverSelected( -1 );
827 return true; 828 return true;
828 } 829 }
829 else 830 else
830 { 831 {
831 // Turn off filter 832 // Turn off filter
832 categoryFilterEnabled = false; 833 categoryFilterEnabled = false;
833 serverSelected( -1 ); 834 serverSelected( -1 );
834 return false; 835 return false;
835 } 836 }
836} 837}
837 838
838bool NetworkPackageManager :: setFilterCategory( ) 839bool NetworkPackageManager :: setFilterCategory( )
839{ 840{
840 // Get categories; 841 // Get categories;
841 CategoryFilterImpl dlg( DataManager::getAvailableCategories(), categoryFilter, this ); 842 CategoryFilterImpl dlg( DataManager::getAvailableCategories(), categoryFilter, this );
842 if ( dlg.exec() == QDialog::Accepted ) 843 if ( dlg.exec() == QDialog::Accepted )
843 { 844 {
844 categoryFilter = dlg.getSelectedFilter(); 845 categoryFilter = dlg.getSelectedFilter();
845 846
846 if ( categoryFilter == "" ) 847 if ( categoryFilter == "" )
847 return false; 848 return false;
848 849
849 categoryFilterEnabled = true; 850 categoryFilterEnabled = true;
850 serverSelected( -1 ); 851 serverSelected( -1 );
851 return true; 852 return true;
852 } 853 }
853 854
854 return false; 855 return false;
855} 856}
diff --git a/noncore/settings/aqpkg/server.cpp b/noncore/settings/aqpkg/server.cpp
index 726cf00..58407d5 100644
--- a/noncore/settings/aqpkg/server.cpp
+++ b/noncore/settings/aqpkg/server.cpp
@@ -1,306 +1,307 @@
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#include "datamgr.h" 31#include "datamgr.h"
32 32
33#ifdef QWS 33#ifdef QWS
34#include <qpe/global.h> 34#include <qpe/global.h>
35#include <qpe/applnk.h> 35#include <qpe/applnk.h>
36#include <qlist.h> 36#include <qlist.h>
37#endif 37#endif
38 38
39#include "utils.h" 39#include "utils.h"
40 40
41#include "global.h" 41#include "global.h"
42 42
43Server :: Server( const char *name, const char *url ) 43Server :: Server( const char *name, const char *url )
44{ 44{
45 serverName = name; 45 serverName = name;
46 serverUrl = url; 46 serverUrl = url;
47 packageFile = IPKG_DIR; 47 packageFile = IPKG_DIR;
48 active = true;
48 packageFile += "lists/" + serverName; 49 packageFile += "lists/" + serverName;
49} 50}
50 51
51Server :: ~Server() 52Server :: ~Server()
52{ 53{
53 cleanUp(); 54 cleanUp();
54} 55}
55 56
56void Server :: cleanUp() 57void Server :: cleanUp()
57{ 58{
58 packageList.clear(); 59 packageList.clear();
59} 60}
60 61
61void Server :: readStatusFile( vector<Destination> &destList ) 62void Server :: readStatusFile( vector<Destination> &destList )
62{ 63{
63 cleanUp(); 64 cleanUp();
64 65
65 vector<Destination>::iterator dit; 66 vector<Destination>::iterator dit;
66 bool rootRead = false; 67 bool rootRead = false;
67 for ( dit = destList.begin() ; dit != destList.end() ; ++dit ) 68 for ( dit = destList.begin() ; dit != destList.end() ; ++dit )
68 { 69 {
69 bool installingToRoot = false; 70 bool installingToRoot = false;
70 71
71 QString path = dit->getDestinationPath(); 72 QString path = dit->getDestinationPath();
72 if ( path.right( 1 ) != "/" ) 73 if ( path.right( 1 ) != "/" )
73 path += "/"; 74 path += "/";
74 75
75 if ( path == "/" ) 76 if ( path == "/" )
76 { 77 {
77 rootRead = true; 78 rootRead = true;
78 installingToRoot = true; 79 installingToRoot = true;
79 } 80 }
80 81
81 packageFile = path + "usr/lib/ipkg/status"; 82 packageFile = path + "usr/lib/ipkg/status";
82 readPackageFile( 0, false, installingToRoot, dit ); 83 readPackageFile( 0, false, installingToRoot, dit );
83 } 84 }
84 85
85 // Ensure that the root status file is read 86 // Ensure that the root status file is read
86 if ( !rootRead ) 87 if ( !rootRead )
87 { 88 {
88 cout << "Reading status file " << "/usr/lib/ipkg/status" << endl; 89 cout << "Reading status file " << "/usr/lib/ipkg/status" << endl;
89 packageFile = "/usr/lib/ipkg/status"; 90 packageFile = "/usr/lib/ipkg/status";
90 readPackageFile( 0, false, true ); 91 readPackageFile( 0, false, true );
91 } 92 }
92} 93}
93 94
94void Server :: readLocalIpks( Server *local ) 95void Server :: readLocalIpks( Server *local )
95{ 96{
96 cleanUp(); 97 cleanUp();
97 98
98#ifdef QWS 99#ifdef QWS
99 // First, get any local IPKGs in the documents area 100 // First, get any local IPKGs in the documents area
100 // Only applicable to Qtopie/Opie 101 // Only applicable to Qtopie/Opie
101 102
102 DocLnkSet files; 103 DocLnkSet files;
103 Global::findDocuments( &files, "application/ipkg" ); 104 Global::findDocuments( &files, "application/ipkg" );
104 105
105 // Now add the items to the list 106 // Now add the items to the list
106 QListIterator<DocLnk> it( files.children() ); 107 QListIterator<DocLnk> it( files.children() );
107 108
108 for ( ; it.current() ; ++it ) 109 for ( ; it.current() ; ++it )
109 { 110 {
110 // OK, we have a local IPK file, I think the standard naming conventions 111 // OK, we have a local IPK file, I think the standard naming conventions
111 // for these are packagename_version_arm.ipk 112 // for these are packagename_version_arm.ipk
112 QString file = (*it)->file(); 113 QString file = (*it)->file();
113 114
114 // Changed to display the filename (excluding the path) 115 // Changed to display the filename (excluding the path)
115 QString packageName = Utils::getFilenameFromIpkFilename( file ); 116 QString packageName = Utils::getFilenameFromIpkFilename( file );
116 QString ver = Utils::getPackageVersionFromIpkFilename( file ); 117 QString ver = Utils::getPackageVersionFromIpkFilename( file );
117 packageList.push_back( Package( packageName ) ); 118 packageList.push_back( Package( packageName ) );
118 packageList.back().setVersion( ver ); 119 packageList.back().setVersion( ver );
119 packageList.back().setFilename( file ); 120 packageList.back().setFilename( file );
120 packageList.back().setPackageStoredLocally( true ); 121 packageList.back().setPackageStoredLocally( true );
121 122
122 } 123 }
123#else 124#else
124 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" }; 125 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" };
125 for ( int i = 0 ; i < 4 ; ++i ) 126 for ( int i = 0 ; i < 4 ; ++i )
126 { 127 {
127 // OK, we have a local IPK file, I think the standard naming conventions 128 // OK, we have a local IPK file, I think the standard naming conventions
128 // for these are packagename_version_arm.ipk 129 // for these are packagename_version_arm.ipk
129 QString file = names[i]; 130 QString file = names[i];
130 int p = file.find( "_" ); 131 int p = file.find( "_" );
131 QString tmp = file.mid( 0, p ); 132 QString tmp = file.mid( 0, p );
132 packageList.push_back( Package( tmp ) ); 133 packageList.push_back( Package( tmp ) );
133 int p2 = file.find( "_", p+1 ); 134 int p2 = file.find( "_", p+1 );
134 tmp = file.mid( p+1, p2-(p+1) ); 135 tmp = file.mid( p+1, p2-(p+1) );
135 packageList.back().setVersion( tmp ); 136 packageList.back().setVersion( tmp );
136 packageList.back().setPackageStoredLocally( true ); 137 packageList.back().setPackageStoredLocally( true );
137 } 138 }
138#endif 139#endif
139 140
140 // build local packages 141 // build local packages
141 buildLocalPackages( local ); 142 buildLocalPackages( local );
142} 143}
143 144
144void Server :: readPackageFile( Server *local, bool clearAll, bool installingToRoot, Destination *dest ) 145void Server :: readPackageFile( Server *local, bool clearAll, bool installingToRoot, Destination *dest )
145{ 146{
146 ifstream in( packageFile ); 147 ifstream in( packageFile );
147 if ( !in.is_open() ) 148 if ( !in.is_open() )
148 return; 149 return;
149 150
150 char line[1001]; 151 char line[1001];
151 char k[21]; 152 char k[21];
152 char v[1001]; 153 char v[1001];
153 QString key; 154 QString key;
154 QString value; 155 QString value;
155 156
156 if ( clearAll ) 157 if ( clearAll )
157 cleanUp(); 158 cleanUp();
158 Package *currPackage = 0; 159 Package *currPackage = 0;
159 160
160 bool newPackage = true; 161 bool newPackage = true;
161 do 162 do
162 { 163 {
163 in.getline( line, 1000 ); 164 in.getline( line, 1000 );
164 if ( in.eof() ) 165 if ( in.eof() )
165 continue; 166 continue;
166 167
167 k[0] = '\0'; 168 k[0] = '\0';
168 v[0] = '\0'; 169 v[0] = '\0';
169 170
170 sscanf( line, "%[^:]: %[^\n]", k, v ); 171 sscanf( line, "%[^:]: %[^\n]", k, v );
171 key = k; 172 key = k;
172 value = v; 173 value = v;
173 key = key.stripWhiteSpace(); 174 key = key.stripWhiteSpace();
174 value = value.stripWhiteSpace(); 175 value = value.stripWhiteSpace();
175 if ( key == "Package" && newPackage ) 176 if ( key == "Package" && newPackage )
176 { 177 {
177 newPackage = false; 178 newPackage = false;
178 179
179 currPackage = getPackage( value ); 180 currPackage = getPackage( value );
180 if ( !currPackage ) 181 if ( !currPackage )
181 { 182 {
182 packageList.push_back( Package( value ) ); 183 packageList.push_back( Package( value ) );
183 currPackage = &(packageList.back()); 184 currPackage = &(packageList.back());
184 currPackage->setInstalledTo( dest ); 185 currPackage->setInstalledTo( dest );
185 186
186 if ( installingToRoot ) 187 if ( installingToRoot )
187 currPackage->setInstalledToRoot( true ); 188 currPackage->setInstalledToRoot( true );
188 } 189 }
189 else 190 else
190 { 191 {
191 if (currPackage->getStatus().find( "deinstall" ) != -1 ) 192 if (currPackage->getStatus().find( "deinstall" ) != -1 )
192 currPackage->setInstalledTo( dest ); 193 currPackage->setInstalledTo( dest );
193 } 194 }
194 } 195 }
195 else if ( key == "Version" ) 196 else if ( key == "Version" )
196 { 197 {
197 if ( currPackage ) 198 if ( currPackage )
198 currPackage->setVersion( value ); 199 currPackage->setVersion( value );
199 } 200 }
200 else if ( key == "Status" ) 201 else if ( key == "Status" )
201 { 202 {
202 if ( currPackage ) 203 if ( currPackage )
203 currPackage->setStatus( value ); 204 currPackage->setStatus( value );
204 } 205 }
205 else if ( key == "Description" ) 206 else if ( key == "Description" )
206 { 207 {
207 if ( currPackage ) 208 if ( currPackage )
208 currPackage->setDescription( value ); 209 currPackage->setDescription( value );
209 } 210 }
210 else if ( key == "Filename" ) 211 else if ( key == "Filename" )
211 { 212 {
212 if ( currPackage ) 213 if ( currPackage )
213 currPackage->setFilename( value ); 214 currPackage->setFilename( value );
214 } 215 }
215 else if ( key == "Size" ) 216 else if ( key == "Size" )
216 { 217 {
217 if ( currPackage ) 218 if ( currPackage )
218 currPackage->setPackageSize( value ); 219 currPackage->setPackageSize( value );
219 } 220 }
220 else if ( key == "Section" ) 221 else if ( key == "Section" )
221 { 222 {
222 if ( currPackage ) 223 if ( currPackage )
223 currPackage->setSection( value ); 224 currPackage->setSection( value );
224 225
225 DataManager::setAvailableCategories( value ); 226 DataManager::setAvailableCategories( value );
226 } 227 }
227 else if ( key == "" ) 228 else if ( key == "" )
228 { 229 {
229 newPackage = true; 230 newPackage = true;
230 } 231 }
231 } while ( !in.eof() ); 232 } while ( !in.eof() );
232 233
233 in.close(); 234 in.close();
234 235
235 // build local packages 236 // build local packages
236 buildLocalPackages( local ); 237 buildLocalPackages( local );
237} 238}
238 239
239void Server :: buildLocalPackages( Server *local ) 240void Server :: buildLocalPackages( Server *local )
240{ 241{
241 for ( unsigned int i = 0 ; i < packageList.size() ; ++i ) 242 for ( unsigned int i = 0 ; i < packageList.size() ; ++i )
242 { 243 {
243 QString name = packageList[i].getPackageName(); 244 QString name = packageList[i].getPackageName();
244 245
245 // If the package name is an ipk name, then convert the filename to a package name 246 // If the package name is an ipk name, then convert the filename to a package name
246 if ( name.find( ".ipk" ) != -1 ) 247 if ( name.find( ".ipk" ) != -1 )
247 name = Utils::getPackageNameFromIpkFilename( packageList[i].getFilename() ); 248 name = Utils::getPackageNameFromIpkFilename( packageList[i].getFilename() );
248 249
249 if ( local ) 250 if ( local )
250 { 251 {
251 Package *p = local->getPackage( name ); 252 Package *p = local->getPackage( name );
252 packageList[i].setLocalPackage( p ); 253 packageList[i].setLocalPackage( p );
253 if ( p ) 254 if ( p )
254 { 255 {
255 // Set some default stuff like size and things 256 // Set some default stuff like size and things
256 if ( p->getInstalledVersion() == packageList[i].getVersion() ) 257 if ( p->getInstalledVersion() == packageList[i].getVersion() )
257 { 258 {
258 p->setPackageSize( packageList[i].getPackageSize() ); 259 p->setPackageSize( packageList[i].getPackageSize() );
259 p->setSection( packageList[i].getSection() ); 260 p->setSection( packageList[i].getSection() );
260 p->setDescription( packageList[i].getDescription() ); 261 p->setDescription( packageList[i].getDescription() );
261 } 262 }
262 } 263 }
263 264
264 } 265 }
265 else 266 else
266 packageList[i].setLocalPackage( 0 ); 267 packageList[i].setLocalPackage( 0 );
267 } 268 }
268 269
269} 270}
270 271
271Package *Server :: getPackage( QString &name ) 272Package *Server :: getPackage( QString &name )
272{ 273{
273 return getPackage( (const char *)name ); 274 return getPackage( (const char *)name );
274} 275}
275 276
276Package *Server :: getPackage( const char *name ) 277Package *Server :: getPackage( const char *name )
277{ 278{
278 Package *ret = 0; 279 Package *ret = 0;
279 280
280 for ( unsigned int i = 0 ; i < packageList.size() && ret == 0; ++i ) 281 for ( unsigned int i = 0 ; i < packageList.size() && ret == 0; ++i )
281 { 282 {
282 if ( packageList[i].getPackageName() == name ) 283 if ( packageList[i].getPackageName() == name )
283 ret = &packageList[i]; 284 ret = &packageList[i];
284 } 285 }
285 286
286 return ret; 287 return ret;
287} 288}
288 289
289QString Server :: toString() 290QString Server :: toString()
290{ 291{
291 QString ret = "Server\n name - " + serverName + 292 QString ret = "Server\n name - " + serverName +
292 "\n url - " + serverUrl + 293 "\n url - " + serverUrl +
293 "\n"; 294 "\n";
294 295
295 for ( unsigned int i = 0 ; i < packageList.size() ; ++i ) 296 for ( unsigned int i = 0 ; i < packageList.size() ; ++i )
296 ret += "\n " + packageList[i].toString(); 297 ret += "\n " + packageList[i].toString();
297 298
298 299
299 return ret; 300 return ret;
300} 301}
301 302
302vector<Package> &Server::getPackageList() 303vector<Package> &Server::getPackageList()
303{ 304{
304 return packageList; 305 return packageList;
305} 306}
306 307