Commit 3e394f2c authored by Karel Slaný's avatar Karel Slaný

Added FileListModel::setFromDb().

parent 184e1bdf
......@@ -42,20 +42,29 @@ Component {
property string userName: ""
property string msgId: ""
property int msgType
/* These properties are set from within the page. */
property string zfoId /*Prevents infinite loop that would be caused by setting msgId from within the page. */
property string msgAnnotation
property string msgDescrHtml /* Message HTML description. */
property string emailBody
property int msgType
function fillContentFromDb() {
if (rawZfoContent != null) {
if (!fromLocalDb && (rawZfoContent != null)) {
zfoId = files.msgIdString(rawZfoContent)
msgAnnotation = files.msgAnnotation(rawZfoContent),
msgDescrHtml = files.msgDescriptionHtml(rawZfoContent),
emailBody = files.msgEmailBody(rawZfoContent)
attachmentModel.setZfo(rawZfoContent)
console.log("Loaded page content from ZFO.")
rawZfoContent = null /* There is no need to remember this. */
} else if ((userName.length != 0) && (msgId.length != 0)) {
} else if (fromLocalDb && (userName.length != 0) && (msgId.length != 0)) {
zfoId = msgId
attachmentModel.setFromDb(userName, zfoId)
}
}
......@@ -211,23 +220,24 @@ Component {
width: parent.width
textFormat: TextEdit.RichText
wrapMode: Text.WordWrap
text: msgDescrHtml
Connections {
target: messages
onMessageDetailChanged: {
messageDetailText.text = txt
}
}
Connections {
target: files
onPushNewMessageDeatilPage: {
statusBar.visible = false
pageView.push(pageZfoMessageDetail, {
"pageView": pageView,
"statusBar": statusBar,
"zfoId": zfoId
}, StackView.Immediate)
}
}
// Connections {
// target: files
// onPushNewMessageDeatilPage: {
// statusBar.visible = false
// pageView.push(pageZfoMessageDetail, {
// "pageView": pageView,
// "statusBar": statusBar,
// "zfoId": zfoId
// }, StackView.Immediate)
// }
// }
}
}
}
......@@ -262,7 +272,7 @@ Component {
visible: true
width: parent.width
interactive: true
model: fileListModel
model: attachmentModel
onCountChanged: {
if (attachmentList.count == 0) {
emptyList.visible = true
......@@ -335,7 +345,22 @@ Component {
anchors.fill: parent
onClicked: {
locker.ignoreNextSuspension()
files.openAttachmentFromDb(userName, msgId, rFileId)
if (files.isZfoFile(rFileName)) {
console.log("Attachment is ZFO: " + rFileName)
var fileContent = files.base64ToRaw(rFileContent)
pageView.push(pageZfoMessageDetail, {
"pageView": pageView,
"statusBar": statusBar,
"fromLocalDb": false,
"rawZfoContent": fileContent
}, StackView.Immediate)
} else {
if (!fromLocalDb) {
files.openAttachment(rFileName, rFileContent)
} else {
files.openAttachmentFromDb(userName, msgId, rFileId)
}
}
}
}
Rectangle {
......@@ -364,7 +389,7 @@ Component {
visible: false
color: datovkaPalette.text
anchors.centerIn: attachmentList
text: qsTr("Attachments have not been downloaded yet.")
text: fromLocalDb ? qsTr("Attachments have not been downloaded yet.") : qsTr("No attachments present.")
}
}
}
......@@ -45,12 +45,12 @@ Component {
/* These properties are set from within the page. */
property string zfoId /*Prevents infinite loop that would be caused by setting msgId from within the page. */
property var msgAnnotation
property var msgDescrHtml /* Message HTML description. */
property string msgAnnotation
property string msgDescrHtml /* Message HTML description. */
property string emailBody
function fillContentFromDb() {
if (rawZfoContent != null) {
if (!fromLocalDb && (rawZfoContent != null)) {
zfoId = files.msgIdString(rawZfoContent)
msgAnnotation = files.msgAnnotation(rawZfoContent),
msgDescrHtml = files.msgDescriptionHtml(rawZfoContent),
......@@ -60,8 +60,10 @@ Component {
console.log("Loaded page content from ZFO.")
rawZfoContent = null /* There is no need to remember this. */
} else if ((userName.length != 0) && (msgId.length != 0)) {
} else if (fromLocalDb && (userName.length != 0) && (msgId.length != 0)) {
zfoId = msgId
attachmentModel.setFromDb(userName, zfoId)
}
}
......@@ -315,7 +317,11 @@ Component {
"rawZfoContent": fileContent
}, StackView.Immediate)
} else {
files.openAttachment(rFileName, rFileContent)
if (!fromLocalDb) {
files.openAttachment(rFileName, rFileContent)
} else {
files.openAttachmentFromDb(userName, msgId, rFileId)
}
}
}
}
......@@ -327,5 +333,12 @@ Component {
}
}
}
Text {
id: emptyList
visible: false
color: datovkaPalette.text
anchors.centerIn: attachmentList
text: fromLocalDb ? qsTr("Attachments have not been downloaded yet.") : qsTr("No attachments present.")
}
}
}
......@@ -904,6 +904,24 @@ bool Files::setAttachmentModel(FileListModel &attachModel,
Q_NULLPTR, getXmlFromCms(rawZfoData));
}
bool Files::setAttachmentModel(FileListModel &attachModel,
const QString &userName, qint64 msgId)
{
qDebug("%s()", __func__);
FileDb *fDb = Q_NULLPTR;
fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "Cannot open file database!";
return false;
}
attachModel.clearAll();
fDb->getFileListFromDb(attachModel, msgId);
return true;
}
void Files::deleteTmpFileFromStorage(const QString &filePath)
{
#if defined Q_OS_IOS
......
......@@ -197,11 +197,23 @@ public:
* @param[out] attachModel Attachment model to be set.
* @param[in] rawZfoData Raw ZFO data.
* @return true if success.
*/
*/
static
bool setAttachmentModel(FileListModel &attachModel,
const QByteArray &rawZfoData);
/*!
* @brief Sets attachment model.
*
* @param[out] attachModel Attachment model to be set.
* @param[in] userName Identifies the account.
* @param[in] msgId Message identifier.
* @return true if success.
*/
static
bool setAttachmentModel(FileListModel &attachModel,
const QString &userName, qint64 msgId);
/*!
* @brief Delete temporary file from storage.
*
......
......@@ -206,3 +206,14 @@ bool FileListModel::setZfo(const QByteArray &rawZfoData)
{
return Files::setAttachmentModel(*this, rawZfoData);
}
bool FileListModel::setFromDb(const QString &userName, const QString &msgIdStr)
{
bool ok = false;
qint64 msgId = msgIdStr.toLongLong(&ok);
if (!ok || (msgId < 0)) {
return false;
}
return Files::setAttachmentModel(*this, userName, msgId);
}
......@@ -138,10 +138,24 @@ public:
* @brief Set content from ZFO content.
*
* @param[in] rawZfoData Message content.
* @return True on success.
*/
Q_INVOKABLE
bool setZfo(const QByteArray &rawZfoData);
/*!
* @brief Set content from database.
*
* @note QML has no notion about qint64, therefore the id is passed
* via a string.
*
* @param[in] userName User name identifying account.
* @param[in] msgIdStr String containing message identifier.
* @return True on success.
*/
Q_INVOKABLE
bool setFromDb(const QString &userName, const QString &msgIdStr);
private:
QList<Entry> m_files; /*!< List of attachment entries. */
};
......
......@@ -365,7 +365,7 @@ fail:
/*
* Get list of files from db - for QML listview.
*/
void FileDb::getFileListFromDb(const qint64 dmId)
void FileDb::getFileListFromDb(FileListModel &model, const qint64 dmId)
/* ========================================================================= */
{
QSqlQuery query(m_db);
......@@ -380,7 +380,7 @@ void FileDb::getFileListFromDb(const qint64 dmId)
query.bindValue(":dmID", dmId);
if (query.exec() && query.isActive()) {
globFilesModel.setQuery(query);
model.setQuery(query);
}
}
......
......@@ -34,7 +34,6 @@
#include "src/messages.h"
#include "src/models/filemodel.h"
/*!
* @brief Encapsulates message database.
*/
......@@ -111,9 +110,10 @@ public:
/*!
* @brief Get list of files from db - for QML listview.
*
* @param[out] model Model to be set.
* @param[in] qint64 dmId of message.
*/
void getFileListFromDb(qint64 dmId);
void getFileListFromDb(FileListModel &model, qint64 dmId);
/*!
* @brief Get list of files from db - for QML listview.
......
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