Commit e95a26db authored by Karel Slaný's avatar Karel Slaný

Generalised and isolated duplicated code.

parent 6b4d886a
......@@ -40,7 +40,6 @@ Accounts::Accounts(QObject *parent) : QObject(parent)
{
}
/* ========================================================================= */
/*
* Slot: Update new message counter.
......@@ -188,10 +187,10 @@ void Accounts::updateAccount(const QString &loginMetod,
qDebug("%s()", __func__);
if (acntName.isEmpty()) {
showErrorMessageBox(tr("Problem while updating account"),
WidgetMessageDialogue::errorMessage(QMessageBox::Critical,
tr("Problem while updating account"),
tr("Account name has not been specified!"),
tr("This field must be filled in."),
true);
tr("This field must be filled in."));
return;
}
......@@ -271,10 +270,10 @@ bool Accounts::createAccount(const QString &loginMetod,
qDebug("%s()", __func__);
if (userName.isEmpty() || acntName.isEmpty()) {
showErrorMessageBox(tr("Problem while creating account"),
WidgetMessageDialogue::errorMessage(QMessageBox::Critical,
tr("Problem while creating account"),
tr("User name or account name has not been specified!"),
tr("These fields must be filled in."),
true);
tr("These fields must be filled in."));
return false;
}
......@@ -291,10 +290,10 @@ bool Accounts::createAccount(const QString &loginMetod,
acntData.setCertPath(url.toLocalFile());
if (globAccountsModelPtr->addAccount(acntData) == -2) {
showErrorMessageBox(tr("Creating account: %1").arg(userName),
WidgetMessageDialogue::errorMessage(QMessageBox::Critical,
tr("Creating account: %1").arg(userName),
tr("Account '%1' could not be created.").arg(acntName),
tr("Account with user name '%1' already exists.").arg(userName),
true);
tr("Account with user name '%1' already exists.").arg(userName));
return false;
}
......@@ -364,20 +363,6 @@ void Accounts::loadModelCounters(void)
}
/* ========================================================================= */
/*
* Func: Show error message box.
*/
void Accounts::showErrorMessageBox(const QString &title,
const QString &text, const QString &informatinText, bool isError)
/* ========================================================================= */
{
WidgetMessageDialogue::message(
isError ? QMessageBox::Critical : QMessageBox::Warning,
title, text, informatinText, QMessageBox::Ok, QMessageBox::Ok);
}
/* ========================================================================= */
/*
* Func: Return string of account storage.
......
......@@ -133,18 +133,6 @@ signals:
void saveAccountResponse(void);
private:
/*!
* @brief Show error message box.
*
* @param[in] title - dialog title.
* @param[in] text - main dialog text.
* @param[in] informatinText - information text.
* @param[in] isError - true = error dialog, false = warning.
*/
void showErrorMessageBox(const QString &title,
const QString &text, const QString &informatinText, bool isError);
/*!
* @brief Return string of account storage.
*/
......
......@@ -73,3 +73,17 @@ int WidgetMessageDialogue::message(enum QMessageBox::Icon icon,
return execRet; /* Potentially clicked a standard button. */
}
void WidgetMessageDialogue::errorMessage(enum QMessageBox::Icon icon,
const QString &title, const QString &text, const QString &infoText)
{
WidgetMessageDialogue msgDlg(icon, title, text, QMessageBox::Ok);
if (!infoText.isEmpty()) {
msgDlg.setInformativeText(infoText);
}
msgDlg.setDefaultButton(QMessageBox::Ok);
msgDlg.exec();
}
......@@ -46,7 +46,17 @@ public:
/*!
* @brief Show message and await response.
*
* @return Dialogue code or standard button value.
* @param[in] icon Icon identifying importance of the message.
* @param[in] title Title of the dialogue window.
* @param[in] text Main message of the dialogue.
* @param[in] infoText Additional informative text.
* @param[in] buttons Standard buttons to be displayed.
* @param[in] dfltButton Identifies default action button.
* @param[in] customButtons List of pairs of custom button strings and values.
* @param[out] selected Value of selected custom button.
* @return Dialogue code or standard button value, -1 if custom button
* was selected and custom button was selected then \a selected is
* set to value of custom button.
*/
static
int message(enum QMessageBox::Icon icon, const QString &title,
......@@ -55,6 +65,18 @@ public:
enum QMessageBox::StandardButton dfltButton = QMessageBox::NoButton,
const QList< QPair<QString, int> > &customButtons = QList< QPair<QString, int> >(),
int *selected = Q_NULLPTR);
/*!
* @brief Show error message that can only be acknowledged.
*
* @param[in] icon Icon identifying importance of the message.
* @param[in] title Title of the dialogue window.
* @param[in] text Main message of the dialogue.
* @param[in] infoText Additional informative text.
*/
static
void errorMessage(enum QMessageBox::Icon icon, const QString &title,
const QString &text, const QString &infoText);
};
#endif /* _WIDGET_MESSAGE_DIALOGUE_H_ */
......@@ -34,6 +34,7 @@
#include "src/common.h"
#include "src/dialogues/qml_dialogue_helper.h"
#include "src/dialogues/qml_input_dialogue.h"
#include "src/dialogues/widget_message_dialogue.h"
#include "src/files.h"
#include "src/locker.h"
#include "src/net/isds_wrapper.h"
......@@ -350,11 +351,11 @@ int main(int argc, char *argv[])
arg(globSet.lastUpdateStr()), false, true);
}
} else {
emit isds.showErrorMessageBox(QObject::tr("Security problem"),
WidgetMessageDialogue::errorMessage(QMessageBox::Warning,
QObject::tr("Security problem"),
QObject::tr("OpenSSL support is required!"),
QObject::tr("The device does not support OpenSSL. "
"The application won't work correctly."),
false);
"The application won't work correctly."));
}
/* Deletion of messages from db is disabled when equal to 0. */
......
This diff is collapsed.
......@@ -104,17 +104,6 @@ public:
*/
void closeAllOtpConnections(void);
/*!
* @brief Show error message box.
*
* @param[in] title - dialog title.
* @param[in] text - main dialog text.
* @param[in] informatinText - information text.
* @param[in] isError - true = error dialog, false = warning.
*/
void showErrorMessageBox(const QString &title, const QString &text,
const QString &informatinText, bool isError);
signals:
/*!
* @brief Set new statusbar text and active busy indicator to QML.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment