summaryrefslogtreecommitdiff
path: root/noncore/unsupported/oipkg/package.cpp
Unidiff
Diffstat (limited to 'noncore/unsupported/oipkg/package.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/oipkg/package.cpp255
1 files changed, 255 insertions, 0 deletions
diff --git a/noncore/unsupported/oipkg/package.cpp b/noncore/unsupported/oipkg/package.cpp
new file mode 100644
index 0000000..82ea1c8
--- a/dev/null
+++ b/noncore/unsupported/oipkg/package.cpp
@@ -0,0 +1,255 @@
1#include "package.h"
2
3#include <qpe/process.h>
4#include <qpe/stringutil.h>
5
6#include "debug.h"
7
8Package::~Package()
9{
10}
11
12Package::Package()
13{
14 _size = "";
15 _section = "";
16 _subsection = "";
17 _shortDesc = "";
18 _desc = "";
19 _name = "";
20 _toProcess = true;
21 _status = "";
22}
23
24Package::Package( QStringList pack )
25 {
26 Package();
27 parsePackage( pack );
28 _toProcess = false;
29}
30
31Package::Package( QString n )
32 {
33 Package();
34 _name = QString( n );
35 _toProcess = false;
36}
37
38Package::Package( Package *pi )
39{
40 Package();
41 copyValues( pi );
42 _toProcess = false;
43}
44
45
46void Package::setValue( QString n, QString t )
47{
48 if ( n == "Status" && installed() ) return;
49 if ( n == "Package" )
50 {
51 _name = QString( t );
52 }
53 if ( n == "Installed-Size" )
54 {
55 _size = t;
56 }
57 if ( n == "Priority")
58 {
59
60 }
61 if ( n == "Section")
62 {
63 setSection( t );
64 }
65 if ( n == "Maintainer")
66 {
67
68 }
69 if ( n == "Architecture")
70 {
71
72 }
73 if ( n == "Version")
74 {
75
76 }
77 if ( n == "Pre-Depends")
78 {
79
80 }
81 if ( n == "Depends")
82 {
83
84 }else if ( n == "Filename")
85 {
86
87 }else if ( n == "Size")
88 {
89
90 }else if ( n == "MD5Sum")
91 {
92
93 }
94 if ( n == "Description")
95 {
96 setDesc( t );
97 }
98 if ( n == "Status")
99 {
100 if ( installed() ) return;
101 _status = t;
102 }
103 if ( t == "Essential")
104 {
105
106 }
107};
108
109QString Package::name()
110{
111 return _name;
112}
113
114bool Package::installed()
115{
116 return _status.contains("installed");
117}
118
119void Package::setDesc( QString s )
120{
121 _desc = s;
122 _shortDesc = s.left( s.find("\n") );
123}
124
125QString Package::desc()
126{
127 return _desc;
128}
129
130QString Package::shortDesc()
131{
132 return _shortDesc;
133}
134
135QString Package::size()
136{
137 return _size;
138}
139
140bool Package::toProcess()
141{
142 return _toProcess;
143}
144
145bool Package::toRemove()
146{
147 if ( _toProcess && installed() ) return true;
148 else return false;
149}
150
151bool Package::toInstall()
152{
153 if ( _toProcess && !installed() ) return true;
154 else return false;
155}
156
157void Package::toggleProcess()
158{
159 _toProcess = !(_toProcess);
160}
161
162
163
164void Package::copyValues( Package* pack )
165{
166 if (_size.isEmpty() && !pack->_size.isEmpty()) _size = QString( pack->_size );
167 if (_section.isEmpty() && !pack->_section.isEmpty()) _section = QString( pack->_section );
168 if (_subsection.isEmpty()&& !pack->_subsection.isEmpty()) _subsection = QString( pack->_subsection );
169 if (_shortDesc.isEmpty() && !pack->_shortDesc.isEmpty()) _shortDesc = QString( pack->_shortDesc );
170 if (_desc.isEmpty() && !pack->_desc.isEmpty()) _desc = QString( pack->_desc );
171 if (_name.isEmpty() && !pack->_name.isEmpty()) _name = QString( pack->_name );
172 if (!installed() && _status.isEmpty() && !pack->_status.isEmpty()) _status = QString( pack->_status );
173}
174
175QString Package::getSection()
176{
177 return _section;
178}
179
180void Package::setSection( QString s)
181{
182 int i = s.find("/");
183 if ( i > 0 )
184 {
185 _section = s.left(i);
186 _subsection = s.mid(i+1);
187 }else{
188 _section = s;
189 _subsection = "";
190 }
191}
192
193QString Package::getSubSection()
194{
195 return _subsection;
196}
197
198void Package::parsePackage( QStringList pack )
199{
200 if ( pack.isEmpty() ) return;
201 int count = pack.count();
202 for( int i = 0; i < count; i++ )
203 {
204 QString line = pack[i];
205 int sep = line.find( QRegExp(":[\t ]+") );
206 if ( sep >= 0 )
207 {
208 QString tag = line.left(sep);
209 QString value = line.mid(sep+2).simplifyWhiteSpace();
210 setValue( tag, value );
211 }else{
212 }
213 }
214 return;
215}
216
217QString Package::details()
218{
219 QString status;
220 Process ipkg_status(QStringList() << "ipkg" << "info" << name() );
221 QString description;
222 if ( ipkg_status.exec("",status) )
223 {
224 QStringList lines = QStringList::split('\n',status,TRUE);
225 for (QStringList::Iterator it = lines.begin(); it!=lines.end(); ++it) {
226 QString line = *it;
227 if ( line == " ." )
228 {
229 description.append("<p>");
230 } else
231 if ( line[0] == ' ' || line[0] == '\t' )
232 {
233 // continuation
234 description.append(" ");
235 description.append(Qtopia::escapeString(line));
236 } else {
237 int sep = line.find(QRegExp(":[\t ]+"));
238 if ( sep >= 0 )
239 {
240 QString tag = line.left(sep);
241 description.append("<br>");
242 description.append("<b>");
243 description.append(Qtopia::escapeString(tag));
244 description.append(":</b> ");
245 description.append(Qtopia::escapeString(line.mid(sep+2)));
246 } else {
247 description.append(" ");
248 description.append(Qtopia::escapeString(line));
249 }
250 }
251 }
252 }
253 return description;
254}
255