[Kde-cygwin-cvs] CVS: tools/installer/shared package.cpp,NONE,1.1 package.h,NONE,1.1 packagelist.cpp
Status: Inactive
Brought to you by:
habacker
From: Ralf H. <hab...@us...> - 2006-01-22 18:33:32
|
Update of /cvsroot/kde-cygwin/tools/installer/shared In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4533/installer/shared Added Files: package.cpp package.h packagelist.cpp packagelist.h Log Message: version 0.3 --- NEW FILE: package.cpp --- /**************************************************************************** ** ** Copyright (C) 2004-2005 Trolltech AS. All rights reserved. ** ** This file is part of the example classes of the Qt Toolkit. ** ** 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 "package.h" #include "packagelist.h" #include <QtGui> #include <QtNetwork> QString Package::baseURL = "http://mesh.dl.sourceforge.net/sourceforge/gnuwin32/"; void Package::parsePackageListLine(const QByteArray &line) { 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); } } void Package::install(const QString &fileName,const QString &destdir) { 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(); } void Package::logOutput() { } --- NEW FILE: package.h --- /**************************************************************************** ** ** Copyright (C) 2004-2005 Trolltech AS. All rights reserved. ** ** This file is part of the example classes of the Qt Toolkit. ** ** 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 PACKAGE_H #define PACKAGE_H #include <QtGui> #include <QtNetwork> class Package { public: Package() {} Package(QString const &_name, QString const &_version) { name = _name; version = _version; } void setName(QString const &_name) { name = _name; } QString &Name() { return 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); private slots: void logOutput(); private: QString name; QString version; }; #endif --- NEW FILE: packagelist.cpp --- /**************************************************************************** ** ** Copyright (C) 2004-2005 Trolltech AS. All rights reserved. ** ** This file is part of the example classes of the Qt Toolkit. ** ** 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 <QtGui> #include <QtNetwork> #include "packagelist.h" 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; void PackageList::addPackage(Package const &package) { packageList.append(package); } void PackageList::listPackages(void) { QList<Package>::iterator i; for (i = packageList.begin(); i != packageList.end(); ++i) qWarning(i->toString().toLatin1()); } bool PackageList::writeToFile(QString const &fileName) { QFile file(fileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) return false; QTextStream out(&file); out << "# package list" << "\n"; QList<Package>::iterator i; for (i = packageList.begin(); i != packageList.end(); ++i) out << i->toString().toLatin1() << "\n"; return true; } bool PackageList::readFromFile(QString const &fileName) { QFile file(fileName); if (!file.open(QIODevice::ReadOnly| QIODevice::Text)) return false; packageList.clear(); Package pkg; while (!file.atEnd()) { QByteArray line = file.readLine(); if (line.startsWith("#")) continue; int i = line.indexOf("-"); pkg.setName(line.left(i)); pkg.setVersion(line.mid(i+1,line.size()-i-2)); PackageList::addPackage(pkg); } PackageList::listPackages(); return true; } bool PackageList::readFromHTMLFile(const QString &fileName) { QFile pkglist(fileName); if (!pkglist.exists()) return false; pkglist.open(QIODevice::ReadOnly); Package pkg; while (!pkglist.atEnd()) { QByteArray line = pkglist.readLine(); Package::parsePackageListLine(line); } PackageList::listPackages(); PackageList::writeToFile(PackageList::OutputFile); return true; } QStringList PackageList::getPackageFiles(QString const &pkgName) { 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; } Package PackageList::getPackage(QString const &pkgName) { QList<Package>::iterator i; for (i = packageList.begin(); i != packageList.end(); ++i) if (i->Name() == pkgName) return *i; return Package(); } --- NEW FILE: packagelist.h --- /**************************************************************************** ** ** Copyright (C) 2004-2005 Trolltech AS. All rights reserved. ** ** This file is part of the example classes of the Qt Toolkit. ** ** 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 PACKAGELIST_H #define PACKAGELIST_H #include "package.h" class PackageList { 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); // 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; private: static QList<Package> packageList; }; #endif |