-rw-r--r-- | noncore/settings/aqpkg/installdlgimpl.cpp | 58 | ||||
-rw-r--r-- | noncore/settings/aqpkg/installdlgimpl.h | 4 | ||||
-rw-r--r-- | noncore/settings/aqpkg/ipkg.cpp | 5 | ||||
-rw-r--r-- | noncore/settings/aqpkg/networkpkgmgr.cpp | 23 |
4 files changed, 46 insertions, 44 deletions
diff --git a/noncore/settings/aqpkg/installdlgimpl.cpp b/noncore/settings/aqpkg/installdlgimpl.cpp index e122064..a924daf 100644 --- a/noncore/settings/aqpkg/installdlgimpl.cpp +++ b/noncore/settings/aqpkg/installdlgimpl.cpp | |||
@@ -1,236 +1,236 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | installdlgimpl.cpp - description | 2 | installdlgimpl.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Mon Aug 26 2002 | 4 | begin : Mon Aug 26 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 | #ifdef QWS | 18 | #ifdef QWS |
19 | #include <qpe/config.h> | 19 | #include <qpe/config.h> |
20 | #endif | 20 | #endif |
21 | 21 | ||
22 | #include <qmultilineedit.h> | 22 | #include <qmultilineedit.h> |
23 | #include <qdialog.h> | 23 | #include <qdialog.h> |
24 | #include <qcombobox.h> | 24 | #include <qcombobox.h> |
25 | #include <qcheckbox.h> | 25 | #include <qcheckbox.h> |
26 | #include <qpushbutton.h> | 26 | #include <qpushbutton.h> |
27 | 27 | ||
28 | 28 | ||
29 | #include "datamgr.h" | 29 | #include "datamgr.h" |
30 | #include "instoptionsimpl.h" | 30 | #include "instoptionsimpl.h" |
31 | #include "destination.h" | 31 | #include "destination.h" |
32 | #include "installdlgimpl.h" | 32 | #include "installdlgimpl.h" |
33 | #include "global.h" | 33 | #include "global.h" |
34 | 34 | ||
35 | InstallDlgImpl::InstallDlgImpl( vector<InstallData> &packageList, DataManager *dataManager, QWidget * parent, const char* name, bool modal, WFlags fl ) | 35 | InstallDlgImpl::InstallDlgImpl( vector<InstallData> &packageList, DataManager *dataManager, QWidget * parent, const char* name, bool modal, WFlags fl ) |
36 | : InstallDlg( parent, name, modal, fl ) | 36 | : InstallDlg( parent, name, modal, fl ) |
37 | { | 37 | { |
38 | upgradePackages = false; | 38 | upgradePackages = false; |
39 | dataMgr = dataManager; | 39 | dataMgr = dataManager; |
40 | vector<Destination>::iterator dit; | 40 | vector<Destination>::iterator dit; |
41 | 41 | ||
42 | QString defaultDest = "root"; | 42 | QString defaultDest = "root"; |
43 | #ifdef QWS | 43 | #ifdef QWS |
44 | Config cfg( "aqpkg" ); | 44 | Config cfg( "aqpkg" ); |
45 | cfg.setGroup( "settings" ); | 45 | cfg.setGroup( "settings" ); |
46 | defaultDest = cfg.readEntry( "dest", "root" ); | 46 | defaultDest = cfg.readEntry( "dest", "root" ); |
47 | 47 | ||
48 | // Grab flags - Turn MAKE_LINKS on by default (if no flags found) | 48 | // Grab flags - Turn MAKE_LINKS on by default (if no flags found) |
49 | // flags = cfg.readNumEntry( "installFlags", MAKE_LINKS ); | 49 | // flags = cfg.readNumEntry( "installFlags", MAKE_LINKS ); |
50 | flags = 0; | 50 | flags = 0; |
51 | #else | 51 | #else |
52 | flags = 0; | 52 | flags = 0; |
53 | #endif | 53 | #endif |
54 | 54 | ||
55 | // Output text is read only | 55 | // Output text is read only |
56 | output->setReadOnly( true ); | 56 | output->setReadOnly( true ); |
57 | QFont f( "helvetica" ); | 57 | QFont f( "helvetica" ); |
58 | f.setPointSize( 10 ); | 58 | f.setPointSize( 10 ); |
59 | output->setFont( f ); | 59 | output->setFont( f ); |
60 | 60 | ||
61 | 61 | ||
62 | // setup destination data | 62 | // setup destination data |
63 | int defIndex = 0; | 63 | int defIndex = 0; |
64 | int i; | 64 | int i; |
65 | for ( i = 0 , dit = dataMgr->getDestinationList().begin() ; dit != dataMgr->getDestinationList().end() ; ++dit, ++i ) | 65 | for ( i = 0 , dit = dataMgr->getDestinationList().begin() ; dit != dataMgr->getDestinationList().end() ; ++dit, ++i ) |
66 | { | 66 | { |
67 | destination->insertItem( dit->getDestinationName() ); | 67 | destination->insertItem( dit->getDestinationName() ); |
68 | if ( dit->getDestinationName() == defaultDest ) | 68 | if ( dit->getDestinationName() == defaultDest ) |
69 | defIndex = i; | 69 | defIndex = i; |
70 | } | 70 | } |
71 | 71 | ||
72 | destination->setCurrentItem( defIndex ); | 72 | destination->setCurrentItem( defIndex ); |
73 | 73 | ||
74 | vector<InstallData>::iterator it; | 74 | vector<InstallData>::iterator it; |
75 | // setup package data | 75 | // setup package data |
76 | QString remove = "Remove\n"; | 76 | QString remove = "Remove\n"; |
77 | QString install = "\nInstall\n"; | 77 | QString install = "\nInstall\n"; |
78 | QString upgrade = "\nUpgrade\n"; | 78 | QString upgrade = "\nUpgrade\n"; |
79 | for ( it = packageList.begin() ; it != packageList.end() ; ++it ) | 79 | for ( it = packageList.begin() ; it != packageList.end() ; ++it ) |
80 | { | 80 | { |
81 | InstallData item = *it; | 81 | InstallData item = *it; |
82 | if ( item.option == "I" ) | 82 | if ( item.option == "I" ) |
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" ) | 92 | else if ( item.option == "U" ) |
93 | { | 93 | { |
94 | updateList.push_back( item ); | 94 | updateList.push_back( item ); |
95 | upgrade += " " + item.packageName + "\n"; | 95 | upgrade += " " + item.packageName + "\n"; |
96 | } | 96 | } |
97 | } | 97 | } |
98 | 98 | ||
99 | output->setText( remove + install + upgrade ); | 99 | output->setText( remove + install + upgrade ); |
100 | |||
101 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); | ||
102 | } | 100 | } |
103 | 101 | ||
104 | InstallDlgImpl::InstallDlgImpl( QWidget *parent, const char *name, bool modal, WFlags fl ) | 102 | InstallDlgImpl::InstallDlgImpl( Ipkg *ipkg, QString initialText, QWidget *parent, const char *name, bool modal, WFlags fl ) |
105 | : InstallDlg( parent, name, modal, fl ) | 103 | : InstallDlg( parent, name, modal, fl ) |
106 | { | 104 | { |
107 | upgradePackages = true; | 105 | pIpkg = ipkg; |
108 | output->setText( "Upgrading installed packages" ); | 106 | output->setText( initialText ); |
109 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); | ||
110 | } | 107 | } |
111 | 108 | ||
112 | 109 | ||
113 | InstallDlgImpl::~InstallDlgImpl() | 110 | InstallDlgImpl::~InstallDlgImpl() |
114 | { | 111 | { |
115 | } | 112 | } |
116 | 113 | ||
117 | bool InstallDlgImpl :: showDlg() | 114 | bool InstallDlgImpl :: showDlg() |
118 | { | 115 | { |
119 | showMaximized(); | 116 | showMaximized(); |
120 | bool ret = exec(); | 117 | bool ret = exec(); |
121 | 118 | ||
122 | return ret; | 119 | return ret; |
123 | } | 120 | } |
124 | 121 | ||
125 | void InstallDlgImpl :: optionsSelected() | 122 | void InstallDlgImpl :: optionsSelected() |
126 | { | 123 | { |
127 | InstallOptionsDlgImpl opt( flags, this, "Option", true ); | 124 | InstallOptionsDlgImpl opt( flags, this, "Option", true ); |
128 | opt.exec(); | 125 | opt.exec(); |
129 | 126 | ||
130 | // set options selected from dialog | 127 | // set options selected from dialog |
131 | flags = 0; | 128 | flags = 0; |
132 | if ( opt.forceDepends->isChecked() ) | 129 | if ( opt.forceDepends->isChecked() ) |
133 | flags |= FORCE_DEPENDS; | 130 | flags |= FORCE_DEPENDS; |
134 | if ( opt.forceReinstall->isChecked() ) | 131 | if ( opt.forceReinstall->isChecked() ) |
135 | flags |= FORCE_REINSTALL; | 132 | flags |= FORCE_REINSTALL; |
136 | if ( opt.forceRemove->isChecked() ) | 133 | if ( opt.forceRemove->isChecked() ) |
137 | flags |= FORCE_REMOVE; | 134 | flags |= FORCE_REMOVE; |
138 | if ( opt.forceOverwrite->isChecked() ) | 135 | if ( opt.forceOverwrite->isChecked() ) |
139 | flags |= FORCE_OVERWRITE; | 136 | flags |= FORCE_OVERWRITE; |
140 | 137 | ||
141 | #ifdef QWS | 138 | #ifdef QWS |
142 | Config cfg( "aqpkg" ); | 139 | Config cfg( "aqpkg" ); |
143 | cfg.setGroup( "settings" ); | 140 | cfg.setGroup( "settings" ); |
144 | cfg.writeEntry( "installFlags", flags ); | 141 | cfg.writeEntry( "installFlags", flags ); |
145 | #endif | 142 | #endif |
146 | } | 143 | } |
147 | 144 | ||
148 | void InstallDlgImpl :: installSelected() | 145 | void InstallDlgImpl :: installSelected() |
149 | { | 146 | { |
150 | if ( btnInstall->text() == "Close" ) | 147 | if ( btnInstall->text() == "Close" ) |
151 | { | 148 | { |
152 | done( 1 ); | 149 | done( 1 ); |
153 | return; | 150 | return; |
154 | } | 151 | } |
155 | 152 | ||
156 | btnInstall->setEnabled( false ); | 153 | btnInstall->setEnabled( false ); |
157 | 154 | ||
158 | if ( upgradePackages ) | 155 | if ( pIpkg ) |
159 | { | 156 | { |
160 | output->setText( "" ); | 157 | output->setText( "" ); |
161 | 158 | ||
162 | Ipkg ipkg; | 159 | connect( pIpkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); |
163 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); | 160 | pIpkg->runIpkg(); |
164 | ipkg.setOption( "upgrade" ); | ||
165 | ipkg.runIpkg(); | ||
166 | } | 161 | } |
167 | else | 162 | else |
168 | { | 163 | { |
169 | output->setText( "" ); | 164 | output->setText( "" ); |
170 | Destination *d = dataMgr->getDestination( destination->currentText() ); | 165 | Destination *d = dataMgr->getDestination( destination->currentText() ); |
171 | QString dest = d->getDestinationName(); | 166 | QString dest = d->getDestinationName(); |
172 | QString destDir = d->getDestinationPath(); | 167 | QString destDir = d->getDestinationPath(); |
173 | int instFlags = flags; | 168 | int instFlags = flags; |
174 | if ( d->linkToRoot() ) | 169 | if ( d->linkToRoot() ) |
175 | instFlags |= MAKE_LINKS; | 170 | instFlags |= MAKE_LINKS; |
176 | 171 | ||
177 | #ifdef QWS | 172 | #ifdef QWS |
178 | // Save settings | 173 | // Save settings |
179 | Config cfg( "aqpkg" ); | 174 | Config cfg( "aqpkg" ); |
180 | cfg.setGroup( "settings" ); | 175 | cfg.setGroup( "settings" ); |
181 | cfg.writeEntry( "dest", dest ); | 176 | cfg.writeEntry( "dest", dest ); |
182 | #endif | 177 | #endif |
183 | 178 | ||
179 | pIpkg = new Ipkg; | ||
180 | connect( pIpkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); | ||
181 | |||
184 | // First run through the remove list, then the install list then the upgrade list | 182 | // First run through the remove list, then the install list then the upgrade list |
185 | vector<InstallData>::iterator it; | 183 | vector<InstallData>::iterator it; |
186 | ipkg.setOption( "remove" ); | 184 | pIpkg->setOption( "remove" ); |
187 | for ( it = removeList.begin() ; it != removeList.end() ; ++it ) | 185 | for ( it = removeList.begin() ; it != removeList.end() ; ++it ) |
188 | { | 186 | { |
189 | ipkg.setDestination( it->destination->getDestinationName() ); | 187 | pIpkg->setDestination( it->destination->getDestinationName() ); |
190 | ipkg.setDestinationDir( it->destination->getDestinationPath() ); | 188 | pIpkg->setDestinationDir( it->destination->getDestinationPath() ); |
191 | ipkg.setPackage( it->packageName ); | 189 | pIpkg->setPackage( it->packageName ); |
192 | 190 | ||
193 | int tmpFlags = flags; | 191 | int tmpFlags = flags; |
194 | if ( it->destination->linkToRoot() ) | 192 | if ( it->destination->linkToRoot() ) |
195 | tmpFlags |= MAKE_LINKS; | 193 | tmpFlags |= MAKE_LINKS; |
196 | 194 | ||
197 | ipkg.setFlags( tmpFlags ); | 195 | pIpkg->setFlags( tmpFlags ); |
198 | ipkg.runIpkg(); | 196 | pIpkg->runIpkg(); |
199 | } | 197 | } |
200 | 198 | ||
201 | ipkg.setOption( "install" ); | 199 | pIpkg->setOption( "install" ); |
202 | ipkg.setDestination( dest ); | 200 | pIpkg->setDestination( dest ); |
203 | ipkg.setDestinationDir( destDir ); | 201 | pIpkg->setDestinationDir( destDir ); |
204 | ipkg.setFlags( instFlags ); | 202 | pIpkg->setFlags( instFlags ); |
205 | for ( it = installList.begin() ; it != installList.end() ; ++it ) | 203 | for ( it = installList.begin() ; it != installList.end() ; ++it ) |
206 | { | 204 | { |
207 | ipkg.setPackage( it->packageName ); | 205 | pIpkg->setPackage( it->packageName ); |
208 | ipkg.runIpkg(); | 206 | pIpkg->runIpkg(); |
209 | } | 207 | } |
210 | 208 | ||
211 | flags |= FORCE_REINSTALL; | 209 | flags |= FORCE_REINSTALL; |
212 | ipkg.setOption( "reinstall" ); | 210 | pIpkg->setOption( "reinstall" ); |
213 | for ( it = updateList.begin() ; it != updateList.end() ; ++it ) | 211 | for ( it = updateList.begin() ; it != updateList.end() ; ++it ) |
214 | { | 212 | { |
215 | ipkg.setDestination( it->destination->getDestinationName() ); | 213 | pIpkg->setDestination( it->destination->getDestinationName() ); |
216 | ipkg.setDestinationDir( it->destination->getDestinationPath() ); | 214 | pIpkg->setDestinationDir( it->destination->getDestinationPath() ); |
217 | ipkg.setPackage( it->packageName ); | 215 | pIpkg->setPackage( it->packageName ); |
218 | 216 | ||
219 | int tmpFlags = flags; | 217 | int tmpFlags = flags; |
220 | if ( it->destination->linkToRoot() && it->recreateLinks ) | 218 | if ( it->destination->linkToRoot() && it->recreateLinks ) |
221 | tmpFlags |= MAKE_LINKS; | 219 | tmpFlags |= MAKE_LINKS; |
222 | ipkg.setFlags( tmpFlags ); | 220 | pIpkg->setFlags( tmpFlags ); |
223 | ipkg.runIpkg(); | 221 | pIpkg->runIpkg(); |
224 | } | 222 | } |
223 | |||
224 | delete pIpkg; | ||
225 | } | 225 | } |
226 | 226 | ||
227 | btnInstall->setEnabled( true ); | 227 | btnInstall->setEnabled( true ); |
228 | btnInstall->setText( tr( "Close" ) ); | 228 | btnInstall->setText( tr( "Close" ) ); |
229 | } | 229 | } |
230 | 230 | ||
231 | void InstallDlgImpl :: displayText(const QString &text ) | 231 | void InstallDlgImpl :: displayText(const QString &text ) |
232 | { | 232 | { |
233 | QString t = output->text() + "\n" + text; | 233 | QString t = output->text() + "\n" + text; |
234 | output->setText( t ); | 234 | output->setText( t ); |
235 | output->setCursorPosition( output->numLines(), 0 ); | 235 | output->setCursorPosition( output->numLines(), 0 ); |
236 | } | 236 | } |
diff --git a/noncore/settings/aqpkg/installdlgimpl.h b/noncore/settings/aqpkg/installdlgimpl.h index 3a5d8b8..6716ced 100644 --- a/noncore/settings/aqpkg/installdlgimpl.h +++ b/noncore/settings/aqpkg/installdlgimpl.h | |||
@@ -1,65 +1,65 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | installdlgimpl.h - description | 2 | installdlgimpl.h - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Mon Aug 26 2002 | 4 | begin : Mon Aug 26 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 | #ifndef INSTALLDLGIMPL_H | 17 | #ifndef INSTALLDLGIMPL_H |
18 | #define INSTALLDLGIMPL_H | 18 | #define INSTALLDLGIMPL_H |
19 | 19 | ||
20 | #include <vector> | 20 | #include <vector> |
21 | using namespace std; | 21 | using namespace std; |
22 | 22 | ||
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | 24 | ||
25 | #include "ipkg.h" | 25 | #include "ipkg.h" |
26 | #include "install.h" | 26 | #include "install.h" |
27 | 27 | ||
28 | class InstallData | 28 | class InstallData |
29 | { | 29 | { |
30 | public: | 30 | public: |
31 | QString option; // I - install, D - delete, U - upgrade | 31 | QString option; // I - install, D - delete, U - upgrade |
32 | QString packageName; | 32 | QString packageName; |
33 | Destination *destination; | 33 | Destination *destination; |
34 | bool recreateLinks; | 34 | bool recreateLinks; |
35 | }; | 35 | }; |
36 | 36 | ||
37 | class InstallDlgImpl : public InstallDlg | 37 | class InstallDlgImpl : public InstallDlg |
38 | { | 38 | { |
39 | public: | 39 | public: |
40 | InstallDlgImpl( vector<InstallData> &packageList, DataManager *dataManager, QWidget * parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); | 40 | InstallDlgImpl( vector<InstallData> &packageList, DataManager *dataManager, QWidget * parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); |
41 | InstallDlgImpl( QWidget * parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); | 41 | InstallDlgImpl( Ipkg *ipkg, QString initialText, QWidget * parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); |
42 | ~InstallDlgImpl(); | 42 | ~InstallDlgImpl(); |
43 | 43 | ||
44 | bool showDlg(); | 44 | bool showDlg(); |
45 | bool upgradeServer( QString &server ); | 45 | bool upgradeServer( QString &server ); |
46 | 46 | ||
47 | protected: | 47 | protected: |
48 | 48 | ||
49 | private: | 49 | private: |
50 | DataManager *dataMgr; | 50 | DataManager *dataMgr; |
51 | vector<InstallData> installList; | 51 | vector<InstallData> installList; |
52 | vector<InstallData> removeList; | 52 | vector<InstallData> removeList; |
53 | vector<InstallData> updateList; | 53 | vector<InstallData> updateList; |
54 | int flags; | 54 | int flags; |
55 | Ipkg ipkg; | 55 | Ipkg *pIpkg; |
56 | bool upgradePackages; | 56 | bool upgradePackages; |
57 | 57 | ||
58 | bool runIpkg( QString &option, const QString& package, const QString& dest, int flags ); | 58 | bool runIpkg( QString &option, const QString& package, const QString& dest, int flags ); |
59 | 59 | ||
60 | void optionsSelected(); | 60 | void optionsSelected(); |
61 | void installSelected(); | 61 | void installSelected(); |
62 | void displayText(const QString &text ); | 62 | void displayText(const QString &text ); |
63 | }; | 63 | }; |
64 | 64 | ||
65 | #endif | 65 | #endif |
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp index 02d4258..eacef76 100644 --- a/noncore/settings/aqpkg/ipkg.cpp +++ b/noncore/settings/aqpkg/ipkg.cpp | |||
@@ -1,368 +1,369 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | ipkg.cpp - description | 2 | ipkg.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Sat Aug 31 2002 | 4 | begin : Sat Aug 31 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 | using namespace std; | 19 | using namespace std; |
20 | 20 | ||
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <unistd.h> | 22 | #include <unistd.h> |
23 | 23 | ||
24 | #ifdef QWS | 24 | #ifdef QWS |
25 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
26 | #else | 26 | #else |
27 | #include <qapplication.h> | 27 | #include <qapplication.h> |
28 | #endif | 28 | #endif |
29 | #include <qdir.h> | 29 | #include <qdir.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | 31 | ||
32 | #include "utils.h" | 32 | #include "utils.h" |
33 | #include "ipkg.h" | 33 | #include "ipkg.h" |
34 | #include "global.h" | 34 | #include "global.h" |
35 | 35 | ||
36 | Ipkg :: Ipkg() | 36 | Ipkg :: Ipkg() |
37 | { | 37 | { |
38 | } | 38 | } |
39 | 39 | ||
40 | Ipkg :: ~Ipkg() | 40 | Ipkg :: ~Ipkg() |
41 | { | 41 | { |
42 | } | 42 | } |
43 | 43 | ||
44 | // Option is what we are going to do - install, upgrade, download, reinstall | 44 | // Option is what we are going to do - install, upgrade, download, reinstall |
45 | // package is the package name to install - either a fully qualified path and ipk | 45 | // package is the package name to install - either a fully qualified path and ipk |
46 | // file (if stored locally) or just the name of the package (for a network package) | 46 | // file (if stored locally) or just the name of the package (for a network package) |
47 | // packageName is the package name - (for a network package this will be the same as | 47 | // packageName is the package name - (for a network package this will be the same as |
48 | // package parameter) | 48 | // package parameter) |
49 | // dest is the destination alias (from ipk.conf) | 49 | // dest is the destination alias (from ipk.conf) |
50 | // destDir is the dir that the destination alias points to (used to link to root) | 50 | // destDir is the dir that the destination alias points to (used to link to root) |
51 | // flags is the ipkg options flags | 51 | // flags is the ipkg options flags |
52 | // dir is the directory to run ipkg in (defaults to "") | 52 | // dir is the directory to run ipkg in (defaults to "") |
53 | bool Ipkg :: runIpkg( ) | 53 | bool Ipkg :: runIpkg( ) |
54 | { | 54 | { |
55 | bool ret = false; | 55 | bool ret = false; |
56 | 56 | ||
57 | QDir::setCurrent( "/tmp" ); | 57 | QDir::setCurrent( "/tmp" ); |
58 | QString cmd = ""; | 58 | QString cmd = ""; |
59 | 59 | ||
60 | if ( runtimeDir != "" ) | 60 | if ( runtimeDir != "" ) |
61 | { | 61 | { |
62 | cmd += "cd "; | 62 | cmd += "cd "; |
63 | cmd += runtimeDir; | 63 | cmd += runtimeDir; |
64 | cmd += " ; "; | 64 | cmd += " ; "; |
65 | } | 65 | } |
66 | cmd += "ipkg"; | 66 | cmd += "ipkg"; |
67 | 67 | ||
68 | if ( option != "update" && option != "download" && option != "upgrade" ) | 68 | if ( option != "update" && option != "download" && option != "upgrade" ) |
69 | { | 69 | { |
70 | cmd += " -dest "+ destination; | 70 | cmd += " -dest "+ destination; |
71 | cmd += " -force-defaults"; | 71 | cmd += " -force-defaults"; |
72 | 72 | ||
73 | if ( flags & FORCE_DEPENDS ) | 73 | if ( flags & FORCE_DEPENDS ) |
74 | cmd += " -force-depends"; | 74 | cmd += " -force-depends"; |
75 | if ( flags & FORCE_REINSTALL ) | 75 | if ( flags & FORCE_REINSTALL ) |
76 | cmd += " -force-reinstall"; | 76 | cmd += " -force-reinstall"; |
77 | if ( flags & FORCE_REMOVE ) | 77 | if ( flags & FORCE_REMOVE ) |
78 | cmd += " -force-removal-of-essential-packages"; | 78 | cmd += " -force-removal-of-essential-packages"; |
79 | if ( flags & FORCE_OVERWRITE ) | 79 | if ( flags & FORCE_OVERWRITE ) |
80 | cmd += " -force-overwrite"; | 80 | cmd += " -force-overwrite"; |
81 | 81 | ||
82 | // Handle make links | 82 | // Handle make links |
83 | // Rules - If make links is switched on, create links to root | 83 | // Rules - If make links is switched on, create links to root |
84 | // if destDir is NOT / | 84 | // if destDir is NOT / |
85 | if ( flags & MAKE_LINKS ) | 85 | if ( flags & MAKE_LINKS ) |
86 | { | 86 | { |
87 | // If destDir == / turn off make links as package is being insalled | 87 | // If destDir == / turn off make links as package is being insalled |
88 | // to root already. | 88 | // to root already. |
89 | if ( destDir == "/" ) | 89 | if ( destDir == "/" ) |
90 | flags ^= MAKE_LINKS; | 90 | flags ^= MAKE_LINKS; |
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
94 | #ifdef X86 | 94 | #ifdef X86 |
95 | cmd += " -f "; | 95 | cmd += " -f "; |
96 | cmd += IPKG_CONF; | 96 | cmd += IPKG_CONF; |
97 | #endif | 97 | #endif |
98 | 98 | ||
99 | 99 | ||
100 | if ( option == "reinstall" ) | 100 | if ( option == "reinstall" ) |
101 | cmd += " install"; | 101 | cmd += " install"; |
102 | else | 102 | else |
103 | cmd += " " + option; | 103 | cmd += " " + option; |
104 | if ( option != "upgrade" ) | 104 | if ( option != "upgrade" ) |
105 | cmd += " " + package; | 105 | cmd += " " + package; |
106 | cmd += " 2>&1"; | 106 | cmd += " 2>&1"; |
107 | 107 | ||
108 | 108 | ||
109 | emit outputText( QString( "Dealing with package " ) + package ); | 109 | if ( package != "" ) |
110 | emit outputText( QString( "Dealing with package " ) + package ); | ||
110 | 111 | ||
111 | qApp->processEvents(); | 112 | qApp->processEvents(); |
112 | 113 | ||
113 | // If we are removing packages and make links option is selected | 114 | // If we are removing packages and make links option is selected |
114 | // create the links | 115 | // create the links |
115 | if ( option == "remove" || option == "reinstall" ) | 116 | if ( option == "remove" || option == "reinstall" ) |
116 | { | 117 | { |
117 | createLinks = false; | 118 | createLinks = false; |
118 | if ( flags & MAKE_LINKS ) | 119 | if ( flags & MAKE_LINKS ) |
119 | { | 120 | { |
120 | emit outputText( QString( "Removing symbolic links...\n" ) ); | 121 | emit outputText( QString( "Removing symbolic links...\n" ) ); |
121 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); | 122 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); |
122 | emit outputText( QString( " " ) ); | 123 | emit outputText( QString( " " ) ); |
123 | } | 124 | } |
124 | } | 125 | } |
125 | 126 | ||
126 | emit outputText( cmd ); | 127 | emit outputText( cmd ); |
127 | 128 | ||
128 | // Execute command | 129 | // Execute command |
129 | dependantPackages = new QList<QString>; | 130 | dependantPackages = new QList<QString>; |
130 | dependantPackages->setAutoDelete( true ); | 131 | dependantPackages->setAutoDelete( true ); |
131 | 132 | ||
132 | ret = executeIpkgCommand( cmd, option ); | 133 | ret = executeIpkgCommand( cmd, option ); |
133 | 134 | ||
134 | if ( option == "install" || option == "reinstall" ) | 135 | if ( option == "install" || option == "reinstall" ) |
135 | { | 136 | { |
136 | // If we are not removing packages and make links option is selected | 137 | // If we are not removing packages and make links option is selected |
137 | // create the links | 138 | // create the links |
138 | createLinks = true; | 139 | createLinks = true; |
139 | if ( flags & MAKE_LINKS ) | 140 | if ( flags & MAKE_LINKS ) |
140 | { | 141 | { |
141 | emit outputText( " " ); | 142 | emit outputText( " " ); |
142 | emit outputText( QString( "Creating symbolic links for " )+ package ); | 143 | emit outputText( QString( "Creating symbolic links for " )+ package ); |
143 | 144 | ||
144 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); | 145 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); |
145 | 146 | ||
146 | // link dependant packages that were installed with this release | 147 | // link dependant packages that were installed with this release |
147 | QString *pkg; | 148 | QString *pkg; |
148 | for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) | 149 | for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) |
149 | { | 150 | { |
150 | if ( *pkg == package ) | 151 | if ( *pkg == package ) |
151 | continue; | 152 | continue; |
152 | emit outputText( " " ); | 153 | emit outputText( " " ); |
153 | emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); | 154 | emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); |
154 | linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); | 155 | linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); |
155 | } | 156 | } |
156 | } | 157 | } |
157 | } | 158 | } |
158 | 159 | ||
159 | delete dependantPackages; | 160 | delete dependantPackages; |
160 | 161 | ||
161 | emit outputText( QString( "Finished - status=" ) + (ret ? "success" : "failure") ); | 162 | emit outputText( QString( "Finished - status=" ) + (ret ? "success" : "failure") ); |
162 | emit outputText( "" ); | 163 | emit outputText( "" ); |
163 | return ret; | 164 | return ret; |
164 | } | 165 | } |
165 | 166 | ||
166 | 167 | ||
167 | int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) | 168 | int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) |
168 | { | 169 | { |
169 | FILE *fp = NULL; | 170 | FILE *fp = NULL; |
170 | char line[130]; | 171 | char line[130]; |
171 | QString lineStr, lineStrOld; | 172 | QString lineStr, lineStrOld; |
172 | int ret = false; | 173 | int ret = false; |
173 | 174 | ||
174 | fp = popen( (const char *) cmd, "r"); | 175 | fp = popen( (const char *) cmd, "r"); |
175 | if ( fp == NULL ) | 176 | if ( fp == NULL ) |
176 | { | 177 | { |
177 | cout << "Couldn't execute " << cmd << "! err = " << fp << endl; | 178 | cout << "Couldn't execute " << cmd << "! err = " << fp << endl; |
178 | QString text; | 179 | QString text; |
179 | text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); | 180 | text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); |
180 | emit outputText( text ); | 181 | emit outputText( text ); |
181 | } | 182 | } |
182 | else | 183 | else |
183 | { | 184 | { |
184 | while ( fgets( line, sizeof line, fp) != NULL ) | 185 | while ( fgets( line, sizeof line, fp) != NULL ) |
185 | { | 186 | { |
186 | lineStr = line; | 187 | lineStr = line; |
187 | lineStr=lineStr.left( lineStr.length()-1 ); | 188 | lineStr=lineStr.left( lineStr.length()-1 ); |
188 | 189 | ||
189 | if ( lineStr != lineStrOld ) | 190 | if ( lineStr != lineStrOld ) |
190 | { | 191 | { |
191 | //See if we're finished | 192 | //See if we're finished |
192 | if ( option == "install" || option == "reinstall" ) | 193 | if ( option == "install" || option == "reinstall" ) |
193 | { | 194 | { |
194 | // Need to keep track of any dependant packages that get installed | 195 | // Need to keep track of any dependant packages that get installed |
195 | // so that we can create links to them as necessary | 196 | // so that we can create links to them as necessary |
196 | if ( lineStr.startsWith( "Installing " ) ) | 197 | if ( lineStr.startsWith( "Installing " ) ) |
197 | { | 198 | { |
198 | cout << "LineStr = " << lineStr << endl; | 199 | cout << "LineStr = " << lineStr << endl; |
199 | int start = lineStr.find( " " ) + 1; | 200 | int start = lineStr.find( " " ) + 1; |
200 | int end = lineStr.find( " ", start ); | 201 | int end = lineStr.find( " ", start ); |
201 | QString *package = new QString( lineStr.mid( start, end-start ) ); | 202 | QString *package = new QString( lineStr.mid( start, end-start ) ); |
202 | dependantPackages->append( package ); | 203 | dependantPackages->append( package ); |
203 | cout << "installing dependant package <" << *package << ">" << endl; | 204 | cout << "installing dependant package <" << *package << ">" << endl; |
204 | } | 205 | } |
205 | } | 206 | } |
206 | 207 | ||
207 | if ( option == "update" ) | 208 | if ( option == "update" ) |
208 | { | 209 | { |
209 | if (lineStr.contains("Updated list")) | 210 | if (lineStr.contains("Updated list")) |
210 | ret = true; | 211 | ret = true; |
211 | } | 212 | } |
212 | else if ( option == "download" ) | 213 | else if ( option == "download" ) |
213 | { | 214 | { |
214 | if (lineStr.contains("Downloaded")) | 215 | if (lineStr.contains("Downloaded")) |
215 | ret = true; | 216 | ret = true; |
216 | } | 217 | } |
217 | else | 218 | else |
218 | { | 219 | { |
219 | if (lineStr.contains("Done")) | 220 | if (lineStr.contains("Done")) |
220 | ret = true; | 221 | ret = true; |
221 | } | 222 | } |
222 | 223 | ||
223 | emit outputText( lineStr ); | 224 | emit outputText( lineStr ); |
224 | } | 225 | } |
225 | lineStrOld = lineStr; | 226 | lineStrOld = lineStr; |
226 | qApp->processEvents(); | 227 | qApp->processEvents(); |
227 | } | 228 | } |
228 | pclose(fp); | 229 | pclose(fp); |
229 | } | 230 | } |
230 | 231 | ||
231 | return ret; | 232 | return ret; |
232 | } | 233 | } |
233 | 234 | ||
234 | 235 | ||
235 | void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) | 236 | void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) |
236 | { | 237 | { |
237 | if ( dest == "root" || dest == "/" ) | 238 | if ( dest == "root" || dest == "/" ) |
238 | return; | 239 | return; |
239 | 240 | ||
240 | qApp->processEvents(); | 241 | qApp->processEvents(); |
241 | QStringList *fileList = getList( packFileName, destDir ); | 242 | QStringList *fileList = getList( packFileName, destDir ); |
242 | qApp->processEvents(); | 243 | qApp->processEvents(); |
243 | processFileList( fileList, destDir ); | 244 | processFileList( fileList, destDir ); |
244 | delete fileList; | 245 | delete fileList; |
245 | } | 246 | } |
246 | 247 | ||
247 | QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) | 248 | QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) |
248 | { | 249 | { |
249 | QString packageFileDir = destDir+"/usr/lib/ipkg/info/"+packageFilename+".list"; | 250 | QString packageFileDir = destDir+"/usr/lib/ipkg/info/"+packageFilename+".list"; |
250 | QFile f( packageFileDir ); | 251 | QFile f( packageFileDir ); |
251 | 252 | ||
252 | cout << "Try to open " << packageFileDir << endl; | 253 | cout << "Try to open " << packageFileDir << endl; |
253 | if ( !f.open(IO_ReadOnly) ) | 254 | if ( !f.open(IO_ReadOnly) ) |
254 | { | 255 | { |
255 | // Couldn't open from dest, try from / | 256 | // Couldn't open from dest, try from / |
256 | cout << "Could not open:" << packageFileDir << endl; | 257 | cout << "Could not open:" << packageFileDir << endl; |
257 | f.close(); | 258 | f.close(); |
258 | 259 | ||
259 | packageFileDir = "/usr/lib/ipkg/info/"+packageFilename+".list"; | 260 | packageFileDir = "/usr/lib/ipkg/info/"+packageFilename+".list"; |
260 | f.setName( packageFileDir ); | 261 | f.setName( packageFileDir ); |
261 | // cout << "Try to open " << packageFileDir.latin1() << endl; | 262 | // cout << "Try to open " << packageFileDir.latin1() << endl; |
262 | if ( ! f.open(IO_ReadOnly) ) | 263 | if ( ! f.open(IO_ReadOnly) ) |
263 | { | 264 | { |
264 | cout << "Could not open:" << packageFileDir << endl; | 265 | cout << "Could not open:" << packageFileDir << endl; |
265 | emit outputText( QString( "Could not open :" ) + packageFileDir ); | 266 | emit outputText( QString( "Could not open :" ) + packageFileDir ); |
266 | return (QStringList*)0; | 267 | return (QStringList*)0; |
267 | } | 268 | } |
268 | } | 269 | } |
269 | QStringList *fileList = new QStringList(); | 270 | QStringList *fileList = new QStringList(); |
270 | QTextStream t( &f ); | 271 | QTextStream t( &f ); |
271 | while ( !t.eof() ) | 272 | while ( !t.eof() ) |
272 | *fileList += t.readLine(); | 273 | *fileList += t.readLine(); |
273 | 274 | ||
274 | f.close(); | 275 | f.close(); |
275 | return fileList; | 276 | return fileList; |
276 | } | 277 | } |
277 | 278 | ||
278 | void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir ) | 279 | void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir ) |
279 | { | 280 | { |
280 | if ( !fileList || fileList->isEmpty() ) | 281 | if ( !fileList || fileList->isEmpty() ) |
281 | return; | 282 | return; |
282 | 283 | ||
283 | QString baseDir = ROOT; | 284 | QString baseDir = ROOT; |
284 | 285 | ||
285 | if ( createLinks == true ) | 286 | if ( createLinks == true ) |
286 | { | 287 | { |
287 | for ( uint i=0; i < fileList->count(); i++ ) | 288 | for ( uint i=0; i < fileList->count(); i++ ) |
288 | { | 289 | { |
289 | processLinkDir( (*fileList)[i], baseDir, destDir ); | 290 | processLinkDir( (*fileList)[i], baseDir, destDir ); |
290 | qApp->processEvents(); | 291 | qApp->processEvents(); |
291 | } | 292 | } |
292 | } | 293 | } |
293 | else | 294 | else |
294 | { | 295 | { |
295 | for ( int i = fileList->count()-1; i >= 0 ; i-- ) | 296 | for ( int i = fileList->count()-1; i >= 0 ; i-- ) |
296 | { | 297 | { |
297 | processLinkDir( (*fileList)[i], baseDir, destDir ); | 298 | processLinkDir( (*fileList)[i], baseDir, destDir ); |
298 | qApp->processEvents(); | 299 | qApp->processEvents(); |
299 | } | 300 | } |
300 | } | 301 | } |
301 | } | 302 | } |
302 | 303 | ||
303 | void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) | 304 | void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) |
304 | { | 305 | { |
305 | 306 | ||
306 | QString sourceFile = baseDir + file; | 307 | QString sourceFile = baseDir + file; |
307 | 308 | ||
308 | QString linkFile = destDir; | 309 | QString linkFile = destDir; |
309 | if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" ) | 310 | if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" ) |
310 | { | 311 | { |
311 | linkFile += file.mid( 1 ); | 312 | linkFile += file.mid( 1 ); |
312 | } | 313 | } |
313 | else | 314 | else |
314 | { | 315 | { |
315 | linkFile += file; | 316 | linkFile += file; |
316 | } | 317 | } |
317 | QString text; | 318 | QString text; |
318 | if ( createLinks ) | 319 | if ( createLinks ) |
319 | { | 320 | { |
320 | // If this file is a directory (ends with a /) and it doesn't exist, | 321 | // If this file is a directory (ends with a /) and it doesn't exist, |
321 | // we need to create it | 322 | // we need to create it |
322 | if ( file.right(1) == "/" ) | 323 | if ( file.right(1) == "/" ) |
323 | { | 324 | { |
324 | QFileInfo f( linkFile ); | 325 | QFileInfo f( linkFile ); |
325 | if ( !f.exists() ) | 326 | if ( !f.exists() ) |
326 | { | 327 | { |
327 | emit outputText( QString( "Creating directory " ) + linkFile ); | 328 | emit outputText( QString( "Creating directory " ) + linkFile ); |
328 | QDir d; | 329 | QDir d; |
329 | d.mkdir( linkFile, true ); | 330 | d.mkdir( linkFile, true ); |
330 | } | 331 | } |
331 | else | 332 | else |
332 | emit outputText( QString( "Directory " ) + linkFile + " exists" ); | 333 | emit outputText( QString( "Directory " ) + linkFile + " exists" ); |
333 | 334 | ||
334 | } | 335 | } |
335 | else | 336 | else |
336 | { | 337 | { |
337 | int rc = symlink( sourceFile, linkFile ); | 338 | int rc = symlink( sourceFile, linkFile ); |
338 | text = (rc == 0 ? "Linked " : "Failed to link "); | 339 | text = (rc == 0 ? "Linked " : "Failed to link "); |
339 | text += sourceFile + " to " + linkFile; | 340 | text += sourceFile + " to " + linkFile; |
340 | emit outputText( text ); | 341 | emit outputText( text ); |
341 | } | 342 | } |
342 | } | 343 | } |
343 | else | 344 | else |
344 | { | 345 | { |
345 | QFileInfo f( linkFile ); | 346 | QFileInfo f( linkFile ); |
346 | if ( f.exists() ) | 347 | if ( f.exists() ) |
347 | { | 348 | { |
348 | if ( f.isFile() ) | 349 | if ( f.isFile() ) |
349 | { | 350 | { |
350 | QFile f( linkFile ); | 351 | QFile f( linkFile ); |
351 | bool rc = f.remove(); | 352 | bool rc = f.remove(); |
352 | 353 | ||
353 | text = (rc ? "Removed " : "Failed to remove "); | 354 | text = (rc ? "Removed " : "Failed to remove "); |
354 | text += linkFile; | 355 | text += linkFile; |
355 | emit outputText( text ); | 356 | emit outputText( text ); |
356 | } | 357 | } |
357 | else if ( f.isDir() ) | 358 | else if ( f.isDir() ) |
358 | { | 359 | { |
359 | QDir d; | 360 | QDir d; |
360 | bool rc = d.rmdir( linkFile, true ); | 361 | bool rc = d.rmdir( linkFile, true ); |
361 | text = (rc ? "Removed " : "Failed to remove "); | 362 | text = (rc ? "Removed " : "Failed to remove "); |
362 | text += linkFile; | 363 | text += linkFile; |
363 | emit outputText( text ); | 364 | emit outputText( text ); |
364 | } | 365 | } |
365 | } | 366 | } |
366 | } | 367 | } |
367 | 368 | ||
368 | } | 369 | } |
diff --git a/noncore/settings/aqpkg/networkpkgmgr.cpp b/noncore/settings/aqpkg/networkpkgmgr.cpp index 52d95a8..6874ded 100644 --- a/noncore/settings/aqpkg/networkpkgmgr.cpp +++ b/noncore/settings/aqpkg/networkpkgmgr.cpp | |||
@@ -1,578 +1,579 @@ | |||
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 | 43 | ||
44 | #include "global.h" | 44 | #include "global.h" |
45 | 45 | ||
46 | NetworkPackageManager::NetworkPackageManager( DataManager *dataManager, QWidget *parent, const char *name) | 46 | NetworkPackageManager::NetworkPackageManager( DataManager *dataManager, QWidget *parent, const char *name) |
47 | : QWidget(parent, name) | 47 | : QWidget(parent, name) |
48 | { | 48 | { |
49 | dataMgr = dataManager; | 49 | dataMgr = dataManager; |
50 | 50 | ||
51 | #ifdef QWS | 51 | #ifdef QWS |
52 | // read download directory from config file | 52 | // read download directory from config file |
53 | Config cfg( "aqpkg" ); | 53 | Config cfg( "aqpkg" ); |
54 | cfg.setGroup( "settings" ); | 54 | cfg.setGroup( "settings" ); |
55 | currentlySelectedServer = cfg.readEntry( "selectedServer", "local" ); | 55 | currentlySelectedServer = cfg.readEntry( "selectedServer", "local" ); |
56 | showJumpTo = cfg.readBoolEntry( "showJumpTo", "true" ); | 56 | showJumpTo = cfg.readBoolEntry( "showJumpTo", "true" ); |
57 | #endif | 57 | #endif |
58 | 58 | ||
59 | 59 | ||
60 | initGui(); | 60 | initGui(); |
61 | setupConnections(); | 61 | setupConnections(); |
62 | 62 | ||
63 | progressDlg = 0; | 63 | progressDlg = 0; |
64 | timerId = startTimer( 100 ); | 64 | timerId = startTimer( 100 ); |
65 | } | 65 | } |
66 | 66 | ||
67 | NetworkPackageManager::~NetworkPackageManager() | 67 | NetworkPackageManager::~NetworkPackageManager() |
68 | { | 68 | { |
69 | } | 69 | } |
70 | 70 | ||
71 | void NetworkPackageManager :: timerEvent ( QTimerEvent * ) | 71 | void NetworkPackageManager :: timerEvent ( QTimerEvent * ) |
72 | { | 72 | { |
73 | killTimer( timerId ); | 73 | killTimer( timerId ); |
74 | 74 | ||
75 | // showProgressDialog(); | 75 | // showProgressDialog(); |
76 | // Add server names to listbox | 76 | // Add server names to listbox |
77 | updateData(); | 77 | updateData(); |
78 | 78 | ||
79 | // progressDlg->hide(); | 79 | // progressDlg->hide(); |
80 | } | 80 | } |
81 | 81 | ||
82 | void NetworkPackageManager :: updateData() | 82 | void NetworkPackageManager :: updateData() |
83 | { | 83 | { |
84 | serversList->clear(); | 84 | serversList->clear(); |
85 | packagesList->clear(); | 85 | packagesList->clear(); |
86 | 86 | ||
87 | 87 | ||
88 | vector<Server>::iterator it; | 88 | vector<Server>::iterator it; |
89 | int activeItem = -1; | 89 | int activeItem = -1; |
90 | int i; | 90 | int i; |
91 | for ( i = 0, it = dataMgr->getServerList().begin() ; it != dataMgr->getServerList().end() ; ++it, ++i ) | 91 | for ( i = 0, it = dataMgr->getServerList().begin() ; it != dataMgr->getServerList().end() ; ++it, ++i ) |
92 | { | 92 | { |
93 | if ( !it->isServerActive() ) | 93 | if ( !it->isServerActive() ) |
94 | { | 94 | { |
95 | i--; | 95 | i--; |
96 | continue; | 96 | continue; |
97 | } | 97 | } |
98 | serversList->insertItem( it->getServerName() ); | 98 | serversList->insertItem( it->getServerName() ); |
99 | if ( it->getServerName() == currentlySelectedServer ) | 99 | if ( it->getServerName() == currentlySelectedServer ) |
100 | activeItem = i; | 100 | activeItem = i; |
101 | } | 101 | } |
102 | 102 | ||
103 | // set selected server to be active server | 103 | // set selected server to be active server |
104 | if ( activeItem != -1 ) | 104 | if ( activeItem != -1 ) |
105 | serversList->setCurrentItem( activeItem ); | 105 | serversList->setCurrentItem( activeItem ); |
106 | serverSelected( 0 ); | 106 | serverSelected( 0 ); |
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
110 | void NetworkPackageManager :: initGui() | 110 | void NetworkPackageManager :: initGui() |
111 | { | 111 | { |
112 | QLabel *l = new QLabel( "Servers", this ); | 112 | QLabel *l = new QLabel( "Servers", this ); |
113 | serversList = new QComboBox( this ); | 113 | serversList = new QComboBox( this ); |
114 | packagesList = new QListView( this ); | 114 | packagesList = new QListView( this ); |
115 | update = new QPushButton( "Refresh List", this ); | 115 | update = new QPushButton( "Refresh List", this ); |
116 | download = new QPushButton( "Download", this ); | 116 | download = new QPushButton( "Download", this ); |
117 | upgrade = new QPushButton( "Upgrade", this ); | 117 | upgrade = new QPushButton( "Upgrade", this ); |
118 | apply = new QPushButton( "Apply", this ); | 118 | apply = new QPushButton( "Apply", this ); |
119 | 119 | ||
120 | QVBoxLayout *vbox = new QVBoxLayout( this, 0, -1, "VBox" ); | 120 | QVBoxLayout *vbox = new QVBoxLayout( this, 0, -1, "VBox" ); |
121 | QHBoxLayout *hbox1 = new QHBoxLayout( vbox, -1, "HBox1" ); | 121 | QHBoxLayout *hbox1 = new QHBoxLayout( vbox, -1, "HBox1" ); |
122 | hbox1->addWidget( l ); | 122 | hbox1->addWidget( l ); |
123 | hbox1->addWidget( serversList ); | 123 | hbox1->addWidget( serversList ); |
124 | 124 | ||
125 | QHBoxLayout *hbox3 = new QHBoxLayout( vbox, -1, "HBox1" ); | 125 | QHBoxLayout *hbox3 = new QHBoxLayout( vbox, -1, "HBox1" ); |
126 | QHBoxLayout *hbox4 = new QHBoxLayout( vbox, -1, "HBox1" ); | 126 | QHBoxLayout *hbox4 = new QHBoxLayout( vbox, -1, "HBox1" ); |
127 | 127 | ||
128 | 128 | ||
129 | if ( showJumpTo ) | 129 | if ( showJumpTo ) |
130 | { | 130 | { |
131 | char text[2]; | 131 | char text[2]; |
132 | text[1] = '\0'; | 132 | text[1] = '\0'; |
133 | for ( int i = 0 ; i < 26 ; ++i ) | 133 | for ( int i = 0 ; i < 26 ; ++i ) |
134 | { | 134 | { |
135 | text[0] = 'A' + i; | 135 | text[0] = 'A' + i; |
136 | LetterPushButton *b = new LetterPushButton( text, this ); | 136 | LetterPushButton *b = new LetterPushButton( text, this ); |
137 | connect( b, SIGNAL( released( QString ) ), this, SLOT( letterPushed( QString ) ) ); | 137 | connect( b, SIGNAL( released( QString ) ), this, SLOT( letterPushed( QString ) ) ); |
138 | if ( i < 13 ) | 138 | if ( i < 13 ) |
139 | hbox3->addWidget( b ); | 139 | hbox3->addWidget( b ); |
140 | else | 140 | else |
141 | hbox4->addWidget( b ); | 141 | hbox4->addWidget( b ); |
142 | } | 142 | } |
143 | } | 143 | } |
144 | 144 | ||
145 | vbox->addWidget( packagesList ); | 145 | vbox->addWidget( packagesList ); |
146 | packagesList->addColumn( "Packages" ); | 146 | packagesList->addColumn( "Packages" ); |
147 | 147 | ||
148 | QHBoxLayout *hbox2 = new QHBoxLayout( vbox, -1, "HBox2" ); | 148 | QHBoxLayout *hbox2 = new QHBoxLayout( vbox, -1, "HBox2" ); |
149 | hbox2->addWidget( update ); | 149 | hbox2->addWidget( update ); |
150 | hbox2->addWidget( download ); | 150 | hbox2->addWidget( download ); |
151 | hbox2->addWidget( upgrade ); | 151 | hbox2->addWidget( upgrade ); |
152 | hbox2->addWidget( apply ); | 152 | hbox2->addWidget( apply ); |
153 | } | 153 | } |
154 | 154 | ||
155 | void NetworkPackageManager :: setupConnections() | 155 | void NetworkPackageManager :: setupConnections() |
156 | { | 156 | { |
157 | connect( serversList, SIGNAL(activated( int )), this, SLOT(serverSelected( int ))); | 157 | connect( serversList, SIGNAL(activated( int )), this, SLOT(serverSelected( int ))); |
158 | connect( apply, SIGNAL(released()), this, SLOT(applyChanges()) ); | 158 | connect( apply, SIGNAL(released()), this, SLOT(applyChanges()) ); |
159 | connect( download, SIGNAL(released()), this, SLOT(downloadPackage()) ); | 159 | connect( download, SIGNAL(released()), this, SLOT(downloadPackage()) ); |
160 | connect( upgrade, SIGNAL( released()), this, SLOT(upgradePackages()) ); | 160 | connect( upgrade, SIGNAL( released()), this, SLOT(upgradePackages()) ); |
161 | connect( update, SIGNAL(released()), this, SLOT(updateServer()) ); | 161 | connect( update, SIGNAL(released()), this, SLOT(updateServer()) ); |
162 | } | 162 | } |
163 | 163 | ||
164 | void NetworkPackageManager :: showProgressDialog( char *initialText ) | 164 | void NetworkPackageManager :: showProgressDialog( char *initialText ) |
165 | { | 165 | { |
166 | if ( !progressDlg ) | 166 | if ( !progressDlg ) |
167 | progressDlg = new ProgressDlg( this, "Progress", false ); | 167 | progressDlg = new ProgressDlg( this, "Progress", false ); |
168 | progressDlg->setText( initialText ); | 168 | progressDlg->setText( initialText ); |
169 | progressDlg->show(); | 169 | progressDlg->show(); |
170 | } | 170 | } |
171 | 171 | ||
172 | 172 | ||
173 | void NetworkPackageManager :: serverSelected( int ) | 173 | void NetworkPackageManager :: serverSelected( int ) |
174 | { | 174 | { |
175 | packagesList->clear(); | 175 | packagesList->clear(); |
176 | 176 | ||
177 | // display packages | 177 | // display packages |
178 | QString serverName = serversList->currentText(); | 178 | QString serverName = serversList->currentText(); |
179 | currentlySelectedServer = serverName; | 179 | currentlySelectedServer = serverName; |
180 | 180 | ||
181 | #ifdef QWS | 181 | #ifdef QWS |
182 | // read download directory from config file | 182 | // read download directory from config file |
183 | Config cfg( "aqpkg" ); | 183 | Config cfg( "aqpkg" ); |
184 | cfg.setGroup( "settings" ); | 184 | cfg.setGroup( "settings" ); |
185 | cfg.writeEntry( "selectedServer", currentlySelectedServer ); | 185 | cfg.writeEntry( "selectedServer", currentlySelectedServer ); |
186 | #endif | 186 | #endif |
187 | 187 | ||
188 | Server *s = dataMgr->getServer( serverName ); | 188 | Server *s = dataMgr->getServer( serverName ); |
189 | // dataMgr->setActiveServer( serverName ); | 189 | // dataMgr->setActiveServer( serverName ); |
190 | 190 | ||
191 | vector<Package> &list = s->getPackageList(); | 191 | vector<Package> &list = s->getPackageList(); |
192 | vector<Package>::iterator it; | 192 | vector<Package>::iterator it; |
193 | for ( it = list.begin() ; it != list.end() ; ++it ) | 193 | for ( it = list.begin() ; it != list.end() ; ++it ) |
194 | { | 194 | { |
195 | QString text = ""; | 195 | QString text = ""; |
196 | 196 | ||
197 | // If the local server, only display installed packages | 197 | // If the local server, only display installed packages |
198 | if ( serverName == LOCAL_SERVER && !it->isInstalled() ) | 198 | if ( serverName == LOCAL_SERVER && !it->isInstalled() ) |
199 | continue; | 199 | continue; |
200 | 200 | ||
201 | text += it->getPackageName(); | 201 | text += it->getPackageName(); |
202 | if ( it->isInstalled() ) | 202 | if ( it->isInstalled() ) |
203 | { | 203 | { |
204 | text += " (installed)"; | 204 | text += " (installed)"; |
205 | 205 | ||
206 | // If a different version of package is available, postfix it with an * | 206 | // If a different version of package is available, postfix it with an * |
207 | if ( it->getVersion() != it->getInstalledVersion() ) | 207 | if ( it->getVersion() != it->getInstalledVersion() ) |
208 | text += "*"; | 208 | text += "*"; |
209 | } | 209 | } |
210 | 210 | ||
211 | QCheckListItem *item = new QCheckListItem( packagesList, text, QCheckListItem::CheckBox ); | 211 | QCheckListItem *item = new QCheckListItem( packagesList, text, QCheckListItem::CheckBox ); |
212 | 212 | ||
213 | if ( it->isInstalled() ) | 213 | if ( it->isInstalled() ) |
214 | { | 214 | { |
215 | QString destName = ""; | 215 | QString destName = ""; |
216 | if ( it->getLocalPackage() ) | 216 | if ( it->getLocalPackage() ) |
217 | { | 217 | { |
218 | if ( it->getLocalPackage()->getInstalledTo() ) | 218 | if ( it->getLocalPackage()->getInstalledTo() ) |
219 | destName = it->getLocalPackage()->getInstalledTo()->getDestinationName(); | 219 | destName = it->getLocalPackage()->getInstalledTo()->getDestinationName(); |
220 | } | 220 | } |
221 | else | 221 | else |
222 | { | 222 | { |
223 | if ( it->getInstalledTo() ) | 223 | if ( it->getInstalledTo() ) |
224 | destName = it->getInstalledTo()->getDestinationName(); | 224 | destName = it->getInstalledTo()->getDestinationName(); |
225 | } | 225 | } |
226 | if ( destName != "" ) | 226 | if ( destName != "" ) |
227 | new QCheckListItem( item, QString( "Installed To - " ) + destName ); | 227 | new QCheckListItem( item, QString( "Installed To - " ) + destName ); |
228 | } | 228 | } |
229 | 229 | ||
230 | if ( !it->isPackageStoredLocally() ) | 230 | if ( !it->isPackageStoredLocally() ) |
231 | new QCheckListItem( item, QString( "Description - " ) + it->getDescription() ); | 231 | new QCheckListItem( item, QString( "Description - " ) + it->getDescription() ); |
232 | else | 232 | else |
233 | new QCheckListItem( item, QString( "Filename - " ) + it->getFilename() ); | 233 | new QCheckListItem( item, QString( "Filename - " ) + it->getFilename() ); |
234 | 234 | ||
235 | new QCheckListItem( item, QString( "V. Available - " ) + it->getVersion() ); | 235 | new QCheckListItem( item, QString( "V. Available - " ) + it->getVersion() ); |
236 | if ( it->getLocalPackage() ) | 236 | if ( it->getLocalPackage() ) |
237 | { | 237 | { |
238 | if ( it->isInstalled() ) | 238 | if ( it->isInstalled() ) |
239 | new QCheckListItem( item, QString( "V. Installed - " ) + it->getInstalledVersion() ); | 239 | new QCheckListItem( item, QString( "V. Installed - " ) + it->getInstalledVersion() ); |
240 | } | 240 | } |
241 | packagesList->insertItem( item ); | 241 | packagesList->insertItem( item ); |
242 | } | 242 | } |
243 | 243 | ||
244 | // If the local server or the local ipkgs server disable the download button | 244 | // If the local server or the local ipkgs server disable the download button |
245 | if ( serverName == LOCAL_SERVER ) | 245 | if ( serverName == LOCAL_SERVER ) |
246 | { | 246 | { |
247 | upgrade->setEnabled( false ); | 247 | upgrade->setEnabled( false ); |
248 | download->setText( "Download" ); | 248 | download->setText( "Download" ); |
249 | download->setEnabled( false ); | 249 | download->setEnabled( false ); |
250 | } | 250 | } |
251 | else if ( serverName == LOCAL_IPKGS ) | 251 | else if ( serverName == LOCAL_IPKGS ) |
252 | { | 252 | { |
253 | upgrade->setEnabled( false ); | 253 | upgrade->setEnabled( false ); |
254 | download->setEnabled( true ); | 254 | download->setEnabled( true ); |
255 | download->setText( "Remove" ); | 255 | download->setText( "Remove" ); |
256 | } | 256 | } |
257 | else | 257 | else |
258 | { | 258 | { |
259 | upgrade->setEnabled( true ); | 259 | upgrade->setEnabled( true ); |
260 | download->setEnabled( true ); | 260 | download->setEnabled( true ); |
261 | download->setText( "Download" ); | 261 | download->setText( "Download" ); |
262 | } | 262 | } |
263 | } | 263 | } |
264 | 264 | ||
265 | void NetworkPackageManager :: updateServer() | 265 | void NetworkPackageManager :: updateServer() |
266 | { | 266 | { |
267 | QString serverName = serversList->currentText(); | 267 | QString serverName = serversList->currentText(); |
268 | 268 | ||
269 | // Update the current server | 269 | // Update the current server |
270 | // Display dialog | 270 | // Display dialog |
271 | ProgressDlg *dlg = new ProgressDlg( this ); | 271 | // ProgressDlg *progDlg = new ProgressDlg( this ); |
272 | QString status = "Updating package lists..."; | 272 | // QString status = "Updating package lists..."; |
273 | dlg->show(); | 273 | // progDlg->show(); |
274 | dlg->setText( status ); | 274 | // progDlg->setText( status ); |
275 | 275 | ||
276 | // Disable buttons to stop silly people clicking lots on them :) | 276 | // Disable buttons to stop silly people clicking lots on them :) |
277 | 277 | ||
278 | // First, write out ipkg_conf file so that ipkg can use it | 278 | // First, write out ipkg_conf file so that ipkg can use it |
279 | dataMgr->writeOutIpkgConf(); | 279 | dataMgr->writeOutIpkgConf(); |
280 | 280 | ||
281 | QString option = "update"; | ||
282 | QString dummy = ""; | ||
283 | Ipkg ipkg; | 281 | Ipkg ipkg; |
284 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); | 282 | ipkg.setOption( "update" ); |
285 | ipkg.setOption( option ); | ||
286 | 283 | ||
287 | ipkg.runIpkg( ); | 284 | InstallDlgImpl dlg( &ipkg, "Refreshing server package lists", this, "Upgrade", true ); |
285 | dlg.showDlg(); | ||
288 | 286 | ||
289 | // Reload data | 287 | // Reload data |
290 | dataMgr->reloadServerData( serversList->currentText() ); | 288 | dataMgr->reloadServerData( serversList->currentText() ); |
291 | serverSelected(-1); | 289 | serverSelected(-1); |
292 | delete dlg; | 290 | // delete progDlg; |
293 | } | 291 | } |
294 | 292 | ||
295 | void NetworkPackageManager :: upgradePackages() | 293 | void NetworkPackageManager :: upgradePackages() |
296 | { | 294 | { |
297 | // We're gonna do an upgrade of all packages | 295 | // We're gonna do an upgrade of all packages |
298 | // First warn user that this isn't recommended | 296 | // First warn user that this isn't recommended |
299 | QString text = "WARNING: Upgrading while\nOpie/Qtopia is running\nis NOT recommended!\n\nAre you sure?\n"; | 297 | QString text = "WARNING: Upgrading while\nOpie/Qtopia is running\nis NOT recommended!\n\nAre you sure?\n"; |
300 | QMessageBox warn("Warning", text, QMessageBox::Warning, | 298 | QMessageBox warn("Warning", text, QMessageBox::Warning, |
301 | QMessageBox::Yes, | 299 | QMessageBox::Yes, |
302 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default , | 300 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default , |
303 | 0, this ); | 301 | 0, this ); |
304 | warn.adjustSize(); | 302 | warn.adjustSize(); |
305 | 303 | ||
306 | if ( warn.exec() == QMessageBox::Yes ) | 304 | if ( warn.exec() == QMessageBox::Yes ) |
307 | { | 305 | { |
308 | // First, write out ipkg_conf file so that ipkg can use it | 306 | // First, write out ipkg_conf file so that ipkg can use it |
309 | dataMgr->writeOutIpkgConf(); | 307 | dataMgr->writeOutIpkgConf(); |
310 | 308 | ||
311 | // Now run upgrade | 309 | // Now run upgrade |
312 | InstallDlgImpl dlg( this, "Upgrade", true ); | 310 | Ipkg ipkg; |
311 | ipkg.setOption( "upgrade" ); | ||
312 | |||
313 | InstallDlgImpl dlg( &ipkg, "Upgrading installed packages", this, "Upgrade", true ); | ||
313 | dlg.showDlg(); | 314 | dlg.showDlg(); |
314 | 315 | ||
315 | // Reload data | 316 | // Reload data |
316 | dataMgr->reloadServerData( LOCAL_SERVER ); | 317 | dataMgr->reloadServerData( LOCAL_SERVER ); |
317 | 318 | ||
318 | dataMgr->reloadServerData( serversList->currentText() ); | 319 | dataMgr->reloadServerData( serversList->currentText() ); |
319 | serverSelected(-1); | 320 | serverSelected(-1); |
320 | } | 321 | } |
321 | } | 322 | } |
322 | 323 | ||
323 | 324 | ||
324 | void NetworkPackageManager :: downloadPackage() | 325 | void NetworkPackageManager :: downloadPackage() |
325 | { | 326 | { |
326 | if ( download->text() == "Download" ) | 327 | if ( download->text() == "Download" ) |
327 | { | 328 | { |
328 | // First, write out ipkg_conf file so that ipkg can use it | 329 | // First, write out ipkg_conf file so that ipkg can use it |
329 | dataMgr->writeOutIpkgConf(); | 330 | dataMgr->writeOutIpkgConf(); |
330 | 331 | ||
331 | // Display dialog to user asking where to download the files to | 332 | // Display dialog to user asking where to download the files to |
332 | bool ok = FALSE; | 333 | bool ok = FALSE; |
333 | QString dir = ""; | 334 | QString dir = ""; |
334 | #ifdef QWS | 335 | #ifdef QWS |
335 | // read download directory from config file | 336 | // read download directory from config file |
336 | Config cfg( "aqpkg" ); | 337 | Config cfg( "aqpkg" ); |
337 | cfg.setGroup( "settings" ); | 338 | cfg.setGroup( "settings" ); |
338 | dir = cfg.readEntry( "downloadDir", "/home/root/Documents/application/ipkg" ); | 339 | dir = cfg.readEntry( "downloadDir", "/home/root/Documents/application/ipkg" ); |
339 | #endif | 340 | #endif |
340 | 341 | ||
341 | QString text = InputDialog::getText( tr( "Download to where" ), tr( "Enter path to download to" ), dir, &ok, this ); | 342 | QString text = InputDialog::getText( tr( "Download to where" ), tr( "Enter path to download to" ), dir, &ok, this ); |
342 | if ( ok && !text.isEmpty() ) | 343 | if ( ok && !text.isEmpty() ) |
343 | dir = text; // user entered something and pressed ok | 344 | dir = text; // user entered something and pressed ok |
344 | else | 345 | else |
345 | return; // user entered nothing or pressed cancel | 346 | return; // user entered nothing or pressed cancel |
346 | 347 | ||
347 | #ifdef QWS | 348 | #ifdef QWS |
348 | // Store download directory in config file | 349 | // Store download directory in config file |
349 | cfg.writeEntry( "downloadDir", dir ); | 350 | cfg.writeEntry( "downloadDir", dir ); |
350 | #endif | 351 | #endif |
351 | 352 | ||
352 | // Get starting directory | 353 | // Get starting directory |
353 | char initDir[PATH_MAX]; | 354 | char initDir[PATH_MAX]; |
354 | getcwd( initDir, PATH_MAX ); | 355 | getcwd( initDir, PATH_MAX ); |
355 | 356 | ||
356 | // Download each package | 357 | // Download each package |
357 | Ipkg ipkg; | 358 | Ipkg ipkg; |
358 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); | 359 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); |
359 | 360 | ||
360 | ipkg.setOption( "download" ); | 361 | ipkg.setOption( "download" ); |
361 | ipkg.setRuntimeDirectory( dir ); | 362 | ipkg.setRuntimeDirectory( dir ); |
362 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | 363 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); |
363 | item != 0 ; | 364 | item != 0 ; |
364 | item = (QCheckListItem *)item->nextSibling() ) | 365 | item = (QCheckListItem *)item->nextSibling() ) |
365 | { | 366 | { |
366 | if ( item->isOn() ) | 367 | if ( item->isOn() ) |
367 | { | 368 | { |
368 | QString name = item->text(); | 369 | QString name = item->text(); |
369 | int pos = name.find( "*" ); | 370 | int pos = name.find( "*" ); |
370 | name.truncate( pos ); | 371 | name.truncate( pos ); |
371 | 372 | ||
372 | // if (there is a (installed), remove it | 373 | // if (there is a (installed), remove it |
373 | pos = name.find( "(installed)" ); | 374 | pos = name.find( "(installed)" ); |
374 | if ( pos > 0 ) | 375 | if ( pos > 0 ) |
375 | name.truncate( pos - 1 ); | 376 | name.truncate( pos - 1 ); |
376 | 377 | ||
377 | ipkg.setPackage( name ); | 378 | ipkg.setPackage( name ); |
378 | ipkg.runIpkg( ); | 379 | ipkg.runIpkg( ); |
379 | } | 380 | } |
380 | } | 381 | } |
381 | } | 382 | } |
382 | else if ( download->text() == "Remove" ) | 383 | else if ( download->text() == "Remove" ) |
383 | { | 384 | { |
384 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | 385 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); |
385 | item != 0 ; | 386 | item != 0 ; |
386 | item = (QCheckListItem *)item->nextSibling() ) | 387 | item = (QCheckListItem *)item->nextSibling() ) |
387 | { | 388 | { |
388 | if ( item->isOn() ) | 389 | if ( item->isOn() ) |
389 | { | 390 | { |
390 | QString name = item->text(); | 391 | QString name = item->text(); |
391 | int pos = name.find( "*" ); | 392 | int pos = name.find( "*" ); |
392 | name.truncate( pos ); | 393 | name.truncate( pos ); |
393 | 394 | ||
394 | // if (there is a (installed), remove it | 395 | // if (there is a (installed), remove it |
395 | pos = name.find( "(installed)" ); | 396 | pos = name.find( "(installed)" ); |
396 | if ( pos > 0 ) | 397 | if ( pos > 0 ) |
397 | name.truncate( pos - 1 ); | 398 | name.truncate( pos - 1 ); |
398 | 399 | ||
399 | Package *p = dataMgr->getServer( serversList->currentText() )->getPackage( name ); | 400 | Package *p = dataMgr->getServer( serversList->currentText() )->getPackage( name ); |
400 | QFile f( p->getFilename() ); | 401 | QFile f( p->getFilename() ); |
401 | f.remove(); | 402 | f.remove(); |
402 | } | 403 | } |
403 | } | 404 | } |
404 | } | 405 | } |
405 | 406 | ||
406 | dataMgr->reloadServerData( LOCAL_IPKGS ); | 407 | dataMgr->reloadServerData( LOCAL_IPKGS ); |
407 | serverSelected( -1 ); | 408 | serverSelected( -1 ); |
408 | } | 409 | } |
409 | 410 | ||
410 | 411 | ||
411 | void NetworkPackageManager :: applyChanges() | 412 | void NetworkPackageManager :: applyChanges() |
412 | { | 413 | { |
413 | stickyOption = ""; | 414 | stickyOption = ""; |
414 | 415 | ||
415 | // First, write out ipkg_conf file so that ipkg can use it | 416 | // First, write out ipkg_conf file so that ipkg can use it |
416 | dataMgr->writeOutIpkgConf(); | 417 | dataMgr->writeOutIpkgConf(); |
417 | 418 | ||
418 | // Now for each selected item | 419 | // Now for each selected item |
419 | // deal with it | 420 | // deal with it |
420 | 421 | ||
421 | vector<InstallData> workingPackages; | 422 | vector<InstallData> workingPackages; |
422 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | 423 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); |
423 | item != 0 ; | 424 | item != 0 ; |
424 | item = (QCheckListItem *)item->nextSibling() ) | 425 | item = (QCheckListItem *)item->nextSibling() ) |
425 | { | 426 | { |
426 | if ( item->isOn() ) | 427 | if ( item->isOn() ) |
427 | { | 428 | { |
428 | InstallData data = dealWithItem( item ); | 429 | InstallData data = dealWithItem( item ); |
429 | workingPackages.push_back( data ); | 430 | workingPackages.push_back( data ); |
430 | } | 431 | } |
431 | } | 432 | } |
432 | 433 | ||
433 | if ( workingPackages.size() == 0 ) | 434 | if ( workingPackages.size() == 0 ) |
434 | { | 435 | { |
435 | // Nothing to do | 436 | // Nothing to do |
436 | QMessageBox::information( this, "Nothing to do", | 437 | QMessageBox::information( this, "Nothing to do", |
437 | "No packages selected", "OK" ); | 438 | "No packages selected", "OK" ); |
438 | 439 | ||
439 | return; | 440 | return; |
440 | } | 441 | } |
441 | 442 | ||
442 | // do the stuff | 443 | // do the stuff |
443 | InstallDlgImpl dlg( workingPackages, dataMgr, this, "Install", true ); | 444 | InstallDlgImpl dlg( workingPackages, dataMgr, this, "Install", true ); |
444 | dlg.showDlg(); | 445 | dlg.showDlg(); |
445 | 446 | ||
446 | // Reload data | 447 | // Reload data |
447 | dataMgr->reloadServerData( LOCAL_SERVER ); | 448 | dataMgr->reloadServerData( LOCAL_SERVER ); |
448 | 449 | ||
449 | dataMgr->reloadServerData( serversList->currentText() ); | 450 | dataMgr->reloadServerData( serversList->currentText() ); |
450 | serverSelected(-1); | 451 | serverSelected(-1); |
451 | 452 | ||
452 | #ifdef QWS | 453 | #ifdef QWS |
453 | // Finally let the main system update itself | 454 | // Finally let the main system update itself |
454 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 455 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
455 | QString lf = QString::null; | 456 | QString lf = QString::null; |
456 | e << lf; | 457 | e << lf; |
457 | #endif | 458 | #endif |
458 | } | 459 | } |
459 | 460 | ||
460 | // decide what to do - either remove, upgrade or install | 461 | // decide what to do - either remove, upgrade or install |
461 | // Current rules: | 462 | // Current rules: |
462 | // If not installed - install | 463 | // If not installed - install |
463 | // If installed and different version available - upgrade | 464 | // If installed and different version available - upgrade |
464 | // If installed and version up to date - remove | 465 | // If installed and version up to date - remove |
465 | InstallData NetworkPackageManager :: dealWithItem( QCheckListItem *item ) | 466 | InstallData NetworkPackageManager :: dealWithItem( QCheckListItem *item ) |
466 | { | 467 | { |
467 | QString name = item->text(); | 468 | QString name = item->text(); |
468 | int pos = name.find( "*" ); | 469 | int pos = name.find( "*" ); |
469 | name.truncate( pos ); | 470 | name.truncate( pos ); |
470 | 471 | ||
471 | // if (there is a (installed), remove it | 472 | // if (there is a (installed), remove it |
472 | pos = name.find( "(installed)" ); | 473 | pos = name.find( "(installed)" ); |
473 | if ( pos > 0 ) | 474 | if ( pos > 0 ) |
474 | name.truncate( pos - 1 ); | 475 | name.truncate( pos - 1 ); |
475 | 476 | ||
476 | // Get package | 477 | // Get package |
477 | Server *s = dataMgr->getServer( serversList->currentText() ); | 478 | Server *s = dataMgr->getServer( serversList->currentText() ); |
478 | Package *p = s->getPackage( name ); | 479 | Package *p = s->getPackage( name ); |
479 | 480 | ||
480 | // If the package has a filename then it is a local file | 481 | // If the package has a filename then it is a local file |
481 | if ( p->isPackageStoredLocally() ) | 482 | if ( p->isPackageStoredLocally() ) |
482 | name = p->getFilename(); | 483 | name = p->getFilename(); |
483 | QString option; | 484 | QString option; |
484 | QString dest = "root"; | 485 | QString dest = "root"; |
485 | if ( !p->isInstalled() ) | 486 | if ( !p->isInstalled() ) |
486 | { | 487 | { |
487 | InstallData item; | 488 | InstallData item; |
488 | item.option = "I"; | 489 | item.option = "I"; |
489 | item.packageName = name; | 490 | item.packageName = name; |
490 | return item; | 491 | return item; |
491 | } | 492 | } |
492 | else | 493 | else |
493 | { | 494 | { |
494 | InstallData item; | 495 | InstallData item; |
495 | item.option = "D"; | 496 | item.option = "D"; |
496 | item.packageName = p->getInstalledPackageName(); | 497 | item.packageName = p->getInstalledPackageName(); |
497 | if ( p->getInstalledTo() ) | 498 | if ( p->getInstalledTo() ) |
498 | { | 499 | { |
499 | item.destination = p->getInstalledTo(); | 500 | item.destination = p->getInstalledTo(); |
500 | cout << "dest - " << p->getInstalledTo()->getDestinationName() << endl; | 501 | cout << "dest - " << p->getInstalledTo()->getDestinationName() << endl; |
501 | cout << "dest - " << p->getInstalledTo()->getDestinationPath() << endl; | 502 | cout << "dest - " << p->getInstalledTo()->getDestinationPath() << endl; |
502 | } | 503 | } |
503 | else | 504 | else |
504 | { | 505 | { |
505 | item.destination = p->getLocalPackage()->getInstalledTo(); | 506 | item.destination = p->getLocalPackage()->getInstalledTo(); |
506 | } | 507 | } |
507 | 508 | ||
508 | // Sticky option not implemented yet, but will eventually allow | 509 | // Sticky option not implemented yet, but will eventually allow |
509 | // the user to say something like 'remove all' | 510 | // the user to say something like 'remove all' |
510 | if ( stickyOption == "" ) | 511 | if ( stickyOption == "" ) |
511 | { | 512 | { |
512 | QString msgtext; | 513 | QString msgtext; |
513 | msgtext.sprintf( "Do you wish to remove or reinstall\n%s?", (const char *)name ); | 514 | msgtext.sprintf( "Do you wish to remove or reinstall\n%s?", (const char *)name ); |
514 | switch( QMessageBox::information( this, "Remove or ReInstall", | 515 | switch( QMessageBox::information( this, "Remove or ReInstall", |
515 | msgtext, "Remove", "ReInstall" ) ) | 516 | msgtext, "Remove", "ReInstall" ) ) |
516 | { | 517 | { |
517 | case 0: // Try again or Enter | 518 | case 0: // Try again or Enter |
518 | item.option = "D"; | 519 | item.option = "D"; |
519 | break; | 520 | break; |
520 | case 1: // Quit or Escape | 521 | case 1: // Quit or Escape |
521 | item.option = "U"; | 522 | item.option = "U"; |
522 | break; | 523 | break; |
523 | } | 524 | } |
524 | } | 525 | } |
525 | else | 526 | else |
526 | { | 527 | { |
527 | // item.option = stickyOption; | 528 | // item.option = stickyOption; |
528 | } | 529 | } |
529 | 530 | ||
530 | // Check if we are reinstalling the same version | 531 | // Check if we are reinstalling the same version |
531 | if ( p->getVersion() != p->getInstalledVersion() ) | 532 | if ( p->getVersion() != p->getInstalledVersion() ) |
532 | item.recreateLinks = true; | 533 | item.recreateLinks = true; |
533 | else | 534 | else |
534 | item.recreateLinks = false; | 535 | item.recreateLinks = false; |
535 | 536 | ||
536 | // User hit cancel (on dlg - assume remove) | 537 | // User hit cancel (on dlg - assume remove) |
537 | return item; | 538 | return item; |
538 | } | 539 | } |
539 | } | 540 | } |
540 | 541 | ||
541 | void NetworkPackageManager :: displayText( const QString &t ) | 542 | void NetworkPackageManager :: displayText( const QString &t ) |
542 | { | 543 | { |
543 | cout << t << endl; | 544 | cout << t << endl; |
544 | } | 545 | } |
545 | 546 | ||
546 | 547 | ||
547 | void NetworkPackageManager :: letterPushed( QString t ) | 548 | void NetworkPackageManager :: letterPushed( QString t ) |
548 | { | 549 | { |
549 | QCheckListItem *top = (QCheckListItem *)packagesList->firstChild(); | 550 | QCheckListItem *top = (QCheckListItem *)packagesList->firstChild(); |
550 | QCheckListItem *start = (QCheckListItem *)packagesList->currentItem(); | 551 | QCheckListItem *start = (QCheckListItem *)packagesList->currentItem(); |
551 | if ( packagesList->firstChild() == 0 ) | 552 | if ( packagesList->firstChild() == 0 ) |
552 | return; | 553 | return; |
553 | 554 | ||
554 | QCheckListItem *item; | 555 | QCheckListItem *item; |
555 | if ( start == 0 ) | 556 | if ( start == 0 ) |
556 | { | 557 | { |
557 | item = (QCheckListItem *)packagesList->firstChild(); | 558 | item = (QCheckListItem *)packagesList->firstChild(); |
558 | start = top; | 559 | start = top; |
559 | } | 560 | } |
560 | else | 561 | else |
561 | item = (QCheckListItem *)start->nextSibling(); | 562 | item = (QCheckListItem *)start->nextSibling(); |
562 | 563 | ||
563 | if ( item == 0 ) | 564 | if ( item == 0 ) |
564 | item = (QCheckListItem *)packagesList->firstChild(); | 565 | item = (QCheckListItem *)packagesList->firstChild(); |
565 | do | 566 | do |
566 | { | 567 | { |
567 | if ( item->text().lower().startsWith( t.lower() ) ) | 568 | if ( item->text().lower().startsWith( t.lower() ) ) |
568 | { | 569 | { |
569 | packagesList->setSelected( item, true ); | 570 | packagesList->setSelected( item, true ); |
570 | packagesList->ensureItemVisible( item ); | 571 | packagesList->ensureItemVisible( item ); |
571 | break; | 572 | break; |
572 | } | 573 | } |
573 | 574 | ||
574 | item = (QCheckListItem *)item->nextSibling(); | 575 | item = (QCheckListItem *)item->nextSibling(); |
575 | if ( !item ) | 576 | if ( !item ) |
576 | item = (QCheckListItem *)packagesList->firstChild(); | 577 | item = (QCheckListItem *)packagesList->firstChild(); |
577 | } while ( item != start); | 578 | } while ( item != start); |
578 | } | 579 | } |