Commit 8052c201 authored by Karel Slaný's avatar Karel Slaný

Removed most of globMessagesModel calls from C++ code.

parent 1e2a7b3f
......@@ -29,6 +29,7 @@ import QtQuick.Dialogs 1.2
import QtGraphicalEffects 1.0
import cz.nic.mobileDatovka 1.0
import cz.nic.mobileDatovka.messages 1.0
import cz.nic.mobileDatovka.models 1.0
Component {
id: menuMessage
......@@ -161,11 +162,11 @@ Component {
if (index == 0) {
isds.downloadMessage(userName, msgType, msgId)
} else if (index == 1) {
messages.markMessageAsLocallyRead(userName, msgId, true)
messages.markMessageAsLocallyRead(messageListModel, userName, msgId, true)
} else if (index == 2) {
messages.markMessageAsLocallyRead(userName, msgId, false)
messages.markMessageAsLocallyRead(messageListModel, userName, msgId, false)
} else if (index == 3) {
messages.deleteMessageFromDbs(userName, msgId)
messages.deleteMessageFromDbs(messageListModel, userName, msgId)
}
pageView.pop(StackView.Immediate)
}
......
......@@ -137,9 +137,9 @@ Component {
anchors.fill: parent
onClicked: {
if (index == 0) {
messages.markMessagesAsLocallyRead(userName, msgType, true)
messages.markMessagesAsLocallyRead(messageListModel, userName, msgType, true)
} else if (index == 1) {
messages.markMessagesAsLocallyRead(userName, msgType, false)
messages.markMessagesAsLocallyRead(messageListModel, userName, msgType, false)
}
pageView.pop(StackView.Immediate)
}
......
......@@ -87,7 +87,7 @@ Component {
} else if (fromLocalDb && (userName.length != 0) && (msgId.length != 0)) {
zfoId = msgId
messages.markMessageAsLocallyRead(userName, msgId, true)
messages.markMessageAsLocallyRead(messageListModel, userName, msgId, true)
msgDescrHtml = messages.getMessageDetail(userName, zfoId)
attachmentModel.setFromDb(userName, zfoId)
......
......@@ -82,7 +82,6 @@ Component {
MouseArea {
anchors.fill: parent
onClicked: {
messages.clearMessagesModel()
accounts.updateNewMessageCounter(userName)
statusBar.visible = false
pageView.pop(StackView.Immediate)
......
......@@ -47,16 +47,6 @@ Messages::Messages(QObject *parent) : QObject(parent)
{
}
/* ========================================================================= */
/*
* Slot: Clear message model in QML.
*/
void Messages::clearMessagesModel(void)
/* ========================================================================= */
{
globMessagesModel.clearAll();
}
/*!
* @brief Translate message type enumeration type into database representation.
*/
......@@ -135,58 +125,55 @@ QString Messages::getMessageDetail(const QString &userName,
return msgDb->getMessageDetailDataFromDb(msgId);
}
/* ========================================================================= */
/*
* Slot: Set message in database as locally read.
*/
void Messages::markMessageAsLocallyRead(const QString &userName, qint64 msgId,
bool isRead)
/* ========================================================================= */
void Messages::markMessageAsLocallyRead(const QVariant &msgModelVariant,
const QString &userName, qint64 msgId, bool isRead)
{
qDebug("%s()", __func__);
MessageDb *msgDb = NULL;
msgDb = globMessageDbsPtr->accessMessageDb(globSet.dbsLocation, userName,
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == NULL) {
qDebug() << "ERROR: Message database cannot open!";
if (msgDb == Q_NULLPTR) {
qCritical() << "Cannot open message database.";
return;
}
msgDb->markMessageLocallyRead(msgId, isRead);
globMessagesModel.overrideRead(msgId, isRead);
}
MessageListModel *messageModel =
MessageListModel::fromVariant(msgModelVariant);
if (messageModel == Q_NULLPTR) {
qWarning("%s", "Cannot access message model.");
return;
}
messageModel->overrideRead(msgId, isRead);
}
/* ========================================================================= */
/*
* Slot: Set all messages in database as locally read/unread.
*/
void Messages::markMessagesAsLocallyRead(const QString &userName,
enum MessageType msgType, bool isRead)
/* ========================================================================= */
void Messages::markMessagesAsLocallyRead(const QVariant &msgModelVariant,
const QString &userName, enum MessageType msgType, bool isRead)
{
qDebug("%s()", __func__);
MessageDb *msgDb = NULL;
msgDb = globMessageDbsPtr->accessMessageDb(globSet.dbsLocation, userName,
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == NULL) {
qDebug() << "ERROR: Message database cannot open!";
if (msgDb == Q_NULLPTR) {
qCritical() << "Cannot open message database.";
return;
}
msgDb->markMessagesLocallyRead(enumToDbRepr(msgType), isRead);
MessageListModel *messageModel =
MessageListModel::fromVariant(msgModelVariant);
if (messageModel == Q_NULLPTR) {
qWarning("%s", "Cannot access message model.");
return;
}
/* The current model should correspond with supplied type. */
globMessagesModel.overrideReadAll(isRead);
messageModel->overrideReadAll(isRead);
}
/* ========================================================================= */
/*
* Slot: Delete selected message from databases.
*/
void Messages::deleteMessageFromDbs(const QString &userName, qint64 msgId)
/* ========================================================================= */
void Messages::deleteMessageFromDbs(const QVariant &msgModelVariant,
const QString &userName, qint64 msgId)
{
qDebug("%s()", __func__);
......@@ -207,26 +194,34 @@ void Messages::deleteMessageFromDbs(const QString &userName, qint64 msgId)
return;
}
MessageDb *msgDb = NULL;
msgDb = globMessageDbsPtr->accessMessageDb(globSet.dbsLocation, userName,
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == NULL) {
qDebug() << "ERROR: Message database cannot open!" << userName;
if (msgDb == Q_NULLPTR) {
qCritical() << "Cannot open message database.";
return;
}
FileDb *fDb = NULL;
fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == NULL) {
qDebug() << "ERROR: File database cannot open!" << userName;
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "Cannot open file database for "
<< userName << ".";
return;
}
MessageListModel *messageModel =
MessageListModel::fromVariant(msgModelVariant);
if (messageModel == Q_NULLPTR) {
qWarning("%s", "Cannot access message model.");
}
if (fDb->deleteFilesFromDb(msgId)) {
if (msgDb->deleteMsgFromDb(msgId)) {
/* Remove row from model, don't regenerate data. */
globMessagesModel.removeMessage(msgId);
if (messageModel != Q_NULLPTR) {
messageModel->removeMessage(msgId);
}
globAccountsModelPtr->updateCounters(userName,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_RECEIVED),
msgDb->getMessageCount(MessageDb::TYPE_RECEIVED),
......
......@@ -78,25 +78,23 @@ public:
/*!
* @brief Set message in database as locally read.
*/
Q_INVOKABLE void markMessageAsLocallyRead(const QString &userName,
qint64 msgId, bool isRead);
Q_INVOKABLE static
void markMessageAsLocallyRead(const QVariant &msgModelVariant,
const QString &userName, qint64 msgId, bool isRead);
/*!
* @brief Set all messages in database as locally read/unread.
*/
Q_INVOKABLE void markMessagesAsLocallyRead(const QString &userName,
enum MessageType msgType, bool isRead);
/*!
* @brief Clear message model.
*/
Q_INVOKABLE void clearMessagesModel(void);
Q_INVOKABLE static
void markMessagesAsLocallyRead(const QVariant &msgModelVariant,
const QString &userName, enum MessageType msgType, bool isRead);
/*!
* @brief Delete selected message from databases.
*/
Q_INVOKABLE void deleteMessageFromDbs(const QString &userName,
qint64 msgId);
Q_INVOKABLE static
void deleteMessageFromDbs(const QVariant &msgModelVariant,
const QString &userName, qint64 msgId);
/*!
* @brief Move or create new databases to new location.
......
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