Commit 311ac7a1 authored by Karel Slaný's avatar Karel Slaný

Opening ZFO attachments from database.

parent 1d7c83fc
...@@ -361,7 +361,12 @@ Component { ...@@ -361,7 +361,12 @@ Component {
locker.ignoreNextSuspension() locker.ignoreNextSuspension()
if (files.isZfoFile(rFileName)) { if (files.isZfoFile(rFileName)) {
console.log("Attachment is ZFO: " + rFileName) console.log("Attachment is ZFO: " + rFileName)
var fileContent = files.base64ToRaw(rFileContent) var fileContent = null
if (!fromLocalDb) {
fileContent = files.base64ToRaw(rFileContent)
} else {
fileContent = files.getAttachmentDb(userName, zfoId, rFileId)
}
pageView.push(pageMessageDetail, { pageView.push(pageMessageDetail, {
"pageView": pageView, "pageView": pageView,
"statusBar": statusBar, "statusBar": statusBar,
......
...@@ -189,34 +189,76 @@ void Files::deleteExpiredFilesFromDbs(int days) ...@@ -189,34 +189,76 @@ void Files::deleteExpiredFilesFromDbs(int days)
} }
} }
void Files::openAttachmentFromDb(const QString &userName, /*!
* @brief Obtain attachment from database.
*
* @param[out] file File data to be acquired.
* @param[in] userName User name identifying the account.
* @param[in] msgIdStr String with message id.
* @param[in] fileId Attachment file identifier.
*/
static
void getAttchment(FileDb::FileData &file, const QString &userName,
qint64 msgId, int fileId) qint64 msgId, int fileId)
{ {
qDebug("%s()", __func__); file.filename = QString();
file.content = QString();
if (userName.isEmpty() || msgId <= 0 || fileId < 0) { if (userName.isEmpty() || (msgId <= 0) || (fileId < 0)) {
return; return;
} }
FileDb *fDb = NULL; FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation, userName, userName, AccountListModel::globAccounts[userName].storeToDisk());
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == NULL) { if (fDb == Q_NULLPTR) {
qDebug() << "ERROR: File database cannot open!"; qCritical() << "Cannot open file database!";
return; return;
} }
FileDb::FileData file = fDb->getFileContentFromDb(fileId); file = fDb->getFileContentFromDb(fileId);
QString fileName = file.filename; }
Q_ASSERT(!fileName.isEmpty()); QByteArray Files::getAttachmentDb(const QString &userName,
if (fileName.isEmpty()) { const QString &msgIdStr, int fileId)
{
qDebug("%s()", __func__);
/* Obtain message identifier. */
bool ok = false;
qint64 msgId = msgIdStr.toLongLong(&ok);
if (!ok || (msgId < 0)) {
return QByteArray();
}
FileDb::FileData file;
getAttchment(file, userName, msgId, fileId);
return QByteArray::fromBase64(file.content.toUtf8());
}
void Files::openAttachmentFromDb(const QString &userName,
const QString &msgIdStr, int fileId)
{
qDebug("%s()", __func__);
/* Obtain message identifier. */
bool ok = false;
qint64 msgId = msgIdStr.toLongLong(&ok);
if (!ok || (msgId < 0)) {
return;
}
FileDb::FileData file;
getAttchment(file, userName, msgId, fileId);
Q_ASSERT(!file.filename.isEmpty());
if (file.filename.isEmpty()) {
qDebug() << "ERROR: File name is empty!"; qDebug() << "ERROR: File name is empty!";
return; return;
} }
openAttachment(fileName, file.content.toUtf8()); openAttachment(file.filename, file.content.toUtf8());
} }
void Files::openAttachment(const QString &fileName, const QByteArray &base64Data) void Files::openAttachment(const QString &fileName, const QByteArray &base64Data)
......
...@@ -43,11 +43,28 @@ public: ...@@ -43,11 +43,28 @@ public:
*/ */
explicit Files(QObject *parent = Q_NULLPTR); explicit Files(QObject *parent = Q_NULLPTR);
/*!
* @brief Obtain attachment from database.
*
* @param[in] userName User name identifying the account.
* @param[in] msgIdStr String with message id.
* @param[in] fileId Attachment file identifier.
* @return Attachment content.
*/
Q_INVOKABLE static
QByteArray getAttachmentDb(const QString &userName,
const QString &msgIdStr, int fileId);
/*! /*!
* @brief Open attachment from database. * @brief Open attachment from database.
*
* @param[in] userName User name identifying the account.
* @param[in] msgIdStr String with message id.
* @param[in] fileId Attachment file identifier.
*/ */
Q_INVOKABLE void openAttachmentFromDb(const QString &userName, Q_INVOKABLE static
qint64 msgId, int fileId); void openAttachmentFromDb(const QString &userName,
const QString &msgIdStr, int fileId);
/*! /*!
* @brief Open attachment in default application. * @brief Open attachment in default application.
...@@ -122,6 +139,9 @@ public: ...@@ -122,6 +139,9 @@ public:
/*! /*!
* @brief Decodes base64-encoded content. * @brief Decodes base64-encoded content.
*
* @param[in] base64Data Base64-encoded data.
* @return Raw data.
*/ */
Q_INVOKABLE static Q_INVOKABLE static
QByteArray base64ToRaw(const QByteArray &base64Data); QByteArray base64ToRaw(const QByteArray &base64Data);
......
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