Commit f27bcb2b authored by Martin Straka's avatar Martin Straka

Show total attachment size in the send qml page

parent 08e2e5b6
......@@ -8,7 +8,7 @@
*
* 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
* 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
......@@ -42,6 +42,19 @@ Item {
property int msgType
property string action: "new"
/*
* These properties are constants and specifies some attachment size limits.
* Do not change these! See ISDS documentation about more message limit info.
*/
property int max_ATTACHMENT_FILES: 900
property int max_ATTACHMENT_SIZE_BYTES: 20000000 // 20MB
property int max_ATTACHMENT_SIZE_MB: 20
property int max_OVM_ATTACHMENT_SIZE_BYTES: 50000000 //50MB
property int max_OVM_ATTACHMENT_SIZE_MB: 50
/* This property holds total attachment size in bytes */
property int totalAttachmentSizeBytes: 0
/* This property defines mandate textinput width. */
property int mandateFieldLenght : defaultTextFont.font.pointSize * 4
......@@ -59,6 +72,37 @@ Item {
: "~" + (fileSize) + " B"
}
/* Check if message has fill an attachment and check total size */
function checkAttachmentSizes() {
attachmentsSizeLabel.color = datovkaPalette.text
var attachmentNumber = sendMsgAttachmentModel.rowCount()
if (attachmentNumber === 0) {
attachmentsSizeLabel.text = qsTr("Total size of attachments is %1 B.").arg(0)
return false;
}
if (attachmentNumber >= max_ATTACHMENT_FILES) {
attachmentsSizeLabel.text = qsTr("The permitted number of (%1) attachments has been exceeded.").arg(max_ATTACHMENT_FILES)
attachmentsSizeLabel.color = "#ff0000"
return false
}
if (totalAttachmentSizeBytes >= max_OVM_ATTACHMENT_SIZE_BYTES) {
attachmentsSizeLabel.text = qsTr("Total size of attachments exceeds %1 MB.").arg(max_OVM_ATTACHMENT_SIZE_MB)
attachmentsSizeLabel.color = "#ff0000"
return false
}
if (totalAttachmentSizeBytes >= max_ATTACHMENT_SIZE_BYTES) {
attachmentsSizeLabel.text = qsTr("Total size of attachments exceeds %1 MB. Most of the data boxes cannot receive messages larger than %1 MB. However, some OVM data boxes can receive message up to %2 MB.").arg(max_ATTACHMENT_SIZE_MB).arg(max_OVM_ATTACHMENT_SIZE_MB)
attachmentsSizeLabel.color = "#ff0000"
return true
}
if (totalAttachmentSizeBytes >= 1024) {
attachmentsSizeLabel.text = qsTr("Total size of attachments is ~%1 KB.").arg(Math.ceil(totalAttachmentSizeBytes/1024))
} else {
attachmentsSizeLabel.text = qsTr("Total size of attachments is %1 B.").arg(totalAttachmentSizeBytes)
}
return true
}
/* Set mandate fields in QML */
function setMandate(isdsEnvelope) {
dmLegalTitleLaw.text = isdsEnvelope.dmLegalTitleLawStr
......@@ -101,6 +145,10 @@ Item {
dmRecipientIdent.text = isdsEnvelope.dmRecipientIdent
setMandate(isdsEnvelope)
sendMsgAttachmentModel.setFromDb(userName, msgId)
for (var i = 0; i < sendMsgAttachmentModel.rowCount(); i++) {
totalAttachmentSizeBytes += sendMsgAttachmentModel.fileSizeBytesFromRow(i)
}
checkAttachmentSizes()
}
/* Set message forward data and add ZFO file to model */
......@@ -112,8 +160,9 @@ Item {
var zfoSize = zfo.getZfoSizeFromDb(userName, msgId)
// Zfo file must exist in the local database so zfoSize must be > 0
if (zfoSize > 0) {
totalAttachmentSizeBytes += zfoSize;
sendMsgAttachmentModel.appendFileFromPath(FileIdType.DB_ZFO_ID, fileName, "",
getFileSizeString(zfoSize), files.getAttachmentFileIcon(fileName))
getFileSizeString(zfoSize), files.getAttachmentFileIcon(fileName), zfoSize)
} 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)
......@@ -164,10 +213,11 @@ Item {
}
if (!isInFiletList) {
var fileName = getFileNameFromPath(pathListModel.get(j).path)
var fileSizeBytes = files.getAttachmentSizeInBytes(pathListModel.get(j).path)
totalAttachmentSizeBytes += fileSizeBytes;
sendMsgAttachmentModel.appendFileFromPath(FileIdType.NO_FILE_ID,
fileName, pathListModel.get(j).path,
getFileSizeString(files.getAttachmentSizeInBytes(pathListModel.get(j).path)),
files.getAttachmentFileIcon(fileName))
fileName, pathListModel.get(j).path, getFileSizeString(fileSizeBytes),
files.getAttachmentFileIcon(fileName), fileSizeBytes)
}
}
pathListModel.clear()
......@@ -246,7 +296,7 @@ Item {
/* Enable send message button if all required fields are filled */
function areReguiredFieldsFilled() {
actionButton.enabled = (dmAnnotation.text.toString() != "" && (recipBoxModel.rowCount() > 0) && (sendMsgAttachmentModel.rowCount() > 0))
actionButton.enabled = (checkAttachmentSizes() && (dmAnnotation.text.toString() !== "") && (recipBoxModel.rowCount() > 0))
}
TabBar {
......@@ -561,6 +611,7 @@ Item {
}
MouseArea {
function handleClick() {
totalAttachmentSizeBytes -= sendMsgAttachmentModel.fileSizeBytesFromRow(index)
sendMsgAttachmentModel.removeItem(index)
}
......@@ -592,7 +643,7 @@ Item {
delegateHeight: listItemHeight
anchors.top: addFile.bottom
anchors.bottom: parent.bottom
anchors.bottom: attachmentsSizeLabel.top
clip: true
spacing: 1
opacity: 1
......@@ -607,6 +658,20 @@ Item {
}
ScrollIndicator.vertical: ScrollIndicator {}
} // Listview
AccessibleText {
id: attachmentsSizeLabel
color: datovkaPalette.text
anchors.left: parent.left
anchors.leftMargin: defaultMargin
anchors.bottom: parent.bottom
anchors.bottomMargin: defaultMargin
anchors.right: parent.right
anchors.rightMargin: defaultMargin
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.Wrap
font.pointSize: textFontSizeSmall
text: qsTr("Total size of attachments is %1 B.").arg(totalAttachmentSizeBytes)
}
}
//----ADDITIONALS SECTION------------
Flickable {
......
......@@ -888,9 +888,9 @@ bool Files::parseAndShowXmlData(enum MsgInfo::ZfoType type, QString *idStr,
attachModel->appendFileEntry(
FileListModel::Entry(-1, document.fileDescr(),
approximateDataSize(document.binaryContent().size()),
getAttachmentFileIconFromFileExtension(
document.fileDescr()),
document.base64Content(), QString()));
getAttachmentFileIconFromFileExtension(document.fileDescr()),
document.base64Content(), document.binaryContent().size(),
QString()));
}
}
if (emailBody != Q_NULLPTR) {
......
/*
* Copyright (C) 2014-2017 CZ.NIC
* Copyright (C) 2014-2018 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
......@@ -8,7 +8,7 @@
*
* 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
* 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
......@@ -33,18 +33,20 @@ FileListModel::Entry::Entry(const Entry &fme)
m_dmFileSize(fme.m_dmFileSize),
m_icon(fme.m_icon),
m_fileContent(fme.m_fileContent),
m_fileSizeBytes(fme.m_fileSizeBytes),
m_filePath(fme.m_filePath)
{
}
FileListModel::Entry::Entry(const int fileId, const QString &dmFileDescr,
const QString &dmFileSize, const QString &icon, const QString &fileContent,
const QString &filePath)
qint64 fileSizeBytes, const QString &filePath)
: m_fileId(fileId),
m_dmFileDescr(dmFileDescr),
m_dmFileSize(dmFileSize),
m_icon(icon),
m_fileContent(fileContent),
m_fileSizeBytes(fileSizeBytes),
m_filePath(filePath)
{
}
......@@ -94,6 +96,16 @@ void FileListModel::Entry::setFileContent(const QString &fileContent)
m_fileContent = fileContent;
}
qint64 FileListModel::Entry::fileSizeBytes(void) const
{
return m_fileSizeBytes;
}
void FileListModel::Entry::setFileSizeBytes(qint64 fileSizeBytes)
{
m_fileSizeBytes = fileSizeBytes;
}
QString FileListModel::Entry::filePath(void) const
{
return m_filePath;
......@@ -136,6 +148,7 @@ QHash<int, QByteArray> FileListModel::roleNames(void) const
roles[ROLE_FILE_SIZE] = "rFileSize";
roles[ROLE_FILE_ICON] = "rFileIcon";
roles[ROLE_FILE_DATA] = "rFileContent";
roles[ROLE_FILE_SIZE_BYTES] = "rFileSizeBytes";
roles[ROLE_FILE_PATH] = "rFilePath";
}
return roles;
......@@ -165,6 +178,9 @@ QVariant FileListModel::data(const QModelIndex &index, int role) const
case ROLE_FILE_DATA:
return file.fileContent();
break;
case ROLE_FILE_SIZE_BYTES:
return file.fileSizeBytes();
break;
case ROLE_FILE_PATH:
return file.filePath();
break;
......@@ -196,6 +212,15 @@ QString FileListModel::filePathFromRow(int row)
return m_files[row].filePath();
}
qint64 FileListModel::fileSizeBytesFromRow(int row)
{
if ((row < 0) || (row >= m_files.size())) {
return 0;
}
return m_files[row].fileSizeBytes();
}
Qt::ItemFlags FileListModel::flags(const QModelIndex &index) const
{
return QAbstractListModel::flags(index);
......@@ -203,7 +228,7 @@ Qt::ItemFlags FileListModel::flags(const QModelIndex &index) const
void FileListModel::setQuery(QSqlQuery &query)
{
if (query.record().count() != 4) {
if (query.record().count() != 5) {
return;
}
......@@ -215,8 +240,9 @@ void FileListModel::setQuery(QSqlQuery &query)
while (query.isActive() && query.isValid()) {
m_files.append(Entry(query.value(0).toInt(),
query.value(1).toString(), query.value(2).toString(),
query.value(3).toString(), QString(), QString()));
query.value(3).toString(), QString(),
QByteArray::fromBase64(query.value(4).toByteArray()).size(),
QString()));
query.next();
}
......@@ -232,11 +258,12 @@ void FileListModel::appendFileEntry(const Entry &entry)
void FileListModel::appendFileFromPath(int fileId, const QString &fileName,
const QString &filePath, const QString &fileSize, const QString &fileIcon)
const QString &filePath, const QString &fileSize, const QString &fileIcon,
qint64 fileSizeBytes)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_files.append(FileListModel::Entry(fileId, fileName, fileSize,
fileIcon, QString(), filePath));
fileIcon, QString(), fileSizeBytes, filePath));
endInsertRows();
}
......
/*
* Copyright (C) 2014-2017 CZ.NIC
* Copyright (C) 2014-2018 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
......@@ -8,7 +8,7 @@
*
* 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
* 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
......@@ -21,8 +21,7 @@
* the two.
*/
#ifndef _FILEMODEL_H_
#define _FILEMODEL_H_
#pragma once
#include <QAbstractListModel>
#include <QSqlQuery>
......@@ -36,7 +35,8 @@ public:
Entry(const Entry &fme);
Entry(const int fileId, const QString &dmFileDescr,
const QString &dmFileSize, const QString &icon,
const QString &fileContent, const QString &filePath);
const QString &fileContent, qint64 fileSize,
const QString &filePath);
int fileId(void) const;
QString dmFileDescr(void) const;
......@@ -47,16 +47,19 @@ public:
void setIcon(const QString &icon);
QString fileContent(void) const;
void setFileContent(const QString &fileContent);
qint64 fileSizeBytes(void) const;
void setFileSizeBytes(qint64 fileSizeBytes);
QString filePath(void) const;
void setFilePath(const QString &filePath);
private:
int m_fileId; /*!< File database file identifier. */
QString m_dmFileDescr; /*!< File name. */
QString m_dmFileSize; /*!< File size. */
QString m_dmFileSize; /*!< File size qml string. */
QString m_icon; /*!< File icon? */
QString m_fileContent; /*!< File content */
QString m_filePath; /*!< File path */
QString m_fileContent; /*!< File content. */
qint64 m_fileSizeBytes; /*!< Real file size in bytes. */
QString m_filePath; /*!< File path. */
};
/*!
......@@ -68,6 +71,7 @@ public:
ROLE_FILE_SIZE,
ROLE_FILE_ICON,
ROLE_FILE_DATA,
ROLE_FILE_SIZE_BYTES,
ROLE_FILE_PATH
};
......@@ -137,6 +141,15 @@ public:
Q_INVOKABLE
QString filePathFromRow(int row);
/*!
* @brief Return real file size in bytes from attachment model.
*
* @param[in] row Row specifying the item.
* @return Real file size in bytes.
*/
Q_INVOKABLE
qint64 fileSizeBytesFromRow(int row);
/*!
* @brief Returns item flags for given index.
*
......@@ -168,11 +181,12 @@ public:
* @param[in] filePath File path.
* @param[in] fileSize File size.
* @param[in] fileIcon File icon.
* @param[in] fileSizeBytes Real file size in bytes.
*/
Q_INVOKABLE
void appendFileFromPath(int fileId, const QString &fileName,
const QString &filePath, const QString &fileSize,
const QString &fileIcon);
const QString &fileIcon, qint64 fileSizeBytes);
/*!
* @brief Clears the model.
......@@ -221,5 +235,3 @@ private:
/* QML passes its arguments via QVariant. */
Q_DECLARE_METATYPE(FileListModel)
#endif /* _FILEMODEL_H_ */
......@@ -107,16 +107,3 @@
* @brief ISDS filter value to download all messages (include long term storage).
*/
#define DOWNLOAD_ALL_MESSAGES 2046
/*!
* @brief Maximum attachment size in MB for message sending (ISDS 20 MB).
*/
#define SEND_ATTACH_SIZE_LIMIT_MB 20
/*!
* @brief Maximum attachment size in MB for message sending (ISDS OVM 50 MB).
*
* @note New ISDS message size limit is 50MB because some
* OVM databoxes can receive message up to 50MB.
*/
#define SEND_OVM_ATTACH_SIZE_LIMIT_MB 50
......@@ -748,33 +748,6 @@ void IsdsWrapper::sendMessage(const QString &userName, qint64 dmID,
envelope.setDmAttachmentSize(totalAttachmentSizeKBs);
/* Get total attachment in MB for error dialogue */
int totalAttachmentSizeMB = totalAttachmentSizeKBs / 1024;
/* Test if total attachment size is above the limit 50MB */
if (totalAttachmentSizeMB > SEND_OVM_ATTACH_SIZE_LIMIT_MB) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("%1: Large message").arg(userName),
tr("Total attachment size exceeds the limit!"),
tr("Total attachment size is %1 MB. ISDS limits its size to %2 MB. Reduce the total attachment size and try sending the message again.")
.arg(totalAttachmentSizeMB).arg(SEND_OVM_ATTACH_SIZE_LIMIT_MB)
);
return;
}
/* Test if total attachment size is larger then 20 MB */
if (totalAttachmentSizeMB >= SEND_ATTACH_SIZE_LIMIT_MB) {
int msgResponse = Dialogues::message(Dialogues::QUESTION,
tr("%1: Large message").arg(userName),
tr("Total size of attachments exceeds %1 MB. Most of the data boxes cannot receive messages larger than %1 MB. However, some OVM data boxes can receive message up to %2 MB.")
.arg(SEND_ATTACH_SIZE_LIMIT_MB).arg(SEND_OVM_ATTACH_SIZE_LIMIT_MB),
tr("Do you really want to send a such large message?"),
Dialogues::NO | Dialogues::YES, Dialogues::NO);
if (msgResponse == Dialogues::NO) {
return;
}
}
const QList<DataboxModelEntry> dbList = databoxModel->allEntries();
/* List of unique identifiers. */
......
......@@ -133,8 +133,8 @@ void FileDb::setFileModelFromDb(FileListModel &model, const qint64 dmId) const
{
QSqlQuery query(m_db);
QString queryStr = "SELECT id, dmFileDescr, _dmFileSize, _icon "
"FROM files WHERE dmID = :dmID";
QString queryStr = "SELECT id, dmFileDescr, _dmFileSize, "
"_icon, dmEncodedContent FROM files WHERE dmID = :dmID";
if (!query.prepare(queryStr)) {
logErrorNL("Cannot prepare SQL query: %s",
query.lastError().text().toUtf8().constData());
......
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