Diffstat (limited to 'noncore/settings/packagemanager/opackagemanager.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/packagemanager/opackagemanager.cpp | 330 |
1 files changed, 330 insertions, 0 deletions
diff --git a/noncore/settings/packagemanager/opackagemanager.cpp b/noncore/settings/packagemanager/opackagemanager.cpp new file mode 100644 index 0000000..6bef918 --- a/dev/null +++ b/noncore/settings/packagemanager/opackagemanager.cpp | |||
@@ -0,0 +1,330 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | |||
4 | Copyright (c) 2003 Dan Williams <drw@handhelds.org> | ||
5 | =. | ||
6 | .=l. | ||
7 | .>+-= | ||
8 | _;:, .> :=|. This program is free software; you can | ||
9 | .> <`_, > . <= redistribute it and/or modify it under | ||
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
11 | .="- .-=="i, .._ License as published by the Free Software | ||
12 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
13 | ._= =} : or (at your option) any later version. | ||
14 | .%`+i> _;_. | ||
15 | .i_,=:_. -<s. This program is distributed in the hope that | ||
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
17 | : .. .:, . . . without even the implied warranty of | ||
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
20 | ..}^=.= = ; Library General Public License for more | ||
21 | ++= -. .` .: details. | ||
22 | : = ...= . :.=- | ||
23 | -. .:....=;==+<; You should have received a copy of the GNU | ||
24 | -_. . . )=. = Library General Public License along with | ||
25 | -- :-=` this library; see the file COPYING.LIB. | ||
26 | If not, write to the Free Software Foundation, | ||
27 | Inc., 59 Temple Place - Suite 330, | ||
28 | Boston, MA 02111-1307, USA. | ||
29 | |||
30 | */ | ||
31 | |||
32 | #include <qpe/qpeapplication.h> | ||
33 | |||
34 | #include "opackagemanager.h" | ||
35 | #include "oipkgconfigdlg.h" | ||
36 | |||
37 | OPackageManager::OPackageManager( Config *config, QObject *parent, const char *name ) | ||
38 | : QObject( parent, name ) | ||
39 | , m_config( config ) | ||
40 | , m_ipkg( m_config, this ) | ||
41 | , m_packages( 9973 ) | ||
42 | , m_categories() | ||
43 | { | ||
44 | m_packages.setAutoDelete( true ); | ||
45 | } | ||
46 | |||
47 | void OPackageManager::loadAvailablePackages() | ||
48 | { | ||
49 | m_packages.clear(); | ||
50 | |||
51 | OConfItemList *serverList = m_ipkg.servers(); | ||
52 | |||
53 | if ( serverList ) | ||
54 | { | ||
55 | // Initialize status messaging | ||
56 | emit initStatus( serverList->count() ); | ||
57 | int serverCount = 0; | ||
58 | |||
59 | bool categoryAdded = false; | ||
60 | |||
61 | for ( OConfItemListIterator serverIt( *serverList ); serverIt.current(); ++serverIt ) | ||
62 | { | ||
63 | OConfItem *server = serverIt.current(); | ||
64 | |||
65 | // Process server only if it is active | ||
66 | if ( server->active() ) | ||
67 | { | ||
68 | // Update status | ||
69 | QString status = tr( "Reading available packages:\n\t" ); | ||
70 | status.append( server->name() ); | ||
71 | emit statusText( status ); | ||
72 | ++serverCount; | ||
73 | emit statusBar( serverCount ); | ||
74 | qApp->processEvents(); | ||
75 | |||
76 | OPackageList *packageList = m_ipkg.availablePackages( server->name() ); | ||
77 | if ( packageList ) | ||
78 | { | ||
79 | for ( OPackageListIterator packageIt( *packageList ); packageIt.current(); ++packageIt ) | ||
80 | { | ||
81 | OPackage *package = packageIt.current(); | ||
82 | |||
83 | // Load package info | ||
84 | if ( !m_packages.find( package->name() ) ) | ||
85 | m_packages.insert( package->name(), package ); | ||
86 | else | ||
87 | { | ||
88 | // If new package is newer version, replace existing package | ||
89 | OPackage *currPackage = m_packages[package->name()]; | ||
90 | if ( compareVersions( package->version(), currPackage->version() ) == 1 ) | ||
91 | m_packages.replace( package->name(), package ); | ||
92 | } | ||
93 | |||
94 | // Add category to list if it doesn't already exist | ||
95 | if ( m_categories.grep( package->category() ).isEmpty() ) | ||
96 | { | ||
97 | m_categories << package->category(); | ||
98 | categoryAdded = true; | ||
99 | } | ||
100 | } | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | delete serverList; | ||
105 | |||
106 | // Sort category list if categories were added | ||
107 | if ( categoryAdded ) | ||
108 | m_categories.sort(); | ||
109 | } | ||
110 | } | ||
111 | |||
112 | void OPackageManager::loadInstalledPackages() | ||
113 | { | ||
114 | OConfItemList *destList = m_ipkg.destinations(); | ||
115 | |||
116 | if ( destList ) | ||
117 | { | ||
118 | // Initialize status messaging | ||
119 | emit initStatus( destList->count() ); | ||
120 | int destCount = 0; | ||
121 | |||
122 | bool categoryAdded = false; | ||
123 | |||
124 | for ( OConfItemListIterator destIt( *destList ); destIt.current(); ++destIt ) | ||
125 | { | ||
126 | OConfItem *destination = destIt.current(); | ||
127 | |||
128 | // Process destination only if it is active | ||
129 | if ( destination->active() ) | ||
130 | { | ||
131 | // Update status | ||
132 | QString status = tr( "Reading installed packages:\n\t" ); | ||
133 | status.append( destination->name() ); | ||
134 | emit statusText( status ); | ||
135 | ++destCount; | ||
136 | emit statusBar( destCount ); | ||
137 | qApp->processEvents(); | ||
138 | |||
139 | OPackageList *packageList = m_ipkg.installedPackages( destination->name(), | ||
140 | destination->value() ); | ||
141 | if ( packageList ) | ||
142 | { | ||
143 | for ( OPackageListIterator packageIt( *packageList ); packageIt.current(); ++packageIt ) | ||
144 | { | ||
145 | OPackage *package = packageIt.current(); | ||
146 | OPackage *currPackage = m_packages[package->name()]; | ||
147 | if ( currPackage ) | ||
148 | { | ||
149 | // Package is in a current feed, update installed version, destination | ||
150 | currPackage->setVersionInstalled( package->versionInstalled() ); | ||
151 | currPackage->setDestination( package->destination() ); | ||
152 | |||
153 | delete package; | ||
154 | } | ||
155 | else | ||
156 | { | ||
157 | // Package isn't in a current feed, add to list | ||
158 | m_packages.insert( package->name(), package ); | ||
159 | |||
160 | // Add category to list if it doesn't already exist | ||
161 | if ( m_categories.grep( package->category() ).isEmpty() ) | ||
162 | { | ||
163 | m_categories << package->category(); | ||
164 | categoryAdded = true; | ||
165 | } | ||
166 | } | ||
167 | } | ||
168 | } | ||
169 | } | ||
170 | } | ||
171 | delete destList; | ||
172 | |||
173 | // Sort category list if categories were added | ||
174 | if ( categoryAdded ) | ||
175 | m_categories.sort(); | ||
176 | } | ||
177 | } | ||
178 | |||
179 | OPackageList *OPackageManager::packages() | ||
180 | { | ||
181 | // TODO - look to see if list is loaded, if not, load available & installed | ||
182 | |||
183 | OPackageList *pl = new OPackageList; | ||
184 | |||
185 | for ( QDictIterator<OPackage> packageIt( m_packages ); packageIt.current(); ++packageIt ) | ||
186 | pl->append( packageIt.current() ); | ||
187 | |||
188 | return pl; | ||
189 | } | ||
190 | |||
191 | OPackageList *OPackageManager::filterPackages( const QString &name,const QString &server, | ||
192 | const QString &destination, Status status, const QString &category ) | ||
193 | { | ||
194 | // TODO - look to see if list is loaded, if not, load available & installed | ||
195 | |||
196 | OPackageList *pl = new OPackageList; | ||
197 | for ( QDictIterator<OPackage> packageIt( m_packages ); packageIt.current(); ++packageIt ) | ||
198 | { | ||
199 | OPackage *package = packageIt.current(); | ||
200 | |||
201 | bool nameMatch = ( name.isNull() || package->name().contains( name ) ); | ||
202 | bool serverMatch = ( server.isNull() || package->source() == server ); | ||
203 | bool destinationMatch = ( destination.isNull() || package->destination() == destination ); | ||
204 | bool statusMatch; | ||
205 | switch ( status ) | ||
206 | { | ||
207 | case All : statusMatch = true; | ||
208 | break; | ||
209 | case NotInstalled : statusMatch = package->versionInstalled().isNull(); | ||
210 | break; | ||
211 | case Installed : statusMatch = !package->versionInstalled().isNull(); | ||
212 | break; | ||
213 | case Updated : statusMatch = ( !package->versionInstalled().isNull() && | ||
214 | compareVersions( package->version(), package->versionInstalled() ) == 1 ); | ||
215 | break; | ||
216 | default : statusMatch = true; | ||
217 | break; | ||
218 | }; | ||
219 | bool categoryMatch = ( category.isNull() || package->category() == category ); | ||
220 | |||
221 | if ( nameMatch && serverMatch && destinationMatch && statusMatch && categoryMatch ) | ||
222 | pl->append( packageIt.current() ); | ||
223 | } | ||
224 | |||
225 | return pl; | ||
226 | } | ||
227 | |||
228 | QStringList *OPackageManager::servers() | ||
229 | { | ||
230 | QStringList *sl = new QStringList(); | ||
231 | |||
232 | OConfItemList *serverList = m_ipkg.servers(); | ||
233 | if ( serverList ) | ||
234 | { | ||
235 | for ( OConfItemListIterator serverIt( *serverList ); serverIt.current(); ++serverIt ) | ||
236 | { | ||
237 | OConfItem *server = serverIt.current(); | ||
238 | |||
239 | // Add only active servers | ||
240 | if ( server->active() ) | ||
241 | *sl << server->name(); | ||
242 | } | ||
243 | } | ||
244 | |||
245 | return sl; | ||
246 | } | ||
247 | |||
248 | QStringList *OPackageManager::destinations() | ||
249 | { | ||
250 | QStringList *dl = new QStringList(); | ||
251 | |||
252 | OConfItemList *destList = m_ipkg.destinations(); | ||
253 | if ( destList ) | ||
254 | { | ||
255 | for ( OConfItemListIterator destIt( *destList ); destIt.current(); ++destIt ) | ||
256 | { | ||
257 | OConfItem *destination = destIt.current(); | ||
258 | |||
259 | // Add only active destinations | ||
260 | if ( destination->active() ) | ||
261 | *dl << destination->name(); | ||
262 | } | ||
263 | } | ||
264 | |||
265 | return dl; | ||
266 | } | ||
267 | |||
268 | OConfItem *OPackageManager::findConfItem( OConfItem::Type type, const QString &name ) | ||
269 | { | ||
270 | OConfItem *confItem = 0x0; | ||
271 | OConfItemList *confList = m_ipkg.configItems(); | ||
272 | if ( confList ) | ||
273 | { | ||
274 | for ( OConfItemListIterator confIt( *confList ); confIt.current(); ++confIt ) | ||
275 | { | ||
276 | OConfItem *conf = confIt.current(); | ||
277 | |||
278 | // Add only active confinations | ||
279 | if ( conf->type() == type && conf->name() == name ) | ||
280 | { | ||
281 | confItem = conf; | ||
282 | break; | ||
283 | } | ||
284 | } | ||
285 | } | ||
286 | |||
287 | return confItem; | ||
288 | |||
289 | } | ||
290 | |||
291 | OPackage *OPackageManager::findPackage( const QString &name ) | ||
292 | { | ||
293 | return m_packages[ name ]; | ||
294 | } | ||
295 | |||
296 | int OPackageManager::compareVersions( const QString &version1, const QString &version2 ) | ||
297 | { | ||
298 | // TODO - do proper compare! | ||
299 | if ( version1 < version2 ) | ||
300 | return -1; | ||
301 | else if ( version1 > version2 ) | ||
302 | return 1; | ||
303 | |||
304 | return 0; | ||
305 | } | ||
306 | |||
307 | bool OPackageManager::configureDlg( bool installOptions ) | ||
308 | { | ||
309 | OIpkgConfigDlg dlg( &m_ipkg, installOptions, static_cast<QWidget *>(parent()) ); | ||
310 | return ( dlg.exec() == QDialog::Accepted ); | ||
311 | } | ||
312 | |||
313 | void OPackageManager::saveSettings() | ||
314 | { | ||
315 | m_ipkg.saveSettings(); | ||
316 | } | ||
317 | |||
318 | bool OPackageManager::executeCommand( OPackage::Command command, QStringList *packages, | ||
319 | const QString &destination, const QObject *receiver, | ||
320 | const char *slotOutput, const char *slotErrors, | ||
321 | const char *slotFinished, bool rawOutput ) | ||
322 | { | ||
323 | return m_ipkg.executeCommand( command, packages, destination, receiver, slotOutput, slotErrors, | ||
324 | slotFinished, rawOutput ); | ||
325 | } | ||
326 | |||
327 | void OPackageManager::abortCommand() | ||
328 | { | ||
329 | m_ipkg.abortCommand(); | ||
330 | } | ||