summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/packagemanager/ChangeLog3
-rw-r--r--noncore/settings/packagemanager/oipkg.cpp2
-rw-r--r--noncore/settings/packagemanager/opackagemanager.cpp101
-rw-r--r--noncore/settings/packagemanager/opackagemanager.h3
-rw-r--r--noncore/settings/packagemanager/opie-packagemanager.control2
-rw-r--r--noncore/settings/packagemanager/promptdlg.cpp2
6 files changed, 103 insertions, 10 deletions
diff --git a/noncore/settings/packagemanager/ChangeLog b/noncore/settings/packagemanager/ChangeLog
index 6ad724f..d53a2b3 100644
--- a/noncore/settings/packagemanager/ChangeLog
+++ b/noncore/settings/packagemanager/ChangeLog
@@ -1,25 +1,28 @@
12004-02-13 Dan Williams <drw@handhelds.org> 12004-02-13 Dan Williams <drw@handhelds.org>
2 2
3 * Released version 0.3.0
3 * Fix handling of filtering options in View menu 4 * Fix handling of filtering options in View menu
5 * Do proper version string comparison
6 * Fix string alignment code in PromptDlg to eliminate QT warning messages
4 7
52004-02-12 Dan Williams <drw@handhelds.org> 82004-02-12 Dan Williams <drw@handhelds.org>
6 9
7 * Package information dialog implemented 10 * Package information dialog implemented
8 * What's This app icon enabled 11 * What's This app icon enabled
9 * Changed all QDialog::exec() occurences to QPEApplication::execDialog() 12 * Changed all QDialog::exec() occurences to QPEApplication::execDialog()
10 13
112004-01-23 Dan Williams <drw@handhelds.org> 142004-01-23 Dan Williams <drw@handhelds.org>
12 15
13 * Added package download functionality 16 * Added package download functionality
14 * Have Opie update links after install/removal so that apps 17 * Have Opie update links after install/removal so that apps
15 will display properly in Launcher 18 will display properly in Launcher
16 19
172004-01-20 Dan Williams <drw@handhelds.org> 202004-01-20 Dan Williams <drw@handhelds.org>
18 21
19 * Released version 0.2.0 22 * Released version 0.2.0
20 * Converted to use libipkg in place of spawning ipkg process 23 * Converted to use libipkg in place of spawning ipkg process
21 24
222004-01-13 Dan Williams <drw@handhelds.org> 252004-01-13 Dan Williams <drw@handhelds.org>
23 26
24 * Released version 0.1.0 27 * Released version 0.1.0
25 * Initial check-in of new package management client to eventually replace AQPkg 28 * Initial check-in of new package management client to eventually replace AQPkg
diff --git a/noncore/settings/packagemanager/oipkg.cpp b/noncore/settings/packagemanager/oipkg.cpp
index eb07a61..086e91b 100644
--- a/noncore/settings/packagemanager/oipkg.cpp
+++ b/noncore/settings/packagemanager/oipkg.cpp
@@ -1,328 +1,326 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2003 Dan Williams <drw@handhelds.org> 4              Copyright (c) 2003 Dan Williams <drw@handhelds.org>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#include "oipkg.h" 32#include "oipkg.h"
33 33
34#include <stdio.h>
35#include <stdlib.h> 34#include <stdlib.h>
36#include <string.h> 35#include <string.h>
37 36
38#include <qdir.h> 37#include <qdir.h>
39#include <qfile.h> 38#include <qfile.h>
40#include <qmessagebox.h> 39#include <qmessagebox.h>
41#include <qtextstream.h> 40#include <qtextstream.h>
42 41
43const QString IPKG_CONF = "/etc/ipkg.conf"; // Fully-qualified name of Ipkg primary configuration file 42const QString IPKG_CONF = "/etc/ipkg.conf"; // Fully-qualified name of Ipkg primary configuration file
44const QString IPKG_CONF_DIR = "/etc/ipkg"; // Directory of secondary Ipkg configuration files 43const QString IPKG_CONF_DIR = "/etc/ipkg"; // Directory of secondary Ipkg configuration files
45const QString IPKG_PKG_PATH = "/usr/lib/ipkg/lists"; // Directory containing server package lists 44const QString IPKG_PKG_PATH = "/usr/lib/ipkg/lists"; // Directory containing server package lists
46const QString IPKG_STATUS_PATH = "usr/lib/ipkg/status"; // Destination status file location 45const QString IPKG_STATUS_PATH = "usr/lib/ipkg/status"; // Destination status file location
47 46
48OIpkg *oipkg; 47OIpkg *oipkg;
49 48
50// Ipkg callback functions 49// Ipkg callback functions
51 50
52int fsignalIpkgMessage( ipkg_conf_t */*conf*/, message_level_t /*level*/, char *msg ) 51int fsignalIpkgMessage( ipkg_conf_t */*conf*/, message_level_t /*level*/, char *msg )
53{ 52{
54 oipkg->ipkgMessage( msg ); 53 oipkg->ipkgMessage( msg );
55 return 0; 54 return 0;
56} 55}
57 56
58char *fIpkgResponse( char */*question*/ ) 57char *fIpkgResponse( char */*question*/ )
59{ 58{
60 return 0x0; 59 return 0x0;
61} 60}
62 61
63int fIpkgStatus( char */*name*/, int /*status*/, char *desc, void */*userdata*/ ) 62int fIpkgStatus( char */*name*/, int /*status*/, char *desc, void */*userdata*/ )
64{ 63{
65 oipkg->ipkgStatus( desc ); 64 oipkg->ipkgStatus( desc );
66 return 0; 65 return 0;
67} 66}
68 67
69int fIpkgFiles( char */*name*/, char *desc, char */*version*/, pkg_state_status_t /*status*/, 68int fIpkgFiles( char */*name*/, char *desc, char */*version*/, pkg_state_status_t /*status*/,
70 void */*userdata*/ ) 69 void */*userdata*/ )
71{ 70{
72printf( "*****List*****\n%s\n", desc );
73 oipkg->ipkgList( desc ); 71 oipkg->ipkgList( desc );
74 return 0; 72 return 0;
75} 73}
76 74
77OIpkg::OIpkg( Config *config, QObject *parent, const char *name ) 75OIpkg::OIpkg( Config *config, QObject *parent, const char *name )
78 : QObject( parent, name ) 76 : QObject( parent, name )
79 , m_config( config ) 77 , m_config( config )
80 , m_confInfo( NULL ) 78 , m_confInfo( NULL )
81 , m_ipkgExecOptions( 0 ) 79 , m_ipkgExecOptions( 0 )
82 , m_ipkgExecVerbosity( 1 ) 80 , m_ipkgExecVerbosity( 1 )
83{ 81{
84 oipkg = this; 82 oipkg = this;
85 83
86 // Initialize libipkg 84 // Initialize libipkg
87 if ( ipkg_init( &fsignalIpkgMessage, &fIpkgResponse, &m_ipkgArgs ) ) 85 if ( ipkg_init( &fsignalIpkgMessage, &fIpkgResponse, &m_ipkgArgs ) )
88 QMessageBox::critical( 0, tr( "OIpkg" ), tr( "Error initialing libipkg" ) ); 86 QMessageBox::critical( 0, tr( "OIpkg" ), tr( "Error initialing libipkg" ) );
89 87
90 // Default ipkg run-time arguments 88 // Default ipkg run-time arguments
91 m_ipkgArgs.noaction = false; 89 m_ipkgArgs.noaction = false;
92 m_ipkgArgs.force_defaults = true; 90 m_ipkgArgs.force_defaults = true;
93} 91}
94 92
95OIpkg::~OIpkg() 93OIpkg::~OIpkg()
96{ 94{
97 // Upon destruction, ensure that items in config list are deleted with list 95 // Upon destruction, ensure that items in config list are deleted with list
98 if ( m_confInfo ) 96 if ( m_confInfo )
99 m_confInfo->setAutoDelete( true ); 97 m_confInfo->setAutoDelete( true );
100 98
101 // Free up libipkg resources 99 // Free up libipkg resources
102 if ( ipkg_deinit( &m_ipkgArgs ) ) 100 if ( ipkg_deinit( &m_ipkgArgs ) )
103 QMessageBox::critical( 0, tr( "OIpkg" ), tr( "Error freeing libipkg" ) ); 101 QMessageBox::critical( 0, tr( "OIpkg" ), tr( "Error freeing libipkg" ) );
104} 102}
105 103
106OConfItemList *OIpkg::configItems() 104OConfItemList *OIpkg::configItems()
107{ 105{
108 // Retrieve all configuration items 106 // Retrieve all configuration items
109 return filterConfItems(); 107 return filterConfItems();
110} 108}
111 109
112OConfItemList *OIpkg::servers() 110OConfItemList *OIpkg::servers()
113{ 111{
114 // Retrieve only servers 112 // Retrieve only servers
115 return filterConfItems( OConfItem::Source ); 113 return filterConfItems( OConfItem::Source );
116} 114}
117 115
118OConfItemList *OIpkg::destinations() 116OConfItemList *OIpkg::destinations()
119{ 117{
120 // Retrieve only destinations 118 // Retrieve only destinations
121 return filterConfItems( OConfItem::Destination ); 119 return filterConfItems( OConfItem::Destination );
122} 120}
123 121
124OConfItemList *OIpkg::options() 122OConfItemList *OIpkg::options()
125{ 123{
126 // Retrieve only destinations 124 // Retrieve only destinations
127 return filterConfItems( OConfItem::Option ); 125 return filterConfItems( OConfItem::Option );
128} 126}
129 127
130void OIpkg::setConfigItems( OConfItemList *configList ) 128void OIpkg::setConfigItems( OConfItemList *configList )
131{ 129{
132 if ( m_confInfo ) 130 if ( m_confInfo )
133 delete m_confInfo; 131 delete m_confInfo;
134 132
135 m_confInfo = configList; 133 m_confInfo = configList;
136} 134}
137 135
138void OIpkg::saveSettings() 136void OIpkg::saveSettings()
139{ 137{
140 // Save Ipkg execution options to application configuration file 138 // Save Ipkg execution options to application configuration file
141 if ( m_config ) 139 if ( m_config )
142 { 140 {
143 m_config->setGroup( "Ipkg" ); 141 m_config->setGroup( "Ipkg" );
144 m_config->writeEntry( "ExecOptions", m_ipkgExecOptions ); 142 m_config->writeEntry( "ExecOptions", m_ipkgExecOptions );
145 m_config->writeEntry( "Verbosity", m_ipkgExecVerbosity ); 143 m_config->writeEntry( "Verbosity", m_ipkgExecVerbosity );
146 } 144 }
147} 145}
148 146
149OPackageList *OIpkg::availablePackages( const QString &server ) 147OPackageList *OIpkg::availablePackages( const QString &server )
150{ 148{
151 // Load Ipkg configuration info if not already cached 149 // Load Ipkg configuration info if not already cached
152 if ( !m_confInfo ) 150 if ( !m_confInfo )
153 loadConfiguration(); 151 loadConfiguration();
154 152
155 // Build new server list (caller is responsible for deleting) 153 // Build new server list (caller is responsible for deleting)
156 OPackageList *pl = new OPackageList; 154 OPackageList *pl = new OPackageList;
157 155
158 // Open package list file 156 // Open package list file
159 QFile f( IPKG_PKG_PATH + "/" + server ); 157 QFile f( IPKG_PKG_PATH + "/" + server );
160 if ( !f.open( IO_ReadOnly ) ) 158 if ( !f.open( IO_ReadOnly ) )
161 return NULL; 159 return NULL;
162 QTextStream t( &f ); 160 QTextStream t( &f );
163 161
164 // Process all information in package list file 162 // Process all information in package list file
165 OPackage *package = NULL; 163 OPackage *package = NULL;
166 QString line = t.readLine(); 164 QString line = t.readLine();
167 while ( !t.eof() ) 165 while ( !t.eof() )
168 { 166 {
169 // Determine key/value pair 167 // Determine key/value pair
170 int pos = line.find( ':', 0 ); 168 int pos = line.find( ':', 0 );
171 QString key; 169 QString key;
172 if ( pos > -1 ) 170 if ( pos > -1 )
173 key = line.mid( 0, pos ); 171 key = line.mid( 0, pos );
174 else 172 else
175 key = QString::null; 173 key = QString::null;
176 QString value = line.mid( pos+2, line.length()-pos ); 174 QString value = line.mid( pos+2, line.length()-pos );
177 175
178 // Allocate new package and insert into list 176 // Allocate new package and insert into list
179 if ( package == NULL && !key.isEmpty() ) 177 if ( package == NULL && !key.isEmpty() )
180 { 178 {
181 package = new OPackage( value ); 179 package = new OPackage( value );
182 package->setSource( server ); 180 package->setSource( server );
183 pl->append( package ); 181 pl->append( package );
184 } 182 }
185 183
186 // Update package data 184 // Update package data
187 if ( key == "Package" ) 185 if ( key == "Package" )
188 package->setName( value ); 186 package->setName( value );
189 else if ( key == "Version" ) 187 else if ( key == "Version" )
190 package->setVersion( value ); 188 package->setVersion( value );
191 else if ( key == "Section" ) 189 else if ( key == "Section" )
192 package->setCategory( value ); 190 package->setCategory( value );
193 //DataManager::setAvailableCategories( value ); 191 //DataManager::setAvailableCategories( value );
194 else if ( key.isEmpty() && value.isEmpty() ) 192 else if ( key.isEmpty() && value.isEmpty() )
195 package = NULL; 193 package = NULL;
196 194
197 // Skip past all description lines 195 // Skip past all description lines
198 if ( key == "Description" ) 196 if ( key == "Description" )
199 { 197 {
200 line = t.readLine(); 198 line = t.readLine();
201 while ( !line.isEmpty() && line.find( ':', 0 ) == -1 && !t.eof() ) 199 while ( !line.isEmpty() && line.find( ':', 0 ) == -1 && !t.eof() )
202 line = t.readLine(); 200 line = t.readLine();
203 } 201 }
204 else 202 else
205 line = t.readLine(); 203 line = t.readLine();
206 } 204 }
207 205
208 f.close(); 206 f.close();
209 207
210 return pl; 208 return pl;
211} 209}
212 210
213OPackageList *OIpkg::installedPackages( const QString &destName, const QString &destPath ) 211OPackageList *OIpkg::installedPackages( const QString &destName, const QString &destPath )
214{ 212{
215 // Load Ipkg configuration info if not already cached 213 // Load Ipkg configuration info if not already cached
216 if ( !m_confInfo ) 214 if ( !m_confInfo )
217 loadConfiguration(); 215 loadConfiguration();
218 216
219 // Build new server list (caller is responsible for deleting) 217 // Build new server list (caller is responsible for deleting)
220 OPackageList *pl = new OPackageList; 218 OPackageList *pl = new OPackageList;
221 219
222 // Open status file 220 // Open status file
223 QString path = destPath; 221 QString path = destPath;
224 if ( path.right( 1 ) != "/" ) 222 if ( path.right( 1 ) != "/" )
225 path.append( "/" ); 223 path.append( "/" );
226 path.append( IPKG_STATUS_PATH ); 224 path.append( IPKG_STATUS_PATH );
227 225
228 QFile f( path ); 226 QFile f( path );
229 if ( !f.open( IO_ReadOnly ) ) 227 if ( !f.open( IO_ReadOnly ) )
230 return NULL; 228 return NULL;
231 QTextStream t( &f ); 229 QTextStream t( &f );
232 230
233 // Process all information in status file 231 // Process all information in status file
234 bool newPackage = false; 232 bool newPackage = false;
235 QString line = t.readLine(); 233 QString line = t.readLine();
236 QString name; 234 QString name;
237 QString version; 235 QString version;
238 QString status; 236 QString status;
239 237
240 while ( !t.eof() ) 238 while ( !t.eof() )
241 { 239 {
242 // Determine key/value pair 240 // Determine key/value pair
243 int pos = line.find( ':', 0 ); 241 int pos = line.find( ':', 0 );
244 QString key; 242 QString key;
245 if ( pos > -1 ) 243 if ( pos > -1 )
246 key = line.mid( 0, pos ); 244 key = line.mid( 0, pos );
247 else 245 else
248 key = QString::null; 246 key = QString::null;
249 QString value = line.mid( pos+2, line.length()-pos ); 247 QString value = line.mid( pos+2, line.length()-pos );
250 248
251 // Allocate new package and insert into list 249 // Allocate new package and insert into list
252 if ( newPackage && !key.isEmpty() ) 250 if ( newPackage && !key.isEmpty() )
253 { 251 {
254 // Add to list only if it has a valid name and is installed 252 // Add to list only if it has a valid name and is installed
255 if ( !name.isNull() && status.contains( " installed" ) ) 253 if ( !name.isNull() && status.contains( " installed" ) )
256 { 254 {
257 pl->append( new OPackage( name, QString::null, version, QString::null, destName ) ); 255 pl->append( new OPackage( name, QString::null, version, QString::null, destName ) );
258 name = QString::null; 256 name = QString::null;
259 version = QString::null; 257 version = QString::null;
260 status = QString::null; 258 status = QString::null;
261 259
262 newPackage = false; 260 newPackage = false;
263 } 261 }
264 } 262 }
265 263
266 // Update package data 264 // Update package data
267 if ( key == "Package" ) 265 if ( key == "Package" )
268 name = value; 266 name = value;
269 else if ( key == "Version" ) 267 else if ( key == "Version" )
270 version = value; 268 version = value;
271 else if ( key == "Status" ) 269 else if ( key == "Status" )
272 status = value; 270 status = value;
273 else if ( key.isEmpty() && value.isEmpty() ) 271 else if ( key.isEmpty() && value.isEmpty() )
274 newPackage = true; 272 newPackage = true;
275 273
276 // Skip past all description lines 274 // Skip past all description lines
277 if ( key == "Description" ) 275 if ( key == "Description" )
278 { 276 {
279 line = t.readLine(); 277 line = t.readLine();
280 while ( !line.isEmpty() && line.find( ':', 0 ) == -1 && !t.eof() ) 278 while ( !line.isEmpty() && line.find( ':', 0 ) == -1 && !t.eof() )
281 line = t.readLine(); 279 line = t.readLine();
282 } 280 }
283 else 281 else
284 line = t.readLine(); 282 line = t.readLine();
285 } 283 }
286 284
287 f.close(); 285 f.close();
288 286
289 return pl; 287 return pl;
290} 288}
291 289
292bool OIpkg::executeCommand( OPackage::Command command, QStringList *parameters, const QString &destination, 290bool OIpkg::executeCommand( OPackage::Command command, QStringList *parameters, const QString &destination,
293 const QObject *receiver, const char *slotOutput, bool rawOutput ) 291 const QObject *receiver, const char *slotOutput, bool rawOutput )
294{ 292{
295 if ( command == OPackage::NotDefined ) 293 if ( command == OPackage::NotDefined )
296 return false; 294 return false;
297 295
298 // Set ipkg run-time options/arguments 296 // Set ipkg run-time options/arguments
299 m_ipkgArgs.force_depends = ( m_ipkgExecOptions & FORCE_DEPENDS ); 297 m_ipkgArgs.force_depends = ( m_ipkgExecOptions & FORCE_DEPENDS );
300 m_ipkgArgs.force_reinstall = ( m_ipkgExecOptions & FORCE_REINSTALL ); 298 m_ipkgArgs.force_reinstall = ( m_ipkgExecOptions & FORCE_REINSTALL );
301 // TODO m_ipkgArgs.force_remove = ( m_ipkgExecOptions & FORCE_REMOVE ); 299 // TODO m_ipkgArgs.force_remove = ( m_ipkgExecOptions & FORCE_REMOVE );
302 m_ipkgArgs.force_overwrite = ( m_ipkgExecOptions & FORCE_OVERWRITE ); 300 m_ipkgArgs.force_overwrite = ( m_ipkgExecOptions & FORCE_OVERWRITE );
303 m_ipkgArgs.verbosity = m_ipkgExecVerbosity; 301 m_ipkgArgs.verbosity = m_ipkgExecVerbosity;
304 if ( m_ipkgArgs.dest ) 302 if ( m_ipkgArgs.dest )
305 free( m_ipkgArgs.dest ); 303 free( m_ipkgArgs.dest );
306 if ( !destination.isNull() ) 304 if ( !destination.isNull() )
307 { 305 {
308 int len = destination.length() + 1; 306 int len = destination.length() + 1;
309 m_ipkgArgs.dest = (char *)malloc( len ); 307 m_ipkgArgs.dest = (char *)malloc( len );
310 strncpy( m_ipkgArgs.dest, destination, destination.length() ); 308 strncpy( m_ipkgArgs.dest, destination, destination.length() );
311 m_ipkgArgs.dest[ len - 1 ] = '\0'; 309 m_ipkgArgs.dest[ len - 1 ] = '\0';
312 } 310 }
313 else 311 else
314 m_ipkgArgs.dest = 0x0; 312 m_ipkgArgs.dest = 0x0;
315 313
316 // Connect output signal to widget 314 // Connect output signal to widget
317 315
318 if ( rawOutput ) 316 if ( rawOutput )
319 { 317 {
320// if ( slotOutput ) 318// if ( slotOutput )
321// connect( this, SIGNAL(signalIpkgMessage(char *)), receiver, slotOutput ); 319// connect( this, SIGNAL(signalIpkgMessage(char *)), receiver, slotOutput );
322 } 320 }
323 else 321 else
324 { 322 {
325 // TODO - connect to local slot and parse output before emitting signalIpkgMessage 323 // TODO - connect to local slot and parse output before emitting signalIpkgMessage
326 } 324 }
327 325
328 switch( command ) 326 switch( command )
diff --git a/noncore/settings/packagemanager/opackagemanager.cpp b/noncore/settings/packagemanager/opackagemanager.cpp
index ad2fe02..3633e05 100644
--- a/noncore/settings/packagemanager/opackagemanager.cpp
+++ b/noncore/settings/packagemanager/opackagemanager.cpp
@@ -1,323 +1,412 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2003 Dan Williams <drw@handhelds.org> 4              Copyright (c) 2003 Dan Williams <drw@handhelds.org>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#include <ctype.h>
33
32#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
33 35
34#include "opackagemanager.h" 36#include "opackagemanager.h"
35#include "oipkgconfigdlg.h" 37#include "oipkgconfigdlg.h"
36 38
37OPackageManager::OPackageManager( Config *config, QObject *parent, const char *name ) 39OPackageManager::OPackageManager( Config *config, QObject *parent, const char *name )
38 : QObject( parent, name ) 40 : QObject( parent, name )
39 , m_config( config ) 41 , m_config( config )
40 , m_ipkg( m_config, this ) 42 , m_ipkg( m_config, this )
41 , m_packages( 9973 ) 43 , m_packages( 9973 )
42 , m_categories() 44 , m_categories()
43{ 45{
44 m_packages.setAutoDelete( true ); 46 m_packages.setAutoDelete( true );
45} 47}
46 48
47void OPackageManager::loadAvailablePackages() 49void OPackageManager::loadAvailablePackages()
48{ 50{
49 m_packages.clear(); 51 m_packages.clear();
50 52
51 OConfItemList *serverList = m_ipkg.servers(); 53 OConfItemList *serverList = m_ipkg.servers();
52 54
53 if ( serverList ) 55 if ( serverList )
54 { 56 {
55 // Initialize status messaging 57 // Initialize status messaging
56 emit initStatus( serverList->count() ); 58 emit initStatus( serverList->count() );
57 int serverCount = 0; 59 int serverCount = 0;
58 60
59 bool categoryAdded = false; 61 bool categoryAdded = false;
60 62
61 for ( OConfItemListIterator serverIt( *serverList ); serverIt.current(); ++serverIt ) 63 for ( OConfItemListIterator serverIt( *serverList ); serverIt.current(); ++serverIt )
62 { 64 {
63 OConfItem *server = serverIt.current(); 65 OConfItem *server = serverIt.current();
64 66
65 // Process server only if it is active 67 // Process server only if it is active
66 if ( server->active() ) 68 if ( server->active() )
67 { 69 {
68 // Update status 70 // Update status
69 QString status = tr( "Reading available packages:\n\t" ); 71 QString status = tr( "Reading available packages:\n\t" );
70 status.append( server->name() ); 72 status.append( server->name() );
71 emit statusText( status ); 73 emit statusText( status );
72 ++serverCount; 74 ++serverCount;
73 emit statusBar( serverCount ); 75 emit statusBar( serverCount );
74 qApp->processEvents(); 76 qApp->processEvents();
75 77
76 OPackageList *packageList = m_ipkg.availablePackages( server->name() ); 78 OPackageList *packageList = m_ipkg.availablePackages( server->name() );
77 if ( packageList ) 79 if ( packageList )
78 { 80 {
79 for ( OPackageListIterator packageIt( *packageList ); packageIt.current(); ++packageIt ) 81 for ( OPackageListIterator packageIt( *packageList ); packageIt.current(); ++packageIt )
80 { 82 {
81 OPackage *package = packageIt.current(); 83 OPackage *package = packageIt.current();
82 84
83 // Load package info 85 // Load package info
84 if ( !m_packages.find( package->name() ) ) 86 if ( !m_packages.find( package->name() ) )
85 m_packages.insert( package->name(), package ); 87 m_packages.insert( package->name(), package );
86 else 88 else
87 { 89 {
88 // If new package is newer version, replace existing package 90 // If new package is newer version, replace existing package
89 OPackage *currPackage = m_packages[package->name()]; 91 OPackage *currPackage = m_packages[package->name()];
90 if ( compareVersions( package->version(), currPackage->version() ) == 1 ) 92 if ( compareVersions( package->version(), currPackage->version() ) == 1 )
91 m_packages.replace( package->name(), package ); 93 m_packages.replace( package->name(), package );
92 } 94 }
93 95
94 // Add category to list if it doesn't already exist 96 // Add category to list if it doesn't already exist
95 if ( m_categories.grep( package->category() ).isEmpty() ) 97 if ( m_categories.grep( package->category() ).isEmpty() )
96 { 98 {
97 m_categories << package->category(); 99 m_categories << package->category();
98 categoryAdded = true; 100 categoryAdded = true;
99 } 101 }
100 } 102 }
101 } 103 }
102 } 104 }
103 } 105 }
104 delete serverList; 106 delete serverList;
105 107
106 // Sort category list if categories were added 108 // Sort category list if categories were added
107 if ( categoryAdded ) 109 if ( categoryAdded )
108 m_categories.sort(); 110 m_categories.sort();
109 } 111 }
110} 112}
111 113
112void OPackageManager::loadInstalledPackages() 114void OPackageManager::loadInstalledPackages()
113{ 115{
114 OConfItemList *destList = m_ipkg.destinations(); 116 OConfItemList *destList = m_ipkg.destinations();
115 117
116 if ( destList ) 118 if ( destList )
117 { 119 {
118 // Initialize status messaging 120 // Initialize status messaging
119 emit initStatus( destList->count() ); 121 emit initStatus( destList->count() );
120 int destCount = 0; 122 int destCount = 0;
121 123
122 bool categoryAdded = false; 124 bool categoryAdded = false;
123 125
124 for ( OConfItemListIterator destIt( *destList ); destIt.current(); ++destIt ) 126 for ( OConfItemListIterator destIt( *destList ); destIt.current(); ++destIt )
125 { 127 {
126 OConfItem *destination = destIt.current(); 128 OConfItem *destination = destIt.current();
127 129
128 // Process destination only if it is active 130 // Process destination only if it is active
129 if ( destination->active() ) 131 if ( destination->active() )
130 { 132 {
131 // Update status 133 // Update status
132 QString status = tr( "Reading installed packages:\n\t" ); 134 QString status = tr( "Reading installed packages:\n\t" );
133 status.append( destination->name() ); 135 status.append( destination->name() );
134 emit statusText( status ); 136 emit statusText( status );
135 ++destCount; 137 ++destCount;
136 emit statusBar( destCount ); 138 emit statusBar( destCount );
137 qApp->processEvents(); 139 qApp->processEvents();
138 140
139 OPackageList *packageList = m_ipkg.installedPackages( destination->name(), 141 OPackageList *packageList = m_ipkg.installedPackages( destination->name(),
140 destination->value() ); 142 destination->value() );
141 if ( packageList ) 143 if ( packageList )
142 { 144 {
143 for ( OPackageListIterator packageIt( *packageList ); packageIt.current(); ++packageIt ) 145 for ( OPackageListIterator packageIt( *packageList ); packageIt.current(); ++packageIt )
144 { 146 {
145 OPackage *package = packageIt.current(); 147 OPackage *package = packageIt.current();
146 OPackage *currPackage = m_packages[package->name()]; 148 OPackage *currPackage = m_packages[package->name()];
147 if ( currPackage ) 149 if ( currPackage )
148 { 150 {
149 // Package is in a current feed, update installed version, destination 151 // Package is in a current feed, update installed version, destination
150 currPackage->setVersionInstalled( package->versionInstalled() ); 152 currPackage->setVersionInstalled( package->versionInstalled() );
151 currPackage->setDestination( package->destination() ); 153 currPackage->setDestination( package->destination() );
152 154
153 delete package; 155 delete package;
154 } 156 }
155 else 157 else
156 { 158 {
157 // Package isn't in a current feed, add to list 159 // Package isn't in a current feed, add to list
158 m_packages.insert( package->name(), package ); 160 m_packages.insert( package->name(), package );
159 161
160 // Add category to list if it doesn't already exist 162 // Add category to list if it doesn't already exist
161 if ( m_categories.grep( package->category() ).isEmpty() ) 163 if ( m_categories.grep( package->category() ).isEmpty() )
162 { 164 {
163 m_categories << package->category(); 165 m_categories << package->category();
164 categoryAdded = true; 166 categoryAdded = true;
165 } 167 }
166 } 168 }
167 } 169 }
168 } 170 }
169 } 171 }
170 } 172 }
171 delete destList; 173 delete destList;
172 174
173 // Sort category list if categories were added 175 // Sort category list if categories were added
174 if ( categoryAdded ) 176 if ( categoryAdded )
175 m_categories.sort(); 177 m_categories.sort();
176 } 178 }
177} 179}
178 180
179OPackageList *OPackageManager::packages() 181OPackageList *OPackageManager::packages()
180{ 182{
181 // TODO - look to see if list is loaded, if not, load available & installed 183 // TODO - look to see if list is loaded, if not, load available & installed
182 184
183 OPackageList *pl = new OPackageList; 185 OPackageList *pl = new OPackageList;
184 186
185 for ( QDictIterator<OPackage> packageIt( m_packages ); packageIt.current(); ++packageIt ) 187 for ( QDictIterator<OPackage> packageIt( m_packages ); packageIt.current(); ++packageIt )
186 pl->append( packageIt.current() ); 188 pl->append( packageIt.current() );
187 189
188 return pl; 190 return pl;
189} 191}
190 192
191OPackageList *OPackageManager::filterPackages( const QString &name,const QString &server, 193OPackageList *OPackageManager::filterPackages( const QString &name,const QString &server,
192 const QString &destination, Status status, const QString &category ) 194 const QString &destination, Status status, const QString &category )
193{ 195{
194 // TODO - look to see if list is loaded, if not, load available & installed 196 // TODO - look to see if list is loaded, if not, load available & installed
195 197
196 OPackageList *pl = new OPackageList; 198 OPackageList *pl = new OPackageList;
197 for ( QDictIterator<OPackage> packageIt( m_packages ); packageIt.current(); ++packageIt ) 199 for ( QDictIterator<OPackage> packageIt( m_packages ); packageIt.current(); ++packageIt )
198 { 200 {
199 OPackage *package = packageIt.current(); 201 OPackage *package = packageIt.current();
200 202
201 bool nameMatch = ( name.isNull() || package->name().contains( name ) ); 203 bool nameMatch = ( name.isNull() || package->name().contains( name ) );
202 bool serverMatch = ( server.isNull() || package->source() == server ); 204 bool serverMatch = ( server.isNull() || package->source() == server );
203 bool destinationMatch = ( destination.isNull() || package->destination() == destination ); 205 bool destinationMatch = ( destination.isNull() || package->destination() == destination );
204 bool statusMatch; 206 bool statusMatch;
205 switch ( status ) 207 switch ( status )
206 { 208 {
207 case All : statusMatch = true; 209 case All : statusMatch = true;
208 break; 210 break;
209 case NotInstalled : statusMatch = package->versionInstalled().isNull(); 211 case NotInstalled : statusMatch = package->versionInstalled().isNull();
210 break; 212 break;
211 case Installed : statusMatch = !package->versionInstalled().isNull(); 213 case Installed : statusMatch = !package->versionInstalled().isNull();
212 break; 214 break;
213 case Updated : statusMatch = ( !package->versionInstalled().isNull() && 215 case Updated : statusMatch = ( !package->versionInstalled().isNull() &&
214 compareVersions( package->version(), package->versionInstalled() ) == 1 ); 216 compareVersions( package->version(), package->versionInstalled() ) == 1 );
215 break; 217 break;
216 default : statusMatch = true; 218 default : statusMatch = true;
217 break; 219 break;
218 }; 220 };
219 bool categoryMatch = ( category.isNull() || package->category() == category ); 221 bool categoryMatch = ( category.isNull() || package->category() == category );
220 222
221 if ( nameMatch && serverMatch && destinationMatch && statusMatch && categoryMatch ) 223 if ( nameMatch && serverMatch && destinationMatch && statusMatch && categoryMatch )
222 pl->append( packageIt.current() ); 224 pl->append( packageIt.current() );
223 } 225 }
224 226
225 return pl; 227 return pl;
226} 228}
227 229
228QStringList *OPackageManager::servers() 230QStringList *OPackageManager::servers()
229{ 231{
230 QStringList *sl = new QStringList(); 232 QStringList *sl = new QStringList();
231 233
232 OConfItemList *serverList = m_ipkg.servers(); 234 OConfItemList *serverList = m_ipkg.servers();
233 if ( serverList ) 235 if ( serverList )
234 { 236 {
235 for ( OConfItemListIterator serverIt( *serverList ); serverIt.current(); ++serverIt ) 237 for ( OConfItemListIterator serverIt( *serverList ); serverIt.current(); ++serverIt )
236 { 238 {
237 OConfItem *server = serverIt.current(); 239 OConfItem *server = serverIt.current();
238 240
239 // Add only active servers 241 // Add only active servers
240 if ( server->active() ) 242 if ( server->active() )
241 *sl << server->name(); 243 *sl << server->name();
242 } 244 }
243 } 245 }
244 246
245 return sl; 247 return sl;
246} 248}
247 249
248QStringList *OPackageManager::destinations() 250QStringList *OPackageManager::destinations()
249{ 251{
250 QStringList *dl = new QStringList(); 252 QStringList *dl = new QStringList();
251 253
252 OConfItemList *destList = m_ipkg.destinations(); 254 OConfItemList *destList = m_ipkg.destinations();
253 if ( destList ) 255 if ( destList )
254 { 256 {
255 for ( OConfItemListIterator destIt( *destList ); destIt.current(); ++destIt ) 257 for ( OConfItemListIterator destIt( *destList ); destIt.current(); ++destIt )
256 { 258 {
257 OConfItem *destination = destIt.current(); 259 OConfItem *destination = destIt.current();
258 260
259 // Add only active destinations 261 // Add only active destinations
260 if ( destination->active() ) 262 if ( destination->active() )
261 *dl << destination->name(); 263 *dl << destination->name();
262 } 264 }
263 } 265 }
264 266
265 return dl; 267 return dl;
266} 268}
267 269
268OConfItem *OPackageManager::findConfItem( OConfItem::Type type, const QString &name ) 270OConfItem *OPackageManager::findConfItem( OConfItem::Type type, const QString &name )
269{ 271{
270 OConfItem *confItem = 0x0; 272 OConfItem *confItem = 0x0;
271 OConfItemList *confList = m_ipkg.configItems(); 273 OConfItemList *confList = m_ipkg.configItems();
272 if ( confList ) 274 if ( confList )
273 { 275 {
274 for ( OConfItemListIterator confIt( *confList ); confIt.current(); ++confIt ) 276 for ( OConfItemListIterator confIt( *confList ); confIt.current(); ++confIt )
275 { 277 {
276 OConfItem *conf = confIt.current(); 278 OConfItem *conf = confIt.current();
277 279
278 // Add only active confinations 280 // Add only active confinations
279 if ( conf->type() == type && conf->name() == name ) 281 if ( conf->type() == type && conf->name() == name )
280 { 282 {
281 confItem = conf; 283 confItem = conf;
282 break; 284 break;
283 } 285 }
284 } 286 }
285 } 287 }
286 288
287 return confItem; 289 return confItem;
288 290
289} 291}
290 292
291OPackage *OPackageManager::findPackage( const QString &name ) 293OPackage *OPackageManager::findPackage( const QString &name )
292{ 294{
293 return m_packages[ name ]; 295 return m_packages[ name ];
294} 296}
295 297
296int OPackageManager::compareVersions( const QString &version1, const QString &version2 ) 298int OPackageManager::compareVersions( const QString &ver1, const QString &ver2 )
297{ 299{
298 // TODO - do proper compare! 300 // TODO - should this be in OIpkg???
299 if ( version1 < version2 ) 301
300 return -1; 302 int epoch1, epoch2;
301 else if ( version1 > version2 ) 303 QString version1, revision1;
304 QString version2, revision2;
305
306 parseVersion( ver1, &epoch1, &version1, &revision1 );
307 parseVersion( ver2, &epoch2, &version2, &revision2 );
308
309 if ( epoch1 > epoch2 )
302 return 1; 310 return 1;
311 else if ( epoch1 < epoch2 )
312 return -1;
303 313
304 return 0; 314 int r = verrevcmp( version1.latin1(), version2.latin1() );
315 if (r)
316 return r;
317
318 r = verrevcmp( revision1.latin1(), revision2.latin1() );
319 return r;
305} 320}
306 321
307bool OPackageManager::configureDlg( bool installOptions ) 322bool OPackageManager::configureDlg( bool installOptions )
308{ 323{
309 OIpkgConfigDlg dlg( &m_ipkg, installOptions, static_cast<QWidget *>(parent()) ); 324 OIpkgConfigDlg dlg( &m_ipkg, installOptions, static_cast<QWidget *>(parent()) );
310 return ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ); 325 return ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted );
311} 326}
312 327
313void OPackageManager::saveSettings() 328void OPackageManager::saveSettings()
314{ 329{
315 m_ipkg.saveSettings(); 330 m_ipkg.saveSettings();
316} 331}
317 332
318bool OPackageManager::executeCommand( OPackage::Command command, QStringList *packages, 333bool OPackageManager::executeCommand( OPackage::Command command, QStringList *packages,
319 const QString &destination, const QObject *receiver, 334 const QString &destination, const QObject *receiver,
320 const char *slotOutput, bool rawOutput ) 335 const char *slotOutput, bool rawOutput )
321{ 336{
322 return m_ipkg.executeCommand( command, packages, destination, receiver, slotOutput, rawOutput ); 337 return m_ipkg.executeCommand( command, packages, destination, receiver, slotOutput, rawOutput );
323} 338}
339
340void OPackageManager::parseVersion( const QString &verstr, int *epoch, QString *version,
341 QString *revision )
342{
343 *epoch = 0;
344 *revision = QString::null;
345
346 // Version string is in the format "ee:vv-rv", where ee=epoch, vv=version, rv=revision
347
348 // Get epoch
349 int colonpos = verstr.find( ':' );
350 if ( colonpos > -1 )
351 {
352 *epoch = verstr.left( colonpos ).toInt();
353 }
354
355 // Get version and revision
356 int hyphenpos = verstr.find( '-', colonpos + 1 );
357 int verlen = verstr.length();
358 if ( hyphenpos > -1 )
359 {
360 *version = verstr.mid( colonpos + 1, hyphenpos - colonpos - 1 );
361 *revision = verstr.right( verlen - hyphenpos - 1 );
362 }
363 else
364 {
365 *version = verstr.right( verlen - colonpos );
366 }
367}
368
369/*
370 * libdpkg - Debian packaging suite library routines
371 * vercmp.c - comparison of version numbers
372 *
373 * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
374 */
375int OPackageManager::verrevcmp( const char *val, const char *ref )
376{
377 int vc, rc;
378 long vl, rl;
379 const char *vp, *rp;
380 const char *vsep, *rsep;
381
382 if (!val) val= "";
383 if (!ref) ref= "";
384 for (;;) {
385 vp= val; while (*vp && !isdigit(*vp)) vp++;
386 rp= ref; while (*rp && !isdigit(*rp)) rp++;
387 for (;;) {
388 vc= (val == vp) ? 0 : *val++;
389 rc= (ref == rp) ? 0 : *ref++;
390 if (!rc && !vc) break;
391 if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
392 if (rc && !isalpha(rc)) rc += 256;
393 if (vc != rc) return vc - rc;
394 }
395 val= vp;
396 ref= rp;
397 vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
398 rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
399 if (vl != rl) return vl - rl;
400
401 vc = *val;
402 rc = *ref;
403 vsep = strchr(".-", vc);
404 rsep = strchr(".-", rc);
405 if (vsep && !rsep) return -1;
406 if (!vsep && rsep) return +1;
407
408 if (!*val && !*ref) return 0;
409 if (!*val) return -1;
410 if (!*ref) return +1;
411 }
412}
diff --git a/noncore/settings/packagemanager/opackagemanager.h b/noncore/settings/packagemanager/opackagemanager.h
index 871af0c..b710a51 100644
--- a/noncore/settings/packagemanager/opackagemanager.h
+++ b/noncore/settings/packagemanager/opackagemanager.h
@@ -1,89 +1,92 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2003 Dan Williams <drw@handhelds.org> 4              Copyright (c) 2003 Dan Williams <drw@handhelds.org>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#ifndef OPACKAGEMANAGER_H 32#ifndef OPACKAGEMANAGER_H
33#define OPACKAGEMANAGER_H 33#define OPACKAGEMANAGER_H
34 34
35#include <qdict.h> 35#include <qdict.h>
36#include <qobject.h> 36#include <qobject.h>
37#include <qstringlist.h> 37#include <qstringlist.h>
38 38
39#include <qpe/config.h> 39#include <qpe/config.h>
40 40
41#include "oipkg.h" 41#include "oipkg.h"
42 42
43class OPackageManager : public QObject 43class OPackageManager : public QObject
44{ 44{
45 Q_OBJECT 45 Q_OBJECT
46 46
47public: 47public:
48 OPackageManager( Config *config = 0x0, QObject *parent = 0x0, const char *name = 0x0 ); 48 OPackageManager( Config *config = 0x0, QObject *parent = 0x0, const char *name = 0x0 );
49 49
50 void loadAvailablePackages(); 50 void loadAvailablePackages();
51 void loadInstalledPackages(); 51 void loadInstalledPackages();
52 52
53 enum Status { All, NotInstalled, Installed, Updated, NotDefined }; 53 enum Status { All, NotInstalled, Installed, Updated, NotDefined };
54 54
55 OPackageList *packages(); 55 OPackageList *packages();
56 OPackageList *filterPackages( const QString &name = 0x0,const QString &server = 0x0, 56 OPackageList *filterPackages( const QString &name = 0x0,const QString &server = 0x0,
57 const QString &destination = 0x0, Status status = NotDefined, 57 const QString &destination = 0x0, Status status = NotDefined,
58 const QString &category = 0x0 ); 58 const QString &category = 0x0 );
59 59
60 const QStringList &categories() { return m_categories; } 60 const QStringList &categories() { return m_categories; }
61 QStringList *servers(); 61 QStringList *servers();
62 QStringList *destinations(); 62 QStringList *destinations();
63 63
64 int compareVersions( const QString &version1, const QString &version2 ); 64 int compareVersions( const QString &version1, const QString &version2 );
65 65
66 OConfItem *findConfItem( OConfItem::Type type = OConfItem::NotDefined, 66 OConfItem *findConfItem( OConfItem::Type type = OConfItem::NotDefined,
67 const QString &name = QString::null ); 67 const QString &name = QString::null );
68 OPackage *findPackage( const QString &name = QString::null ); 68 OPackage *findPackage( const QString &name = QString::null );
69 69
70 bool configureDlg( bool installOptions = false ); 70 bool configureDlg( bool installOptions = false );
71 void saveSettings(); 71 void saveSettings();
72 72
73 bool executeCommand( OPackage::Command command = OPackage::NotDefined, QStringList *parameters = 0x0, 73 bool executeCommand( OPackage::Command command = OPackage::NotDefined, QStringList *parameters = 0x0,
74 const QString &destination = QString::null, const QObject *receiver = 0x0, 74 const QString &destination = QString::null, const QObject *receiver = 0x0,
75 const char *slotOutput = 0x0, bool rawOutput = true ); 75 const char *slotOutput = 0x0, bool rawOutput = true );
76 76
77private: 77private:
78 Config *m_config; // Pointer to application configuration file 78 Config *m_config; // Pointer to application configuration file
79 OIpkg m_ipkg; // OIpkg object to retrieve package/configuration information 79 OIpkg m_ipkg; // OIpkg object to retrieve package/configuration information
80 QDict<OPackage> m_packages; // Global list of available packages 80 QDict<OPackage> m_packages; // Global list of available packages
81 QStringList m_categories; // List of all categories 81 QStringList m_categories; // List of all categories
82 82
83 void parseVersion( const QString &verstr, int *epoch, QString *version, QString *revision );
84 int verrevcmp( const char *val, const char *ref );
85
83signals: 86signals:
84 void initStatus( int numSteps ); 87 void initStatus( int numSteps );
85 void statusText( const QString &status ); 88 void statusText( const QString &status );
86 void statusBar( int currStep ); 89 void statusBar( int currStep );
87}; 90};
88 91
89#endif 92#endif
diff --git a/noncore/settings/packagemanager/opie-packagemanager.control b/noncore/settings/packagemanager/opie-packagemanager.control
index 095e3be..5a3908e 100644
--- a/noncore/settings/packagemanager/opie-packagemanager.control
+++ b/noncore/settings/packagemanager/opie-packagemanager.control
@@ -1,10 +1,10 @@
1Package: opie-packagemanager 1Package: opie-packagemanager
2Files: plugins/application/libpackagemanager.so* bin/packagemanager pics/packagemanager apps/Settings/packagemanager.desktop 2Files: plugins/application/libpackagemanager.so* bin/packagemanager pics/packagemanager apps/Settings/packagemanager.desktop
3Priority: optional 3Priority: optional
4Section: Settings 4Section: Settings
5Depends: task-opie-minimal 5Depends: task-opie-minimal
6Replaces: packagemanager 6Replaces: packagemanager
7Architecture: arm 7Architecture: arm
8Maintainer: Dan Williams (drw@handhelds.org) 8Maintainer: Dan Williams (drw@handhelds.org)
9Description: Opie package management client 9Description: Opie package management client
10Version: 0.2.0 10Version: 0.3.0
diff --git a/noncore/settings/packagemanager/promptdlg.cpp b/noncore/settings/packagemanager/promptdlg.cpp
index 128e88e..4e82ba9 100644
--- a/noncore/settings/packagemanager/promptdlg.cpp
+++ b/noncore/settings/packagemanager/promptdlg.cpp
@@ -1,140 +1,140 @@
1/* 1/*
2                This file is part of the OPIE Project 2                This file is part of the OPIE Project
3 3
4 =. Copyright (c) 2003 Dan Williams <drw@handhelds.org> 4 =. Copyright (c) 2003 Dan Williams <drw@handhelds.org>
5             .=l. 5             .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This file is free software; you can 7 _;:,     .>    :=|. This file is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU General Public 9:`=1 )Y*s>-.--   : the terms of the GNU General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This file is distributed in the hope that 14    .i_,=:_.      -<s. This file is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
19..}^=.=       =       ; Public License for more details. 19..}^=.=       =       ; Public License for more details.
20++=   -.     .`     .: 20++=   -.     .`     .:
21 :     =  ...= . :.=- You should have received a copy of the GNU 21 :     =  ...= . :.=- You should have received a copy of the GNU
22 -.   .:....=;==+<; General Public License along with this file; 22 -.   .:....=;==+<; General Public License along with this file;
23  -_. . .   )=.  = see the file COPYING. If not, write to the 23  -_. . .   )=.  = see the file COPYING. If not, write to the
24    --        :-=` Free Software Foundation, Inc., 24    --        :-=` Free Software Foundation, Inc.,
25 59 Temple Place - Suite 330, 25 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27 27
28*/ 28*/
29 29
30#include "promptdlg.h" 30#include "promptdlg.h"
31 31
32#include <qlabel.h> 32#include <qlabel.h>
33#include <qlayout.h> 33#include <qlayout.h>
34#include <qpushbutton.h> 34#include <qpushbutton.h>
35#include <qwidgetlist.h> 35#include <qwidgetlist.h>
36 36
37#include <qpe/qpeapplication.h> 37#include <qpe/qpeapplication.h>
38 38
39PromptDlg::PromptDlg( const QString &caption, const QString &text, const QString &btn1, const QString &btn2, 39PromptDlg::PromptDlg( const QString &caption, const QString &text, const QString &btn1, const QString &btn2,
40 QWidget *parent ) 40 QWidget *parent )
41 : QWidget( parent, QString::null, WType_Modal | WType_TopLevel | WStyle_Dialog ) 41 : QWidget( parent, QString::null, WType_Modal | WType_TopLevel | WStyle_Dialog )
42 , m_btnClicked( -1 ) 42 , m_btnClicked( -1 )
43{ 43{
44 setCaption( caption ); 44 setCaption( caption );
45 45
46 QGridLayout *layout = new QGridLayout( this, 2, 2, 4, 2 ); 46 QGridLayout *layout = new QGridLayout( this, 2, 2, 4, 2 );
47 QLabel *label = new QLabel( text, this ); 47 QLabel *label = new QLabel( text, this );
48 label->setAlignment( AlignCenter | AlignTop | WordBreak ); 48 label->setAlignment( AlignCenter | WordBreak );
49 layout->addMultiCellWidget( label, 0, 0, 0, 1 ); 49 layout->addMultiCellWidget( label, 0, 0, 0, 1 );
50 50
51 QPushButton *btn = new QPushButton( btn1, this ); 51 QPushButton *btn = new QPushButton( btn1, this );
52 layout->addWidget( btn, 1, 0 ); 52 layout->addWidget( btn, 1, 0 );
53 connect( btn, SIGNAL(clicked()), this, SLOT(slotBtn1Clicked()) ); 53 connect( btn, SIGNAL(clicked()), this, SLOT(slotBtn1Clicked()) );
54 54
55 btn = new QPushButton( btn2, this ); 55 btn = new QPushButton( btn2, this );
56 layout->addWidget( btn, 1, 1 ); 56 layout->addWidget( btn, 1, 1 );
57 connect( btn, SIGNAL(clicked()), this, SLOT(slotBtn2Clicked()) ); 57 connect( btn, SIGNAL(clicked()), this, SLOT(slotBtn2Clicked()) );
58} 58}
59 59
60int PromptDlg::display() 60int PromptDlg::display()
61{ 61{
62 // Determine position of dialog. Derived from QT's QDialog::show() method. 62 // Determine position of dialog. Derived from QT's QDialog::show() method.
63 QWidget *w = parentWidget(); 63 QWidget *w = parentWidget();
64 QPoint p( 0, 0 ); 64 QPoint p( 0, 0 );
65 int extraw = 0, extrah = 0; 65 int extraw = 0, extrah = 0;
66 QWidget * desk = QApplication::desktop(); 66 QWidget * desk = QApplication::desktop();
67 if ( w ) 67 if ( w )
68 w = w->topLevelWidget(); 68 w = w->topLevelWidget();
69 69
70 QWidgetList *list = QApplication::topLevelWidgets(); 70 QWidgetList *list = QApplication::topLevelWidgets();
71 QWidgetListIt it( *list ); 71 QWidgetListIt it( *list );
72 while ( (extraw == 0 || extrah == 0) && it.current() != 0 ) 72 while ( (extraw == 0 || extrah == 0) && it.current() != 0 )
73 { 73 {
74 int w, h; 74 int w, h;
75 QWidget * current = it.current(); 75 QWidget * current = it.current();
76 ++it; 76 ++it;
77 w = current->geometry().x() - current->x(); 77 w = current->geometry().x() - current->x();
78 h = current->geometry().y() - current->y(); 78 h = current->geometry().y() - current->y();
79 79
80 extraw = QMAX( extraw, w ); 80 extraw = QMAX( extraw, w );
81 extrah = QMAX( extrah, h ); 81 extrah = QMAX( extrah, h );
82 } 82 }
83 delete list; 83 delete list;
84 84
85 // sanity check for decoration frames. With embedding, we 85 // sanity check for decoration frames. With embedding, we
86 // might get extraordinary values 86 // might get extraordinary values
87 if ( extraw >= 10 || extrah >= 40 ) 87 if ( extraw >= 10 || extrah >= 40 )
88 extraw = extrah = 0; 88 extraw = extrah = 0;
89 89
90 if ( w ) 90 if ( w )
91 { 91 {
92 // Use mapToGlobal rather than geometry() in case w might 92 // Use mapToGlobal rather than geometry() in case w might
93 // be embedded in another application 93 // be embedded in another application
94 QPoint pp = w->mapToGlobal( QPoint(0,0) ); 94 QPoint pp = w->mapToGlobal( QPoint(0,0) );
95 p = QPoint( pp.x() + w->width()/2, pp.y() + w->height()/ 2 ); 95 p = QPoint( pp.x() + w->width()/2, pp.y() + w->height()/ 2 );
96 } 96 }
97 else 97 else
98 p = QPoint( desk->width()/2, desk->height()/2 ); 98 p = QPoint( desk->width()/2, desk->height()/2 );
99 99
100 p = QPoint( p.x()-width()/2 - extraw, p.y()-height()/2 - extrah ); 100 p = QPoint( p.x()-width()/2 - extraw, p.y()-height()/2 - extrah );
101 101
102 if ( p.x() + extraw + width() > desk->width() ) 102 if ( p.x() + extraw + width() > desk->width() )
103 p.setX( desk->width() - width() - extraw ); 103 p.setX( desk->width() - width() - extraw );
104 if ( p.x() < 0 ) 104 if ( p.x() < 0 )
105 p.setX( 0 ); 105 p.setX( 0 );
106 106
107 if ( p.y() + extrah + height() > desk->height() ) 107 if ( p.y() + extrah + height() > desk->height() )
108 p.setY( desk->height() - height() - extrah ); 108 p.setY( desk->height() - height() - extrah );
109 if ( p.y() < 0 ) 109 if ( p.y() < 0 )
110 p.setY( 0 ); 110 p.setY( 0 );
111 111
112 move( p ); 112 move( p );
113 show(); 113 show();
114 114
115 // Enter event loop for modality 115 // Enter event loop for modality
116 qApp->enter_loop(); 116 qApp->enter_loop();
117 117
118 return m_btnClicked; 118 return m_btnClicked;
119} 119}
120 120
121int PromptDlg::ask( const QString &caption, const QString &text, const QString &btn1, const QString &btn2, 121int PromptDlg::ask( const QString &caption, const QString &text, const QString &btn1, const QString &btn2,
122 QWidget *parent ) 122 QWidget *parent )
123{ 123{
124 PromptDlg *dlg = new PromptDlg( caption, text, btn1, btn2, parent ); 124 PromptDlg *dlg = new PromptDlg( caption, text, btn1, btn2, parent );
125 int rc = dlg->display(); 125 int rc = dlg->display();
126 delete dlg; 126 delete dlg;
127 return rc; 127 return rc;
128} 128}
129 129
130void PromptDlg::slotBtn1Clicked() 130void PromptDlg::slotBtn1Clicked()
131{ 131{
132 m_btnClicked = 1; 132 m_btnClicked = 1;
133 qApp->exit_loop(); 133 qApp->exit_loop();
134} 134}
135 135
136void PromptDlg::slotBtn2Clicked() 136void PromptDlg::slotBtn2Clicked()
137{ 137{
138 m_btnClicked = 2; 138 m_btnClicked = 2;
139 qApp->exit_loop(); 139 qApp->exit_loop();
140} 140}