Commit 97a42643 authored by Martin Straka's avatar Martin Straka

Files refactoring

parent 65bf3aff
......@@ -45,7 +45,6 @@
#include "src/crypto/crypto.h"
#endif
QStack<QList<Files::File>> stackFileList;
QStack<QString> stackMessageDetail;
......@@ -131,24 +130,12 @@ Files::Files(QObject *parent) : QObject(parent)
{
}
/* ========================================================================= */
/*
* Slot: Clear file model in QML.
*/
void Files::clearFileModel(void)
/* ========================================================================= */
{
globFilesModel.clearAll();
}
/* ========================================================================= */
/*
* Slot: Clear zfo file model in QML.
*/
void Files::clearFileModelZfo(void)
/* ========================================================================= */
{
globFilesModelZfo.clearAll();
if (!stackFileList.isEmpty()) {
......@@ -168,13 +155,7 @@ void Files::clearFileModelZfo(void)
}
/* ========================================================================= */
/*
* Func: Delete files from all file databases where file lifetime expired.
*/
void Files::deleteExpiredFilesFromDbs(int days)
/* ========================================================================= */
{
qDebug("%s()", __func__);
......@@ -209,13 +190,7 @@ void Files::deleteExpiredFilesFromDbs(int days)
}
}
/* ========================================================================= */
/*
* Slot: Fill file list in QML.
*/
void Files::fillFileList(const QString &userName, qint64 msgId)
/* ========================================================================= */
{
qDebug("%s()", __func__);
......@@ -231,13 +206,8 @@ void Files::fillFileList(const QString &userName, qint64 msgId)
fDb->getFileListFromDb(msgId);
}
/* ========================================================================= */
/*
* Slot: Open attachment from database.
*/
void Files::openAttachmentFromDb(const QString &userName, qint64 msgId, int fileId)
/* ========================================================================= */
void Files::openAttachmentFromDb(const QString &userName,
qint64 msgId, int fileId)
{
qDebug("%s()", __func__);
......@@ -264,20 +234,15 @@ void Files::openAttachmentFromDb(const QString &userName, qint64 msgId, int file
}
if (isAttachmentZfoFile(fileName)) {
parseZfoData(decodeZfoFile(file.content));
QByteArray xmlData = decodeZfoFile(file.content);
parseXmlData(xmlData);
return;
}
openAttachment(fileName, file.content);
}
/* ========================================================================= */
/*
* Slot: Open attachment in default application.
*/
void Files::openAttachment(const QString &fileName, const QString &content)
/* ========================================================================= */
{
Q_ASSERT(!fileName.isEmpty());
......@@ -289,7 +254,8 @@ void Files::openAttachment(const QString &fileName, const QString &content)
}
if (isAttachmentZfoFile(fileName)) {
parseZfoData(decodeZfoFile(content));
QByteArray xmlData = decodeZfoFile(content);
parseXmlData(xmlData);
return;
}
......@@ -330,14 +296,8 @@ void Files::openAttachment(const QString &fileName, const QString &content)
}
}
/* ========================================================================= */
/*
* Slot: Send attachments from database with email application.
*/
void Files::sendAttachmentsWithEmailFromDb(const QString &userName,
qint64 msgId)
/* ========================================================================= */
{
qDebug("%s()", __func__);
......@@ -407,14 +367,8 @@ void Files::sendAttachmentsWithEmailFromDb(const QString &userName,
sendEmail(emailMessage, fileList, subject, body, msgId);
}
/* ========================================================================= */
/*
* Slot: Send attachment from zfo with email application.
*/
void Files::sendAttachmentsWithEmailFromZfo(qint64 msgId, QString subject,
QString body)
/* ========================================================================= */
{
qDebug("%s()", __func__);
......@@ -444,13 +398,7 @@ void Files::sendAttachmentsWithEmailFromZfo(qint64 msgId, QString subject,
sendEmail(emailMessage, fileList, subject, body, msgId);
}
/* ========================================================================= */
/*
* Slot: Save attachments to disk.
*/
void Files::saveAttachmentsToDisk(const QString &userName, qint64 msgId)
/* ========================================================================= */
{
qDebug("%s()", __func__);
......@@ -532,13 +480,7 @@ void Files::saveAttachmentsToDisk(const QString &userName, qint64 msgId)
msgBox.exec();
}
/* ========================================================================= */
/*
* Slot: Delete file database.
*/
void Files::deleteFileDb(const QString &userName)
/* ========================================================================= */
{
qDebug("%s()", __func__);
......@@ -580,13 +522,7 @@ void Files::deleteFileDb(const QString &userName)
}
}
/* ========================================================================= */
/*
* Slot: Vacuum all file databases.
*/
void Files::vacuumFileDbs(void)
/* ========================================================================= */
{
qDebug("%s()", __func__);
......@@ -607,13 +543,7 @@ void Files::vacuumFileDbs(void)
emit statusBarTextChanged(tr("Operation Vacuum has finished"), false);
}
/* ========================================================================= */
/*
* Slot: Delete message attachments from databases.
*/
bool Files::deleteAttachmentsFromDb(const QString &userName, qint64 msgId)
/* ========================================================================= */
{
qDebug("%s()", __func__);
......@@ -639,14 +569,8 @@ bool Files::deleteAttachmentsFromDb(const QString &userName, qint64 msgId)
return false;
}
/* ========================================================================= */
/*
* 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);
......@@ -674,13 +598,7 @@ void Files::sendEmail(const QString &emailMessage, const QStringList &fileList,
}
}
/* ========================================================================= */
/*
* Func: Test, if attachmenti is ZFO
*/
bool Files::isAttachmentZfoFile(const QString &fileName)
/* ========================================================================= */
{
qDebug("%s()", __func__);
......@@ -688,30 +606,21 @@ bool Files::isAttachmentZfoFile(const QString &fileName)
return (fi.suffix().toLower() == "zfo");
}
/* ========================================================================= */
/*
* Func: Decode data from ZFO file.
*/
QByteArray Files::decodeZfoFile(const QString &content)
/* ========================================================================= */
QByteArray Files::decodeCmsData(const QByteArray &cmsData)
{
qDebug("%s()", __func__);
Q_ASSERT(!content.isEmpty());
if (content.isEmpty()) {
Q_ASSERT(!cmsData.isEmpty());
if (cmsData.isEmpty()) {
qDebug() << "ERROR: File content is empty!";
return QByteArray();
}
/* decode signature from base64 and obtain something cms message */
QByteArray cmsData = QByteArray::fromBase64(content.toUtf8());
/* decode cms and obtain message xml data - used openssl */
void *xmlContent = NULL;
size_t xmlContentLen = 0;
if (extract_cms_data(cmsData.data(), cmsData.length(), &xmlContent,
&xmlContentLen) != 0) {
&xmlContentLen) != 0) {
return QByteArray();
}
if (xmlContentLen == 0) {
......@@ -725,13 +634,23 @@ QByteArray Files::decodeZfoFile(const QString &content)
return soap;
}
QByteArray Files::decodeZfoFile(const QString &content)
{
qDebug("%s()", __func__);
Q_ASSERT(!content.isEmpty());
if (content.isEmpty()) {
qDebug() << "ERROR: File content is empty!";
return QByteArray();
}
/* decode signature from base64 and obtain something cms message */
QByteArray cmsData = QByteArray::fromBase64(content.toUtf8());
/* ========================================================================= */
/*
* Func: Parse XML data.
*/
bool Files::parseZfoData(QByteArray data)
/* ========================================================================= */
return decodeCmsData(cmsData);
}
bool Files::parseXmlData(QByteArray &data)
{
qDebug("%s()", __func__);
......@@ -887,3 +806,30 @@ bool Files::parseZfoData(QByteArray data)
return success;
}
bool Files::openZfoFileFromStorage(const QString &filePath)
{
qDebug("%s()", __func__);
bool ret = false;
Q_ASSERT(!filePath.isEmpty());
if (filePath.isEmpty()) {
qDebug() << "ERROR: Target ZFO path is empty!";
return ret;
}
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly)) {
qDebug() << "ERROR: Cannot open ZFO file from" << filePath;
return ret;
}
QByteArray content = file.readAll();
content = decodeCmsData(content);
ret = parseXmlData(content);
file.remove();
return ret;
}
......@@ -57,8 +57,8 @@ public:
/*!
* @brief Send attachments from database with email application.
*
* @param[in] userName - user name of account.
* @param[in] msgId - message id.
* @param[in] userName User name of account.
* @param[in] msgId Message id.
*/
Q_INVOKABLE void sendAttachmentsWithEmailFromDb(const QString &userName,
qint64 msgId);
......@@ -66,9 +66,9 @@ public:
/*!
* @brief Send attachment from zfo with email application.
*
* @param[in] msgId - message id.
* @param[in] subject - email subject.
* @param[in] body - email body.
* @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);
......@@ -98,7 +98,7 @@ public:
* @brief Delete files from all file databases
* where file lifetime expired.
*
* @param[in] days - lifetime in days.
* @param[in] days Lifetime in days.
*/
void deleteExpiredFilesFromDbs(int days);
......@@ -110,13 +110,21 @@ public:
/*!
* @brief Delete message attachments from databases.
*
* @param[in] userName - user name of account.
* @param[in] msgId - message id.
* @param[in] userName User name of account.
* @param[in] msgId Message id.
* @return true if success.
*/
Q_INVOKABLE
bool deleteAttachmentsFromDb(const QString &userName, qint64 msgId);
/*!
* @brief Open ZFO file from path.
*
* @param[in] filePath File path with file name.
* @return true if success.
*/
bool openZfoFileFromStorage(const QString &filePath);
class File {
public:
File(void)
......@@ -146,8 +154,8 @@ signals:
/*!
* @brief Set new statusbar text and active busy indicator to QML.
*
* @param[in] txt - text message for statusbar.
* @param[in] busy - true means the statusbar busy indicator is active
* @param[in] txt Text message for statusbar.
* @param[in] busy True means the statusbar busy indicator is active
* and shown, false = disabled and hidden
*/
void statusBarTextChanged(QString txt, bool busy);
......@@ -155,24 +163,23 @@ signals:
/*!
* @brief Change message detait html string to QML.
*
* @param[in] txt - message detail text.
* @param[in] txt Message detail text.
*/
void messageDetailChanged(QString txt);
/*!
* @brief Send message detait html string to QML.
*
* @param[in] txt - message detail text.
* @param[in] body - email body.
* @param[in] subject - email subject
* @param[in] txt Message detail text.
* @param[in] body Email body.
* @param[in] subject Email subject.
*/
void setMessageDetailData(QString txt, QString body, QString subject);
/*!
* @brief Push and open a new message detail page to stackview in QML.
*
* @param[in] zfoId - zfo message Id.
* @param[in] zfoId Zfo message Id.
*/
void pushNewMessageDeatilPage(QString zfoId);
......@@ -181,38 +188,46 @@ 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.
* @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.
* @brief Test, if attachment is ZFO file.
*
* @param[in] fileName File name.
* @return true if file is zfo.
*/
bool isAttachmentZfoFile(const QString &fileName);
/*!
* @brief Decode XML data from CMS.
*
* @param[in] fileName - file name.
* @return true if file is zfo.
* @param[in] content File content.
* @return decoded data or QByteArray().
*/
bool isAttachmentZfoFile(const QString &fileName);
QByteArray decodeCmsData(const QByteArray &cmsData);
/*!
* @brief Decode data from ZFO file.
*
* @param[in] content - file content.
* @param[in] content File content.
* @return decoded data or QByteArray().
*/
QByteArray decodeZfoFile(const QString &content);
/*!
* @brief Parse zfo data.
* @brief Parse xml data of zfo file.
*
* @param[in] data - file data.
* @param[in] data Xml file data.
* @return true if success.
*/
bool parseZfoData(QByteArray data);
bool parseXmlData(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