diff options
Diffstat (limited to 'src/libs/installer/repository.cpp')
-rw-r--r-- | src/libs/installer/repository.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libs/installer/repository.cpp b/src/libs/installer/repository.cpp index cc80a20d9..8842a7899 100644 --- a/src/libs/installer/repository.cpp +++ b/src/libs/installer/repository.cpp @@ -32,6 +32,9 @@ #include "repository.h" +#include <QFileInfo> +#include <QStringList> + namespace QInstaller { /* @@ -69,6 +72,33 @@ Repository::Repository(const QUrl &url, bool isDefault) } /*! + Constructs a new repository by setting it's address to \a repositoryUrl as string and it's + default state. + + Note: user and password can be inside the \a repositoryUrl string: http://user:password@repository.url +*/ +Repository Repository::fromUserInput(const QString &repositoryUrl, bool isDefault) +{ + QStringList supportedShemes; + supportedShemes << QLatin1String("http") << QLatin1String("https") << QLatin1String("ftp") << + QLatin1String("file"); + + QUrl url = QUrl::fromUserInput(repositoryUrl); + if (!supportedShemes.contains(url.scheme()) && QFileInfo(url.toString()).exists()) + url = QLatin1String("file:///") + url.toString(); + + QString userName = url.userName(); + QString password = url.password(); + url.setUserName(QString()); + url.setPassword(QString()); + + Repository repository(url, isDefault); + repository.setUsername(userName); + repository.setPassword(password); + return repository; +} + +/*! Returns true if the repository URL is valid; otherwise returns false. Note: The URL is simply run through a conformance test. It is not checked that the repository |