diff --git a/src/plugins/git/gerrit/gerritserver.cpp b/src/plugins/git/gerrit/gerritserver.cpp index ea80e8d6e2b..babe4fd0f47 100644 --- a/src/plugins/git/gerrit/gerritserver.cpp +++ b/src/plugins/git/gerrit/gerritserver.cpp @@ -29,12 +29,14 @@ #include "../gitplugin.h" #include "../gitclient.h" +#include #include #include #include #include #include +#include using namespace Utils; using namespace Git::Internal; @@ -44,6 +46,11 @@ namespace Internal { static const char defaultHostC[] = "codereview.qt-project.org"; static const char accountUrlC[] = "/accounts/self"; +static const char isGerritKey[] = "IsGerrit"; +static const char rootPathKey[] = "RootPath"; +static const char userNameKey[] = "UserName"; +static const char fullNameKey[] = "FullName"; +static const char isAuthenticatedKey[] = "IsAuthenticated"; bool GerritUser::isSameAs(const GerritUser &other) const { @@ -136,12 +143,60 @@ bool GerritServer::fillFromRemote(const QString &remote, const GerritParameters curlBinary = parameters.curl; if (curlBinary.isEmpty() || !QFile::exists(curlBinary)) return false; - rootPath = r.path; - // Strip the last part of the path, which is always the repo name - // The rest of the path needs to be inspected to find the root path - // (can be http://example.net/review) - ascendPath(); - return resolveRoot(); + switch (loadSettings()) { + case Invalid: + rootPath = r.path; + // Strip the last part of the path, which is always the repo name + // The rest of the path needs to be inspected to find the root path + // (can be http://example.net/review) + ascendPath(); + return resolveRoot(); + case NotGerrit: + return false; + case Valid: + return true; + } + return true; +} + +GerritServer::StoredHostValidity GerritServer::loadSettings() +{ + StoredHostValidity validity = Invalid; + QSettings *settings = Core::ICore::settings(); + settings->beginGroup("Gerrit/" + host); + if (!settings->value(isGerritKey, true).toBool()) { + validity = NotGerrit; + } else if (settings->contains(isAuthenticatedKey)) { + rootPath = settings->value(rootPathKey).toString(); + user.userName = settings->value(userNameKey).toString(); + user.fullName = settings->value(fullNameKey).toString(); + authenticated = settings->value(isAuthenticatedKey).toBool(); + validity = Valid; + } + settings->endGroup(); + return validity; +} + +void GerritServer::saveSettings(StoredHostValidity validity) const +{ + QSettings *settings = Core::ICore::settings(); + settings->beginGroup("Gerrit/" + host); + switch (validity) { + case NotGerrit: + settings->setValue(isGerritKey, false); + break; + case Valid: + settings->setValue(rootPathKey, rootPath); + settings->setValue(userNameKey, user.userName); + settings->setValue(fullNameKey, user.fullName); + settings->setValue(isAuthenticatedKey, authenticated); + break; + case Invalid: + settings->clear(); + break; + } + + settings->endGroup(); } QStringList GerritServer::curlArguments() @@ -182,6 +237,7 @@ bool GerritServer::setupAuthentication() if (!dialog.exec()) return false; authenticated = dialog.isAuthenticated(); + saveSettings(Valid); return true; } @@ -199,12 +255,15 @@ bool GerritServer::resolveRoot() for (;;) { switch (testConnection()) { case 200: + saveSettings(Valid); return true; case 401: return setupAuthentication(); case 404: - if (!ascendPath()) + if (!ascendPath()) { + saveSettings(NotGerrit); return false; + } break; default: // unknown error - fail return false; diff --git a/src/plugins/git/gerrit/gerritserver.h b/src/plugins/git/gerrit/gerritserver.h index b24c0248514..dad3a790851 100644 --- a/src/plugins/git/gerrit/gerritserver.h +++ b/src/plugins/git/gerrit/gerritserver.h @@ -61,6 +61,13 @@ public: RestUrl }; + enum StoredHostValidity + { + Invalid, + NotGerrit, + Valid + }; + GerritServer(); GerritServer(const QString &host, unsigned short port, const QString &userName, HostType type); bool operator==(const GerritServer &other) const; @@ -68,6 +75,8 @@ public: QString hostArgument() const; QString url(UrlType urlType = DefaultUrl) const; bool fillFromRemote(const QString &remote, const GerritParameters ¶meters); + StoredHostValidity loadSettings(); + void saveSettings(StoredHostValidity validity) const; int testConnection(); static QStringList curlArguments();