Commit c55bd35f authored by Martin Straka's avatar Martin Straka

Added send zfo message by email

parent e01b6156
......@@ -24,6 +24,7 @@
import QtQuick 2.7
import QtQuick.Controls 2.1
import cz.nic.mobileDatovka 1.0
import cz.nic.mobileDatovka.files 1.0
import cz.nic.mobileDatovka.messages 1.0
import cz.nic.mobileDatovka.models 1.0
......@@ -119,8 +120,12 @@ Component {
"messageModel": messageModel
}, StackView.Immediate)
},
"sendEmail": function callSendEmail() {
files.sendAttachmentsWithEmail(userName, msgId)
"sendAttachEmail": function callSendAttachEmail() {
files.sendMsgFilesWithEmail(userName, msgId, EmailAttachType.SEND_EMAIL_ATTACHMENT_ONLY)
pageView.pop(StackView.Immediate)
},
"sendZfoEmail": function callSendZfoEmail() {
files.sendMsgFilesWithEmail(userName, msgId, EmailAttachType.SEND_EMAIL_ZFO_ONLY)
pageView.pop(StackView.Immediate)
},
"saveAttachs": function callSaveAttachs() {
......@@ -174,12 +179,19 @@ Component {
name: qsTr("Upload to records management")
funcName: "uploadRM"
}
ListElement {
image: "qrc:/ui/attach-to-mail.svg"
showEntry: true
showNext: false
name: qsTr("Send zfo message by email")
funcName: "sendZfoEmail"
}
ListElement {
image: "qrc:/ui/attach-to-mail.svg"
showEntry: true
showNext: false
name: qsTr("Send attachments by email")
funcName: "sendEmail"
funcName: "sendAttachEmail"
}
ListElement {
image: "qrc:/ui/save-to-disk.svg"
......
......@@ -43,11 +43,14 @@
#include "src/sqlite/dbs.h"
#include "src/sqlite/file_db_container.h"
#include "src/sqlite/message_db_container.h"
#include "src/sqlite/zfo_db.h"
void Files::declareQML(void)
{
qmlRegisterType<Files>("cz.nic.mobileDatovka.files", 1, 0, "FileIdType");
qmlRegisterType<Files>("cz.nic.mobileDatovka.files", 1, 0, "EmailAttachType");
qRegisterMetaType<Files::FileIdType>();
qRegisterMetaType<Files::EmailAttachType>();
}
Files::Files(QObject *parent)
......@@ -236,13 +239,15 @@ void Files::openAttachmentFromPath(const QString &filePath)
#endif
}
void Files::sendAttachmentsWithEmail(const QString &userName, qint64 msgId)
void Files::sendMsgFilesWithEmail(const QString &userName, qint64 msgId,
enum Files::EmailAttachType attachType)
{
qDebug("%s()", __func__);
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR) ||
(GlobInstcs::zfoDbPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
......@@ -254,8 +259,8 @@ void Files::sendAttachmentsWithEmail(const QString &userName, qint64 msgId)
QString body;
QString subject;
QStringList fileList;
/* Fill email subject and body */
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
......@@ -268,26 +273,48 @@ void Files::sendAttachmentsWithEmail(const QString &userName, qint64 msgId)
return;
}
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database cannot open!";
return;
}
QList<FileDb::FileData> filelist;
filelist = fDb->getFilesFromDb(msgId);
if (filelist.isEmpty()) {
qCritical() << "ERROR: File list is empty!";
return;
/* Get attachment files from database if needed */
if (Files::SEND_EMAIL_ZFO_ATTACHMENT == attachType
|| Files::SEND_EMAIL_ATTACHMENT_ONLY == attachType ) {
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database cannot open!";
return;
}
filelist = fDb->getFilesFromDb(msgId);
if (filelist.isEmpty()) {
qCritical() << "ERROR: File list is empty!";
return;
}
}
const QString boundary = generateBoundaryString();
QString emailMessage = createEmailMessage(body, subject, boundary);
/* Get zfo file from database if needed */
if (Files::SEND_EMAIL_ZFO_ATTACHMENT == attachType
|| Files::SEND_EMAIL_ZFO_ONLY == attachType ) {
FileDb::FileData msgData;
msgData.content = GlobInstcs::zfoDbPtr->getZfoContentFromDb(msgId,
(*GlobInstcs::acntMapPtr)[userName].isTestAccount());
if (msgData.content.isEmpty()) {
/* TODO - show error dialogue */
qCritical() << "ERROR: ZFO message data missing!";
Q_ASSERT(0);
return;
}
msgData.filename = QString("DZ_%1.zfo").arg(msgId);
filelist.append(msgData);
}
/* Create email content, email attachment and send email */
removeDirFromDocLoc(DATOVKA_MAIL_DIR_NAME);
QString targetPath(appEmailDirPath(QString::number(msgId)));
QStringList fileListPath;
const QString boundary = generateBoundaryString();
QString emailMessage = createEmailMessage(body, subject, boundary);
foreach (const FileDb::FileData &file, filelist) {
QString fileName = file.filename;
......@@ -297,14 +324,14 @@ void Files::sendAttachmentsWithEmail(const QString &userName, qint64 msgId)
}
fileName = writeFile(targetPath, fileName,
base64ToRaw(file.content.toUtf8()));
fileList.append(fileName);
fileListPath.append(fileName);
addAttachmentToEmailMessage(emailMessage, file.filename,
file.content.toUtf8(), boundary);
}
finishEmailMessage(emailMessage, boundary);
sendEmail(emailMessage, fileList, subject, body, msgId);
sendEmail(emailMessage, fileListPath, subject, body, msgId);
}
void Files::deleteFileDb(const QString &userName)
......
......@@ -38,6 +38,14 @@ class Files : public QObject {
public:
/* Defines attachment type to be sent via email */
enum EmailAttachType {
SEND_EMAIL_ZFO_ATTACHMENT = 0,
SEND_EMAIL_ZFO_ONLY,
SEND_EMAIL_ATTACHMENT_ONLY
};
Q_ENUM(EmailAttachType)
/* Defines missing file id vaule and zfo id */
enum FileIdType {
NO_FILE_ID = -1,
......@@ -130,14 +138,16 @@ public:
void openAttachmentFromPath(const QString &filePath);
/*!
* @brief Send attachments from database with email application.
* @brief Send message attachments or complete zfo message
* from database with email application.
*
* @param[in] userName User name of account.
* @param[in] msgId Message id.
* @param[in] attachType Email attachment type to be sent.
*/
Q_INVOKABLE
void sendAttachmentsWithEmail(const QString &userName,
qint64 msgId);
void sendMsgFilesWithEmail(const QString &userName,
qint64 msgId, enum EmailAttachType attachType);
/*!
* @brief Delete file database.
......@@ -359,5 +369,6 @@ private:
/* Declare FileIdType to QML. */
Q_DECLARE_METATYPE(Files::FileIdType)
Q_DECLARE_METATYPE(Files::EmailAttachType)
#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