Commit a64b9095 authored by Martin Straka's avatar Martin Straka

Updated code for using of new attachnemt data class

parent 4f746e5e
......@@ -37,6 +37,7 @@
#include "src/io/filesystem.h"
#include "ios/src/url_opener.h"
#include "src/models/accountmodel.h"
#include "src/qml_interaction/attachment_data.h"
#include "src/qml_interaction/message_envelope.h"
#include "src/sqlite/file_db_container.h"
#include "src/sqlite/message_db_container.h"
......@@ -141,13 +142,13 @@ Files::Files(QObject *parent) : QObject(parent)
*/
static
void setZfoFilesToModel(FileListModel &model,
const QList<Files::File> &fileList)
const QList<AttachmentData> &fileList)
{
model.clearAll();
foreach (const Files::File &file, fileList) {
model.appendFileEntry(FileListModel::Entry(-1, file.dmFileDescr,
file._dmFileSize, file._icon, file.dmEncodedContent));
foreach (const AttachmentData &file, fileList) {
model.appendFileEntry(FileListModel::Entry(-1, file.dmFileDescr(),
file._dmFileSize(), file._icon(), file.dmEncodedContent()));
}
}
......@@ -875,7 +876,7 @@ bool Files::parseAndShowXmlData(enum MsgInfo::ZfoType type, QString *idStr,
QXmlStreamReader xml;
XmlLayer xmlLayer;
MsgEnvelope msg;
QList<Files::File> fileList;
QList<AttachmentData> fileList;
QList<Messages::Event> eventList;
if (type == MsgInfo::TYPE_UNKNOWN) {
......
......@@ -248,30 +248,6 @@ public:
Q_INVOKABLE
void deleteTmpFileFromStorage(const QString &filePath);
class File {
public:
File(void)
: id (-1), dmID(-1), dmFileDescr(), dmUpFileGuid(),
dmFileGuid(), dmMimeType(), dmFormat(), dmFileMetaType(),
dmEncodedContent(), _dmFileSize(), _dmDownloadDate(),
_icon()
{
}
int id;
qint64 dmID;
QString dmFileDescr;
QString dmUpFileGuid;
QString dmFileGuid;
QString dmMimeType;
QString dmFormat;
QString dmFileMetaType;
QString dmEncodedContent;
QString _dmFileSize;
QString _dmDownloadDate;
QString _icon;
};
signals:
/*!
* @brief Set new statusbar text and active busy indicator to QML.
......
......@@ -184,7 +184,7 @@ bool DbWrapper::insertMessageListToDb(const QString &userName,
}
bool DbWrapper::insertCompleteMessageToDb(const QString &userName,
MsgEnvelope &msg, QList<Files::File> &fileList, QString &txt)
MsgEnvelope &msg, QList<AttachmentData> &fileList, QString &txt)
{
bool ret = true;
......@@ -201,7 +201,7 @@ bool DbWrapper::insertCompleteMessageToDb(const QString &userName,
for (int i = 0; i < fileList.count(); ++i) {
if (!fDb->insertUpdateFilesIntoDb(fileList.at(i))) {
txt = tr("File %1 insertion failed!").
arg(fileList.at(i).dmFileDescr);
arg(fileList.at(i).dmFileDescr());
ret = ret * false;
}
}
......
......@@ -140,7 +140,7 @@ public:
* @return true if success.
*/
bool insertCompleteMessageToDb(const QString &userName,
MsgEnvelope &msg, QList<Files::File> &fileList,
MsgEnvelope &msg, QList<AttachmentData> &fileList,
QString &txt);
/*!
......
......@@ -483,23 +483,20 @@ void IsdsWrapper::sendMessage(const QString &userName,
msg.setDmPersonalDelivery(dmPersonalDelivery);
int totalAttachmentSizeKBs = 0;
QList<Files::File> attachList;
QList<AttachmentData> attachList;
/* Load file contents from storage (path) to file structure */
foreach (const QString &file, filePaths) {
Files::File attach;
AttachmentData attach;
QFileInfo fi(file);
attach.dmFileDescr = fi.fileName();
attach.setDmFileDescr(fi.fileName());
totalAttachmentSizeKBs += fi.size() / 1024;
QFile fin(file);
if (!fin.open(QIODevice::ReadOnly)) {
continue;
}
attach.dmEncodedContent = fin.readAll().toBase64();
attach._dmFileSize =
getApproximatelyAttachmentFileSizeFromBase64(
attach.dmEncodedContent.length());
attach._icon =
getAttachmentFileIconFromFileExtension(attach.dmFileDescr);
attach.setDmEncodedContent(fin.readAll().toBase64());
attach._setDmFileSize(getApproximatelyAttachmentFileSizeFromBase64(attach.dmEncodedContent().length()));
attach._setIcon(getAttachmentFileIconFromFileExtension(attach.dmFileDescr()));
attachList.append(attach);
}
......
......@@ -224,7 +224,7 @@ QByteArray XmlLayer::xmlCreateMarkMessageAsDownloadedSoapRequest(qint64 msgId)
}
QByteArray XmlLayer::xmlCreateSendMessageSoapRequest(const MsgEnvelope &msg,
const QList<Files::File> &fileList, bool dmOVM, bool dmPublishOwnID)
const QList<AttachmentData> &fileList, bool dmOVM, bool dmPublishOwnID)
{
QString xmlContent("<CreateMessage xmlns=\"");
xmlContent.append(ISDS_NS);
......@@ -332,10 +332,10 @@ QByteArray XmlLayer::xmlCreateSendMessageSoapRequest(const MsgEnvelope &msg,
xmlContent.append("<dmFile dmMimeType=\"\" dmFileMetaType=\"");
(i > 0) ? xmlContent.append("enclosure") : xmlContent.append("main");
xmlContent.append("\" dmFileDescr=\"");
xmlContent.append(fileList.at(i).dmFileDescr);
xmlContent.append(fileList.at(i).dmFileDescr());
xmlContent.append("\">");
xmlContent.append("<dmEncodedContent>");
xmlContent.append(fileList.at(i).dmEncodedContent);
xmlContent.append(fileList.at(i).dmEncodedContent());
xmlContent.append("</dmEncodedContent>");
xmlContent.append("</dmFile>");
}
......@@ -375,7 +375,7 @@ QByteArray XmlLayer::xmlCreateSoapEnvelope(const QString &xmlContent)
}
bool XmlLayer::completeMessageParse(QXmlStreamReader &xml,
MsgEnvelope &msg, QList<Files::File> &fileList)
MsgEnvelope &msg, QList<AttachmentData> &fileList)
{
qDebug("%s()", __func__);
......@@ -683,7 +683,7 @@ bool XmlLayer::parseLoginResponse(const QByteArray &xmlData, QString &txt)
}
bool XmlLayer::parseSignedMessageDownloadResponse(const QByteArray &xmlData,
MsgEnvelope &msg, QList<Files::File> &fileList, QString &txt,
MsgEnvelope &msg, QList<AttachmentData> &fileList, QString &txt,
QByteArray &zfoData)
{
qDebug("%s()", __func__);
......@@ -1483,12 +1483,12 @@ DataboxModelEntry XmlLayer::parseDataboxData(QXmlStreamReader &xml)
dbEffectiveOVM, dbSendOptions);
}
Files::File XmlLayer::parseFile(QXmlStreamReader &xml, const qint64 msgId)
AttachmentData XmlLayer::parseFile(QXmlStreamReader &xml, const qint64 msgId)
{
qDebug("%s()", __func__);
Files::File file;
file.dmID = msgId;
AttachmentData file;
file.setDmId(msgId);
while (!(xml.tokenType() == QXmlStreamReader::EndElement
&& xml.name() == "dmFile")) {
......@@ -1496,27 +1496,25 @@ Files::File XmlLayer::parseFile(QXmlStreamReader &xml, const qint64 msgId)
&& (xml.name() == "dmFile")) {
foreach(const QXmlStreamAttribute &attr, xml.attributes()) {
if (attr.name() == "dmFileDescr") {
file.dmFileDescr = attr.value().toString();
file.setDmFileDescr(attr.value().toString());
} else if (attr.name() == "dmUpFileGuid") {
file.dmUpFileGuid = attr.value().toString();
file.setDmUpFileGuid(attr.value().toString());
} else if (attr.name() == "dmFileGuid") {
file.dmFileGuid = attr.value().toString();
file.setDmFileGuid(attr.value().toString());
} else if (attr.name() == "dmMimeType") {
file.dmMimeType = attr.value().toString();
file.setDmMimeType(attr.value().toString());
} else if (attr.name() == "dmFormat") {
file.dmFormat = attr.value().toString();
file.setDmFormat(attr.value().toString());
} else if (attr.name() == "dmFileMetaType") {
file.dmFileMetaType = attr.value().toString();
file.setDmFileMetaType(attr.value().toString());
}
}
} else if ((xml.tokenType() == QXmlStreamReader::StartElement)
&& (xml.name() == "dmEncodedContent")) {
xml.readNext();
file.dmEncodedContent = xml.text().toString();
file._dmFileSize =
getApproximatelyAttachmentFileSizeFromBase64(file.dmEncodedContent.length());
file._icon = getAttachmentFileIconFromFileExtension(file.dmFileDescr);
file.setDmEncodedContent(xml.text().toString());
file._setDmFileSize(getApproximatelyAttachmentFileSizeFromBase64(file.dmEncodedContent().length()));
file._setIcon(getAttachmentFileIconFromFileExtension(file.dmFileDescr()));
}
xml.readNext();
}
......
......@@ -182,7 +182,7 @@ public:
*/
static
QByteArray xmlCreateSendMessageSoapRequest(const MsgEnvelope &msg,
const QList<Files::File> &fileList, bool dmOVM, bool dmPublishOwnID);
const QList<AttachmentData> &fileList, bool dmOVM, bool dmPublishOwnID);
/*!
* @brief Create send SMS soap request.
......@@ -220,7 +220,7 @@ public:
*/
static
bool completeMessageParse(QXmlStreamReader &xml, MsgEnvelope &msg,
QList<Files::File> &fileList);
QList<AttachmentData> &fileList);
/*!
* @brief Parse event from XML.
......@@ -298,7 +298,7 @@ public:
*/
static
bool parseSignedMessageDownloadResponse(const QByteArray &xmlData,
MsgEnvelope &msg, QList<Files::File> &fileList, QString &txt,
MsgEnvelope &msg, QList<AttachmentData> &fileList, QString &txt,
QByteArray &zfoData);
/*!
......@@ -429,7 +429,7 @@ public:
* @return File structure.
*/
static
Files::File parseFile(QXmlStreamReader &xml, const qint64 msgId);
AttachmentData parseFile(QXmlStreamReader &xml, const qint64 msgId);
/*!
* @brief Parse find databox info xml data.
......
......@@ -227,7 +227,7 @@ QList<FileDb::FileData> FileDb::getFilesFromDb(qint64 dmId)
return filelist;
}
bool FileDb::insertUpdateFilesIntoDb(const Files::File &fileData)
bool FileDb::insertUpdateFilesIntoDb(const AttachmentData &fileData)
{
QSqlQuery query(m_db);
int id = -1;
......@@ -239,8 +239,8 @@ bool FileDb::insertUpdateFilesIntoDb(const Files::File &fileData)
query.lastError().text().toUtf8().constData();
goto fail;
}
query.bindValue(":dmID", fileData.dmID);
query.bindValue(":dmFileDescr", fileData.dmFileDescr);
query.bindValue(":dmID", fileData.dmId());
query.bindValue(":dmFileDescr", fileData.dmFileDescr());
if (query.exec() && query.isActive()) {
query.first();
if (query.isValid()) {
......@@ -277,17 +277,17 @@ bool FileDb::insertUpdateFilesIntoDb(const Files::File &fileData)
goto fail;
}
query.bindValue(":dmID", fileData.dmID);
query.bindValue(":dmFileDescr", fileData.dmFileDescr);
query.bindValue(":dmUpFileGuid", fileData.dmUpFileGuid);
query.bindValue(":dmFileGuid", fileData.dmFileGuid);
query.bindValue(":dmMimeType", fileData.dmMimeType);
query.bindValue(":dmFormat", fileData.dmFormat);
query.bindValue(":dmFileMetaType", fileData.dmFileMetaType);
query.bindValue(":dmEncodedContent", fileData.dmEncodedContent);
query.bindValue(":_dmFileSize", fileData._dmFileSize);
query.bindValue(":dmID", fileData.dmId());
query.bindValue(":dmFileDescr", fileData.dmFileDescr());
query.bindValue(":dmUpFileGuid", fileData.dmUpFileGuid());
query.bindValue(":dmFileGuid", fileData.dmFileGuid());
query.bindValue(":dmMimeType", fileData.dmMimeType());
query.bindValue(":dmFormat", fileData.dmFormat());
query.bindValue(":dmFileMetaType", fileData.dmFileMetaType());
query.bindValue(":dmEncodedContent", fileData.dmEncodedContent());
query.bindValue(":_dmFileSize", fileData._dmFileSize());
query.bindValue(":_dmDownloadDate", QDate::currentDate().toString(DATE_DB_FORMAT));
query.bindValue(":_icon", fileData._icon);
query.bindValue(":_icon", fileData._icon());
if (-1 != id) {
query.bindValue(":id", id);
}
......
......@@ -32,6 +32,7 @@
#include "src/io/sqlite/db.h"
#include "src/messages.h"
#include "src/models/filemodel.h"
#include "src/qml_interaction/attachment_data.h"
/*!
* @brief Encapsulates message database.
......@@ -144,7 +145,7 @@ public:
* @param[in] fileData Struct holds file data (name and content).
* @return True on success.
*/
bool insertUpdateFilesIntoDb(const Files::File &fileData);
bool insertUpdateFilesIntoDb(const AttachmentData &fileData);
/*!
* @brief Move db.
......
......@@ -101,7 +101,7 @@ enum TaskDownloadMessage::Result TaskDownloadMessage::downloadMessage(
MsgEnvelope msg;
QByteArray xmlDataOut;
QList<Files::File> fileList;
QList<AttachmentData> fileList;
QList<Messages::Event> eventList;
QString userType, authorName;
QByteArray zfoData;
......
......@@ -31,7 +31,7 @@
TaskSendMessage::TaskSendMessage(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, DbWrapper *dbWrapper, MsgEnvelope &msg,
QList<Files::File> &fileList, bool dmOVM, bool dmPublishOwnID)
QList<AttachmentData> &fileList, bool dmOVM, bool dmPublishOwnID)
: m_result(DL_ERR),
m_msgID(0),
m_lastError(),
......@@ -77,7 +77,7 @@ void TaskSendMessage::run(void)
enum TaskSendMessage::Result TaskSendMessage::sendMessage(
IsdsSession::IsdsContext &ctx, NetLayer *netLayer, DbWrapper *dbWrapper,
MsgEnvelope &msg, QList<Files::File> &fileList,
MsgEnvelope &msg, QList<AttachmentData> &fileList,
bool dmOVM, bool dmPublishOwnID, qint64 &msgID, QString &lastError)
{
if (ctx.username.isEmpty()) {
......@@ -115,9 +115,9 @@ enum TaskSendMessage::Result TaskSendMessage::sendMessage(
msg._setDmMessageType(Messages::TYPE_SENT);
/* Fill missing message id to file list */
QList<Files::File>::iterator it_file;
QList<AttachmentData>::iterator it_file;
for (it_file = fileList.begin(); it_file != fileList.end(); ++it_file) {
it_file->dmID = msgID;
it_file->setDmId(msgID);
}
/* Store data into db */
......
......@@ -59,7 +59,7 @@ public:
*/
explicit TaskSendMessage(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, DbWrapper *dbWrapper,
MsgEnvelope &msg, QList<Files::File> &fileList,
MsgEnvelope &msg, QList<AttachmentData> &fileList,
bool dmOVM, bool dmPublishOwnID);
/*!
......@@ -85,7 +85,7 @@ public:
static
enum Result sendMessage(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, DbWrapper *dbWrapper, MsgEnvelope &msg,
QList<Files::File> &fileList, bool dmOVM, bool dmPublishOwnID,
QList<AttachmentData> &fileList, bool dmOVM, bool dmPublishOwnID,
qint64 &msgID, QString &lastError);
enum Result m_result; /*!< Return state. */
......@@ -103,7 +103,7 @@ private:
NetLayer *m_netLayer; /*!< Pointer to network manager to send request. */
DbWrapper *m_dbWrapper; /*!< Pointer to database wrapper to store reply. */
MsgEnvelope m_msg; /*!< Message subject string. */
QList<Files::File> m_fileList; /*!< List of files. */
QList<AttachmentData> m_fileList; /*!< List of files. */
bool m_dmOVM; /*!< True if send message as OVM. */
bool m_dmPublishOwnID; /*!< True if add sender name to message. */
};
......
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