Commit 790b82bb authored by Martin Straka's avatar Martin Straka

Added support for opening of ZFO (issue #40)

parent 29e1a0ef
......@@ -175,7 +175,7 @@ Component {
if (index == 0) {
isds.downloadMessage(userName, msgType, msgId)
} else if (index == 1) {
files.sendAttachmentsWithEmail(userName, msgId)
files.sendAttachmentsWithEmailFromDb(userName, msgId)
} else if (index == 2) {
files.saveAttachmentsToDisk(userName, msgId)
} else if (index == 3) {
......
......@@ -24,21 +24,16 @@
import QtQuick 2.7
import QtQuick.Controls 2.0
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: pageZfoMessageDetail
Item {
id: msgZfoDetailPage
/* These properties must be set by caller. */
/* These properties are set from cpp. */
property string zfoId
Component.onCompleted: {
//files.fillZfoFileList(zfoId)
}
property string eSubject
property string eBody
Rectangle {
id: header
anchors.top: parent.top
......@@ -95,7 +90,7 @@ Component {
MouseArea {
anchors.fill: parent
onClicked: {
files.sendAttachmentsWithEmail("", zfoId)
files.sendAttachmentsWithEmailFromZfo(zfoId, eSubject, eBody)
}
}
}
......@@ -145,6 +140,8 @@ Component {
target: files
onMessageDetailChanged: {
messageDetailText.text = txt
eSubject = subject
eBody = body
}
}
}
......
......@@ -246,7 +246,7 @@ void Files::openAttachmentFromDb(const QString &userName, qint64 msgId, int file
}
if (isAttachmentZfoFile(fileName)) {
parseXMLData(decodeZfoFile(file.content));
parseZfoData(decodeZfoFile(file.content));
return;
}
......@@ -273,7 +273,7 @@ void Files::openAttachment(const QString &fileName, const QString &content)
// TODO - here is problem if file is zfo again!
if (isAttachmentZfoFile(fileName)) {
// TODO - what to do?
//parseXMLData(decodeZfoFile(content));
//parseZfoData(decodeZfoFile(content));
return;
}
......@@ -317,9 +317,10 @@ void Files::openAttachment(const QString &fileName, const QString &content)
/* ========================================================================= */
/*
* Slot: Send attachment with email application.
* Slot: Send attachments from database with email application.
*/
void Files::sendAttachmentsWithEmail(const QString &userName, qint64 msgId)
void Files::sendAttachmentsWithEmailFromDb(const QString &userName,
qint64 msgId)
/* ========================================================================= */
{
qDebug("%s()", __func__);
......@@ -387,28 +388,44 @@ void Files::sendAttachmentsWithEmail(const QString &userName, qint64 msgId)
finishEmailMessage(emailMessage, boundary);
if (!fileList.isEmpty()) {
sendEmail(emailMessage, fileList, subject, body, msgId);
}
#if defined Q_OS_IOS
UrlOpener urlOpener;
urlOpener.createEmail(body, subject, fileList);
#elif defined Q_OS_ANDROID
//QDesktopServices::openUrl(QUrl::fromLocalFile(tmpEmailFile));
QDesktopServices::openUrl(QUrl("mailto:?subject=" +
subject + "&body=" + body));
#elif defined Q_OS_WINRT
QDesktopServices::openUrl(QUrl("mailto:?subject=" +
subject + "&body=" + body));
#else
QString tmpEmailFile = writeFileToEmailDir(QString::number(msgId)
+ "_mail.eml", msgId, emailMessage.toUtf8());
QDesktopServices::openUrl(QUrl::fromLocalFile(tmpEmailFile));
#endif
/* TODO -- Handle openUrl() return value. */
} else {
qDebug() << "Tmp file save error";
/* ========================================================================= */
/*
* Slot: Send attachment from zfo with email application.
*/
void Files::sendAttachmentsWithEmailFromZfo(qint64 msgId, QString subject,
QString body)
/* ========================================================================= */
{
qDebug("%s()", __func__);
QStringList fileList;
QString emailMessage;
QString boundary("-----123456789asdfghj_" +
QDateTime::currentDateTimeUtc().toString(
"dd.MM.yyyy-HH:mm:ss.zzz"));
createEmailMessage(emailMessage, body, subject, boundary);
deleteFilesFromDir(EMAIL_DIR_NAME);
QString filePath;
QByteArray data;
for (int i = 0; i < globFilesModelZfo.rowCount(); ++i) {
QModelIndex index = globFilesModelZfo.index(i);
data = QByteArray::fromBase64(globFilesModelZfo.data(index, FileListModel::ROLE_FILE_DATA).toByteArray());
QString fileName = globFilesModelZfo.data(index, FileListModel::ROLE_FILE_NAME).toString();
filePath = writeFileToEmailDir(fileName, msgId, data);
fileList.append(filePath);
addAttachmentToEmailMessage(emailMessage, fileName, globFilesModelZfo.data(index, FileListModel::ROLE_FILE_DATA).toByteArray(), boundary);
}
finishEmailMessage(emailMessage, boundary);
sendEmail(emailMessage, fileList, subject, body, msgId);
}
......@@ -607,6 +624,41 @@ bool Files::deleteAttachmentsFromDb(const QString &userName, qint64 msgId)
}
/* ========================================================================= */
/*
* Func: Send email.
*/
void Files::sendEmail(const QString &emailMessage, const QStringList &fileList,
const QString &subject, const QString &body, qint64 msgId)
/* ========================================================================= */
{
Q_UNUSED(subject);
Q_UNUSED(body);
if (!fileList.isEmpty()) {
#if defined Q_OS_IOS
UrlOpener urlOpener;
urlOpener.createEmail(body, subject, fileList);
#elif defined Q_OS_ANDROID
QDesktopServices::openUrl(QUrl("mailto:?subject=" +
subject + "&body=" + body));
#elif defined Q_OS_WINRT
QDesktopServices::openUrl(QUrl("mailto:?subject=" +
subject + "&body=" + body));
#else
QString tmpEmailFile = writeFileToEmailDir(QString::number(msgId)
+ "_mail.eml", msgId, emailMessage.toUtf8());
QDesktopServices::openUrl(QUrl::fromLocalFile(tmpEmailFile));
#endif
/* TODO -- Handle openUrl() return value. */
} else {
qDebug() << "Tmp file save error";
}
}
/* ========================================================================= */
/*
* Func: Test, if attachmenti is ZFO
......@@ -662,7 +714,7 @@ QByteArray Files::decodeZfoFile(const QString &content)
/*
* Func: Parse XML data.
*/
bool Files::parseXMLData(QByteArray data)
bool Files::parseZfoData(QByteArray data)
/* ========================================================================= */
{
qDebug("%s()", __func__);
......@@ -793,12 +845,26 @@ bool Files::parseXMLData(QByteArray data)
html += divEnd;
// Create body for email
QString body = QObject::tr("ID") + ": ";
body += QString::number(msg.dmID) + "\n";
body += QObject::tr("FROM") + ": ";
body += msg.dmSender + "\n";
body += QObject::tr("TO") + ": ";
body += msg.dmRecipient + "\n";
body += QObject::tr("DELIVERED") + ": ";
body += dateTimeStrFromDbFormat(dateTimeStrToUTCDbFormat(msg.dmAcceptanceTime), DATETIME_QML_FORMAT) + "\n\n---\n";
body += QObject::tr("This email has been generated with Datovka "
"application based on a data message (%1) delivered "
"to databox.").arg(msg.dmID);
body += "\n";
// set file model
globFilesModelZfo.setZfoFilesToModel(fileList);
// open new qml page
emit pushNewMessageDeatilPage(QString::number(msg.dmID));
// set message deatil string to qml
emit messageDetailChanged(html);
emit messageDetailChanged(html, body, msg.dmAnnotation);
return success;
}
......@@ -55,11 +55,24 @@ public:
const QString &content);
/*!
* @brief Send attachment with email application.
* @brief Send attachments from database with email application.
*
* @param[in] userName - user name of account.
* @param[in] msgId - message id.
*/
Q_INVOKABLE void sendAttachmentsWithEmail(const QString &userName,
Q_INVOKABLE void sendAttachmentsWithEmailFromDb(const QString &userName,
qint64 msgId);
/*!
* @brief Send attachment from zfo with email application.
*
* @param[in] msgId - message id.
* @param[in] subject - email subject.
* @param[in] body - email body.
*/
Q_INVOKABLE void sendAttachmentsWithEmailFromZfo(qint64 msgId,
QString subject, QString body);
/*!
* @brief Save attachments to disk.
*/
......@@ -141,16 +154,34 @@ signals:
/*!
* @brief Send message detait html string to QML.
*
* @param[in] txt - message detail text.
* @param[in] body - email body.
* @param[in] subject - email subject
*/
void messageDetailChanged(QString txt);
void messageDetailChanged(QString txt, QString body, QString subject);
/*!
* @brief Push a new message detail page to stackview in QML.
* @brief Push and open a new message detail page to stackview in QML.
*
* @param[in] zfoId - zfo message Id.
*/
void pushNewMessageDeatilPage(QString zfoId);
private:
/*!
* @brief Send email.
*
* @param[in] emailMessage - eml email content.
* @param[in] fileList - file list for email.
* @param[in] subject - email subject
* @param[in] body - email body.
* @param[in] msgId - message ID.
*/
void sendEmail(const QString &emailMessage, const QStringList &fileList,
const QString &subject, const QString &body, qint64 msgId);
/*!
* @brief Test, if attachment is ZFO file.
*
......@@ -168,12 +199,12 @@ private:
QByteArray decodeZfoFile(const QString &content);
/*!
* @brief Parse XML data.
* @brief Parse zfo data.
*
* @param[in] data - file data.
* @return true if success.
*/
bool parseXMLData(QByteArray data);
bool parseZfoData(QByteArray data);
};
#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