summaryrefslogtreecommitdiff
authorandyq <andyq>2002-10-25 18:58:30 (UTC)
committer andyq <andyq>2002-10-25 18:58:30 (UTC)
commit835fadbad01b725a46ffd68ca458fd39c7313ea0 (patch) (unidiff)
tree4fbc213e01292e4e850ad561c387f75098e2b059
parent1d3135677f1f49b9cc87ebf01f1c4eaab3c450f4 (diff)
downloadopie-835fadbad01b725a46ffd68ca458fd39c7313ea0.zip
opie-835fadbad01b725a46ffd68ca458fd39c7313ea0.tar.gz
opie-835fadbad01b725a46ffd68ca458fd39c7313ea0.tar.bz2
Added version handling
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/aqpkg.pro4
-rw-r--r--noncore/settings/aqpkg/installdlgimpl.cpp5
-rw-r--r--noncore/settings/aqpkg/networkpkgmgr.cpp81
-rw-r--r--noncore/settings/aqpkg/version.cpp214
4 files changed, 279 insertions, 25 deletions
diff --git a/noncore/settings/aqpkg/aqpkg.pro b/noncore/settings/aqpkg/aqpkg.pro
index b869f32..99b82a1 100644
--- a/noncore/settings/aqpkg/aqpkg.pro
+++ b/noncore/settings/aqpkg/aqpkg.pro
@@ -23,22 +23,22 @@ SOURCES = mainwin.cpp \
23 ipkg.cpp \ 23 ipkg.cpp \
24 networkpkgmgr.cpp \ 24 networkpkgmgr.cpp \
25 main.cpp \ 25 main.cpp \
26 package.cpp \ 26 package.cpp \
27 progressdlg.cpp \ 27 progressdlg.cpp \
28 installdlgimpl.cpp \ 28 installdlgimpl.cpp \
29 instoptionsimpl.cpp \ 29 instoptionsimpl.cpp \
30 destination.cpp \ 30 destination.cpp \
31 utils.cpp \ 31 utils.cpp \
32 server.cpp \ 32 server.cpp \
33 helpwindow.cpp \ 33 helpwindow.cpp \
34 letterpushbutton.cpp \ 34 letterpushbutton.cpp \
35 inputdlg.cpp 35 inputdlg.cpp \
36 version.cpp
36 INTERFACES= settings.ui \ 37 INTERFACES= settings.ui \
37 install.ui \ 38 install.ui \
38 instoptions.ui 39 instoptions.ui
39 TARGET = aqpkg 40 TARGET = aqpkg
40DESTDIR=$(OPIEDIR)/bin
41INCLUDEPATH += $(OPIEDIR)/include 41INCLUDEPATH += $(OPIEDIR)/include
42DEPENDPATH += $(OPIEDIR)/include 42DEPENDPATH += $(OPIEDIR)/include
43LIBS += -lqpe -lstdc++ 43LIBS += -lqpe -lstdc++
44 44
diff --git a/noncore/settings/aqpkg/installdlgimpl.cpp b/noncore/settings/aqpkg/installdlgimpl.cpp
index 2ea70e0..b297437 100644
--- a/noncore/settings/aqpkg/installdlgimpl.cpp
+++ b/noncore/settings/aqpkg/installdlgimpl.cpp
@@ -83,25 +83,28 @@ InstallDlgImpl::InstallDlgImpl( vector<InstallData> &packageList, DataManager *d
83 { 83 {
84 installList.push_back( item ); 84 installList.push_back( item );
85 install += " " + item.packageName + "\n"; 85 install += " " + item.packageName + "\n";
86 } 86 }
87 else if ( item.option == "D" ) 87 else if ( item.option == "D" )
88 { 88 {
89 removeList.push_back( item ); 89 removeList.push_back( item );
90 remove += " " + item.packageName + "\n"; 90 remove += " " + item.packageName + "\n";
91 } 91 }
92 else if ( item.option == "U" || item.option == "R" ) 92 else if ( item.option == "U" || item.option == "R" )
93 { 93 {
94 updateList.push_back( item ); 94 updateList.push_back( item );
95 upgrade += " " + item.packageName + "\n"; 95 QString type = " (Upgrade)";
96 if ( item.option == "R" )
97 type = " (ReInstall)";
98 upgrade += " " + item.packageName + type + "\n";
96 } 99 }
97 } 100 }
98 101
99 output->setText( remove + install + upgrade ); 102 output->setText( remove + install + upgrade );
100} 103}
101 104
102InstallDlgImpl::InstallDlgImpl( Ipkg *ipkg, QString initialText, QWidget *parent, const char *name, bool modal, WFlags fl ) 105InstallDlgImpl::InstallDlgImpl( Ipkg *ipkg, QString initialText, QWidget *parent, const char *name, bool modal, WFlags fl )
103 : InstallDlg( parent, name, modal, fl ) 106 : InstallDlg( parent, name, modal, fl )
104{ 107{
105 pIpkg = ipkg; 108 pIpkg = ipkg;
106 output->setText( initialText ); 109 output->setText( initialText );
107} 110}
diff --git a/noncore/settings/aqpkg/networkpkgmgr.cpp b/noncore/settings/aqpkg/networkpkgmgr.cpp
index 3971aea..02e4e73 100644
--- a/noncore/settings/aqpkg/networkpkgmgr.cpp
+++ b/noncore/settings/aqpkg/networkpkgmgr.cpp
@@ -34,24 +34,26 @@ using namespace std;
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 43
44#include "global.h" 44#include "global.h"
45 45
46extern int compareVersions( const char *v1, const char *v2 );
47
46NetworkPackageManager::NetworkPackageManager( DataManager *dataManager, QWidget *parent, const char *name) 48NetworkPackageManager::NetworkPackageManager( DataManager *dataManager, QWidget *parent, const char *name)
47 : QWidget(parent, name) 49 : QWidget(parent, name)
48{ 50{
49 dataMgr = dataManager; 51 dataMgr = dataManager;
50 52
51#ifdef QWS 53#ifdef QWS
52 // read download directory from config file 54 // read download directory from config file
53 Config cfg( "aqpkg" ); 55 Config cfg( "aqpkg" );
54 cfg.setGroup( "settings" ); 56 cfg.setGroup( "settings" );
55 currentlySelectedServer = cfg.readEntry( "selectedServer", "local" ); 57 currentlySelectedServer = cfg.readEntry( "selectedServer", "local" );
56 showJumpTo = cfg.readBoolEntry( "showJumpTo", "true" ); 58 showJumpTo = cfg.readBoolEntry( "showJumpTo", "true" );
57#endif 59#endif
@@ -223,25 +225,28 @@ void NetworkPackageManager :: serverSelected( int )
223 225
224 // If the local server, only display installed packages 226 // If the local server, only display installed packages
225 if ( serverName == LOCAL_SERVER && !it->isInstalled() ) 227 if ( serverName == LOCAL_SERVER && !it->isInstalled() )
226 continue; 228 continue;
227 229
228 text += it->getPackageName(); 230 text += it->getPackageName();
229 if ( it->isInstalled() ) 231 if ( it->isInstalled() )
230 { 232 {
231 text += " (installed)"; 233 text += " (installed)";
232 234
233 // If a different version of package is available, postfix it with an * 235 // If a different version of package is available, postfix it with an *
234 if ( it->getVersion() != it->getInstalledVersion() ) 236 if ( it->getVersion() != it->getInstalledVersion() )
235 text += "*"; 237 {
238 if ( compareVersions( it->getInstalledVersion(), it->getVersion() ) == 1 )
239 text += "*";
240 }
236 } 241 }
237 242
238 QCheckListItem *item = new QCheckListItem( packagesList, text, QCheckListItem::CheckBox ); 243 QCheckListItem *item = new QCheckListItem( packagesList, text, QCheckListItem::CheckBox );
239 244
240 if ( it->isInstalled() ) 245 if ( it->isInstalled() )
241 { 246 {
242 QString destName = ""; 247 QString destName = "";
243 if ( it->getLocalPackage() ) 248 if ( it->getLocalPackage() )
244 { 249 {
245 if ( it->getLocalPackage()->getInstalledTo() ) 250 if ( it->getLocalPackage()->getInstalledTo() )
246 destName = it->getLocalPackage()->getInstalledTo()->getDestinationName(); 251 destName = it->getLocalPackage()->getInstalledTo()->getDestinationName();
247 } 252 }
@@ -524,55 +529,87 @@ InstallData NetworkPackageManager :: dealWithItem( QCheckListItem *item )
524 item.packageName = p->getInstalledPackageName(); 529 item.packageName = p->getInstalledPackageName();
525 if ( p->getInstalledTo() ) 530 if ( p->getInstalledTo() )
526 { 531 {
527 item.destination = p->getInstalledTo(); 532 item.destination = p->getInstalledTo();
528 cout << "dest - " << p->getInstalledTo()->getDestinationName() << endl; 533 cout << "dest - " << p->getInstalledTo()->getDestinationName() << endl;
529 cout << "dest - " << p->getInstalledTo()->getDestinationPath() << endl; 534 cout << "dest - " << p->getInstalledTo()->getDestinationPath() << endl;
530 } 535 }
531 else 536 else
532 { 537 {
533 item.destination = p->getLocalPackage()->getInstalledTo(); 538 item.destination = p->getLocalPackage()->getInstalledTo();
534 } 539 }
535 540
536 // Sticky option not implemented yet, but will eventually allow 541 // Now see if version is newer or not
537 // the user to say something like 'remove all' 542 int val = compareVersions( p->getInstalledVersion(), p->getVersion() );
538 if ( stickyOption == "" ) 543 if ( val == -2 )
539 { 544 {
540 QString msgtext; 545 // Error - should handle
541 msgtext.sprintf( "Do you wish to remove or reinstall\n%s?", (const char *)name ); 546 }
542 switch( QMessageBox::information( this, "Remove or ReInstall", 547 else if ( val == -1 )
543 msgtext, "Remove", "ReInstall" ) ) 548 {
544 { 549 // Version available is older - remove only
545 case 0: // Try again or Enter 550 item.option = "R";
546 item.option = "D";
547 break;
548 case 1: // Quit or Escape
549 item.option = "U";
550 break;
551 }
552 } 551 }
553 else 552 else
554 { 553 {
555// item.option = stickyOption; 554 QString caption;
555 QString text;
556 QString secondButton;
557 QString secondOption;
558 if ( val == 0 )
559 {
560 // Version available is the same - option to remove or reinstall
561 caption = "Do you wish to remove or reinstall\n%s?";
562 text = "Remove or ReInstall";
563 secondButton = "ReInstall";
564 secondOption = "R";
565 }
566 else if ( val == 1 )
567 {
568 // Version available is newer - option to remove or upgrade
569 caption = "Do you wish to remove or upgrade\n%s?";
570 text = "Remove or Upgrade";
571 secondButton = "Upgrade";
572 secondOption = "U";
573 }
574
575 // Sticky option not implemented yet, but will eventually allow
576 // the user to say something like 'remove all'
577 if ( stickyOption == "" )
578 {
579 QString msgtext;
580 msgtext.sprintf( caption, (const char *)name );
581 switch( QMessageBox::information( this, text,
582 msgtext, "Remove", secondButton ) )
583 {
584 case 0: // Try again or Enter
585 item.option = "D";
586 break;
587 case 1: // Quit or Escape
588 item.option = secondOption;
589 break;
590 }
591 }
592 else
593 {
594// item.option = stickyOption;
595 }
556 } 596 }
597
557 598
558 // Check if we are reinstalling the same version 599 // Check if we are reinstalling the same version
559 if ( p->getVersion() != p->getInstalledVersion() ) 600 if ( item.option != "R" )
560 item.recreateLinks = true; 601 item.recreateLinks = true;
561 else 602 else
562 {
563 if ( item.option == "U" )
564 item.option = "R";
565 item.recreateLinks = false; 603 item.recreateLinks = false;
566 }
567 604
568 // User hit cancel (on dlg - assume remove) 605 // User hit cancel (on dlg - assume remove)
569 return item; 606 return item;
570 } 607 }
571} 608}
572 609
573void NetworkPackageManager :: displayText( const QString &t ) 610void NetworkPackageManager :: displayText( const QString &t )
574{ 611{
575 cout << t << endl; 612 cout << t << endl;
576} 613}
577 614
578 615
diff --git a/noncore/settings/aqpkg/version.cpp b/noncore/settings/aqpkg/version.cpp
new file mode 100644
index 0000000..e836da1
--- a/dev/null
+++ b/noncore/settings/aqpkg/version.cpp
@@ -0,0 +1,214 @@
1/*
2 * libdpkg - Debian packaging suite library routines
3 * vercmp.c - comparison of version numbers
4 *
5 * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
6 *
7 * This is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2,
10 * or (at your option) any later version.
11 *
12 * This is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public
18 * License along with dpkg; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21#include <stdio.h>
22#include <stdlib.h>
23#include <ctype.h>
24#include <string.h>
25
26# define _(Text) Text
27
28class versionrevision
29{
30public:
31 versionrevision()
32 {
33 version = 0;
34 }
35
36 ~versionrevision()
37 {
38 if ( version )
39 delete version;
40 }
41
42 void setVersion( const char *str )
43 {
44 version = new char[(strlen(str)+1)];
45 strcpy( version, str );
46 }
47
48 unsigned long epoch;
49 char *version;
50 const char *revision;
51 const char *familiar_revision;
52};
53
54static int verrevcmp(const char *val, const char *ref)
55{
56 int vc, rc;
57 long vl, rl;
58 const char *vp, *rp;
59
60 if (!val) val= "";
61 if (!ref) ref= "";
62 for (;;) {
63 vp= val; while (*vp && !isdigit(*vp)) vp++;
64 rp= ref; while (*rp && !isdigit(*rp)) rp++;
65 for (;;) {
66 vc= val == vp ? 0 : *val++;
67 rc= ref == rp ? 0 : *ref++;
68 if (!rc && !vc) break;
69 if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
70 if (rc && !isalpha(rc)) rc += 256;
71 if (vc != rc) return vc - rc;
72 }
73 val= vp;
74 ref= rp;
75 vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
76 rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
77 if (vl != rl) return vl - rl;
78 if (!*val && !*ref) return 0;
79 if (!*val) return -1;
80 if (!*ref) return +1;
81 }
82}
83
84int versioncompare(const struct versionrevision *version,
85 const struct versionrevision *refversion)
86{
87 int r;
88
89 if (version->epoch > refversion->epoch) return 1;
90 if (version->epoch < refversion->epoch) return -1;
91 r= verrevcmp(version->version,refversion->version); if (r) return r;
92 r= verrevcmp(version->revision,refversion->revision); if (r) return r;
93 return verrevcmp(version->familiar_revision,refversion->familiar_revision);
94}
95
96int versionsatisfied3(const struct versionrevision *it,
97 const struct versionrevision *ref,
98 const char *op)
99{
100 int r;
101 r= versioncompare(it,ref);
102 if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0)
103 return r <= 0;
104 if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0)
105 return r >= 0;
106 if (strcmp(op, "<<") == 0)
107 return r < 0;
108 if (strcmp(op, ">>") == 0)
109 return r > 0;
110 if (strcmp(op, "=") == 0)
111 return r == 0;
112 fprintf(stderr, "unknown operator: %s", op);
113
114 exit(1);
115}
116
117const char *parseversion(struct versionrevision *rversion, const char *string)
118{
119 char *hyphen, *colon, *eepochcolon;
120 unsigned long epoch;
121
122 if (!*string) return _("version string is empty");
123
124 colon= strchr(string,':');
125 if (colon) {
126 epoch= strtoul(string,&eepochcolon,10);
127 if (colon != eepochcolon) return _("epoch in version is not number");
128 if (!*++colon) return _("nothing after colon in version number");
129 string= colon;
130 rversion->epoch= epoch;
131 } else {
132 rversion->epoch= 0;
133 }
134
135 rversion->revision = "";
136 rversion->familiar_revision = "";
137
138 rversion->setVersion( string );
139 hyphen= strrchr(rversion->version,'-');
140 if (hyphen) {
141 *hyphen++= 0;
142 if (strncmp("fam", hyphen, 3) == 0) {
143 rversion->familiar_revision=hyphen+3;
144 hyphen= strrchr(rversion->version,'-');
145 if (hyphen) {
146 *hyphen++= 0;
147 rversion->revision = hyphen;
148 }
149 } else {
150 rversion->revision = hyphen;
151 }
152 }
153/*
154 fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
155 rversion->epoch,
156 rversion->version,
157 rversion->revision,
158 rversion->familiar_revision);
159*/
160 return 0;
161}
162
163int compareVersions( const char *v1, const char *v2 )
164{
165 const char *err;
166 versionrevision ver, ref;
167
168 err = parseversion(&ref, v1);
169 if (err) {
170 fprintf(stderr, "Invalid version `%s': %s\n", v2, err);
171 return -2;
172 }
173
174 err = parseversion(&ver, v2);
175 if (err) {
176 fprintf(stderr, "Invalid version `%s': %s\n", v1, err);
177 return -2;
178 }
179
180 if ( versionsatisfied3( &ver, &ref, "=" ) )
181 return 0;
182 else if ( versionsatisfied3( &ver, &ref, "<" ) )
183 return -1;
184 else
185 return 1;
186}
187
188/*
189int main(int argc, char *argv[])
190{
191 const char *err;
192 versionrevision ver, ref;
193
194 if (argc < 4) {
195 fprintf(stderr, "usage: %s: version op refversion\n", argv[0]);
196 return 2;
197 }
198
199 err = parseversion(&ver, argv[1]);
200 if (err) {
201 fprintf(stderr, "Invalid version `%s': %s\n", argv[1], err);
202 return 2;
203 }
204
205 err = parseversion(&ref, argv[3]);
206 if (err) {
207 fprintf(stderr, "Invalid version `%s': %s\n", argv[3], err);
208 return 2;
209 }
210
211 printf( "Result: %d\n", versionsatisfied3(&ver, &ref, argv[2]) );
212}
213
214*/