diff --git a/src/librssguard/core/message.cpp b/src/librssguard/core/message.cpp index 109a4aad4..f58887ceb 100644 --- a/src/librssguard/core/message.cpp +++ b/src/librssguard/core/message.cpp @@ -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(";"); + qDebugNN << LOGSEC_MESSAGEMODEL + << "Query for MSG duplicate identification is: '" + << full_query + << "'."; + q.setForwardOnly(true); q.prepare(full_query); diff --git a/src/librssguard/definitions/definitions.h b/src/librssguard/definitions/definitions.h index 216c8728e..01228854a 100755 --- a/src/librssguard/definitions/definitions.h +++ b/src/librssguard/definitions/definitions.h @@ -88,6 +88,7 @@ #define LOGSEC_MESSAGEMODEL "message-model: " #define LOGSEC_GUI "gui: " #define LOGSEC_CORE "core: " +#define LOGSEC_DB "database: " #define MAX_ZOOM_FACTOR 5.0f #define MIN_ZOOM_FACTOR 0.25f @@ -160,10 +161,6 @@ #define qCriticalNN qCritical().noquote().nospace() #endif -#ifndef qFatalNN -#define qFatalNN qFatal().noquote().nospace() -#endif - #ifndef qInfoNN #define qInfoNN qInfo().noquote().nospace() #endif diff --git a/src/librssguard/gui/basetoolbar.cpp b/src/librssguard/gui/basetoolbar.cpp index 707ec71bd..8714b1f50 100644 --- a/src/librssguard/gui/basetoolbar.cpp +++ b/src/librssguard/gui/basetoolbar.cpp @@ -17,7 +17,7 @@ BaseToolBar::BaseToolBar(const QString& title, QWidget* parent) : QToolBar(title } BaseToolBar::~BaseToolBar() { - qDebug("Destroying BaseToolBar instance."); + qDebugNN << LOGSEC_GUI << "Destroying BaseToolBar instance."; } void BaseBar::loadSavedActions() { diff --git a/src/librssguard/gui/colorlabel.cpp b/src/librssguard/gui/colorlabel.cpp deleted file mode 100644 index dc9c3ae77..000000000 --- a/src/librssguard/gui/colorlabel.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// For license of this file, see /LICENSE.md. - -#include "gui/colorlabel.h" - -#include -#include - -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); -} diff --git a/src/librssguard/gui/colorlabel.h b/src/librssguard/gui/colorlabel.h deleted file mode 100644 index 423d2c36d..000000000 --- a/src/librssguard/gui/colorlabel.h +++ /dev/null @@ -1,25 +0,0 @@ -// For license of this file, see /LICENSE.md. - -#ifndef COLORLABEL_H -#define COLORLABEL_H - -#include - -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 diff --git a/src/librssguard/gui/dialogs/formsettings.cpp b/src/librssguard/gui/dialogs/formsettings.cpp index 49d261092..dc996ce1d 100644 --- a/src/librssguard/gui/dialogs/formsettings.cpp +++ b/src/librssguard/gui/dialogs/formsettings.cpp @@ -43,7 +43,7 @@ FormSettings::FormSettings(QWidget& parent) } FormSettings::~FormSettings() { - qDebug("Destroying FormSettings distance."); + qDebugNN << LOGSEC_GUI << "Destroying FormSettings distance."; } void FormSettings::saveSettings() { diff --git a/src/librssguard/gui/dialogs/formupdate.cpp b/src/librssguard/gui/dialogs/formupdate.cpp index 13b73165c..ff0ee3d43 100644 --- a/src/librssguard/gui/dialogs/formupdate.cpp +++ b/src/librssguard/gui/dialogs/formupdate.cpp @@ -94,6 +94,7 @@ void FormUpdate::checkForUpdates() { } } }); + qApp->system()->checkForUpdates(); } @@ -133,12 +134,14 @@ void FormUpdate::saveUpdateFile(const QByteArray& file_contents) { m_readyToInstall = true; } else { - qDebug("Cannot save downloaded update file because target temporary file '%s' cannot be " - "opened for writing.", qPrintable(output_file_name)); + qDebugNN << LOGSEC_GUI + << "Cannot save downloaded update file because target temporary file '" + << output_file_name + << "' cannot be opened for writing."; } } 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) { - 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) { - case QNetworkReply::NoError: + case QNetworkReply::NetworkError::NoError: saveUpdateFile(contents); m_ui.m_lblStatus->setStatus(WidgetWithStatus::StatusType::Ok, tr("Downloaded successfully"), tr("Package was downloaded successfully.\nYou can install it now.")); @@ -200,7 +204,11 @@ void FormUpdate::startUpdate() { if (m_readyToInstall) { 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) HINSTANCE exec_result = ShellExecute(nullptr, nullptr, @@ -210,7 +218,7 @@ void FormUpdate::startUpdate() { SW_NORMAL); 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"), tr("Cannot launch external updater. Update application manually."), QSystemTrayIcon::Warning, this); @@ -219,6 +227,7 @@ void FormUpdate::startUpdate() { qApp->quit(); } #endif + } else if (update_for_this_system) { updateProgress(0, 100); diff --git a/src/librssguard/gui/feedmessageviewer.cpp b/src/librssguard/gui/feedmessageviewer.cpp index c0d653805..1f24665d3 100644 --- a/src/librssguard/gui/feedmessageviewer.cpp +++ b/src/librssguard/gui/feedmessageviewer.cpp @@ -64,7 +64,7 @@ FeedMessageViewer::FeedMessageViewer(QWidget* parent) : TabContent(parent), m_to } FeedMessageViewer::~FeedMessageViewer() { - qDebug("Destroying FeedMessageViewer instance."); + qDebugNN << LOGSEC_GUI << "Destroying FeedMessageViewer instance."; } #if defined(USE_WEBENGINE) diff --git a/src/librssguard/gui/feedsview.cpp b/src/librssguard/gui/feedsview.cpp index dc66aa8f5..e01b2f014 100755 --- a/src/librssguard/gui/feedsview.cpp +++ b/src/librssguard/gui/feedsview.cpp @@ -48,7 +48,7 @@ FeedsView::FeedsView(QWidget* parent) } FeedsView::~FeedsView() { - qDebug("Destroying FeedsView instance."); + qDebugNN << LOGSEC_GUI << "Destroying FeedsView instance."; } void FeedsView::reloadFontSettings() { diff --git a/src/librssguard/gui/messagebox.cpp b/src/librssguard/gui/messagebox.cpp index cf81845ee..474e8383f 100644 --- a/src/librssguard/gui/messagebox.cpp +++ b/src/librssguard/gui/messagebox.cpp @@ -36,16 +36,16 @@ void MessageBox::setCheckBox(QMessageBox* msg_box, const QString& text, bool* da QIcon MessageBox::iconForStatus(QMessageBox::Icon status) { switch (status) { - case QMessageBox::Information: + case QMessageBox::Icon::Information: return qApp->icons()->fromTheme(QSL("dialog-information")); - case QMessageBox::Warning: + case QMessageBox::Icon::Warning: return qApp->icons()->fromTheme(QSL("dialog-warning")); - case QMessageBox::Critical: + case QMessageBox::Icon::Critical: return qApp->icons()->fromTheme(QSL("dialog-error")); - case QMessageBox::Question: + case QMessageBox::Icon::Question: return qApp->icons()->fromTheme(QSL("dialog-question")); default: diff --git a/src/librssguard/gui/messagesview.cpp b/src/librssguard/gui/messagesview.cpp index 62a8d68bf..8288ebeda 100644 --- a/src/librssguard/gui/messagesview.cpp +++ b/src/librssguard/gui/messagesview.cpp @@ -42,7 +42,7 @@ MessagesView::MessagesView(QWidget* parent) : QTreeView(parent), m_contextMenu(n } MessagesView::~MessagesView() { - qDebug("Destroying MessagesView instance."); + qDebugNN << LOGSEC_GUI << "Destroying MessagesView instance."; } void MessagesView::reloadFontSettings() { @@ -128,7 +128,10 @@ void MessagesView::reloadSelections() { 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() { @@ -163,7 +166,7 @@ void MessagesView::focusInEvent(QFocusEvent* event) { void MessagesView::keyPressEvent(QKeyEvent* event) { QTreeView::keyPressEvent(event); - if (event->key() == Qt::Key_Delete) { + if (event->key() == Qt::Key::Key_Delete) { deleteSelectedMessages(); } } @@ -248,7 +251,7 @@ void MessagesView::mousePressEvent(QMouseEvent* event) { QTreeView::mousePressEvent(event); switch (event->button()) { - case Qt::LeftButton: { + case Qt::MouseButton::LeftButton: { // Make sure that message importance is switched when user // clicks the "important" column. const QModelIndex clicked_index = indexAt(event->pos()); @@ -266,7 +269,7 @@ void MessagesView::mousePressEvent(QMouseEvent* event) { break; } - case Qt::MiddleButton: { + case Qt::MouseButton::MiddleButton: { // Make sure that message importance is switched when user // clicks the "important" column. 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 mapped_current_index = m_proxyModel->mapToSource(current_index); - qDebug("Current row changed - row [%d,%d] source [%d, %d].", - current_index.row(), - current_index.column(), - mapped_current_index.row(), - mapped_current_index.column()); + qDebugNN << LOGSEC_GUI + << "Current row changed - proxy '" + << current_index << "', source '" + << mapped_current_index << "'."; if (mapped_current_index.isValid() && selected_rows.count() > 0) { Message message = m_sourceModel->messageAt(m_proxyModel->mapToSource(current_index).row()); diff --git a/src/librssguard/gui/messagetextbrowser.cpp b/src/librssguard/gui/messagetextbrowser.cpp index d957cf8fd..238ceec13 100644 --- a/src/librssguard/gui/messagetextbrowser.cpp +++ b/src/librssguard/gui/messagetextbrowser.cpp @@ -12,7 +12,7 @@ QVariant MessageTextBrowser::loadResource(int type, const QUrl& name) { Q_UNUSED(name) switch (type) { - case QTextDocument::ImageResource: { + case QTextDocument::ResourceType::ImageResource: { if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::DisplayImagePlaceholders)).toBool()) { if (m_imagePlaceholder.isNull()) { m_imagePlaceholder = qApp->icons()->miscPixmap(QSL("image-placeholder")).scaledToWidth(20, Qt::FastTransformation); diff --git a/src/librssguard/gui/newspaperpreviewer.cpp b/src/librssguard/gui/newspaperpreviewer.cpp index 82d875083..2fb275655 100644 --- a/src/librssguard/gui/newspaperpreviewer.cpp +++ b/src/librssguard/gui/newspaperpreviewer.cpp @@ -41,7 +41,7 @@ void NewspaperPreviewer::showMoreMessages() { else { qApp->showGuiMessage(tr("Cannot show more messages"), tr("Cannot show more messages because parent feed was removed."), - QSystemTrayIcon::Warning, + QSystemTrayIcon::MessageIcon::Warning, qApp->mainForm(), true); } } diff --git a/src/librssguard/gui/settings/settingsdatabase.cpp b/src/librssguard/gui/settings/settingsdatabase.cpp index c2f1e9003..0e770b326 100644 --- a/src/librssguard/gui/settings/settingsdatabase.cpp +++ b/src/librssguard/gui/settings/settingsdatabase.cpp @@ -52,8 +52,8 @@ void SettingsDatabase::mysqlTestConnection() { const QString interpretation = qApp->database()->mysqlInterpretErrorCode(error_code); switch (error_code) { - case DatabaseFactory::MySQLError::MySQLOk: - case DatabaseFactory::MySQLError::MySQLUnknownDatabase: + case DatabaseFactory::MySQLError::Ok: + case DatabaseFactory::MySQLError::UnknownDatabase: m_ui->m_lblMysqlTestResult->setStatus(WidgetWithStatus::StatusType::Ok, interpretation, interpretation); break; @@ -109,7 +109,10 @@ void SettingsDatabase::selectSqlBackend(int index) { m_ui->m_stackedDatabaseDriver->setCurrentIndex(1); } 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."; } } diff --git a/src/librssguard/gui/statusbar.cpp b/src/librssguard/gui/statusbar.cpp index de791b8a0..7ef78c2e0 100644 --- a/src/librssguard/gui/statusbar.cpp +++ b/src/librssguard/gui/statusbar.cpp @@ -49,14 +49,15 @@ StatusBar::StatusBar(QWidget* parent) : QStatusBar(parent), m_mutex(new Mutex(QM StatusBar::~StatusBar() { clear(); - qDebug("Destroying StatusBar instance."); + qDebugNN << LOGSEC_GUI "Destroying StatusBar instance."; } QList StatusBar::availableActions() const { QList actions = qApp->userActions(); // 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; } diff --git a/src/librssguard/gui/systemtrayicon.cpp b/src/librssguard/gui/systemtrayicon.cpp index 436ed89b4..91232acec 100644 --- a/src/librssguard/gui/systemtrayicon.cpp +++ b/src/librssguard/gui/systemtrayicon.cpp @@ -31,7 +31,7 @@ SystemTrayIcon::SystemTrayIcon(const QString& normal_icon, const QString& plain_ : QSystemTrayIcon(parent), m_normalIcon(normal_icon), m_plainPixmap(plain_icon) { - qDebug("Creating SystemTrayIcon instance."); + qDebugNN << LOGSEC_GUI << "Creating SystemTrayIcon instance."; m_font.setBold(true); // Initialize icon. @@ -43,7 +43,7 @@ SystemTrayIcon::SystemTrayIcon(const QString& normal_icon, const QString& plain_ } SystemTrayIcon::~SystemTrayIcon() { - qDebug("Destroying SystemTrayIcon instance."); + qDebugNN << LOGSEC_GUI << "Destroying SystemTrayIcon instance."; hide(); } @@ -82,19 +82,17 @@ void SystemTrayIcon::showPrivate() { QSystemTrayIcon::show(); emit shown(); - qDebug("Tray icon displayed."); + qDebugNN << LOGSEC_GUI << "Tray icon displayed."; } void SystemTrayIcon::show() { #if defined(Q_OS_WIN) - // Show immediately. - qDebug("Showing tray icon immediately."); + qDebugNN << LOGSEC_GUI << "Showing tray icon immediately."; showPrivate(); #else - // 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())); #endif } diff --git a/src/librssguard/gui/tabbar.cpp b/src/librssguard/gui/tabbar.cpp index fde45d09b..200041d54 100644 --- a/src/librssguard/gui/tabbar.cpp +++ b/src/librssguard/gui/tabbar.cpp @@ -17,7 +17,7 @@ TabBar::TabBar(QWidget* parent) : QTabBar(parent) { } TabBar::~TabBar() { - qDebug("Destroying TabBar instance."); + qDebugNN << LOGSEC_GUI << "Destroying TabBar instance."; } void TabBar::setTabType(int index, const TabBar::TabType& type) { diff --git a/src/librssguard/gui/tabwidget.cpp b/src/librssguard/gui/tabwidget.cpp index 71eeab61b..1ba44858b 100644 --- a/src/librssguard/gui/tabwidget.cpp +++ b/src/librssguard/gui/tabwidget.cpp @@ -33,7 +33,7 @@ TabWidget::TabWidget(QWidget* parent) : QTabWidget(parent), m_menuMain(nullptr) } TabWidget::~TabWidget() { - qDebug("Destroying TabWidget instance."); + qDebugNN << LOGSEC_GUI << "Destroying TabWidget instance."; } void TabWidget::setupMainMenuButton() { diff --git a/src/librssguard/gui/timespinbox.cpp b/src/librssguard/gui/timespinbox.cpp index 77e502ebb..abc91d8e3 100644 --- a/src/librssguard/gui/timespinbox.cpp +++ b/src/librssguard/gui/timespinbox.cpp @@ -77,7 +77,7 @@ void TimeSpinBox::fixup(QString& input) const { QValidator::State TimeSpinBox::validate(QString& input, int& pos) const { 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 { diff --git a/src/librssguard/librssguard.pro b/src/librssguard/librssguard.pro index 941e52649..be2bb6528 100644 --- a/src/librssguard/librssguard.pro +++ b/src/librssguard/librssguard.pro @@ -47,7 +47,6 @@ HEADERS += core/feeddownloader.h \ exceptions/ioexception.h \ gui/baselineedit.h \ gui/basetoolbar.h \ - gui/colorlabel.h \ gui/comboboxwithstatus.h \ gui/dialogs/formabout.h \ gui/dialogs/formaddaccount.h \ @@ -192,7 +191,6 @@ SOURCES += core/feeddownloader.cpp \ exceptions/ioexception.cpp \ gui/baselineedit.cpp \ gui/basetoolbar.cpp \ - gui/colorlabel.cpp \ gui/comboboxwithstatus.cpp \ gui/dialogs/formabout.cpp \ gui/dialogs/formaddaccount.cpp \ diff --git a/src/librssguard/miscellaneous/application.cpp b/src/librssguard/miscellaneous/application.cpp index 82d341ca8..71a22506f 100755 --- a/src/librssguard/miscellaneous/application.cpp +++ b/src/librssguard/miscellaneous/application.cpp @@ -94,7 +94,7 @@ Application::Application(const QString& id, int& argc, char** argv) } Application::~Application() { - qDebug("Destroying Application instance."); + qDebugNN << LOGSEC_CORE << "Destroying Application instance."; } void Application::reactOnForeignNotifications() { @@ -104,11 +104,11 @@ void Application::reactOnForeignNotifications() { void Application::hideOrShowMainForm() { // Display main window. 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); } 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(); } } @@ -322,7 +322,11 @@ void Application::restoreDatabaseSettings(bool restore_database, bool restore_se } 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); if (messages.contains(APP_QUIT_INSTANCE)) { @@ -378,14 +382,14 @@ NetworkUrlInterceptor* Application::urlIinterceptor() { void Application::showTrayIcon() { // Display tray icon if it is enabled and available. if (SystemTrayIcon::isSystemTrayActivated()) { - qDebug("Showing tray icon."); + qDebugNN << LOGSEC_CORE << "Showing tray icon."; trayIcon()->show(); } } void Application::deleteTrayIcon() { 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(); delete m_trayIcon; 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); } else { - qDebug("Silencing GUI message: '%s'.", qPrintable(message)); + qDebugNN << LOGSEC_CORE << "Silencing GUI message: '" << message << "'."; } } void Application::onCommitData(QSessionManager& manager) { - qDebug("OS asked application to commit its data."); + qDebugNN << LOGSEC_CORE << "OS asked application to commit its data."; onAboutToQuit(); - manager.setRestartHint(QSessionManager::RestartNever); + manager.setRestartHint(QSessionManager::RestartHint::RestartNever); manager.release(); } void Application::onSaveState(QSessionManager& manager) { - qDebug("OS asked application to save its state."); - manager.setRestartHint(QSessionManager::RestartNever); + qDebugNN << LOGSEC_CORE << "OS asked application to save its state."; + + manager.setRestartHint(QSessionManager::RestartHint::RestartNever); manager.release(); } void Application::onAboutToQuit() { if (m_quitLogicDone) { - qWarning("On-close logic is already done."); + qWarningNN << LOGSEC_CORE << "On-close logic is already done."; return; } @@ -441,7 +446,7 @@ void Application::onAboutToQuit() { const bool locked_safely = feedUpdateLock()->tryLock(4 * CLOSE_LOCK_TIMEOUT); processEvents(); - qDebug("Cleaning up resources and saving application state."); + qDebugNN << LOGSEC_CORE << "Cleaning up resources and saving application state."; #if defined(Q_OS_WIN) system()->removeTrolltechJunkRegistryKeys(); @@ -449,7 +454,7 @@ void Application::onAboutToQuit() { if (locked_safely) { // 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. feedUpdateLock()->unlock(); @@ -457,7 +462,7 @@ void Application::onAboutToQuit() { else { // Request for write lock timed-out. This means // that some critical action can be processed right now. - qDebug("Close lock timed-out."); + qWarningNN << LOGSEC_CORE << "Close lock timed-out."; } qApp->feedReader()->quit(); @@ -470,13 +475,13 @@ void Application::onAboutToQuit() { // Now, we can check if application should just quit or restart itself. if (m_shouldRestart) { 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()), {})) { - qDebug("New application instance was started."); + qDebugNN << LOGSEC_CORE << "New application instance was started."; } else { - qWarning("New application instance was not started successfully."); + qCriticalNN << LOGSEC_CORE << "New application instance was not started successfully."; } } } diff --git a/src/librssguard/miscellaneous/autosaver.cpp b/src/librssguard/miscellaneous/autosaver.cpp index 5658a1d00..25d4b06fa 100644 --- a/src/librssguard/miscellaneous/autosaver.cpp +++ b/src/librssguard/miscellaneous/autosaver.cpp @@ -6,6 +6,8 @@ #include #include +#include "definitions/definitions.h" + #define AUTOSAVE_IN (1000 * 3) // seconds #define MAXWAIT (1000 * 15) // seconds @@ -15,10 +17,10 @@ AutoSaver::AutoSaver(QObject* parent) : QObject(parent) { AutoSaver::~AutoSaver() { 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) { - qWarning("Should call saveIfNeccessary."); + qDebugNN << LOGSEC_CORE << "Should call saveIfNeccessary."; } } } @@ -51,7 +53,7 @@ void AutoSaver::saveIfNeccessary() { m_firstChange.invalidate(); 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."); } } } diff --git a/src/librssguard/miscellaneous/databasecleaner.cpp b/src/librssguard/miscellaneous/databasecleaner.cpp index 1d3e38712..f2071c77d 100644 --- a/src/librssguard/miscellaneous/databasecleaner.cpp +++ b/src/librssguard/miscellaneous/databasecleaner.cpp @@ -11,7 +11,7 @@ DatabaseCleaner::DatabaseCleaner(QObject* parent) : QObject(parent) {} 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. emit purgeStarted(); diff --git a/src/librssguard/miscellaneous/databasefactory.cpp b/src/librssguard/miscellaneous/databasefactory.cpp index 3b05df7b6..d344d0303 100644 --- a/src/librssguard/miscellaneous/databasefactory.cpp +++ b/src/librssguard/miscellaneous/databasefactory.cpp @@ -91,15 +91,18 @@ DatabaseFactory::MySQLError DatabaseFactory::mysqlTestConnection(const QString& QSqlQuery query(QSL("SELECT version();"), database); 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. database.close(); - return MySQLError::MySQLOk; + return MySQLError::Ok; } else { database.close(); - return MySQLError::MySQLUnknownError; + return MySQLError::UnknownError; } } else if (database.lastError().isValid()) { @@ -111,37 +114,36 @@ DatabaseFactory::MySQLError DatabaseFactory::mysqlTestConnection(const QString& return static_cast(nat_int); } 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 { - return MySQLError::MySQLUnknownError; + return MySQLError::UnknownError; } } QString DatabaseFactory::mysqlInterpretErrorCode(MySQLError error_code) const { switch (error_code) { - case MySQLError::MySQLOk: + case MySQLError::Ok: 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."); - case MySQLError::MySQLCantConnect: - case MySQLError::MySQLConnectionError: - case MySQLError::MySQLUnknownHost: + case MySQLError::CantConnect: + case MySQLError::ConnectionError: + case MySQLError::UnknownHost: return tr("No MySQL server is running in the target destination."); - case MySQLError::MySQLAccessDenied: - - //: Access to MySQL server was denied. + case MySQLError::AccessDenied: return tr("Access denied. Invalid username or password used."); default: - - //: Unknown MySQL error arised. 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; 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)) { QFile::remove(backup_database_file); - qDebug("Database file was restored successully."); + qDebugNN << LOGSEC_DB << "Database file was restored successully."; } 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:")); 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 { 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'")); 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); if (!file_init.open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -231,17 +238,20 @@ QSqlDatabase DatabaseFactory::sqliteInitializeInMemoryDatabase() { query_db.exec(statement); 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(); - qDebug("In-memory SQLite database backend should be ready now."); + qDebugNN << LOGSEC_DB << "In-memory SQLite database backend should be ready now."; } else { query_db.next(); - qDebug("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 connection seems to be established."; + qDebugNN << LOGSEC_DB << "In-memory SQLite database has version '" + << query_db.value(0).toString() + << "'."; } // 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)); } - 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. copy_contents.exec(QSL("DETACH 'storage'")); @@ -322,7 +332,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString& c // Sample query which checks for existence of tables. 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); if (!file_init.open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -352,7 +362,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString& c database.commit(); 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 { 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 (sqliteUpdateDatabaseSchema(database, installed_db_schema)) { - qDebug("Database schema was updated from '%s' to '%s' successully or it is already up to date.", - qPrintable(installed_db_schema), - APP_DB_SCHEMA_VERSION); + qDebugNN << LOGSEC_DB + << "Database schema was updated from '" + << installed_db_schema + << "' to '" + << APP_DB_SCHEMA_VERSION + << "' successully or it is already up to date."; } else { 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.", - qPrintable(connection_name), - qPrintable(QDir::toNativeSeparators(database.databaseName()))); - qDebug("File-based SQLite database has version '%s'.", qPrintable(installed_db_schema)); + qDebugNN << LOGSEC_DB + << "File-based SQLite database connection '" + << connection_name + << "' 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. if (IOFactory::copyFile(sqliteDatabaseFilePath(), sqliteDatabaseFilePath() + ".bak")) { - qDebug("Creating backup of SQLite DB file."); + qDebugNN << LOGSEC_DB << "Creating backup of SQLite DB file."; } else { qFatal("Creation of backup SQLite DB file failed."); @@ -433,7 +452,13 @@ bool DatabaseFactory::sqliteUpdateDatabaseSchema(const QSqlDatabase& database, c } // 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++; } @@ -478,7 +503,13 @@ bool DatabaseFactory::mysqlUpdateDatabaseSchema(const QSqlDatabase& database, } // 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++; } @@ -522,7 +553,7 @@ QString DatabaseFactory::humanDriverName(const QString& driver_code) const { } 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); } @@ -536,7 +567,7 @@ QString DatabaseFactory::obtainBeginTransactionSql() const { } 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 file_database = sqliteConnection(QSL("SaveToFile"), DesiredType::StrictlyFileBased); @@ -559,28 +590,37 @@ void DatabaseFactory::sqliteSaveMemoryDatabase() { for (const QString& table : tables) { 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 { - qCritical("Failed to clean old data from 'storage.%s', error: '%s'.", - qPrintable(table), qPrintable(copy_contents.lastError().text())); + qCriticalNN << LOGSEC_DB << "Failed to clean old data from 'storage." + << table << "', error: '" + << copy_contents.lastError().text() << "'."; } 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 { - qCritical("Failed to copy new data to 'main.%s', error: '%s'.", - qPrintable(table), qPrintable(copy_contents.lastError().text())); + qCriticalNN << LOGSEC_DB + << "Failed to copy new data to 'main." + << table + << "', error: '" + << copy_contents.lastError().text() + << "'."; } } // Detach database and finish. if (copy_contents.exec(QSL("DETACH 'storage'"))) { - qDebug("Detaching persistent SQLite file."); + qDebugNN << LOGSEC_DB << "Detaching persistent SQLite file."; } 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(); @@ -592,7 +632,7 @@ void DatabaseFactory::determineDriver() { 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. m_activeDatabaseDriver = UsedDriver::MYSQL; - qDebug("Working database source was as MySQL database."); + qDebugNN << LOGSEC_DB << "Working database source was as MySQL database."; } else { // 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()) { // Use in-memory SQLite database. 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 { // Use strictly file-base SQLite database. 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(); @@ -625,7 +665,10 @@ QSqlDatabase DatabaseFactory::mysqlConnection(const QString& connection_name) { QSqlDatabase database; 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 // setup its properties. @@ -647,9 +690,12 @@ QSqlDatabase DatabaseFactory::mysqlConnection(const QString& connection_name) { qPrintable(database.lastError().text())); } else { - qDebug("MySQL database connection '%s' to file '%s' seems to be established.", - qPrintable(connection_name), - qPrintable(QDir::toNativeSeparators(database.databaseName()))); + qDebugNN << LOGSEC_DB + << "MySQL database connection '" + << connection_name + << "' to file '" + << QDir::toNativeSeparators(database.databaseName()) + << "' seems to be established."; } return database; @@ -667,7 +713,10 @@ QSqlDatabase DatabaseFactory::mysqlInitializeDatabase(const QString& connection_ database.setPassword(qApp->settings()->password(GROUP(Database), SETTING(Database::MySQLPassword)).toString()); 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. // 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)) || !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. - 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); if (!file_init.open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -716,7 +765,7 @@ QSqlDatabase DatabaseFactory::mysqlInitializeDatabase(const QString& connection_ } database.commit(); - qDebug("MySQL database backend should be ready now."); + qDebugNN << LOGSEC_DB << "MySQL database backend should be ready now."; } else { // Database was previously initialized. Now just check the schema version. diff --git a/src/librssguard/miscellaneous/databasefactory.h b/src/librssguard/miscellaneous/databasefactory.h index ef566bcec..dae258833 100644 --- a/src/librssguard/miscellaneous/databasefactory.h +++ b/src/librssguard/miscellaneous/databasefactory.h @@ -27,13 +27,13 @@ class DatabaseFactory : public QObject { // Describes possible MySQL-specific errors. enum class MySQLError { - MySQLOk = 0, - MySQLUnknownError = 1, - MySQLAccessDenied = 1045, - MySQLUnknownDatabase = 1049, - MySQLConnectionError = 2002, - MySQLCantConnect = 2003, - MySQLUnknownHost = 2005 + Ok = 0, + UnknownError = 1, + AccessDenied = 1045, + UnknownDatabase = 1049, + ConnectionError = 2002, + CantConnect = 2003, + UnknownHost = 2005 }; //