This commit is contained in:
Martin Rotter 2020-08-07 12:16:51 +02:00
parent db6f08cf6e
commit d40409f62a
25 changed files with 204 additions and 183 deletions

View File

@ -192,6 +192,11 @@ bool MessageObject::isDuplicateWithAttribute(int attribute_check) const {
QString full_query = QSL("SELECT COUNT(*) FROM Messages WHERE ") + where_clauses.join(QSL(" AND ")) + QSL(";"); QString full_query = QSL("SELECT COUNT(*) FROM Messages WHERE ") + where_clauses.join(QSL(" AND ")) + QSL(";");
qDebugNN << LOGSEC_MESSAGEMODEL
<< "Query for MSG duplicate identification is: '"
<< full_query
<< "'.";
q.setForwardOnly(true); q.setForwardOnly(true);
q.prepare(full_query); q.prepare(full_query);

View File

@ -88,6 +88,7 @@
#define LOGSEC_MESSAGEMODEL "message-model: " #define LOGSEC_MESSAGEMODEL "message-model: "
#define LOGSEC_GUI "gui: " #define LOGSEC_GUI "gui: "
#define LOGSEC_CORE "core: " #define LOGSEC_CORE "core: "
#define LOGSEC_DB "database: "
#define MAX_ZOOM_FACTOR 5.0f #define MAX_ZOOM_FACTOR 5.0f
#define MIN_ZOOM_FACTOR 0.25f #define MIN_ZOOM_FACTOR 0.25f
@ -160,10 +161,6 @@
#define qCriticalNN qCritical().noquote().nospace() #define qCriticalNN qCritical().noquote().nospace()
#endif #endif
#ifndef qFatalNN
#define qFatalNN qFatal().noquote().nospace()
#endif
#ifndef qInfoNN #ifndef qInfoNN
#define qInfoNN qInfo().noquote().nospace() #define qInfoNN qInfo().noquote().nospace()
#endif #endif

View File

@ -17,7 +17,7 @@ BaseToolBar::BaseToolBar(const QString& title, QWidget* parent) : QToolBar(title
} }
BaseToolBar::~BaseToolBar() { BaseToolBar::~BaseToolBar() {
qDebug("Destroying BaseToolBar instance."); qDebugNN << LOGSEC_GUI << "Destroying BaseToolBar instance.";
} }
void BaseBar::loadSavedActions() { void BaseBar::loadSavedActions() {

View File

@ -1,23 +0,0 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#include "gui/colorlabel.h"
#include <QPainter>
#include <QPaintEvent>
ColorLabel::ColorLabel(QWidget* parent) : QLabel(parent) {
setFixedWidth(20);
}
QColor ColorLabel::color() const {
return m_color;
}
void ColorLabel::setColor(const QColor& color) {
m_color = color;
repaint();
}
void ColorLabel::paintEvent(QPaintEvent* event) {
QPainter(this).fillRect(event->rect(), m_color);
}

View File

@ -1,25 +0,0 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#ifndef COLORLABEL_H
#define COLORLABEL_H
#include <QLabel>
class ColorLabel : public QLabel {
Q_OBJECT
public:
explicit ColorLabel(QWidget* parent = nullptr);
virtual ~ColorLabel() = default;
QColor color() const;
void setColor(const QColor& color);
protected:
void paintEvent(QPaintEvent* event);
private:
QColor m_color;
};
#endif // COLORLABEL_H

View File

@ -43,7 +43,7 @@ FormSettings::FormSettings(QWidget& parent)
} }
FormSettings::~FormSettings() { FormSettings::~FormSettings() {
qDebug("Destroying FormSettings distance."); qDebugNN << LOGSEC_GUI << "Destroying FormSettings distance.";
} }
void FormSettings::saveSettings() { void FormSettings::saveSettings() {

View File

@ -94,6 +94,7 @@ void FormUpdate::checkForUpdates() {
} }
} }
}); });
qApp->system()->checkForUpdates(); qApp->system()->checkForUpdates();
} }
@ -133,12 +134,14 @@ void FormUpdate::saveUpdateFile(const QByteArray& file_contents) {
m_readyToInstall = true; m_readyToInstall = true;
} }
else { else {
qDebug("Cannot save downloaded update file because target temporary file '%s' cannot be " qDebugNN << LOGSEC_GUI
"opened for writing.", qPrintable(output_file_name)); << "Cannot save downloaded update file because target temporary file '"
<< output_file_name
<< "' cannot be opened for writing.";
} }
} }
else { else {
qDebug("Cannot save downloaded update file because no TEMP directory is available."); qDebugNN << LOGSEC_GUI << "Cannot save downloaded update file because no TEMP directory is available.";
} }
} }
@ -167,10 +170,11 @@ void FormUpdate::loadAvailableFiles() {
} }
void FormUpdate::updateCompleted(QNetworkReply::NetworkError status, const QByteArray& contents) { void FormUpdate::updateCompleted(QNetworkReply::NetworkError status, const QByteArray& contents) {
qDebug("Download of application update file was completed with code '%d'.", status); qDebugNN << LOGSEC_GUI
<< "Download of application update file was completed with code '" << status << "'.";
switch (status) { switch (status) {
case QNetworkReply::NoError: case QNetworkReply::NetworkError::NoError:
saveUpdateFile(contents); saveUpdateFile(contents);
m_ui.m_lblStatus->setStatus(WidgetWithStatus::StatusType::Ok, tr("Downloaded successfully"), m_ui.m_lblStatus->setStatus(WidgetWithStatus::StatusType::Ok, tr("Downloaded successfully"),
tr("Package was downloaded successfully.\nYou can install it now.")); tr("Package was downloaded successfully.\nYou can install it now."));
@ -200,7 +204,11 @@ void FormUpdate::startUpdate() {
if (m_readyToInstall) { if (m_readyToInstall) {
close(); close();
qDebug("Preparing to launch external installer '%s'.", qPrintable(QDir::toNativeSeparators(m_updateFilePath))); qDebugNN << LOGSEC_GUI
<< "Preparing to launch external installer '"
<< QDir::toNativeSeparators(m_updateFilePath)
<< "'.";
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
HINSTANCE exec_result = ShellExecute(nullptr, HINSTANCE exec_result = ShellExecute(nullptr,
nullptr, nullptr,
@ -210,7 +218,7 @@ void FormUpdate::startUpdate() {
SW_NORMAL); SW_NORMAL);
if (exec_result <= HINSTANCE(32)) { if (exec_result <= HINSTANCE(32)) {
qDebug("External updater was not launched due to error."); qDebugNN << LOGSEC_GUI << "External updater was not launched due to error.";
qApp->showGuiMessage(tr("Cannot update application"), qApp->showGuiMessage(tr("Cannot update application"),
tr("Cannot launch external updater. Update application manually."), tr("Cannot launch external updater. Update application manually."),
QSystemTrayIcon::Warning, this); QSystemTrayIcon::Warning, this);
@ -219,6 +227,7 @@ void FormUpdate::startUpdate() {
qApp->quit(); qApp->quit();
} }
#endif #endif
} }
else if (update_for_this_system) { else if (update_for_this_system) {
updateProgress(0, 100); updateProgress(0, 100);

View File

@ -64,7 +64,7 @@ FeedMessageViewer::FeedMessageViewer(QWidget* parent) : TabContent(parent), m_to
} }
FeedMessageViewer::~FeedMessageViewer() { FeedMessageViewer::~FeedMessageViewer() {
qDebug("Destroying FeedMessageViewer instance."); qDebugNN << LOGSEC_GUI << "Destroying FeedMessageViewer instance.";
} }
#if defined(USE_WEBENGINE) #if defined(USE_WEBENGINE)

View File

@ -48,7 +48,7 @@ FeedsView::FeedsView(QWidget* parent)
} }
FeedsView::~FeedsView() { FeedsView::~FeedsView() {
qDebug("Destroying FeedsView instance."); qDebugNN << LOGSEC_GUI << "Destroying FeedsView instance.";
} }
void FeedsView::reloadFontSettings() { void FeedsView::reloadFontSettings() {

View File

@ -36,16 +36,16 @@ void MessageBox::setCheckBox(QMessageBox* msg_box, const QString& text, bool* da
QIcon MessageBox::iconForStatus(QMessageBox::Icon status) { QIcon MessageBox::iconForStatus(QMessageBox::Icon status) {
switch (status) { switch (status) {
case QMessageBox::Information: case QMessageBox::Icon::Information:
return qApp->icons()->fromTheme(QSL("dialog-information")); return qApp->icons()->fromTheme(QSL("dialog-information"));
case QMessageBox::Warning: case QMessageBox::Icon::Warning:
return qApp->icons()->fromTheme(QSL("dialog-warning")); return qApp->icons()->fromTheme(QSL("dialog-warning"));
case QMessageBox::Critical: case QMessageBox::Icon::Critical:
return qApp->icons()->fromTheme(QSL("dialog-error")); return qApp->icons()->fromTheme(QSL("dialog-error"));
case QMessageBox::Question: case QMessageBox::Icon::Question:
return qApp->icons()->fromTheme(QSL("dialog-question")); return qApp->icons()->fromTheme(QSL("dialog-question"));
default: default:

View File

@ -42,7 +42,7 @@ MessagesView::MessagesView(QWidget* parent) : QTreeView(parent), m_contextMenu(n
} }
MessagesView::~MessagesView() { MessagesView::~MessagesView() {
qDebug("Destroying MessagesView instance."); qDebugNN << LOGSEC_GUI << "Destroying MessagesView instance.";
} }
void MessagesView::reloadFontSettings() { void MessagesView::reloadFontSettings() {
@ -128,7 +128,10 @@ void MessagesView::reloadSelections() {
const QDateTime dt2 = QDateTime::currentDateTime(); const QDateTime dt2 = QDateTime::currentDateTime();
qDebug("Reloading of msg selections took %lld miliseconds.", dt1.msecsTo(dt2)); qDebugNN << LOGSEC_GUI
<< "Reloading of msg selections took "
<< dt1.msecsTo(dt2)
<< " miliseconds.";
} }
void MessagesView::setupAppearance() { void MessagesView::setupAppearance() {
@ -163,7 +166,7 @@ void MessagesView::focusInEvent(QFocusEvent* event) {
void MessagesView::keyPressEvent(QKeyEvent* event) { void MessagesView::keyPressEvent(QKeyEvent* event) {
QTreeView::keyPressEvent(event); QTreeView::keyPressEvent(event);
if (event->key() == Qt::Key_Delete) { if (event->key() == Qt::Key::Key_Delete) {
deleteSelectedMessages(); deleteSelectedMessages();
} }
} }
@ -248,7 +251,7 @@ void MessagesView::mousePressEvent(QMouseEvent* event) {
QTreeView::mousePressEvent(event); QTreeView::mousePressEvent(event);
switch (event->button()) { switch (event->button()) {
case Qt::LeftButton: { case Qt::MouseButton::LeftButton: {
// Make sure that message importance is switched when user // Make sure that message importance is switched when user
// clicks the "important" column. // clicks the "important" column.
const QModelIndex clicked_index = indexAt(event->pos()); const QModelIndex clicked_index = indexAt(event->pos());
@ -266,7 +269,7 @@ void MessagesView::mousePressEvent(QMouseEvent* event) {
break; break;
} }
case Qt::MiddleButton: { case Qt::MouseButton::MiddleButton: {
// Make sure that message importance is switched when user // Make sure that message importance is switched when user
// clicks the "important" column. // clicks the "important" column.
const QModelIndex clicked_index = indexAt(event->pos()); const QModelIndex clicked_index = indexAt(event->pos());
@ -297,11 +300,10 @@ void MessagesView::selectionChanged(const QItemSelection& selected, const QItemS
const QModelIndex current_index = currentIndex(); const QModelIndex current_index = currentIndex();
const QModelIndex mapped_current_index = m_proxyModel->mapToSource(current_index); const QModelIndex mapped_current_index = m_proxyModel->mapToSource(current_index);
qDebug("Current row changed - row [%d,%d] source [%d, %d].", qDebugNN << LOGSEC_GUI
current_index.row(), << "Current row changed - proxy '"
current_index.column(), << current_index << "', source '"
mapped_current_index.row(), << mapped_current_index << "'.";
mapped_current_index.column());
if (mapped_current_index.isValid() && selected_rows.count() > 0) { if (mapped_current_index.isValid() && selected_rows.count() > 0) {
Message message = m_sourceModel->messageAt(m_proxyModel->mapToSource(current_index).row()); Message message = m_sourceModel->messageAt(m_proxyModel->mapToSource(current_index).row());

View File

@ -12,7 +12,7 @@ QVariant MessageTextBrowser::loadResource(int type, const QUrl& name) {
Q_UNUSED(name) Q_UNUSED(name)
switch (type) { switch (type) {
case QTextDocument::ImageResource: { case QTextDocument::ResourceType::ImageResource: {
if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::DisplayImagePlaceholders)).toBool()) { if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::DisplayImagePlaceholders)).toBool()) {
if (m_imagePlaceholder.isNull()) { if (m_imagePlaceholder.isNull()) {
m_imagePlaceholder = qApp->icons()->miscPixmap(QSL("image-placeholder")).scaledToWidth(20, Qt::FastTransformation); m_imagePlaceholder = qApp->icons()->miscPixmap(QSL("image-placeholder")).scaledToWidth(20, Qt::FastTransformation);

View File

@ -41,7 +41,7 @@ void NewspaperPreviewer::showMoreMessages() {
else { else {
qApp->showGuiMessage(tr("Cannot show more messages"), qApp->showGuiMessage(tr("Cannot show more messages"),
tr("Cannot show more messages because parent feed was removed."), tr("Cannot show more messages because parent feed was removed."),
QSystemTrayIcon::Warning, QSystemTrayIcon::MessageIcon::Warning,
qApp->mainForm(), true); qApp->mainForm(), true);
} }
} }

View File

@ -52,8 +52,8 @@ void SettingsDatabase::mysqlTestConnection() {
const QString interpretation = qApp->database()->mysqlInterpretErrorCode(error_code); const QString interpretation = qApp->database()->mysqlInterpretErrorCode(error_code);
switch (error_code) { switch (error_code) {
case DatabaseFactory::MySQLError::MySQLOk: case DatabaseFactory::MySQLError::Ok:
case DatabaseFactory::MySQLError::MySQLUnknownDatabase: case DatabaseFactory::MySQLError::UnknownDatabase:
m_ui->m_lblMysqlTestResult->setStatus(WidgetWithStatus::StatusType::Ok, interpretation, interpretation); m_ui->m_lblMysqlTestResult->setStatus(WidgetWithStatus::StatusType::Ok, interpretation, interpretation);
break; break;
@ -109,7 +109,10 @@ void SettingsDatabase::selectSqlBackend(int index) {
m_ui->m_stackedDatabaseDriver->setCurrentIndex(1); m_ui->m_stackedDatabaseDriver->setCurrentIndex(1);
} }
else { else {
qWarning("GUI for given database driver '%s' is not available.", qPrintable(selected_db_driver)); qWarningNN << LOGSEC_GUI
<< "GUI for given database driver '"
<< selected_db_driver
<< "' is not available.";
} }
} }

View File

@ -49,14 +49,15 @@ StatusBar::StatusBar(QWidget* parent) : QStatusBar(parent), m_mutex(new Mutex(QM
StatusBar::~StatusBar() { StatusBar::~StatusBar() {
clear(); clear();
qDebug("Destroying StatusBar instance."); qDebugNN << LOGSEC_GUI "Destroying StatusBar instance.";
} }
QList<QAction*> StatusBar::availableActions() const { QList<QAction*> StatusBar::availableActions() const {
QList<QAction*> actions = qApp->userActions(); QList<QAction*> actions = qApp->userActions();
// Now, add placeholder actions for custom stuff. // Now, add placeholder actions for custom stuff.
actions << m_barProgressDownloadAction << m_barProgressFeedsAction << m_lblProgressDownloadAction << m_lblProgressFeedsAction; actions << m_barProgressDownloadAction << m_barProgressFeedsAction
<< m_lblProgressDownloadAction << m_lblProgressFeedsAction;
return actions; return actions;
} }

View File

@ -31,7 +31,7 @@ SystemTrayIcon::SystemTrayIcon(const QString& normal_icon, const QString& plain_
: QSystemTrayIcon(parent), : QSystemTrayIcon(parent),
m_normalIcon(normal_icon), m_normalIcon(normal_icon),
m_plainPixmap(plain_icon) { m_plainPixmap(plain_icon) {
qDebug("Creating SystemTrayIcon instance."); qDebugNN << LOGSEC_GUI << "Creating SystemTrayIcon instance.";
m_font.setBold(true); m_font.setBold(true);
// Initialize icon. // Initialize icon.
@ -43,7 +43,7 @@ SystemTrayIcon::SystemTrayIcon(const QString& normal_icon, const QString& plain_
} }
SystemTrayIcon::~SystemTrayIcon() { SystemTrayIcon::~SystemTrayIcon() {
qDebug("Destroying SystemTrayIcon instance."); qDebugNN << LOGSEC_GUI << "Destroying SystemTrayIcon instance.";
hide(); hide();
} }
@ -82,19 +82,17 @@ void SystemTrayIcon::showPrivate() {
QSystemTrayIcon::show(); QSystemTrayIcon::show();
emit shown(); emit shown();
qDebug("Tray icon displayed."); qDebugNN << LOGSEC_GUI << "Tray icon displayed.";
} }
void SystemTrayIcon::show() { void SystemTrayIcon::show() {
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
// Show immediately. // Show immediately.
qDebug("Showing tray icon immediately."); qDebugNN << LOGSEC_GUI << "Showing tray icon immediately.";
showPrivate(); showPrivate();
#else #else
// Delay avoids race conditions and tray icon is properly displayed. // Delay avoids race conditions and tray icon is properly displayed.
qDebug("Showing tray icon with 1000 ms delay."); qDebugNN << LOGSEC_GUI << "Showing tray icon with 1000 ms delay.";
QTimer::singleShot(1000, this, SLOT(showPrivate())); QTimer::singleShot(1000, this, SLOT(showPrivate()));
#endif #endif
} }

View File

@ -17,7 +17,7 @@ TabBar::TabBar(QWidget* parent) : QTabBar(parent) {
} }
TabBar::~TabBar() { TabBar::~TabBar() {
qDebug("Destroying TabBar instance."); qDebugNN << LOGSEC_GUI << "Destroying TabBar instance.";
} }
void TabBar::setTabType(int index, const TabBar::TabType& type) { void TabBar::setTabType(int index, const TabBar::TabType& type) {

View File

@ -33,7 +33,7 @@ TabWidget::TabWidget(QWidget* parent) : QTabWidget(parent), m_menuMain(nullptr)
} }
TabWidget::~TabWidget() { TabWidget::~TabWidget() {
qDebug("Destroying TabWidget instance."); qDebugNN << LOGSEC_GUI << "Destroying TabWidget instance.";
} }
void TabWidget::setupMainMenuButton() { void TabWidget::setupMainMenuButton() {

View File

@ -77,7 +77,7 @@ void TimeSpinBox::fixup(QString& input) const {
QValidator::State TimeSpinBox::validate(QString& input, int& pos) const { QValidator::State TimeSpinBox::validate(QString& input, int& pos) const {
Q_UNUSED(pos) Q_UNUSED(pos)
return (valueFromText(input) != -1.0) ? QValidator::Acceptable : QValidator::Intermediate; return (valueFromText(input) != -1.0) ? QValidator::State::Acceptable : QValidator::State::Intermediate;
} }
TimeSpinBox::Mode TimeSpinBox::mode() const { TimeSpinBox::Mode TimeSpinBox::mode() const {

View File

@ -47,7 +47,6 @@ HEADERS += core/feeddownloader.h \
exceptions/ioexception.h \ exceptions/ioexception.h \
gui/baselineedit.h \ gui/baselineedit.h \
gui/basetoolbar.h \ gui/basetoolbar.h \
gui/colorlabel.h \
gui/comboboxwithstatus.h \ gui/comboboxwithstatus.h \
gui/dialogs/formabout.h \ gui/dialogs/formabout.h \
gui/dialogs/formaddaccount.h \ gui/dialogs/formaddaccount.h \
@ -192,7 +191,6 @@ SOURCES += core/feeddownloader.cpp \
exceptions/ioexception.cpp \ exceptions/ioexception.cpp \
gui/baselineedit.cpp \ gui/baselineedit.cpp \
gui/basetoolbar.cpp \ gui/basetoolbar.cpp \
gui/colorlabel.cpp \
gui/comboboxwithstatus.cpp \ gui/comboboxwithstatus.cpp \
gui/dialogs/formabout.cpp \ gui/dialogs/formabout.cpp \
gui/dialogs/formaddaccount.cpp \ gui/dialogs/formaddaccount.cpp \

View File

@ -94,7 +94,7 @@ Application::Application(const QString& id, int& argc, char** argv)
} }
Application::~Application() { Application::~Application() {
qDebug("Destroying Application instance."); qDebugNN << LOGSEC_CORE << "Destroying Application instance.";
} }
void Application::reactOnForeignNotifications() { void Application::reactOnForeignNotifications() {
@ -104,11 +104,11 @@ void Application::reactOnForeignNotifications() {
void Application::hideOrShowMainForm() { void Application::hideOrShowMainForm() {
// Display main window. // Display main window.
if (qApp->settings()->value(GROUP(GUI), SETTING(GUI::MainWindowStartsHidden)).toBool() && SystemTrayIcon::isSystemTrayActivated()) { if (qApp->settings()->value(GROUP(GUI), SETTING(GUI::MainWindowStartsHidden)).toBool() && SystemTrayIcon::isSystemTrayActivated()) {
qDebug("Hiding the main window when the application is starting."); qDebugNN << LOGSEC_CORE << "Hiding the main window when the application is starting.";
mainForm()->switchVisibility(true); mainForm()->switchVisibility(true);
} }
else { else {
qDebug("Showing the main window when the application is starting."); qDebugNN << LOGSEC_CORE << "Showing the main window when the application is starting.";
mainForm()->show(); mainForm()->show();
} }
} }
@ -322,7 +322,11 @@ void Application::restoreDatabaseSettings(bool restore_database, bool restore_se
} }
void Application::processExecutionMessage(const QString& message) { void Application::processExecutionMessage(const QString& message) {
qDebug("Received '%s' execution message from another application instance.", qPrintable(message)); qDebugNN << LOGSEC_CORE
<< "Received '"
<< message
<< "' execution message from another application instance.";
const QStringList messages = message.split(ARGUMENTS_LIST_SEPARATOR); const QStringList messages = message.split(ARGUMENTS_LIST_SEPARATOR);
if (messages.contains(APP_QUIT_INSTANCE)) { if (messages.contains(APP_QUIT_INSTANCE)) {
@ -378,14 +382,14 @@ NetworkUrlInterceptor* Application::urlIinterceptor() {
void Application::showTrayIcon() { void Application::showTrayIcon() {
// Display tray icon if it is enabled and available. // Display tray icon if it is enabled and available.
if (SystemTrayIcon::isSystemTrayActivated()) { if (SystemTrayIcon::isSystemTrayActivated()) {
qDebug("Showing tray icon."); qDebugNN << LOGSEC_CORE << "Showing tray icon.";
trayIcon()->show(); trayIcon()->show();
} }
} }
void Application::deleteTrayIcon() { void Application::deleteTrayIcon() {
if (m_trayIcon != nullptr) { if (m_trayIcon != nullptr) {
qDebug("Disabling tray icon, deleting it and raising main application window."); qDebugNN << LOGSEC_CORE << "Disabling tray icon, deleting it and raising main application window.";
m_mainForm->display(); m_mainForm->display();
delete m_trayIcon; delete m_trayIcon;
m_trayIcon = nullptr; m_trayIcon = nullptr;
@ -406,28 +410,29 @@ void Application::showGuiMessage(const QString& title, const QString& message,
MessageBox::show(parent, QMessageBox::Icon(message_type), title, message); MessageBox::show(parent, QMessageBox::Icon(message_type), title, message);
} }
else { else {
qDebug("Silencing GUI message: '%s'.", qPrintable(message)); qDebugNN << LOGSEC_CORE << "Silencing GUI message: '" << message << "'.";
} }
} }
void Application::onCommitData(QSessionManager& manager) { void Application::onCommitData(QSessionManager& manager) {
qDebug("OS asked application to commit its data."); qDebugNN << LOGSEC_CORE << "OS asked application to commit its data.";
onAboutToQuit(); onAboutToQuit();
manager.setRestartHint(QSessionManager::RestartNever); manager.setRestartHint(QSessionManager::RestartHint::RestartNever);
manager.release(); manager.release();
} }
void Application::onSaveState(QSessionManager& manager) { void Application::onSaveState(QSessionManager& manager) {
qDebug("OS asked application to save its state."); qDebugNN << LOGSEC_CORE << "OS asked application to save its state.";
manager.setRestartHint(QSessionManager::RestartNever);
manager.setRestartHint(QSessionManager::RestartHint::RestartNever);
manager.release(); manager.release();
} }
void Application::onAboutToQuit() { void Application::onAboutToQuit() {
if (m_quitLogicDone) { if (m_quitLogicDone) {
qWarning("On-close logic is already done."); qWarningNN << LOGSEC_CORE << "On-close logic is already done.";
return; return;
} }
@ -441,7 +446,7 @@ void Application::onAboutToQuit() {
const bool locked_safely = feedUpdateLock()->tryLock(4 * CLOSE_LOCK_TIMEOUT); const bool locked_safely = feedUpdateLock()->tryLock(4 * CLOSE_LOCK_TIMEOUT);
processEvents(); processEvents();
qDebug("Cleaning up resources and saving application state."); qDebugNN << LOGSEC_CORE << "Cleaning up resources and saving application state.";
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
system()->removeTrolltechJunkRegistryKeys(); system()->removeTrolltechJunkRegistryKeys();
@ -449,7 +454,7 @@ void Application::onAboutToQuit() {
if (locked_safely) { if (locked_safely) {
// Application obtained permission to close in a safe way. // Application obtained permission to close in a safe way.
qDebug("Close lock was obtained safely."); qDebugNN << LOGSEC_CORE << "Close lock was obtained safely.";
// We locked the lock to exit peacefully, unlock it to avoid warnings. // We locked the lock to exit peacefully, unlock it to avoid warnings.
feedUpdateLock()->unlock(); feedUpdateLock()->unlock();
@ -457,7 +462,7 @@ void Application::onAboutToQuit() {
else { else {
// Request for write lock timed-out. This means // Request for write lock timed-out. This means
// that some critical action can be processed right now. // that some critical action can be processed right now.
qDebug("Close lock timed-out."); qWarningNN << LOGSEC_CORE << "Close lock timed-out.";
} }
qApp->feedReader()->quit(); qApp->feedReader()->quit();
@ -470,13 +475,13 @@ void Application::onAboutToQuit() {
// Now, we can check if application should just quit or restart itself. // Now, we can check if application should just quit or restart itself.
if (m_shouldRestart) { if (m_shouldRestart) {
finish(); finish();
qDebug("Killing local peer connection to allow another instance to start."); qDebugNN << LOGSEC_CORE << "Killing local peer connection to allow another instance to start.";
if (QProcess::startDetached(QDir::toNativeSeparators(applicationFilePath()), {})) { if (QProcess::startDetached(QDir::toNativeSeparators(applicationFilePath()), {})) {
qDebug("New application instance was started."); qDebugNN << LOGSEC_CORE << "New application instance was started.";
} }
else { else {
qWarning("New application instance was not started successfully."); qCriticalNN << LOGSEC_CORE << "New application instance was not started successfully.";
} }
} }
} }

View File

@ -6,6 +6,8 @@
#include <QDir> #include <QDir>
#include <QMetaObject> #include <QMetaObject>
#include "definitions/definitions.h"
#define AUTOSAVE_IN (1000 * 3) // seconds #define AUTOSAVE_IN (1000 * 3) // seconds
#define MAXWAIT (1000 * 15) // seconds #define MAXWAIT (1000 * 15) // seconds
@ -15,10 +17,10 @@ AutoSaver::AutoSaver(QObject* parent) : QObject(parent) {
AutoSaver::~AutoSaver() { AutoSaver::~AutoSaver() {
if (m_timer.isActive()) { if (m_timer.isActive()) {
qWarning("AutoSaver: still active when destroyed, changes not saved."); qWarningNN << LOGSEC_CORE << "AutoSaver still active when destroyed, changes not saved.";
if (parent() != nullptr && parent()->metaObject() != nullptr) { if (parent() != nullptr && parent()->metaObject() != nullptr) {
qWarning("Should call saveIfNeccessary."); qDebugNN << LOGSEC_CORE << "Should call saveIfNeccessary.";
} }
} }
} }
@ -51,7 +53,7 @@ void AutoSaver::saveIfNeccessary() {
m_firstChange.invalidate(); m_firstChange.invalidate();
if (!QMetaObject::invokeMethod(parent(), "save", Qt::DirectConnection)) { if (!QMetaObject::invokeMethod(parent(), "save", Qt::DirectConnection)) {
qWarning("AutoSaver: error invoking slot save() on parent."); qCriticalNN << LOGSEC_CORE << ("AutoSaver error invoking slot save() on parent.");
} }
} }
} }

View File

@ -11,7 +11,7 @@
DatabaseCleaner::DatabaseCleaner(QObject* parent) : QObject(parent) {} DatabaseCleaner::DatabaseCleaner(QObject* parent) : QObject(parent) {}
void DatabaseCleaner::purgeDatabaseData(const CleanerOrders& which_data) { void DatabaseCleaner::purgeDatabaseData(const CleanerOrders& which_data) {
qDebug().nospace() << "Performing database cleanup in thread: \'" << QThread::currentThreadId() << "\'."; qDebugNN << LOGSEC_DB << "Performing database cleanup in thread: '" << QThread::currentThreadId() << "'.";
// Inform everyone about the start of the process. // Inform everyone about the start of the process.
emit purgeStarted(); emit purgeStarted();

View File

@ -91,15 +91,18 @@ DatabaseFactory::MySQLError DatabaseFactory::mysqlTestConnection(const QString&
QSqlQuery query(QSL("SELECT version();"), database); QSqlQuery query(QSL("SELECT version();"), database);
if (!query.lastError().isValid() && query.next()) { if (!query.lastError().isValid() && query.next()) {
qDebug("Checked MySQL database, version is '%s'.", qPrintable(query.value(0).toString())); qDebugNN << LOGSEC_DB
<< "Checked MySQL database, version is '"
<< query.value(0).toString()
<< "'.";
// Connection succeeded, clean up the mess and return OK status. // Connection succeeded, clean up the mess and return OK status.
database.close(); database.close();
return MySQLError::MySQLOk; return MySQLError::Ok;
} }
else { else {
database.close(); database.close();
return MySQLError::MySQLUnknownError; return MySQLError::UnknownError;
} }
} }
else if (database.lastError().isValid()) { else if (database.lastError().isValid()) {
@ -111,37 +114,36 @@ DatabaseFactory::MySQLError DatabaseFactory::mysqlTestConnection(const QString&
return static_cast<MySQLError>(nat_int); return static_cast<MySQLError>(nat_int);
} }
else { else {
qWarning("Failed to recognize MySQL error code: '%s'.", qPrintable(nat)); qWarningNN << LOGSEC_DB
<< "Failed to recognize MySQL error code: '"
<< nat
<< "'.";
return MySQLError::MySQLUnknownError; return MySQLError::UnknownError;
} }
} }
else { else {
return MySQLError::MySQLUnknownError; return MySQLError::UnknownError;
} }
} }
QString DatabaseFactory::mysqlInterpretErrorCode(MySQLError error_code) const { QString DatabaseFactory::mysqlInterpretErrorCode(MySQLError error_code) const {
switch (error_code) { switch (error_code) {
case MySQLError::MySQLOk: case MySQLError::Ok:
return tr("MySQL server works as expected."); return tr("MySQL server works as expected.");
case MySQLError::MySQLUnknownDatabase: case MySQLError::UnknownDatabase:
return tr("Selected database does not exist (yet). It will be created. It's okay."); return tr("Selected database does not exist (yet). It will be created. It's okay.");
case MySQLError::MySQLCantConnect: case MySQLError::CantConnect:
case MySQLError::MySQLConnectionError: case MySQLError::ConnectionError:
case MySQLError::MySQLUnknownHost: case MySQLError::UnknownHost:
return tr("No MySQL server is running in the target destination."); return tr("No MySQL server is running in the target destination.");
case MySQLError::MySQLAccessDenied: case MySQLError::AccessDenied:
//: Access to MySQL server was denied.
return tr("Access denied. Invalid username or password used."); return tr("Access denied. Invalid username or password used.");
default: default:
//: Unknown MySQL error arised.
return tr("Unknown error: '%1'.").arg(int(error_code)); return tr("Unknown error: '%1'.").arg(int(error_code));
} }
} }
@ -167,14 +169,18 @@ void DatabaseFactory::finishRestoration() {
const QString backup_database_file = m_sqliteDatabaseFilePath + QDir::separator() + BACKUP_NAME_DATABASE + BACKUP_SUFFIX_DATABASE; const QString backup_database_file = m_sqliteDatabaseFilePath + QDir::separator() + BACKUP_NAME_DATABASE + BACKUP_SUFFIX_DATABASE;
if (QFile::exists(backup_database_file)) { if (QFile::exists(backup_database_file)) {
qWarning("Backup database file '%s' was detected. Restoring it.", qPrintable(QDir::toNativeSeparators(backup_database_file))); qDebugNN << LOGSEC_DB
<< "Backup database file '"
<< QDir::toNativeSeparators(backup_database_file)
<< "' was detected. Restoring it.";
if (IOFactory::copyFile(backup_database_file, m_sqliteDatabaseFilePath + QDir::separator() + APP_DB_SQLITE_FILE)) { if (IOFactory::copyFile(backup_database_file, m_sqliteDatabaseFilePath + QDir::separator() + APP_DB_SQLITE_FILE)) {
QFile::remove(backup_database_file); QFile::remove(backup_database_file);
qDebug("Database file was restored successully."); qDebugNN << LOGSEC_DB << "Database file was restored successully.";
} }
else { else {
qCritical("Database file was NOT restored due to error when copying the file."); qCriticalNN << LOGSEC_DB
<< "Database file was NOT restored due to error when copying the file.";
} }
} }
} }
@ -190,7 +196,8 @@ QSqlDatabase DatabaseFactory::sqliteInitializeInMemoryDatabase() {
database.setDatabaseName(QSL("file::memory:")); database.setDatabaseName(QSL("file::memory:"));
if (!database.open()) { if (!database.open()) {
qFatal("In-memory SQLite database was NOT opened. Delivered error message: '%s'", qPrintable(database.lastError().text())); qFatal("In-memory SQLite database was NOT opened. Delivered error message: '%s'",
qPrintable(database.lastError().text()));
} }
else { else {
QSqlQuery query_db(database); QSqlQuery query_db(database);
@ -208,7 +215,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeInMemoryDatabase() {
query_db.exec(QSL("SELECT inf_value FROM Information WHERE inf_key = 'schema_version'")); query_db.exec(QSL("SELECT inf_value FROM Information WHERE inf_key = 'schema_version'"));
if (query_db.lastError().isValid()) { if (query_db.lastError().isValid()) {
qWarning("Error occurred. In-memory SQLite database is not initialized. Initializing now."); qWarningNN << LOGSEC_DB << "Error occurred. In-memory SQLite database is not initialized. Initializing now.";
QFile file_init(APP_SQL_PATH + QDir::separator() + APP_DB_SQLITE_INIT); QFile file_init(APP_SQL_PATH + QDir::separator() + APP_DB_SQLITE_INIT);
if (!file_init.open(QIODevice::ReadOnly | QIODevice::Text)) { if (!file_init.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -231,17 +238,20 @@ QSqlDatabase DatabaseFactory::sqliteInitializeInMemoryDatabase() {
query_db.exec(statement); query_db.exec(statement);
if (query_db.lastError().isValid()) { if (query_db.lastError().isValid()) {
qFatal("In-memory SQLite database initialization failed. Initialization script '%s' is not correct.", APP_DB_SQLITE_INIT); qFatal("In-memory SQLite database initialization failed. Initialization script '%s' is not correct.",
APP_DB_SQLITE_INIT);
} }
} }
database.commit(); database.commit();
qDebug("In-memory SQLite database backend should be ready now."); qDebugNN << LOGSEC_DB << "In-memory SQLite database backend should be ready now.";
} }
else { else {
query_db.next(); query_db.next();
qDebug("In-memory SQLite database connection seems to be established."); qDebugNN << LOGSEC_DB << "In-memory SQLite database connection seems to be established.";
qDebug("In-memory SQLite database has version '%s'.", qPrintable(query_db.value(0).toString())); qDebugNN << LOGSEC_DB << "In-memory SQLite database has version '"
<< query_db.value(0).toString()
<< "'.";
} }
// Loading messages from file-based database. // Loading messages from file-based database.
@ -267,7 +277,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeInMemoryDatabase() {
copy_contents.exec(QString("INSERT INTO main.%1 SELECT * FROM storage.%1;").arg(table)); copy_contents.exec(QString("INSERT INTO main.%1 SELECT * FROM storage.%1;").arg(table));
} }
qDebug("Copying data from file-based database into working in-memory database."); qDebugNN << LOGSEC_DB << "Copying data from file-based database into working in-memory database.";
// Detach database and finish. // Detach database and finish.
copy_contents.exec(QSL("DETACH 'storage'")); copy_contents.exec(QSL("DETACH 'storage'"));
@ -322,7 +332,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString& c
// Sample query which checks for existence of tables. // Sample query which checks for existence of tables.
if (!query_db.exec(QSL("SELECT inf_value FROM Information WHERE inf_key = 'schema_version'"))) { if (!query_db.exec(QSL("SELECT inf_value FROM Information WHERE inf_key = 'schema_version'"))) {
qWarning("Error occurred. File-based SQLite database is not initialized. Initializing now."); qWarningNN << LOGSEC_DB << "Error occurred. File-based SQLite database is not initialized. Initializing now.";
QFile file_init(APP_SQL_PATH + QDir::separator() + APP_DB_SQLITE_INIT); QFile file_init(APP_SQL_PATH + QDir::separator() + APP_DB_SQLITE_INIT);
if (!file_init.open(QIODevice::ReadOnly | QIODevice::Text)) { if (!file_init.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -352,7 +362,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString& c
database.commit(); database.commit();
query_db.finish(); query_db.finish();
qDebug("File-based SQLite database backend should be ready now."); qDebugNN << LOGSEC_DB << "File-based SQLite database backend should be ready now.";
} }
else { else {
query_db.next(); query_db.next();
@ -362,9 +372,12 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString& c
if (installed_db_schema.toInt() < QString(APP_DB_SCHEMA_VERSION).toInt()) { if (installed_db_schema.toInt() < QString(APP_DB_SCHEMA_VERSION).toInt()) {
if (sqliteUpdateDatabaseSchema(database, installed_db_schema)) { if (sqliteUpdateDatabaseSchema(database, installed_db_schema)) {
qDebug("Database schema was updated from '%s' to '%s' successully or it is already up to date.", qDebugNN << LOGSEC_DB
qPrintable(installed_db_schema), << "Database schema was updated from '"
APP_DB_SCHEMA_VERSION); << installed_db_schema
<< "' to '"
<< APP_DB_SCHEMA_VERSION
<< "' successully or it is already up to date.";
} }
else { else {
qFatal("Database schema was not updated from '%s' to '%s' successully.", qFatal("Database schema was not updated from '%s' to '%s' successully.",
@ -373,10 +386,16 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString& c
} }
} }
qDebug("File-based SQLite database connection '%s' to file '%s' seems to be established.", qDebugNN << LOGSEC_DB
qPrintable(connection_name), << "File-based SQLite database connection '"
qPrintable(QDir::toNativeSeparators(database.databaseName()))); << connection_name
qDebug("File-based SQLite database has version '%s'.", qPrintable(installed_db_schema)); << "' to file '"
<< QDir::toNativeSeparators(database.databaseName())
<< "' seems to be established.";
qDebugNN << LOGSEC_DB
<< "File-based SQLite database has version '"
<< installed_db_schema
<< "'.";
} }
} }
@ -395,7 +414,7 @@ bool DatabaseFactory::sqliteUpdateDatabaseSchema(const QSqlDatabase& database, c
// Now, it would be good to create backup of SQLite DB file. // Now, it would be good to create backup of SQLite DB file.
if (IOFactory::copyFile(sqliteDatabaseFilePath(), sqliteDatabaseFilePath() + ".bak")) { if (IOFactory::copyFile(sqliteDatabaseFilePath(), sqliteDatabaseFilePath() + ".bak")) {
qDebug("Creating backup of SQLite DB file."); qDebugNN << LOGSEC_DB << "Creating backup of SQLite DB file.";
} }
else { else {
qFatal("Creation of backup SQLite DB file failed."); qFatal("Creation of backup SQLite DB file failed.");
@ -433,7 +452,13 @@ bool DatabaseFactory::sqliteUpdateDatabaseSchema(const QSqlDatabase& database, c
} }
// Increment the version. // Increment the version.
qDebug("Updating database schema: '%d' -> '%d'.", working_version, working_version + 1); qDebugNN << LOGSEC_DB
<< "Updating database schema: '"
<< working_version
<< "' -> '"
<< working_version + 1
<< "'.";
working_version++; working_version++;
} }
@ -478,7 +503,13 @@ bool DatabaseFactory::mysqlUpdateDatabaseSchema(const QSqlDatabase& database,
} }
// Increment the version. // Increment the version.
qDebug("Updating database schema: '%d' -> '%d'.", working_version, working_version + 1); qDebugNN << LOGSEC_DB
<< "Updating database schema: '"
<< working_version
<< "' -> '"
<< working_version + 1
<< "'.";
working_version++; working_version++;
} }
@ -522,7 +553,7 @@ QString DatabaseFactory::humanDriverName(const QString& driver_code) const {
} }
void DatabaseFactory::removeConnection(const QString& connection_name) { void DatabaseFactory::removeConnection(const QString& connection_name) {
qDebug("Removing database connection '%s'.", qPrintable(connection_name)); qDebugNN << LOGSEC_DB << "Removing database connection '" << connection_name << "'.";
QSqlDatabase::removeDatabase(connection_name); QSqlDatabase::removeDatabase(connection_name);
} }
@ -536,7 +567,7 @@ QString DatabaseFactory::obtainBeginTransactionSql() const {
} }
void DatabaseFactory::sqliteSaveMemoryDatabase() { void DatabaseFactory::sqliteSaveMemoryDatabase() {
qDebug("Saving in-memory working database back to persistent file-based storage."); qDebugNN << LOGSEC_DB << "Saving in-memory working database back to persistent file-based storage.";
QSqlDatabase database = sqliteConnection(QSL("SaveFromMemory"), DesiredType::StrictlyInMemory); QSqlDatabase database = sqliteConnection(QSL("SaveFromMemory"), DesiredType::StrictlyInMemory);
QSqlDatabase file_database = sqliteConnection(QSL("SaveToFile"), DesiredType::StrictlyFileBased); QSqlDatabase file_database = sqliteConnection(QSL("SaveToFile"), DesiredType::StrictlyFileBased);
@ -559,28 +590,37 @@ void DatabaseFactory::sqliteSaveMemoryDatabase() {
for (const QString& table : tables) { for (const QString& table : tables) {
if (copy_contents.exec(QString(QSL("DELETE FROM storage.%1;")).arg(table))) { if (copy_contents.exec(QString(QSL("DELETE FROM storage.%1;")).arg(table))) {
qDebug("Cleaning old data from 'storage.%s'.", qPrintable(table)); qDebugNN << LOGSEC_DB << "Cleaning old data from 'storage." << table << "'.";
} }
else { else {
qCritical("Failed to clean old data from 'storage.%s', error: '%s'.", qCriticalNN << LOGSEC_DB << "Failed to clean old data from 'storage."
qPrintable(table), qPrintable(copy_contents.lastError().text())); << table << "', error: '"
<< copy_contents.lastError().text() << "'.";
} }
if (copy_contents.exec(QString(QSL("INSERT INTO storage.%1 SELECT * FROM main.%1;")).arg(table))) { if (copy_contents.exec(QString(QSL("INSERT INTO storage.%1 SELECT * FROM main.%1;")).arg(table))) {
qDebug("Copying new data into 'main.%s'.", qPrintable(table)); qDebugNN << LOGSEC_DB << "Copying new data into 'main."
<< table << "'.";
} }
else { else {
qCritical("Failed to copy new data to 'main.%s', error: '%s'.", qCriticalNN << LOGSEC_DB
qPrintable(table), qPrintable(copy_contents.lastError().text())); << "Failed to copy new data to 'main."
<< table
<< "', error: '"
<< copy_contents.lastError().text()
<< "'.";
} }
} }
// Detach database and finish. // Detach database and finish.
if (copy_contents.exec(QSL("DETACH 'storage'"))) { if (copy_contents.exec(QSL("DETACH 'storage'"))) {
qDebug("Detaching persistent SQLite file."); qDebugNN << LOGSEC_DB << "Detaching persistent SQLite file.";
} }
else { else {
qCritical("Failed to detach SQLite file, error: '%s'.", qPrintable(copy_contents.lastError().text())); qCriticalNN << LOGSEC_DB
<< "Failed to detach SQLite file, error: '"
<< copy_contents.lastError().text()
<< "'.";
} }
copy_contents.finish(); copy_contents.finish();
@ -592,7 +632,7 @@ void DatabaseFactory::determineDriver() {
if (db_driver == APP_DB_MYSQL_DRIVER && QSqlDatabase::isDriverAvailable(APP_DB_SQLITE_DRIVER)) { if (db_driver == APP_DB_MYSQL_DRIVER && QSqlDatabase::isDriverAvailable(APP_DB_SQLITE_DRIVER)) {
// User wants to use MySQL and MySQL is actually available. Use it. // User wants to use MySQL and MySQL is actually available. Use it.
m_activeDatabaseDriver = UsedDriver::MYSQL; m_activeDatabaseDriver = UsedDriver::MYSQL;
qDebug("Working database source was as MySQL database."); qDebugNN << LOGSEC_DB << "Working database source was as MySQL database.";
} }
else { else {
// User wants to use SQLite, which is always available. Check if file-based // User wants to use SQLite, which is always available. Check if file-based
@ -600,12 +640,12 @@ void DatabaseFactory::determineDriver() {
if (qApp->settings()->value(GROUP(Database), SETTING(Database::UseInMemory)).toBool()) { if (qApp->settings()->value(GROUP(Database), SETTING(Database::UseInMemory)).toBool()) {
// Use in-memory SQLite database. // Use in-memory SQLite database.
m_activeDatabaseDriver = UsedDriver::SQLITE_MEMORY; m_activeDatabaseDriver = UsedDriver::SQLITE_MEMORY;
qDebug("Working database source was determined as SQLite in-memory database."); qDebugNN << LOGSEC_DB << "Working database source was determined as SQLite in-memory database.";
} }
else { else {
// Use strictly file-base SQLite database. // Use strictly file-base SQLite database.
m_activeDatabaseDriver = UsedDriver::SQLITE; m_activeDatabaseDriver = UsedDriver::SQLITE;
qDebug("Working database source was determined as SQLite file-based database."); qDebugNN << LOGSEC_DB << "Working database source was determined as SQLite file-based database.";
} }
sqliteAssemblyDatabaseFilePath(); sqliteAssemblyDatabaseFilePath();
@ -625,7 +665,10 @@ QSqlDatabase DatabaseFactory::mysqlConnection(const QString& connection_name) {
QSqlDatabase database; QSqlDatabase database;
if (QSqlDatabase::contains(connection_name)) { if (QSqlDatabase::contains(connection_name)) {
qDebug("MySQL connection '%s' is already active.", qPrintable(connection_name)); qDebugNN << LOGSEC_DB
<< "MySQL connection '"
<< connection_name
<< "' is already active.";
// This database connection was added previously, no need to // This database connection was added previously, no need to
// setup its properties. // setup its properties.
@ -647,9 +690,12 @@ QSqlDatabase DatabaseFactory::mysqlConnection(const QString& connection_name) {
qPrintable(database.lastError().text())); qPrintable(database.lastError().text()));
} }
else { else {
qDebug("MySQL database connection '%s' to file '%s' seems to be established.", qDebugNN << LOGSEC_DB
qPrintable(connection_name), << "MySQL database connection '"
qPrintable(QDir::toNativeSeparators(database.databaseName()))); << connection_name
<< "' to file '"
<< QDir::toNativeSeparators(database.databaseName())
<< "' seems to be established.";
} }
return database; return database;
@ -667,7 +713,10 @@ QSqlDatabase DatabaseFactory::mysqlInitializeDatabase(const QString& connection_
database.setPassword(qApp->settings()->password(GROUP(Database), SETTING(Database::MySQLPassword)).toString()); database.setPassword(qApp->settings()->password(GROUP(Database), SETTING(Database::MySQLPassword)).toString());
if (!database.open()) { if (!database.open()) {
qCritical("MySQL database was NOT opened. Delivered error message: '%s'", qPrintable(database.lastError().text())); qCriticalNN << LOGSEC_DB
<< "MySQL database was NOT opened. Delivered error message: '"
<< database.lastError().text()
<< "'.";
// Now, we will display error warning and return SQLite connection. // Now, we will display error warning and return SQLite connection.
// Also, we set the SQLite driver as active one. // Also, we set the SQLite driver as active one.
@ -686,7 +735,7 @@ QSqlDatabase DatabaseFactory::mysqlInitializeDatabase(const QString& connection_
if (!query_db.exec(QString("USE %1").arg(database_name)) if (!query_db.exec(QString("USE %1").arg(database_name))
|| !query_db.exec(QSL("SELECT inf_value FROM Information WHERE inf_key = 'schema_version'"))) { || !query_db.exec(QSL("SELECT inf_value FROM Information WHERE inf_key = 'schema_version'"))) {
// If no "rssguard" database exists or schema version is wrong, then initialize it. // If no "rssguard" database exists or schema version is wrong, then initialize it.
qWarning("Error occurred. MySQL database is not initialized. Initializing now."); qWarningNN << LOGSEC_DB << "Error occurred. MySQL database is not initialized. Initializing now.";
QFile file_init(APP_SQL_PATH + QDir::separator() + APP_DB_MYSQL_INIT); QFile file_init(APP_SQL_PATH + QDir::separator() + APP_DB_MYSQL_INIT);
if (!file_init.open(QIODevice::ReadOnly | QIODevice::Text)) { if (!file_init.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -716,7 +765,7 @@ QSqlDatabase DatabaseFactory::mysqlInitializeDatabase(const QString& connection_
} }
database.commit(); database.commit();
qDebug("MySQL database backend should be ready now."); qDebugNN << LOGSEC_DB << "MySQL database backend should be ready now.";
} }
else { else {
// Database was previously initialized. Now just check the schema version. // Database was previously initialized. Now just check the schema version.

View File

@ -27,13 +27,13 @@ class DatabaseFactory : public QObject {
// Describes possible MySQL-specific errors. // Describes possible MySQL-specific errors.
enum class MySQLError { enum class MySQLError {
MySQLOk = 0, Ok = 0,
MySQLUnknownError = 1, UnknownError = 1,
MySQLAccessDenied = 1045, AccessDenied = 1045,
MySQLUnknownDatabase = 1049, UnknownDatabase = 1049,
MySQLConnectionError = 2002, ConnectionError = 2002,
MySQLCantConnect = 2003, CantConnect = 2003,
MySQLUnknownHost = 2005 UnknownHost = 2005
}; };
// //