1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #3266

Diadlo (2):
      fix(i18n): Divide getting and translating Toxme error message
      feat(profileform): Added log toxme errors
This commit is contained in:
sudden6 2016-05-11 12:29:48 +02:00
commit e797bf9582
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
3 changed files with 56 additions and 13 deletions

View File

@ -288,21 +288,65 @@ Toxme::ExecCode Toxme::deleteAddress(QString server, ToxId id)
return extractError(response); return extractError(response);
} }
/**
* @brief Return string of the corresponding error code
* @param errorCode Code to get error message
* @return Source error message
*/
QString Toxme::getErrorMessage(int errorCode) QString Toxme::getErrorMessage(int errorCode)
{ {
switch (errorCode) { switch (errorCode) {
case IncorrectResponse: case IncorrectResponse:
return QObject::tr("Incorrect response"); return "Incorrect response";
case NoPassword: case NoPassword:
return QObject::tr("No password in response"); return "No password in response";
case ServerError:
return "Server doesn't support Toxme";
case -1:
return "You must send POST requests to /api";
case -2:
return "Problem with HTTPS connection";
case -3:
return "I was unable to read your encrypted payload";
case -4:
return "You're making too many requests. Wait an hour and try again";
case -25:
return "This name is already in use";
case -26:
return "This Tox ID is already registered under another name";
case -27:
return "Please don't use a space in your name";
case -28:
return "Password incorrect";
case -29:
return "You can't use this name";
case -30:
return "Name not found";
case -31:
return "Tox ID not sent";
case -41:
return "Lookup failed because the server replied with invalid data";
case -42:
return "That user does not exist";
case -43:
return "Internal lookup error. Please file a bug";
default:
return QString("Unknown error (%1)").arg(errorCode);
}
}
/**
* @brief Return translated error message
* @param errorCode Code to translate
* @return Translated Toxme error message
*/
QString Toxme::translateErrorMessage(int errorCode)
{
switch (errorCode) {
case ServerError: case ServerError:
return QObject::tr("Server doesn't support Toxme"); return QObject::tr("Server doesn't support Toxme");
case -1:
return QObject::tr("You must send POST requests to /api");
case -2: case -2:
return QObject::tr("Please try again using a HTTPS connection"); return QObject::tr("Problem with HTTPS connection");
case -3:
return QObject::tr("I was unable to read your encrypted payload");
case -4: case -4:
return QObject::tr("You're making too many requests. Wait an hour and try again"); return QObject::tr("You're making too many requests. Wait an hour and try again");
case -25: case -25:
@ -319,13 +363,9 @@ QString Toxme::getErrorMessage(int errorCode)
return QObject::tr("Name not found"); return QObject::tr("Name not found");
case -31: case -31:
return QObject::tr("Tox ID not sent"); return QObject::tr("Tox ID not sent");
case -41:
return QObject::tr("Lookup failed because the server replied with invalid data");
case -42: case -42:
return QObject::tr("That user does not exist"); return QObject::tr("That user does not exist");
case -43:
return QObject::tr("Internal lookup error. Please file a bug");
default: default:
return QObject::tr("Unknown error (%1)").arg(errorCode); return QObject::tr("Internal ToxMe error");
} }
} }

View File

@ -57,6 +57,7 @@ public:
static ExecCode deleteAddress(QString server, ToxId id); static ExecCode deleteAddress(QString server, ToxId id);
/// Return string of the corresponding error code /// Return string of the corresponding error code
static QString getErrorMessage(int errorCode); static QString getErrorMessage(int errorCode);
static QString translateErrorMessage(int errorCode);
private: private:
Toxme()=delete; Toxme()=delete;

View File

@ -520,7 +520,9 @@ void ProfileForm::onRegisterButtonClicked()
break; break;
default: default:
QString errorMessage = Toxme::getErrorMessage(code); QString errorMessage = Toxme::getErrorMessage(code);
GUI::showWarning(tr("Toxme error"), errorMessage); qWarning() << errorMessage;
QString translated = Toxme::translateErrorMessage(code);
GUI::showWarning(tr("Toxme error"), translated);
} }
bodyUI->toxmeRegisterButton->setEnabled(true); bodyUI->toxmeRegisterButton->setEnabled(true);