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

Using Isds::Document::binaryContent() when appropriate.

Directly accessing raw data produces much lower overhead than conversion
from and to base64.
parent 8998579f
......@@ -35,14 +35,13 @@ const QSet<QString> knowExp = QSet<QString> () <<
"odt" << "pdf" << "png" << "ppt" << "pptx" << "rtf" << "tiff" <<
"txt" << "wav" << "xls" << "xlsx" << "xml" << "zfo";
QString getApproximatelyAttachmentFileSizeFromBase64(int base64Length)
QString approximateDataSize(int dataSize)
{
QString str = "";
base64Length = base64Length * 3 / 4;
if (base64Length >= 1000) {
str = "~" + QString::number(base64Length / 1000) + " kB" ;
QString str;
if (dataSize >= 1000) {
str = QLatin1String("~") + QString::number(dataSize / 1000) + QLatin1String(" kB");
} else {
str = "~" + QString::number(base64Length) + " B" ;
str = QLatin1String("~") + QString::number(dataSize) + QLatin1String(" B");
}
return str;
}
......
......@@ -21,18 +21,17 @@
* the two.
*/
#ifndef _ATTACHMENT_HELPER_H_
#define _ATTACHMENT_HELPER_H_
#pragma once
#include <QString>
/*!
* @brief Get aproximatle attachment file size from base64 length.
* @brief Get approximate data chunk size from supplied data size.
*
* @param[in] base64Length Base64 content length.
* @return Aproximatle file size string.
* @param[in] dataSize Actual data size.
* @return Approximate data size including the unit.
*/
QString getApproximatelyAttachmentFileSizeFromBase64(int base64Length);
QString approximateDataSize(int dataSize);
/*!
* @brief Get attachment icon from attachment file extension.
......@@ -41,5 +40,3 @@ QString getApproximatelyAttachmentFileSizeFromBase64(int base64Length);
* @return Attachment icon filename string.
*/
QString getAttachmentFileIconFromFileExtension(const QString &fileName);
#endif /* _ATTACHMENT_HELPER_H_ */
......@@ -147,7 +147,7 @@ QByteArray Files::getFileRawContentFromDb(const QString &userName, int fileId)
return QByteArray();
}
return base64ToRaw(fDb->getFileFromDb(fileId).base64Content().toUtf8());
return fDb->getFileFromDb(fileId).binaryContent();
}
void Files::openAttachmentFromDb(const QString &userName, int fileId)
......@@ -170,7 +170,7 @@ void Files::openAttachmentFromDb(const QString &userName, int fileId)
return;
}
Isds::Document document = fDb->getFileFromDb(fileId);
Isds::Document document(fDb->getFileFromDb(fileId));
openAttachment(document.fileDescr(), document.base64Content().toUtf8());
}
......@@ -302,7 +302,7 @@ void Files::sendMsgFilesWithEmail(const QString &userName, qint64 msgId,
Isds::Document document;
document.setBase64Content(GlobInstcs::zfoDbPtr->getZfoContentFromDb(
msgId, (*GlobInstcs::acntMapPtr)[userName].isTestAccount()));
if (document.base64Content().isEmpty()) {
if (document.binaryContent().isEmpty()) {
qCritical("Missing zfo data for message '%s'.",
QString::number(msgId).toUtf8().constData());
Dialogues::errorMessage(Dialogues::CRITICAL,
......@@ -331,7 +331,7 @@ void Files::sendMsgFilesWithEmail(const QString &userName, qint64 msgId,
return;
}
fileName = writeFile(targetPath, fileName,
base64ToRaw(document.base64Content().toUtf8()));
document.binaryContent());
filePathList.append(fileName);
addAttachmentToEmailMessage(emailMessage, document.fileDescr(),
document.base64Content().toUtf8(), boundary);
......@@ -642,7 +642,7 @@ void Files::saveMsgFilesToDisk(const QString &userName,
Isds::Document document;
document.setBase64Content(GlobInstcs::zfoDbPtr->getZfoContentFromDb(
msgId, (*GlobInstcs::acntMapPtr)[userName].isTestAccount()));
if (document.base64Content().isEmpty()) {
if (document.binaryContent().isEmpty()) {
qCritical("Missing zfo data for message '%s'.",
QString::number(msgId).toUtf8().constData());
Dialogues::errorMessage(Dialogues::CRITICAL,
......@@ -661,7 +661,7 @@ void Files::saveMsgFilesToDisk(const QString &userName,
QString destPath;
foreach (const Isds::Document &document, documents) {
destPath = writeFile(filePath, document.fileDescr(),
base64ToRaw(document.base64Content().toUtf8()));
document.binaryContent());
}
attachmentSavingNotification(destPath);
......@@ -904,8 +904,7 @@ bool Files::parseAndShowXmlData(enum MsgInfo::ZfoType type, QString *idStr,
foreach (const Isds::Document &document, message.documents()) {
attachModel->appendFileEntry(
FileListModel::Entry(-1, document.fileDescr(),
getApproximatelyAttachmentFileSizeFromBase64(
document.base64Content().length()),
approximateDataSize(document.binaryContent().size()),
getAttachmentFileIconFromFileExtension(
document.fileDescr()),
document.base64Content(), QString()));
......
......@@ -26,8 +26,8 @@
#include "src/auxiliaries/attachment_helper.h"
#include "src/datovka_shared/isds/message_interface.h"
#include "src/datovka_shared/isds/types.h"
#include "src/datovka_shared/isds/type_conversion.h"
#include "src/datovka_shared/isds/types.h"
#include "src/datovka_shared/utility/strings.h"
#include "src/datovka_shared/worker/pool.h"
#include "src/dialogues/dialogues.h"
......@@ -676,15 +676,13 @@ void IsdsWrapper::sendMessage(const QString &userName, qint64 dmID,
// load file content from database, valid file ID
document = fDb->getFileFromDb(file.fileId());
document.setFileMetaType(fileMetaType);
totalAttachmentSizeKBs += document.base64Content().length() / 1024;
totalAttachmentSizeKBs += document.binaryContent().size() / 1024;
} else if (file.fileId() == Files::DB_ZFO_ID) {
// load zfo content from zfo database
document.setBase64Content(
GlobInstcs::zfoDbPtr->getZfoContentFromDb(dmID,
(*GlobInstcs::acntMapPtr)[userName].isTestAccount()));
QByteArray binData = QByteArray::fromBase64(
document.base64Content().toUtf8());
totalAttachmentSizeKBs += binData.length() / 1024;
totalAttachmentSizeKBs += document.binaryContent().size() / 1024;
GlobInstcs::zfoDbPtr->updateZfoLastAccessTime(dmID,
(*GlobInstcs::acntMapPtr)[userName].isTestAccount());
} else if (!file.filePath().isEmpty()) {
......@@ -698,7 +696,7 @@ void IsdsWrapper::sendMessage(const QString &userName, qint64 dmID,
file.filePath());
return;
}
document.setBase64Content(fin.readAll().toBase64());
document.setBinaryContent(fin.readAll());
} else {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), tr("No file to sending."),
......
/*
* 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
......
/*
* 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
......@@ -21,8 +21,7 @@
* the two.
*/
#ifndef _MESSAGE_ENVELOPE_H_
#define _MESSAGE_ENVELOPE_H_
#pragma once
#include <QObject>
#include <QString>
......@@ -267,5 +266,3 @@ private:
/* QML passes its arguments via QVariant. */
Q_DECLARE_METATYPE(MsgEnvelope)
#endif /* _MESSAGE_ENVELOPE_H_ */
......@@ -274,8 +274,7 @@ bool FileDb::insertUpdateFileIntoDb(qint64 dmId, const Isds::Document &document)
Isds::m_fileMetaType2Variant(document.fileMetaType()));
query.bindValue(":dmEncodedContent", document.base64Content());
query.bindValue(":_dmFileSize",
getApproximatelyAttachmentFileSizeFromBase64(
document.base64Content().length()));
approximateDataSize(document.binaryContent().size()));
query.bindValue(":_dmDownloadDate",
QDate::currentDate().toString(DATE_DB_FORMAT));
query.bindValue(":_icon",
......
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