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