Commit 982ee11b authored by Karel Slaný's avatar Karel Slaný

Loading ZFO attachment content into model that is held within a QML page.

parent f140fe22
......@@ -288,13 +288,12 @@ ApplicationWindow {
* enabled.
*/
console.log("Showing zfo file: " + filePath)
if (files.openZfoFileFromStorage(filePath)) {
mainStack.push(pageZfoMessageDetail, {
"pageView": mainStack,
"zfoFilePath": filePath
}, StackView.Immediate)
}
}
}
/* Android back button. */
focus: true
......
......@@ -25,6 +25,7 @@ import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Window 2.1
import QtGraphicalEffects 1.0
import cz.nic.mobileDatovka.models 1.0
Component {
id: pageZfoMessageDetail
......@@ -34,11 +35,24 @@ Component {
/* These properties must be set by caller. */
property var pageView
property var statusBar
property var zfoFilePath
property string zfoId
/* These properties are set from cpp. */
property string eSubject
property string eBody
FileListModel {
id: attachmentModel
Component.onCompleted: {
/* Load content from ZFO file if such is supplied. */
if (typeof(zfoFilePath) != "undefined") {
setZfoFile(zfoFilePath)
}
}
}
Rectangle {
id: header
anchors.top: parent.top
......@@ -191,7 +205,7 @@ Component {
visible: true
width: parent.width
interactive: true
model: fileListModelZfo
model: attachmentModel
delegate: Rectangle {
id: attachmentItem
width: parent.width
......
......@@ -253,7 +253,7 @@ void Files::openAttachmentFromDb(const QString &userName,
}
if (isAttachmentZfoFile(fileName)) {
parseXmlData(decodeZfoFile(file.content));
parseXmlData(globFilesModelZfo, decodeZfoFile(file.content));
return;
}
......@@ -272,7 +272,7 @@ void Files::openAttachment(const QString &fileName, const QString &content)
}
if (isAttachmentZfoFile(fileName)) {
parseXmlData(decodeZfoFile(content));
parseXmlData(globFilesModelZfo, decodeZfoFile(content));
return;
}
......@@ -667,7 +667,7 @@ QByteArray Files::decodeZfoFile(const QString &content)
return decodeCmsData(cmsData);
}
bool Files::parseXmlData(QByteArray data)
bool Files::parseXmlData(FileListModel &attachModel, QByteArray data)
{
qDebug("%s()", __func__);
......@@ -812,19 +812,21 @@ bool Files::parseXmlData(QByteArray data)
body += "\n";
// set file model
setZfoFilesToModel(globFilesModelZfo, fileList);
setZfoFilesToModel(attachModel, fileList);
// remember file list and message detail
stackFileList.push(fileList);
stackMessageDetail.push(html);
/* TODO -- This method should not emit any signals. */
// open new qml page
emit pushNewMessageDeatilPage(QString::number(msg.dmID));
// emit pushNewMessageDeatilPage(QString::number(msg.dmID));
// set message deatil string to qml
emit setMessageDetailData(html, body, msg.dmAnnotation);
// emit setMessageDetailData(html, body, msg.dmAnnotation);
return success;
}
bool Files::openZfoFileFromStorage(const QString &filePath)
bool Files::openZfoFileFromStorage(FileListModel &attachModel,
const QString &filePath)
{
qDebug("%s()", __func__);
......@@ -842,7 +844,7 @@ bool Files::openZfoFileFromStorage(const QString &filePath)
return ret;
}
ret = parseXmlData(decodeCmsData(file.readAll()));
ret = parseXmlData(attachModel, decodeCmsData(file.readAll()));
return ret;
}
......@@ -26,6 +26,8 @@
#include <QObject>
#include "src/models/filemodel.h"
/*
* Class Files provides interface between QML and file database.
* Class is initialised in the main function (main.cpp)
......@@ -124,11 +126,13 @@ public:
/*!
* @brief Open ZFO file from path.
*
* @param[out] attachModel Attachment model to be set.
* @param[in] filePath File path with file name.
* @return true if success.
*/
Q_INVOKABLE
bool openZfoFileFromStorage(const QString &filePath);
static
bool openZfoFileFromStorage(FileListModel &attachModel,
const QString &filePath);
class File {
public:
......@@ -208,6 +212,7 @@ private:
* @param[in] fileName File name.
* @return true if file is zfo.
*/
static
bool isAttachmentZfoFile(const QString &fileName);
/*!
......@@ -216,6 +221,7 @@ private:
* @param[in] content File content.
* @return decoded data or QByteArray().
*/
static
QByteArray decodeCmsData(const QByteArray &cmsData);
/*!
......@@ -224,15 +230,18 @@ private:
* @param[in] content File content.
* @return decoded data or QByteArray().
*/
static
QByteArray decodeZfoFile(const QString &content);
/*!
* @brief Parse xml data of zfo file.
*
* @param[out] attachModel Attachment model to be set.
* @param[in] data Xml file data.
* @return true if success.
*/
bool parseXmlData(QByteArray data);
static
bool parseXmlData(FileListModel &attachModel, QByteArray data);
};
#endif // FILES_H
......@@ -254,6 +254,7 @@ int main(int argc, char *argv[])
registerQmlTypes(uri, QML_COMPONENT_LOC, qmlComponents);
/* Register types into QML. */
FileListModel::declareQML();
Messages::declareQML();
InteractionZfoFile interactionZfoFile;
......
......@@ -21,8 +21,10 @@
* the two.
*/
#include <QQmlEngine> /* qmlRegisterType */
#include <QSqlRecord>
#include "src/files.h" /* TODO -- Do something with it. */
#include "src/models/filemodel.h"
FileListModel::Entry::Entry(const Entry &fme)
......@@ -92,6 +94,11 @@ void FileListModel::Entry::setFileContent(const QString &fileContent)
FileListModel globFilesModel;
FileListModel globFilesModelZfo;
void FileListModel::declareQML(void)
{
qmlRegisterType<FileListModel>("cz.nic.mobileDatovka.models", 1, 0, "FileListModel");
}
FileListModel::FileListModel(QObject *parent)
: QAbstractListModel(parent)
{
......@@ -194,3 +201,8 @@ void FileListModel::clearAll(void)
m_files.clear();
endResetModel();
}
bool FileListModel::setZfoFile(const QString &filePath)
{
return Files::openZfoFileFromStorage(*this, filePath);
}
......@@ -67,6 +67,10 @@ public:
ROLE_FILE_DATA
};
/* Don't forget to declare various propertiers to the QML system. */
static
void declareQML(void);
/*!
* @brief Constructor.
*
......@@ -130,6 +134,12 @@ public:
*/
void clearAll(void);
/*!
* @brief Set content from ZFO file.
*/
Q_INVOKABLE
bool setZfoFile(const QString &filePath);
private:
QList<Entry> m_files; /*!< List of attachment entries. */
};
......
......@@ -43,8 +43,6 @@ bool InteractionZfoFile::openZfoFile(const QString &filePath)
}
}
/* TODO */
emit displayZfoFileContent(filePath);
return true;
......
......@@ -21,6 +21,9 @@
* the two.
*/
#ifndef _INTERACTION_ZFO_FILE_H_
#define _INTERACTION_ZFO_FILE_H_
#include <QObject>
/*!
......@@ -33,9 +36,9 @@ public:
/*!
* @brief Constructor.
*
* @Param[in] parent Patent object.
* @param[in] parent Parent object.
*/
InteractionZfoFile(QObject *parent = Q_NULLPTR);
explicit InteractionZfoFile(QObject *parent = Q_NULLPTR);
/*!
* @brief Check ZFO file, prepares model and causes QML to display.
......@@ -56,3 +59,5 @@ signals:
*/
void displayZfoFileContent(QString filePath);
};
#endif /* _INTERACTION_ZFO_FILE_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