Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Datovka projects
mobile Datovka
Commits
482317b7
Commit
482317b7
authored
Mar 15, 2017
by
Karel Slaný
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added interim helper methods into Files to help filling message detail page.
parent
ef0d943c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
147 additions
and
25 deletions
+147
-25
qml/main.qml
qml/main.qml
+4
-1
qml/pages/PageZfoMessageDetail.qml
qml/pages/PageZfoMessageDetail.qml
+6
-6
src/files.cpp
src/files.cpp
+93
-17
src/files.h
src/files.h
+44
-1
No files found.
qml/main.qml
View file @
482317b7
...
...
@@ -290,7 +290,10 @@ ApplicationWindow {
console
.
log
(
"
Showing zfo file:
"
+
filePath
)
mainStack
.
push
(
pageZfoMessageDetail
,
{
"
pageView
"
:
mainStack
,
"
zfoFilePath
"
:
filePath
"
zfoFilePath
"
:
filePath
,
"
msgAnnotation
"
:
files
.
msgAnnotation
(
filePath
),
"
msgDescrHtml
"
:
files
.
msgDescriptionHtml
(
filePath
),
"
emailBody
"
:
files
.
msgEmailBody
(
filePath
)
},
StackView
.
Immediate
)
}
}
...
...
qml/pages/PageZfoMessageDetail.qml
View file @
482317b7
...
...
@@ -36,19 +36,18 @@ Component {
property
var
pageView
property
var
statusBar
property
var
zfoFilePath
property
var
msgAnnotation
property
var
msgDescrHtml
/* Message HTML description. */
property
string
emailBody
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
)
setZfoFile
(
zfoFilePath
)
/* Model method. */
}
}
}
...
...
@@ -110,7 +109,7 @@ Component {
MouseArea
{
anchors.fill
:
parent
onClicked
:
{
files
.
sendAttachmentsWithEmailFromZfo
(
zfoId
,
eSubject
,
e
Body
)
files
.
sendAttachmentsWithEmailFromZfo
(
zfoId
,
msgAnnotation
,
email
Body
)
}
}
}
...
...
@@ -156,6 +155,7 @@ Component {
width
:
parent
.
width
textFormat
:
TextEdit
.
RichText
wrapMode
:
Text
.
WordWrap
text
:
msgDescrHtml
Connections
{
target
:
files
onMessageDetailChanged
:
{
...
...
src/files.cpp
View file @
482317b7
...
...
@@ -233,7 +233,8 @@ void Files::openAttachmentFromDb(const QString &userName,
}
if
(
isAttachmentZfoFile
(
fileName
))
{
parseXmlData
(
globFilesModelZfo
,
decodeZfoFile
(
file
.
content
));
parseXmlData
(
Q_NULLPTR
,
Q_NULLPTR
,
&
globFilesModelZfo
,
Q_NULLPTR
,
decodeZfoFile
(
file
.
content
));
return
;
}
...
...
@@ -252,7 +253,8 @@ void Files::openAttachment(const QString &fileName, const QString &content)
}
if
(
isAttachmentZfoFile
(
fileName
))
{
parseXmlData
(
globFilesModelZfo
,
decodeZfoFile
(
content
));
parseXmlData
(
Q_NULLPTR
,
Q_NULLPTR
,
&
globFilesModelZfo
,
Q_NULLPTR
,
decodeZfoFile
(
content
));
return
;
}
...
...
@@ -647,7 +649,8 @@ QByteArray Files::decodeZfoFile(const QString &content)
return
decodeCmsData
(
cmsData
);
}
bool
Files
::
parseXmlData
(
FileListModel
&
attachModel
,
QByteArray
data
)
bool
Files
::
parseXmlData
(
QString
*
annotation
,
QString
*
msgDescrHtml
,
FileListModel
*
attachModel
,
QString
*
emailBody
,
QByteArray
data
)
{
qDebug
(
"%s()"
,
__func__
);
...
...
@@ -791,8 +794,18 @@ bool Files::parseXmlData(FileListModel &attachModel, QByteArray data)
"to databox."
).
arg
(
msg
.
dmID
);
body
+=
"
\n
"
;
// set file model
setZfoFilesToModel
(
attachModel
,
fileList
);
if
(
annotation
!=
Q_NULLPTR
)
{
*
annotation
=
msg
.
dmAnnotation
;
}
if
(
msgDescrHtml
!=
Q_NULLPTR
)
{
*
msgDescrHtml
=
html
;
}
if
(
attachModel
!=
Q_NULLPTR
)
{
setZfoFilesToModel
(
*
attachModel
,
fileList
);
}
if
(
emailBody
!=
Q_NULLPTR
)
{
*
emailBody
=
body
;
}
// remember file list and message detail
stackFileList
.
push
(
fileList
);
stackMessageDetail
.
push
(
html
);
...
...
@@ -803,26 +816,89 @@ bool Files::parseXmlData(FileListModel &attachModel, QByteArray data)
return
success
;
}
bool
Files
::
openZfoFileFromStorage
(
FileListModel
&
attachModel
,
const
QString
&
filePath
)
bool
Files
::
fileReadable
(
const
QString
&
filePath
)
{
qDebug
(
"%s()"
,
__func__
);
if
(
filePath
.
isEmpty
())
{
Q_ASSERT
(
0
);
qCritical
()
<<
"Target ZFO path is empty!"
;
return
false
;
}
{
QFileInfo
fileInfo
(
filePath
);
if
(
!
fileInfo
.
isFile
()
||
!
fileInfo
.
isReadable
())
{
qCritical
()
<<
"Cannot open ZFO file from"
<<
filePath
;
return
false
;
}
}
bool
ret
=
false
;
return
true
;
}
Q_ASSERT
(
!
filePath
.
isEmpty
());
if
(
filePath
.
isEmpty
())
{
qDebug
()
<<
"ERROR: Target ZFO path is empty!"
;
return
ret
;
QString
Files
::
msgAnnotation
(
const
QString
&
filePath
)
{
if
(
!
fileReadable
(
filePath
))
{
return
QString
()
;
}
QFile
file
(
filePath
);
if
(
!
file
.
open
(
QIODevice
::
ReadOnly
))
{
qDebug
()
<<
"ERROR: Cannot open ZFO file from"
<<
filePath
;
return
ret
;
file
.
open
(
QIODevice
::
ReadOnly
);
QString
annotation
;
bool
ret
=
parseXmlData
(
&
annotation
,
Q_NULLPTR
,
Q_NULLPTR
,
Q_NULLPTR
,
decodeCmsData
(
file
.
readAll
()));
file
.
close
();
return
ret
?
annotation
:
QString
();
}
QString
Files
::
msgDescriptionHtml
(
const
QString
&
filePath
)
{
if
(
!
fileReadable
(
filePath
))
{
return
QString
();
}
ret
=
parseXmlData
(
attachModel
,
decodeCmsData
(
file
.
readAll
()));
QFile
file
(
filePath
);
file
.
open
(
QIODevice
::
ReadOnly
);
QString
htmlDescr
;
bool
ret
=
parseXmlData
(
Q_NULLPTR
,
&
htmlDescr
,
Q_NULLPTR
,
Q_NULLPTR
,
decodeCmsData
(
file
.
readAll
()));
file
.
close
();
return
ret
?
htmlDescr
:
QString
();
}
QString
Files
::
msgEmailBody
(
const
QString
&
filePath
)
{
if
(
!
fileReadable
(
filePath
))
{
return
QString
();
}
QFile
file
(
filePath
);
file
.
open
(
QIODevice
::
ReadOnly
);
QString
emailBody
;
bool
ret
=
parseXmlData
(
Q_NULLPTR
,
Q_NULLPTR
,
Q_NULLPTR
,
&
emailBody
,
decodeCmsData
(
file
.
readAll
()));
file
.
close
();
return
ret
?
emailBody
:
QString
();
}
bool
Files
::
openZfoFileFromStorage
(
FileListModel
&
attachModel
,
const
QString
&
filePath
)
{
if
(
!
fileReadable
(
filePath
))
{
return
false
;
}
QFile
file
(
filePath
);
file
.
open
(
QIODevice
::
ReadOnly
);
bool
ret
=
parseXmlData
(
Q_NULLPTR
,
Q_NULLPTR
,
&
attachModel
,
Q_NULLPTR
,
decodeCmsData
(
file
.
readAll
()));
file
.
close
();
return
ret
;
}
src/files.h
View file @
482317b7
...
...
@@ -118,6 +118,42 @@ public:
Q_INVOKABLE
bool
deleteAttachmentsFromDb
(
const
QString
&
userName
,
qint64
msgId
);
/*!
* @brief Checks whether file is readable.
*
* @param[in] filePath Path to file.
* @return True if file exists and is readable.
*/
static
bool
fileReadable
(
const
QString
&
filePath
);
/*!
* @brief Parses content of ZFO file.
*
* @param[in] filePath Path to file.
* @return Annotation on success, empty string else.
*/
Q_INVOKABLE
static
QString
msgAnnotation
(
const
QString
&
filePath
);
/*!
* @brief Parses content of ZFO file.
*
* @param[in] filePath Path to file.
* @return Message description on success, empty string else.
*/
Q_INVOKABLE
static
QString
msgDescriptionHtml
(
const
QString
&
filePath
);
/*!
* @brief Parses content of ZFO file.
*
* @param[in] filePath Path to file.
* @return Email containing message on success, empty string else.
*/
Q_INVOKABLE
static
QString
msgEmailBody
(
const
QString
&
filePath
);
/*!
* @brief Open ZFO file from path.
*
...
...
@@ -222,12 +258,19 @@ private:
/*!
* @brief Parse xml data of zfo file.
*
* @todo This function must be reworked as it is called multiple times
* on a single message to obtain various data.
*
* @param[out] annotation Annotation string.
* @param[out] msgDescrHtml Message text.
* @param[out] attachModel Attachment model to be set.
* @param[out] emailBody Email body.
* @param[in] data Xml file data.
* @return true if success.
*/
static
bool
parseXmlData
(
FileListModel
&
attachModel
,
QByteArray
data
);
bool
parseXmlData
(
QString
*
annotation
,
QString
*
msgDescrHtml
,
FileListModel
*
attachModel
,
QString
*
emailBody
,
QByteArray
data
);
};
#endif // FILES_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment