From 79d114b13c326c2f11c6b2f13593ce4227df4a46 Mon Sep 17 00:00:00 2001 From: Karel Slany Date: Fri, 24 Mar 2017 21:43:33 +0100 Subject: [PATCH] Hid the widget-based implementation of WidgetMessageDialogue::message(). --- mobile-datovka.pro | 4 +- src/accounts.cpp | 15 +- src/dialogues/dialogues.cpp | 219 ++++++++++++++++++ .../{input_dialogue.h => dialogues.h} | 72 +++++- src/dialogues/input_dialogue.cpp | 79 ------- src/files.cpp | 25 +- src/main.cpp | 4 +- src/messages.cpp | 17 +- src/net/isds_session.cpp | 4 +- src/net/isds_wrapper.cpp | 54 ++--- src/net/net_layer.cpp | 19 +- src/setwrapper.cpp | 7 +- 12 files changed, 353 insertions(+), 166 deletions(-) create mode 100644 src/dialogues/dialogues.cpp rename src/dialogues/{input_dialogue.h => dialogues.h} (51%) delete mode 100644 src/dialogues/input_dialogue.cpp diff --git a/mobile-datovka.pro b/mobile-datovka.pro index edf288f..265a2b1 100644 --- a/mobile-datovka.pro +++ b/mobile-datovka.pro @@ -83,7 +83,7 @@ TRANSLATIONS_FILES += \ SOURCES += \ src/accounts.cpp \ - src/dialogues/input_dialogue.cpp \ + src/dialogues/dialogues.cpp \ src/dialogues/qml_dialogue_helper.cpp \ src/dialogues/qml_input_dialogue.cpp \ src/dialogues/widget_input_dialogue.cpp \ @@ -120,7 +120,7 @@ SOURCES += \ HEADERS += \ src/accounts.h \ src/common.h \ - src/dialogues/input_dialogue.h \ + src/dialogues/dialogues.h \ src/dialogues/qml_dialogue_helper.h \ src/dialogues/qml_input_dialogue.h \ src/dialogues/widget_input_dialogue.h \ diff --git a/src/accounts.cpp b/src/accounts.cpp index d96be6d..aee7ecf 100644 --- a/src/accounts.cpp +++ b/src/accounts.cpp @@ -27,7 +27,7 @@ #include "src/accounts.h" #include "src/common.h" -#include "src/dialogues/widget_message_dialogue.h" +#include "src/dialogues/dialogues.h" #include "src/net/isds_wrapper.h" #include "src/net/isds_session.h" #include "src/settings.h" @@ -110,13 +110,12 @@ bool Accounts::removeAccount(const QString &userName, bool showDialog) qDebug("%s()", __func__); if (showDialog) { - int msgResponse = WidgetMessageDialogue::message( - QMessageBox::Question, + int msgResponse = Dialogues::message(Dialogues::QUESTION, tr("Remove account: %1").arg(userName), tr("Do you want to remove the account '%1'?").arg(userName), tr("Note: It will also remove all related local databases and account information."), - QMessageBox::No | QMessageBox::Yes, QMessageBox::No); - if (msgResponse == QMessageBox::No) { + Dialogues::NO | Dialogues::YES, Dialogues::NO); + if (msgResponse == Dialogues::NO) { return false; } } @@ -187,7 +186,7 @@ void Accounts::updateAccount(const QString &loginMetod, qDebug("%s()", __func__); if (acntName.isEmpty()) { - WidgetMessageDialogue::errorMessage(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("Problem while updating account"), tr("Account name has not been specified!"), tr("This field must be filled in.")); @@ -270,7 +269,7 @@ bool Accounts::createAccount(const QString &loginMetod, qDebug("%s()", __func__); if (userName.isEmpty() || acntName.isEmpty()) { - WidgetMessageDialogue::errorMessage(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("Problem while creating account"), tr("User name or account name has not been specified!"), tr("These fields must be filled in.")); @@ -290,7 +289,7 @@ bool Accounts::createAccount(const QString &loginMetod, acntData.setCertPath(url.toLocalFile()); if (globAccountsModelPtr->addAccount(acntData) == -2) { - WidgetMessageDialogue::errorMessage(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::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)); diff --git a/src/dialogues/dialogues.cpp b/src/dialogues/dialogues.cpp new file mode 100644 index 0000000..ce0eae2 --- /dev/null +++ b/src/dialogues/dialogues.cpp @@ -0,0 +1,219 @@ +/* + * Copyright (C) 2014-2017 CZ.NIC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations including + * the two. + */ + +#if !defined(Q_OS_IOS) +#define USE_QML_DIALOGUES 1 +#endif /* !defined(Q_OS_IOS) */ + +#include + +#include "src/dialogues/dialogues.h" +#include "src/dialogues/qml_input_dialogue.h" +#include "src/dialogues/widget_input_dialogue.h" +#include "src/dialogues/widget_message_dialogue.h" + +#if !defined(USE_QML_DIALOGUES) +/*! + * @brief Converts echo mode from helper class definition. + * + * @param[in] echoMode Echo mode as defined in QmlDlgHelper. + * @return Echo mode as defined in QLineEdit. + */ +static +QLineEdit::EchoMode toLineEditEchoMode( + enum QmlDlgHelper::QmlDlgEchoMode echoMode) +{ + switch (echoMode) { + case QmlDlgHelper::EM_NORMAL: + return QLineEdit::Normal; + break; + case QmlDlgHelper::EM_PWD: + return QLineEdit::NoEcho; + break; + case QmlDlgHelper::EM_NOECHO: + return QLineEdit::Password; + break; + case QmlDlgHelper::EM_PWD_ECHOONEDIT: + return QLineEdit::PasswordEchoOnEdit; + break; + default: + Q_ASSERT(0); + return QLineEdit::Normal; + break; + } +} +#endif /* !defined(USE_QML_DIALOGUES) */ + +/*! + * @brief Converts dialogue icon from helper class definition. + * + * @param[in] icon Icon as used in Dialogues. + * @return Icon as used in WidgetMessageDialogue. + */ +static +enum QMessageBox::Icon toMessageBoxIcon(enum Dialogues::Icon icon) +{ + switch (icon) { + case Dialogues::NO_ICON: + return QMessageBox::NoIcon; + break; + case Dialogues::QUESTION: + return QMessageBox::Question; + break; + case Dialogues::INFORMATION: + return QMessageBox::Information; + break; + case Dialogues::WARNING: + return QMessageBox::Warning; + break; + case Dialogues::CRITICAL: + return QMessageBox::Critical; + break; + default: + Q_ASSERT(0); + return QMessageBox::NoIcon; + break; + } +} + +/*! + * @brief Converts dialogue button from helper class definition. + * + * @param[in] button Button as used in Dialogues. + * @return Button as used in WidgetMessageDialogue. + */ +static +enum QMessageBox::StandardButton toMessageBoxButton( + enum Dialogues::Button button) +{ + switch (button) { + case Dialogues::OK: + return QMessageBox::Ok; + break; + case Dialogues::CANCEL: + return QMessageBox::Cancel; + break; + case Dialogues::YES: + return QMessageBox::Yes; + break; + case Dialogues::NO: + return QMessageBox::No; + break; + case Dialogues::NO_BUTTON: + return QMessageBox::NoButton; + break; + default: + Q_ASSERT(0); + return QMessageBox::NoButton; + break; + } +} + +/*! + * @brief Concerts return value from message dialogue. + * + * @param[in] retVal Return value as returned by message dialogue. + * @return Converted value. + */ +static +int toDialogueRetVal(int retVal) +{ + switch (retVal) { + case -1: + return -1; + break; + case QMessageBox::Ok: + return Dialogues::OK; + break; + case QMessageBox::Cancel: + return Dialogues::CANCEL; + break; + case QMessageBox::Yes: + return Dialogues::YES; + break; + case QMessageBox::No: + return Dialogues::NO; + break; + case QMessageBox::NoButton: + return Dialogues::NO_BUTTON; + break; + default: + Q_ASSERT(0); + return retVal; + break; + } +} + +/*! + * @brief Converts dialogue button from helper class definition. + * + * @param[in] button Button as used in Dialogues. + * @return Button as used in WidgetMessageDialogue. + */ +static +QMessageBox::StandardButtons toMessageBoxButtons(Dialogues::Buttons buttons) +{ + QMessageBox::StandardButtons outButtons = QMessageBox::NoButton; + + outButtons |= (buttons & Dialogues::OK) ? QMessageBox::Ok : QMessageBox::NoButton; + outButtons |= (buttons & Dialogues::CANCEL) ? QMessageBox::Cancel : QMessageBox::NoButton; + outButtons |= (buttons & Dialogues::YES) ? QMessageBox::Yes : QMessageBox::NoButton; + outButtons |= (buttons & Dialogues::NO) ? QMessageBox::No : QMessageBox::NoButton; + + return outButtons; +} + +QString Dialogues::getText(QObject *parent, const QString &title, + const QString &message, enum QmlDlgHelper::QmlDlgEchoMode echoMode, + const QString &text, const QString &placeholderText, bool *ok, + Qt::InputMethodHints inputMethodHints) +{ +#if defined(USE_QML_DIALOGUES) + return QmlInputDialogue::getText(qobject_cast(parent), + title, message, echoMode, text, placeholderText, ok, + inputMethodHints); +#else /* !defined(USE_QML_DIALOGUES) */ + Q_UNUSED(placeholderText); + return WidgetInputDialogue::getText(qobject_cast(parent), + title, message, toLineEditEchoMode(echoMode), text, ok, + Qt::Dialog, inputMethodHints); +#endif /* defined(USE_QML_DIALOGUES) */ +} + +int Dialogues::message(enum Icon icon, const QString &title, + const QString &text, const QString &infoText, + Buttons buttons, enum Button dfltButton, + const QList< QPair > &customButtons, int *selected) +{ + return toDialogueRetVal( + WidgetMessageDialogue::message(toMessageBoxIcon(icon), title, + text, infoText, toMessageBoxButtons(buttons), + toMessageBoxButton(dfltButton), customButtons, selected)); +} + +void Dialogues::errorMessage(enum Icon icon, const QString &title, + const QString &text, const QString &infoText) +{ + WidgetMessageDialogue::errorMessage(toMessageBoxIcon(icon), title, + text, infoText); +} diff --git a/src/dialogues/input_dialogue.h b/src/dialogues/dialogues.h similarity index 51% rename from src/dialogues/input_dialogue.h rename to src/dialogues/dialogues.h index 7ba7efe..bdfef34 100644 --- a/src/dialogues/input_dialogue.h +++ b/src/dialogues/dialogues.h @@ -21,27 +21,49 @@ * the two. */ -#ifndef _INPUT_DIALOGUE_H_ -#define _INPUT_DIALOGUE_H_ +#ifndef _DIALOGUES_H_ +#define _DIALOGUES_H_ #include -#include #include "src/dialogues/qml_dialogue_helper.h" /*! - * @brief Encapsulates input dialogues. + * @brief Encapsulates dialogues. */ -class InputDialogue : public QObject { +class Dialogues : public QObject { Q_OBJECT private: /*! * @brief Private constructor. */ - explicit InputDialogue(QObject *parent = Q_NULLPTR); + explicit Dialogues(QObject *parent = Q_NULLPTR); public: + /*! + * @brief Dialogue icon decoration. + */ + enum Icon { + NO_ICON, + QUESTION, + INFORMATION, + WARNING, + CRITICAL + }; + + /*! + * @brief Dialogue button declaration. + */ + enum Button { + OK = 0x00000400, + CANCEL = 0x00400000, + YES = 0x00004000, + NO = 0x00010000, + NO_BUTTON = 0x00000000 + }; + Q_DECLARE_FLAGS(Buttons, Button) + /*! * @brief Generates a text edit dialogue. Paste button is added on * Android devices. @@ -64,6 +86,42 @@ public: const QString &text = QString(), const QString &placeholderText = QString(), bool *ok = Q_NULLPTR, Qt::InputMethodHints inputMethodHints = Qt::ImhNone); + + /*! + * @brief Show message and await response. + * + * @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 Icon icon, const QString &title, + const QString &text, const QString &infoText, + Buttons buttons = NO_BUTTON, enum Button dfltButton = NO_BUTTON, + const QList< QPair > &customButtons = QList< QPair >(), + 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 Icon icon, const QString &title, + const QString &text, const QString &infoText); }; -#endif /* _INPUT_DIALOGUE_H_ */ +Q_DECLARE_OPERATORS_FOR_FLAGS(Dialogues::Buttons) + +#endif /* _DIALOGUES_H_ */ diff --git a/src/dialogues/input_dialogue.cpp b/src/dialogues/input_dialogue.cpp deleted file mode 100644 index 339d578..0000000 --- a/src/dialogues/input_dialogue.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2014-2017 CZ.NIC - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * In addition, as a special exception, the copyright holders give - * permission to link the code of portions of this program with the - * OpenSSL library under certain conditions as described in each - * individual source file, and distribute linked combinations including - * the two. - */ - -#if !defined(Q_OS_IOS) -#define USE_QML_DIALOGUES 1 -#endif /* !defined(Q_OS_IOS) */ - -#include "src/dialogues/input_dialogue.h" -#include "src/dialogues/qml_input_dialogue.h" -#include "src/dialogues/widget_input_dialogue.h" - -#if !defined(USE_QML_DIALOGUES) -/*! - * @brief Converts echo mode from helper class definition. - * - * @param[in] echoMode Echo mode as defined in QmlDlgHelper. - * @return Echo mode as defined in QLineEdit. - */ -static -QLineEdit::EchoMode toLineEditEchoMode( - enum QmlDlgHelper::QmlDlgEchoMode echoMode) -{ - switch (echoMode) { - case QmlDlgHelper::EM_NORMAL: - return QLineEdit::Normal; - break; - case QmlDlgHelper::EM_PWD: - return QLineEdit::NoEcho; - break; - case QmlDlgHelper::EM_NOECHO: - return QLineEdit::Password; - break; - case QmlDlgHelper::EM_PWD_ECHOONEDIT: - return QLineEdit::PasswordEchoOnEdit; - break; - default: - Q_ASSERT(0); - return QLineEdit::Normal; - break; - } -} -#endif /* !defined(USE_QML_DIALOGUES) */ - -QString InputDialogue::getText(QObject *parent, const QString &title, - const QString &message, enum QmlDlgHelper::QmlDlgEchoMode echoMode, - const QString &text, const QString &placeholderText, bool *ok, - Qt::InputMethodHints inputMethodHints) -{ -#if defined(USE_QML_DIALOGUES) - return QmlInputDialogue::getText(qobject_cast(parent), - title, message, echoMode, text, placeholderText, ok, - inputMethodHints); -#else /* !defined(USE_QML_DIALOGUES) */ - Q_UNUSED(placeholderText); - return WidgetInputDialogue::getText(qobject_cast(parent), - title, message, toLineEditEchoMode(echoMode), text, ok, - Qt::Dialog, inputMethodHints); -#endif /* defined(USE_QML_DIALOGUES) */ -} diff --git a/src/files.cpp b/src/files.cpp index cb10ea1..e731798 100644 --- a/src/files.cpp +++ b/src/files.cpp @@ -30,7 +30,7 @@ #include /* qmlRegisterType */ #include "src/common.h" -#include "src/dialogues/widget_message_dialogue.h" +#include "src/dialogues/dialogues.h" #include "src/files.h" #include "src/settings.h" #include "src/io/filesystem.h" @@ -289,19 +289,18 @@ void Files::openAttachment(const QString &fileName, const QByteArray &base64Data */ #else /* !defined Q_OS_IOS */ if (!QDesktopServices::openUrl(QUrl::fromLocalFile(filePath))) { - WidgetMessageDialogue::message(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("Open attachment error"), tr("There is no application to open this file format."), - tr("File: '%1'").arg(filePath), - QMessageBox::Ok, QMessageBox::Ok); + tr("File: '%1'").arg(filePath)); } #endif /* defined Q_OS_IOS */ } else { qCritical() << "Cannot create temporary file for" << fileName; - WidgetMessageDialogue::message(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("Open attachment error"), tr("Cannot save selected file to disk for opening."), - QString(), QMessageBox::Ok, QMessageBox::Ok); + QString()); } } @@ -380,12 +379,12 @@ void Files::deleteFileDb(const QString &userName) { qDebug("%s()", __func__); - int msgResponse = WidgetMessageDialogue::message(QMessageBox::Question, + int msgResponse = Dialogues::message(Dialogues::QUESTION, tr("Delete files: %1").arg(userName), tr("Do you want to clean up the file database of account '%1'?").arg(userName), tr("Note: All attachment files of messages will be removed from the database."), - QMessageBox::No | QMessageBox::Yes, QMessageBox::No); - if (msgResponse == QMessageBox::No) { + Dialogues::NO | Dialogues::YES, Dialogues::NO); + if (msgResponse == Dialogues::NO) { return; } @@ -635,14 +634,12 @@ void attachmentSavingNotification(const QString &destPath) { QFileInfo fi(destPath); - WidgetMessageDialogue::message( - !destPath.isEmpty() ? QMessageBox::Information : - QMessageBox::Critical, + Dialogues::errorMessage( + !destPath.isEmpty() ? Dialogues::INFORMATION : Dialogues::CRITICAL, QObject::tr("Attachment saving"), !destPath.isEmpty() ? QObject::tr("Attachments have been saved.") : QObject::tr("Attachments have not been saved!"), - QObject::tr("Path: '%1'").arg(fi.absolutePath()), - QMessageBox::Ok, QMessageBox::Ok); + QObject::tr("Path: '%1'").arg(fi.absolutePath())); } void Files::saveAttachmentsToDiskDb(const QString &userName, diff --git a/src/main.cpp b/src/main.cpp index 7b4c135..886253e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,7 +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/dialogues/dialogues.h" #include "src/files.h" #include "src/locker.h" #include "src/net/isds_wrapper.h" @@ -351,7 +351,7 @@ int main(int argc, char *argv[]) arg(globSet.lastUpdateStr()), false, true); } } else { - WidgetMessageDialogue::errorMessage(QMessageBox::Warning, + Dialogues::errorMessage(Dialogues::WARNING, QObject::tr("Security problem"), QObject::tr("OpenSSL support is required!"), QObject::tr("The device does not support OpenSSL. " diff --git a/src/messages.cpp b/src/messages.cpp index 2fb059a..3db6edb 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -29,7 +29,7 @@ #include #include "src/common.h" -#include "src/dialogues/widget_message_dialogue.h" +#include "src/dialogues/dialogues.h" #include "src/messages.h" #include "src/settings.h" #include "src/models/accountmodel.h" @@ -185,12 +185,12 @@ void Messages::deleteMessageFromDbs(const QString &userName, qint64 msgId) return; } - int msgResponse = WidgetMessageDialogue::message(QMessageBox::Question, + int msgResponse = Dialogues::message(Dialogues::QUESTION, tr("Delete message: %1").arg(msgId), tr("Do you want to delete the message '%1'?").arg(msgId), tr("Note: It will delete all attachments and message information from the local database."), - QMessageBox::No | QMessageBox::Yes, QMessageBox::No); - if (msgResponse == QMessageBox::No) { + Dialogues::NO | Dialogues::YES, Dialogues::NO); + if (msgResponse == Dialogues::NO) { return; } @@ -262,11 +262,10 @@ bool Messages::moveOrCreateNewDbsToNewLocation(const QString &newLocation) { QStorageInfo si(newLocation); if (si.bytesAvailable() < allDbSize) { - WidgetMessageDialogue::message(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("New location error"), tr("It is not possible to store databases in the new location because there is not enough free space left."), - tr("Databases size is %1 MB.").arg(allDbSize / (1024 * 1024)), - QMessageBox::Ok, QMessageBox::Ok); + tr("Databases size is %1 MB.").arg(allDbSize / (1024 * 1024))); return false; } } @@ -330,11 +329,11 @@ enum Messages::ReloactionAction Messages::askAction(void) customButtons.append(QPair(tr("Create new"), RA_CREATE_NEW)); int customVal = -1; - WidgetMessageDialogue::message(QMessageBox::Question, + Dialogues::message(Dialogues::QUESTION, tr("Change database location"), tr("What do you want to do with the currently used database files?"), tr("You have the option to move the current database files to a new location or you can delete them and create new empty databases."), - QMessageBox::Cancel, QMessageBox::Cancel, + Dialogues::CANCEL, Dialogues::CANCEL, customButtons, &customVal); if (customVal == RA_RELOCATE) { diff --git a/src/net/isds_session.cpp b/src/net/isds_session.cpp index fa3d8a9..c31dc00 100644 --- a/src/net/isds_session.cpp +++ b/src/net/isds_session.cpp @@ -26,7 +26,7 @@ #include #include "src/common.h" -#include "src/dialogues/input_dialogue.h" +#include "src/dialogues/dialogues.h" #include "src/net/isds_const.h" #include "src/net/isds_session.h" #include "src/net/xml_layer.h" @@ -123,7 +123,7 @@ bool IsdsSession::setCertificateData(const QString &userName, return false; } - const QString passPhrase = InputDialogue::getText(Q_NULLPTR, + const QString passPhrase = Dialogues::getText(Q_NULLPTR, tr("Certificate password: %1").arg(userName), tr("Certificate password for '%1' required").arg(accountName), QmlDlgHelper::EM_PWD, QString(), tr("Enter certificate password"), diff --git a/src/net/isds_wrapper.cpp b/src/net/isds_wrapper.cpp index b6e3113..fab0b43 100644 --- a/src/net/isds_wrapper.cpp +++ b/src/net/isds_wrapper.cpp @@ -23,8 +23,7 @@ #include -#include "src/dialogues/input_dialogue.h" -#include "src/dialogues/widget_message_dialogue.h" +#include "src/dialogues/dialogues.h" #include "src/net/isds_wrapper.h" #include "src/models/accountmodel.h" #include "src/settings.h" @@ -50,7 +49,7 @@ void IsdsWrapper::downloadMessage(const QString &userName, int mesasgeType, QString errTxt = tr("Wrong username or message ID"); if (userName.isEmpty() || msgId <= 0) { - WidgetMessageDialogue::errorMessage(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("Error"), errTxt, tr("Internal error")); return; } @@ -66,8 +65,7 @@ void IsdsWrapper::downloadMessage(const QString &userName, int mesasgeType, if (mesasgeType == MessageDb::TYPE_RECEIVED) { if (!m_xmlLayer.isdsGetCompleteMsgWithoutCms( m_isdsSession.isdsCtxMap[userName], msgId)) { - WidgetMessageDialogue::errorMessage( - QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("Delivery info: %1").arg(userName), tr("Failed to download complete received message %1.").arg(msgId), m_isdsSession.isdsCtxMap[userName].last_isds_msg); @@ -76,8 +74,7 @@ void IsdsWrapper::downloadMessage(const QString &userName, int mesasgeType, } else { if (!m_xmlLayer.isdsGetCompleteSentMsgWithCms( m_isdsSession.isdsCtxMap[userName], msgId)) { - WidgetMessageDialogue::errorMessage( - QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("Downloading message: %1").arg(userName), tr("Failed to download complete sent message %1.").arg(msgId), m_isdsSession.isdsCtxMap[userName].last_isds_msg); @@ -107,7 +104,7 @@ void IsdsWrapper::getDeliveryInfo(const QString &userName, qint64 msgId) QString errTxt = tr("Wrong username or message ID"); if (userName.isEmpty() || msgId <= 0) { - WidgetMessageDialogue::errorMessage(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("Error"), errTxt, tr("Internal error")); return; } @@ -122,7 +119,7 @@ void IsdsWrapper::getDeliveryInfo(const QString &userName, qint64 msgId) if (!m_xmlLayer.isdsGetMsgDeliveryInfoWithoutCms( m_isdsSession.isdsCtxMap[userName], msgId)) { - WidgetMessageDialogue::errorMessage(QMessageBox::Warning, + Dialogues::errorMessage(Dialogues::WARNING, tr("Delivery info: %1").arg(userName), tr("Failed to download delivery info for message %1.").arg(msgId), m_isdsSession.isdsCtxMap[userName].last_isds_msg); @@ -174,7 +171,7 @@ bool IsdsWrapper::syncSingleAccountReceived(const QString &userName) /* ========================================================================= */ { if (userName.isEmpty()) { - WidgetMessageDialogue::errorMessage(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("Error"), tr("Empty user name"), tr("Internal error")); return false; } @@ -194,7 +191,7 @@ bool IsdsWrapper::syncSingleAccountReceived(const QString &userName) if (!m_xmlLayer.isdsGetReceivedMessageList( m_isdsSession.isdsCtxMap[userName], globSet.downloadOnlyNewMsgs, receivedMsgIds)) { - WidgetMessageDialogue::errorMessage(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("%1: received messages").arg(userName), tr("Failed to download list of received messages for user name '%1'.").arg(userName), m_isdsSession.isdsCtxMap[userName].last_isds_msg); @@ -226,7 +223,7 @@ bool IsdsWrapper::syncSingleAccountSent(const QString &userName) /* ========================================================================= */ { if (userName.isEmpty()) { - WidgetMessageDialogue::errorMessage(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("Error"), tr("Empty user name"), tr("Internal error")); return false; } @@ -245,7 +242,7 @@ bool IsdsWrapper::syncSingleAccountSent(const QString &userName) if (!m_xmlLayer.isdsGetSentMessageList( m_isdsSession.isdsCtxMap[userName], globSet.downloadOnlyNewMsgs, sentMsgIds)) { - WidgetMessageDialogue::errorMessage(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("%1: sent messages").arg(userName), tr("Failed to download list of sent messages for user name %1.").arg(userName), m_isdsSession.isdsCtxMap[userName].last_isds_msg); @@ -276,7 +273,7 @@ bool IsdsWrapper::getAccountInfo(const QString &userName, bool firstLogin) QString errTxt = tr("Wrong username"); if (userName.isEmpty()) { - WidgetMessageDialogue::errorMessage(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("Error"), errTxt, tr("Internal error")); return false; } @@ -309,7 +306,7 @@ bool IsdsWrapper::getAccountInfo(const QString &userName, bool firstLogin) m_xmlLayer.isdsGetPasswordExpiration(m_isdsSession.isdsCtxMap[userName]); if (!success) { - WidgetMessageDialogue::errorMessage(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("Account info: %1").arg(userName), tr("Failed to get account info for username %1.").arg(userName), m_isdsSession.isdsCtxMap[userName].last_isds_msg); @@ -336,7 +333,7 @@ void IsdsWrapper::changePassword(const QString &userName, QString errTxt = tr("Wrong username"); if (userName.isEmpty()) { - WidgetMessageDialogue::errorMessage(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("Error"), errTxt, tr("Internal error")); return; } @@ -347,7 +344,7 @@ void IsdsWrapper::changePassword(const QString &userName, } bool ok; - QString newPwd = InputDialogue::getText(Q_NULLPTR, + QString newPwd = Dialogues::getText(Q_NULLPTR, tr("New password: %1").arg(userName), tr("Enter new password for account\n'%1'").arg(accountName), QmlDlgHelper::EM_NORMAL, QString(), tr("Enter password"), &ok); @@ -355,7 +352,7 @@ void IsdsWrapper::changePassword(const QString &userName, return; } if (!isCorrectPassword(newPwd)) { - WidgetMessageDialogue::errorMessage(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("Change password: %1").arg(userName), tr("Wrong password format for username '%1'.").arg(userName), tr("The new password must contain at least 8 characters including " @@ -365,25 +362,24 @@ void IsdsWrapper::changePassword(const QString &userName, if (m_isdsSession.isdsCtxMap[userName].login_method == USERNAME_PWD_TOTP) { /* Show SMS request dialogue. */ - int msgResponse = WidgetMessageDialogue::message( - QMessageBox::Question, tr("SMS code: %1").arg(userName), + int msgResponse = Dialogues::message(Dialogues::QUESTION, + tr("SMS code: %1").arg(userName), tr("Account '%1' requires authentication with SMS code.").arg(accountName), tr("Do you want to send SMS code now?"), - QMessageBox::No | QMessageBox::Yes, QMessageBox::Yes); - if (msgResponse == QMessageBox::No) { + Dialogues::NO | Dialogues::YES, Dialogues::YES); + if (msgResponse == Dialogues::NO) { return; } if (!m_xmlLayer.isdsSendSMS(m_isdsSession.isdsCtxMap[userName])) { - WidgetMessageDialogue::errorMessage( - QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("Change password: %1").arg(userName), tr("Failed to send SMS code for username '%1'.").arg(userName), m_isdsSession.isdsCtxMap[userName].last_isds_msg); return; } - QString text = InputDialogue::getText(Q_NULLPTR, + QString text = Dialogues::getText(Q_NULLPTR, tr("SMS code: %1").arg(userName), tr("SMS code for '%1' required").arg(accountName), QmlDlgHelper::EM_NORMAL, QString(), tr("Enter SMS code"), @@ -395,7 +391,7 @@ void IsdsWrapper::changePassword(const QString &userName, } } else if (m_isdsSession.isdsCtxMap[userName].login_method == USERNAME_PWD_HOTP) { - QString text = InputDialogue::getText(Q_NULLPTR, + QString text = Dialogues::getText(Q_NULLPTR, tr("Security code: %1").arg(userName), tr("Security code for '%1' required").arg(accountName), QmlDlgHelper::EM_NORMAL, QString(), @@ -412,7 +408,7 @@ void IsdsWrapper::changePassword(const QString &userName, if (!m_xmlLayer.isdsChangePassword(m_isdsSession.isdsCtxMap[userName], newPwd)) { - WidgetMessageDialogue::errorMessage(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("Change password: %1").arg(userName), tr("Failed to change password for username '%1'.").arg(userName), m_isdsSession.isdsCtxMap[userName].last_isds_msg); @@ -568,7 +564,7 @@ void IsdsWrapper::showLoginProblemDialog(const QString &userName, emit statusBarTextChanged("", false, false); if (!errTxt.isEmpty()) { - WidgetMessageDialogue::errorMessage(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("Login problem: %1").arg(userName), tr("Error while logging in with username '%1'.").arg(userName), tr("System ISDS returns:") + " " + errTxt + "\n\n" + @@ -588,7 +584,7 @@ void IsdsWrapper::showFirstLoginProblemDialog(const QString &userName, emit statusBarTextChanged("", false, false); if (!errTxt.isEmpty()) { - WidgetMessageDialogue::errorMessage(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("Problem adding account: %1").arg(userName), tr("New account could not be created because an error occurred " "while trying to log in with user name '%1'.").arg(userName), diff --git a/src/net/net_layer.cpp b/src/net/net_layer.cpp index 812433b..d17d5be 100644 --- a/src/net/net_layer.cpp +++ b/src/net/net_layer.cpp @@ -31,8 +31,7 @@ #include #include "src/common.h" -#include "src/dialogues/input_dialogue.h" -#include "src/dialogues/widget_message_dialogue.h" +#include "src/dialogues/dialogues.h" #include "src/net/net_layer.h" #include "src/net/xml_layer.h" #include "src/net/isds_const.h" @@ -141,7 +140,7 @@ bool NetLayer::createLoginRequest(IsdsContext &ctx, if (ctx.password.isEmpty()) { do { - pwd = InputDialogue::getText(Q_NULLPTR, + pwd = Dialogues::getText(Q_NULLPTR, tr("Password: %1").arg(ctx.username), tr("Password for '%1' missing").arg(ctx.account_name), QmlDlgHelper::EM_PWD, QString(), @@ -160,7 +159,7 @@ bool NetLayer::createLoginRequest(IsdsContext &ctx, if (ctx.login_method == USERNAME_PWD_HOTP) { do { - pwd = InputDialogue::getText(Q_NULLPTR, + pwd = Dialogues::getText(Q_NULLPTR, tr("Security code: %1").arg(ctx.username), tr("Security code for '%1' required").arg(ctx.account_name), QmlDlgHelper::EM_NORMAL, QString(), @@ -178,12 +177,12 @@ bool NetLayer::createLoginRequest(IsdsContext &ctx, } else if (ctx.login_method == USERNAME_PWD_TOTP) { /* Show SMS dialogue. */ - int msgResponse = WidgetMessageDialogue::message( - QMessageBox::Question, tr("SMS code: %1").arg(ctx.username), + int msgResponse = Dialogues::message(Dialogues::QUESTION, + tr("SMS code: %1").arg(ctx.username), tr("Account '%1' requires authentication with SMS code.").arg(ctx.account_name), tr("Do you want to send SMS code now?"), - QMessageBox::No | QMessageBox::Yes, QMessageBox::Yes); - if (msgResponse == QMessageBox::No) { + Dialogues::NO | Dialogues::YES, Dialogues::YES); + if (msgResponse == Dialogues::NO) { return success; } authorization.append(ctx.username + ":" + ctx.password); @@ -579,7 +578,7 @@ bool NetLayer::doTotpLoginRequest(IsdsContext &ctx, const QByteArray &xmlDataIn, do { if (iteration > 1) { // SMS input dialog after wrong code - code = InputDialogue::getText(Q_NULLPTR, + code = Dialogues::getText(Q_NULLPTR, tr("Wrong SMS code: %1").arg(ctx.username), tr("Correct SMS code for '%1' required").arg(ctx.account_name), QmlDlgHelper::EM_NORMAL, @@ -587,7 +586,7 @@ bool NetLayer::doTotpLoginRequest(IsdsContext &ctx, const QByteArray &xmlDataIn, Qt::ImhDigitsOnly); } else { // first SMS input dialog - code = InputDialogue::getText(Q_NULLPTR, + code = Dialogues::getText(Q_NULLPTR, tr("SMS code: %1").arg(ctx.username), tr("SMS code for '%1' required").arg(ctx.account_name), QmlDlgHelper::EM_NORMAL, diff --git a/src/setwrapper.cpp b/src/setwrapper.cpp index 1fae09e..281b76e 100644 --- a/src/setwrapper.cpp +++ b/src/setwrapper.cpp @@ -26,7 +26,7 @@ #include "src/crypto/pin.h" #include "src/crypto/wrapped.h" -#include "src/dialogues/widget_message_dialogue.h" +#include "src/dialogues/dialogues.h" #include "src/models/accountmodel.h" /* globAccountsModelPtr */ #include "src/io/filesystem.h" #include "src/setwrapper.h" @@ -272,11 +272,10 @@ QString GlobalSettingsQmlWrapper::changeDbPath(const QString ¤tLocation, /* check if new location is writable */ QFileInfo fi(newLocation); if (!fi.isWritable()) { - WidgetMessageDialogue::message(QMessageBox::Critical, + Dialogues::errorMessage(Dialogues::CRITICAL, tr("New location error"), tr("It is not possible to store databases in the new location. Write permission denied."), - tr("Action will be cancelled."), - QMessageBox::Ok, QMessageBox::Ok); + tr("Action will be cancelled.")); return QString(); } -- 2.22.0