Commit 1e51026d authored by Karel Slaný's avatar Karel Slaný
Browse files

Exporting enum MessageDb::MessageType through Messages::MessageType into QML.

Using the enum type extensively throughout the C++ and QML code.
Previous solution used constants defined on at lest two places. These
constants were in conflict with enum MessageDb::MessageType!
parent 6eb70153
......@@ -27,7 +27,7 @@ import QtQuick.Controls 2.0
import QtQuick.Window 2.1
import QtQuick.Layouts 1.2
import QtQuick.Dialogs 1.2
import cz.nic.mobiledatovka 1.0
import cz.nic.mobileDatovka 1.0
ApplicationWindow {
......@@ -77,9 +77,6 @@ ApplicationWindow {
property int acntListSpacing: defaultMargin * 2
property int formItemVerticalSpacing: defaultMargin * 3
property int formButtonHorizontalSpacing: defaultMargin * 5
// message type = must correspond with common.h
property int receivedMESSAGE: 1
property int sentMESSAGE: 0
// global passing arguments between pages
property string gUserName
property string gAcntName
......
......@@ -27,6 +27,7 @@ import QtQuick.Window 2.1
import QtQuick.Layouts 1.2
import QtQuick.Dialogs 1.2
import QtGraphicalEffects 1.0
import cz.nic.mobileDatovka.messages 1.0
Component {
id: accountspage
......@@ -281,9 +282,9 @@ Component {
onClicked: {
gAcntName = rAcntName
gUserName = rUserName
gMsgType = receivedMESSAGE
gMsgType = MessageType.TYPE_RECEIVED
statusBar.visible = false
messages.fillMessageList(rUserName, receivedMESSAGE)
messages.fillMessageList(rUserName, MessageType.TYPE_RECEIVED)
pageView.push(messagesPage, StackView.Immediate)
}
}
......@@ -347,9 +348,9 @@ Component {
onClicked: {
gAcntName = rAcntName
gUserName = rUserName
gMsgType = sentMESSAGE
gMsgType = MessageType.TYPE_SENT
statusBar.visible = false
messages.fillMessageList(rUserName, sentMESSAGE)
messages.fillMessageList(rUserName, MessageType.TYPE_SENT)
pageView.push(messagesPage, StackView.Immediate)
}
}
......
......@@ -28,7 +28,7 @@ import QtQuick.Window 2.1
import QtQuick.Layouts 1.2
import QtQuick.Dialogs 1.2
import QtGraphicalEffects 1.0
import cz.nic.mobileDatovka.messages 1.0
Component {
id: messageDetailMenuPage
......@@ -67,10 +67,10 @@ Component {
anchors.leftMargin: defaultMargin
Label {
text: {
if (gMsgType == sentMESSAGE) {
qsTr("Sent message") + " " + gMsgId
} else {
if (gMsgType == MessageType.TYPE_RECEIVED) {
qsTr("Received message") + " " + gMsgId
} else {
qsTr("Sent message") + " " + gMsgId
}
}
font.bold: true
......
......@@ -28,6 +28,7 @@ import QtQuick.Window 2.1
import QtQuick.Layouts 1.2
import QtQuick.Dialogs 1.2
import QtGraphicalEffects 1.0
import cz.nic.mobileDatovka.messages 1.0
Component {
id: messageDetailPage
......@@ -79,10 +80,10 @@ Component {
}
Label {
text: {
if (gMsgType == sentMESSAGE) {
qsTr("Sent message") + " " + gMsgId
} else {
if (gMsgType == MessageType.TYPE_RECEIVED) {
qsTr("Received message") + " " + gMsgId
} else {
qsTr("Sent message") + " " + gMsgId
}
}
font.bold: true
......
......@@ -28,7 +28,7 @@ import QtQuick.Window 2.1
import QtQuick.Layouts 1.2
import QtQuick.Dialogs 1.2
import QtGraphicalEffects 1.0
import cz.nic.mobileDatovka.messages 1.0
Component {
id: messageMenuPage
......@@ -71,10 +71,10 @@ Component {
anchors.leftMargin: defaultMargin
Label {
text: {
if (gMsgType == sentMESSAGE) {
qsTr("Sent message") + " " + gMsgId
} else {
if (gMsgType == MessageType.TYPE_RECEIVED) {
qsTr("Received message") + " " + gMsgId
} else {
qsTr("Sent message") + " " + gMsgId
}
}
font.bold: true
......
......@@ -28,7 +28,7 @@ import QtQuick.Window 2.1
import QtQuick.Layouts 1.2
import QtQuick.Dialogs 1.2
import QtGraphicalEffects 1.0
import cz.nic.mobileDatovka.messages 1.0
Component {
id: messagesMenuPage
......@@ -67,10 +67,10 @@ Component {
anchors.leftMargin: defaultMargin
Label {
text: {
if (gMsgType == sentMESSAGE) {
qsTr("Sent messages")
} else {
if (gMsgType == MessageType.TYPE_RECEIVED) {
qsTr("Received messages")
} else {
qsTr("Sent messages")
}
}
font.bold: true
......
......@@ -28,6 +28,7 @@ import QtQuick.Window 2.1
import QtQuick.Layouts 1.2
import QtQuick.Dialogs 1.2
import QtGraphicalEffects 1.0
import cz.nic.mobileDatovka.messages 1.0
Component {
id: messagespage
......@@ -79,10 +80,10 @@ Component {
}
Label {
text: {
if (gMsgType == sentMESSAGE) {
qsTr("Sent messages")
} else {
if (gMsgType == MessageType.TYPE_RECEIVED) {
qsTr("Received messages")
} else {
qsTr("Sent messages")
}
}
font.bold: true
......@@ -281,9 +282,9 @@ Component {
onMovementEnded: {
if (downloadStart) {
downloadStart = false
if (gMsgType == receivedMESSAGE) {
if (gMsgType == MessageType.TYPE_RECEIVED) {
isds.syncSingleAccountReceived(gUserName)
} else if (gMsgType == sentMESSAGE) {
} else if (gMsgType == MessageType.TYPE_SENT) {
isds.syncSingleAccountSent(gUserName)
}
messages.fillMessageList(gUserName, gMsgType)
......
......@@ -59,8 +59,8 @@ void Accounts::updateNewMessageCounter(const QString &userName)
}
globAccountsModelPtr->updateCounters(userName,
msgDb->getCntOfNewMsgs(RECEIVED_MESSAGE), -1,
msgDb->getCntOfNewMsgs(SENT_MESSAGE), -1);
msgDb->getCntOfNewMsgs(MessageDb::TYPE_RECEIVED), -1,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_SENT), -1);
}
......@@ -358,10 +358,10 @@ void Accounts::loadModelCounters(void)
}
globAccountsModelPtr->updateCounters(userName,
msgDb->getCntOfNewMsgs(RECEIVED_MESSAGE),
msgDb->getMessageCount(RECEIVED_MESSAGE),
msgDb->getCntOfNewMsgs(SENT_MESSAGE),
msgDb->getMessageCount(SENT_MESSAGE));
msgDb->getCntOfNewMsgs(MessageDb::TYPE_RECEIVED),
msgDb->getMessageCount(MessageDb::TYPE_RECEIVED),
msgDb->getCntOfNewMsgs(MessageDb::TYPE_SENT),
msgDb->getMessageCount(MessageDb::TYPE_SENT));
}
}
......
......@@ -41,10 +41,6 @@
(QString("<div>") + (title) + ": " + (value) + "</div>")
#define divEnd "</div>"
/* MESSAGE TYPE */
#define RECEIVED_MESSAGE 1
#define SENT_MESSAGE 0
/* LOGIN METHOD TYPE */
#define USERNAME_PWD_ONLY "pwd" //qml combobox index = 0
#define USERNAME_PWD_CERT "cert" //qml combobox index = 1
......
......@@ -44,7 +44,7 @@
#include "src/setwrapper.h"
/* namespace for QML registered objects */
const char *uri = "cz.nic.mobiledatovka";
const char *uri = "cz.nic.mobileDatovka";
/* For registering of pages */
static const struct {
......@@ -153,6 +153,9 @@ int main(int argc, char *argv[])
qmldir_pages[i].type);
}
/* Register types into QML. */
Messages::declareQML();
/* register classes in QML */
ctx->setContextProperty("isds", &isds);
ctx->setContextProperty("messages", &messages);
......
......@@ -26,6 +26,7 @@
#include <QMessageBox>
#include <QPair>
#include <QPushButton>
#include <QQmlEngine> /* qmlRegisterType */
#include <QStorageInfo>
#include "src/common.h"
......@@ -35,6 +36,10 @@
#include "src/sqlite/message_db_container.h"
#include "src/sqlite/file_db_container.h"
void Messages::declareQML(void)
{
qmlRegisterType<Messages>("cz.nic.mobileDatovka.messages", 1, 0, "MessageType");
}
Messages::Messages(QObject *parent) : QObject(parent)
{
......@@ -56,7 +61,8 @@ void Messages::clearMessagesModel(void)
/*
* Slot: Fill message list in QML.
*/
void Messages::fillMessageList(const QString &userName, int msgType)
void Messages::fillMessageList(const QString &userName,
enum MessageType msgType)
/* ========================================================================= */
{
qDebug("%s()", __func__);
......@@ -70,7 +76,9 @@ void Messages::fillMessageList(const QString &userName, int msgType)
}
globMessagesModel.clearAll();
msgDb->getMessageListDataFromDb(msgType);
/* Translate into database enum type. */
msgDb->getMessageListDataFromDb((msgType == TYPE_RECEIVED) ?
MessageDb::TYPE_RECEIVED : MessageDb::TYPE_SENT);
}
......@@ -187,10 +195,10 @@ void Messages::deleteMessageFromDbs(const QString &userName, qint64 msgId)
/* Remove row from model, don't regenerate data. */
globMessagesModel.removeMessage(msgId);
globAccountsModelPtr->updateCounters(userName,
msgDb->getCntOfNewMsgs(RECEIVED_MESSAGE),
msgDb->getMessageCount(RECEIVED_MESSAGE),
msgDb->getCntOfNewMsgs(SENT_MESSAGE),
msgDb->getMessageCount(SENT_MESSAGE));
msgDb->getCntOfNewMsgs(MessageDb::TYPE_RECEIVED),
msgDb->getMessageCount(MessageDb::TYPE_RECEIVED),
msgDb->getCntOfNewMsgs(MessageDb::TYPE_SENT),
msgDb->getMessageCount(MessageDb::TYPE_SENT));
}
}
}
......
......@@ -34,6 +34,16 @@ class Messages : public QObject {
Q_OBJECT
public:
/* See class MessageDb. */
enum MessageType {
TYPE_RECEIVED = 1, /*!< One is received. */
TYPE_SENT = 2 /*!< Two is sent. */
};
Q_ENUMS(MessageType)
/* Don't forget to declare various propertiers to the QML system. */
static
void declareQML(void);
Messages(QObject* parent = 0);
......@@ -41,7 +51,7 @@ public:
* @brief Load messages from databse and fill QML listview via model.
*/
Q_INVOKABLE void fillMessageList(const QString &userName,
int msgType);
enum MessageType msgType);
/*!
* @brief Load message detail from databse and fill QML
......
......@@ -41,7 +41,8 @@ DbWrapper::~DbWrapper(void)
/*
* Func: Insert messagelist to db.
*/
bool DbWrapper::insertMessageListToDb(const QString &userName, int messageType,
bool DbWrapper::insertMessageListToDb(const QString &userName,
enum MessageDb::MessageType messageType,
const QList<Messages::Message> &messages, QString &txt)
/* ========================================================================= */
{
......@@ -72,10 +73,11 @@ bool DbWrapper::insertMessageListToDb(const QString &userName, int messageType,
}
msgDb->commitTransaction();
if (messageType == RECEIVED_MESSAGE) {
if (messageType == MessageDb::TYPE_RECEIVED) {
globAccountsModelPtr->updateCounters(userName,
msgDb->getCntOfNewMsgs(RECEIVED_MESSAGE),
msgDb->getMessageCount(RECEIVED_MESSAGE), -1, -1);
msgDb->getCntOfNewMsgs(MessageDb::TYPE_RECEIVED),
msgDb->getMessageCount(MessageDb::TYPE_RECEIVED),
-1, -1);
if (newMsgs > 0) {
txt = tr("%1: new messages: %2")
......@@ -84,9 +86,10 @@ bool DbWrapper::insertMessageListToDb(const QString &userName, int messageType,
txt = tr("%1: No new messages.").arg(userName);
}
} else {
globAccountsModelPtr->updateCounters(userName, -1, -1,
msgDb->getCntOfNewMsgs(SENT_MESSAGE),
msgDb->getMessageCount(SENT_MESSAGE));
globAccountsModelPtr->updateCounters(userName,
-1, -1,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_SENT),
msgDb->getMessageCount(MessageDb::TYPE_SENT));
}
//qDebug() << "Messages:" << messages.count();
......
......@@ -111,7 +111,8 @@ public:
* @param[out] txt - error description if something fails.
* @return true if success.
*/
bool insertMessageListToDb(const QString &userName, int messageType,
bool insertMessageListToDb(const QString &userName,
enum MessageDb::MessageType messageType,
const QList<Messages::Message> &messages, QString &txt);
/*!
......
......@@ -63,21 +63,21 @@ void IsdsWrapper::downloadMessage(const QString &userName, int mesasgeType,
return;
}
if (mesasgeType == SENT_MESSAGE) {
if (!m_xmlLayer.isdsGetCompleteSentMsgWithCms(
if (mesasgeType == MessageDb::TYPE_RECEIVED) {
if (!m_xmlLayer.isdsGetCompleteMsgWithoutCms(
m_isdsSession.isdsCtxMap[userName], msgId)) {
showErrorMessageBox(
tr("Downloading message: %1").arg(userName),
tr("Failed to download complete sent message %1.").arg(msgId),
showErrorMessageBox(tr("Delivery info: %1").arg(userName),
tr("Failed to download complete received message %1.").arg(msgId),
m_isdsSession.isdsCtxMap[userName].last_isds_msg,
true);
return;
}
} else {
if (!m_xmlLayer.isdsGetCompleteMsgWithoutCms(
if (!m_xmlLayer.isdsGetCompleteSentMsgWithCms(
m_isdsSession.isdsCtxMap[userName], msgId)) {
showErrorMessageBox(tr("Delivery info: %1").arg(userName),
tr("Failed to download complete received message %1.").arg(msgId),
showErrorMessageBox(
tr("Downloading message: %1").arg(userName),
tr("Failed to download complete sent message %1.").arg(msgId),
m_isdsSession.isdsCtxMap[userName].last_isds_msg,
true);
return;
......@@ -203,7 +203,8 @@ bool IsdsWrapper::syncSingleAccountReceived(const QString &userName)
if (globSet.downloadCompleteMsgs) {
foreach (qint64 msgId, receivedMsgIds) {
downloadMessage(userName, RECEIVED_MESSAGE, msgId);
downloadMessage(userName, MessageDb::TYPE_RECEIVED,
msgId);
}
}
......@@ -243,7 +244,7 @@ bool IsdsWrapper::syncSingleAccountSent(const QString &userName)
if (globSet.downloadCompleteMsgs) {
foreach (qint64 msgId, sentMsgIds) {
downloadMessage(userName, SENT_MESSAGE, msgId);
downloadMessage(userName, MessageDb::TYPE_SENT, msgId);
}
}
......
......@@ -65,6 +65,10 @@ public:
bool syncSingleAccountSent(const QString &userName);
Q_INVOKABLE bool getAccountInfo(const QString &userName, bool firstLogin);
/*
* Cannot use enum Messages::MessageType here; QML complains about
* unknown type.
*/
Q_INVOKABLE void downloadMessage(const QString &userName,
int mesasgeType, qint64 msgId);
Q_INVOKABLE void getDeliveryInfo(const QString &userName, qint64 msgId);
......
......@@ -219,7 +219,7 @@ bool XmlLayer::isdsGetReceivedMessageList(IsdsContext &ctx,
}
QList<Messages::Message> messages;
if (!parseGetListOfMessagesResponse(RECEIVED_MESSAGE, xmlDataOut,
if (!parseGetListOfMessagesResponse(MessageDb::TYPE_RECEIVED, xmlDataOut,
messages, ctx.last_isds_msg)) {
return false;
}
......@@ -232,8 +232,8 @@ bool XmlLayer::isdsGetReceivedMessageList(IsdsContext &ctx,
msgIds.append(msg.dmID);
}
return m_dbWrapper.insertMessageListToDb(ctx.username, RECEIVED_MESSAGE,
messages, ctx.last_isds_msg);
return m_dbWrapper.insertMessageListToDb(ctx.username,
MessageDb::TYPE_RECEIVED, messages, ctx.last_isds_msg);
}
......@@ -270,7 +270,7 @@ bool XmlLayer::isdsGetSentMessageList(IsdsContext &ctx,
}
QList<Messages::Message> messages;
if (!parseGetListOfMessagesResponse(SENT_MESSAGE, xmlDataOut,
if (!parseGetListOfMessagesResponse(MessageDb::TYPE_SENT, xmlDataOut,
messages, ctx.last_isds_msg)) {
return false;
}
......@@ -283,8 +283,8 @@ bool XmlLayer::isdsGetSentMessageList(IsdsContext &ctx,
msgIds.append(msg.dmID);
}
return m_dbWrapper.insertMessageListToDb(ctx.username, SENT_MESSAGE,
messages, ctx.last_isds_msg);
return m_dbWrapper.insertMessageListToDb(ctx.username,
MessageDb::TYPE_SENT, messages, ctx.last_isds_msg);
}
......@@ -875,7 +875,7 @@ bool XmlLayer::parseSignedSentMessageDownloadResponse(const QByteArray &xmlData,
/*
* Func: Parse message list from xml.
*/
bool XmlLayer::parseGetListOfMessagesResponse(int messageType,
bool XmlLayer::parseGetListOfMessagesResponse(enum MessageDb::MessageType messageType,
const QByteArray &xmlData, QList<Messages::Message> &messages, QString &txt)
/* ========================================================================= */
{
......@@ -1010,7 +1010,7 @@ bool XmlLayer::parseGetPasswordInfo(const QByteArray &xmlData,
* Func: Parse message envelope from xml.
*/
Messages::Message XmlLayer::msgEnvelopeParse(QXmlStreamReader &xml,
int messageType)
enum MessageDb::MessageType messageType)
/* ========================================================================= */
{
Messages::Message msg;
......
......@@ -245,7 +245,7 @@ private:
* @param[out] txt - error description if something failed.
* @return true if success.
*/
bool parseGetListOfMessagesResponse(int messageType,
bool parseGetListOfMessagesResponse(enum MessageDb::MessageType messageType,
const QByteArray &xmlData, QList<Messages::Message> &messages,
QString &txt);
......@@ -314,7 +314,7 @@ private:
* @return Message envelope structure.
*/
Messages::Message msgEnvelopeParse(QXmlStreamReader &xml,
int messageType);
enum MessageDb::MessageType messageType);
/*!
* @brief Parse completeMessageParse XML.
......
......@@ -572,13 +572,13 @@ short MessageDb::getMessageStatusFromDb(qint64 msgId) const
/*
* Select model data for message list in QML page.
*/
void MessageDb::getMessageListDataFromDb(int messageType)
void MessageDb::getMessageListDataFromDb(enum MessageType messageType)
/* ========================================================================= */
{
QSqlQuery query(m_db);
QString queryStr = "SELECT dmID, ";
queryStr += (RECEIVED_MESSAGE == messageType) ?
queryStr += (TYPE_RECEIVED == messageType) ?
"dmSender" : "dmRecipient";
queryStr += ", dmAnnotation, dmDeliveryTime, dmAcceptanceTime, "
"_dmReadLocally, _dmAttachDownloaded FROM messages "
......@@ -785,7 +785,7 @@ QString MessageDb::getMessageDetailDataFromDb(qint64 dmId) const
html += strongInfoLine(QObject::tr("Delivery by fiction"),
(query.value(11).toBool()) ? QObject::tr("Yes") : QObject::tr("No"));
if (query.value(0).toInt() == RECEIVED_MESSAGE) {
if (query.value(0).toInt() == TYPE_RECEIVED) {
/* Information about message sender. */
html += "<h3>" + QObject::tr("Sender") + "</h3>";
html += strongInfoLine(QObject::tr("Databox ID"),
......@@ -906,7 +906,7 @@ fail:
/*
* Func: Get count of new messages.
*/
int MessageDb::getCntOfNewMsgs(int messageType)
int MessageDb::getCntOfNewMsgs(enum MessageType messageType)
/* ========================================================================= */
{
QSqlQuery query(m_db);
......@@ -933,7 +933,7 @@ int MessageDb::getCntOfNewMsgs(int messageType)
/*
* Func: Get count of received/sent messages.
*/
int MessageDb::getMessageCount(int messageType)
int MessageDb::getMessageCount(enum MessageType messageType)
/* ========================================================================= */
{
QSqlQuery query(m_db);
......
......@@ -122,10 +122,10 @@ public:
/*!
* @brief Get list of messages from db - for QML.
*
* @param[in] int messageType.
* @param[in] messageType Received or sent.
* @return messageListModel for QML.
*/
void getMessageListDataFromDb(int messageType);
void getMessageListDataFromDb(enum MessageType messageType);
/*!
* @brief Check if message exists in the database.
......@@ -192,18 +192,18 @@ public:
/*!
* @brief Get count of new messages.
*
* @param[in] int message type.
* @param[in] messageType Message type.
* @return count.
*/
int getCntOfNewMsgs(int messageType);
int getCntOfNewMsgs(enum MessageType messageType);
/*!
* @brief Get count of received/sent messages.
*
* @param[in] int message type.
* @param[in] messageType Message type.
* @return count.
*/
int getMessageCount(int messageType);
int getMessageCount(enum MessageType messageType);
/*!
* @brief Update author data.
......
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