Commit 4bff0108 authored by Karel Slaný's avatar Karel Slaný

Sanitised error messages in messages.cpp.

parent 40362550
......@@ -21,7 +21,6 @@
* the two.
*/
#include <QDebug>
#include <QFile>
#include <QPair>
#include <QPushButton>
......@@ -71,13 +70,8 @@ enum MessageDb::MessageType enumToDbRepr(enum Messages::MessageType msgType)
}
}
/* ========================================================================= */
/*
* Slot: Fill message list in QML.
*/
void Messages::fillMessageList(const QVariant &msgModelVariant,
const QString &userName, enum MessageType msgType)
/* ========================================================================= */
{
qDebug("%s()", __func__);
......@@ -93,7 +87,7 @@ void Messages::fillMessageList(const QVariant &msgModelVariant,
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical() << "Cannot open message database.";
qCritical("%s", "Cannot open message database.");
return;
}
......@@ -103,7 +97,6 @@ void Messages::fillMessageList(const QVariant &msgModelVariant,
enumToDbRepr(msgType));
}
QString Messages::getMessageDetail(const QString &userName,
const QString &msgIdStr)
{
......@@ -115,11 +108,11 @@ QString Messages::getMessageDetail(const QString &userName,
return QString();
}
MessageDb *msgDb = NULL;
msgDb = globMessageDbsPtr->accessMessageDb(globSet.dbsLocation, userName,
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == NULL) {
qDebug() << "ERROR: Message database cannot open!";
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
return QString();
}
return msgDb->getMessageDetailDataFromDb(msgId);
......@@ -134,7 +127,7 @@ void Messages::markMessageAsLocallyRead(const QVariant &msgModelVariant,
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical() << "Cannot open message database.";
qCritical("%s", "Cannot open message database.");
return;
}
msgDb->markMessageLocallyRead(msgId, isRead);
......@@ -157,7 +150,7 @@ void Messages::markMessagesAsLocallyRead(const QVariant &msgModelVariant,
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical() << "Cannot open message database.";
qCritical("%s", "Cannot open message database.");
return;
}
msgDb->markMessagesLocallyRead(enumToDbRepr(msgType), isRead);
......@@ -198,15 +191,15 @@ void Messages::deleteMessageFromDbs(const QVariant &msgModelVariant,
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical() << "Cannot open message database.";
qCritical("%s", "Cannot open message database.");
return;
}
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "Cannot open file database for "
<< userName << ".";
qCritical("Cannot open file database for %s.",
userName.toUtf8().constData());
return;
}
......@@ -277,14 +270,7 @@ bool Messages::moveOrCreateNewDbsToNewLocation(const QString &newLocation)
return relocateDatabases(newLocation, action);
}
/* ========================================================================= */
/*
* Func: Delete messages from all message databases together with files
* where lifetime expired.
*/
void Messages::deleteExpiredMessagesFromDbs(int days)
/* ========================================================================= */
{
qDebug("%s()", __func__);
......@@ -292,11 +278,12 @@ void Messages::deleteExpiredMessagesFromDbs(int days)
QStringList userNameList = AccountListModel::globAccounts.keys();
foreach (const QString &userName, userNameList) {
MessageDb *msgDb = NULL;
msgDb = globMessageDbsPtr->accessMessageDb(globSet.dbsLocation, userName,
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == NULL) {
qDebug() << "ERROR: Message database cannot open!" << userName;
if (msgDb == Q_NULLPTR) {
qCritical("Cannot open message database for %s.",
userName.toUtf8().constData());
return;
}
msgIDList = msgDb->getExpireMsgListFromDb(days);
......@@ -305,11 +292,12 @@ void Messages::deleteExpiredMessagesFromDbs(int days)
continue;
}
FileDb *fDb = NULL;
fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation, userName,
FileDb *fDb = globFileDbsPtr->accessFileDb(
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == NULL) {
qDebug() << "ERROR: File database cannot open!" << userName;
if (fDb == Q_NULLPTR) {
qCritical("Cannot open file database for %s.",
userName.toUtf8().constData());
return;
}
......@@ -358,8 +346,9 @@ int Messages::getAllDbSize(void)
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == NULL) {
qDebug("ERROR: Cannot open message database for user name '%s'.", userName.toUtf8().constData());
if (msgDb == Q_NULLPTR) {
qCritical("Cannot open message database for user name '%s'.",
userName.toUtf8().constData());
return -1;
}
size += msgDb->getDbSizeInBytes();
......@@ -367,8 +356,9 @@ int Messages::getAllDbSize(void)
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == NULL) {
qDebug("ERROR: Cannot open file database for user name '%s'.", userName.toUtf8().constData());
if (fDb == Q_NULLPTR) {
qCritical("Cannot open file database for user name '%s'.",
userName.toUtf8().constData());
return -1;
}
size += fDb->getDbSizeInBytes();
......@@ -408,7 +398,7 @@ bool Messages::relocateDatabases(const QString &newLocation,
MessageDb *mDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
relocationSucceeded = (mDb != NULL);
relocationSucceeded = (mDb != Q_NULLPTR);
if (!relocationSucceeded) {
qWarning("Cannot access message database for user name '%s'.",
userName.toUtf8().constData());
......@@ -417,7 +407,7 @@ bool Messages::relocateDatabases(const QString &newLocation,
FileDb *fDb = globFileDbsPtr->accessFileDb(
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
relocationSucceeded = (fDb != NULL);
relocationSucceeded = (fDb != Q_NULLPTR);
if (!relocationSucceeded) {
qWarning("Cannot access file database for user name '%s'.",
userName.toUtf8().constData());
......@@ -542,7 +532,7 @@ int Messages::searchMsg(const QVariant &msgModelVariant, const QString &phrase,
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qDebug() << "ERROR: Message database cannot open!" << userName;
qCritical("%s", "Cannot open message database.");
continue;
}
......
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