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

Opening ZFO attachments from database.

parent 1d7c83fc
......@@ -361,7 +361,12 @@ Component {
locker.ignoreNextSuspension()
if (files.isZfoFile(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": pageView,
"statusBar": statusBar,
......
......@@ -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)
{
qDebug("%s()", __func__);
file.filename = QString();
file.content = QString();
if (userName.isEmpty() || msgId <= 0 || fileId < 0) {
if (userName.isEmpty() || (msgId <= 0) || (fileId < 0)) {
return;
}
FileDb *fDb = NULL;
fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == NULL) {
qDebug() << "ERROR: File database cannot open!";
if (fDb == Q_NULLPTR) {
qCritical() << "Cannot open file database!";
return;
}
FileDb::FileData file = fDb->getFileContentFromDb(fileId);
QString fileName = file.filename;
file = fDb->getFileContentFromDb(fileId);
}
Q_ASSERT(!fileName.isEmpty());
if (fileName.isEmpty()) {
QByteArray Files::getAttachmentDb(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 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!";
return;
}
openAttachment(fileName, file.content.toUtf8());
openAttachment(file.filename, file.content.toUtf8());
}
void Files::openAttachment(const QString &fileName, const QByteArray &base64Data)
......
......@@ -43,11 +43,28 @@ public:
*/
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.
*
* @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,
qint64 msgId, int fileId);
Q_INVOKABLE static
void openAttachmentFromDb(const QString &userName,
const QString &msgIdStr, int fileId);
/*!
* @brief Open attachment in default application.
......@@ -122,6 +139,9 @@ public:
/*!
* @brief Decodes base64-encoded content.
*
* @param[in] base64Data Base64-encoded data.
* @return Raw data.
*/
Q_INVOKABLE static
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