Commit 3e7af529 authored by Martin Straka's avatar Martin Straka

Updated send file model and qml

parent 1f3ce7cb
......@@ -53,12 +53,6 @@ Component {
property string emailBody
property int zfoType: MsgInfo.TYPE_UNKNOWN
/* Return file size string in bytes or kilobytes */
function getFileSizeString(fileSize) {
return (fileSize >= 1024) ? "~" + Math.ceil(fileSize / 1024) + " kB"
: "~" + (fileSize) + " B"
}
function setTopButtonVisibility() {
/* More than two visible icons causes problems on iOS devices. */
msgEmailButton.visible = !fromLocalDb && (attachmentList.count > 0)
......@@ -90,7 +84,7 @@ Component {
messages.markMessageAsLocallyRead(messageModel, userName, msgId, true)
msgDescrHtml = messages.getMessageDetail(userName, zfoId)
attachmentModel.setFromDb(userName, zfoId)
attachmentModel.setFromDb(userName, zfoId, false) // false = real file size won't calculate
zfoType = MsgInfo.TYPE_MESSAGE
}
emptyList.visible = (attachmentList.count === 0)
......@@ -314,7 +308,7 @@ Component {
Text {
id: filesizeid
anchors.left: parent.left
text: getFileSizeString(rFileSize)
text: rFileSize
color: datovkaPalette.mid
font.pointSize: textFontSizeSmall
renderType: Text.NativeRendering
......
......@@ -47,9 +47,9 @@ Item {
* 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_BYTES: 20971520 // = 20 * 1024 * 1024.
property int max_ATTACHMENT_SIZE_MB: 20
property int max_OVM_ATTACHMENT_SIZE_BYTES: 50000000 //50MB
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"
......@@ -146,7 +146,7 @@ Item {
dmRecipientRefNumber.text = isdsEnvelope.dmRecipientRefNumber
dmRecipientIdent.text = isdsEnvelope.dmRecipientIdent
setMandate(isdsEnvelope)
sendMsgAttachmentModel.setFromDb(userName, msgId)
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)
}
......@@ -163,8 +163,8 @@ Item {
// 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, files.getAttachmentFileIcon(fileName))
sendMsgAttachmentModel.appendFileFromPath(FileIdType.DB_ZFO_ID, 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)
......@@ -218,8 +218,8 @@ Item {
var fileSizeBytes = files.getAttachmentSizeInBytes(pathListModel.get(j).path)
totalAttachmentSizeBytes += fileSizeBytes;
sendMsgAttachmentModel.appendFileFromPath(FileIdType.NO_FILE_ID,
fileName, pathListModel.get(j).path, fileSizeBytes,
files.getAttachmentFileIcon(fileName))
fileName, pathListModel.get(j).path, getFileSizeString(fileSizeBytes),
files.getAttachmentFileIcon(fileName), fileSizeBytes)
}
}
pathListModel.clear()
......@@ -585,7 +585,7 @@ Item {
font.pointSize: textFontSizeSmall
}
Text {
text: getFileSizeString(rFileSize)
text: getFileSizeString(rFileSizeBytes)
color: datovkaPalette.mid
font.pointSize: textFontSizeSmall
}
......
......@@ -38,8 +38,8 @@ const QSet<QString> knowExp = QSet<QString> () <<
QString approximateDataSize(int dataSize)
{
QString str;
if (dataSize >= 1000) {
str = QLatin1String("~") + QString::number(dataSize / 1000) + QLatin1String(" kB");
if (dataSize >= 1024) {
str = QLatin1String("~") + QString::number(dataSize / 1024) + QLatin1String(" kB");
} else {
str = QLatin1String("~") + QString::number(dataSize) + QLatin1String(" B");
}
......@@ -50,8 +50,8 @@ QString getAttachmentFileIconFromFileExtension(const QString &fileName)
{
QString img("qrc:/fileicons/fileicon_blank.png");
QFileInfo fi(fileName);
const QString ext = fi.suffix();
ext.toLower();
QString ext = fi.suffix();
ext = ext.toLower();
if (!ext.isNull()) {
if (knowExp.contains(ext)) {
img = "qrc:/fileicons/fileicon_" + ext + ".png";
......
......@@ -526,7 +526,7 @@ MsgInfo *Files::zfoData(const QVariant &attachModelVariant,
}
bool Files::setAttachmentModel(FileListModel &attachModel,
const QString &userName, qint64 msgId)
const QString &userName, qint64 msgId, bool includeRealFileSize)
{
debugFuncCall();
......@@ -545,8 +545,14 @@ bool Files::setAttachmentModel(FileListModel &attachModel,
logErrorNL("%s", "Cannot access file database.");
return false;
}
attachModel.clearAll();
fDb->setFileModelFromDb(attachModel, msgId);
if (includeRealFileSize) {
fDb->setFileModelFromDbWithRealFileSize(attachModel, msgId);
} else {
fDb->setFileModelFromDb(attachModel, msgId);
}
return true;
}
......@@ -887,9 +893,10 @@ bool Files::parseAndShowXmlData(enum MsgInfo::ZfoType type, QString *idStr,
foreach (const Isds::Document &document, message.documents()) {
attachModel->appendFileEntry(
FileListModel::Entry(-1, document.fileDescr(),
document.binaryContent().size(),
approximateDataSize(document.binaryContent().size()),
getAttachmentFileIconFromFileExtension(document.fileDescr()),
document.base64Content(), QString()));
document.base64Content(), document.binaryContent().size(),
QString()));
}
}
if (emailBody != Q_NULLPTR) {
......
......@@ -238,11 +238,12 @@ public:
* @param[out] attachModel Attachment model to be set.
* @param[in] userName Identifies the account.
* @param[in] msgId Message identifier.
* @param[in] includeRealFileSize True if real file size will include in the model.
* @return True if success.
*/
static
bool setAttachmentModel(FileListModel &attachModel,
const QString &userName, qint64 msgId);
const QString &userName, qint64 msgId, bool includeRealFileSize);
/*!
* @brief Send attachment from ZFO with email application.
......
......@@ -30,21 +30,23 @@
FileListModel::Entry::Entry(const Entry &fme)
: m_fileId(fme.m_fileId),
m_dmFileDescr(fme.m_dmFileDescr),
m_fileSize(fme.m_fileSize),
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,
qint64 fileSize, const QString &icon, const QString &fileContent,
const QString &filePath)
const QString &dmFileSize, const QString &icon, const QString &fileContent,
qint64 fileSizeBytes, const QString &filePath)
: m_fileId(fileId),
m_dmFileDescr(dmFileDescr),
m_fileSize(fileSize),
m_dmFileSize(dmFileSize),
m_icon(icon),
m_fileContent(fileContent),
m_fileSizeBytes(fileSizeBytes),
m_filePath(filePath)
{
}
......@@ -64,14 +66,14 @@ void FileListModel::Entry::setDmFileDescr(const QString &dmFileDescr)
m_dmFileDescr = dmFileDescr;
}
qint64 FileListModel::Entry::fileSize(void) const
QString FileListModel::Entry::dmFileSize(void) const
{
return m_fileSize;
return m_dmFileSize;
}
void FileListModel::Entry::setFileSize(qint64 fileSize)
void FileListModel::Entry::setDmFileSize(const QString &dmFileSize)
{
m_fileSize = fileSize;
m_dmFileSize = dmFileSize;
}
QString FileListModel::Entry::icon(void) const
......@@ -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;
......@@ -157,7 +170,7 @@ QVariant FileListModel::data(const QModelIndex &index, int role) const
return file.dmFileDescr();
break;
case ROLE_FILE_SIZE:
return file.fileSize();
return file.dmFileSize();
break;
case ROLE_FILE_ICON:
return file.icon();
......@@ -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;
......@@ -202,7 +218,7 @@ qint64 FileListModel::fileSizeBytesFromRow(int row)
return 0;
}
return m_files[row].fileSize();
return m_files[row].fileSizeBytes();
}
Qt::ItemFlags FileListModel::flags(const QModelIndex &index) const
......@@ -223,9 +239,31 @@ void FileListModel::setQuery(QSqlQuery &query)
query.first();
while (query.isActive() && query.isValid()) {
m_files.append(Entry(query.value(0).toInt(),
query.value(1).toString(),
QByteArray::fromBase64(query.value(2).toByteArray()).size(),
query.value(3).toString(), QString(), QString()));
query.value(1).toString(), query.value(2).toString(),
query.value(3).toString(), QString(), 0, QString()));
query.next();
}
endResetModel();
}
void FileListModel::setQueryWithFileContent(QSqlQuery &query)
{
if (query.record().count() != 5) {
return;
}
beginResetModel();
m_files.clear();
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(),
QByteArray::fromBase64(query.value(4).toByteArray()).size(),
QString()));
query.next();
}
......@@ -241,11 +279,12 @@ void FileListModel::appendFileEntry(const Entry &entry)
void FileListModel::appendFileFromPath(int fileId, const QString &fileName,
const QString &filePath, qint64 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();
}
......@@ -265,7 +304,8 @@ FileListModel *FileListModel::fromVariant(const QVariant &modelVariant)
return qobject_cast<FileListModel *>(obj);
}
bool FileListModel::setFromDb(const QString &userName, const QString &msgIdStr)
bool FileListModel::setFromDb(const QString &userName, const QString &msgIdStr,
bool includeRealFileSize)
{
bool ok = false;
qint64 msgId = msgIdStr.toLongLong(&ok);
......@@ -273,7 +313,8 @@ bool FileListModel::setFromDb(const QString &userName, const QString &msgIdStr)
return false;
}
return Files::setAttachmentModel(*this, userName, msgId);
return Files::setAttachmentModel(*this, userName, msgId,
includeRealFileSize);
}
void FileListModel::removeItem(int row)
......
......@@ -34,27 +34,31 @@ public:
public:
Entry(const Entry &fme);
Entry(const int fileId, const QString &dmFileDescr,
qint64 fileSize, const QString &icon,
const QString &fileContent, const QString &filePath);
const QString &dmFileSize, const QString &icon,
const QString &fileContent, qint64 fileSize,
const QString &filePath);
int fileId(void) const;
QString dmFileDescr(void) const;
void setDmFileDescr(const QString &dmFileDescr);
qint64 fileSize(void) const;
void setFileSize(qint64 fileSize);
QString dmFileSize(void) const;
void setDmFileSize(const QString &dmFileSize);
QString icon(void) const;
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. */
qint64 m_fileSize; /*!< Real file size in bytes. */
QString m_dmFileSize; /*!< Approximate file size for qml. */
QString m_icon; /*!< File icon? */
QString m_fileContent; /*!< File content. */
qint64 m_fileSizeBytes; /*!< Real file size in bytes. */
QString m_filePath; /*!< File path. */
};
......@@ -67,6 +71,7 @@ public:
ROLE_FILE_SIZE,
ROLE_FILE_ICON,
ROLE_FILE_DATA,
ROLE_FILE_SIZE_BYTES,
ROLE_FILE_PATH
};
......@@ -155,12 +160,22 @@ public:
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
/*!
* @brief Sets the content of the model according to the supplied query.
* @brief Set the content of the model according to the supplied query.
*
* @param[in,out] query SQL query result.
*/
void setQuery(QSqlQuery &query);
/*!
* @brief Set the content of the model according to the supplied query.
*
* @note Real file size for model is calculated from file content.
* This method is slow and it is used in the send message page only.
*
* @param[in,out] query SQL query result.
*/
void setQueryWithFileContent(QSqlQuery &query);
/*!
* @brief Appends entry line to model.
*
......@@ -176,10 +191,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, qint64 fileSize, const QString &fileIcon);
const QString &filePath, const QString &fileSize,
const QString &fileIcon, qint64 fileSizeBytes);
/*!
* @brief Clears the model.
......@@ -209,10 +226,12 @@ public:
*
* @param[in] userName User name identifying account.
* @param[in] msgIdStr String containing message identifier.
* @param[in] includeRealFileSize True if real file size will include to model.
* @return True on success.
*/
Q_INVOKABLE
bool setFromDb(const QString &userName, const QString &msgIdStr);
bool setFromDb(const QString &userName, const QString &msgIdStr,
bool includeRealFileSize);
/*!
* @brief Remove file from attachment model.
......
......@@ -133,7 +133,7 @@ void FileDb::setFileModelFromDb(FileListModel &model, const qint64 dmId) const
{
QSqlQuery query(m_db);
QString queryStr = "SELECT id, dmFileDescr, dmEncodedContent, _icon "
QString queryStr = "SELECT id, dmFileDescr, _dmFileSize, _icon "
"FROM files WHERE dmID = :dmID";
if (!query.prepare(queryStr)) {
logErrorNL("Cannot prepare SQL query: %s",
......@@ -147,6 +147,25 @@ void FileDb::setFileModelFromDb(FileListModel &model, const qint64 dmId) const
}
}
void FileDb::setFileModelFromDbWithRealFileSize(FileListModel &model,
const qint64 dmId) const
{
QSqlQuery query(m_db);
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());
return;
}
query.bindValue(":dmID", dmId);
if (query.exec() && query.isActive()) {
model.setQueryWithFileContent(query);
}
}
Isds::Document FileDb::getFileFromDb(int fileId) const
{
QSqlQuery query(m_db);
......
......@@ -114,6 +114,15 @@ public:
*/
void setFileModelFromDb(FileListModel &model, qint64 dmId) const;
/*!
* @brief Set attachment model from db. Real file size will include in the model.
*
* @param[in,out] model Model to be set.
* @param[in] dmId Message Id.
*/
void setFileModelFromDbWithRealFileSize(FileListModel &model,
qint64 dmId) const;
/*!
* @brief Insert or update file data into files table.
*
......
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