Commit 616559f9 authored by Martin Straka's avatar Martin Straka

Added save message zfo to extrenal storage

parent b46e2b5f
......@@ -121,15 +121,19 @@ Component {
}, StackView.Immediate)
},
"sendAttachEmail": function callSendAttachEmail() {
files.sendMsgFilesWithEmail(userName, msgId, EmailAttachFlag.MSG_ATTACHS)
files.sendMsgFilesWithEmail(userName, msgId, MsgAttachFlag.MSG_ATTACHS)
pageView.pop(StackView.Immediate)
},
"sendZfoEmail": function callSendZfoEmail() {
files.sendMsgFilesWithEmail(userName, msgId, EmailAttachFlag.MSG_ZFO)
files.sendMsgFilesWithEmail(userName, msgId, MsgAttachFlag.MSG_ZFO)
pageView.pop(StackView.Immediate)
},
"saveAttachs": function callSaveAttachs() {
files.saveAttachmentsToDiskDb(userName, msgId)
"saveAttachDisk": function callSaveAttachDisk() {
files.saveMsgFilesToDisk(userName, msgId, MsgAttachFlag.MSG_ATTACHS)
pageView.pop(StackView.Immediate)
},
"saveZfoDisk": function callSaveZfoDisk() {
files.saveMsgFilesToDisk(userName, msgId, MsgAttachFlag.MSG_ZFO)
pageView.pop(StackView.Immediate)
},
"delAttachs": function callDelAttachs() {
......@@ -193,12 +197,19 @@ Component {
name: qsTr("Send attachments by email")
funcName: "sendAttachEmail"
}
ListElement {
image: "qrc:/ui/save-to-disk.svg"
showEntry: true
showNext: false
name: qsTr("Save message zfo")
funcName: "saveZfoDisk"
}
ListElement {
image: "qrc:/ui/save-to-disk.svg"
showEntry: true
showNext: false
name: qsTr("Save attachments")
funcName: "saveAttachs"
funcName: "saveAttachDisk"
}
ListElement {
image: "qrc:/ui/delete.svg"
......
......@@ -26,6 +26,7 @@ import QtQuick.Controls 2.1
import QtGraphicalEffects 1.0
import cz.nic.mobileDatovka 1.0
import cz.nic.mobileDatovka.messages 1.0
import cz.nic.mobileDatovka.files 1.0
import cz.nic.mobileDatovka.models 1.0
import cz.nic.mobileDatovka.msgInfo 1.0
......@@ -173,7 +174,7 @@ Component {
if (!fromLocalDb) {
files.saveAttachmentsToDiskZfo(attachmentModel, zfoId)
} else {
files.saveAttachmentsToDiskDb(userName, zfoId)
saveMsgFilesToDisk(userName, zfoId, MsgAttachFlag.MSG_ATTACHS)
}
}
}
......
......@@ -48,9 +48,9 @@
void Files::declareQML(void)
{
qmlRegisterType<Files>("cz.nic.mobileDatovka.files", 1, 0, "FileIdType");
qmlRegisterType<Files>("cz.nic.mobileDatovka.files", 1, 0, "EmailAttachFlag");
qmlRegisterType<Files>("cz.nic.mobileDatovka.files", 1, 0, "MsgAttachFlag");
qRegisterMetaType<Files::FileIdType>();
qRegisterMetaType<Files::EmailAttachFlag>();
qRegisterMetaType<Files::MsgAttachFlag>();
}
Files::Files(QObject *parent)
......@@ -240,7 +240,7 @@ void Files::openAttachmentFromPath(const QString &filePath)
}
void Files::sendMsgFilesWithEmail(const QString &userName, qint64 msgId,
EmailAttachFlags attachFlags)
MsgAttachFlags attachFlags)
{
qDebug("%s()", __func__);
......@@ -589,13 +589,14 @@ void Files::sendAttachmentEmailZfo(const QVariant &attachModelVariant,
sendEmail(emailMessage, fileList, subject, body, msgId);
}
void Files::saveAttachmentsToDiskDb(const QString &userName,
const QString &msgIdStr)
void Files::saveMsgFilesToDisk(const QString &userName,
const QString &msgIdStr, MsgAttachFlags attachFlags)
{
qDebug("%s()", __func__);
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR) ||
(GlobInstcs::zfoDbPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
......@@ -614,19 +615,44 @@ void Files::saveAttachmentsToDiskDb(const QString &userName,
return;
}
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
QList<FileDb::FileData> filelist;
if (fDb == Q_NULLPTR) {
qCritical() << "Cannot open file database!";
return;
/* Get attachment files from database if needed */
if (attachFlags & MSG_ATTACHS) {
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical("Cannot open file database for '%s'.",
userName.toUtf8().constData());
return;
}
filelist = fDb->getFilesFromDb(msgId);
if (filelist.isEmpty()) {
qCritical("Missing attachments for message '%s'.",
QString::number(msgId).toUtf8().constData());
return;
}
}
QList<FileDb::FileData> filelist = fDb->getFilesFromDb(msgId);
if (filelist.isEmpty()) {
qCritical() << "File list is empty!";
return;
/* Get zfo file from database if needed */
if (attachFlags & MSG_ZFO) {
FileDb::FileData msgData;
msgData.content = GlobInstcs::zfoDbPtr->getZfoContentFromDb(
msgId, (*GlobInstcs::acntMapPtr)[userName].isTestAccount());
if (msgData.content.isEmpty()) {
qCritical("Missing zfo data for message '%s'.",
QString::number(msgId).toUtf8().constData());
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("ZFO missing"),
tr("ZFO message is not present in local database."),
tr("Download complete message again to obtain it."));
Q_ASSERT(0);
return;
}
msgData.filename = QString("DZ_%1.zfo").arg(msgId);
filelist.append(msgData);
}
QString filePath(appMsgAttachDirPath(msgIdStr));
......
......@@ -38,19 +38,19 @@ class Files : public QObject {
public:
/* Defines attachment type to be sent via email */
enum EmailAttachFlag {
/* Defines file type to be saved or sent via email */
enum MsgAttachFlag {
NO_FILES = 0x00,
MSG_ZFO = 0x01, /* Complete message in zfo format. */
MSG_ATTACHS = 0x02 /* Attachments of the data message. */
};
Q_ENUM(EmailAttachFlag)
Q_ENUM(MsgAttachFlag)
/*
* Flags inside QML:
* https://forum.qt.io/topic/10060/q_enums-q_declare_metatype-and-qml/2
*/
Q_DECLARE_FLAGS(EmailAttachFlags, EmailAttachFlag)
Q_FLAG(EmailAttachFlags)
Q_DECLARE_FLAGS(MsgAttachFlags, MsgAttachFlag)
Q_FLAG(MsgAttachFlags)
/* Defines missing file id vaule and zfo id */
enum FileIdType {
......@@ -153,7 +153,7 @@ public:
*/
Q_INVOKABLE
void sendMsgFilesWithEmail(const QString &userName,
qint64 msgId, EmailAttachFlags attachFlags);
qint64 msgId, MsgAttachFlags attachFlags);
/*!
* @brief Delete file database.
......@@ -261,14 +261,16 @@ public:
const QString &msgIdStr, QString subject, QString body);
/*!
* @brief Save attachments from database to disk.
* @brief Save message attachments or complete zfo message from
* database to external storage.
*
* @param[in] userName User name identifying the account.
* @param[in] msgIdStr String with message id.
* @param[in] attachFlags Specifies which attachments to save.
*/
Q_INVOKABLE static
void saveAttachmentsToDiskDb(const QString &userName,
const QString &msgIdStr);
void saveMsgFilesToDisk(const QString &userName,
const QString &msgIdStr, MsgAttachFlags attachFlags);
/*!
* @brief Save attachments from ZFO to disk.
......@@ -373,11 +375,11 @@ private:
QByteArray &xmlData);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Files::EmailAttachFlags)
Q_DECLARE_OPERATORS_FOR_FLAGS(Files::MsgAttachFlags)
/* Declare FileIdType to QML. */
Q_DECLARE_METATYPE(Files::FileIdType)
Q_DECLARE_METATYPE(Files::EmailAttachFlag)
Q_DECLARE_METATYPE(Files::EmailAttachFlags)
Q_DECLARE_METATYPE(Files::MsgAttachFlag)
Q_DECLARE_METATYPE(Files::MsgAttachFlags)
#endif // FILES_H
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