Gerrit: Replace magic numbers with an enum

Change-Id: I591716865831877eda4a17e9c85169935d633b09
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
Orgad Shaneh
2017-04-24 23:06:10 +03:00
committed by Orgad Shaneh
parent 3624a663d8
commit 46b7701398

View File

@@ -52,6 +52,14 @@ static const char userNameKey[] = "UserName";
static const char fullNameKey[] = "FullName"; static const char fullNameKey[] = "FullName";
static const char isAuthenticatedKey[] = "IsAuthenticated"; static const char isAuthenticatedKey[] = "IsAuthenticated";
enum ErrorCodes
{
Success = 200,
UnknownError = 400,
AuthenticationFailure = 401,
PageNotFound = 404
};
bool GerritUser::isSameAs(const GerritUser &other) const bool GerritUser::isSameAs(const GerritUser &other) const
{ {
if (!userName.isEmpty() && !other.userName.isEmpty()) if (!userName.isEmpty() && !other.userName.isEmpty())
@@ -230,13 +238,13 @@ int GerritServer::testConnection()
if (!userName.isEmpty()) if (!userName.isEmpty())
user.userName = userName; user.userName = userName;
} }
return 200; return Success;
} }
const QRegularExpression errorRegexp("returned error: (\\d+)"); const QRegularExpression errorRegexp("returned error: (\\d+)");
QRegularExpressionMatch match = errorRegexp.match(resp.stdErr()); QRegularExpressionMatch match = errorRegexp.match(resp.stdErr());
if (match.hasMatch()) if (match.hasMatch())
return match.captured(1).toInt(); return match.captured(1).toInt();
return 400; return UnknownError;
} }
bool GerritServer::setupAuthentication() bool GerritServer::setupAuthentication()
@@ -262,12 +270,12 @@ bool GerritServer::resolveRoot()
{ {
for (;;) { for (;;) {
switch (testConnection()) { switch (testConnection()) {
case 200: case Success:
saveSettings(Valid); saveSettings(Valid);
return true; return true;
case 401: case AuthenticationFailure:
return setupAuthentication(); return setupAuthentication();
case 404: case PageNotFound:
if (!ascendPath()) { if (!ascendPath()) {
saveSettings(NotGerrit); saveSettings(NotGerrit);
return false; return false;