Commit 887eb280 authored by Karel Slaný's avatar Karel Slaný

Passing icon into QML message dialogue.

parent 76dd6c67
......@@ -24,6 +24,7 @@
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Dialogs 1.2
import cz.nic.mobileDatovka.dialogues 1.0
/*
* All objectName properties are used to navigate through the structure from
......@@ -43,6 +44,7 @@ Item {
id: dialogue
objectName: "dialogue"
property int icon: Dialogues.NO_ICON
property alias content: content
//visible: true /* Set from C++. */
......@@ -60,6 +62,25 @@ Item {
anchors.fill: parent
Text { /* Currently there is only a text information. */
id: importanceText
objectName: "importanceText"
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width
text: (dialogue.icon == Dialogues.NO_ICON) ? "" :
(dialogue.icon == Dialogues.QUESTION ) ? qsTr("Question") + ":" :
(dialogue.icon == Dialogues.INFORMATION ) ? qsTr("Information") + ":" :
(dialogue.icon == Dialogues.WARNING ) ? qsTr("Warning") + ":" :
(dialogue.icon == Dialogues.CRITICAL ) ? qsTr("Critical") + ":" : ""
//color: datovkaPalette.mid /* TODO */
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.Wrap
visible: dialogue.icon != Dialogues.NO_ICON
}
Text {
id: messageText
objectName: "messageText"
......
......@@ -24,7 +24,7 @@
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Dialogs 1.2
import cz.nic.mobileDatovka.qmlDialogue 1.0
import cz.nic.mobileDatovka.dialogues 1.0
/*
* All objectName properties are used to navigate through the structure from
......@@ -47,7 +47,7 @@ Item {
property alias content: content
property bool explicitPasteMenu: false
property int dlgEchoMode: QmlDlgEchoMode.EM_NORMAL
property int dlgEchoMode: Dialogues.EM_NORMAL
//visible: true /* Set from C++. */
title: ""
......@@ -95,10 +95,10 @@ Item {
focus: true
echoMode: (dialogue.dlgEchoMode == QmlDlgEchoMode.EM_NORMAL) ? TextInput.Normal :
(dialogue.dlgEchoMode == QmlDlgEchoMode.EM_PWD) ? TextInput.Password :
(dialogue.dlgEchoMode == QmlDlgEchoMode.NOECHO) ? TextInput.NoEcho :
(dialogue.dlgEchoMode == QmlDlgEchoMode.EM_PWD_ECHOONEDIT) ? TextInput.PasswordEchoOnEdit : TextInput.Normal
echoMode: (dialogue.dlgEchoMode == Dialogues.EM_NORMAL) ? TextInput.Normal :
(dialogue.dlgEchoMode == Dialogues.EM_PWD) ? TextInput.Password :
(dialogue.dlgEchoMode == Dialogues.NOECHO) ? TextInput.NoEcho :
(dialogue.dlgEchoMode == Dialogues.EM_PWD_ECHOONEDIT) ? TextInput.PasswordEchoOnEdit : TextInput.Normal
passwordMaskDelay: 500 // milliseconds
Menu {
......
......@@ -414,6 +414,7 @@ ApplicationWindow {
return;
}
dlgObj.dialogue.icon = icon
dlgObj.dialogue.title = title
dlgObj.dialogue.content.messageText.text = message
dlgObj.dialogue.content.infoMessageText.text = infoMessage
......
......@@ -25,6 +25,7 @@
#define USE_QML_DIALOGUES 1
#endif /* !defined(Q_OS_IOS) */
#include <QQmlEngine> /* qmlRegisterType */
#include <QWindow>
#include "src/dialogues/dialogues.h"
......@@ -37,24 +38,24 @@
/*!
* @brief Converts echo mode from helper class definition.
*
* @param[in] echoMode Echo mode as defined in QmlDlgHelper.
* @param[in] echoMode Echo mode as defined in Dialogues.
* @return Echo mode as defined in QLineEdit.
*/
static
QLineEdit::EchoMode toLineEditEchoMode(
enum QmlDlgHelper::QmlDlgEchoMode echoMode)
enum Dialogues::EchoMode echoMode)
{
switch (echoMode) {
case QmlDlgHelper::EM_NORMAL:
case Dialogues::EM_NORMAL:
return QLineEdit::Normal;
break;
case QmlDlgHelper::EM_PWD:
case Dialogues::EM_PWD:
return QLineEdit::NoEcho;
break;
case QmlDlgHelper::EM_NOECHO:
case Dialogues::EM_NOECHO:
return QLineEdit::Password;
break;
case QmlDlgHelper::EM_PWD_ECHOONEDIT:
case Dialogues::EM_PWD_ECHOONEDIT:
return QLineEdit::PasswordEchoOnEdit;
break;
default:
......@@ -184,9 +185,17 @@ QMessageBox::StandardButtons toMessageBoxButtons(Dialogues::Buttons buttons)
return outButtons;
}
void Dialogues::declareQML(void)
{
qmlRegisterType<Dialogues>("cz.nic.mobileDatovka.dialogues", 1, 0, "Dialogues");
qRegisterMetaType<Dialogues::EchoMode>();
qRegisterMetaType<Dialogues::Icon>();
qRegisterMetaType<Dialogues::Button>();
}
QString Dialogues::getText(QObject *parent, const QString &title,
const QString &message, enum QmlDlgHelper::QmlDlgEchoMode echoMode,
const QString &text, const QString &placeholderText, bool *ok,
const QString &message, enum EchoMode echoMode, const QString &text,
const QString &placeholderText, bool *ok,
Qt::InputMethodHints inputMethodHints)
{
#if defined(USE_QML_DIALOGUES)
......@@ -216,7 +225,8 @@ void Dialogues::errorMessage(enum Icon icon, const QString &title,
const QString &text, const QString &infoText)
{
#if defined(USE_QML_DIALOGUES)
QmlMessageDialogue::errorMessage(Q_NULLPTR, title, text, infoText);
QmlMessageDialogue::errorMessage(Q_NULLPTR, icon, title, text,
infoText);
#else /* !defined(USE_QML_DIALOGUES) */
WidgetMessageDialogue::errorMessage(toMessageBoxIcon(icon), title,
text, infoText);
......
......@@ -26,21 +26,26 @@
#include <QObject>
#include "src/dialogues/qml_dialogue_helper.h"
/*!
* @brief Encapsulates dialogues.
*/
class Dialogues : public QObject {
Q_OBJECT
private:
/*!
* @brief Private constructor.
public:
/*
* See TextInput documentation.
* QQuickTextField header file, where similar enum values are defined,
* cannot be accessed directly.
*/
explicit Dialogues(QObject *parent = Q_NULLPTR);
enum EchoMode {
EM_NORMAL,
EM_PWD,
EM_NOECHO,
EM_PWD_ECHOONEDIT
};
Q_ENUM(EchoMode)
public:
/*!
* @brief Dialogue icon decoration.
*/
......@@ -51,6 +56,7 @@ public:
WARNING,
CRITICAL
};
Q_ENUM(Icon)
/*!
* @brief Dialogue button declaration.
......@@ -62,8 +68,13 @@ public:
NO = 0x00010000,
NO_BUTTON = 0x00000000
};
Q_ENUM(Button)
Q_DECLARE_FLAGS(Buttons, Button)
/* Don't forget to declare various properties to the QML system. */
static
void declareQML(void);
/*!
* @brief Generates a text edit dialogue. Paste button is added on
* Android devices.
......@@ -81,8 +92,7 @@ public:
*/
static
QString getText(QObject *parent, const QString &title,
const QString &message,
enum QmlDlgHelper::QmlDlgEchoMode echoMode = QmlDlgHelper::EM_NORMAL,
const QString &message, enum EchoMode echoMode = EM_NORMAL,
const QString &text = QString(),
const QString &placeholderText = QString(), bool *ok = Q_NULLPTR,
Qt::InputMethodHints inputMethodHints = Qt::ImhNone);
......@@ -124,4 +134,9 @@ public:
Q_DECLARE_OPERATORS_FOR_FLAGS(Dialogues::Buttons)
/* QML passes its arguments via QVariant. */
Q_DECLARE_METATYPE(Dialogues::EchoMode)
Q_DECLARE_METATYPE(Dialogues::Icon)
Q_DECLARE_METATYPE(Dialogues::Button)
#endif /* _DIALOGUES_H_ */
......@@ -28,11 +28,6 @@
QmlDlgHelper *QmlDlgHelper::dlgEmitter = Q_NULLPTR;
void QmlDlgHelper::declareQML(void)
{
qmlRegisterType<QmlDlgHelper>("cz.nic.mobileDatovka.qmlDialogue", 1, 0, "QmlDlgEchoMode");
}
void QmlDlgHelper::emitAccepted(const QString &input)
{
emit accepted(input);
......
......@@ -40,23 +40,6 @@ class QmlDlgHelper : public QObject {
Q_OBJECT
public:
/*
* See TextInput documentation.
* QQuickTextField header file, where similar enum values are defined,
* cannot be accessed directly.
*/
enum QmlDlgEchoMode {
EM_NORMAL,
EM_PWD,
EM_NOECHO,
EM_PWD_ECHOONEDIT
};
Q_ENUMS(QmlDlgEchoMode)
/* Don't forget to declare various properties to the QML system. */
static
void declareQML(void);
/*!
* @brief Emits accepted signal.
*
......@@ -122,7 +105,7 @@ signals:
* @brief This signal should be emitted when QML message dialogue
* should be displayed.
*/
void dlgMessage(const QString &title, const QString &message,
void dlgMessage(int icon, const QString &title, const QString &message,
const QString &infoMessage);
/*!
......
......@@ -24,6 +24,7 @@
#include <QQmlApplicationEngine>
//#include <QQuickItem>
#include "src/dialogues/qml_dialogue_helper.h"
#include "src/dialogues/qml_input_dialogue.h"
QObject *QmlInputDialogue::s_dlgTextInput = Q_NULLPTR;
......@@ -104,9 +105,8 @@ QmlInputDialogue::QmlInputDialogue(QObject *parent, QWindow *window)
#endif
QString QmlInputDialogue::getText(QWindow *parent, const QString &title,
const QString &message,
enum QmlDlgHelper::QmlDlgEchoMode echoMode, const QString &text,
const QString &placeholderText, bool *ok,
const QString &message, enum Dialogues::EchoMode echoMode,
const QString &text, const QString &placeholderText, bool *ok,
Qt::InputMethodHints inputMethodHints)
{
QmlInputDialogue dialogue(parent, QmlDlgHelper::topLevelWindow());
......
......@@ -29,7 +29,7 @@
#include <QString>
#include <QWindow>
#include "src/dialogues/qml_dialogue_helper.h"
#include "src/dialogues/dialogues.h"
class QQmlApplicationEngine; /* Forward declaration. */
......@@ -67,7 +67,7 @@ public:
static
QString getText(QWindow *parent, const QString &title,
const QString &message,
enum QmlDlgHelper::QmlDlgEchoMode echoMode = QmlDlgHelper::EM_NORMAL,
enum Dialogues::EchoMode echoMode = Dialogues::EM_NORMAL,
const QString &text = QString(),
const QString &placeholderText = QString(), bool *ok = Q_NULLPTR,
Qt::InputMethodHints inputMethodHints = Qt::ImhNone);
......
......@@ -32,8 +32,9 @@ QmlMessageDialogue::QmlMessageDialogue(QObject *parent, QWindow *window)
Q_UNUSED(window)
}
void QmlMessageDialogue::errorMessage(QWindow *parent, const QString &title,
const QString &text, const QString &infoText)
void QmlMessageDialogue::errorMessage(QWindow *parent,
enum Dialogues::Icon icon, const QString &title, const QString &text,
const QString &infoText)
{
QmlMessageDialogue dialogue(parent, QmlDlgHelper::topLevelWindow());
......@@ -42,7 +43,7 @@ void QmlMessageDialogue::errorMessage(QWindow *parent, const QString &title,
&dialogue, SLOT(dlgClosed(int, int)));
/* Cause QML window to pop up. */
emit QmlDlgHelper::dlgEmitter->dlgMessage(title, text, infoText);
emit QmlDlgHelper::dlgEmitter->dlgMessage(icon, title, text, infoText);
if (!dialogue.m_alreadyReturned) {
dialogue.m_loop.exec();
......
......@@ -29,6 +29,8 @@
#include <QString>
#include <QWindow>
#include "src/dialogues/dialogues.h"
/*!
* @brief Encapsulates QML-based dialogues.
*/
......@@ -49,13 +51,14 @@ public:
* @brief Generates error message dialogue with.
*
* @param[in] parent Parent window.
* @param[in] icon Identifies importance level.
* @param[in] title Window title.
* @param[in] text Text shown in dialogue window.
* @param[in] infoText Informative text.
*/
static
void errorMessage(QWindow *parent, const QString &title,
const QString &text, const QString &infoText);
void errorMessage(QWindow *parent, enum Dialogues::Icon icon,
const QString &title, const QString &text, const QString &infoText);
private slots:
/*!
......
......@@ -271,12 +271,12 @@ int main(int argc, char *argv[])
registerQmlTypes(uri, QML_DIALOGUES, qmlDialogues);
/* Register types into QML. */
Dialogues::declareQML();
FileListModel::declareQML();
ListSortFilterProxyModel::declareQML();
MessageListModel::declareQML();
Messages::declareQML();
MsgInfo::declareQML();
QmlDlgHelper::declareQML();
InteractionZfoFile interactionZfoFile;
......
......@@ -126,7 +126,7 @@ bool IsdsSession::setCertificateData(const QString &userName,
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"),
Dialogues::EM_PWD, QString(), tr("Enter certificate password"),
&ok);
// is PEM format
......
......@@ -347,7 +347,7 @@ void IsdsWrapper::changePassword(const QString &userName,
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);
Dialogues::EM_NORMAL, QString(), tr("Enter password"), &ok);
if (!ok) {
return;
}
......@@ -382,7 +382,7 @@ void IsdsWrapper::changePassword(const QString &userName,
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"),
Dialogues::EM_NORMAL, QString(), tr("Enter SMS code"),
&ok, Qt::ImhDigitsOnly);
if (ok && !text.isEmpty()) {
m_isdsSession.isdsCtxMap[userName].pass_phrase = text;
......@@ -394,7 +394,7 @@ void IsdsWrapper::changePassword(const QString &userName,
QString text = Dialogues::getText(Q_NULLPTR,
tr("Security code: %1").arg(userName),
tr("Security code for '%1' required").arg(accountName),
QmlDlgHelper::EM_NORMAL, QString(),
Dialogues::EM_NORMAL, QString(),
tr("Enter security code"), &ok, Qt::ImhDigitsOnly);
if (ok && !text.isEmpty()) {
m_isdsSession.isdsCtxMap[userName].pass_phrase = text;
......
......@@ -143,7 +143,7 @@ bool NetLayer::createLoginRequest(IsdsContext &ctx,
pwd = Dialogues::getText(Q_NULLPTR,
tr("Password: %1").arg(ctx.username),
tr("Password for '%1' missing").arg(ctx.account_name),
QmlDlgHelper::EM_PWD, QString(),
Dialogues::EM_PWD, QString(),
tr("Enter password"), &ok);
if (!ok) {
ctx.password = "";
......@@ -162,7 +162,7 @@ bool NetLayer::createLoginRequest(IsdsContext &ctx,
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(),
Dialogues::EM_NORMAL, QString(),
tr("Enter security code"), &ok, Qt::ImhDigitsOnly);
if (!ok) {
ctx.last_isds_msg = "";
......@@ -581,7 +581,7 @@ bool NetLayer::doTotpLoginRequest(IsdsContext &ctx, const QByteArray &xmlDataIn,
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,
Dialogues::EM_NORMAL,
QString(), tr("Enter SMS code"), &ok,
Qt::ImhDigitsOnly);
} else {
......@@ -589,7 +589,7 @@ bool NetLayer::doTotpLoginRequest(IsdsContext &ctx, const QByteArray &xmlDataIn,
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,
Dialogues::EM_NORMAL,
QString(), tr("Enter SMS code"), &ok,
Qt::ImhDigitsOnly);
}
......
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