Commit bf664a6f authored by Karel Slaný's avatar Karel Slaný

Merge branch 'attachment-size' into 'develop'

Show total attachment size in the send qml page

Closes #132

See merge request !138
parents 08e2e5b6 4612d10c
......@@ -89,7 +89,6 @@ TRANSLATIONS_FILES += \
SOURCES += \
src/accounts.cpp \
src/auxiliaries/attachment_helper.cpp \
src/auxiliaries/email_helper.cpp \
src/datovka_shared/gov_services/helper.cpp \
src/datovka_shared/gov_services/service/gov_mv_crr_vbh.cpp \
......@@ -211,7 +210,6 @@ SOURCES += \
HEADERS += \
src/accounts.h \
src/auxiliaries/attachment_helper.h \
src/auxiliaries/email_helper.h \
src/common.h \
src/datovka_shared/gov_services/helper.h \
......
......@@ -57,7 +57,7 @@ Component {
/* More than two visible icons causes problems on iOS devices. */
msgEmailButton.visible = !fromLocalDb && (attachmentList.count > 0)
attachmentSaveButon.visible = !fromLocalDb && (attachmentList.count > 0)
msgDownloadButton.visible = fromLocalDb && (attachmentList.count == 0)
msgDownloadButton.visible = fromLocalDb && (attachmentList.count === 0)
attachmentMenuButon.visible = fromLocalDb && (attachmentList.count > 0)
}
......@@ -87,7 +87,7 @@ Component {
attachmentModel.setFromDb(userName, zfoId)
zfoType = MsgInfo.TYPE_MESSAGE
}
emptyList.visible = (attachmentList.count == 0)
emptyList.visible = (attachmentList.count === 0)
setTopButtonVisibility()
}
......@@ -276,7 +276,7 @@ Component {
interactive: true
model: attachmentModel
onCountChanged: {
emptyList.visible = (attachmentList.count == 0)
emptyList.visible = (attachmentList.count === 0)
setTopButtonVisibility()
}
delegate: Rectangle {
......@@ -289,7 +289,7 @@ Component {
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
sourceSize.height: imgHeightHeader * 1.2
source: rFileIcon
source: files.getAttachmentFileIcon(rFileName)
}
Item {
anchors.left: imageAttachment.right
......@@ -308,7 +308,7 @@ Component {
Text {
id: filesizeid
anchors.left: parent.left
text: rFileSize
text: rFileSizeStr
color: datovkaPalette.mid
font.pointSize: textFontSizeSmall
renderType: Text.NativeRendering
......@@ -343,7 +343,7 @@ Component {
console.log("Attachment is ZFO: " + rFileName)
var fileContent = null
if (!fromLocalDb) {
fileContent = files.base64ToRaw(rFileContent)
fileContent = rBinaryContent
} else {
fileContent = files.getFileRawContentFromDb(userName, rFileId)
}
......@@ -355,7 +355,7 @@ Component {
})
} else {
if (!fromLocalDb) {
files.openAttachment(rFileName, rFileContent)
files.openAttachment(rFileName, rBinaryContent)
} else {
files.openAttachmentFromDb(userName, rFileId)
}
......
......@@ -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,21 @@ 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: 20971520 // = 20 * 1024 * 1024.
property int max_ATTACHMENT_SIZE_MB: 20
property int max_OVM_ATTACHMENT_SIZE_BYTES: 52428800 // = 50 * 1024 * 1024.
property int max_OVM_ATTACHMENT_SIZE_MB: 50
property string text_COLOR_RED: "#ff0000"
/* 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
......@@ -53,10 +68,35 @@ Item {
return filePath.replace(/^.*[\\\/]/, '')
}
/* Return file size string in bytes or kilobytes */
function getFileSizeString(fileSize) {
return (fileSize >= 1000) ? "~" + Math.ceil(fileSize / 1000) + " kB"
: "~" + (fileSize) + " B"
/* Check attachment number ans size. */
function attachmentSizeOk() {
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 = text_COLOR_RED
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 = text_COLOR_RED
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 = text_COLOR_RED
return true
}
if (totalAttachmentSizeBytes >= 1024) {
attachmentsSizeLabel.text = qsTr("Total size of attachments is ~%1 kB.").arg(Math.round(totalAttachmentSizeBytes/1024))
} else {
attachmentsSizeLabel.text = qsTr("Total size of attachments is %1 B.").arg(totalAttachmentSizeBytes)
}
return true
}
/* Set mandate fields in QML */
......@@ -101,6 +141,8 @@ Item {
dmRecipientIdent.text = isdsEnvelope.dmRecipientIdent
setMandate(isdsEnvelope)
sendMsgAttachmentModel.setFromDb(userName, msgId)
totalAttachmentSizeBytes = sendMsgAttachmentModel.dataSizeSum()
attachmentSizeOk()
}
/* Set message forward data and add ZFO file to model */
......@@ -112,8 +154,8 @@ Item {
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))
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)
......@@ -164,10 +206,10 @@ Item {
}
if (!isInFiletList) {
var fileName = getFileNameFromPath(pathListModel.get(j).path)
var fileSizeBytes = files.getAttachmentSizeInBytes(pathListModel.get(j).path)
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, fileSizeBytes)
totalAttachmentSizeBytes = sendMsgAttachmentModel.dataSizeSum()
}
}
pathListModel.clear()
......@@ -246,7 +288,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 = (attachmentSizeOk() && (dmAnnotation.text.toString() !== "") && (recipBoxModel.rowCount() > 0))
}
TabBar {
......@@ -511,7 +553,7 @@ Item {
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
sourceSize.height: attachmentListSend.delegateHeight * 0.8
source: rFileIcon
source: files.getAttachmentFileIcon(rFileName)
}
Item {
anchors.left: imageAttachment.right
......@@ -533,7 +575,7 @@ Item {
font.pointSize: textFontSizeSmall
}
Text {
text: rFileSize
text: rFileSizeStr
color: datovkaPalette.mid
font.pointSize: textFontSizeSmall
}
......@@ -562,6 +604,7 @@ Item {
MouseArea {
function handleClick() {
sendMsgAttachmentModel.removeItem(index)
totalAttachmentSizeBytes = sendMsgAttachmentModel.dataSizeSum()
}
anchors.fill: parent
......@@ -586,12 +629,26 @@ Item {
}
} // Rectangle
} // Component
AccessibleText {
id: attachmentsSizeLabel
color: datovkaPalette.text
anchors.left: parent.left
anchors.leftMargin: defaultMargin
anchors.top: addFile.bottom
anchors.topMargin: 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)
}
ScrollableListView {
id: attachmentListSend
delegateHeight: listItemHeight
anchors.top: addFile.bottom
anchors.top: attachmentsSizeLabel.bottom
anchors.bottom: parent.bottom
clip: true
spacing: 1
......
/*
* 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
* 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.
*/
#include <QFileInfo>
#include <QSet>
#include "src/auxiliaries/attachment_helper.h"
/*
* There is list of know file extension sufixes. For these we have png images.
*/
const QSet<QString> knowExp = QSet<QString> () <<
"avi" << "bmp" << "doc" << "docx" << "dwg" << "gif" << "html" <<
"htm" << "jpeg" << "jpg" << "mpeg" << "mpg" << "mp3" << "ods" <<
"odt" << "pdf" << "png" << "ppt" << "pptx" << "rtf" << "tiff" <<
"txt" << "wav" << "xls" << "xlsx" << "xml" << "zfo";
QString approximateDataSize(int dataSize)
{
QString str;
if (dataSize >= 1000) {
str = QLatin1String("~") + QString::number(dataSize / 1000) + QLatin1String(" kB");
} else {
str = QLatin1String("~") + QString::number(dataSize) + QLatin1String(" B");
}
return str;
}
QString getAttachmentFileIconFromFileExtension(const QString &fileName)
{
QString img("qrc:/fileicons/fileicon_blank.png");
QFileInfo fi(fileName);
const QString ext = fi.suffix();
ext.toLower();
if (!ext.isNull()) {
if (knowExp.contains(ext)) {
img = "qrc:/fileicons/fileicon_" + ext + ".png";
}
}
return img;
}
/*
* 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
* 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.
*/
#pragma once
#include <QString>
/*!
* @brief Get approximate data chunk size from supplied data size.
*
* @param[in] dataSize Actual data size.
* @return Approximate data size including the unit.
*/
QString approximateDataSize(int dataSize);
/*!
* @brief Get attachment icon from attachment file extension.
*
* @param[in] fileName Attachment filename with extension.
* @return Attachment icon filename string.
*/
QString getAttachmentFileIconFromFileExtension(const QString &fileName);
......@@ -24,9 +24,9 @@
#include <QDesktopServices>
#include <QFileInfo>
#include <QQmlEngine>
#include <QStringBuilder>
#include "ios/src/url_opener.h"
#include "src/auxiliaries/attachment_helper.h"
#include "src/auxiliaries/email_helper.h"
#include "src/common.h"
#include "src/crypto/crypto.h"
......@@ -118,7 +118,18 @@ void Files::deleteExpiredFilesFromDbs(int days)
QString Files::getAttachmentFileIcon(const QString &fileName)
{
return getAttachmentFileIconFromFileExtension(fileName);
/* List of know file extension sufixes. For these we have png images. */
static const QSet<QString> knowExp(QSet<QString> () <<
"avi" << "bmp" << "doc" << "docx" << "dwg" << "gif" << "html" <<
"htm" << "jpeg" << "jpg" << "mpeg" << "mpg" << "mp3" << "ods" <<
"odt" << "pdf" << "png" << "ppt" << "pptx" << "rtf" << "tiff" <<
"txt" << "wav" << "xls" << "xlsx" << "xml" << "zfo");
const QString ext(QFileInfo(fileName).suffix().toLower());
if ((!ext.isEmpty()) && knowExp.contains(ext)) {
return QStringLiteral("qrc:/fileicons/fileicon_") % ext % QStringLiteral(".png");
}
return QStringLiteral("qrc:/fileicons/fileicon_blank.png");
}
qint64 Files::getAttachmentSizeInBytes(const QString &filePath)
......@@ -174,17 +185,15 @@ void Files::openAttachmentFromDb(const QString &userName, int fileId)
Isds::Document document(fDb->getFileFromDb(fileId));
openAttachment(document.fileDescr(), document.base64Content().toUtf8());
openAttachment(document.fileDescr(), document.binaryContent());
}
void Files::openAttachment(const QString &fileName,
const QByteArray &base64Data)
const QByteArray &binaryData)
{
Q_ASSERT(!fileName.isEmpty());
Q_ASSERT(!base64Data.isEmpty());
if (fileName.isEmpty() || base64Data.isEmpty()) {
if (Q_UNLIKELY(fileName.isEmpty() || binaryData.isEmpty())) {
logErrorNL("%s", "File name or its content is empty.");
Q_ASSERT(0);
return;
}
......@@ -195,8 +204,7 @@ void Files::openAttachment(const QString &fileName,
return;
}
QString filePath(writeFile(appTmpDirPath(), fileName,
base64ToRaw(base64Data)));
QString filePath(writeFile(appTmpDirPath(), fileName, binaryData));
if (!filePath.isEmpty()) {
logInfoNL("Creating temporary file '%s'.",
......@@ -419,7 +427,7 @@ void Files::vacuumFileDbs(void)
userName.toUtf8().constData());
return;
}
fDb->vacuumFileDb();
fDb->vacuum();
}
emit statusBarTextChanged(tr("Operation Vacuum has finished"), false);
......@@ -504,11 +512,6 @@ QByteArray Files::rawFileContent(const QString &filePath)
return rawData;
}
QByteArray Files::base64ToRaw(const QByteArray &base64Data)
{
return QByteArray::fromBase64(base64Data);
}
MsgInfo *Files::zfoData(const QVariant &attachModelVariant,
const QByteArray &rawZfoData)
{
......@@ -582,18 +585,17 @@ void Files::sendAttachmentEmailZfo(const QVariant &attachModelVariant,
for (int row = 0; row < attachModel->rowCount(); ++row) {
QModelIndex idx(attachModel->index(row));
/*
* On Android the attachment must be saved and the explicitly
* add into the email message.
* On Android the attachment must be saved and then explicitly
* added into the email message.
*/
QByteArray base64Data(attachModel->data(idx,
FileListModel::ROLE_FILE_DATA).toByteArray());
QByteArray binaryData(
attachModel->data(idx, FileListModel::ROLE_BINARY_DATA).toByteArray());
QString attachName(attachModel->data(idx,
FileListModel::ROLE_FILE_NAME).toString());
QString filePath(writeFile(targetPath, attachName,
base64ToRaw(base64Data)));
QString filePath(writeFile(targetPath, attachName, binaryData));
fileList.append(filePath);
addAttachmentToEmailMessage(emailMessage, attachName,
base64Data, boundary);
binaryData.toBase64(), boundary);
}
finishEmailMessage(emailMessage, boundary);
......@@ -699,8 +701,8 @@ void Files::saveAttachmentsToDiskZfo(const QVariant &attachModelVariant,
QModelIndex idx(attachModel->index(row));
destPath = writeFile(targetPath, attachModel->data(idx,
FileListModel::ROLE_FILE_NAME).toString(),
base64ToRaw(attachModel->data(idx,
FileListModel::ROLE_FILE_DATA).toByteArray()));
attachModel->data(idx,
FileListModel::ROLE_BINARY_DATA).toByteArray());
}
attachmentSavingNotification(destPath);
......@@ -887,10 +889,8 @@ bool Files::parseAndShowXmlData(enum MsgInfo::ZfoType type, QString *idStr,
foreach (const Isds::Document &document, message.documents()) {
attachModel->appendFileEntry(
FileListModel::Entry(-1, document.fileDescr(),
approximateDataSize(document.binaryContent().size()),
getAttachmentFileIconFromFileExtension(
document.fileDescr()),
document.base64Content(), QString()));
document.binaryContent(), document.binaryContent().size(),
QString()));
}
}
if (emailBody != Q_NULLPTR) {
......
......@@ -128,11 +128,11 @@ public:
* @brief Open attachment in default application.
*
* @param[in] fileName File name.
* @param[in] base64Data File content base64.
* @param[in] binaryData Raw file content.
*/
Q_INVOKABLE static
void openAttachment(const QString &fileName,
const QByteArray &base64Data);
const QByteArray &binaryData);
/*!
* @brief Open attachment from path in default application.
......@@ -205,15 +205,6 @@ public:
Q_INVOKABLE static
QByteArray rawFileContent(const QString &filePath);
/*!
* @brief Decodes base64-encoded content.
*
* @param[in] base64Data Base64-encoded data.
* @return Raw data.
*/
Q_INVOKABLE static
QByteArray base64ToRaw(const QByteArray &base64Data);
/*!
* @brief Parse content of ZFO file.
*
......
<
/*
* 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
......@@ -23,28 +23,26 @@
#include <QQmlEngine> /* qmlRegisterType */
#include <QSqlRecord>
#include <QStringBuilder>
#include "src/files.h" /* TODO -- Do something with it. */
#include "src/models/filemodel.h"
FileListModel::Entry::Entry(const Entry &fme)
: m_fileId(fme.m_fileId),
m_dmFileDescr(fme.m_dmFileDescr),
m_dmFileSize(fme.m_dmFileSize),
m_icon(fme.m_icon),
m_fileContent(fme.m_fileContent),
m_filePath(fme.m_filePath)
FileListModel::Entry::Entry(const Entry &other)
: m_fileId(other.m_fileId),
m_fileName(other.m_fileName),
m_data(other.m_data),
m_fileSize(other.m_fileSize),
m_filePath(other.m_filePath)
{
}
FileListModel::Entry::Entry(const int fileId, const QString &dmFileDescr,
const QString &dmFileSize, const QString &icon, const QString &fileContent,
const QString &filePath)
FileListModel::Entry::Entry(const int fileId, const QString &fileName,
const QByteArray &data, qint64 fileSize, const QString &filePath)
: m_fileId(fileId),
m_dmFileDescr(dmFileDescr),
m_dmFileSize(dmFileSize),
m_icon(icon),
m_fileContent(fileContent),
m_fileName(fileName),
m_data(data),
m_fileSize(fileSize),
m_filePath(filePath)
{
}
......@@ -54,47 +52,65 @@ int FileListModel::Entry::fileId(void) const
return m_fileId;
}
QString FileListModel::Entry::dmFileDescr(void) const
const QString &FileListModel::Entry::fileName(void) const
{
return m_dmFileDescr;
return m_fileName;
}
void FileListModel::Entry::setDmFileDescr(const QString &dmFileDescr)
void FileListModel::Entry::setFileName(const QString &fileName)
{
m_dmFileDescr = dmFileDescr;
m_fileName = fileName;
}
QString FileListModel::Entry::dmFileSize(void) const
/*!
* @brief Creates human readable size description string.
*
* @param[in] dataSize Size in bytes.
* @return String containing units.
*/
static
QString approximateDataSize(qint64 dataSize)
{
return m_dmFileSize;
if (dataSize >= 1024) {
qint64 kBytes = dataSize >> 10; /* dataSize / 1024 */
/* (dataSize % 1024) >= 512 -> increase dicision by 1 */
kBytes += (dataSize & 0x0200) ? 1 : 0; /* round((float)(dataSize / 1024)) */
return QStringLiteral("~") % QString::number(kBytes) % QStringLiteral(" kB");
} else {
return QStringLiteral("~") % QString::number(dataSize) % QStringLiteral(" B");
}
}
void FileListModel::Entry::setDmFileSize(const QString &dmFileSize)
QString FileListModel::Entry::fileSizeStr(void) const
{
m_dmFileSize = dmFileSize;
if (m_fileSize >= 0) {
return approximateDataSize(m_fileSize);
} else {
return QString();
}
}
QString FileListModel::Entry::icon(void) const
const QByteArray &FileListModel::Entry::binaryContent(void) const
{
return m_icon;
return m_data;
}
void FileListModel::Entry::setIcon(const QString &icon)
void FileListModel::Entry::setBinaryContent(const QByteArray &data)
{
m_icon = icon;
m_data = data;
}
QString FileListModel::Entry::fileContent(void) const
qint64 FileListModel::Entry::fileSize(void) const
{
return m_fileContent;
return m_fileSize;
}
void FileListModel::Entry::setFileContent(const QString &fileContent)
void FileListModel::Entry::setFileSize(qint64 fileSize)
{
m_fileContent = fileContent;
m_fileSize = fileSize;
}
QString FileListModel::Entry::filePath(void) const
const QString &FileListModel::Entry::filePath(void) const
{
return m_filePath;
}
......@@ -133,9 +149,9 @@ QHash<int, QByteArray> FileListModel::roleNames(void) const
if (roles.isEmpty()) {
roles[ROLE_FILE_ID] = "rFileId";
roles[ROLE_FILE_NAME] = "rFileName";
roles[ROLE_FILE_SIZE] = "rFileSize";
roles[ROLE_FILE_ICON] = "rFileIcon";
roles[ROLE_FILE_DATA] = "rFileContent";
roles[ROLE_FILE_SIZE_STR] = "rFileSizeStr";
roles[ROLE_BINARY_DATA] = "rBinaryContent";
roles[ROLE_FILE_SIZE_BYTES] = "rFileSizeBytes";
roles[ROLE_FILE_PATH] = "rFilePath";
}
return roles;
......@@ -154,16 +170,16 @@ QVariant FileListModel::data(const QModelIndex &index, int role) const
return file.fileId();
break;
case ROLE_FILE_NAME:
return file.dmFileDescr();
return file.fileName();
break;
case ROLE_FILE_SIZE:
return file.dmFileSize();
case ROLE_FILE_SIZE_STR:
return file.fileSizeStr();
break;
case ROLE_FILE_ICON:
return file.icon();
case ROLE_BINARY_DATA:
return file.binaryContent();
break;
case ROLE_FILE_DATA:
return file.fileContent();
case ROLE_FILE_SIZE_BYTES:
return file.fileSize();
break;
case ROLE_FILE_PATH:
return file.filePath();
......@@ -187,15 +203,25 @@ 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::dataSizeSum(void) const
{
qint64 sum = 0;
foreach (const Entry &entry, m_files) {
sum += entry.fileSize();
}
return sum;
}
Qt::ItemFlags FileListModel::flags(const QModelIndex &index) const
{
return QAbstractListModel::flags(index);
......@@ -203,7 +229,7 @@ Qt::ItemFlags FileListModel::flags(const QModelIndex &index) const
void FileListModel::setQuery(QSqlQuery &query)
{
if (query.record().count() != 4) {
if (query.record().count() != 3) {
return;
}
......@@ -214,9 +240,8 @@ void FileListModel::setQuery(QSqlQuery &query)
query.first();
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(1).toString(), QByteArray(),
query.value(2).toLongLong(), QString()));
query.next();
}
......@@ -230,13 +255,12 @@ void FileListModel::appendFileEntry(const Entry &entry)
endInsertRows();
}
void FileListModel::appendFileFromPath(int fileId, const QString &fileName,
const QString &filePath, const QString &fileSize, const QString &fileIcon)