Commit c23dd8e5 authored by Martin Straka's avatar Martin Straka

Added zfo forwarding

parent 4b91cf1e
......@@ -86,6 +86,12 @@ Component {
image: "qrc:/ui/reply.svg"
showNext: false
}
ListElement {
index: 6
name: qsTr("Forward")
image: "qrc:/ui/forward.svg"
showNext: false
}
ListElement {
index: 5
name: qsTr("Use as template")
......@@ -199,7 +205,16 @@ Component {
"msgType": msgType,
"action": "template"
}, StackView.Immediate)
}
} else if (index == 6) {
pageView.replace(pageSendMessage, {
"pageView": pageView,
"statusBar": statusBar,
"userName": userName,
"msgId": msgId,
"msgType": msgType,
"action": "fwdzfo"
}, StackView.Immediate)
}
}
}
}
......
......@@ -26,6 +26,7 @@ import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.0
import cz.nic.mobileDatovka 1.0
import cz.nic.mobileDatovka.files 1.0
import cz.nic.mobileDatovka.messages 1.0
import cz.nic.mobileDatovka.models 1.0
......@@ -43,8 +44,6 @@ Item {
/* Hold file path list for sending. */
property var filePaths: []
property int noFileId: -1
/* This property defines mandate textinput width. */
property int mandateFieldLenght : defaultTextFont.font.pointSize * 4
......@@ -96,6 +95,24 @@ Item {
sendMsgAttachmentModel.setFromDb(userName, msgId)
}
/* Set message forward data and add ZFO file to model */
function setForwardZfoData(userName, msgId) {
headerBar.title = qsTr("Forward %1").arg(msgId) + " (" + userName + ")"
var msgEnvelope = messages.getMsgEnvelopeDataAndSetRecipient(userName, msgId, null)
dmAnnotation.text = "Fwd: " + msgEnvelope.dmAnnotation
var fileName = (msgType == MessageType.TYPE_SENT) ? "ODZ_" + msgId + ".zfo" : "DDZ_" + msgId + ".zfo"
var zfoSize = zfo.getZfoSizeFromDb(userName, msgId)
// Zfo file must exist in the local database so zfoSize must be > 0
if (zfoSize > 0) {
sendMsgAttachmentModel.appendFileFromPath(FileIdType.DB_ZFO_ID, fileName, "",
getFileSizeString(zfoSize), files.getAttachmentFileIcon(fileName))
} else {
mainPanel.visible = false
errorText.text = qsTr("ZFO file of message %1 is not available. Download complete message to get it before forwarding.").arg(msgId)
errorText.visible = true
}
}
Component.onCompleted: {
if (action === "new") {
headerBar.title = qsTr("Create message") + " (" + userName + ")"
......@@ -103,6 +120,8 @@ Item {
setReplyData(userName, msgId)
} else if (action === "template") {
setTemplateData(userName, msgId)
} else if (action == "fwdzfo") {
setForwardZfoData(userName, msgId)
}
actionButton.enabled = false
var boxEffectiveOVM = accounts.boxEffectiveOVM(userName)
......@@ -124,8 +143,8 @@ Item {
}
if (!isInFiletList) {
var fileName = getFileNameFromPath(path)
sendMsgAttachmentModel.appendFileFromPath(noFileId, fileName, path,
getFileSizeString(files.getAttachmentSizeInBytes(path)),
sendMsgAttachmentModel.appendFileFromPath(FileIdType.NO_FILE_ID,
fileName, path, getFileSizeString(files.getAttachmentSizeInBytes(path)),
files.getAttachmentFileIcon(fileName))
}
}
......@@ -195,7 +214,7 @@ Item {
Connections {
target: isds
onRunSendMessageSig: {
isds.sendMessage(userName, dmAnnotation.text.toString(),
isds.sendMessage(userName, msgId, dmAnnotation.text.toString(),
recipBoxModel, sendMsgAttachmentModel,
dmLegalTitleLaw.text.toString(), dmLegalTitleYear.text.toString(),
dmLegalTitleSect.text.toString(), dmLegalTitlePar.text.toString(),
......@@ -386,7 +405,7 @@ Item {
anchors.fill: parent
onClicked: {
// fileId is set and is valid, use files from database
if (rFileId != noFileId) {
if (rFileId != FileIdType.NO_FILE_ID) {
if (files.isZfoFile(rFileName)) {
pageView.push(pageMessageDetail, {
"pageView": pageView,
......
......@@ -130,6 +130,12 @@ void finishEmailMessage(QString &message, const QString &boundary)
message += newLine + "--" + boundary + "--" + newLine;
}
void Files::declareQML(void)
{
qmlRegisterType<Files>("cz.nic.mobileDatovka.files", 1, 0, "FileIdType");
qRegisterMetaType<Files::FileIdType>();
}
Files::Files(QObject *parent) : QObject(parent)
{
}
......
......@@ -37,6 +37,18 @@ class Files : public QObject {
Q_OBJECT
public:
/* Defines missing file id vaule and zfo id */
enum FileIdType {
NO_FILE_ID = -1,
DB_ZFO_ID = -2
};
Q_ENUM(FileIdType)
/* Don't forget to declare various properties to the QML system. */
static
void declareQML(void);
/*!
* @brief Constructor.
*
......@@ -328,4 +340,7 @@ private:
FileListModel *attachModel, QString *emailBody, QByteArray &xmlData);
};
/* Declare FileIdType to QML. */
Q_DECLARE_METATYPE(Files::FileIdType)
#endif // FILES_H
......@@ -301,6 +301,7 @@ int main(int argc, char *argv[])
DataboxModelEntry::declareQML();
Dialogues::declareQML();
FileListModel::declareQML();
Files::declareQML();
InteractionFilesystem::declareQML();
ListSortFilterProxyModel::declareQML();
MessageListModel::declareQML();
......
......@@ -33,6 +33,7 @@
#include "src/net/xml_layer.h"
#include "src/qml_interaction/message_envelope.h"
#include "src/settings.h"
#include "src/sqlite/zfo_db.h"
#include "src/worker/emitter.h"
#include "src/worker/task_change_password.h"
#include "src/worker/task_download_account_info.h"
......@@ -434,7 +435,7 @@ void IsdsWrapper::inputDialogReturnPassword(const QString &isdsAction,
}
}
void IsdsWrapper::sendMessage(const QString &userName,
void IsdsWrapper::sendMessage(const QString &userName, qint64 dmID,
const QString &dmAnnotation, const QVariant &dbModelVariant,
const QVariant &attachmentModelVariant,
const QString &dmLegalTitleLaw, const QString &dmLegalTitleYear,
......@@ -455,6 +456,9 @@ void IsdsWrapper::sendMessage(const QString &userName,
/* User must be logged to isds */
if (!isLoggedToIsds(userName)) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), tr("User must be logged to databox."),
tr("ISDS error."));
return;
}
......@@ -463,6 +467,9 @@ void IsdsWrapper::sendMessage(const QString &userName,
if (databoxModel == Q_NULLPTR) {
Q_ASSERT(0);
qCritical("%s", "Cannot access databox model.");
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), tr("Cannot access databox model."),
tr("Internal error"));
return;
}
......@@ -471,6 +478,9 @@ void IsdsWrapper::sendMessage(const QString &userName,
if (attachModel == Q_NULLPTR) {
Q_ASSERT(0);
qCritical("%s", "Cannot access attachment model.");
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), tr("Cannot access attachment model."),
tr("Internal error"));
return;
}
......@@ -496,6 +506,9 @@ void IsdsWrapper::sendMessage(const QString &userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == NULL) {
qDebug() << "ERROR: File database cannot open!" << userName;
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), tr("Cannot access file database."),
tr("Internal error"));
return;
}
......@@ -506,20 +519,35 @@ void IsdsWrapper::sendMessage(const QString &userName,
AttachmentData attach;
attach.setDmFileDescr(file.dmFileDescr());
if (file.fileId() >= 0) {
// load file content from database
if (file.fileId() > 0) {
// load file content from database, valid file ID
FileDb::FileData fileData = fDb->getFileContentFromDb(file.fileId());
attach.setDmEncodedContent(fileData.content);
totalAttachmentSizeKBs += fileData.content.length() / 1024;
} else {
} else if (file.fileId() == Files::DB_ZFO_ID) {
// load zfo content from zfo database
attach.setDmEncodedContent(globZfoDbPtr->getZfoContentFromDb(dmID,
AccountListModel::globAccounts[userName].isTestAccount()));
totalAttachmentSizeKBs += attach.dmEncodedContent().length() / 1024;
globZfoDbPtr->updateZfoLastAccessTime(dmID,
AccountListModel::globAccounts[userName].isTestAccount());
} else if (!file.filePath().isEmpty()) {
// load file content from storage (path)
QFileInfo fi(file.filePath());
totalAttachmentSizeKBs += fi.size() / 1024;
QFile fin(file.filePath());
if (!fin.open(QIODevice::ReadOnly)) {
continue;
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), tr("Cannot load file content from path:"),
file.filePath());
return;
}
attach.setDmEncodedContent(fin.readAll().toBase64());
} else {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), tr("No file to sending."),
tr("Internal error"));
return;
}
attach._setDmFileSize(getApproximatelyAttachmentFileSizeFromBase64(attach.dmEncodedContent().length()));
......
......@@ -172,6 +172,7 @@ public:
* @brief Send message.
*
* @param[in] userName Account username string.
* @param[in] dmID Message ID.
* @param[in] dmAnnotation Message subject string.
* @param[in] dbModelVariant Recipient databox model.
* @param[in] filePaths List of path to files.
......@@ -191,7 +192,7 @@ public:
* @param[in] dmPersonalDelivery True if personal delivery.
*/
Q_INVOKABLE
void sendMessage(const QString &userName,
void sendMessage(const QString &userName, qint64 dmID,
const QString &dmAnnotation, const QVariant &dbModelVariant,
const QVariant &attachmentModelVariant,
const QString &dmLegalTitleLaw, const QString &dmLegalTitleYear,
......
......@@ -21,6 +21,7 @@
* the two.
*/
#include "src/models/accountmodel.h"
#include "src/sqlite/zfo_db.h"
#include "src/zfo.h"
......@@ -28,9 +29,10 @@ Zfo::Zfo(QObject *parent) : QObject(parent)
{
}
int Zfo::getZfoSizeFromDb(qint64 msgId, bool isTestAccount)
int Zfo::getZfoSizeFromDb(const QString &userName, qint64 msgId)
{
return globZfoDbPtr->getZfoSizeFromDb(msgId, isTestAccount);
return globZfoDbPtr->getZfoSizeFromDb(msgId,
AccountListModel::globAccounts[userName].isTestAccount());
}
void Zfo::reduceZfoDbSize(unsigned int releaseSpaceInMB)
......
......@@ -44,12 +44,12 @@ public:
/*!
* @brief Get Zfo size in bytes.
*
* @param[in] userName User name identifying account.
* @param[in] msgId String with message id.
* @param[in] isTestAccount True if account is in the ISDS testing environment.
* @return Size of zfo file in bytes.
*/
Q_INVOKABLE static
int getZfoSizeFromDb(qint64 msgId, bool isTestAccount);
int getZfoSizeFromDb(const QString &userName, qint64 msgId);
/*!
* @brief Release db - delete oldest zfo files and vacuum db.
......
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