Commit 2b4e7f55 authored by Karel Slaný's avatar Karel Slaný

Added FileListModel::dataSizeSum().

parent b3c24925
......@@ -98,7 +98,7 @@ Item {
return true
}
if (totalAttachmentSizeBytes >= 1024) {
attachmentsSizeLabel.text = qsTr("Total size of attachments is ~%1 KB.").arg(Math.ceil(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)
}
......@@ -147,9 +147,7 @@ Item {
dmRecipientIdent.text = isdsEnvelope.dmRecipientIdent
setMandate(isdsEnvelope)
sendMsgAttachmentModel.setFromDb(userName, msgId, true) // true = real file size will calculate from file content
for (var i = 0; i < sendMsgAttachmentModel.rowCount(); i++) {
totalAttachmentSizeBytes += sendMsgAttachmentModel.fileSizeBytesFromRow(i)
}
totalAttachmentSizeBytes = sendMsgAttachmentModel.dataSizeSum()
checkAttachmentSizes()
}
......@@ -162,8 +160,8 @@ 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, "", zfoSize)
totalAttachmentSizeBytes = sendMsgAttachmentModel.dataSizeSum()
} 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)
......@@ -215,9 +213,9 @@ 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, fileSizeBytes)
totalAttachmentSizeBytes = sendMsgAttachmentModel.dataSizeSum()
}
}
pathListModel.clear()
......@@ -611,8 +609,8 @@ Item {
}
MouseArea {
function handleClick() {
totalAttachmentSizeBytes -= sendMsgAttachmentModel.fileSizeBytesFromRow(index)
sendMsgAttachmentModel.removeItem(index)
totalAttachmentSizeBytes = sendMsgAttachmentModel.dataSizeSum()
}
anchors.fill: parent
......
......@@ -200,22 +200,23 @@ QList<FileListModel::Entry> FileListModel::allEntries(void) const
return entries;
}
QString FileListModel::filePathFromRow(int row)
QString FileListModel::filePathFromRow(int row) const
{
if ((row < 0) || (row >= m_files.size())) {
if (Q_UNLIKELY((row < 0) || (row >= m_files.size()))) {
Q_ASSERT(0);
return QString();
}
return m_files[row].filePath();
}
qint64 FileListModel::fileSizeBytesFromRow(int row)
qint64 FileListModel::dataSizeSum(void) const
{
if ((row < 0) || (row >= m_files.size())) {
return 0;
qint64 sum = 0;
foreach (const Entry &entry, m_files) {
sum += entry.fileSize();
}
return m_files[row].fileSize();
return sum;
}
Qt::ItemFlags FileListModel::flags(const QModelIndex &index) const
......
......@@ -132,16 +132,15 @@ public:
* @return File path string.
*/
Q_INVOKABLE
QString filePathFromRow(int row);
QString filePathFromRow(int row) const;
/*!
* @brief Return real file size in bytes from attachment model.
* @brief Compute the sum of sizes of all data.
*
* @param[in] row Row specifying the item.
* @return Real file size in bytes.
*/
Q_INVOKABLE
qint64 fileSizeBytesFromRow(int row);
qint64 dataSizeSum(void) const;
/*!
* @brief Returns item flags for given index.
......
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