[Kde-cygwin-cvs] CVS: tools/installer/shared downloader.cpp,NONE,1.1 downloader.h,NONE,1.1 installer
Status: Inactive
Brought to you by:
habacker
Update of /cvsroot/kde-cygwin/tools/installer/shared In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7851/installer/shared Modified Files: package.cpp package.h packagelist.cpp packagelist.h Added Files: downloader.cpp downloader.h installer.cpp installer.h Log Message: version 0.5.1 --- NEW FILE: downloader.cpp --- /**************************************************************************** ** ** Copyright (C) 2005-2006Ralf Habacker. All rights reserved. ** ** This file is part of the KDE installer for windows ** ** This file may be used under the terms of the GNU General Public ** License version 2.0 as published by the Free Software Foundation ** and appearing in the file LICENSE.GPL included in the packaging of ** this file. Please review the following information to ensure GNU ** General Public Licensing requirements will be met: ** http://www.trolltech.com/products/qt/opensource.html ** ** If you are unsure which license is appropriate for your use, please ** review the following information: ** http://www.trolltech.com/products/qt/licensing.html or contact the ** sales department at sa...@tr.... ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ****************************************************************************/ #include <QtNetwork> #include <QtCore> #include "packagelist.h" #include "package.h" #include "downloader.h" class DownloaderProgress { public: void show() {visible = true; } void hide() {visible = false; } void setLabel(const QString &label) { qDebug() << label; } void setMaximum(int value) {} void setValue(int value) { int unit = value/10240; if (oldunit != value/10240) { if (visible) putchar('.'); oldunit = unit; } } private: int oldunit; bool visible; }; Downloader::Downloader(bool _blocking) { blocking = _blocking; progress = new DownloaderProgress(); http = new QHttp(this); connect(http, SIGNAL(requestFinished(int, bool)),this, SLOT(httpRequestFinished(int, bool))); connect(http, SIGNAL(dataReadProgress(int, int)),this, SLOT(updateDataReadProgress(int, int))); connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),this, SLOT(readResponseHeader(const QHttpResponseHeader &))); connect(http, SIGNAL(done(bool)),this, SLOT(allDone(bool))); connect(http, SIGNAL(stateChanged(int)),this, SLOT(stateChanged(int))); } Downloader::~Downloader() { delete progress; delete http; } void Downloader::setError(const QString &text) { qDebug() << text; } bool Downloader::start(const QString &_url, const QString &_fileName) { QString fileName = _fileName; QUrl url(_url); if (fileName == "") { QFileInfo fileInfo(url.path()); fileName = fileInfo.fileName(); } file = new QFile(fileName); if (!file->open(QIODevice::WriteOnly)) { setError(tr("Unable to save the file %1: %2.").arg(fileName).arg(file->errorString())); delete file; file = 0; return false; } http->setHost(url.host(), url.port() != -1 ? url.port() : 80); if (!url.userName().isEmpty()) http->setUser(url.userName(), url.password()); httpRequestAborted = false; QByteArray query = url.encodedQuery(); httpGetId = http->get(url.path() + (!query.isEmpty() ? "?" + url.encodedQuery() : ""), file); progress->show(); progress->setLabel(tr("Downloading %1 to %2.").arg(_url).arg(fileName)); if (blocking) { eventLoop = new QEventLoop(); eventLoop->exec(); delete eventLoop; } return true; } void Downloader::cancel() { progress->setLabel(tr("Download canceled.")); httpRequestAborted = true; http->abort(); } void Downloader::httpRequestFinished(int requestId, bool error) { if (httpRequestAborted) { if (file) { file->close(); file->remove(); delete file; file = 0; } if (progress) progress->hide(); return; } if (requestId != httpGetId) return; if (progress) progress->hide(); file->close(); if (error) { file->remove(); setError(tr("Download failed: %1.").arg(http->errorString())); } else { progress->setLabel(tr("download ready")); } delete file; file = 0; } void Downloader::readResponseHeader(const QHttpResponseHeader &responseHeader) { if (responseHeader.statusCode() != 200) { setError(tr("Download failed: %1.").arg(responseHeader.reasonPhrase())); httpRequestAborted = true; progress->hide(); http->abort(); return; } } void Downloader::updateDataReadProgress(int bytesRead, int totalBytes) { if (httpRequestAborted) return; if (progress) { progress->setMaximum(totalBytes); progress->setValue(bytesRead); } } void Downloader::allDone(bool error) { emit done(error); if (blocking) eventLoop->quit(); } void Downloader::stateChanged(int state) { QString stateLabel; switch (state) { case QHttp::Unconnected : stateLabel = "Unconnected"; break; case QHttp::HostLookup : stateLabel = "HostLookup "; break; case QHttp::Connecting : stateLabel = "Connecting "; break; case QHttp::Sending : stateLabel = "Sending "; break; case QHttp::Reading : stateLabel = "Reading "; break; case QHttp::Connected : stateLabel = "Connected "; break; case QHttp::Closing : stateLabel = "Closing "; break; } progress->setLabel(stateLabel); } --- NEW FILE: downloader.h --- /**************************************************************************** ** ** Copyright (C) 2005-2006Ralf Habacker. All rights reserved. ** ** This file is part of the KDE installer for windows ** ** This file may be used under the terms of the GNU General Public ** License version 2.0 as published by the Free Software Foundation ** and appearing in the file LICENSE.GPL included in the packaging of ** this file. Please review the following information to ensure GNU ** General Public Licensing requirements will be met: ** http://www.trolltech.com/products/qt/opensource.html ** ** If you are unsure which license is appropriate for your use, please ** review the following information: ** http://www.trolltech.com/products/qt/licensing.html or contact the ** sales department at sa...@tr.... ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ****************************************************************************/ #ifndef DOWNLOADER_H #define DOWNLOADER_H #include <QtCore> class QHttpResponseHeader; class QHttp; class DownloaderProgress; class QEventLoop; class QFile; class Downloader: public QObject { Q_OBJECT public: Downloader(bool blocking=false); virtual ~Downloader(); bool start(const QString &url, const QString &fileName=""); void cancel(); signals: void done(bool error); private slots: void httpRequestFinished(int requestId, bool error); void readResponseHeader(const QHttpResponseHeader &responseHeader); void updateDataReadProgress(int bytesRead, int totalBytes); void allDone(bool error); void stateChanged(int state); private: void setError(const QString&); QHttp *http; QFile *file; int httpGetId; bool httpRequestAborted; DownloaderProgress *progress; bool blocking; QEventLoop *eventLoop; }; #endif --- NEW FILE: installer.cpp --- /**************************************************************************** ** ** Copyright (C) 2005-2006Ralf Habacker. All rights reserved. ** ** This file is part of the KDE installer for windows ** ** This file may be used under the terms of the GNU General Public ** License version 2.0 as published by the Free Software Foundation ** and appearing in the file LICENSE.GPL included in the packaging of ** this file. Please review the following information to ensure GNU ** General Public Licensing requirements will be met: ** http://www.trolltech.com/products/qt/opensource.html ** ** If you are unsure which license is appropriate for your use, please ** review the following information: ** http://www.trolltech.com/products/qt/licensing.html or contact the ** sales department at sa...@tr.... ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ****************************************************************************/ // @TODO load installer config from manifest dir #include <QtCore> #include "installer.h" #include "packagelist.h" Installer::Installer(PackageList *_packageList) : QObject() { packageList = _packageList; connect (packageList,SIGNAL(loadedConfig()),this,SLOT(updatePackageList())); installedList = new QList<QString>(); // if (QFile::exists("installed.txt")) // readFromFile("installed.txt"); // else // loadConfig(); } Installer::~Installer() { // writeToFile("installed.txt"); delete installedList; } /* void Installer::printList(const QString &title) { #ifdef DEBUG qDebug() << __PRETTY_FUNCTION__; #endif qDebug() << title; QList<QString>::iterator i; for (i = installedList->begin(); i != installedList->end(); ++i) qWarning(i->toLatin1()); } */ /* not required at now bool Installer::readFromFile(QString const &fileName) { #ifdef DEBUG qDebug() << __PRETTY_FUNCTION__; #endif QFile file(fileName); if (!file.open(QIODevice::ReadOnly| QIODevice::Text)) return false; installedList->clear(); while (!file.atEnd()) { QByteArray line = file.readLine(); if (line.startsWith("#")) continue; installedList->append(line); } return true; } bool Installer::writeToFile(QString const &fileName) { #ifdef DEBUG qDebug() << __PRETTY_FUNCTION__; #endif QFile file(fileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) return false; QTextStream out(&file); out << "# installed package list" << "\n"; QList<QString>::iterator i; for (i = installedList->begin(); i != installedList->end(); ++i) out << i->toLatin1() << "\n"; return true; } */ bool Installer::loadConfig(const QString &destdir) { #ifdef DEBUG qDebug() << __PRETTY_FUNCTION__; #endif installedList->clear(); QDir dir(destdir + "manifest"); dir.setFilter(QDir::Files); dir.setNameFilters(QStringList("*.ver")); dir.setSorting(QDir::Size | QDir::Reversed); QFileInfoList list = dir.entryInfoList(); for (int i = 0; i < list.size(); ++i) { QFileInfo fileInfo = list.at(i); Package pkg; pkg.setFromVersionFile(fileInfo.fileName()); packageList->updatePackage(pkg); // installedList->append(fileInfo.fileName()); } // printList("installed packages"); return true; } void Installer::install(const QString &fileName, const QString &destdir) { QString cmd = "bin\\unzip.exe -o"; if (destdir != "") cmd += " -d " + destdir; cmd += " " + fileName; qDebug() << cmd; QProcess unzip; unzip.setReadChannelMode(QProcess::MergedChannels); unzip.start(cmd); if (!unzip.waitForFinished()) qDebug() << "unzip failed:" << unzip.errorString(); else qDebug() << "unzip output:" << unzip.readAll(); } void Installer::updatePackageList() { #ifdef DEBUG qDebug() << __PRETTY_FUNCTION__; #endif loadConfig(); } --- NEW FILE: installer.h --- /**************************************************************************** ** ** Copyright (C) 2005-2006Ralf Habacker. All rights reserved. ** ** This file is part of the KDE installer for windows ** ** This file may be used under the terms of the GNU General Public ** License version 2.0 as published by the Free Software Foundation ** and appearing in the file LICENSE.GPL included in the packaging of ** this file. Please review the following information to ensure GNU ** General Public Licensing requirements will be met: ** http://www.trolltech.com/products/qt/opensource.html ** ** If you are unsure which license is appropriate for your use, please ** review the following information: ** http://www.trolltech.com/products/qt/licensing.html or contact the ** sales department at sa...@tr.... ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ****************************************************************************/ #ifndef INSTALLER_H #define INSTALLER_H #include <QtCore> class PackageList; class Installer : public QObject { Q_OBJECT public: Installer(PackageList *packageList); virtual ~Installer(); void install(const QString &fileName, const QString &destdir=""); // installPackage(Package *pkg) // bool readFromFile(QString const &fileName); // bool writeToFile(QString const &fileName); bool loadConfig(const QString &destdir=""); public slots: void updatePackageList(); private: QList<QString> *installedList; PackageList *packageList; }; #endif Index: package.cpp =================================================================== RCS file: /cvsroot/kde-cygwin/tools/installer/shared/package.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- package.cpp 22 Jan 2006 18:33:24 -0000 1.1 +++ package.cpp 22 Jan 2006 18:40:04 -0000 1.2 @@ -1,8 +1,8 @@ /**************************************************************************** ** -** Copyright (C) 2004-2005 Trolltech AS. All rights reserved. +** Copyright (C) 2005-2006Ralf Habacker. All rights reserved. ** -** This file is part of the example classes of the Qt Toolkit. +** This file is part of the KDE installer for windows ** ** This file may be used under the terms of the GNU General Public ** License version 2.0 as published by the Free Software Foundation @@ -27,40 +27,119 @@ #include <QtGui> #include <QtNetwork> -QString Package::baseURL = "http://mesh.dl.sourceforge.net/sourceforge/gnuwin32/"; +QString Package::baseURL = "http://ovh.dl.sourceforge.net/sourceforge/gnuwin32/"; -void Package::parsePackageListLine(const QByteArray &line) +Package::Package() { - static Package pkg; - - if (line.contains("<td><a href=\"/project/showfiles.php?group_id=23617")) { - int a = line.indexOf("\">") + 2; - int b = line.indexOf("</a>"); - QByteArray value = line.mid(a,b-a); - if (line.indexOf("release_id") > -1) { - pkg.setVersion(value); - PackageList::addPackage(pkg); - } - else - pkg.setName(value); + installedLIB = false; + installedBIN = false; + installedDOC = false; + installedSRC = false; +} + +Package::Package(QString const &_name, QString const &_version) +{ + name = _name; version = _version; + installedLIB = false; + installedBIN = false; + installedDOC = false; + installedSRC = false; +} + + +const QString Package::getFileName(Package::Type type) +{ + switch (type) { + case BIN: return name + "-" + version + "-bin.zip"; + case LIB: return name + "-" + version + "-lib.zip"; + case SRC: return name + "-" + version + "-doc.zip"; + case DOC: return name + "-" + version + "-src.zip"; + default: return ""; } } -void Package::install(const QString &fileName,const QString &destdir) +const QString Package::getURL(Package::Type type) +{ + switch (type) { + case BIN: return baseURL + name + "-" + version + "-bin.zip"; + case LIB: return baseURL + name + "-" + version + "-lib.zip"; + case SRC: return baseURL + name + "-" + version + "-doc.zip"; + case DOC: return baseURL + name + "-" + version + "-src.zip"; + default: return ""; + } +} + +void Package::setType(const QString &typeString) +{ + if (typeString == "bin") + installedBIN = true; + else if (typeString == "lib") + installedLIB = true; + else if (typeString == "src") + installedSRC = true; + else if (typeString == "doc") + installedDOC = true; +} + +QString Package::toString() +{ + QString result = name + "-" + version; + QString installedTypes = getTypeAsString(); + if (installedTypes != "") + result += " ( installed =" + getTypeAsString() + ")"; + return result; +} + +const QString Package::getTypeAsString() +{ + QString types; + if (installedBIN) + types += " bin "; + if (installedLIB) + types += " lib "; + if (installedSRC) + types += " src "; + if (installedDOC) + types += " doc "; + return types; +} + +bool Package::setFromVersionFile(const QString &str) +{ + QString verString = str; + verString.replace(".ver",""); + int i = verString.indexOf("-"); + int j = verString.lastIndexOf("-"); + QString name = verString.left(i); + QString version = verString.mid(i+1,j-1-i); + QString type = verString.mid(j+1); + setName(name); + setVersion(version); + setType(type); + return true; +} + +/* +bool Package::updateFromVersionFile(const QString &str) +{ + qDebug() << str; + QString verString = str; + verString.replace(".ver",""); + int i = verString.indexOf("-"); + int j = verString.lastIndexOf("-"); + QString name = verString.left(i); + QString version = verString.mid(i+1,j-1-i+1); + QString type = verString.right(j+1); + return true; +} +*/ + +void Package::addInstalledTypes(const Package &pkg) { - QString cmd = "unzip -o"; - if (destdir != "") - cmd += " -d " + destdir; - cmd += " " + fileName; - qDebug() << cmd; - - QProcess unzip; - unzip.setReadChannelMode(QProcess::MergedChannels); - unzip.start(cmd); - if (!unzip.waitForFinished()) - qDebug() << "unzip failed:" << unzip.errorString(); - else - qDebug() << "unzip output:" << unzip.readAll(); + installedLIB = pkg.installedLIB ? pkg.installedLIB : installedLIB ; + installedBIN = pkg.installedBIN ? pkg.installedBIN : installedBIN ; + installedDOC = pkg.installedDOC ? pkg.installedDOC : installedDOC ; + installedSRC = pkg.installedSRC ? pkg.installedSRC : installedSRC ; } void Package::logOutput() Index: package.h =================================================================== RCS file: /cvsroot/kde-cygwin/tools/installer/shared/package.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- package.h 22 Jan 2006 18:33:24 -0000 1.1 +++ package.h 22 Jan 2006 18:40:04 -0000 1.2 @@ -1,8 +1,8 @@ /**************************************************************************** ** -** Copyright (C) 2004-2005 Trolltech AS. All rights reserved. +** Copyright (C) 2005-2006Ralf Habacker. All rights reserved. ** -** This file is part of the example classes of the Qt Toolkit. +** This file is part of the KDE installer for windows ** ** This file may be used under the terms of the GNU General Public ** License version 2.0 as published by the Free Software Foundation @@ -27,31 +27,36 @@ #include <QtNetwork> class Package { + public: - Package() {} - Package(QString const &_name, QString const &_version) { name = _name; version = _version; } - void setName(QString const &_name) { name = _name; } + enum Type { BIN = 1 ,LIB = 2 ,DOC = 4 ,SRC = 8 }; + + Package(); + Package(QString const &_name, QString const &_version); QString &Name() { return name; } + void setName(QString const &_name) { name = _name; } void setVersion(QString const &_version) { version = _version; } - static void parsePackageListLine(const QByteArray &line); - QString toString() { return name + "-" + version; } - const QString binURL() { return baseURL + name + "-" + version + "-bin.zip"; } - const QString libURL() { return baseURL + name + "-" + version + "-lib.zip"; } - const QString docURL() { return baseURL + name + "-" + version + "-doc.zip"; } - const QString srcURL() { return baseURL + name + "-" + version + "-src.zip"; } - const QString binFileName() { return name + "-" + version + "-bin.zip"; } - const QString libFileName() { return name + "-" + version + "-lib.zip"; } - const QString docFileName() { return name + "-" + version + "-doc.zip"; } - const QString srcFileName() { return name + "-" + version + "-src.zip"; } - static QString baseURL; - void install(const QString &fileName,const QString &destdir=0); + void setType(const QString &typeString); + bool setFromVersionFile(const QString &verString); + QString toString(); + const QString getTypeAsString(); + + const QString getFileName(Package::Type type); + const QString getURL(Package::Type type); + bool isEmpty() {return name == ""; } + void addInstalledTypes(const Package &pkg); private slots: void logOutput(); private: + static QString baseURL; QString name; QString version; + bool installedLIB; + bool installedBIN; + bool installedDOC; + bool installedSRC; }; #endif Index: packagelist.cpp =================================================================== RCS file: /cvsroot/kde-cygwin/tools/installer/shared/packagelist.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- packagelist.cpp 22 Jan 2006 18:33:24 -0000 1.1 +++ packagelist.cpp 22 Jan 2006 18:40:04 -0000 1.2 @@ -1,8 +1,8 @@ /**************************************************************************** ** -** Copyright (C) 2004-2005 Trolltech AS. All rights reserved. +** Copyright (C) 2005-2006Ralf Habacker. All rights reserved. ** -** This file is part of the example classes of the Qt Toolkit. +** This file is part of the KDE installer for windows ** ** This file may be used under the terms of the GNU General Public ** License version 2.0 as published by the Free Software Foundation @@ -25,27 +25,49 @@ #include <QtNetwork> #include "packagelist.h" +//#define DEBUG -QString PackageList::InputFile = "packages.html"; -QString PackageList::OutputFile = "packages.txt"; -QString PackageList::URL = "http://sourceforge.net/project/showfiles.php?group_id=23617"; - -QList<Package> PackageList::packageList; +PackageList::PackageList() + : QObject() +{ +#ifdef DEBUG + qDebug() << __PRETTY_FUNCTION__; +#endif + packageList = new QList<Package>; +} + +PackageList::~PackageList() +{ +#ifdef DEBUG + qDebug() << __PRETTY_FUNCTION__; +#endif + delete packageList; +} void PackageList::addPackage(Package const &package) { - packageList.append(package); +#ifdef DEBUG + qDebug() << __PRETTY_FUNCTION__; +#endif + packageList->append(package); } -void PackageList::listPackages(void) -{ +void PackageList::listPackages(const QString &title) +{ +#ifdef DEBUG + qDebug() << __PRETTY_FUNCTION__; +#endif + qDebug() << title; QList<Package>::iterator i; - for (i = packageList.begin(); i != packageList.end(); ++i) + for (i = packageList->begin(); i != packageList->end(); ++i) qWarning(i->toString().toLatin1()); } bool PackageList::writeToFile(QString const &fileName) { +#ifdef DEBUG + qDebug() << __PRETTY_FUNCTION__; +#endif QFile file(fileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) return false; @@ -53,18 +75,21 @@ QTextStream out(&file); out << "# package list" << "\n"; QList<Package>::iterator i; - for (i = packageList.begin(); i != packageList.end(); ++i) + for (i = packageList->begin(); i != packageList->end(); ++i) out << i->toString().toLatin1() << "\n"; return true; } bool PackageList::readFromFile(QString const &fileName) { +#ifdef DEBUG + qDebug() << __PRETTY_FUNCTION__; +#endif QFile file(fileName); if (!file.open(QIODevice::ReadOnly| QIODevice::Text)) return false; - packageList.clear(); + packageList->clear(); Package pkg; while (!file.atEnd()) { @@ -74,50 +99,95 @@ int i = line.indexOf("-"); pkg.setName(line.left(i)); pkg.setVersion(line.mid(i+1,line.size()-i-2)); - PackageList::addPackage(pkg); + addPackage(pkg); } - PackageList::listPackages(); + emit loadedConfig(); return true; } bool PackageList::readFromHTMLFile(const QString &fileName) { +#ifdef DEBUG + qDebug() << __PRETTY_FUNCTION__; +#endif QFile pkglist(fileName); if (!pkglist.exists()) return false; + packageList->clear(); + pkglist.open(QIODevice::ReadOnly); Package pkg; while (!pkglist.atEnd()) { QByteArray line = pkglist.readLine(); - Package::parsePackageListLine(line); + if (line.contains("<td><a href=\"/project/showfiles.php?group_id=23617")) { + int a = line.indexOf("\">") + 2; + int b = line.indexOf("</a>"); + QByteArray value = line.mid(a,b-a); + if (line.indexOf("release_id") > -1) { + pkg.setVersion(value); + addPackage(pkg); + } + else + pkg.setName(value); + } } - PackageList::listPackages(); - PackageList::writeToFile(PackageList::OutputFile); + emit loadedConfig(); return true; } -QStringList PackageList::getPackageFiles(QString const &pkgName) +Package *PackageList::getPackage(QString const &pkgName) { +#ifdef DEBUG + qDebug() << __PRETTY_FUNCTION__; +#endif QList<Package>::iterator i; - QStringList list; - for (i = packageList.begin(); i != packageList.end(); ++i) { - if (pkgName == "*" || i->Name() == pkgName) { - list << i->binURL(); - list << i->libURL(); - list << i->docURL(); - list << i->srcURL(); - } - } - return list; + for (i = packageList->begin(); i != packageList->end(); ++i) + if (i->Name() == pkgName) + return &*i; + return 0; } -Package PackageList::getPackage(QString const &pkgName) +QStringList PackageList::getFilesToInstall(QString const &pkgName) { - QList<Package>::iterator i; - for (i = packageList.begin(); i != packageList.end(); ++i) - if (i->Name() == pkgName) - return *i; - return Package(); +#ifdef DEBUG + qDebug() << __PRETTY_FUNCTION__; +#endif + QStringList result; + Package *pkg = getPackage(pkgName); + if (!pkg) + return result; + result << pkg->getFileName(Package::BIN); + result << pkg->getFileName(Package::LIB); + result << pkg->getFileName(Package::DOC); + result << pkg->getFileName(Package::SRC); + return result; +} + +QStringList PackageList::getFilesForDownload(QString const &pkgName) +{ +#ifdef DEBUG + qDebug() << __PRETTY_FUNCTION__; +#endif + QStringList result; + Package *pkg = getPackage(pkgName); + if (!pkg) + return result; + result << pkg->getURL(Package::BIN); + result << pkg->getURL(Package::LIB); + result << pkg->getURL(Package::DOC); + result << pkg->getURL(Package::SRC); + return result; +} + +bool PackageList::updatePackage(Package &apkg) +{ + Package *pkg = getPackage(apkg.Name()); + if (!pkg) { + qDebug() << __PRETTY_FUNCTION__ << "package " << apkg.Name() << " not found"; + return false; + } + pkg->addInstalledTypes(apkg); + return true; } Index: packagelist.h =================================================================== RCS file: /cvsroot/kde-cygwin/tools/installer/shared/packagelist.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- packagelist.h 22 Jan 2006 18:33:24 -0000 1.1 +++ packagelist.h 22 Jan 2006 18:40:04 -0000 1.2 @@ -1,8 +1,8 @@ /**************************************************************************** ** -** Copyright (C) 2004-2005 Trolltech AS. All rights reserved. +** Copyright (C) 2005-2006Ralf Habacker. All rights reserved. ** -** This file is part of the example classes of the Qt Toolkit. +** This file is part of the KDE installer for windows ** ** This file may be used under the terms of the GNU General Public ** License version 2.0 as published by the Free Software Foundation @@ -26,21 +26,29 @@ #include "package.h" -class PackageList { +class PackageList : public QObject { + Q_OBJECT + public: - static void addPackage(Package const &package); - static void listPackages(void); - static bool writeToFile(QString const &fileName); - static bool readFromFile(QString const &fileName); - static bool readFromHTMLFile(const QString &fileName); + PackageList(); + virtual ~PackageList(); + void addPackage(Package const &package); + void listPackages(const QString &title=""); + bool readFromFile(QString const &fileName); + bool readFromHTMLFile(const QString &fileName); + bool writeToFile(QString const &fileName); // static bool downloadPackage(QString const &pkgName); - static QStringList getPackageFiles(QString const &pkgName); - static Package getPackage(QString const &pkgName); - static QString InputFile; - static QString OutputFile; - static QString URL; + QStringList getPackageFiles(QString const &pkgName); + Package *getPackage(QString const &pkgName); + QStringList getFilesToInstall(QString const &pkgName); + QStringList getFilesForDownload(QString const &pkgName); + bool updatePackage(Package &pkg); + + signals: + void loadedConfig(); + private: - static QList<Package> packageList; + QList<Package> *packageList; }; |