Commit 0f9ce7e9 authored by Martin Straka's avatar Martin Straka

Removed unused method from file db. Code refactoring

parent 29f2d75c
......@@ -146,7 +146,7 @@ QByteArray Files::getFileRawContentFromDb(const QString &userName, int fileId)
return QByteArray();
}
return base64ToRaw(fDb->getFileContentFromDb(fileId).content.toUtf8());
return base64ToRaw(fDb->getFileFromDb(fileId).content.toUtf8());
}
void Files::openAttachmentFromDb(const QString &userName, int fileId)
......@@ -169,7 +169,7 @@ void Files::openAttachmentFromDb(const QString &userName, int fileId)
return;
}
FileDb::FileData file = fDb->getFileContentFromDb(fileId);
FileDb::FileData file = fDb->getFileFromDb(fileId);
openAttachment(file.filename, file.content.toUtf8());
}
......@@ -535,7 +535,7 @@ bool Files::setAttachmentModel(FileListModel &attachModel,
return false;
}
attachModel.clearAll();
fDb->getFileListFromDb(attachModel, msgId);
fDb->setFileModelFromDb(attachModel, msgId);
return true;
}
......
......@@ -203,7 +203,7 @@ bool DbWrapper::insertCompleteMessageToDb(const QString &userName,
/* Insert or update files into files database */
fDb->beginTransaction();
for (int i = 0; i < fileList.count(); ++i) {
if (!fDb->insertUpdateFilesIntoDb(fileList.at(i))) {
if (!fDb->insertUpdateFileIntoDb(fileList.at(i))) {
txt = tr("File %1 insertion failed!").
arg(fileList.at(i).dmFileDescr());
ret = ret * false;
......
......@@ -654,7 +654,7 @@ void IsdsWrapper::sendMessage(const QString &userName, qint64 dmID,
if (file.fileId() > 0) {
// load file content from database, valid file ID
FileDb::FileData fileData = fDb->getFileContentFromDb(file.fileId());
FileDb::FileData fileData = fDb->getFileFromDb(file.fileId());
attach.setDmEncodedContent(fileData.content);
totalAttachmentSizeKBs += fileData.content.length() / 1024;
} else if (file.fileId() == Files::DB_ZFO_ID) {
......
......@@ -89,24 +89,6 @@ bool FileDb::copyDb(const QString &newFileName)
return SQLiteDb::copyDb(newFileName, SQLiteDb::CREATE_MISSING);
}
int FileDb::countFilesInDb(void)
{
QSqlQuery query(m_db);
QString queryStr = "SELECT COUNT(*) FROM files";
if (!query.prepare(queryStr)) {
qCritical() << "Cannot prepare SQL query:" <<
query.lastError().text().toUtf8().constData();
return -1;
}
if (query.exec() && query.isActive() &&
query.first() && query.isValid()) {
return query.value(0).toInt();
}
return -1;
}
bool FileDb::reopenDb(const QString &newFileName)
{
return SQLiteDb::reopenDb(newFileName, SQLiteDb::CREATE_MISSING);
......@@ -134,13 +116,13 @@ fail:
return false;
}
int FileDb::getDbSizeInBytes(void)
int FileDb::getDbSizeInBytes(void) const
{
QFileInfo fi(m_db.databaseName());
return fi.size();
}
void FileDb::getFileListFromDb(FileListModel &model, const qint64 dmId)
void FileDb::setFileModelFromDb(FileListModel &model, const qint64 dmId) const
{
QSqlQuery query(m_db);
......@@ -158,7 +140,7 @@ void FileDb::getFileListFromDb(FileListModel &model, const qint64 dmId)
}
}
FileDb::FileData FileDb::getFileContentFromDb(int fileId)
FileDb::FileData FileDb::getFileFromDb(int fileId) const
{
QSqlQuery query(m_db);
FileDb::FileData filedata;
......@@ -184,7 +166,7 @@ FileDb::FileData FileDb::getFileContentFromDb(int fileId)
return FileDb::FileData();
}
QList<FileDb::FileData> FileDb::getFilesFromDb(qint64 dmId)
QList<FileDb::FileData> FileDb::getFilesFromDb(qint64 dmId) const
{
QSqlQuery query(m_db);
FileDb::FileData filedata;
......@@ -216,7 +198,7 @@ QList<FileDb::FileData> FileDb::getFilesFromDb(qint64 dmId)
return filelist;
}
bool FileDb::insertUpdateFilesIntoDb(const AttachmentData &fileData)
bool FileDb::insertUpdateFileIntoDb(const AttachmentData &fileData)
{
QSqlQuery query(m_db);
int id = -1;
......
......@@ -67,13 +67,6 @@ public:
*/
bool copyDb(const QString &newFileName);
/*!
* @brief Get count of records in files db.
*
* @return record count.
*/
int countFilesInDb(void);
/*!
* @brief Open a new empty database file.
*
......@@ -95,7 +88,7 @@ public:
*
* @return True size in bytes.
*/
int getDbSizeInBytes(void);
int getDbSizeInBytes(void) const;
/*!
* @brief Get file content from db.
......@@ -103,23 +96,23 @@ public:
* @param[in] fileId File Id.
* @return File name and content.
*/
FileDb::FileData getFileContentFromDb(int fileId);
FileDb::FileData getFileFromDb(int fileId) const;
/*!
* @brief Get list of files from db - for QML listview.
* @brief Get list of files from db.
*
* @param[in] dmId Message Id.
* @return List of files (name and content).
*/
QList<FileDb::FileData> getFilesFromDb(qint64 dmId);
QList<FileDb::FileData> getFilesFromDb(qint64 dmId) const;
/*!
* @brief Get list of files from db - for QML listview.
* @brief Set attachment model from db - for QML listview.
*
* @param[in,out] model Model to be set.
* @param[in] dmId Message Id.
*/
void getFileListFromDb(FileListModel &model, qint64 dmId);
void setFileModelFromDb(FileListModel &model, qint64 dmId) const;
/*!
* @brief Insert or update file data into files table.
......@@ -127,7 +120,7 @@ public:
* @param[in] fileData Struct holds file data (name and content).
* @return True on success.
*/
bool insertUpdateFilesIntoDb(const AttachmentData &fileData);
bool insertUpdateFileIntoDb(const AttachmentData &fileData);
/*!
* @brief Open database file.
......
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