Commit 76a2aaac authored by Martin Straka's avatar Martin Straka Committed by Karel Slaný

Changed message detail page and moved files operations to listview (issue #15)

parent 38c0cc57
......@@ -49,6 +49,7 @@ ApplicationWindow {
property Component accountsPage: AccountsPage {}
property Component messagesPage: MessagesPage {}
property Component messageDetailPage: MessageDetailPage {}
property Component messageDetailMenuPage: MessageDetailMenuPage {}
property Component accountDetailPage: AccountDetailPage {}
property Component accountSettingsPage: AccountSettingsPage {}
property Component accountMenuPage: AccountMenuPage {}
......@@ -82,6 +83,24 @@ ApplicationWindow {
property string gAcntName
property int gMsgType
property string gMsgId
/* compare message delivery date with current date-90days */
property int deleteAfterDays: 90
function compareMsgDate(msgDeliveryTime) {
if (msgDeliveryTime == "") {
// message has virus or delivery time missing
return true
} else {
// convert qml date format to ISO date format
var inputDateFormat = /(\d{2})\.(\d{2})\.(\d{4})/;
var msgDate = new Date(msgDeliveryTime.replace(inputDateFormat,'$3-$2-$1'));
var today = new Date()
today.setDate(today.getDate()-deleteAfterDays)
// compare both dates in milliseconds
return (today.getTime() > msgDate.getTime())
}
}
// page stack
Rectangle {
id: mainPage
......
/*
* Copyright (C) 2014-2016 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Window 2.1
import QtQuick.Layouts 1.2
import QtQuick.Dialogs 1.2
import QtGraphicalEffects 1.0
Component {
id: messageDetailMenuPage
Item {
id: mainLayout
property int myWidht: mainLayout.width - 2 * defaultMargin
Rectangle {
id: header
anchors.top: parent.top
width: parent.width
height: headerHeight
color: datovkaPalette.highlight
Image {
id: backElement
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: defaultMargin
sourceSize.height: navImgHeight
source: "qrc:/ui/back.svg"
}
Rectangle {
anchors.left: parent.left
width: parent.width * 0.5
height: parent.height
color: "transparent"
MouseArea {
anchors.fill: parent
onClicked: {
pageView.pop(StackView.Immediate)
}
}
}
Column {
anchors.verticalCenter: parent.verticalCenter
anchors.left: backElement.right
anchors.leftMargin: defaultMargin
Label {
text: {
if (gMsgType == sentMESSAGE) {
qsTr("Sent message") + " " + gMsgId
} else {
qsTr("Received message") + " " + gMsgId
}
}
font.bold: true
color: datovkaPalette.text
}
Label {
text: qsTr("Attachments options")
font.bold: true
color: datovkaPalette.text
}
}
}
Rectangle {
anchors.top: header.bottom
anchors.bottom: parent.bottom
width: parent.width
color: "transparent"
ListModel {
id: messageDetailMenuListModel
ListElement {
index: 0
name: qsTr("Download attachments")
image: "qrc:/ui/datovka-email-download.svg"
showNext: false
}
ListElement {
index: 1
name: qsTr("Send attachments by email")
image: "qrc:/ui/reply.svg"
showNext: false
}
ListElement {
index: 2
name: qsTr("Save attachments to disk")
image: "qrc:/ui/save-to-disk.svg"
showNext: false
}
ListElement {
index: 3
name: qsTr("Delete attachments")
image: "qrc:/ui/delete.svg"
showNext: false
}
}
Component {
id: messageDetailMenuComponent
Rectangle {
color: datovkaPalette.base
height: headerHeight
width: parent.width
Image {
id: menuImage
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: defaultMargin
sourceSize.height: imgHeight * 0.7
source: image
}
ColorOverlay {
anchors.fill: menuImage
source: menuImage
color: datovkaPalette.text
}
Text {
anchors.verticalCenter: parent.verticalCenter
anchors.left: menuImage.right
anchors.leftMargin: defaultMargin
color: datovkaPalette.text
text: name
}
Rectangle {
id: next2
visible: showNext
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
height: parent.height
width: parent.width * 0.07
color: parent.color
Image {
id: nextImage2
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: defaultMargin
sourceSize.height: navImgHeight
source: "qrc:/ui/next.svg"
}
ColorOverlay {
anchors.fill: nextImage2
source: nextImage2
color: datovkaPalette.text
}
}
MouseArea {
anchors.fill: parent
onClicked: {
if (index == 0) {
isds.downloadMessage(gUserName, gMsgType, gMsgId)
} else if (index == 1) {
files.sendAttachmentsWithEmail(gUserName, gMsgId)
} else if (index == 2) {
files.saveAttachmentsToDisk(gUserName, gMsgId)
} else if (index == 3) {
if (files.deleteAttachmentsFromDb(gUserName, gMsgId)) {
files.clearFileModel()
}
}
pageView.pop(StackView.Immediate)
}
}
}
}
ListView {
id: messageDetailMenuList
anchors.fill: parent
clip: true
spacing: 1
opacity: 1
visible: true
width: parent.width
interactive: true
model: messageDetailMenuListModel
delegate: messageDetailMenuComponent
}
}
}
}
......@@ -35,8 +35,9 @@ Component {
id: msgDetailPage
Component.onCompleted: {
if (attachmentList.count == 0) {
fileMenu.visible = false
emptyList.visible = true
msgDownloadButton.visible = true
attachmentMenuButon.visible = false
}
}
Rectangle {
......@@ -97,11 +98,25 @@ Component {
id: msgDownloadButton
anchors.verticalCenter: parent.verticalCenter
sourceSize.height: imgHeight
source: "qrc:/ui/attach-download.svg"
source: "qrc:/ui/datovka-email-download.svg"
MouseArea {
anchors.fill: parent
onClicked: {
isds.downloadMessage(gUserName, gMsgType, gMsgId)
msgDownloadButton.visible = false
attachmentMenuButon.visible = true
}
}
}
Image {
id: attachmentMenuButon
anchors.verticalCenter: parent.verticalCenter
sourceSize.height: imgHeight
source: "qrc:/ui/attach-download.svg"
MouseArea {
anchors.fill: parent
onClicked: {
pageView.push(messageDetailMenuPage, StackView.Immediate)
}
}
}
......@@ -157,48 +172,6 @@ Component {
text: "<h3>" + qsTr("Attachments") + "</h3>"
font.bold: true
}
Item {
id: fileMenu
anchors.top: parent.top
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
Image {
id: msgSaveButton
anchors.right: parent.right
anchors.rightMargin: defaultMargin
sourceSize.height: imgHeight
source: "qrc:/ui/save-to-disk.svg"
MouseArea {
anchors.fill: parent
onClicked: {
files.saveAttachmentsToDisk(gUserName, gMsgId)
}
}
}
ColorOverlay {
anchors.fill: msgSaveButton
source: msgSaveButton
color: datovkaPalette.text
}
Image {
id: msgEmailButton
anchors.right: msgSaveButton.left
anchors.rightMargin: defaultMargin
sourceSize.height: imgHeight
source: "qrc:/ui/attach-to-mail.svg"
MouseArea {
anchors.fill: parent
onClicked: {
files.sendAttachmentsWithEmail(gUserName, gMsgId)
}
}
}
ColorOverlay {
anchors.fill: msgEmailButton
source: msgEmailButton
color: datovkaPalette.text
}
}
Rectangle {
id: attachmentLabelLine
anchors.bottom: parent.bottom
......@@ -209,7 +182,6 @@ Component {
}
ListView {
id: attachmentList
anchors.top: attachmentLabel.bottom
anchors.bottom: parent.bottom
clip: true
......@@ -222,10 +194,12 @@ Component {
onCountChanged: {
if (attachmentList.count == 0) {
emptyList.visible = true
fileMenu.visible = false
msgDownloadButton.visible = true
attachmentMenuButon.visible = false
} else {
emptyList.visible = false
fileMenu.visible = true
msgDownloadButton.visible = false
attachmentMenuButon.visible = true
}
}
delegate: Rectangle {
......@@ -298,7 +272,6 @@ Component {
color: datovkaPalette.mid
}
}
property bool downloadStart: false
//onContentYChanged: // whenever position changes
//onVerticalVelocityChanged:
......@@ -322,4 +295,3 @@ Component {
}
}
}
......@@ -40,7 +40,6 @@ Component {
}
}
property bool canDeleteMsg: false
property int deleteAfterDays: 90
Rectangle {
id: header2
anchors.top: parent.top
......@@ -318,21 +317,6 @@ Component {
files.fillFileList(gUserName, rMsgId)
}
onPressAndHold: {
/* compare message delivery date with current date-90days */
function compareMsgDate(msgDeliveryTime) {
if (msgDeliveryTime == "") {
// message has virus or delivery time missing
return true
} else {
// convert qml date format to ISO date format
var inputDateFormat = /(\d{2})\.(\d{2})\.(\d{4})/;
var msgDate = new Date(msgDeliveryTime.replace(inputDateFormat,'$3-$2-$1'));
var today = new Date()
today.setDate(today.getDate()-deleteAfterDays)
// compare both dates in milliseconds
return (today.getTime() > msgDate.getTime())
}
}
gMsgId = rMsgId
canDeleteMsg = compareMsgDate(rDelivTime)
statusBar.visible = false
......
......@@ -106,5 +106,6 @@
<file>../qml/pages/SettingsMainPage.qml</file>
<file>../qml/pages/SettingsStoragePage.qml</file>
<file>../qml/pages/AccountMenuPage.qml</file>
<file>../qml/pages/MessageDetailMenuPage.qml</file>
</qresource>
</RCC>
......@@ -442,3 +442,34 @@ void Files::vacuumFileDbs(void)
emit statusBarTextChanged(tr("Operation Vacuum has finished"), false);
}
/* ========================================================================= */
/*
* Slot: Delete message attachments from databases.
*/
bool Files::deleteAttachmentsFromDb(const QString &userName, qint64 msgId)
/* ========================================================================= */
{
qDebug("%s()", __func__);
FileDb *fDb = NULL;
fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation, userName);
if (fDb == NULL) {
qDebug() << "ERROR: File database cannot open!" << userName;
return false;
}
if (fDb->deleteFilesFromDb(msgId)) {
MessageDb *msgDb = NULL;
msgDb = globMessageDbsPtr->accessMessageDb(globSet.dbsLocation,
userName);
if (msgDb == NULL) {
qDebug() << "ERROR: Message database cannot open!";
return false;
}
return msgDb->setAttachmentDownloaded(msgId, false);
}
return false;
}
......@@ -83,6 +83,16 @@ public:
*/
Q_INVOKABLE void vacuumFileDbs(void);
/*!
* @brief Delete message attachments from databases.
*
* @param[in] userName - user name of account.
* @param[in] msgId - message id.
* @return true if success.
*/
Q_INVOKABLE
bool deleteAttachmentsFromDb(const QString &userName, qint64 msgId);
class File {
public:
File(void)
......
......@@ -54,6 +54,7 @@ static const struct {
{ "AccountsPage", 1, 0 },
{ "MessagesPage", 1, 0 },
{ "MessageDetailPage", 1, 0 },
{ "MessageDetailMenuPage", 1, 0 },
{ "AccountDetailPage", 1, 0 },
{ "AccountSettingsPage", 1, 0 },
{ "AccountMenuPage", 1, 0 },
......
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