diff options
author | Tim Jenssen <tim.jenssen@nokia.com> | 2012-04-24 18:42:28 +0200 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@nokia.com> | 2012-04-25 15:47:22 +0200 |
commit | e9d2d7640148e07feebf76e0e2d681c1ddf85f1a (patch) | |
tree | 785cfebc6c5a090327d9c6a86cd7849cffd75b38 /src/libs/installer/repository.cpp | |
parent | 3eb3be2e042a6c93007f8bf4a1b6079b4961d919 (diff) |
add the possibility to add a repository from script side
Change-Id: Ida419095138fcfb924210484c2bf2d1cb77fc55b
Reviewed-by: Karsten Heimrich <karsten.heimrich@nokia.com>
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 |