summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@digia.com>2014-03-05 11:48:57 +0100
committerKarsten Heimrich <karsten.heimrich@digia.com>2014-03-25 14:12:41 +0100
commitd2815ad5a6d836bd67f1002b1a6fe2733e9b1b79 (patch)
treeb51561fa5057e742e81f393bf6badb10e9d0627b
parentdc70e9b9bbe086dee04640c4196eabf9c91b05be (diff)
Unify access to the supported schemes.
Fixes an issue that https downloaded files where not properly named and put in the right temporary download directory. Change-Id: I8a973e8b63cfae2f575d84591a8ebbef53d45a3a Reviewed-by: Niels Weber <niels.weber@digia.com> Reviewed-by: Karsten Heimrich <karsten.heimrich@digia.com>
-rw-r--r--src/libs/installer/downloadarchivesjob.cpp7
-rw-r--r--src/libs/installer/repository.cpp6
-rw-r--r--src/libs/kdtools/kdupdaterfiledownloader.cpp2
-rw-r--r--src/libs/kdtools/kdupdaterfiledownloaderfactory.cpp21
-rw-r--r--src/libs/kdtools/kdupdaterfiledownloaderfactory.h14
-rw-r--r--src/sdk/installerbase_p.cpp11
6 files changed, 32 insertions, 29 deletions
diff --git a/src/libs/installer/downloadarchivesjob.cpp b/src/libs/installer/downloadarchivesjob.cpp
index 82f9b365c..620eedd60 100644
--- a/src/libs/installer/downloadarchivesjob.cpp
+++ b/src/libs/installer/downloadarchivesjob.cpp
@@ -319,10 +319,9 @@ KDUpdater::FileDownloader *DownloadArchivesJob::setupDownloader(const QString &s
Qt::QueuedConnection);
connect(downloader, SIGNAL(downloadStatus(QString)), this, SIGNAL(downloadStatusChanged(QString)));
- if (scheme == QLatin1String("http") || scheme == QLatin1String("ftp") ||
- scheme == QLatin1String("file")) {
- downloader->setDownloadedFileName(component->localTempPath() + QLatin1String("/")
- + component->name() + QLatin1String("/") + fi.fileName() + suffix);
+ if (FileDownloaderFactory::isSupportedScheme(scheme)) {
+ downloader->setDownloadedFileName(component->localTempPath() + QLatin1Char('/')
+ + component->name() + QLatin1Char('/') + fi.fileName() + suffix);
}
QString message = tr("Downloading archive hash for component: %1");
diff --git a/src/libs/installer/repository.cpp b/src/libs/installer/repository.cpp
index 786cb2a49..261bdaac9 100644
--- a/src/libs/installer/repository.cpp
+++ b/src/libs/installer/repository.cpp
@@ -40,6 +40,7 @@
**************************************************************************/
#include "repository.h"
+#include "kdupdaterfiledownloaderfactory.h"
#include <QFileInfo>
#include <QStringList>
@@ -89,11 +90,8 @@ Repository::Repository(const QUrl &url, bool isDefault)
*/
Repository Repository::fromUserInput(const QString &repositoryUrl)
{
- QStringList supportedSchemes;
- supportedSchemes << QLatin1String("http") << QLatin1String("https") << QLatin1String("ftp") <<
- QLatin1String("file");
-
QUrl url = QUrl::fromUserInput(repositoryUrl);
+ const QStringList supportedSchemes = KDUpdater::FileDownloaderFactory::supportedSchemes();
if (!supportedSchemes.contains(url.scheme()) && QFileInfo(url.toString()).exists())
url = QLatin1String("file:///") + url.toString();
diff --git a/src/libs/kdtools/kdupdaterfiledownloader.cpp b/src/libs/kdtools/kdupdaterfiledownloader.cpp
index 95b574b2f..cbd4ee184 100644
--- a/src/libs/kdtools/kdupdaterfiledownloader.cpp
+++ b/src/libs/kdtools/kdupdaterfiledownloader.cpp
@@ -714,7 +714,7 @@ QString KDUpdater::ResourceFileDownloader::downloadedFileName() const
void KDUpdater::ResourceFileDownloader::setDownloadedFileName(const QString &/*name*/)
{
- Q_ASSERT_X(false, "KDUpdater::ResourceFileDownloader::setDownloadedFileName", "Not supported!");
+ // Not supported!
}
KDUpdater::ResourceFileDownloader *KDUpdater::ResourceFileDownloader::clone(QObject *parent) const
diff --git a/src/libs/kdtools/kdupdaterfiledownloaderfactory.cpp b/src/libs/kdtools/kdupdaterfiledownloaderfactory.cpp
index 7f6e72efb..92dff42ee 100644
--- a/src/libs/kdtools/kdupdaterfiledownloaderfactory.cpp
+++ b/src/libs/kdtools/kdupdaterfiledownloaderfactory.cpp
@@ -59,16 +59,6 @@
using namespace KDUpdater;
-struct FileDownloaderFactory::FileDownloaderFactoryData
-{
- FileDownloaderFactoryData() : m_factory(0) {}
- ~FileDownloaderFactoryData() { delete m_factory; }
-
- bool m_followRedirects;
- bool m_ignoreSslErrors;
- FileDownloaderProxyFactory *m_factory;
-};
-
FileDownloaderFactory& FileDownloaderFactory::instance()
{
static KDUpdater::FileDownloaderFactory theFactory;
@@ -129,6 +119,17 @@ FileDownloaderFactory::~FileDownloaderFactory()
delete d;
}
+QStringList FileDownloaderFactory::supportedSchemes()
+{
+ return FileDownloaderFactory::instance().d->m_supportedSchemes;
+}
+
+bool FileDownloaderFactory::isSupportedScheme(const QString &scheme)
+{
+ return FileDownloaderFactory::instance().d->m_supportedSchemes.contains(scheme
+ , Qt::CaseInsensitive);
+}
+
/*!
Returns a new instance to the \ref KDUpdater::FileDownloader based whose scheme is equal to the string
passed as parameter to this function.
diff --git a/src/libs/kdtools/kdupdaterfiledownloaderfactory.h b/src/libs/kdtools/kdupdaterfiledownloaderfactory.h
index a4338e3ce..5377923fe 100644
--- a/src/libs/kdtools/kdupdaterfiledownloaderfactory.h
+++ b/src/libs/kdtools/kdupdaterfiledownloaderfactory.h
@@ -68,6 +68,15 @@ class KDTOOLS_EXPORT FileDownloaderProxyFactory : public QNetworkProxyFactory
class KDTOOLS_EXPORT FileDownloaderFactory : public KDGenericFactory<FileDownloader>
{
Q_DISABLE_COPY(FileDownloaderFactory)
+ struct FileDownloaderFactoryData {
+ FileDownloaderFactoryData() : m_factory(0) {}
+ ~FileDownloaderFactoryData() { delete m_factory; }
+
+ bool m_followRedirects;
+ bool m_ignoreSslErrors;
+ QStringList m_supportedSchemes;
+ FileDownloaderProxyFactory *m_factory;
+ };
public:
static FileDownloaderFactory &instance();
@@ -77,6 +86,7 @@ public:
void registerFileDownloader(const QString &scheme)
{
registerProduct<T>(scheme);
+ d->m_supportedSchemes.append(scheme);
}
FileDownloader *create(const QString &scheme, QObject *parent = 0) const;
@@ -88,11 +98,13 @@ public:
static bool ignoreSslErrors();
static void setIgnoreSslErrors(bool ignore);
+ static QStringList supportedSchemes();
+ static bool isSupportedScheme(const QString &scheme);
+
private:
FileDownloaderFactory();
private:
- struct FileDownloaderFactoryData;
FileDownloaderFactoryData *d;
};
diff --git a/src/sdk/installerbase_p.cpp b/src/sdk/installerbase_p.cpp
index 2c79e0dde..57de0dc5d 100644
--- a/src/sdk/installerbase_p.cpp
+++ b/src/sdk/installerbase_p.cpp
@@ -79,13 +79,6 @@ InstallerBase::~InstallerBase()
{
}
-static bool supportedScheme(const QString &scheme)
-{
- if (scheme == QLatin1String("http") || scheme == QLatin1String("ftp") || scheme == QLatin1String("file"))
- return true;
- return false;
-}
-
int InstallerBase::replaceMaintenanceToolBinary(QStringList arguments)
{
QInstaller::setVerbose(arguments.contains(QLatin1String("--verbose"))
@@ -96,7 +89,7 @@ int InstallerBase::replaceMaintenanceToolBinary(QStringList arguments)
arguments.removeAll(QLatin1String("--update-installerbase"));
QUrl url = arguments.value(1);
- if (!supportedScheme(url.scheme()) && QFileInfo(url.toString()).exists())
+ if (!FileDownloaderFactory::isSupportedScheme(url.scheme()) && QFileInfo(url.toString()).exists())
url = QLatin1String("file:///") + url.toString();
m_downloader.reset(FileDownloaderFactory::instance().create(url.scheme(), 0));
if (m_downloader.isNull()) {
@@ -107,7 +100,7 @@ int InstallerBase::replaceMaintenanceToolBinary(QStringList arguments)
m_downloader->setAutoRemoveDownloadedFile(true);
QString target = QDir::tempPath() + QLatin1String("/") + QFileInfo(arguments.at(1)).fileName();
- if (supportedScheme(url.scheme()))
+ if (FileDownloaderFactory::isSupportedScheme(url.scheme()))
m_downloader->setDownloadedFileName(target);
connect(m_downloader.data(), SIGNAL(downloadStarted()), this, SLOT(downloadStarted()));