-rw-r--r-- | noncore/settings/aqpkg/networkpkgmgr.cpp | 166 | ||||
-rw-r--r-- | noncore/settings/aqpkg/networkpkgmgr.h | 2 |
2 files changed, 115 insertions, 53 deletions
diff --git a/noncore/settings/aqpkg/networkpkgmgr.cpp b/noncore/settings/aqpkg/networkpkgmgr.cpp index a058285..76c7a9c 100644 --- a/noncore/settings/aqpkg/networkpkgmgr.cpp +++ b/noncore/settings/aqpkg/networkpkgmgr.cpp | |||
@@ -80,129 +80,129 @@ void NetworkPackageManager :: timerEvent ( QTimerEvent * ) | |||
80 | updateData(); | 80 | updateData(); |
81 | 81 | ||
82 | // progressDlg->hide(); | 82 | // progressDlg->hide(); |
83 | } | 83 | } |
84 | 84 | ||
85 | void NetworkPackageManager :: updateData() | 85 | void NetworkPackageManager :: updateData() |
86 | { | 86 | { |
87 | serversList->clear(); | 87 | serversList->clear(); |
88 | packagesList->clear(); | 88 | packagesList->clear(); |
89 | 89 | ||
90 | 90 | ||
91 | vector<Server>::iterator it; | 91 | vector<Server>::iterator it; |
92 | int activeItem = -1; | 92 | int activeItem = -1; |
93 | int i; | 93 | int i; |
94 | for ( i = 0, it = dataMgr->getServerList().begin() ; it != dataMgr->getServerList().end() ; ++it, ++i ) | 94 | for ( i = 0, it = dataMgr->getServerList().begin() ; it != dataMgr->getServerList().end() ; ++it, ++i ) |
95 | { | 95 | { |
96 | if ( !it->isServerActive() ) | 96 | if ( !it->isServerActive() ) |
97 | { | 97 | { |
98 | i--; | 98 | i--; |
99 | continue; | 99 | continue; |
100 | } | 100 | } |
101 | serversList->insertItem( it->getServerName() ); | 101 | serversList->insertItem( it->getServerName() ); |
102 | if ( it->getServerName() == currentlySelectedServer ) | 102 | if ( it->getServerName() == currentlySelectedServer ) |
103 | activeItem = i; | 103 | activeItem = i; |
104 | } | 104 | } |
105 | 105 | ||
106 | // set selected server to be active server | 106 | // set selected server to be active server |
107 | if ( activeItem != -1 ) | 107 | if ( activeItem != -1 ) |
108 | serversList->setCurrentItem( activeItem ); | 108 | serversList->setCurrentItem( activeItem ); |
109 | serverSelected( 0 ); | 109 | serverSelected( 0 ); |
110 | } | 110 | } |
111 | 111 | ||
112 | void NetworkPackageManager :: selectLocalPackage( const QString &pkg ) | 112 | void NetworkPackageManager :: selectLocalPackage( const QString &pkg ) |
113 | { | 113 | { |
114 | // First select local server | 114 | // First select local server |
115 | for ( int i = 0 ; i < serversList->count() ; ++i ) | 115 | for ( int i = 0 ; i < serversList->count() ; ++i ) |
116 | { | 116 | { |
117 | if ( serversList->text( i ) == LOCAL_IPKGS ) | 117 | if ( serversList->text( i ) == LOCAL_IPKGS ) |
118 | { | 118 | { |
119 | serversList->setCurrentItem( i ); | 119 | serversList->setCurrentItem( i ); |
120 | break; | 120 | break; |
121 | } | 121 | } |
122 | } | 122 | } |
123 | serverSelected( 0 ); | 123 | serverSelected( 0 ); |
124 | 124 | ||
125 | // Now set the check box of the selected package | 125 | // Now set the check box of the selected package |
126 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | 126 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); |
127 | item != 0 ; | 127 | item != 0 ; |
128 | item = (QCheckListItem *)item->nextSibling() ) | 128 | item = (QCheckListItem *)item->nextSibling() ) |
129 | { | 129 | { |
130 | if ( item->text().startsWith( pkg ) ) | 130 | if ( item->text().startsWith( pkg ) ) |
131 | { | 131 | { |
132 | item->setOn( true ); | 132 | item->setOn( true ); |
133 | break; | 133 | break; |
134 | } | 134 | } |
135 | } | 135 | } |
136 | } | 136 | } |
137 | 137 | ||
138 | 138 | ||
139 | void NetworkPackageManager :: initGui() | 139 | void NetworkPackageManager :: initGui() |
140 | { | 140 | { |
141 | QLabel *l = new QLabel( "Servers", this ); | 141 | QLabel *l = new QLabel( "Servers", this ); |
142 | serversList = new QComboBox( this ); | 142 | serversList = new QComboBox( this ); |
143 | packagesList = new QListView( this ); | 143 | packagesList = new QListView( this ); |
144 | update = new QPushButton( "Refresh List", this ); | 144 | update = new QPushButton( "Refresh Lists", this ); |
145 | download = new QPushButton( "Download", this ); | 145 | download = new QPushButton( "Download", this ); |
146 | upgrade = new QPushButton( "Upgrade", this ); | 146 | upgrade = new QPushButton( "Upgrade", this ); |
147 | apply = new QPushButton( "Apply", this ); | 147 | apply = new QPushButton( "Apply", this ); |
148 | 148 | ||
149 | QVBoxLayout *vbox = new QVBoxLayout( this, 0, -1, "VBox" ); | 149 | QVBoxLayout *vbox = new QVBoxLayout( this, 0, -1, "VBox" ); |
150 | QHBoxLayout *hbox1 = new QHBoxLayout( vbox, -1, "HBox1" ); | 150 | QHBoxLayout *hbox1 = new QHBoxLayout( vbox, -1, "HBox1" ); |
151 | hbox1->addWidget( l ); | 151 | hbox1->addWidget( l ); |
152 | hbox1->addWidget( serversList ); | 152 | hbox1->addWidget( serversList ); |
153 | 153 | ||
154 | QHBoxLayout *hbox3 = new QHBoxLayout( vbox, -1, "HBox1" ); | 154 | QHBoxLayout *hbox3 = new QHBoxLayout( vbox, -1, "HBox1" ); |
155 | QHBoxLayout *hbox4 = new QHBoxLayout( vbox, -1, "HBox1" ); | 155 | QHBoxLayout *hbox4 = new QHBoxLayout( vbox, -1, "HBox1" ); |
156 | 156 | ||
157 | 157 | ||
158 | if ( showJumpTo ) | 158 | if ( showJumpTo ) |
159 | { | 159 | { |
160 | char text[2]; | 160 | char text[2]; |
161 | text[1] = '\0'; | 161 | text[1] = '\0'; |
162 | for ( int i = 0 ; i < 26 ; ++i ) | 162 | for ( int i = 0 ; i < 26 ; ++i ) |
163 | { | 163 | { |
164 | text[0] = 'A' + i; | 164 | text[0] = 'A' + i; |
165 | LetterPushButton *b = new LetterPushButton( text, this ); | 165 | LetterPushButton *b = new LetterPushButton( text, this ); |
166 | connect( b, SIGNAL( released( QString ) ), this, SLOT( letterPushed( QString ) ) ); | 166 | connect( b, SIGNAL( released( QString ) ), this, SLOT( letterPushed( QString ) ) ); |
167 | if ( i < 13 ) | 167 | if ( i < 13 ) |
168 | hbox3->addWidget( b ); | 168 | hbox3->addWidget( b ); |
169 | else | 169 | else |
170 | hbox4->addWidget( b ); | 170 | hbox4->addWidget( b ); |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | vbox->addWidget( packagesList ); | 174 | vbox->addWidget( packagesList ); |
175 | packagesList->addColumn( "Packages" ); | 175 | packagesList->addColumn( "Packages" ); |
176 | 176 | ||
177 | QHBoxLayout *hbox2 = new QHBoxLayout( vbox, -1, "HBox2" ); | 177 | QHBoxLayout *hbox2 = new QHBoxLayout( vbox, -1, "HBox2" ); |
178 | hbox2->addWidget( update ); | 178 | hbox2->addWidget( update ); |
179 | hbox2->addWidget( download ); | 179 | hbox2->addWidget( download ); |
180 | hbox2->addWidget( upgrade ); | 180 | hbox2->addWidget( upgrade ); |
181 | hbox2->addWidget( apply ); | 181 | hbox2->addWidget( apply ); |
182 | } | 182 | } |
183 | 183 | ||
184 | void NetworkPackageManager :: setupConnections() | 184 | void NetworkPackageManager :: setupConnections() |
185 | { | 185 | { |
186 | connect( serversList, SIGNAL(activated( int )), this, SLOT(serverSelected( int ))); | 186 | connect( serversList, SIGNAL(activated( int )), this, SLOT(serverSelected( int ))); |
187 | connect( apply, SIGNAL(released()), this, SLOT(applyChanges()) ); | 187 | connect( apply, SIGNAL(released()), this, SLOT(applyChanges()) ); |
188 | connect( download, SIGNAL(released()), this, SLOT(downloadPackage()) ); | 188 | connect( download, SIGNAL(released()), this, SLOT(downloadPackage()) ); |
189 | connect( upgrade, SIGNAL( released()), this, SLOT(upgradePackages()) ); | 189 | connect( upgrade, SIGNAL( released()), this, SLOT(upgradePackages()) ); |
190 | connect( update, SIGNAL(released()), this, SLOT(updateServer()) ); | 190 | connect( update, SIGNAL(released()), this, SLOT(updateServer()) ); |
191 | } | 191 | } |
192 | 192 | ||
193 | void NetworkPackageManager :: showProgressDialog( char *initialText ) | 193 | void NetworkPackageManager :: showProgressDialog( char *initialText ) |
194 | { | 194 | { |
195 | if ( !progressDlg ) | 195 | if ( !progressDlg ) |
196 | progressDlg = new ProgressDlg( this, "Progress", false ); | 196 | progressDlg = new ProgressDlg( this, "Progress", false ); |
197 | progressDlg->setText( initialText ); | 197 | progressDlg->setText( initialText ); |
198 | progressDlg->show(); | 198 | progressDlg->show(); |
199 | } | 199 | } |
200 | 200 | ||
201 | 201 | ||
202 | void NetworkPackageManager :: serverSelected( int ) | 202 | void NetworkPackageManager :: serverSelected( int ) |
203 | { | 203 | { |
204 | packagesList->clear(); | 204 | packagesList->clear(); |
205 | 205 | ||
206 | // display packages | 206 | // display packages |
207 | QString serverName = serversList->currentText(); | 207 | QString serverName = serversList->currentText(); |
208 | currentlySelectedServer = serverName; | 208 | currentlySelectedServer = serverName; |
@@ -224,302 +224,362 @@ void NetworkPackageManager :: serverSelected( int ) | |||
224 | QString text = ""; | 224 | QString text = ""; |
225 | 225 | ||
226 | // If the local server, only display installed packages | 226 | // If the local server, only display installed packages |
227 | if ( serverName == LOCAL_SERVER && !it->isInstalled() ) | 227 | if ( serverName == LOCAL_SERVER && !it->isInstalled() ) |
228 | continue; | 228 | continue; |
229 | 229 | ||
230 | text += it->getPackageName(); | 230 | text += it->getPackageName(); |
231 | if ( it->isInstalled() ) | 231 | if ( it->isInstalled() ) |
232 | { | 232 | { |
233 | text += " (installed)"; | 233 | text += " (installed)"; |
234 | 234 | ||
235 | // If a different version of package is available, postfix it with an * | 235 | // If a different version of package is available, postfix it with an * |
236 | if ( it->getVersion() != it->getInstalledVersion() ) | 236 | if ( it->getVersion() != it->getInstalledVersion() ) |
237 | { | 237 | { |
238 | 238 | ||
239 | if ( compareVersions( it->getInstalledVersion(), it->getVersion() ) == 1 ) | 239 | if ( compareVersions( it->getInstalledVersion(), it->getVersion() ) == 1 ) |
240 | text += "*"; | 240 | text += "*"; |
241 | } | 241 | } |
242 | } | 242 | } |
243 | 243 | ||
244 | QCheckListItem *item = new QCheckListItem( packagesList, text, QCheckListItem::CheckBox ); | 244 | QCheckListItem *item = new QCheckListItem( packagesList, text, QCheckListItem::CheckBox ); |
245 | 245 | ||
246 | if ( it->isInstalled() ) | 246 | if ( it->isInstalled() ) |
247 | { | 247 | { |
248 | QString destName = ""; | 248 | QString destName = ""; |
249 | if ( it->getLocalPackage() ) | 249 | if ( it->getLocalPackage() ) |
250 | { | 250 | { |
251 | if ( it->getLocalPackage()->getInstalledTo() ) | 251 | if ( it->getLocalPackage()->getInstalledTo() ) |
252 | destName = it->getLocalPackage()->getInstalledTo()->getDestinationName(); | 252 | destName = it->getLocalPackage()->getInstalledTo()->getDestinationName(); |
253 | } | 253 | } |
254 | else | 254 | else |
255 | { | 255 | { |
256 | if ( it->getInstalledTo() ) | 256 | if ( it->getInstalledTo() ) |
257 | destName = it->getInstalledTo()->getDestinationName(); | 257 | destName = it->getInstalledTo()->getDestinationName(); |
258 | } | 258 | } |
259 | if ( destName != "" ) | 259 | if ( destName != "" ) |
260 | new QCheckListItem( item, QString( "Installed To - " ) + destName ); | 260 | new QCheckListItem( item, QString( "Installed To - " ) + destName ); |
261 | } | 261 | } |
262 | 262 | ||
263 | if ( !it->isPackageStoredLocally() ) | 263 | if ( !it->isPackageStoredLocally() ) |
264 | new QCheckListItem( item, QString( "Description - " ) + it->getDescription() ); | 264 | new QCheckListItem( item, QString( "Description - " ) + it->getDescription() ); |
265 | else | 265 | else |
266 | new QCheckListItem( item, QString( "Filename - " ) + it->getFilename() ); | 266 | new QCheckListItem( item, QString( "Filename - " ) + it->getFilename() ); |
267 | 267 | ||
268 | if ( serverName == LOCAL_SERVER ) | 268 | if ( serverName == LOCAL_SERVER ) |
269 | { | 269 | { |
270 | new QCheckListItem( item, QString( "V. Installed - " ) + it->getVersion() ); | 270 | new QCheckListItem( item, QString( "V. Installed - " ) + it->getVersion() ); |
271 | } | 271 | } |
272 | else | 272 | else |
273 | { | 273 | { |
274 | new QCheckListItem( item, QString( "V. Available - " ) + it->getVersion() ); | 274 | new QCheckListItem( item, QString( "V. Available - " ) + it->getVersion() ); |
275 | if ( it->getLocalPackage() ) | 275 | if ( it->getLocalPackage() ) |
276 | { | 276 | { |
277 | if ( it->isInstalled() ) | 277 | if ( it->isInstalled() ) |
278 | new QCheckListItem( item, QString( "V. Installed - " ) + it->getInstalledVersion() ); | 278 | new QCheckListItem( item, QString( "V. Installed - " ) + it->getInstalledVersion() ); |
279 | } | 279 | } |
280 | } | 280 | } |
281 | packagesList->insertItem( item ); | 281 | packagesList->insertItem( item ); |
282 | } | 282 | } |
283 | 283 | ||
284 | // If the local server or the local ipkgs server disable the download button | 284 | // If the local server or the local ipkgs server disable the download button |
285 | if ( serverName == LOCAL_SERVER ) | 285 | if ( serverName == LOCAL_SERVER ) |
286 | { | 286 | { |
287 | upgrade->setEnabled( false ); | 287 | upgrade->setEnabled( false ); |
288 | download->setText( "Download" ); | 288 | download->setText( "Install Remote" ); |
289 | download->setEnabled( false ); | 289 | download->setEnabled( true ); |
290 | } | 290 | } |
291 | else if ( serverName == LOCAL_IPKGS ) | 291 | else if ( serverName == LOCAL_IPKGS ) |
292 | { | 292 | { |
293 | upgrade->setEnabled( false ); | 293 | upgrade->setEnabled( false ); |
294 | download->setEnabled( true ); | 294 | download->setEnabled( true ); |
295 | download->setText( "Remove" ); | 295 | download->setText( "Remove" ); |
296 | } | 296 | } |
297 | else | 297 | else |
298 | { | 298 | { |
299 | upgrade->setEnabled( true ); | 299 | upgrade->setEnabled( true ); |
300 | download->setEnabled( true ); | 300 | download->setEnabled( true ); |
301 | download->setText( "Download" ); | 301 | download->setText( "Download" ); |
302 | } | 302 | } |
303 | } | 303 | } |
304 | 304 | ||
305 | void NetworkPackageManager :: updateServer() | 305 | void NetworkPackageManager :: updateServer() |
306 | { | 306 | { |
307 | QString serverName = serversList->currentText(); | 307 | QString serverName = serversList->currentText(); |
308 | 308 | ||
309 | // Update the current server | 309 | // Update the current server |
310 | // Display dialog | 310 | // Display dialog |
311 | // ProgressDlg *progDlg = new ProgressDlg( this ); | 311 | // ProgressDlg *progDlg = new ProgressDlg( this ); |
312 | // QString status = "Updating package lists..."; | 312 | // QString status = "Updating package lists..."; |
313 | // progDlg->show(); | 313 | // progDlg->show(); |
314 | // progDlg->setText( status ); | 314 | // progDlg->setText( status ); |
315 | 315 | ||
316 | // Disable buttons to stop silly people clicking lots on them :) | 316 | // Disable buttons to stop silly people clicking lots on them :) |
317 | 317 | ||
318 | // First, write out ipkg_conf file so that ipkg can use it | 318 | // First, write out ipkg_conf file so that ipkg can use it |
319 | dataMgr->writeOutIpkgConf(); | 319 | dataMgr->writeOutIpkgConf(); |
320 | 320 | ||
321 | Ipkg ipkg; | 321 | Ipkg ipkg; |
322 | ipkg.setOption( "update" ); | 322 | ipkg.setOption( "update" ); |
323 | 323 | ||
324 | InstallDlgImpl dlg( &ipkg, "Refreshing server package lists", this, "Upgrade", true ); | 324 | InstallDlgImpl dlg( &ipkg, "Refreshing server package lists", this, "Upgrade", true ); |
325 | dlg.showDlg(); | 325 | dlg.showDlg(); |
326 | 326 | ||
327 | // Reload data | 327 | // Reload data |
328 | dataMgr->reloadServerData(); | 328 | dataMgr->reloadServerData(); |
329 | serverSelected(-1); | 329 | serverSelected(-1); |
330 | // delete progDlg; | 330 | // delete progDlg; |
331 | } | 331 | } |
332 | 332 | ||
333 | void NetworkPackageManager :: upgradePackages() | 333 | void NetworkPackageManager :: upgradePackages() |
334 | { | 334 | { |
335 | // We're gonna do an upgrade of all packages | 335 | // We're gonna do an upgrade of all packages |
336 | // First warn user that this isn't recommended | 336 | // First warn user that this isn't recommended |
337 | QString text = "WARNING: Upgrading while\nOpie/Qtopia is running\nis NOT recommended!\n\nAre you sure?\n"; | 337 | QString text = "WARNING: Upgrading while\nOpie/Qtopia is running\nis NOT recommended!\n\nAre you sure?\n"; |
338 | QMessageBox warn("Warning", text, QMessageBox::Warning, | 338 | QMessageBox warn("Warning", text, QMessageBox::Warning, |
339 | QMessageBox::Yes, | 339 | QMessageBox::Yes, |
340 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default , | 340 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default , |
341 | 0, this ); | 341 | 0, this ); |
342 | warn.adjustSize(); | 342 | warn.adjustSize(); |
343 | 343 | ||
344 | if ( warn.exec() == QMessageBox::Yes ) | 344 | if ( warn.exec() == QMessageBox::Yes ) |
345 | { | 345 | { |
346 | // First, write out ipkg_conf file so that ipkg can use it | 346 | // First, write out ipkg_conf file so that ipkg can use it |
347 | dataMgr->writeOutIpkgConf(); | 347 | dataMgr->writeOutIpkgConf(); |
348 | 348 | ||
349 | // Now run upgrade | 349 | // Now run upgrade |
350 | Ipkg ipkg; | 350 | Ipkg ipkg; |
351 | ipkg.setOption( "upgrade" ); | 351 | ipkg.setOption( "upgrade" ); |
352 | 352 | ||
353 | InstallDlgImpl dlg( &ipkg, "Upgrading installed packages", this, "Upgrade", true ); | 353 | InstallDlgImpl dlg( &ipkg, "Upgrading installed packages", this, "Upgrade", true ); |
354 | dlg.showDlg(); | 354 | dlg.showDlg(); |
355 | 355 | ||
356 | // Reload data | 356 | // Reload data |
357 | dataMgr->reloadServerData(); | 357 | dataMgr->reloadServerData(); |
358 | serverSelected(-1); | 358 | serverSelected(-1); |
359 | } | 359 | } |
360 | } | 360 | } |
361 | 361 | ||
362 | 362 | ||
363 | void NetworkPackageManager :: downloadPackage() | 363 | void NetworkPackageManager :: downloadPackage() |
364 | { | 364 | { |
365 | bool doUpdate = true; | 365 | bool doUpdate = true; |
366 | if ( download->text() == "Download" ) | 366 | if ( download->text() == "Download" ) |
367 | { | 367 | { |
368 | // First, write out ipkg_conf file so that ipkg can use it | 368 | // See if any packages are selected |
369 | dataMgr->writeOutIpkgConf(); | 369 | bool found = false; |
370 | 370 | if ( serversList->currentText() != LOCAL_SERVER ) | |
371 | // Display dialog to user asking where to download the files to | ||
372 | bool ok = FALSE; | ||
373 | QString dir = ""; | ||
374 | #ifdef QWS | ||
375 | // read download directory from config file | ||
376 | Config cfg( "aqpkg" ); | ||
377 | cfg.setGroup( "settings" ); | ||
378 | dir = cfg.readEntry( "downloadDir", "/home/root/Documents/application/ipkg" ); | ||
379 | #endif | ||
380 | |||
381 | QString text = InputDialog::getText( tr( "Download to where" ), tr( "Enter path to download to" ), dir, &ok, this ); | ||
382 | if ( ok && !text.isEmpty() ) | ||
383 | dir = text; // user entered something and pressed ok | ||
384 | else | ||
385 | return; // user entered nothing or pressed cancel | ||
386 | |||
387 | #ifdef QWS | ||
388 | // Store download directory in config file | ||
389 | cfg.writeEntry( "downloadDir", dir ); | ||
390 | #endif | ||
391 | |||
392 | // Get starting directory | ||
393 | char initDir[PATH_MAX]; | ||
394 | getcwd( initDir, PATH_MAX ); | ||
395 | |||
396 | // Download each package | ||
397 | Ipkg ipkg; | ||
398 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); | ||
399 | |||
400 | ipkg.setOption( "download" ); | ||
401 | ipkg.setRuntimeDirectory( dir ); | ||
402 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | ||
403 | item != 0 ; | ||
404 | item = (QCheckListItem *)item->nextSibling() ) | ||
405 | { | 371 | { |
406 | if ( item->isOn() ) | 372 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); |
373 | item != 0 && !found; | ||
374 | item = (QCheckListItem *)item->nextSibling() ) | ||
407 | { | 375 | { |
408 | QString name = item->text(); | 376 | if ( item->isOn() ) |
409 | int pos = name.find( "*" ); | 377 | found = true; |
410 | name.truncate( pos ); | ||
411 | |||
412 | // if (there is a (installed), remove it | ||
413 | pos = name.find( "(installed)" ); | ||
414 | if ( pos > 0 ) | ||
415 | name.truncate( pos - 1 ); | ||
416 | |||
417 | ipkg.setPackage( name ); | ||
418 | ipkg.runIpkg( ); | ||
419 | } | 378 | } |
420 | } | 379 | } |
380 | |||
381 | // If user selected some packages then download the and store the locally | ||
382 | // otherwise, display dialog asking user what package to download from an http server | ||
383 | // and whether to install it | ||
384 | if ( found ) | ||
385 | downloadSelectedPackages(); | ||
386 | else | ||
387 | downloadRemotePackage(); | ||
388 | |||
421 | } | 389 | } |
422 | else if ( download->text() == "Remove" ) | 390 | else if ( download->text() == "Remove" ) |
423 | { | 391 | { |
424 | doUpdate = false; | 392 | doUpdate = false; |
425 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | 393 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); |
426 | item != 0 ; | 394 | item != 0 ; |
427 | item = (QCheckListItem *)item->nextSibling() ) | 395 | item = (QCheckListItem *)item->nextSibling() ) |
428 | { | 396 | { |
429 | if ( item->isOn() ) | 397 | if ( item->isOn() ) |
430 | { | 398 | { |
431 | QString name = item->text(); | 399 | QString name = item->text(); |
432 | int pos = name.find( "*" ); | 400 | int pos = name.find( "*" ); |
433 | name.truncate( pos ); | 401 | name.truncate( pos ); |
434 | 402 | ||
435 | // if (there is a (installed), remove it | 403 | // if (there is a (installed), remove it |
436 | pos = name.find( "(installed)" ); | 404 | pos = name.find( "(installed)" ); |
437 | if ( pos > 0 ) | 405 | if ( pos > 0 ) |
438 | name.truncate( pos - 1 ); | 406 | name.truncate( pos - 1 ); |
439 | 407 | ||
440 | Package *p = dataMgr->getServer( serversList->currentText() )->getPackage( name ); | 408 | Package *p = dataMgr->getServer( serversList->currentText() )->getPackage( name ); |
441 | 409 | ||
442 | QString msgtext; | 410 | QString msgtext; |
443 | msgtext.sprintf( "Are you sure you wish to delete\n%s?", (const char *)p->getPackageName() ); | 411 | msgtext.sprintf( "Are you sure you wish to delete\n%s?", (const char *)p->getPackageName() ); |
444 | if ( QMessageBox::information( this, "Are you sure?", | 412 | if ( QMessageBox::information( this, "Are you sure?", |
445 | msgtext, "No", "Yes" ) == 1 ) | 413 | msgtext, "No", "Yes" ) == 1 ) |
446 | { | 414 | { |
447 | doUpdate = true; | 415 | doUpdate = true; |
448 | QFile f( p->getFilename() ); | 416 | QFile f( p->getFilename() ); |
449 | f.remove(); | 417 | f.remove(); |
450 | } | 418 | } |
451 | } | 419 | } |
452 | } | 420 | } |
453 | } | 421 | } |
454 | 422 | ||
455 | if ( doUpdate ) | 423 | if ( doUpdate ) |
456 | { | 424 | { |
457 | dataMgr->reloadServerData(); | 425 | dataMgr->reloadServerData(); |
458 | serverSelected( -1 ); | 426 | serverSelected( -1 ); |
459 | } | 427 | } |
460 | } | 428 | } |
461 | 429 | ||
430 | void NetworkPackageManager :: downloadSelectedPackages() | ||
431 | { | ||
432 | // First, write out ipkg_conf file so that ipkg can use it | ||
433 | dataMgr->writeOutIpkgConf(); | ||
434 | |||
435 | // Display dialog to user asking where to download the files to | ||
436 | bool ok = FALSE; | ||
437 | QString dir = ""; | ||
438 | #ifdef QWS | ||
439 | // read download directory from config file | ||
440 | Config cfg( "aqpkg" ); | ||
441 | cfg.setGroup( "settings" ); | ||
442 | dir = cfg.readEntry( "downloadDir", "/home/root/Documents/application/ipkg" ); | ||
443 | #endif | ||
444 | |||
445 | QString text = InputDialog::getText( tr( "Download to where" ), tr( "Enter path to download to" ), dir, &ok, this ); | ||
446 | if ( ok && !text.isEmpty() ) | ||
447 | dir = text; // user entered something and pressed ok | ||
448 | else | ||
449 | return; // user entered nothing or pressed cancel | ||
450 | |||
451 | #ifdef QWS | ||
452 | // Store download directory in config file | ||
453 | cfg.writeEntry( "downloadDir", dir ); | ||
454 | #endif | ||
455 | |||
456 | // Get starting directory | ||
457 | char initDir[PATH_MAX]; | ||
458 | getcwd( initDir, PATH_MAX ); | ||
459 | |||
460 | // Download each package | ||
461 | Ipkg ipkg; | ||
462 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); | ||
463 | |||
464 | ipkg.setOption( "download" ); | ||
465 | ipkg.setRuntimeDirectory( dir ); | ||
466 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | ||
467 | item != 0 ; | ||
468 | item = (QCheckListItem *)item->nextSibling() ) | ||
469 | { | ||
470 | if ( item->isOn() ) | ||
471 | { | ||
472 | QString name = item->text(); | ||
473 | int pos = name.find( "*" ); | ||
474 | name.truncate( pos ); | ||
475 | |||
476 | // if (there is a (installed), remove it | ||
477 | pos = name.find( "(installed)" ); | ||
478 | if ( pos > 0 ) | ||
479 | name.truncate( pos - 1 ); | ||
480 | |||
481 | ipkg.setPackage( name ); | ||
482 | ipkg.runIpkg( ); | ||
483 | } | ||
484 | } | ||
485 | } | ||
486 | |||
487 | void NetworkPackageManager :: downloadRemotePackage() | ||
488 | { | ||
489 | // Display dialog | ||
490 | bool ok; | ||
491 | QString package = InputDialog::getText( "Install Remote Package", tr( "Enter package location" ), "http://", &ok, this ); | ||
492 | if ( !ok || package.isEmpty() ) | ||
493 | return; | ||
494 | // DownloadRemoteDlgImpl dlg( this, "Install", true ); | ||
495 | // if ( dlg.exec() == QDialog::Rejected ) | ||
496 | // return; | ||
497 | |||
498 | // grab details from dialog | ||
499 | // QString package = dlg.getPackageLocation(); | ||
500 | |||
501 | InstallData item; | ||
502 | item.option = "I"; | ||
503 | item.packageName = package; | ||
504 | vector<InstallData> workingPackages; | ||
505 | workingPackages.push_back( item ); | ||
506 | |||
507 | InstallDlgImpl dlg2( workingPackages, dataMgr, this, "Install", true ); | ||
508 | dlg2.showDlg(); | ||
509 | |||
510 | // Reload data | ||
511 | dataMgr->reloadServerData(); | ||
512 | serverSelected(-1); | ||
513 | |||
514 | #ifdef QWS | ||
515 | // Finally let the main system update itself | ||
516 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | ||
517 | QString lf = QString::null; | ||
518 | e << lf; | ||
519 | #endif | ||
520 | } | ||
521 | |||
462 | 522 | ||
463 | void NetworkPackageManager :: applyChanges() | 523 | void NetworkPackageManager :: applyChanges() |
464 | { | 524 | { |
465 | stickyOption = ""; | 525 | stickyOption = ""; |
466 | 526 | ||
467 | // First, write out ipkg_conf file so that ipkg can use it | 527 | // First, write out ipkg_conf file so that ipkg can use it |
468 | dataMgr->writeOutIpkgConf(); | 528 | dataMgr->writeOutIpkgConf(); |
469 | 529 | ||
470 | // Now for each selected item | 530 | // Now for each selected item |
471 | // deal with it | 531 | // deal with it |
472 | 532 | ||
473 | vector<InstallData> workingPackages; | 533 | vector<InstallData> workingPackages; |
474 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | 534 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); |
475 | item != 0 ; | 535 | item != 0 ; |
476 | item = (QCheckListItem *)item->nextSibling() ) | 536 | item = (QCheckListItem *)item->nextSibling() ) |
477 | { | 537 | { |
478 | if ( item->isOn() ) | 538 | if ( item->isOn() ) |
479 | { | 539 | { |
480 | InstallData data = dealWithItem( item ); | 540 | InstallData data = dealWithItem( item ); |
481 | workingPackages.push_back( data ); | 541 | workingPackages.push_back( data ); |
482 | } | 542 | } |
483 | } | 543 | } |
484 | 544 | ||
485 | if ( workingPackages.size() == 0 ) | 545 | if ( workingPackages.size() == 0 ) |
486 | { | 546 | { |
487 | // Nothing to do | 547 | // Nothing to do |
488 | QMessageBox::information( this, "Nothing to do", | 548 | QMessageBox::information( this, "Nothing to do", |
489 | "No packages selected", "OK" ); | 549 | "No packages selected", "OK" ); |
490 | 550 | ||
491 | return; | 551 | return; |
492 | } | 552 | } |
493 | 553 | ||
494 | // do the stuff | 554 | // do the stuff |
495 | InstallDlgImpl dlg( workingPackages, dataMgr, this, "Install", true ); | 555 | InstallDlgImpl dlg( workingPackages, dataMgr, this, "Install", true ); |
496 | dlg.showDlg(); | 556 | dlg.showDlg(); |
497 | 557 | ||
498 | // Reload data | 558 | // Reload data |
499 | dataMgr->reloadServerData(); | 559 | dataMgr->reloadServerData(); |
500 | serverSelected(-1); | 560 | serverSelected(-1); |
501 | 561 | ||
502 | #ifdef QWS | 562 | #ifdef QWS |
503 | // Finally let the main system update itself | 563 | // Finally let the main system update itself |
504 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 564 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
505 | QString lf = QString::null; | 565 | QString lf = QString::null; |
506 | e << lf; | 566 | e << lf; |
507 | #endif | 567 | #endif |
508 | } | 568 | } |
509 | 569 | ||
510 | // decide what to do - either remove, upgrade or install | 570 | // decide what to do - either remove, upgrade or install |
511 | // Current rules: | 571 | // Current rules: |
512 | // If not installed - install | 572 | // If not installed - install |
513 | // If installed and different version available - upgrade | 573 | // If installed and different version available - upgrade |
514 | // If installed and version up to date - remove | 574 | // If installed and version up to date - remove |
515 | InstallData NetworkPackageManager :: dealWithItem( QCheckListItem *item ) | 575 | InstallData NetworkPackageManager :: dealWithItem( QCheckListItem *item ) |
516 | { | 576 | { |
517 | QString name = item->text(); | 577 | QString name = item->text(); |
518 | int pos = name.find( "*" ); | 578 | int pos = name.find( "*" ); |
519 | name.truncate( pos ); | 579 | name.truncate( pos ); |
520 | 580 | ||
521 | // if (there is a (installed), remove it | 581 | // if (there is a (installed), remove it |
522 | pos = name.find( "(installed)" ); | 582 | pos = name.find( "(installed)" ); |
523 | if ( pos > 0 ) | 583 | if ( pos > 0 ) |
524 | name.truncate( pos - 1 ); | 584 | name.truncate( pos - 1 ); |
525 | 585 | ||
@@ -647,65 +707,65 @@ void NetworkPackageManager :: letterPushed( QString t ) | |||
647 | QCheckListItem *start = (QCheckListItem *)packagesList->currentItem(); | 707 | QCheckListItem *start = (QCheckListItem *)packagesList->currentItem(); |
648 | if ( packagesList->firstChild() == 0 ) | 708 | if ( packagesList->firstChild() == 0 ) |
649 | return; | 709 | return; |
650 | 710 | ||
651 | QCheckListItem *item; | 711 | QCheckListItem *item; |
652 | if ( start == 0 ) | 712 | if ( start == 0 ) |
653 | { | 713 | { |
654 | item = (QCheckListItem *)packagesList->firstChild(); | 714 | item = (QCheckListItem *)packagesList->firstChild(); |
655 | start = top; | 715 | start = top; |
656 | } | 716 | } |
657 | else | 717 | else |
658 | item = (QCheckListItem *)start->nextSibling(); | 718 | item = (QCheckListItem *)start->nextSibling(); |
659 | 719 | ||
660 | if ( item == 0 ) | 720 | if ( item == 0 ) |
661 | item = (QCheckListItem *)packagesList->firstChild(); | 721 | item = (QCheckListItem *)packagesList->firstChild(); |
662 | do | 722 | do |
663 | { | 723 | { |
664 | if ( item->text().lower().startsWith( t.lower() ) ) | 724 | if ( item->text().lower().startsWith( t.lower() ) ) |
665 | { | 725 | { |
666 | packagesList->setSelected( item, true ); | 726 | packagesList->setSelected( item, true ); |
667 | packagesList->ensureItemVisible( item ); | 727 | packagesList->ensureItemVisible( item ); |
668 | break; | 728 | break; |
669 | } | 729 | } |
670 | 730 | ||
671 | item = (QCheckListItem *)item->nextSibling(); | 731 | item = (QCheckListItem *)item->nextSibling(); |
672 | if ( !item ) | 732 | if ( !item ) |
673 | item = (QCheckListItem *)packagesList->firstChild(); | 733 | item = (QCheckListItem *)packagesList->firstChild(); |
674 | } while ( item != start); | 734 | } while ( item != start); |
675 | } | 735 | } |
676 | 736 | ||
677 | 737 | ||
678 | void NetworkPackageManager :: searchForPackage( bool findNext ) | 738 | void NetworkPackageManager :: searchForPackage( bool findNext ) |
679 | { | 739 | { |
680 | bool ok = false; | 740 | bool ok = false; |
681 | if ( !findNext || lastSearchText.isEmpty() ) | 741 | if ( !findNext || lastSearchText.isEmpty() ) |
682 | lastSearchText = InputDialog::getText( "Search for package", "Enter package to search for", lastSearchText, &ok, this ).lower(); | 742 | lastSearchText = InputDialog::getText( "Search for package", "Enter package to search for", lastSearchText, &ok, this ).lower(); |
683 | else | 743 | else |
684 | ok = true; | 744 | ok = true; |
685 | 745 | ||
686 | if ( ok && !lastSearchText.isEmpty() ) | 746 | if ( ok && !lastSearchText.isEmpty() ) |
687 | { | 747 | { |
688 | cout << "searching for " << lastSearchText << endl; | 748 | cout << "searching for " << lastSearchText << endl; |
689 | // look through package list for text startng at current position | 749 | // look through package list for text startng at current position |
690 | vector<InstallData> workingPackages; | 750 | vector<InstallData> workingPackages; |
691 | QCheckListItem *start = (QCheckListItem *)packagesList->currentItem(); | 751 | QCheckListItem *start = (QCheckListItem *)packagesList->currentItem(); |
692 | if ( start != 0 ) | 752 | if ( start != 0 ) |
693 | start = (QCheckListItem *)start->nextSibling(); | 753 | start = (QCheckListItem *)start->nextSibling(); |
694 | 754 | ||
695 | if ( start == 0 ) | 755 | if ( start == 0 ) |
696 | start = (QCheckListItem *)packagesList->firstChild(); | 756 | start = (QCheckListItem *)packagesList->firstChild(); |
697 | 757 | ||
698 | for ( QCheckListItem *item = start; item != 0 ; | 758 | for ( QCheckListItem *item = start; item != 0 ; |
699 | item = (QCheckListItem *)item->nextSibling() ) | 759 | item = (QCheckListItem *)item->nextSibling() ) |
700 | { | 760 | { |
701 | cout << "checking " << item->text().lower() << endl; | 761 | cout << "checking " << item->text().lower() << endl; |
702 | if ( item->text().lower().find( lastSearchText ) != -1 ) | 762 | if ( item->text().lower().find( lastSearchText ) != -1 ) |
703 | { | 763 | { |
704 | cout << "matched " << item->text() << endl; | 764 | cout << "matched " << item->text() << endl; |
705 | packagesList->ensureItemVisible( item ); | 765 | packagesList->ensureItemVisible( item ); |
706 | packagesList->setCurrentItem( item ); | 766 | packagesList->setCurrentItem( item ); |
707 | break; | 767 | break; |
708 | } | 768 | } |
709 | } | 769 | } |
710 | } | 770 | } |
711 | } \ No newline at end of file | 771 | } |
diff --git a/noncore/settings/aqpkg/networkpkgmgr.h b/noncore/settings/aqpkg/networkpkgmgr.h index 20f6e2d..66a8903 100644 --- a/noncore/settings/aqpkg/networkpkgmgr.h +++ b/noncore/settings/aqpkg/networkpkgmgr.h | |||
@@ -2,78 +2,80 @@ | |||
2 | networkpkgmgr.h - description | 2 | networkpkgmgr.h - 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 | #ifndef NETWORKPKGMGR_H | 18 | #ifndef NETWORKPKGMGR_H |
19 | #define NETWORKPKGMGR_H | 19 | #define NETWORKPKGMGR_H |
20 | 20 | ||
21 | #include <qlayout.h> | 21 | #include <qlayout.h> |
22 | #include <qpushbutton.h> | 22 | #include <qpushbutton.h> |
23 | #include <qwidget.h> | 23 | #include <qwidget.h> |
24 | #include <qcombobox.h> | 24 | #include <qcombobox.h> |
25 | #include <qlistview.h> | 25 | #include <qlistview.h> |
26 | 26 | ||
27 | #include "datamgr.h" | 27 | #include "datamgr.h" |
28 | #include "progressdlg.h" | 28 | #include "progressdlg.h" |
29 | class InstallData; | 29 | class InstallData; |
30 | 30 | ||
31 | /** NetworkPackageManager is the base class of the project */ | 31 | /** NetworkPackageManager is the base class of the project */ |
32 | class NetworkPackageManager : public QWidget | 32 | class NetworkPackageManager : public QWidget |
33 | { | 33 | { |
34 | Q_OBJECT | 34 | Q_OBJECT |
35 | public: | 35 | public: |
36 | /** construtor */ | 36 | /** construtor */ |
37 | NetworkPackageManager( DataManager *dataManager, QWidget* parent=0, const char *name=0); | 37 | NetworkPackageManager( DataManager *dataManager, QWidget* parent=0, const char *name=0); |
38 | /** destructor */ | 38 | /** destructor */ |
39 | ~NetworkPackageManager(); | 39 | ~NetworkPackageManager(); |
40 | 40 | ||
41 | void selectLocalPackage( const QString &pkg ); | 41 | void selectLocalPackage( const QString &pkg ); |
42 | void updateData(); | 42 | void updateData(); |
43 | void searchForPackage( bool findNext ); | 43 | void searchForPackage( bool findNext ); |
44 | private: | 44 | private: |
45 | DataManager *dataMgr; | 45 | DataManager *dataMgr; |
46 | 46 | ||
47 | QComboBox *serversList; | 47 | QComboBox *serversList; |
48 | QListView *packagesList; | 48 | QListView *packagesList; |
49 | QPushButton *update; | 49 | QPushButton *update; |
50 | QPushButton *upgrade; | 50 | QPushButton *upgrade; |
51 | QPushButton *download; | 51 | QPushButton *download; |
52 | QPushButton *apply; | 52 | QPushButton *apply; |
53 | 53 | ||
54 | ProgressDlg *progressDlg; | 54 | ProgressDlg *progressDlg; |
55 | QString currentlySelectedServer; | 55 | QString currentlySelectedServer; |
56 | QString lastSearchText; | 56 | QString lastSearchText; |
57 | 57 | ||
58 | bool showJumpTo; | 58 | bool showJumpTo; |
59 | int timerId; | 59 | int timerId; |
60 | 60 | ||
61 | void timerEvent ( QTimerEvent * ); | 61 | void timerEvent ( QTimerEvent * ); |
62 | 62 | ||
63 | void initGui(); | 63 | void initGui(); |
64 | void setupConnections(); | 64 | void setupConnections(); |
65 | void showProgressDialog( char *initialText ); | 65 | void showProgressDialog( char *initialText ); |
66 | void downloadSelectedPackages(); | ||
67 | void downloadRemotePackage(); | ||
66 | InstallData dealWithItem( QCheckListItem *item ); | 68 | InstallData dealWithItem( QCheckListItem *item ); |
67 | QString stickyOption; | 69 | QString stickyOption; |
68 | 70 | ||
69 | public slots: | 71 | public slots: |
70 | void serverSelected( int index ); | 72 | void serverSelected( int index ); |
71 | void applyChanges(); | 73 | void applyChanges(); |
72 | void upgradePackages(); | 74 | void upgradePackages(); |
73 | void downloadPackage(); | 75 | void downloadPackage(); |
74 | void updateServer(); | 76 | void updateServer(); |
75 | void displayText( const QString &t ); | 77 | void displayText( const QString &t ); |
76 | void letterPushed( QString t ); | 78 | void letterPushed( QString t ); |
77 | }; | 79 | }; |
78 | 80 | ||
79 | #endif | 81 | #endif |