2 #include "installfile.h"
3 #include "repository.h"
6 InstallFile::InstallFile(QString filename): iIsValid(true)
8 sections sect = sectNone;
9 QStringList catalogues;
10 Repository* newrepo = 0;
11 QString currentRepoSect;
13 qDebug() << "--reading install file" << filename;
16 if( f.open(QIODevice::ReadOnly | QIODevice::Text) )
18 while( !f.atEnd() && iIsValid )
20 QString line = f.readLine().simplified();
21 //qDebug() << ">" << line;
23 if( line == "[install]" ) {
25 qDebug() << "install section";
26 } else if( line == "[catalogues]" ) {
27 sect = sectCatalogues;
28 qDebug() << "catalogues section";
29 } else if( line.startsWith('[') && line.endsWith(']') ) {
31 currentRepoSect = line.mid(1,line.length()-2);
32 if( !catalogues.contains( currentRepoSect ) )
35 iErrorString = "File contains an unknown section";
37 qDebug() << "unknown section" << currentRepoSect;
39 qDebug() << "repo section" << currentRepoSect;
40 newrepo = new Repository();
42 qDebug() << "FATAL ERROR";
46 iRepos.append(newrepo);
50 if( sect == sectCatalogues || sect == sectInstall ) {
51 if( line.startsWith("catalogues") )
53 catalogues.append( TrimList( line.mid( line.indexOf('=')+1 ).split(';') ) );
54 qDebug() << catalogues;
57 if( sect == sectInstall ) {
58 if( line.startsWith("package") ) {
59 iInstallPackages.append( TrimList( line.mid( line.indexOf('=')+1 ).split(';') ) );
60 qDebug() << iInstallPackages;
63 if( sect == sectRepo ) {
64 if( line.startsWith("name") ) {
65 newrepo->setName( line.mid( line.indexOf('=')+1 ).trimmed() );
67 if( line.startsWith("uri") ) {
68 newrepo->setEnabled(true);
69 newrepo->setUrlDir( line.mid( line.indexOf('=')+1 ).trimmed() );
71 if( line.startsWith("components") ) {
72 newrepo->setComponents( line.mid( line.indexOf('=')+1 ).trimmed() );
74 if( line.startsWith("dist") ) {
75 newrepo->setDist( line.mid( line.indexOf('=')+1 ).trimmed() );
83 iErrorString = "Could not open file";
84 qDebug() << "could not open file";
87 qDebug() << "--done" << filename;
89 for(int i=0; i<iRepos.count(); i++) {
91 if( iRepos.at(i)->dist().isEmpty() )
92 iRepos.at(i)->setDist("fremantle-1.3"); // this is not exactly the right way...
97 InstallFile::~InstallFile()
99 for(int i=0; i<iRepos.count(); i++) {
106 QStringList InstallFile::TrimList(QStringList l)
109 for(int i=0; i<l.count(); i++)
111 n << l.at(i).trimmed();