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
4b57255a
Commit
4b57255a
authored
Mar 15, 2017
by
Karel Slaný
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Passing message content into ZFO message detail page.
parent
314f9f0f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
131 additions
and
113 deletions
+131
-113
qml/main.qml
qml/main.qml
+2
-4
qml/pages/PageZfoMessageDetail.qml
qml/pages/PageZfoMessageDetail.qml
+25
-7
src/files.cpp
src/files.cpp
+61
-76
src/files.h
src/files.h
+37
-22
src/models/filemodel.cpp
src/models/filemodel.cpp
+2
-2
src/models/filemodel.h
src/models/filemodel.h
+4
-2
No files found.
qml/main.qml
View file @
4b57255a
...
...
@@ -288,12 +288,10 @@ ApplicationWindow {
* enabled.
*/
console
.
log
(
"
Showing zfo file:
"
+
filePath
)
var
fileContent
=
files
.
rawFileContent
(
filePath
)
mainStack
.
push
(
pageZfoMessageDetail
,
{
"
pageView
"
:
mainStack
,
"
zfoFilePath
"
:
filePath
,
"
msgAnnotation
"
:
files
.
msgAnnotation
(
filePath
),
"
msgDescrHtml
"
:
files
.
msgDescriptionHtml
(
filePath
),
"
emailBody
"
:
files
.
msgEmailBody
(
filePath
)
"
rawZfoContent
"
:
fileContent
},
StackView
.
Immediate
)
}
}
...
...
qml/pages/PageZfoMessageDetail.qml
View file @
4b57255a
...
...
@@ -28,27 +28,35 @@ import QtGraphicalEffects 1.0
import
cz
.
nic
.
mobileDatovka
.
models
1.0
Component
{
id
:
pageZfoMessageDetail
id
:
componentZfoMessageDetail
Item
{
id
:
msgZfoDetailPage
/* These properties must be set by caller. */
property
var
pageView
property
var
statusBar
property
var
zfoFilePath
property
var
rawZfoContent
/* Raw ZFO file content. */
/* These properties are set from within the page. */
property
var
msgAnnotation
property
var
msgDescrHtml
/* Message HTML description. */
property
string
emailBody
property
string
zfoId
onRawZfoContentChanged
:
{
console
.
log
(
"
File path changed.
"
)
msgAnnotation
=
files
.
msgAnnotation
(
rawZfoContent
),
msgDescrHtml
=
files
.
msgDescriptionHtml
(
rawZfoContent
),
emailBody
=
files
.
msgEmailBody
(
rawZfoContent
)
attachmentModel
.
setZfo
(
rawZfoContent
)
}
FileListModel
{
id
:
attachmentModel
Component.onCompleted
:
{
/* Load content from ZFO file if such is supplied. */
if
(
typeof
(
zfoFilePath
)
!=
"
undefined
"
)
{
setZfoFile
(
zfoFilePath
)
/* Model method. */
}
}
}
...
...
@@ -258,7 +266,17 @@ Component {
anchors.fill
:
parent
onClicked
:
{
locker
.
ignoreNextSuspension
()
files
.
openAttachment
(
rFileName
,
rFileContent
)
if
(
files
.
isZfoFile
(
rFileName
))
{
console
.
log
(
"
Attachment is ZFO:
"
+
rFileName
)
var
fileContent
=
files
.
base64ToRaw
(
rFileContent
)
pageView
.
push
(
pageZfoMessageDetail
,
{
"
pageView
"
:
pageView
,
"
statusBar
"
:
statusBar
,
"
rawZfoContent
"
:
fileContent
},
StackView
.
Immediate
)
}
else
{
files
.
openAttachment
(
rFileName
,
rFileContent
)
}
}
}
Rectangle
{
...
...
src/files.cpp
View file @
4b57255a
...
...
@@ -232,37 +232,38 @@ void Files::openAttachmentFromDb(const QString &userName,
return
;
}
if
(
is
Attachment
ZfoFile
(
fileName
))
{
if
(
isZfoFile
(
fileName
))
{
parseXmlData
(
Q_NULLPTR
,
Q_NULLPTR
,
&
globFilesModelZfo
,
Q_NULLPTR
,
decodeZfoFile
(
file
.
content
));
Q_NULLPTR
,
decodeZfoFile
(
file
.
content
.
toUtf8
()
));
return
;
}
openAttachment
(
fileName
,
file
.
content
);
openAttachment
(
fileName
,
file
.
content
.
toUtf8
()
);
}
void
Files
::
openAttachment
(
const
QString
&
fileName
,
const
Q
String
&
content
)
void
Files
::
openAttachment
(
const
QString
&
fileName
,
const
Q
ByteArray
&
base64Data
)
{
Q_ASSERT
(
!
fileName
.
isEmpty
());
Q_ASSERT
(
!
content
.
isEmpty
());
Q_ASSERT
(
!
base64Data
.
isEmpty
());
if
(
fileName
.
isEmpty
()
||
content
.
isEmpty
())
{
q
Debug
()
<<
"ERROR:
File name or its content is empty!"
;
if
(
fileName
.
isEmpty
()
||
base64Data
.
isEmpty
())
{
q
Critical
()
<<
"
File name or its content is empty!"
;
return
;
}
if
(
isAttachmentZfoFile
(
fileName
))
{
parseXmlData
(
Q_NULLPTR
,
Q_NULLPTR
,
&
globFilesModelZfo
,
Q_NULLPTR
,
decodeZfoFile
(
content
));
if
(
isZfoFile
(
fileName
))
{
/* Don't open zfo files from here. */
Q_ASSERT
(
0
);
qCritical
()
<<
"This should open ZFO files by itself."
;
return
;
}
QByteArray
data
=
QByteArray
::
fromBase64
(
content
.
toUtf8
(
));
QString
filePath
=
writeFileToTmpDir
(
fileName
,
TEMP_DIR_NAME
,
d
ata
);
QByteArray
rawData
(
QByteArray
::
fromBase64
(
base64Data
));
QString
filePath
(
writeFileToTmpDir
(
fileName
,
TEMP_DIR_NAME
,
rawD
ata
)
)
;
if
(
!
filePath
.
isEmpty
())
{
q
Debug
()
<<
filePath
;
q
Info
()
<<
"Creating temporary file"
<<
filePath
;
#if defined Q_OS_IOS
UrlOpener
urlOpener
;
...
...
@@ -284,7 +285,7 @@ void Files::openAttachment(const QString &fileName, const QString &content)
}
#endif
/* defined Q_OS_IOS */
}
else
{
q
Debug
()
<<
"Tmp file save error"
;
q
Critical
()
<<
"Cannot create temporary file for"
<<
fileName
;
QMessageBox
msgBox
;
msgBox
.
setIcon
(
QMessageBox
::
Critical
);
msgBox
.
setWindowTitle
(
tr
(
"Open attachment error"
));
...
...
@@ -597,28 +598,20 @@ void Files::sendEmail(const QString &emailMessage, const QStringList &fileList,
}
}
bool
Files
::
isAttachmentZfoFile
(
const
QString
&
fileName
)
{
qDebug
(
"%s()"
,
__func__
);
QFileInfo
fi
(
fileName
);
return
(
fi
.
suffix
().
toLower
()
==
"zfo"
);
}
QByteArray
Files
::
decodeCmsData
(
const
QByteArray
&
cmsData
)
QByteArray
Files
::
getXmlFromCms
(
const
QByteArray
&
rawData
)
{
qDebug
(
"%s()"
,
__func__
);
Q_ASSERT
(
!
cms
Data
.
isEmpty
())
;
if
(
cmsData
.
isEmpty
())
{
q
Debug
()
<<
"ERROR:
File content is empty!"
;
if
(
raw
Data
.
isEmpty
())
{
Q_ASSERT
(
0
);
q
Critical
()
<<
"
File content is empty!"
;
return
QByteArray
();
}
/*
d
ecode
cms
and obtain message
xml
data - use
d openssl
*/
/*
D
ecode
CMS
and obtain message
XML
data - use
s OpenSSL.
*/
void
*
xmlContent
=
NULL
;
size_t
xmlContentLen
=
0
;
if
(
extract_cms_data
(
cms
Data
.
data
(),
cms
Data
.
length
(),
&
xmlContent
,
if
(
extract_cms_data
(
raw
Data
.
data
(),
raw
Data
.
length
(),
&
xmlContent
,
&
xmlContentLen
)
!=
0
)
{
return
QByteArray
();
}
...
...
@@ -627,26 +620,24 @@ QByteArray Files::decodeCmsData(const QByteArray &cmsData)
return
QByteArray
();
}
QByteArray
soap
((
char
*
)
xmlContent
,
xmlContentLen
);
QByteArray
soap
((
char
*
)
xmlContent
,
xmlContentLen
);
free
(
xmlContent
);
xmlContent
=
NULL
;
return
soap
;
}
QByteArray
Files
::
decodeZfoFile
(
const
Q
String
&
content
)
QByteArray
Files
::
decodeZfoFile
(
const
Q
ByteArray
&
base64ZfoData
)
{
qDebug
(
"%s()"
,
__func__
);
Q_ASSERT
(
!
content
.
isEmpty
())
;
if
(
content
.
isEmpty
())
{
q
Debug
()
<<
"ERROR:
File content is empty
!
"
;
if
(
base64ZfoData
.
isEmpty
())
{
Q_ASSERT
(
0
);
q
Critical
()
<<
"
File content is empty
.
"
;
return
QByteArray
();
}
/* decode signature from base64 and obtain something cms message */
QByteArray
cmsData
=
QByteArray
::
fromBase64
(
content
.
toUtf8
());
return
decodeCmsData
(
cmsData
);
/* decode signature from base64 and obtain something CMS message */
return
getXmlFromCms
(
QByteArray
::
fromBase64
(
base64ZfoData
));
}
bool
Files
::
parseXmlData
(
QString
*
annotation
,
QString
*
msgDescrHtml
,
...
...
@@ -835,70 +826,64 @@ bool Files::fileReadable(const QString &filePath)
return
true
;
}
QString
Files
::
msgAnnotation
(
const
QString
&
filePath
)
bool
Files
::
isZfoFile
(
const
QString
&
fileName
)
{
return
QFileInfo
(
fileName
).
suffix
().
toLower
()
==
QStringLiteral
(
"zfo"
);
}
QByteArray
Files
::
rawFileContent
(
const
QString
&
filePath
)
{
if
(
!
fileReadable
(
filePath
))
{
return
Q
String
();
return
Q
ByteArray
();
}
QFile
file
(
filePath
);
file
.
open
(
QIODevice
::
ReadOnly
);
if
(
!
file
.
open
(
QIODevice
::
ReadOnly
))
{
Q_ASSERT
(
0
);
qCritical
()
<<
"Cannot open file"
<<
filePath
;
return
QByteArray
();
}
QString
annotation
;
bool
ret
=
parseXmlData
(
&
annotation
,
Q_NULLPTR
,
Q_NULLPTR
,
Q_NULLPTR
,
decodeCmsData
(
file
.
readAll
()));
QByteArray
rawData
(
file
.
readAll
());
file
.
close
();
return
rawData
;
}
return
ret
?
annotation
:
QString
();
QByteArray
Files
::
base64ToRaw
(
const
QByteArray
&
base64Data
)
{
return
QByteArray
::
fromBase64
(
base64Data
);
}
QString
Files
::
msg
DescriptionHtml
(
const
QString
&
fileP
at
h
)
QString
Files
::
msg
Annotation
(
const
QByteArray
&
rawZfoD
at
a
)
{
if
(
!
fileReadable
(
filePath
))
{
return
QString
();
}
QString
annotation
;
bool
ret
=
parseXmlData
(
&
annotation
,
Q_NULLPTR
,
Q_NULLPTR
,
Q_NULLPTR
,
getXmlFromCms
(
rawZfoData
));
QFile
file
(
filePath
);
file
.
open
(
QIODevice
::
ReadOnly
);
return
ret
?
annotation
:
QString
(
);
}
QString
Files
::
msgDescriptionHtml
(
const
QByteArray
&
rawZfoData
)
{
QString
htmlDescr
;
bool
ret
=
parseXmlData
(
Q_NULLPTR
,
&
htmlDescr
,
Q_NULLPTR
,
Q_NULLPTR
,
decodeCmsData
(
file
.
readAll
()));
file
.
close
();
getXmlFromCms
(
rawZfoData
));
return
ret
?
htmlDescr
:
QString
();
}
QString
Files
::
msgEmailBody
(
const
Q
String
&
fileP
at
h
)
QString
Files
::
msgEmailBody
(
const
Q
ByteArray
&
rawZfoD
at
a
)
{
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
();
getXmlFromCms
(
rawZfoData
));
return
ret
?
emailBody
:
QString
();
}
bool
Files
::
openZfoFileFromStorage
(
FileListModel
&
attachModel
,
const
Q
String
&
fileP
at
h
)
bool
Files
::
setAttachmentModel
(
FileListModel
&
attachModel
,
const
Q
ByteArray
&
rawZfoD
at
a
)
{
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
;
return
parseXmlData
(
Q_NULLPTR
,
Q_NULLPTR
,
&
attachModel
,
Q_NULLPTR
,
getXmlFromCms
(
rawZfoData
));
}
src/files.h
View file @
4b57255a
...
...
@@ -58,7 +58,7 @@ public:
* @brief Open attachment in default application.
*/
Q_INVOKABLE
void
openAttachment
(
const
QString
&
fileName
,
const
Q
String
&
content
);
const
Q
ByteArray
&
base64Data
);
/*!
* @brief Send attachments from database with email application.
...
...
@@ -127,6 +127,30 @@ public:
static
bool
fileReadable
(
const
QString
&
filePath
);
/*!
* @brief Tests whether attachment is ZFO file.
*
* @param[in] fileName File name.
* @return True if file has zfo suffix.
*/
Q_INVOKABLE
static
bool
isZfoFile
(
const
QString
&
fileName
);
/*!
* @brief Returns raw file content.
*
* @param[in] filePath Path to file.
* @return File content, QByteArray() on error.
*/
Q_INVOKABLE
static
QByteArray
rawFileContent
(
const
QString
&
filePath
);
/*!
* @brief Decodes base64-encoded content.
*/
Q_INVOKABLE
static
QByteArray
base64ToRaw
(
const
QByteArray
&
base64Data
);
/*!
* @brief Parses content of ZFO file.
*
...
...
@@ -134,7 +158,7 @@ public:
* @return Annotation on success, empty string else.
*/
Q_INVOKABLE
static
QString
msgAnnotation
(
const
Q
String
&
fileP
at
h
);
QString
msgAnnotation
(
const
Q
ByteArray
&
rawZfoD
at
a
);
/*!
* @brief Parses content of ZFO file.
...
...
@@ -143,7 +167,7 @@ public:
* @return Message description on success, empty string else.
*/
Q_INVOKABLE
static
QString
msgDescriptionHtml
(
const
Q
String
&
fileP
at
h
);
QString
msgDescriptionHtml
(
const
Q
ByteArray
&
rawZfoD
at
a
);
/*!
* @brief Parses content of ZFO file.
...
...
@@ -152,18 +176,18 @@ public:
* @return Email containing message on success, empty string else.
*/
Q_INVOKABLE
static
QString
msgEmailBody
(
const
Q
String
&
fileP
at
h
);
QString
msgEmailBody
(
const
Q
ByteArray
&
rawZfoD
at
a
);
/*!
* @brief
Open ZFO file from path
.
* @brief
Sets attachment model
.
*
* @param[out] attachModel Attachment model to be set.
* @param[in] filePath File path with file name.
* @return true if success.
*/
static
bool
openZfoFileFromStorage
(
FileListModel
&
attachModel
,
const
Q
String
&
fileP
at
h
);
bool
setAttachmentModel
(
FileListModel
&
attachModel
,
const
Q
ByteArray
&
rawZfoD
at
a
);
class
File
{
public:
...
...
@@ -228,32 +252,23 @@ private:
void
sendEmail
(
const
QString
&
emailMessage
,
const
QStringList
&
fileList
,
const
QString
&
subject
,
const
QString
&
body
,
qint64
msgId
);
/*!
* @brief Test, if attachment is ZFO file.
*
* @param[in] fileName File name.
* @return true if file is zfo.
*/
static
bool
isAttachmentZfoFile
(
const
QString
&
fileName
);
/*!
* @brief Decode XML data from CMS.
*
* @param[in]
content
File content.
* @return
d
ecoded data or QByteArray().
* @param[in]
rawData
File content.
* @return
D
ecoded
XML
data or QByteArray().
*/
static
QByteArray
decodeCmsData
(
const
QByteArray
&
cms
Data
);
QByteArray
getXmlFromCms
(
const
QByteArray
&
raw
Data
);
/*!
* @brief Decode data from ZFO file.
*
* @param[in]
content F
ile content.
* @return
d
ecoded data or QByteArray().
* @param[in]
base64ZfoData Base64-encoded zfo f
ile content.
* @return
D
ecoded
raw
data or QByteArray().
*/
static
QByteArray
decodeZfoFile
(
const
Q
String
&
content
);
QByteArray
decodeZfoFile
(
const
Q
ByteArray
&
base64ZfoData
);
/*!
* @brief Parse xml data of zfo file.
...
...
src/models/filemodel.cpp
View file @
4b57255a
...
...
@@ -202,7 +202,7 @@ void FileListModel::clearAll(void)
endResetModel
();
}
bool
FileListModel
::
setZfo
File
(
const
Q
String
&
fileP
at
h
)
bool
FileListModel
::
setZfo
(
const
Q
ByteArray
&
rawZfoD
at
a
)
{
return
Files
::
openZfoFileFromStorage
(
*
this
,
fileP
at
h
);
return
Files
::
setAttachmentModel
(
*
this
,
rawZfoD
at
a
);
}
src/models/filemodel.h
View file @
4b57255a
...
...
@@ -135,10 +135,12 @@ public:
void
clearAll
(
void
);
/*!
* @brief Set content from ZFO file.
* @brief Set content from ZFO content.
*
* @param[in] rawZfoData Message content.
*/
Q_INVOKABLE
bool
setZfo
File
(
const
Q
String
&
fileP
at
h
);
bool
setZfo
(
const
Q
ByteArray
&
rawZfoD
at
a
);
private:
QList
<
Entry
>
m_files
;
/*!< List of attachment entries. */
...
...
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