Commit 61faf775 authored by Martin Straka's avatar Martin Straka

Files: final refactoring

parent 87115ecb
......@@ -24,8 +24,7 @@
#include <QDebug>
#include <QDesktopServices>
#include <QFileInfo>
#include <QUrl>
#include <QQmlEngine> /* qmlRegisterType */
#include <QQmlEngine>
#include "ios/src/url_opener.h"
#include "src/auxiliaries/attachment_helper.h"
......@@ -81,11 +80,12 @@ void Files::deleteExpiredFilesFromDbs(int days)
QStringList msgIDList;
QStringList userNameList = AccountListModel::globAccounts.keys();
foreach (const QString &userName, userNameList) {
FileDb *fDb = NULL;
fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation, userName,
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == NULL) {
qCritical() << "ERROR: File database cannot open!" << userName;
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database cannot open!"
<< userName;
return;
}
msgIDList = fDb->cleanFilesInDb(days);
......@@ -93,10 +93,11 @@ void Files::deleteExpiredFilesFromDbs(int days)
continue;
}
MessageDb *msgDb = NULL;
msgDb = globMessageDbsPtr->accessMessageDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == NULL) {
MessageDb *msgDb =
globMessageDbsPtr->accessMessageDb(globSet.dbsLocation,
userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical() << "ERROR: Message database cannot open!";
return;
}
......@@ -249,7 +250,7 @@ void Files::sendAttachmentsWithEmail(const QString &userName, qint64 msgId)
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == NULL) {
if (msgDb == Q_NULLPTR) {
qCritical() << "ERROR: Message database cannot open!";
return;
}
......@@ -260,7 +261,7 @@ void Files::sendAttachmentsWithEmail(const QString &userName, qint64 msgId)
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == NULL) {
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database cannot open!";
return;
}
......@@ -308,10 +309,9 @@ void Files::deleteFileDb(const QString &userName)
return;
}
FileDb *fDb = NULL;
fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == NULL) {
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database open error!";
return;
}
......@@ -320,10 +320,10 @@ void Files::deleteFileDb(const QString &userName)
return;
}
MessageDb *msgDb = NULL;
msgDb = globMessageDbsPtr->accessMessageDb(globSet.dbsLocation, userName,
MessageDb *msgDb =
globMessageDbsPtr->accessMessageDb(globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == NULL) {
if (msgDb == Q_NULLPTR) {
qCritical() << "ERROR: Message database cannot open!";
return;
}
......@@ -341,10 +341,10 @@ void Files::vacuumFileDbs(void)
QStringList userNameList = AccountListModel::globAccounts.keys();
foreach (const QString &userName, userNameList) {
FileDb *fDb = NULL;
fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation, userName,
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == NULL) {
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database cannot open!"
<< userName;
return;
......@@ -359,19 +359,19 @@ bool Files::deleteAttachmentsFromDb(const QString &userName, qint64 msgId)
{
qDebug("%s()", __func__);
FileDb *fDb = NULL;
fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == NULL) {
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database cannot open!" << userName;
return false;
}
if (fDb->deleteFilesFromDb(msgId)) {
MessageDb *msgDb = NULL;
msgDb = globMessageDbsPtr->accessMessageDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == NULL) {
MessageDb *msgDb =
globMessageDbsPtr->accessMessageDb(globSet.dbsLocation,
userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical() << "ERROR: Message database cannot open!";
return false;
}
......@@ -528,23 +528,18 @@ void Files::saveAttachmentsToDiskDb(const QString &userName,
return;
}
QList<FileDb::FileData> filelist;
{
FileDb *fDb = Q_NULLPTR;
fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "Cannot open file database!";
return;
}
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
filelist = fDb->getFilesFromDb(msgId);
if (filelist.isEmpty()) {
qCritical() << "File list is empty!";
return;
}
if (fDb == Q_NULLPTR) {
qCritical() << "Cannot open file database!";
return;
}
QList<FileDb::FileData> filelist = fDb->getFilesFromDb(msgId);
if (filelist.isEmpty()) {
qCritical() << "File list is empty!";
return;
}
QString destPath;
......@@ -642,19 +637,19 @@ QByteArray Files::getXmlFromCms(const QByteArray &rawData)
}
/* Decode CMS and obtain message XML data - uses OpenSSL. */
void *xmlContent = NULL;
void *xmlContent = Q_NULLPTR;
size_t xmlContentLen = 0;
if (extract_cms_data(rawData.data(), rawData.length(), &xmlContent,
&xmlContentLen) != 0) {
return QByteArray();
}
if (xmlContentLen == 0) {
free(xmlContent); xmlContent = NULL;
free(xmlContent); xmlContent = Q_NULLPTR;
return QByteArray();
}
QByteArray soap((char *)xmlContent, xmlContentLen);
free(xmlContent); xmlContent = NULL;
free(xmlContent); xmlContent = Q_NULLPTR;
return soap;
}
......@@ -876,8 +871,10 @@ bool Files::parseAndShowXmlData(enum MsgInfo::ZfoType type, QString *idStr,
if (attachModel != Q_NULLPTR) {
attachModel->clearAll();
foreach (const AttachmentData &file, fileList) {
attachModel->appendFileEntry(FileListModel::Entry(-1, file.dmFileDescr(),
file._dmFileSize(), file._icon(), file.dmEncodedContent(), QString()));
attachModel->appendFileEntry(
FileListModel::Entry(-1, file.dmFileDescr(),
file._dmFileSize(), file._icon(),
file.dmEncodedContent(), QString()));
}
}
if (emailBody != Q_NULLPTR) {
......
......@@ -75,6 +75,13 @@ public:
static
QString fileSaveLocation(void);
/*!
* @brief Delete files from all databases where file lifetime expired.
*
* @param[in] days Lifetime in days.
*/
void deleteExpiredFilesFromDbs(int days);
/*!
* @brief Get attachment file icon from file name.
*
......@@ -152,14 +159,6 @@ public:
Q_INVOKABLE
void deleteFileDb(const QString &userName);
/*!
* @brief Delete files from all file databases
* where file lifetime expired.
*
* @param[in] days Lifetime in days.
*/
void deleteExpiredFilesFromDbs(int days);
/*!
* @brief Vacuum all file databases.
*/
......@@ -170,7 +169,7 @@ public:
* @brief Delete message attachments from databases.
*
* @param[in] userName User name of account.
* @param[in] msgId Message id.
* @param[in] msgId Message id.
* @return true if success.
*/
Q_INVOKABLE
......@@ -251,7 +250,7 @@ public:
* @param[in] attachModelVariant QVariant holding attachment model.
* @param[in] msgIdStr String with message id.
* @param[in] subject Email subject.
* @param[in] body Email body.
* @param[in] body Email body.
*/
Q_INVOKABLE static
void sendAttachmentEmailZfo(const QVariant &attachModelVariant,
......@@ -305,7 +304,7 @@ private:
*
* @param[in] emailMessage Eml email content.
* @param[in] fileList File list for email.
* @param[in] subject Email subject
* @param[in] subject Email subject.
* @param[in] body Email body.
* @param[in] msgId Message ID.
*/
......@@ -344,7 +343,7 @@ private:
* @param[out] attachModel Attachment model to be set.
* @param[out] emailBody Email body.
* @param[in] xmlData Xml file data.
* @return true if success.
* @return True if success.
*/
static
bool parseXmlData(enum MsgInfo::ZfoType *type, QString *idStr,
......@@ -361,12 +360,13 @@ private:
* @param[out] attachModel Attachment model to be set.
* @param[out] emailBody Email body.
* @param[in] xmlData Xml file data.
* @return true if success.
* @return True if success.
*/
static
bool parseAndShowXmlData(enum MsgInfo::ZfoType type, QString *idStr,
QString *annotation, QString *msgDescrHtml,
FileListModel *attachModel, QString *emailBody, QByteArray &xmlData);
FileListModel *attachModel, QString *emailBody,
QByteArray &xmlData);
};
/* Declare FileIdType to QML. */
......
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