diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2008-03-05 21:12:24 +0000 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2008-03-05 21:12:24 +0000 |
commit | 5a75184c4abfd2c8fa2a3ee705b94fc800d7b918 (patch) | |
tree | dcbb9529aafc259fd8922b471c8ff537bb48a8fe | |
parent | 0def1dd23cf1990536122d35ed040173ddaa06ba (diff) |
add global proxy / cache settings to httpget class. This removes the need of passing proxy / cache values around all the time. Each object can still override the global values.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16530 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | rbutil/rbutilqt/httpget.cpp | 29 | ||||
-rw-r--r-- | rbutil/rbutilqt/httpget.h | 12 | ||||
-rw-r--r-- | rbutil/rbutilqt/install.cpp | 8 | ||||
-rw-r--r-- | rbutil/rbutilqt/install.h | 2 | ||||
-rw-r--r-- | rbutil/rbutilqt/installbootloader.cpp | 9 | ||||
-rw-r--r-- | rbutil/rbutilqt/installbootloader.h | 2 | ||||
-rw-r--r-- | rbutil/rbutilqt/installthemes.cpp | 16 | ||||
-rw-r--r-- | rbutil/rbutilqt/installthemes.h | 2 | ||||
-rw-r--r-- | rbutil/rbutilqt/installzip.cpp | 8 | ||||
-rw-r--r-- | rbutil/rbutilqt/installzip.h | 4 | ||||
-rw-r--r-- | rbutil/rbutilqt/rbutilqt.cpp | 40 | ||||
-rw-r--r-- | rbutil/rbutilqt/utils.cpp | 2 | ||||
-rw-r--r-- | rbutil/rbutilqt/voicefile.cpp | 1 | ||||
-rw-r--r-- | rbutil/rbutilqt/voicefile.h | 2 |
14 files changed, 63 insertions, 74 deletions
diff --git a/rbutil/rbutilqt/httpget.cpp b/rbutil/rbutilqt/httpget.cpp index acd8940b77..a45769c246 100644 --- a/rbutil/rbutilqt/httpget.cpp +++ b/rbutil/rbutilqt/httpget.cpp @@ -23,6 +23,8 @@ #include "httpget.h" +QDir HttpGet::m_globalCache; +QUrl HttpGet::m_globalProxy; HttpGet::HttpGet(QObject *parent) : QObject(parent) @@ -36,6 +38,14 @@ HttpGet::HttpGet(QObject *parent) // hint about this in the http response instead of nonsense. response = -1; + // default to global proxy / cache if not empty. + // proxy is automatically enabled, disable it by setting an empty proxy + // cache is enabled to be in line, can get disabled with setCache(bool) + qDebug() << "setting global proxy / cache"; + if(!m_globalProxy.isEmpty()) + setProxy(m_globalProxy); + m_usecache = false; + m_cachedir = m_globalCache; connect(&http, SIGNAL(done(bool)), this, SLOT(httpDone(bool))); connect(&http, SIGNAL(dataReadProgress(int, int)), this, SLOT(httpProgress(int, int))); connect(&http, SIGNAL(requestFinished(int, bool)), this, SLOT(httpFinished(int, bool))); @@ -60,13 +70,14 @@ void HttpGet::setCache(QDir d) result = m_cachedir.mkdir("rbutil-cache"); } else result = false; - qDebug() << "HttpGet::setCache(QDir)" << result; + qDebug() << "HttpGet::setCache(QDir)" << d << result; m_usecache = result; } void HttpGet::setCache(bool c) { + qDebug() << "setCache(bool)" << c; m_usecache = c; } @@ -91,8 +102,19 @@ void HttpGet::httpProgress(int read, int total) void HttpGet::setProxy(const QUrl &proxy) { - qDebug() << "HttpGet::setProxy" << proxy.toString(); - http.setProxy(proxy.host(), proxy.port(), proxy.userName(), proxy.password()); + qDebug() << "HttpGet::setProxy(QUrl)" << proxy.toString(); + m_proxy = proxy; + http.setProxy(m_proxy.host(), m_proxy.port(), m_proxy.userName(), m_proxy.password()); +} + + +void HttpGet::setProxy(bool enable) +{ + qDebug() << "HttpGet::setProxy(bool)" << enable; + if(enable) + http.setProxy(m_proxy.host(), m_proxy.port(), m_proxy.userName(), m_proxy.password()); + else + http.setProxy("", 0); } @@ -171,6 +193,7 @@ bool HttpGet::getFile(const QUrl &url) else { qDebug() << "[HTTP] cache DISABLED"; } + http.setHost(url.host(), url.port(80)); // construct query (if any) QList<QPair<QString, QString> > qitems = url.queryItems(); diff --git a/rbutil/rbutilqt/httpget.h b/rbutil/rbutilqt/httpget.h index 4a3d811e05..79522f6e8f 100644 --- a/rbutil/rbutilqt/httpget.h +++ b/rbutil/rbutilqt/httpget.h @@ -35,6 +35,7 @@ class HttpGet : public QObject bool getFile(const QUrl &url); void setProxy(const QUrl &url); + void setProxy(bool); QHttp::Error error(void); QString errorString(void); void setFile(QFile*); @@ -43,6 +44,10 @@ class HttpGet : public QObject int httpResponse(void); QByteArray readAll(void); bool isCached() { return cached; } + static void setGlobalCache(const QDir d) //< set global cache path + { m_globalCache = d; } + static void setGlobalProxy(const QUrl p) //< set global proxy value + { m_globalProxy = p; } public slots: void abort(void); @@ -61,9 +66,9 @@ class HttpGet : public QObject void httpStarted(int); private: - QHttp http; + QHttp http; //< download object QFile *outputFile; - int response; + int response; //< http response int getRequest; QByteArray dataBuffer; bool outputToBuffer; @@ -72,6 +77,9 @@ class HttpGet : public QObject QDir m_cachedir; QString cachefile; bool cached; + QUrl m_proxy; + static QDir m_globalCache; //< global cache path value + static QUrl m_globalProxy; //< global proxy value }; #endif diff --git a/rbutil/rbutilqt/install.cpp b/rbutil/rbutilqt/install.cpp index 1d265404ea..bd59172870 100644 --- a/rbutil/rbutilqt/install.cpp +++ b/rbutil/rbutilqt/install.cpp @@ -37,13 +37,6 @@ void Install::setCached(bool cache) } -void Install::setProxy(QUrl proxy_url) -{ - proxy = proxy_url; - qDebug() << "Install::setProxy" << proxy; -} - - void Install::accept() { logger = new ProgressLoggerGui(this); @@ -92,7 +85,6 @@ void Install::accept() installer = new ZipInstaller(this); installer->setUrl(file); - installer->setProxy(proxy); installer->setLogSection("Rockbox (Base)"); if(!settings->cacheDisabled() && !ui.radioCurrent->isChecked() diff --git a/rbutil/rbutilqt/install.h b/rbutil/rbutilqt/install.h index 4d102a0e65..db4c06ced4 100644 --- a/rbutil/rbutilqt/install.h +++ b/rbutil/rbutilqt/install.h @@ -32,7 +32,6 @@ class Install : public QDialog Q_OBJECT public: Install(QWidget *parent = 0); - void setProxy(QUrl); void setSettings(RbSettings* sett); void setVersionStrings(QMap<QString, QString>); @@ -42,7 +41,6 @@ class Install : public QDialog private: Ui::InstallFrm ui; ProgressLoggerGui* logger; - QUrl proxy; RbSettings* settings; QHttp *download; QFile *target; diff --git a/rbutil/rbutilqt/installbootloader.cpp b/rbutil/rbutilqt/installbootloader.cpp index 4b78ee484b..3c6ca82c1b 100644 --- a/rbutil/rbutilqt/installbootloader.cpp +++ b/rbutil/rbutilqt/installbootloader.cpp @@ -203,8 +203,6 @@ bool BootloaderInstaller::downloadInfo() connect(infodownloader, SIGNAL(done(bool)), this, SLOT(infoDownloadDone(bool))); connect(infodownloader, SIGNAL(requestFinished(int, bool)), this, SLOT(infoRequestFinished(int, bool))); - infodownloader->setProxy(m_proxy); - qDebug() << "downloading bootloader info"; infodownloader->setFile(&bootloaderInfo); infodownloader->getFile(QUrl(m_bootloaderinfoUrl)); @@ -319,7 +317,6 @@ void BootloaderInstaller::gigabeatPrepare() downloadFile.close(); // get the real file. getter = new HttpGet(this); - getter->setProxy(m_proxy); getter->setFile(&downloadFile); getter->getFile(QUrl(url)); // connect signals from HttpGet @@ -462,7 +459,6 @@ void BootloaderInstaller::iaudioPrepare() downloadFile.close(); // get the real file. getter = new HttpGet(this); - getter->setProxy(m_proxy); getter->setFile(&downloadFile); getter->getFile(QUrl(url)); // connect signals from HttpGet @@ -519,7 +515,6 @@ void BootloaderInstaller::h10Prepare() downloadFile.close(); // get the real file. getter = new HttpGet(this); - getter->setProxy(m_proxy); getter->setFile(&downloadFile); getter->getFile(QUrl(url)); // connect signals from HttpGet @@ -672,7 +667,6 @@ void BootloaderInstaller::mrobe100Prepare() downloadFile.close(); // get the real file. getter = new HttpGet(this); - getter->setProxy(m_proxy); getter->setFile(&downloadFile); getter->getFile(QUrl(url)); // connect signals from HttpGet @@ -838,7 +832,6 @@ void BootloaderInstaller::ipodPrepare() downloadFile.close(); // get the real file. getter = new HttpGet(this); - getter->setProxy(m_proxy); getter->setFile(&downloadFile); getter->getFile(QUrl(url)); // connect signals from HttpGet @@ -1081,7 +1074,6 @@ void BootloaderInstaller::sansaPrepare() downloadFile.close(); // get the real file. getter = new HttpGet(this); - getter->setProxy(m_proxy); getter->setFile(&downloadFile); getter->getFile(QUrl(url)); // connect signals from HttpGet @@ -1270,7 +1262,6 @@ void BootloaderInstaller::iriverPrepare() downloadFile.close(); // get the real file. getter = new HttpGet(this); - getter->setProxy(m_proxy); getter->setFile(&downloadFile); getter->getFile(QUrl(url)); // connect signals from HttpGet diff --git a/rbutil/rbutilqt/installbootloader.h b/rbutil/rbutilqt/installbootloader.h index aea118cd7d..a026a35fad 100644 --- a/rbutil/rbutilqt/installbootloader.h +++ b/rbutil/rbutilqt/installbootloader.h @@ -51,7 +51,6 @@ public: void uninstall(ProgressloggerInterface* dp); void setMountPoint(QString mountpoint) {m_mountpoint = mountpoint;} - void setProxy(QUrl proxy) {m_proxy= proxy;} void setDevice(QString device) {m_device= device;} //!< the current plattform void setBootloaderMethod(QString method) {m_bootloadermethod= method;} void setBootloaderName(QString name){m_bootloadername= name;} @@ -116,7 +115,6 @@ private: QString m_mountpoint, m_device,m_bootloadermethod,m_bootloadername; QString m_bootloaderUrlBase,m_tempfilename,m_origfirmware; - QUrl m_proxy; QString m_bootloaderinfoUrl; bool m_install; diff --git a/rbutil/rbutilqt/installthemes.cpp b/rbutil/rbutilqt/installthemes.cpp index dac7710713..37e2d9ebd7 100644 --- a/rbutil/rbutilqt/installthemes.cpp +++ b/rbutil/rbutilqt/installthemes.cpp @@ -65,9 +65,8 @@ void ThemesInstallWindow::downloadInfo() url = QUrl(settings->themeUrl() + "/rbutilqt.php?res=" + resolution()); qDebug() << "downloadInfo()" << url; qDebug() << url.queryItems(); - getter->setProxy(proxy); if(settings->cacheOffline()) - getter->setCache(settings->cachePath()); + getter->setCache(true); getter->setFile(&themesInfo); getter->getFile(url); } @@ -172,9 +171,8 @@ void ThemesInstallWindow::updateDetails(int row) iniDetails.endGroup(); igetter.abort(); - igetter.setProxy(proxy); if(!settings->cacheDisabled()) - igetter.setCache(settings->cachePath()); + igetter.setCache(true); else { if(infocachedir=="") @@ -248,13 +246,6 @@ void ThemesInstallWindow::abort() } -void ThemesInstallWindow::setProxy(QUrl p) -{ - proxy = p; - qDebug() << "setProxy()" << proxy; -} - - void ThemesInstallWindow::acceptAll() { ui.listThemes->selectAll(); @@ -299,12 +290,11 @@ void ThemesInstallWindow::accept() installer = new ZipInstaller(this); installer->setUrl(themes); - installer->setProxy(proxy); installer->setLogSection(names); installer->setLogVersion(version); installer->setMountPoint(mountPoint); if(!settings->cacheDisabled()) - installer->setCache(settings->cachePath()); + installer->setCache(true); installer->install(logger); connect(logger, SIGNAL(closed()), this, SLOT(close())); } diff --git a/rbutil/rbutilqt/installthemes.h b/rbutil/rbutilqt/installthemes.h index 0f7d0f4a6b..0c71ff7376 100644 --- a/rbutil/rbutilqt/installthemes.h +++ b/rbutil/rbutilqt/installthemes.h @@ -37,7 +37,6 @@ class ThemesInstallWindow : public QDialog ThemesInstallWindow(QWidget* parent = 0); ~ThemesInstallWindow(); void setSettings(RbSettings* sett){settings=sett;} - void setProxy(QUrl); void downloadInfo(void); void show(void); @@ -52,7 +51,6 @@ class ThemesInstallWindow : public QDialog HttpGet igetter; QTemporaryFile themesInfo; QString resolution(void); - QUrl proxy; int currentItem; void resizeEvent(QResizeEvent*); QByteArray imgData; diff --git a/rbutil/rbutilqt/installzip.cpp b/rbutil/rbutilqt/installzip.cpp index 641b057175..3948e7ea75 100644 --- a/rbutil/rbutilqt/installzip.cpp +++ b/rbutil/rbutilqt/installzip.cpp @@ -25,7 +25,7 @@ ZipInstaller::ZipInstaller(QObject* parent): QObject(parent) { m_unzip = true; - m_cache = ""; + m_usecache = false; } @@ -86,10 +86,8 @@ void ZipInstaller::installStart() downloadFile->close(); // get the real file. getter = new HttpGet(this); - getter->setProxy(m_proxy); - if(m_cache.exists()) { - getter->setCache(m_cache); - + if(m_usecache) { + getter->setCache(true); } getter->setFile(downloadFile); getter->getFile(QUrl(m_url)); diff --git a/rbutil/rbutilqt/installzip.h b/rbutil/rbutilqt/installzip.h index 906fc21013..ece5d88072 100644 --- a/rbutil/rbutilqt/installzip.h +++ b/rbutil/rbutilqt/installzip.h @@ -39,7 +39,6 @@ public: void setMountPoint(QString mountpoint) {m_mountpoint = mountpoint;} void setUrl(QString url){m_urllist = QStringList(url);} void setUrl(QStringList url) { m_urllist = url; } - void setProxy(QUrl proxy) {m_proxy= proxy;} void setLogSection(QString name) {m_loglist = QStringList(name);} void setLogSection(QStringList name) { m_loglist = name; } void setLogVersion(QString v) { m_verlist = QStringList(v); qDebug() << m_verlist;} @@ -47,6 +46,7 @@ public: void setUnzip(bool i) { m_unzip = i; } void setTarget(QString t) { m_target = t; } void setCache(QDir c) { m_cache = c; }; + void setCache(bool c) { m_usecache = c; }; void setCache(QString c) { m_cache = QDir(c);} signals: @@ -63,11 +63,11 @@ private: void installSingle(ProgressloggerInterface *dp); QString m_url, m_file, m_mountpoint, m_logsection, m_logver; QStringList m_urllist, m_loglist, m_verlist; - QUrl m_proxy; bool m_unzip; QString m_target; int runner; QDir m_cache; + bool m_usecache; HttpGet *getter; QTemporaryFile *downloadFile; diff --git a/rbutil/rbutilqt/rbutilqt.cpp b/rbutil/rbutilqt/rbutilqt.cpp index becab29638..c3f088f0a6 100644 --- a/rbutil/rbutilqt/rbutilqt.cpp +++ b/rbutil/rbutilqt/rbutilqt.cpp @@ -56,8 +56,7 @@ RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent) settings->open(); // manual tab - updateManual(); - updateDevice(); + updateSettings(); ui.radioPdf->setChecked(true); // info tab @@ -132,9 +131,10 @@ void RbUtilQt::downloadInfo() connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool))); connect(daily, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool))); connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort())); - daily->setProxy(proxy()); if(settings->cacheOffline()) - daily->setCache(settings->cachePath()); + daily->setCache(true); + else + daily->setCache(false); qDebug() << "downloading build info"; daily->setFile(&buildInfo); daily->getFile(QUrl(settings->serverConfUrl())); @@ -159,9 +159,8 @@ void RbUtilQt::downloadDone(bool error) connect(bleeding, SIGNAL(done(bool)), this, SLOT(downloadBleedingDone(bool))); connect(bleeding, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool))); connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort())); - bleeding->setProxy(proxy()); if(settings->cacheOffline()) - bleeding->setCache(settings->cachePath()); + bleeding->setCache(true); bleeding->setFile(&bleedingInfo); bleeding->getFile(QUrl(settings->bleedingInfo())); @@ -252,6 +251,13 @@ void RbUtilQt::updateSettings() qDebug() << "updateSettings()"; updateDevice(); updateManual(); + if(settings->proxyType() == "system") { + HttpGet::setGlobalProxy(systemProxy()); + } + else if(settings->proxyType() == "manual") { + HttpGet::setGlobalProxy(settings->proxy()); + } + HttpGet::setGlobalCache(settings->cachePath()); } @@ -452,11 +458,10 @@ bool RbUtilQt::installAuto() ZipInstaller* installer = new ZipInstaller(this); installer->setUrl(file); - installer->setProxy(proxy()); installer->setLogSection("Rockbox (Base)"); installer->setLogVersion(myversion); if(!settings->cacheDisabled()) - installer->setCache(settings->cachePath()); + installer->setCache(true); installer->setMountPoint(settings->mountpoint()); installer->install(logger); @@ -469,7 +474,6 @@ void RbUtilQt::install() { Install *installWindow = new Install(this); installWindow->setSettings(settings); - installWindow->setProxy(proxy()); buildInfo.open(); QSettings info(buildInfo.fileName(), QSettings::IniFormat, this); @@ -516,7 +520,6 @@ void RbUtilQt::installBootloader() blinstaller->setMountPoint(settings->mountpoint()); - blinstaller->setProxy(proxy()); blinstaller->setDevice(platform); blinstaller->setBootloaderMethod(settings->curBootloaderMethod()); blinstaller->setBootloaderName(settings->curBootloaderName()); @@ -606,12 +609,11 @@ void RbUtilQt::installFonts() installer = new ZipInstaller(this); installer->setUrl(settings->fontUrl()); - installer->setProxy(proxy()); installer->setLogSection("Fonts"); installer->setLogVersion(versmap.value("arch_date")); installer->setMountPoint(settings->mountpoint()); if(!settings->cacheDisabled()) - installer->setCache(settings->cachePath()); + installer->setCache(true); installer->install(logger); } @@ -636,14 +638,13 @@ void RbUtilQt::installVoice() versmap.value("arch_date") + "-english.voice"; qDebug() << voiceurl; - installer->setProxy(proxy()); installer->setUrl(voiceurl); installer->setLogSection("Voice"); installer->setLogVersion(versmap.value("arch_date")); installer->setMountPoint(settings->mountpoint()); installer->setTarget("/.rockbox/langs/english.voice"); if(!settings->cacheDisabled()) - installer->setCache(settings->cachePath()); + installer->setCache(true); installer->install(logger); } @@ -684,12 +685,11 @@ void RbUtilQt::installDoom() installer = new ZipInstaller(this); installer->setUrl(settings->doomUrl()); - installer->setProxy(proxy()); installer->setLogSection("Game Addons"); installer->setLogVersion(versmap.value("arch_date")); installer->setMountPoint(settings->mountpoint()); if(!settings->cacheDisabled()) - installer->setCache(settings->cachePath()); + installer->setCache(true); installer->install(logger); } @@ -699,7 +699,6 @@ void RbUtilQt::installThemes() if(chkConfig(true)) return; ThemesInstallWindow* tw = new ThemesInstallWindow(this); tw->setSettings(settings); - tw->setProxy(proxy()); tw->setModal(true); tw->show(); } @@ -720,8 +719,7 @@ void RbUtilQt::createVoiceFile(void) if(chkConfig(true)) return; CreateVoiceWindow *installWindow = new CreateVoiceWindow(this); installWindow->setSettings(settings); - installWindow->setProxy(proxy()); - + installWindow->show(); connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo())); connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings())); @@ -747,7 +745,6 @@ void RbUtilQt::uninstallBootloader(void) logger->show(); BootloaderInstaller blinstaller(this); - blinstaller.setProxy(proxy()); blinstaller.setMountPoint(settings->mountpoint()); blinstaller.setDevice(settings->curPlatform()); blinstaller.setBootloaderMethod(settings->curBootloaderMethod()); @@ -802,8 +799,7 @@ void RbUtilQt::downloadManual(void) installer = new ZipInstaller(this); installer->setMountPoint(settings->mountpoint()); if(!settings->cacheDisabled()) - installer->setCache(settings->cachePath()); - installer->setProxy(proxy()); + installer->setCache(true); installer->setLogSection(section); installer->setLogVersion(date); installer->setUrl(manualurl); diff --git a/rbutil/rbutilqt/utils.cpp b/rbutil/rbutilqt/utils.cpp index ee7337b209..18aac68510 100644 --- a/rbutil/rbutilqt/utils.cpp +++ b/rbutil/rbutilqt/utils.cpp @@ -52,7 +52,7 @@ bool recRmdir( const QString &dirName ) } -//Function to get the system proxy +//! @brief get system proxy value. QUrl systemProxy(void) { #if defined(Q_OS_LINUX) diff --git a/rbutil/rbutilqt/voicefile.cpp b/rbutil/rbutilqt/voicefile.cpp index e2944eb79d..08b39fdfef 100644 --- a/rbutil/rbutilqt/voicefile.cpp +++ b/rbutil/rbutilqt/voicefile.cpp @@ -90,7 +90,6 @@ bool VoiceFileCreator::createVoiceFile(ProgressloggerInterface* logger) downloadFile->close(); // get the real file. getter = new HttpGet(this); - getter->setProxy(m_proxy); getter->setFile(downloadFile); getter->getFile(genlangUrl); diff --git a/rbutil/rbutilqt/voicefile.h b/rbutil/rbutilqt/voicefile.h index fb567b32de..611203a134 100644 --- a/rbutil/rbutilqt/voicefile.h +++ b/rbutil/rbutilqt/voicefile.h @@ -51,7 +51,6 @@ public: void setTargetId(int id){m_targetid = id;} void setLang(QString name){m_lang =name;} void setWavtrimThreshold(int th){m_wavtrimThreshold = th;} - void setProxy(QUrl proxy){m_proxy = proxy;} signals: void done(bool error); @@ -69,7 +68,6 @@ private: RbSettings* settings; HttpGet *getter; - QUrl m_proxy; //proxy QString filename; //the temporary file QString m_mountpoint; //mountpoint of the device |