00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "packagelist.h"
00011
00012 #include <assert.h>
00013 #include <qfile.h>
00014 #include <qfileinfo.h>
00015 #include <qtextstream.h>
00016
00017 #include "debug.h"
00018
00019 static QDict<OipkgPackage> *packageListAll;
00020 static int packageListAllRefCount = 0;
00021
00022 PackageList::PackageList(QObject *parent, const char *name)
00023 : QObject(parent,name), packageIter( packageList )
00024 {
00025 empty=true;
00026 if (!packageListAll) packageListAll = new QDict<OipkgPackage>();
00027 packageListAllRefCount++;
00028 sections << "All";
00029 subSections.insert("All", new QStringList() );
00030 QStringList *ss = subSections["All"];
00031 *ss << "All";
00032 aktSection = "All";
00033 aktSubSection = "All";
00034 }
00035
00036 PackageList::PackageList( PackageManagerSettings* s, QObject *parent, const char *name)
00037 : QObject(parent,name), packageIter( packageList )
00038 {
00039 settings = s;
00040 PackageList(parent, name);
00041 }
00042
00043 PackageList::~PackageList()
00044 {
00045 if (--packageListAllRefCount < 1 ) delete packageListAll;
00046 }
00047
00049 void PackageList::insertPackage( OipkgPackage* pack )
00050 {
00051 if (!pack) return;
00052 OipkgPackage* p = packageListAll->find( pack->name() );
00053 if ( p )
00054 {
00055 if ( (p->version() == pack->version())
00056
00057 )
00058 {
00059 p->copyValues( pack );
00060 delete pack;
00061 pack = p;
00062 } else {
00063 QDict<OipkgPackage> *packver = p->getOtherVersions();
00064
00065 if (!packver)
00066 {
00067 packver = new QDict<OipkgPackage>();
00068 packver->insert( pack->name(), p );
00069 p->setOtherVersions( packver );
00070 }
00071 pack->setName( pack->name() );
00072 pack->setOtherVersions( packver );
00073 packver->insert( pack->name(), pack );
00074 packageListAll->insert( pack->name(), pack );
00075 packageList.insert( pack->name(), pack );
00076 origPackageList.insert( pack->name(), pack );
00077 }
00078 }else{
00079 packageListAll->insert( pack->name(), pack );
00080 packageList.insert( pack->name(), pack );
00081 origPackageList.insert( pack->name(), pack );
00082 };
00083 empty=false;
00084 updateSections( pack );
00085 }
00086
00087 void PackageList::filterPackages( QString f )
00088 {
00089 packageList.clear();
00090 QDictIterator<OipkgPackage> filterIter( origPackageList );
00091 filterIter.toFirst();
00092 OipkgPackage *pack= filterIter.current() ;
00093 while ( pack )
00094 {
00095 if (
00096 ((aktSection=="All")||(pack->section()==aktSection)) &&
00097 ((aktSubSection=="All")||(pack->subSection()==aktSubSection)) &&
00098 pack->name().contains( f )
00099 )
00100 {
00101 packageList.insert( pack->name(), pack );
00102 }
00103 ++filterIter;
00104 pack = filterIter.current();
00105 }
00106 }
00107
00108 OipkgPackage* PackageList::find( QString n )
00109 {
00110 return packageList.find( n );
00111 }
00112
00113 OipkgPackage* PackageList::first()
00114 {
00115 packageIter.toFirst();
00116 return packageIter.current();
00117 }
00118
00119 OipkgPackage* PackageList::next()
00120 {
00121 ++packageIter;
00122 return packageIter.current();
00123 }
00124
00125 QStringList PackageList::getSections()
00126 {
00127 sections.sort();
00128 return sections;
00129 }
00130
00131 QStringList PackageList::getSubSections()
00132 {
00133 QStringList ss;
00134 if ( !subSections[aktSection] ) return ss;
00135 ss = *subSections[aktSection];
00136 ss.sort();
00137 return ss;
00138 }
00139
00140 void PackageList::setSection( QString sec )
00141 {
00142 aktSection = sec;
00143 }
00144
00145 void PackageList::setSubSection( QString ssec )
00146 {
00147 aktSubSection = ssec;
00148 }
00149
00150 void PackageList::updateSections( OipkgPackage* pack )
00151 {
00152 QString s = pack->section();
00153 if ( s.isEmpty() || s == "") return;
00154 if ( !sections.contains(s) ) sections += s;
00155 QString ss = pack->subSection();
00156 if ( ss.isEmpty() || ss == "" ) return;
00157 if ( !subSections[s] ) {
00158 subSections.insert( s, new QStringList() );
00159 QStringList *subsecs = subSections[s];
00160 *subsecs += "All";
00161 }
00162 QStringList *subsecs = subSections[s];
00163 if ( !subsecs->contains(ss) ) *subsecs += ss;
00164
00165
00166
00167 }
00168
00169
00170 void PackageList::readFileEntries( QString filename, QString dest )
00171 {
00172 pvDebug(5,"PackageList::readFileEntries "+filename+" dest "+dest);
00173 QStringList packEntry;
00174 QFile f( filename );
00175 if ( !f.open(IO_ReadOnly) ) return;
00176 QTextStream *statusStream = new QTextStream( &f );
00177 while ( !statusStream ->eof() )
00178 {
00179 QString line = statusStream->readLine();
00180 if ( line.find(QRegExp("[\n\t ]*")) || line == "" )
00181 {
00182
00183 if ( ! packEntry.isEmpty() )
00184 {
00185 OipkgPackage *p = new OipkgPackage( packEntry, settings );
00186 if ( p )
00187 {
00188 p->setDest( dest );
00189 insertPackage( p );
00190 packEntry.clear();
00191 }
00192 }
00193 }else{
00194 packEntry << line;
00195 };
00196 }
00197
00198 if ( ! packEntry.isEmpty() )
00199 {
00200 OipkgPackage *p = new OipkgPackage( packEntry, settings );
00201 if ( p )
00202 {
00203 p->setDest( dest );
00204 insertPackage( p );
00205 packEntry.clear();
00206 }
00207 }
00208 delete statusStream;
00209 f.close();
00210 return;
00211 }
00212
00213 void PackageList::setSettings( PackageManagerSettings *s )
00214 {
00215 settings = s;
00216 }
00217
00218 OipkgPackage* PackageList::getByName( QString n )
00219 {
00220 return origPackageList[n];
00221 }
00222
00223 void PackageList::clear()
00224 {
00225 origPackageList.clear();
00226 packageList.clear();
00227 }
00228
00229 void PackageList::allPackages()
00230 {
00231 packageList.clear();
00232 QDictIterator<OipkgPackage> filterIter( origPackageList );
00233 filterIter.toFirst();
00234 OipkgPackage *pack= filterIter.current() ;
00235 while ( pack )
00236 {
00237 packageList.insert( pack->name(), pack );
00238 ++filterIter;
00239 pack = filterIter.current();
00240 }
00241 }