summaryrefslogtreecommitdiff
path: root/noncore/unsupported/oipkg/packagelist.cpp
Unidiff
Diffstat (limited to 'noncore/unsupported/oipkg/packagelist.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/unsupported/oipkg/packagelist.cpp215
1 files changed, 215 insertions, 0 deletions
diff --git a/noncore/unsupported/oipkg/packagelist.cpp b/noncore/unsupported/oipkg/packagelist.cpp
new file mode 100644
index 0000000..d72ef75
--- a/dev/null
+++ b/noncore/unsupported/oipkg/packagelist.cpp
@@ -0,0 +1,215 @@
1#include "packagelist.h"
2
3#include <assert.h>
4#include <qfile.h>
5#include <qfileinfo.h>
6#include <qtextstream.h>
7#include <qpe/config.h>
8
9#include "debug.h"
10
11PackageList::PackageList()
12 : packageIter( packageList )
13{
14 empty=true;
15 {
16 Config cfg( "oipkg", Config::User );
17 cfg.setGroup( "Common" );
18 statusDir = cfg.readEntry( "statusDir", "" );
19 listsDir = cfg.readEntry( "listsDir", "" );
20 if ( statusDir=="" || ! QFileInfo(statusDir+"/status").isFile() )
21 {
22 statusDir="/usr/lib/ipkg/";
23 listsDir="/usr/lib/ipkg/lists/";
24 cfg.writeEntry( "statusDir", statusDir );
25 cfg.writeEntry( "listsDir", listsDir );
26 }
27 }
28 pvDebug( 5, "PackageList::PackageList statusDir "+statusDir);
29 pvDebug( 5, "PackageList::PackageList listsDir "+listsDir);
30 sections << "All";
31 subSections.insert("All", new QStringList() );
32 QStringList *ss = subSections["All"];
33 *ss << "All";
34 aktSection = "All";
35 aktSubSection = "All";
36}
37
38PackageList::PackageList( PackageManagerSettings* s)
39 : packageIter( packageList )
40{
41 settings = s;
42 PackageList();
43}
44
45PackageList::~PackageList()
46{
47}
48
49/** Inserts a package into the list */
50void PackageList::insertPackage( Package* pack )
51{
52 Package* p = packageList.find( pack->name() );
53 if ( p )
54 {
55 p->copyValues( pack );
56 delete pack;
57 pack = p;
58 }else{
59 packageList.insert( pack->name(), pack );
60 origPackageList.insert( pack->name(), pack );
61 empty=false;
62 };
63 updateSections( pack );
64}
65
66void PackageList::filterPackages()
67 {
68 packageList.clear();
69 QDictIterator<Package> filterIter( origPackageList );
70 filterIter.toFirst();
71 Package *pack= filterIter.current() ;
72 while ( pack )
73 {
74 if ( ((aktSection=="All")||(pack->getSection()==aktSection)) &&
75 ((aktSubSection=="All")||(pack->getSubSection()==aktSubSection)) )
76 {
77 packageList.insert( pack->name(), pack );
78 }
79 ++filterIter;
80 pack = filterIter.current();
81 }
82}
83
84Package* PackageList::find( QString n )
85{
86 return packageList.find( n );
87}
88
89Package* PackageList::first()
90 {
91 packageIter.toFirst();
92 return packageIter.current();
93}
94
95Package* PackageList::next()
96{
97 ++packageIter;
98 return packageIter.current();
99}
100
101QStringList PackageList::getSections()
102{
103 sections.sort();
104 return sections;
105}
106
107QStringList PackageList::getSubSections()
108{
109 QStringList ss;
110 if ( !subSections[aktSection] ) return ss;
111 ss = *subSections[aktSection];
112 ss.sort();
113 return ss;
114}
115
116void PackageList::setSection( QString sec )
117{
118 aktSection = sec;
119}
120
121void PackageList::setSubSection( QString ssec )
122{
123 aktSubSection = ssec;
124}
125
126void PackageList::updateSections( Package* pack )
127{
128 QString s = pack->getSection();
129 if ( s.isEmpty() || s == "") return;
130 if ( sections.contains(s) ) return;
131 sections += s;
132 QString ss = pack->getSubSection();
133 if ( ss.isEmpty() || ss == "" ) return;
134 if ( !subSections[s] ) {
135 subSections.insert( s, new QStringList() );
136 QStringList *subsecs = subSections[s];
137 *subsecs += "All";
138 }
139 QStringList *subsecs = subSections[s];
140 *subsecs += ss;
141 if ( !subSections["All"] ) subSections.insert( "All", new QStringList() );
142 subsecs = subSections["All"];
143 *subsecs += ss;
144}
145
146
147
148/** No descriptions */
149void PackageList::parseStatus()
150{
151 QStringList dests = settings->getDestinationUrls();
152 for ( QStringList::Iterator it = dests.begin(); it != dests.end(); ++it )
153 {
154 pvDebug( 2,"Status Dir: "+*it+statusDir+"/status");
155 readFileEntries( *it+statusDir+"/status" );
156 };
157}
158
159void PackageList::parseList()
160{
161 QStringList srvs = settings->getActiveServers();
162
163 for ( QStringList::Iterator it = srvs.begin(); it != srvs.end(); ++it )
164 {
165 pvDebug( 2, "List Dir: "+listsDir+"/"+*it);
166 readFileEntries( listsDir+"/"+*it );
167 }
168}
169
170void PackageList::readFileEntries( QString filename )
171 {
172 QStringList packEntry;
173 QFile f( filename );
174 if ( !f.open(IO_ReadOnly) ) return;
175 QTextStream *statusStream = new QTextStream( &f );
176 while ( !statusStream ->eof() )
177 {
178 QString line = statusStream->readLine();
179 if ( line.find(QRegExp("[\n\t ]*")) || line == "" )
180 {
181 //end of package
182 if ( ! packEntry.isEmpty() )
183 {
184 Package *p = new Package( packEntry );
185 if ( p )
186 {
187 insertPackage( p );
188 packEntry.clear();
189 }
190 }
191 }else{
192 packEntry << line;
193 };
194 }
195 return;
196}
197
198
199void PackageList::update()
200{
201 pvDebug( 3, "parseStatus");
202 parseStatus();
203 pvDebug( 3, "parseList");
204 parseList();
205 pvDebug( 3, "finished parsing");
206}
207
208
209
210/** No descriptions */
211void PackageList::setSettings( PackageManagerSettings *s )
212{
213 settings = s;
214}
215