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