[Kde-cygwin-cvs] CVS: tools/installer readme.txt,NONE,1.1 installer.cpp,1.1,1.2 installer.h,1.1,1.2
Status: Inactive
Brought to you by:
habacker
From: Ralf H. <hab...@us...> - 2006-01-22 18:29:18
|
Update of /cvsroot/kde-cygwin/tools/installer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2831/installer Modified Files: installer.cpp installer.h installer.pro packagelist.cpp packagelist.h packages.h Added Files: readme.txt Log Message: version 0.2 --- NEW FILE: readme.txt --- TODO - define blocking function for downloading - import unzip support - add package selection page Index: installer.cpp =================================================================== RCS file: /cvsroot/kde-cygwin/tools/installer/installer.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- installer.cpp 22 Jan 2006 18:28:27 -0000 1.1 +++ installer.cpp 22 Jan 2006 18:29:10 -0000 1.2 @@ -30,16 +30,13 @@ #include <QtNetwork> #include <QStringListModel> -QString packageListURL = "http://sourceforge.net/project/showfiles.php?group_id=23617"; -QString packageListInputFile = "packages.html"; -QString packageListOutputFile = "packages.txt"; +QString packageInstallDir = "packages"; Installer::Installer(QWidget *parent) : QDialog(parent) { -/* - QComboBox *downloadMirror = new QComboBox(this); + downloadMirror = new QComboBox(this); downloadMirror->addItem("aleron (US)"); downloadMirror->addItem("belnet (BE)"); downloadMirror->addItem("easynews (US)"); @@ -56,27 +53,29 @@ downloadMirror->addItem("umn (US)"); downloadMirror->addItem("unc (US)"); downloadMirror->addItem("voxel (US)"); -*/ - urlLineEdit = new QLineEdit("http://sourceforge.net/project/showfiles.php?group_id=23617"); urlLabel = new QLabel(tr("&URL:")); - urlLabel->setBuddy(urlLineEdit); - statusLabel = new QLabel(tr("Please enter the URL of a file you want to " - "download.")); + urlLabel->setBuddy(downloadMirror); + statusLabel = new QLabel(tr("Initial message")); downloadPackageListButton = new QPushButton(tr("Download Package List")); downloadPackageListButton->setDefault(true); - quitButton = new QPushButton(tr("Quit")); - DownloadPackageButton = new QPushButton(tr("Download")); - installButton = new QPushButton(tr("Install")); parseButton = new QPushButton(tr("Parse")); - + installButton = new QPushButton(tr("Install")); + downloadPackageButton = new QPushButton(tr("Download")); + quitButton = new QPushButton(tr("Quit")); + + downloadMirror->setEnabled(false); + parseButton->setEnabled(false); + installButton->setEnabled(false); + downloadPackageButton->setEnabled(false); + progressDialog = new QProgressDialog(this); http = new QHttp(this); - connect(urlLineEdit, SIGNAL(textChanged(const QString &)), - this, SLOT(enableDownloadPackageButton())); +// connect(urlLineEdit, SIGNAL(textChanged(const QString &)), +// this, SLOT(enabledownloadPackageButton())); connect(http, SIGNAL(requestFinished(int, bool)), this, SLOT(httpRequestFinished(int, bool))); connect(http, SIGNAL(dataReadProgress(int, int)), @@ -85,21 +84,20 @@ this, SLOT(readResponseHeader(const QHttpResponseHeader &))); connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload())); connect(downloadPackageListButton, SIGNAL(clicked()), this, SLOT(downloadPackageList())); - connect(DownloadPackageButton, SIGNAL(clicked()), this, SLOT(downloadFiles())); connect(parseButton, SIGNAL(clicked()), this, SLOT(parsePackageList())); + connect(downloadPackageButton, SIGNAL(clicked()), this, SLOT(downloadFiles())); connect(installButton, SIGNAL(clicked()), this, SLOT(installFiles())); connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); QHBoxLayout *topLayout = new QHBoxLayout; topLayout->addWidget(urlLabel); - topLayout->addWidget(urlLineEdit); - // topLayout->addWidget(downloadMirror); + topLayout->addWidget(downloadMirror); QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addStretch(1); buttonLayout->addWidget(downloadPackageListButton); buttonLayout->addWidget(parseButton); - buttonLayout->addWidget(DownloadPackageButton); + buttonLayout->addWidget(downloadPackageButton); buttonLayout->addWidget(installButton); buttonLayout->addWidget(quitButton); @@ -111,13 +109,101 @@ setLayout(mainLayout); setWindowTitle(tr("HTTP")); - urlLineEdit->setFocus(); + downloadMirror->setFocus(); } void Installer::downloadPackageList() { - QUrl url(packageListURL); - QString fileName = packageListInputFile; + QUrl url(PackageList::URL); + QString fileName = PackageList::InputFile; + + if (QFile::exists(fileName)) { + QMessageBox::information(this, tr("HTTP"), + tr("There already exists a file called %1 in " + "the current directory. Remove to fore download.") + .arg(fileName)); + parseButton->setEnabled(true); + statusLabel->setText(tr("Now press Parse to generate a package list.")); + return; + } + + file = new QFile(fileName); + if (!file->open(QIODevice::WriteOnly)) { + QMessageBox::information(this, tr("HTTP"), + tr("Unable to save the file %1: %2.") + .arg(fileName).arg(file->errorString())); + delete file; + file = 0; + return; + } + + 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); + + progressDialog->setWindowTitle(tr("HTTP")); + progressDialog->setLabelText(tr("Downloading %1.").arg(fileName)); + + parseButton->setEnabled(true); + statusLabel->setText(tr("Now press Parse to generate a package list.")); +} + + +void Installer::parsePackageList() +{ + parseButton->setEnabled(false); + QString fileName = PackageList::InputFile; + if (!PackageList::readFromHTMLFile(fileName)) { + QMessageBox::information(this, tr("HTTP"), + tr("could not open: %1") + .arg(fileName) ); + parseButton->setEnabled(true); + return; + } + parseButton->setEnabled(true); + downloadPackageButton->setEnabled(true); + downloadMirror->setEnabled(true); + statusLabel->setText(tr("Now edit packages.txt to select the packages for download.")); +} + +void Installer::downloadFiles() +{ + if (!PackageList::readFromFile(PackageList::OutputFile)) { + QMessageBox::information(this, tr("HTTP"), + tr("could not open: %1") + .arg(PackageList::OutputFile) ); + return; + } + QStringList list = PackageList::getPackageFiles("*"); + qDebug() << list.join("\n"); + for (int i = 0; i < list.size(); ++i) + downloadSingleFile(list.at(i)); + + installButton->setEnabled(true); + statusLabel->setText(tr("Now press Install to install your selected packages.")); +} + +void Installer::installFiles() +{ + Package pkg = PackageList::getPackage("unzip"); + pkg.install(pkg.binFileName(),packageInstallDir); +} + +void Installer::downloadSingleFile(QString _url) +{ + qWarning("downloading " + _url.toLatin1()); + QUrl url(_url); + QMessageBox::information(this, tr("HTTP"), + tr("%1 " + ".") + .arg(url.toString())); + + QFileInfo fileInfo(url.path()); + QString fileName = fileInfo.fileName(); if (QFile::exists(fileName)) { QMessageBox::information(this, tr("HTTP"), @@ -144,18 +230,15 @@ httpRequestAborted = false; QByteArray query = url.encodedQuery(); httpGetId = http->get(url.path() + (!query.isEmpty() ? "?" + url.encodedQuery() : ""), file); - - progressDialog->setWindowTitle(tr("HTTP")); - progressDialog->setLabelText(tr("Downloading %1.").arg(fileName)); - DownloadPackageButton->setEnabled(false); } + void Installer::cancelDownload() { statusLabel->setText(tr("Download canceled.")); httpRequestAborted = true; http->abort(); - DownloadPackageButton->setEnabled(true); +// downloadPackageButton->setEnabled(true); } void Installer::httpRequestFinished(int requestId, bool error) @@ -184,11 +267,11 @@ tr("Download failed: %1.") .arg(http->errorString())); } else { - QString fileName = QFileInfo(QUrl(urlLineEdit->text()).path()).fileName(); - statusLabel->setText(tr("Downloaded %1 to current directory.").arg(fileName)); +// QString fileName = QFileInfo(QUrl(urlLineEdit->text()).path()).fileName(); +// statusLabel->setText(tr("Downloaded %1 to current directory.").arg(fileName)); } - DownloadPackageButton->setEnabled(true); + downloadPackageButton->setEnabled(true); delete file; file = 0; } @@ -215,89 +298,7 @@ progressDialog->setValue(bytesRead); } -void Installer::enableDownloadPackageButton() +void Installer::enabledownloadPackageButton() { - DownloadPackageButton->setEnabled(!urlLineEdit->text().isEmpty()); -} - -void Installer::parsePackageList() -{ - parseButton->setEnabled(false); - QString fileName = packageListInputFile; - - QFile pkglist(fileName); - if (!pkglist.exists()) { - QMessageBox::information(this, tr("HTTP"), - tr("could not open: %1") - .arg(fileName) ); - parseButton->setEnabled(true); - return; - } - - pkglist.open(QIODevice::ReadOnly); - Package pkg; - - while (!pkglist.atEnd()) { - QByteArray line = pkglist.readLine(); - Package::parsePackageListLine(line); - } - PackageList::listPackages(); - PackageList::writeToFile("packages.txt"); - - parseButton->setEnabled(true); -} - - -void Installer::downloadFiles() -{ - QStringList list = PackageList::getPackageFiles("unzip"); - for (int i = 0; i < list.size(); ++i) - downloadSingleFile(list.at(i)); -} - - -void Installer::installFiles() -{ - Package pkg = PackageList::getPackage("unzip"); - pkg.install(pkg.binFileName(),"test"); -} - - -void Installer::downloadSingleFile(QString _url) -{ - qWarning("downloading " + _url.toLatin1()); - QUrl url(_url); - QMessageBox::information(this, tr("HTTP"), - tr("%1 " - ".") - .arg(url.toString())); - - QFileInfo fileInfo(url.path()); - QString fileName = fileInfo.fileName(); - - if (QFile::exists(fileName)) { - QMessageBox::information(this, tr("HTTP"), - tr("There already exists a file called %1 in " - "the current directory.") - .arg(fileName)); - return; - } - - file = new QFile(fileName); - if (!file->open(QIODevice::WriteOnly)) { - QMessageBox::information(this, tr("HTTP"), - tr("Unable to save the file %1: %2.") - .arg(fileName).arg(file->errorString())); - delete file; - file = 0; - return; - } - - 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); +// downloadPackageButton->setEnabled(!urlLineEdit->text().isEmpty()); } Index: installer.h =================================================================== RCS file: /cvsroot/kde-cygwin/tools/installer/installer.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- installer.h 22 Jan 2006 18:28:27 -0000 1.1 +++ installer.h 22 Jan 2006 18:29:10 -0000 1.2 @@ -34,7 +34,9 @@ class QProgressDialog; class QPushButton; class QListView; +class QComboBox; class QAbstractItemModel; + class Installer : public QDialog { Q_OBJECT @@ -54,16 +56,16 @@ void httpRequestFinished(int requestId, bool error); void readResponseHeader(const QHttpResponseHeader &responseHeader); void updateDataReadProgress(int bytesRead, int totalBytes); - void enableDownloadPackageButton(); + void enabledownloadPackageButton(); private: QLabel *statusLabel; QLabel *urlLabel; - QLineEdit *urlLineEdit; + QComboBox *downloadMirror; QProgressDialog *progressDialog; QPushButton *quitButton; QPushButton *downloadPackageListButton; - QPushButton *DownloadPackageButton; + QPushButton *downloadPackageButton; QPushButton *parseButton; QPushButton *installButton; Index: installer.pro =================================================================== RCS file: /cvsroot/kde-cygwin/tools/installer/installer.pro,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- installer.pro 22 Jan 2006 18:28:27 -0000 1.1 +++ installer.pro 22 Jan 2006 18:29:10 -0000 1.2 @@ -6,7 +6,8 @@ package.cpp \ packagelist.cpp \ main.cpp -QT += network +QT += network +CONFIG += # install target.path = $$[QT_INSTALL_EXAMPLES]/network/http Index: packagelist.cpp =================================================================== RCS file: /cvsroot/kde-cygwin/tools/installer/packagelist.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- packagelist.cpp 22 Jan 2006 18:28:27 -0000 1.1 +++ packagelist.cpp 22 Jan 2006 18:29:10 -0000 1.2 @@ -26,6 +26,10 @@ #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) @@ -54,12 +58,52 @@ 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 (i->Name() == pkgName) { + if (pkgName == "*" || i->Name() == pkgName) { list << i->binURL(); list << i->libURL(); list << i->docURL(); Index: packagelist.h =================================================================== RCS file: /cvsroot/kde-cygwin/tools/installer/packagelist.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- packagelist.h 22 Jan 2006 18:28:27 -0000 1.1 +++ packagelist.h 22 Jan 2006 18:29:10 -0000 1.2 @@ -31,11 +31,14 @@ 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; Index: packages.h =================================================================== RCS file: /cvsroot/kde-cygwin/tools/installer/packages.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- packages.h 22 Jan 2006 18:28:27 -0000 1.1 +++ packages.h 22 Jan 2006 18:29:10 -0000 1.2 @@ -119,8 +119,8 @@ "download.")); quitButton = new QPushButton(tr("Quit")); - DownloadPackageButton = new QPushButton(tr("Download")); - DownloadPackageButton->setDefault(true); + downloadPackageButton = new QPushButton(tr("Download")); + downloadPackageButton->setDefault(true); parseButton = new QPushButton(tr("Parse")); QListView *parseOutput = new QListView(this); @@ -130,7 +130,7 @@ http = new QHttp(this); connect(urlLineEdit, SIGNAL(textChanged(const QString &)), - this, SLOT(enableDownloadPackageButton())); + this, SLOT(enabledownloadPackageButton())); connect(http, SIGNAL(requestFinished(int, bool)), this, SLOT(httpRequestFinished(int, bool))); connect(http, SIGNAL(dataReadProgress(int, int)), @@ -138,7 +138,7 @@ connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)), this, SLOT(readResponseHeader(const QHttpResponseHeader &))); connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload())); - connect(DownloadPackageButton, SIGNAL(clicked()), this, SLOT(downloadFile())); + connect(downloadPackageButton, SIGNAL(clicked()), this, SLOT(downloadFile())); connect(parseButton, SIGNAL(clicked()), this, SLOT(parseFile())); connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); @@ -149,7 +149,7 @@ QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addStretch(1); - buttonLayout->addWidget(DownloadPackageButton); + buttonLayout->addWidget(downloadPackageButton); buttonLayout->addWidget(parseButton); buttonLayout->addWidget(quitButton); @@ -207,7 +207,7 @@ progressDialog->setWindowTitle(tr("HTTP")); progressDialog->setLabelText(tr("Downloading %1.").arg(fileName)); - DownloadPackageButton->setEnabled(false); + downloadPackageButton->setEnabled(false); } void Installer::cancelDownload() @@ -215,7 +215,7 @@ statusLabel->setText(tr("Download canceled.")); httpRequestAborted = true; http->abort(); - DownloadPackageButton->setEnabled(true); + downloadPackageButton->setEnabled(true); } void Installer::httpRequestFinished(int requestId, bool error) @@ -248,7 +248,7 @@ statusLabel->setText(tr("Downloaded %1 to current directory.").arg(fileName)); } - DownloadPackageButton->setEnabled(true); + downloadPackageButton->setEnabled(true); delete file; file = 0; } @@ -275,9 +275,9 @@ progressDialog->setValue(bytesRead); } -void Installer::enableDownloadPackageButton() +void Installer::enabledownloadPackageButton() { - DownloadPackageButton->setEnabled(!urlLineEdit->text().isEmpty()); + downloadPackageButton->setEnabled(!urlLineEdit->text().isEmpty()); } |