-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,291 +1,292 @@ | |||
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 |