Commit 6f964cf0 authored by Karel Slaný's avatar Karel Slaný

Isolated QMessageBox invocations into single compilation unit.

parent 593deedf
......@@ -87,6 +87,7 @@ SOURCES += \
src/dialogues/qml_dialogue_helper.cpp \
src/dialogues/qml_input_dialogue.cpp \
src/dialogues/widget_input_dialogue.cpp \
src/dialogues/widget_message_dialogue.cpp \
src/files.cpp \
src/io/filesystem.cpp \
src/io/sqlite/db.cpp \
......@@ -123,6 +124,7 @@ HEADERS += \
src/dialogues/qml_dialogue_helper.h \
src/dialogues/qml_input_dialogue.h \
src/dialogues/widget_input_dialogue.h \
src/dialogues/widget_message_dialogue.h \
src/files.h \
src/io/filesystem.h \
src/io/sqlite/db.h \
......
/*
* Copyright (C) 2014-2016 CZ.NIC
* 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
......@@ -22,12 +22,12 @@
*/
#include <QDebug>
#include <QMessageBox>
#include <QSettings>
#include <QUrl>
#include "src/accounts.h"
#include "src/common.h"
#include "src/dialogues/widget_message_dialogue.h"
#include "src/net/isds_wrapper.h"
#include "src/net/isds_session.h"
#include "src/settings.h"
......@@ -111,15 +111,13 @@ bool Accounts::removeAccount(const QString &userName, bool showDialog)
qDebug("%s()", __func__);
if (showDialog) {
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Remove account: %1").arg(userName));
msgBox.setIcon(QMessageBox::Question);
msgBox.setText(tr("Do you want to remove the account '%1'?").arg(userName));
msgBox.setInformativeText(tr("Note: It will also remove all related "
"local databases and account information."));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::No);
if (msgBox.exec() == QMessageBox::No) {
int msgResponse = WidgetMessageDialogue::message(
QMessageBox::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) {
return false;
}
}
......@@ -374,18 +372,9 @@ void Accounts::showErrorMessageBox(const QString &title,
const QString &text, const QString &informatinText, bool isError)
/* ========================================================================= */
{
QMessageBox msgBox;
msgBox.setWindowTitle(title);
if (isError) {
msgBox.setIcon(QMessageBox::Critical);
} else {
msgBox.setIcon(QMessageBox::Warning);
}
msgBox.setText(text);
msgBox.setInformativeText(informatinText);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
WidgetMessageDialogue::message(
isError ? QMessageBox::Critical : QMessageBox::Warning,
title, text, informatinText, QMessageBox::Ok, QMessageBox::Ok);
}
......
......@@ -26,12 +26,12 @@
#include <QUrl>
#include <QMimeDatabase>
#include <QFileDialog>
#include <QMessageBox>
#include <QMimeType>
#include <QQmlEngine> /* qmlRegisterType */
#include "src/files.h"
#include "src/common.h"
#include "src/dialogues/widget_message_dialogue.h"
#include "src/files.h"
#include "src/settings.h"
#include "src/io/filesystem.h"
#include "ios/src/url_opener.h"
......@@ -289,25 +289,19 @@ void Files::openAttachment(const QString &fileName, const QByteArray &base64Data
*/
#else /* !defined Q_OS_IOS */
if (!QDesktopServices::openUrl(QUrl::fromLocalFile(filePath))) {
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical);
msgBox.setWindowTitle(tr("Open attachment error"));
msgBox.setText(tr("There is no application to open this file format."));
msgBox.setInformativeText(tr("File: '%1'").arg(filePath));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
WidgetMessageDialogue::message(QMessageBox::Critical,
tr("Open attachment error"),
tr("There is no application to open this file format."),
tr("File: '%1'").arg(filePath),
QMessageBox::Ok, QMessageBox::Ok);
}
#endif /* defined Q_OS_IOS */
} else {
qCritical() << "Cannot create temporary file for" << fileName;
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical);
msgBox.setWindowTitle(tr("Open attachment error"));
msgBox.setText(tr("Cannot save selected file to disk for opening."));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
WidgetMessageDialogue::message(QMessageBox::Critical,
tr("Open attachment error"),
tr("Cannot save selected file to disk for opening."),
QString(), QMessageBox::Ok, QMessageBox::Ok);
}
}
......@@ -386,16 +380,12 @@ void Files::deleteFileDb(const QString &userName)
{
qDebug("%s()", __func__);
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Delete files: %1").arg(userName));
msgBox.setIcon(QMessageBox::Question);
msgBox.setText(tr("Do you want to clean up the file database "
"of account '%1'?").arg(userName));
msgBox.setInformativeText(tr("Note: All attachment files of messages "
"will be removed from the database."));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::No);
if (msgBox.exec() == QMessageBox::No) {
int msgResponse = WidgetMessageDialogue::message(QMessageBox::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) {
return;
}
......@@ -645,21 +635,14 @@ void attachmentSavingNotification(const QString &destPath)
{
QFileInfo fi(destPath);
QMessageBox msgBox;
msgBox.setWindowTitle(QObject::tr("Attachment saving"));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
if (!destPath.isEmpty()) {
msgBox.setIcon(QMessageBox::Information);
msgBox.setText(QObject::tr("Attachments have been saved."));
} else {
msgBox.setIcon(QMessageBox::Critical);
msgBox.setText(QObject::tr("Attachments have not been saved!"));
}
msgBox.setInformativeText(
QObject::tr("Path: '%1'").arg(fi.absolutePath()));
msgBox.exec();
WidgetMessageDialogue::message(
!destPath.isEmpty() ? QMessageBox::Information :
QMessageBox::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);
}
void Files::saveAttachmentsToDiskDb(const QString &userName,
......
......@@ -23,13 +23,13 @@
#include <QDebug>
#include <QFile>
#include <QMessageBox>
#include <QPair>
#include <QPushButton>
#include <QQmlEngine> /* qmlRegisterType */
#include <QStorageInfo>
#include "src/common.h"
#include "src/dialogues/widget_message_dialogue.h"
#include "src/messages.h"
#include "src/settings.h"
#include "src/models/accountmodel.h"
......@@ -185,15 +185,12 @@ void Messages::deleteMessageFromDbs(const QString &userName, qint64 msgId)
return;
}
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Delete message: %1").arg(msgId));
msgBox.setIcon(QMessageBox::Question);
msgBox.setText(tr("Do you want to delete the message '%1'?").arg(msgId));
msgBox.setInformativeText(tr("Note: It will delete all attachments "
"and message information from the local database."));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::No);
if (msgBox.exec() == QMessageBox::No) {
int msgResponse = WidgetMessageDialogue::message(QMessageBox::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) {
return;
}
......@@ -265,16 +262,11 @@ bool Messages::moveOrCreateNewDbsToNewLocation(const QString &newLocation)
{
QStorageInfo si(newLocation);
if (si.bytesAvailable() < allDbSize) {
QMessageBox msgBox;
msgBox.setWindowTitle(tr("New location error"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setText(tr(
"It is not possible to store databases in the new location because there is not enough free space left."));
msgBox.setInformativeText(tr("Databases size is %1 MB.")
.arg(allDbSize / (1024 * 1024)));
msgBox.exec();
WidgetMessageDialogue::message(QMessageBox::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);
return false;
}
}
......@@ -333,24 +325,21 @@ void Messages::deleteExpiredMessagesFromDbs(int days)
enum Messages::ReloactionAction Messages::askAction(void)
{
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Change database location"));
msgBox.setIcon(QMessageBox::Question);
msgBox.setText(tr(
"What do you want to do with the currently used database files?"));
msgBox.setInformativeText(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."));
QAbstractButton *moveButton = msgBox.addButton(tr("Move"),
QMessageBox::ActionRole);
QAbstractButton *newButton = msgBox.addButton(tr("Create new"),
QMessageBox::ActionRole);
msgBox.setStandardButtons(QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Cancel);
msgBox.exec();
if (msgBox.clickedButton() == moveButton) {
QList< QPair<QString, int> > customButtons;
customButtons.append(QPair<QString, int>(tr("Move"), RA_RELOCATE));
customButtons.append(QPair<QString, int>(tr("Create new"), RA_CREATE_NEW));
int customVal = -1;
WidgetMessageDialogue::message(QMessageBox::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,
customButtons, &customVal);
if (customVal == RA_RELOCATE) {
return RA_RELOCATE;
} else if (msgBox.clickedButton() == newButton) {
} else if (customVal == RA_CREATE_NEW) {
return RA_CREATE_NEW;
} else {
return RA_NONE;
......
......@@ -22,9 +22,9 @@
*/
#include <QDebug>
#include <QMessageBox>
#include "src/dialogues/input_dialogue.h"
#include "src/dialogues/widget_message_dialogue.h"
#include "src/net/isds_wrapper.h"
#include "src/models/accountmodel.h"
#include "src/settings.h"
......@@ -366,16 +366,13 @@ void IsdsWrapper::changePassword(const QString &userName,
}
if (m_isdsSession.isdsCtxMap[userName].login_method == USERNAME_PWD_TOTP) {
/* show SMS request dialog */
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Question);
msgBox.setWindowTitle(tr("SMS code: %1").arg(userName));
msgBox.setText(tr("Account '%1' requires authentication "
"with SMS code.").arg(accountName));
msgBox.setInformativeText("Do you want to send SMS code now?");
msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
msgBox.setDefaultButton(QMessageBox::Yes);
if (QMessageBox::No == msgBox.exec()) {
/* Show SMS request dialogue. */
int msgResponse = WidgetMessageDialogue::message(
QMessageBox::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) {
return;
}
......@@ -569,18 +566,9 @@ void IsdsWrapper::showErrorMessageBox(const QString &title,
const QString &text, const QString &informatinText, bool isError)
/* ========================================================================= */
{
QMessageBox msgBox;
msgBox.setWindowTitle(title);
if (isError) {
msgBox.setIcon(QMessageBox::Critical);
} else {
msgBox.setIcon(QMessageBox::Warning);
}
msgBox.setText(text);
msgBox.setInformativeText(informatinText);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
WidgetMessageDialogue::message(
isError ? QMessageBox::Critical : QMessageBox::Warning,
title, text, informatinText, QMessageBox::Ok, QMessageBox::Ok);
}
......
/*
* Copyright (C) 2014-2016 CZ.NIC
* 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
......@@ -23,7 +23,6 @@
#include <QDebug>
#include <QEventLoop>
#include <QMessageBox>
#include <QNetworkAccessManager>
#include <QNetworkCookie>
#include <QNetworkCookieJar>
......@@ -33,6 +32,7 @@
#include "src/common.h"
#include "src/dialogues/input_dialogue.h"
#include "src/dialogues/widget_message_dialogue.h"
#include "src/net/net_layer.h"
#include "src/net/xml_layer.h"
#include "src/net/isds_const.h"
......@@ -177,15 +177,13 @@ bool NetLayer::createLoginRequest(IsdsContext &ctx,
} else if (ctx.login_method == USERNAME_PWD_TOTP) {
/* show SMS dialog */
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Question);
msgBox.setWindowTitle(tr("SMS code: %1").arg(ctx.username));
msgBox.setText(tr("Account '%1' requires authentication with SMS code.").arg(ctx.account_name));
msgBox.setInformativeText("Do you want to send SMS code now?");
msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
msgBox.setDefaultButton(QMessageBox::Yes);
if (QMessageBox::No == msgBox.exec()) {
/* Show SMS dialogue. */
int msgResponse = WidgetMessageDialogue::message(
QMessageBox::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) {
return success;
}
authorization.append(ctx.username + ":" + ctx.password);
......
/*
* Copyright (C) 2014-2016 CZ.NIC
* 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
......@@ -23,16 +23,15 @@
#include <QtDebug> // qCritical
#include <QFileDialog>
#include <QMessageBox>
#include "src/crypto/pin.h"
#include "src/crypto/wrapped.h"
#include "src/dialogues/widget_message_dialogue.h"
#include "src/models/accountmodel.h" /* globAccountsModelPtr */
#include "src/io/filesystem.h"
#include "src/setwrapper.h"
#include "src/settings.h"
GlobalSettingsQmlWrapper::GlobalSettingsQmlWrapper(QObject *parent)
: QObject(parent)
{
......@@ -273,15 +272,11 @@ QString GlobalSettingsQmlWrapper::changeDbPath(const QString &currentLocation,
/* check if new location is writable */
QFileInfo fi(newLocation);
if (!fi.isWritable()) {
QMessageBox msgBox;
msgBox.setWindowTitle(tr("New location error"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setText(tr("It is not possible to store databases in the new "
"location. Write permission denied."));
msgBox.setInformativeText(tr("Action will be canceled."));
msgBox.exec();
WidgetMessageDialogue::message(QMessageBox::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);
return QString();
}
......
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