author | andyq <andyq> | 2002-10-16 21:25:25 (UTC) |
---|---|---|
committer | andyq <andyq> | 2002-10-16 21:25:25 (UTC) |
commit | bf58f7bc221ba10f6681d9a1a5193bd208d9920e (patch) (unidiff) | |
tree | ba87cbc5c490b60e6c447eadded833408d829438 | |
parent | 6c5cf5e778ce7cce306b5e02c1ce66a536d3a11c (diff) | |
download | opie-bf58f7bc221ba10f6681d9a1a5193bd208d9920e.zip opie-bf58f7bc221ba10f6681d9a1a5193bd208d9920e.tar.gz opie-bf58f7bc221ba10f6681d9a1a5193bd208d9920e.tar.bz2 |
Now allows for multiple servers active
Added basic search facility (lots of buttons)
-rw-r--r-- | noncore/settings/aqpkg/networkpkgmgr.cpp | 97 | ||||
-rw-r--r-- | noncore/settings/aqpkg/networkpkgmgr.h | 2 |
2 files changed, 75 insertions, 24 deletions
diff --git a/noncore/settings/aqpkg/networkpkgmgr.cpp b/noncore/settings/aqpkg/networkpkgmgr.cpp index 0bc01df..318b26d 100644 --- a/noncore/settings/aqpkg/networkpkgmgr.cpp +++ b/noncore/settings/aqpkg/networkpkgmgr.cpp | |||
@@ -1,453 +1,502 @@ | |||
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> |
20 | using namespace std; | 20 | using 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 | 43 | ||
43 | #include "global.h" | 44 | #include "global.h" |
44 | 45 | ||
45 | NetworkPackageManager::NetworkPackageManager( DataManager *dataManager, QWidget *parent, const char *name) | 46 | NetworkPackageManager::NetworkPackageManager( DataManager *dataManager, QWidget *parent, const char *name) |
46 | : QWidget(parent, name) | 47 | : QWidget(parent, name) |
47 | { | 48 | { |
48 | dataMgr = dataManager; | 49 | dataMgr = dataManager; |
49 | 50 | ||
51 | #ifdef QWS | ||
52 | // read download directory from config file | ||
53 | Config cfg( "aqpkg" ); | ||
54 | cfg.setGroup( "settings" ); | ||
55 | currentlySelectedServer = cfg.readEntry( "selectedServer", "local" ); | ||
56 | #endif | ||
57 | |||
58 | |||
50 | initGui(); | 59 | initGui(); |
51 | setupConnections(); | 60 | setupConnections(); |
52 | 61 | ||
53 | progressDlg = 0; | 62 | progressDlg = 0; |
54 | timerId = startTimer( 100 ); | 63 | timerId = startTimer( 100 ); |
55 | } | 64 | } |
56 | 65 | ||
57 | NetworkPackageManager::~NetworkPackageManager() | 66 | NetworkPackageManager::~NetworkPackageManager() |
58 | { | 67 | { |
59 | } | 68 | } |
60 | 69 | ||
61 | void NetworkPackageManager :: timerEvent ( QTimerEvent * ) | 70 | void NetworkPackageManager :: timerEvent ( QTimerEvent * ) |
62 | { | 71 | { |
63 | killTimer( timerId ); | 72 | killTimer( timerId ); |
64 | 73 | ||
65 | // showProgressDialog(); | 74 | // showProgressDialog(); |
66 | // Add server names to listbox | 75 | // Add server names to listbox |
67 | updateData(); | 76 | updateData(); |
68 | 77 | ||
69 | // progressDlg->hide(); | 78 | // progressDlg->hide(); |
70 | } | 79 | } |
71 | 80 | ||
72 | void NetworkPackageManager :: updateData() | 81 | void NetworkPackageManager :: updateData() |
73 | { | 82 | { |
74 | serversList->clear(); | 83 | serversList->clear(); |
75 | packagesList->clear(); | 84 | packagesList->clear(); |
76 | 85 | ||
77 | vector<Server>::iterator it; | 86 | vector<Server>::iterator it; |
78 | int activeItem = -1; | 87 | int activeItem = -1; |
79 | int i; | 88 | int i; |
80 | for ( i = 0, it = dataMgr->getServerList().begin() ; it != dataMgr->getServerList().end() ; ++it, ++i ) | 89 | for ( i = 0, it = dataMgr->getServerList().begin() ; it != dataMgr->getServerList().end() ; ++it, ++i ) |
81 | { | 90 | { |
82 | serversList->insertItem( it->getServerName() ); | 91 | serversList->insertItem( it->getServerName() ); |
83 | if ( it->getServerName() == dataMgr->getActiveServer() ) | 92 | if ( it->getServerName() == currentlySelectedServer ) |
84 | activeItem = i; | 93 | activeItem = i; |
85 | } | 94 | } |
86 | 95 | ||
87 | // set selected server to be active server | 96 | // set selected server to be active server |
88 | if ( activeItem != -1 ) | 97 | if ( activeItem != -1 ) |
89 | serversList->setCurrentItem( activeItem ); | 98 | serversList->setCurrentItem( activeItem ); |
90 | serverSelected( 0 ); | 99 | serverSelected( 0 ); |
91 | } | 100 | } |
92 | 101 | ||
93 | 102 | ||
94 | void NetworkPackageManager :: initGui() | 103 | void NetworkPackageManager :: initGui() |
95 | { | 104 | { |
96 | QLabel *l = new QLabel( "Servers", this ); | 105 | QLabel *l = new QLabel( "Servers", this ); |
97 | serversList = new QComboBox( this ); | 106 | serversList = new QComboBox( this ); |
98 | packagesList = new QListView( this ); | 107 | packagesList = new QListView( this ); |
99 | update = new QPushButton( "Refresh List", this ); | 108 | update = new QPushButton( "Refresh List", this ); |
100 | download = new QPushButton( "Download", this ); | 109 | download = new QPushButton( "Download", this ); |
101 | upgrade = new QPushButton( "Upgrade", this ); | 110 | upgrade = new QPushButton( "Upgrade", this ); |
102 | apply = new QPushButton( "Apply", this ); | 111 | apply = new QPushButton( "Apply", this ); |
103 | 112 | ||
104 | QVBoxLayout *vbox = new QVBoxLayout( this, 0, -1, "VBox" ); | 113 | QVBoxLayout *vbox = new QVBoxLayout( this, 0, -1, "VBox" ); |
105 | QHBoxLayout *hbox1 = new QHBoxLayout( vbox, -1, "HBox1" ); | 114 | QHBoxLayout *hbox1 = new QHBoxLayout( vbox, -1, "HBox1" ); |
106 | hbox1->addWidget( l ); | 115 | hbox1->addWidget( l ); |
107 | hbox1->addWidget( serversList ); | 116 | hbox1->addWidget( serversList ); |
108 | 117 | ||
118 | QHBoxLayout *hbox3 = new QHBoxLayout( vbox, -1, "HBox1" ); | ||
119 | QHBoxLayout *hbox4 = new QHBoxLayout( vbox, -1, "HBox1" ); | ||
120 | |||
121 | char text[2]; | ||
122 | text[1] = '\0'; | ||
123 | for ( int i = 0 ; i < 26 ; ++i ) | ||
124 | { | ||
125 | text[0] = 'A' + i; | ||
126 | LetterPushButton *b = new LetterPushButton( text, this ); | ||
127 | connect( b, SIGNAL( released( QString ) ), this, SLOT( letterPushed( QString ) ) ); | ||
128 | if ( i < 16 ) | ||
129 | hbox3->addWidget( b ); | ||
130 | else | ||
131 | hbox4->addWidget( b ); | ||
132 | } | ||
133 | |||
109 | vbox->addWidget( packagesList ); | 134 | vbox->addWidget( packagesList ); |
110 | packagesList->addColumn( "Packages" ); | 135 | packagesList->addColumn( "Packages" ); |
111 | 136 | ||
112 | QHBoxLayout *hbox2 = new QHBoxLayout( vbox, -1, "HBox2" ); | 137 | QHBoxLayout *hbox2 = new QHBoxLayout( vbox, -1, "HBox2" ); |
113 | hbox2->addWidget( update ); | 138 | hbox2->addWidget( update ); |
114 | hbox2->addWidget( download ); | 139 | hbox2->addWidget( download ); |
115 | hbox2->addWidget( upgrade ); | 140 | hbox2->addWidget( upgrade ); |
116 | hbox2->addWidget( apply ); | 141 | hbox2->addWidget( apply ); |
117 | } | 142 | } |
118 | 143 | ||
119 | void NetworkPackageManager :: setupConnections() | 144 | void NetworkPackageManager :: setupConnections() |
120 | { | 145 | { |
121 | connect( serversList, SIGNAL(activated( int )), this, SLOT(serverSelected( int ))); | 146 | connect( serversList, SIGNAL(activated( int )), this, SLOT(serverSelected( int ))); |
122 | connect( apply, SIGNAL(released()), this, SLOT(applyChanges()) ); | 147 | connect( apply, SIGNAL(released()), this, SLOT(applyChanges()) ); |
123 | connect( download, SIGNAL(released()), this, SLOT(downloadPackage()) ); | 148 | connect( download, SIGNAL(released()), this, SLOT(downloadPackage()) ); |
124 | connect( upgrade, SIGNAL( released()), this, SLOT(upgradePackages()) ); | 149 | connect( upgrade, SIGNAL( released()), this, SLOT(upgradePackages()) ); |
125 | connect( update, SIGNAL(released()), this, SLOT(updateServer()) ); | 150 | connect( update, SIGNAL(released()), this, SLOT(updateServer()) ); |
126 | } | 151 | } |
127 | 152 | ||
128 | void NetworkPackageManager :: showProgressDialog( char *initialText ) | 153 | void NetworkPackageManager :: showProgressDialog( char *initialText ) |
129 | { | 154 | { |
130 | if ( !progressDlg ) | 155 | if ( !progressDlg ) |
131 | progressDlg = new ProgressDlg( this, "Progress", false ); | 156 | progressDlg = new ProgressDlg( this, "Progress", false ); |
132 | progressDlg->setText( initialText ); | 157 | progressDlg->setText( initialText ); |
133 | progressDlg->show(); | 158 | progressDlg->show(); |
134 | } | 159 | } |
135 | 160 | ||
136 | 161 | ||
137 | void NetworkPackageManager :: serverSelected( int ) | 162 | void NetworkPackageManager :: serverSelected( int ) |
138 | { | 163 | { |
139 | packagesList->clear(); | 164 | packagesList->clear(); |
140 | 165 | ||
141 | // display packages | 166 | // display packages |
142 | QString serverName = serversList->currentText(); | 167 | QString serverName = serversList->currentText(); |
168 | currentlySelectedServer = serverName; | ||
169 | |||
170 | #ifdef QWS | ||
171 | // read download directory from config file | ||
172 | Config cfg( "aqpkg" ); | ||
173 | cfg.setGroup( "settings" ); | ||
174 | cfg.writeEntry( "selectedServer", currentlySelectedServer ); | ||
175 | #endif | ||
176 | |||
143 | Server *s = dataMgr->getServer( serverName ); | 177 | Server *s = dataMgr->getServer( serverName ); |
144 | dataMgr->setActiveServer( serverName ); | 178 | // dataMgr->setActiveServer( serverName ); |
145 | 179 | ||
146 | vector<Package> &list = s->getPackageList(); | 180 | vector<Package> &list = s->getPackageList(); |
147 | vector<Package>::iterator it; | 181 | vector<Package>::iterator it; |
148 | for ( it = list.begin() ; it != list.end() ; ++it ) | 182 | for ( it = list.begin() ; it != list.end() ; ++it ) |
149 | { | 183 | { |
150 | QString text = ""; | 184 | QString text = ""; |
151 | 185 | ||
152 | // If the local server, only display installed packages | 186 | // If the local server, only display installed packages |
153 | if ( serverName == LOCAL_SERVER && !it->isInstalled() ) | 187 | if ( serverName == LOCAL_SERVER && !it->isInstalled() ) |
154 | continue; | 188 | continue; |
155 | 189 | ||
156 | text += it->getPackageName(); | 190 | text += it->getPackageName(); |
157 | if ( it->isInstalled() ) | 191 | if ( it->isInstalled() ) |
158 | { | 192 | { |
159 | text += " (installed)"; | 193 | text += " (installed)"; |
160 | 194 | ||
161 | // If a different version of package is available, postfix it with an * | 195 | // If a different version of package is available, postfix it with an * |
162 | if ( it->getVersion() != it->getInstalledVersion() ) | 196 | if ( it->getVersion() != it->getInstalledVersion() ) |
163 | text += "*"; | 197 | text += "*"; |
164 | } | 198 | } |
165 | 199 | ||
166 | QCheckListItem *item = new QCheckListItem( packagesList, text, QCheckListItem::CheckBox ); | 200 | QCheckListItem *item = new QCheckListItem( packagesList, text, QCheckListItem::CheckBox ); |
167 | if ( !it->isPackageStoredLocally() ) | 201 | if ( !it->isPackageStoredLocally() ) |
168 | new QCheckListItem( item, QString( "Description - " ) + it->getDescription() ); | 202 | new QCheckListItem( item, QString( "Description - " ) + it->getDescription() ); |
169 | else | 203 | else |
170 | new QCheckListItem( item, QString( "Filename - " ) + it->getFilename() ); | 204 | new QCheckListItem( item, QString( "Filename - " ) + it->getFilename() ); |
171 | 205 | ||
172 | new QCheckListItem( item, QString( "V. Available - " ) + it->getVersion() ); | 206 | new QCheckListItem( item, QString( "V. Available - " ) + it->getVersion() ); |
173 | if ( it->getLocalPackage() ) | 207 | if ( it->getLocalPackage() ) |
174 | { | 208 | { |
175 | if ( it->isInstalled() ) | 209 | if ( it->isInstalled() ) |
176 | new QCheckListItem( item, QString( "V. Installed - " ) + it->getInstalledVersion() ); | 210 | new QCheckListItem( item, QString( "V. Installed - " ) + it->getInstalledVersion() ); |
177 | } | 211 | } |
178 | packagesList->insertItem( item ); | 212 | packagesList->insertItem( item ); |
179 | } | 213 | } |
180 | 214 | ||
181 | // If the local server or the local ipkgs server disable the download button | 215 | // If the local server or the local ipkgs server disable the download button |
182 | if ( serverName == LOCAL_SERVER ) | 216 | if ( serverName == LOCAL_SERVER ) |
183 | { | 217 | { |
184 | upgrade->setEnabled( false ); | 218 | upgrade->setEnabled( false ); |
185 | download->setText( "Download" ); | 219 | download->setText( "Download" ); |
186 | download->setEnabled( false ); | 220 | download->setEnabled( false ); |
187 | } | 221 | } |
188 | else if ( serverName == LOCAL_IPKGS ) | 222 | else if ( serverName == LOCAL_IPKGS ) |
189 | { | 223 | { |
190 | upgrade->setEnabled( false ); | 224 | upgrade->setEnabled( false ); |
191 | download->setEnabled( true ); | 225 | download->setEnabled( true ); |
192 | download->setText( "Remove" ); | 226 | download->setText( "Remove" ); |
193 | } | 227 | } |
194 | else | 228 | else |
195 | { | 229 | { |
196 | upgrade->setEnabled( true ); | 230 | upgrade->setEnabled( true ); |
197 | download->setEnabled( true ); | 231 | download->setEnabled( true ); |
198 | download->setText( "Download" ); | 232 | download->setText( "Download" ); |
199 | } | 233 | } |
200 | } | 234 | } |
201 | 235 | ||
202 | void NetworkPackageManager :: updateServer() | 236 | void NetworkPackageManager :: updateServer() |
203 | { | 237 | { |
204 | QString serverName = serversList->currentText(); | 238 | QString serverName = serversList->currentText(); |
205 | 239 | ||
206 | // Update the current server | 240 | // Update the current server |
207 | // Display dialog | 241 | // Display dialog |
208 | ProgressDlg *dlg = new ProgressDlg( this ); | 242 | ProgressDlg *dlg = new ProgressDlg( this ); |
209 | QString status = "Updating package list for "; | 243 | QString status = "Updating package lists..."; |
210 | status += serverName; | ||
211 | dlg->show(); | 244 | dlg->show(); |
212 | dlg->setText( status ); | 245 | dlg->setText( status ); |
213 | 246 | ||
214 | // Disable buttons to stop silly people clicking lots on them :) | 247 | // Disable buttons to stop silly people clicking lots on them :) |
215 | 248 | ||
216 | // First, write out ipkg_conf file so that ipkg can use it | 249 | // First, write out ipkg_conf file so that ipkg can use it |
217 | dataMgr->writeOutIpkgConf(); | 250 | dataMgr->writeOutIpkgConf(); |
218 | 251 | ||
219 | if ( serverName == LOCAL_SERVER ) | 252 | // if ( serverName == LOCAL_SERVER ) |
220 | ; | 253 | // ; |
221 | else if ( serverName == LOCAL_IPKGS ) | 254 | // else if ( serverName == LOCAL_IPKGS ) |
222 | ; | 255 | // ; |
223 | else | 256 | // else |
224 | { | 257 | { |
225 | QString option = "update"; | 258 | QString option = "update"; |
226 | QString dummy = ""; | 259 | QString dummy = ""; |
227 | Ipkg ipkg; | 260 | Ipkg ipkg; |
228 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); | 261 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); |
229 | ipkg.setOption( option ); | 262 | ipkg.setOption( option ); |
230 | 263 | ||
231 | ipkg.runIpkg( ); | 264 | ipkg.runIpkg( ); |
232 | } | 265 | } |
233 | 266 | ||
234 | // Reload data | 267 | // Reload data |
235 | dataMgr->reloadServerData( serversList->currentText() ); | 268 | dataMgr->reloadServerData( serversList->currentText() ); |
236 | serverSelected(-1); | 269 | serverSelected(-1); |
237 | delete dlg; | 270 | delete dlg; |
238 | } | 271 | } |
239 | 272 | ||
240 | void NetworkPackageManager :: upgradePackages() | 273 | void NetworkPackageManager :: upgradePackages() |
241 | { | 274 | { |
242 | // We're gonna do an upgrade of all packages | 275 | // We're gonna do an upgrade of all packages |
243 | // First warn user that this isn't recommended | 276 | // First warn user that this isn't recommended |
244 | QString text = "WARNING: Upgrading while\nOpie/Qtopia is running\nis NOT recommended!\n\nAre you sure?\n"; | 277 | QString text = "WARNING: Upgrading while\nOpie/Qtopia is running\nis NOT recommended!\n\nAre you sure?\n"; |
245 | QMessageBox warn("Warning", text, QMessageBox::Warning, | 278 | QMessageBox warn("Warning", text, QMessageBox::Warning, |
246 | QMessageBox::Yes, | 279 | QMessageBox::Yes, |
247 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default , | 280 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default , |
248 | 0, this ); | 281 | 0, this ); |
249 | warn.adjustSize(); | 282 | warn.adjustSize(); |
250 | 283 | ||
251 | if ( warn.exec() == QMessageBox::Yes ) | 284 | if ( warn.exec() == QMessageBox::Yes ) |
252 | { | 285 | { |
253 | // First, write out ipkg_conf file so that ipkg can use it | 286 | // First, write out ipkg_conf file so that ipkg can use it |
254 | dataMgr->writeOutIpkgConf(); | 287 | dataMgr->writeOutIpkgConf(); |
255 | 288 | ||
256 | // Now run upgrade | 289 | // Now run upgrade |
257 | InstallDlgImpl dlg( this, "Upgrade", true ); | 290 | InstallDlgImpl dlg( this, "Upgrade", true ); |
258 | dlg.showDlg(); | 291 | dlg.showDlg(); |
259 | 292 | ||
260 | // Reload data | 293 | // Reload data |
261 | dataMgr->reloadServerData( LOCAL_SERVER ); | 294 | dataMgr->reloadServerData( LOCAL_SERVER ); |
262 | 295 | ||
263 | dataMgr->reloadServerData( serversList->currentText() ); | 296 | dataMgr->reloadServerData( serversList->currentText() ); |
264 | serverSelected(-1); | 297 | serverSelected(-1); |
265 | } | 298 | } |
266 | } | 299 | } |
267 | 300 | ||
268 | 301 | ||
269 | void NetworkPackageManager :: downloadPackage() | 302 | void NetworkPackageManager :: downloadPackage() |
270 | { | 303 | { |
271 | if ( download->text() == "Download" ) | 304 | if ( download->text() == "Download" ) |
272 | { | 305 | { |
273 | // First, write out ipkg_conf file so that ipkg can use it | 306 | // First, write out ipkg_conf file so that ipkg can use it |
274 | dataMgr->writeOutIpkgConf(); | 307 | dataMgr->writeOutIpkgConf(); |
275 | 308 | ||
276 | // Display dialog to user asking where to download the files to | 309 | // Display dialog to user asking where to download the files to |
277 | bool ok = FALSE; | 310 | bool ok = FALSE; |
278 | QString dir = ""; | 311 | QString dir = ""; |
279 | #ifdef QWS | 312 | #ifdef QWS |
280 | // read download directory from config file | 313 | // read download directory from config file |
281 | Config cfg( "aqpkg" ); | 314 | Config cfg( "aqpkg" ); |
282 | cfg.setGroup( "settings" ); | 315 | cfg.setGroup( "settings" ); |
283 | dir = cfg.readEntry( "downloadDir", "/home/root/Documents/application/ipkg" ); | 316 | dir = cfg.readEntry( "downloadDir", "/home/root/Documents/application/ipkg" ); |
284 | #endif | 317 | #endif |
285 | 318 | ||
286 | QString text = InputDialog::getText( tr( "Download to where" ), tr( "Enter path to download to" ), dir, &ok, this ); | 319 | QString text = InputDialog::getText( tr( "Download to where" ), tr( "Enter path to download to" ), dir, &ok, this ); |
287 | if ( ok && !text.isEmpty() ) | 320 | if ( ok && !text.isEmpty() ) |
288 | dir = text; // user entered something and pressed ok | 321 | dir = text; // user entered something and pressed ok |
289 | else | 322 | else |
290 | return; // user entered nothing or pressed cancel | 323 | return; // user entered nothing or pressed cancel |
291 | 324 | ||
292 | #ifdef QWS | 325 | #ifdef QWS |
293 | // Store download directory in config file | 326 | // Store download directory in config file |
294 | cfg.writeEntry( "downloadDir", dir ); | 327 | cfg.writeEntry( "downloadDir", dir ); |
295 | #endif | 328 | #endif |
296 | 329 | ||
297 | // Get starting directory | 330 | // Get starting directory |
298 | char initDir[PATH_MAX]; | 331 | char initDir[PATH_MAX]; |
299 | getcwd( initDir, PATH_MAX ); | 332 | getcwd( initDir, PATH_MAX ); |
300 | 333 | ||
301 | // Download each package | 334 | // Download each package |
302 | Ipkg ipkg; | 335 | Ipkg ipkg; |
303 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); | 336 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); |
304 | 337 | ||
305 | QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | ||
306 | ipkg.setOption( "download" ); | 338 | ipkg.setOption( "download" ); |
307 | ipkg.setRuntimeDirectory( dir ); | 339 | ipkg.setRuntimeDirectory( dir ); |
308 | do | 340 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); |
341 | item != 0 ; | ||
342 | item = (QCheckListItem *)item->nextSibling() ) | ||
309 | { | 343 | { |
310 | if ( item->isOn() ) | 344 | if ( item->isOn() ) |
311 | { | 345 | { |
312 | QString name = item->text(); | 346 | QString name = item->text(); |
313 | int pos = name.find( "*" ); | 347 | int pos = name.find( "*" ); |
314 | name.truncate( pos ); | 348 | name.truncate( pos ); |
315 | 349 | ||
316 | // if (there is a (installed), remove it | 350 | // if (there is a (installed), remove it |
317 | pos = name.find( "(installed)" ); | 351 | pos = name.find( "(installed)" ); |
318 | if ( pos > 0 ) | 352 | if ( pos > 0 ) |
319 | name.truncate( pos - 1 ); | 353 | name.truncate( pos - 1 ); |
320 | 354 | ||
321 | ipkg.setPackage( name ); | 355 | ipkg.setPackage( name ); |
322 | ipkg.runIpkg( ); | 356 | ipkg.runIpkg( ); |
323 | } | 357 | } |
324 | 358 | } | |
325 | item = (QCheckListItem *)item->nextSibling(); | ||
326 | } while ( item ); | ||
327 | } | 359 | } |
328 | else if ( download->text() == "Remove" ) | 360 | else if ( download->text() == "Remove" ) |
329 | { | 361 | { |
330 | QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | 362 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); |
331 | do | 363 | item != 0 ; |
364 | item = (QCheckListItem *)item->nextSibling() ) | ||
332 | { | 365 | { |
333 | if ( item->isOn() ) | 366 | if ( item->isOn() ) |
334 | { | 367 | { |
335 | QString name = item->text(); | 368 | QString name = item->text(); |
336 | int pos = name.find( "*" ); | 369 | int pos = name.find( "*" ); |
337 | name.truncate( pos ); | 370 | name.truncate( pos ); |
338 | 371 | ||
339 | // if (there is a (installed), remove it | 372 | // if (there is a (installed), remove it |
340 | pos = name.find( "(installed)" ); | 373 | pos = name.find( "(installed)" ); |
341 | if ( pos > 0 ) | 374 | if ( pos > 0 ) |
342 | name.truncate( pos - 1 ); | 375 | name.truncate( pos - 1 ); |
343 | 376 | ||
344 | Package *p = dataMgr->getServer( serversList->currentText() )->getPackage( name ); | 377 | Package *p = dataMgr->getServer( serversList->currentText() )->getPackage( name ); |
345 | QFile f( p->getFilename() ); | 378 | QFile f( p->getFilename() ); |
346 | f.remove(); | 379 | f.remove(); |
347 | } | 380 | } |
348 | item = (QCheckListItem *)item->nextSibling(); | 381 | } |
349 | } while ( item ); | ||
350 | } | 382 | } |
351 | 383 | ||
352 | dataMgr->reloadServerData( LOCAL_IPKGS ); | 384 | dataMgr->reloadServerData( LOCAL_IPKGS ); |
353 | serverSelected( -1 ); | 385 | serverSelected( -1 ); |
354 | } | 386 | } |
355 | 387 | ||
356 | 388 | ||
357 | void NetworkPackageManager :: applyChanges() | 389 | void NetworkPackageManager :: applyChanges() |
358 | { | 390 | { |
359 | // Disable buttons to stop silly people clicking lots on them :) | 391 | // Disable buttons to stop silly people clicking lots on them :) |
360 | 392 | ||
361 | // First, write out ipkg_conf file so that ipkg can use it | 393 | // First, write out ipkg_conf file so that ipkg can use it |
362 | dataMgr->writeOutIpkgConf(); | 394 | dataMgr->writeOutIpkgConf(); |
363 | 395 | ||
364 | // Now for each selected item | 396 | // Now for each selected item |
365 | // deal with it | 397 | // deal with it |
366 | 398 | ||
367 | vector<QString> workingPackages; | 399 | vector<QString> workingPackages; |
368 | QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | 400 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); |
369 | do | 401 | item != 0 ; |
402 | item = (QCheckListItem *)item->nextSibling() ) | ||
370 | { | 403 | { |
371 | if ( item->isOn() ) | 404 | if ( item->isOn() ) |
372 | { | 405 | { |
373 | QString p = dealWithItem( item ); | 406 | QString p = dealWithItem( item ); |
374 | workingPackages.push_back( p ); | 407 | workingPackages.push_back( p ); |
375 | } | 408 | } |
376 | 409 | } | |
377 | item = (QCheckListItem *)item->nextSibling(); | ||
378 | } while ( item ); | ||
379 | 410 | ||
380 | // do the stuff | 411 | // do the stuff |
381 | InstallDlgImpl dlg( workingPackages, dataMgr, this, "Install", true ); | 412 | InstallDlgImpl dlg( workingPackages, dataMgr, this, "Install", true ); |
382 | dlg.showDlg(); | 413 | dlg.showDlg(); |
383 | 414 | ||
384 | // Reload data | 415 | // Reload data |
385 | dataMgr->reloadServerData( LOCAL_SERVER ); | 416 | dataMgr->reloadServerData( LOCAL_SERVER ); |
386 | 417 | ||
387 | dataMgr->reloadServerData( serversList->currentText() ); | 418 | dataMgr->reloadServerData( serversList->currentText() ); |
388 | serverSelected(-1); | 419 | serverSelected(-1); |
389 | 420 | ||
390 | #ifdef QWS | 421 | #ifdef QWS |
391 | // Finally let the main system update itself | 422 | // Finally let the main system update itself |
392 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 423 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
393 | QString lf = QString::null; | 424 | QString lf = QString::null; |
394 | e << lf; | 425 | e << lf; |
395 | #endif | 426 | #endif |
396 | } | 427 | } |
397 | 428 | ||
398 | // decide what to do - either remove, upgrade or install | 429 | // decide what to do - either remove, upgrade or install |
399 | // Current rules: | 430 | // Current rules: |
400 | // If not installed - install | 431 | // If not installed - install |
401 | // If installed and different version available - upgrade | 432 | // If installed and different version available - upgrade |
402 | // If installed and version up to date - remove | 433 | // If installed and version up to date - remove |
403 | QString NetworkPackageManager :: dealWithItem( QCheckListItem *item ) | 434 | QString NetworkPackageManager :: dealWithItem( QCheckListItem *item ) |
404 | { | 435 | { |
405 | QString name = item->text(); | 436 | QString name = item->text(); |
406 | int pos = name.find( "*" ); | 437 | int pos = name.find( "*" ); |
407 | name.truncate( pos ); | 438 | name.truncate( pos ); |
408 | 439 | ||
409 | // if (there is a (installed), remove it | 440 | // if (there is a (installed), remove it |
410 | pos = name.find( "(installed)" ); | 441 | pos = name.find( "(installed)" ); |
411 | if ( pos > 0 ) | 442 | if ( pos > 0 ) |
412 | name.truncate( pos - 1 ); | 443 | name.truncate( pos - 1 ); |
413 | 444 | ||
414 | // Get package | 445 | // Get package |
415 | Server *s = dataMgr->getServer( serversList->currentText() ); | 446 | Server *s = dataMgr->getServer( serversList->currentText() ); |
416 | Package *p = s->getPackage( name ); | 447 | Package *p = s->getPackage( name ); |
417 | 448 | ||
418 | // If the package has a filename then it is a local file | 449 | // If the package has a filename then it is a local file |
419 | if ( p->isPackageStoredLocally() ) | 450 | if ( p->isPackageStoredLocally() ) |
420 | name = p->getFilename(); | 451 | name = p->getFilename(); |
421 | QString option; | 452 | QString option; |
422 | QString dest = "root"; | 453 | QString dest = "root"; |
423 | if ( !p->isInstalled() ) | 454 | if ( !p->isInstalled() ) |
424 | return QString( "I" ) + name; | 455 | return QString( "I" ) + name; |
425 | else | 456 | else |
426 | { | 457 | { |
427 | if ( p->getVersion() == p->getInstalledVersion() ) | 458 | if ( p->getVersion() == p->getInstalledVersion() ) |
428 | { | 459 | { |
429 | QString msgtext; | 460 | QString msgtext; |
430 | msgtext.sprintf( "Do you wish to remove or reinstall\n%s?", (const char *)name ); | 461 | msgtext.sprintf( "Do you wish to remove or reinstall\n%s?", (const char *)name ); |
431 | switch( QMessageBox::information( this, "Remove or ReInstall", | 462 | switch( QMessageBox::information( this, "Remove or ReInstall", |
432 | msgtext, "Remove", "ReInstall" ) ) | 463 | msgtext, "Remove", "ReInstall" ) ) |
433 | { | 464 | { |
434 | case 0: // Try again or Enter | 465 | case 0: // Try again or Enter |
435 | return QString( "D" ) + name; | 466 | return QString( "D" ) + name; |
436 | break; | 467 | break; |
437 | case 1: // Quit or Escape | 468 | case 1: // Quit or Escape |
438 | return QString( "U" ) + name; | 469 | return QString( "U" ) + name; |
439 | break; | 470 | break; |
440 | } | 471 | } |
441 | 472 | ||
442 | // User hit cancel (on dlg - assume remove) | 473 | // User hit cancel (on dlg - assume remove) |
443 | return QString( "D" ) + name; | 474 | return QString( "D" ) + name; |
444 | } | 475 | } |
445 | else | 476 | else |
446 | return QString( "U" ) + name; | 477 | return QString( "U" ) + name; |
447 | } | 478 | } |
448 | } | 479 | } |
449 | 480 | ||
450 | void NetworkPackageManager :: displayText( const QString &t ) | 481 | void NetworkPackageManager :: displayText( const QString &t ) |
451 | { | 482 | { |
452 | cout << t << endl; | 483 | cout << t << endl; |
453 | } | 484 | } |
485 | |||
486 | |||
487 | void NetworkPackageManager :: letterPushed( QString t ) | ||
488 | { | ||
489 | QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | ||
490 | do | ||
491 | { | ||
492 | if ( item->text().lower().startsWith( t.lower() ) ) | ||
493 | { | ||
494 | cout << "Found - item->text()" << endl; | ||
495 | packagesList->setSelected( item, true ); | ||
496 | packagesList->ensureItemVisible( item ); | ||
497 | break; | ||
498 | } | ||
499 | |||
500 | item = (QCheckListItem *)item->nextSibling(); | ||
501 | } while ( item ); | ||
502 | } | ||
diff --git a/noncore/settings/aqpkg/networkpkgmgr.h b/noncore/settings/aqpkg/networkpkgmgr.h index 8a88b35..0ae64a6 100644 --- a/noncore/settings/aqpkg/networkpkgmgr.h +++ b/noncore/settings/aqpkg/networkpkgmgr.h | |||
@@ -1,72 +1,74 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
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 | 29 | ||
30 | /** NetworkPackageManager is the base class of the project */ | 30 | /** NetworkPackageManager is the base class of the project */ |
31 | class NetworkPackageManager : public QWidget | 31 | class NetworkPackageManager : public QWidget |
32 | { | 32 | { |
33 | Q_OBJECT | 33 | Q_OBJECT |
34 | public: | 34 | public: |
35 | /** construtor */ | 35 | /** construtor */ |
36 | NetworkPackageManager( DataManager *dataManager, QWidget* parent=0, const char *name=0); | 36 | NetworkPackageManager( DataManager *dataManager, QWidget* parent=0, const char *name=0); |
37 | /** destructor */ | 37 | /** destructor */ |
38 | ~NetworkPackageManager(); | 38 | ~NetworkPackageManager(); |
39 | 39 | ||
40 | void updateData(); | 40 | void updateData(); |
41 | 41 | ||
42 | private: | 42 | private: |
43 | DataManager *dataMgr; | 43 | DataManager *dataMgr; |
44 | 44 | ||
45 | QComboBox *serversList; | 45 | QComboBox *serversList; |
46 | QListView *packagesList; | 46 | QListView *packagesList; |
47 | QPushButton *update; | 47 | QPushButton *update; |
48 | QPushButton *upgrade; | 48 | QPushButton *upgrade; |
49 | QPushButton *download; | 49 | QPushButton *download; |
50 | QPushButton *apply; | 50 | QPushButton *apply; |
51 | 51 | ||
52 | ProgressDlg *progressDlg; | 52 | ProgressDlg *progressDlg; |
53 | QString currentlySelectedServer; | ||
53 | 54 | ||
54 | int timerId; | 55 | int timerId; |
55 | 56 | ||
56 | void timerEvent ( QTimerEvent * ); | 57 | void timerEvent ( QTimerEvent * ); |
57 | 58 | ||
58 | void initGui(); | 59 | void initGui(); |
59 | void setupConnections(); | 60 | void setupConnections(); |
60 | void showProgressDialog( char *initialText ); | 61 | void showProgressDialog( char *initialText ); |
61 | QString dealWithItem( QCheckListItem *item ); | 62 | QString dealWithItem( QCheckListItem *item ); |
62 | 63 | ||
63 | public slots: | 64 | public slots: |
64 | void serverSelected( int index ); | 65 | void serverSelected( int index ); |
65 | void applyChanges(); | 66 | void applyChanges(); |
66 | void upgradePackages(); | 67 | void upgradePackages(); |
67 | void downloadPackage(); | 68 | void downloadPackage(); |
68 | void updateServer(); | 69 | void updateServer(); |
69 | void displayText( const QString &t ); | 70 | void displayText( const QString &t ); |
71 | void letterPushed( QString t ); | ||
70 | }; | 72 | }; |
71 | 73 | ||
72 | #endif | 74 | #endif |