refactoring pt. 1

This commit is contained in:
Martin Rotter 2019-04-12 07:12:13 +02:00
parent 484849dd0c
commit 7c8d4bd0a6
49 changed files with 165 additions and 179 deletions

View file

@ -30,7 +30,7 @@
<url type="donation">https://martinrotter.github.io/donate/</url> <url type="donation">https://martinrotter.github.io/donate/</url>
<content_rating type="oars-1.1" /> <content_rating type="oars-1.1" />
<releases> <releases>
<release version="3.5.7" date="2019-04-11"/> <release version="3.5.7" date="2019-04-12"/>
</releases> </releases>
<content_rating type="oars-1.0"> <content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute> <content_attribute id="violence-cartoon">none</content_attribute>

View file

@ -25,6 +25,8 @@
#include <algorithm> #include <algorithm>
using RootItemPtr = RootItem *;
FeedsModel::FeedsModel(QObject* parent) : QAbstractItemModel(parent), m_itemHeight(-1) { FeedsModel::FeedsModel(QObject* parent) : QAbstractItemModel(parent), m_itemHeight(-1) {
setObjectName(QSL("FeedsModel")); setObjectName(QSL("FeedsModel"));
@ -81,7 +83,6 @@ QStringList FeedsModel::mimeTypes() const {
return QStringList() << QSL(MIME_TYPE_ITEM_POINTER); return QStringList() << QSL(MIME_TYPE_ITEM_POINTER);
} }
typedef RootItem* RootItemPtr;
bool FeedsModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, bool FeedsModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column,
const QModelIndex& parent) { const QModelIndex& parent) {
Q_UNUSED(row) Q_UNUSED(row)

View file

@ -16,8 +16,8 @@
#include <QSqlField> #include <QSqlField>
MessagesModel::MessagesModel(QObject* parent) MessagesModel::MessagesModel(QObject* parent)
: QSqlQueryModel(parent), MessagesModelSqlLayer(), : QSqlQueryModel(parent), m_cache(new MessagesModelCache(this)), m_messageHighlighter(NoHighlighting),
m_cache(new MessagesModelCache(this)), m_messageHighlighter(NoHighlighting), m_customDateFormat(QString()), m_itemHeight(-1) { m_customDateFormat(QString()), m_selectedItem(nullptr), m_itemHeight(-1) {
setupFonts(); setupFonts();
setupIcons(); setupIcons();
setupHeaderData(); setupHeaderData();

View file

@ -4,9 +4,7 @@
#include "miscellaneous/textfactory.h" #include "miscellaneous/textfactory.h"
MessagesModelCache::MessagesModelCache(QObject* parent) : QObject(parent), m_msgCache(QHash<int, QSqlRecord>()) {} MessagesModelCache::MessagesModelCache(QObject* parent) : QObject(parent) {}
MessagesModelCache::~MessagesModelCache() {}
void MessagesModelCache::setData(const QModelIndex& index, const QVariant& value, const QSqlRecord& record) { void MessagesModelCache::setData(const QModelIndex& index, const QVariant& value, const QSqlRecord& record) {
if (!m_msgCache.contains(index.row())) { if (!m_msgCache.contains(index.row())) {

View file

@ -15,7 +15,7 @@ class MessagesModelCache : public QObject {
public: public:
explicit MessagesModelCache(QObject* parent = nullptr); explicit MessagesModelCache(QObject* parent = nullptr);
virtual ~MessagesModelCache(); virtual ~MessagesModelCache() = default;
inline bool containsData(int row_idx) const { inline bool containsData(int row_idx) const {
return m_msgCache.contains(row_idx); return m_msgCache.contains(row_idx);

View file

@ -5,10 +5,8 @@
#include "definitions/definitions.h" #include "definitions/definitions.h"
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
MessagesModelSqlLayer::MessagesModelSqlLayer() MessagesModelSqlLayer::MessagesModelSqlLayer() : m_filter(QSL(DEFAULT_SQL_MESSAGES_FILTER)) {
: m_filter(QSL(DEFAULT_SQL_MESSAGES_FILTER)), m_fieldNames(QMap<int, QString>()), m_db = qApp->database()->connection(QSL("MessagesModel"));
m_sortColumns(QList<int>()), m_sortOrders(QList<Qt::SortOrder>()) {
m_db = qApp->database()->connection(QSL("MessagesModel"), DatabaseFactory::FromSettings);
// Used in <x>: SELECT <x1>, <x2> FROM ....; // Used in <x>: SELECT <x1>, <x2> FROM ....;
m_fieldNames[MSG_DB_ID_INDEX] = "Messages.id"; m_fieldNames[MSG_DB_ID_INDEX] = "Messages.id";

View file

@ -80,7 +80,7 @@ QModelIndexList MessagesProxyModel::match(const QModelIndex& start, int role,
QModelIndexList result; QModelIndexList result;
const int match_type = flags & 0x0F; const int match_type = flags & 0x0F;
const Qt::CaseSensitivity case_sensitivity = Qt::CaseInsensitive; const Qt::CaseSensitivity case_sensitivity = Qt::CaseInsensitive;
const bool wrap = flags & Qt::MatchWrap; const bool wrap = (flags& Qt::MatchWrap) > 0;
const bool all_hits = (hits == -1); const bool all_hits = (hits == -1);
QString entered_text; QString entered_text;
int from = start.row(); int from = start.row();

View file

@ -8,8 +8,6 @@
#include <QAction> #include <QAction>
DynamicShortcuts::DynamicShortcuts() {}
void DynamicShortcuts::save(const QList<QAction*>& actions) { void DynamicShortcuts::save(const QList<QAction*>& actions) {
Settings* settings = qApp->settings(); Settings* settings = qApp->settings();

View file

@ -21,7 +21,7 @@ class DynamicShortcuts {
private: private:
// Constructor. // Constructor.
explicit DynamicShortcuts(); explicit DynamicShortcuts() = default;
}; };
#endif // DYNAMICSHORTCUTS_H #endif // DYNAMICSHORTCUTS_H

View file

@ -60,7 +60,7 @@ void DynamicShortcutsWidget::populate(QList<QAction*> actions) {
foreach (QAction* action, actions) { foreach (QAction* action, actions) {
// Create shortcut catcher for this action and set default shortcut. // Create shortcut catcher for this action and set default shortcut.
ShortcutCatcher* catcher = new ShortcutCatcher(this); auto* catcher = new ShortcutCatcher(this);
catcher->setDefaultShortcut(action->shortcut()); catcher->setDefaultShortcut(action->shortcut());
@ -72,12 +72,13 @@ void DynamicShortcutsWidget::populate(QList<QAction*> actions) {
m_actionBindings << new_binding; m_actionBindings << new_binding;
// Add new catcher to our control. // Add new catcher to our control.
QLabel* action_label = new QLabel(this); auto* action_label = new QLabel(this);
action_label->setText(action->text().remove(QSL("&"))); action_label->setText(action->text().remove(QSL("&")));
action_label->setToolTip(action->toolTip()); action_label->setToolTip(action->toolTip());
action_label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); action_label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
QLabel* action_icon = new QLabel(this);
auto* action_icon = new QLabel(this);
action_icon->setPixmap(action->icon().pixmap(ICON_SIZE_SETTINGS, ICON_SIZE_SETTINGS)); action_icon->setPixmap(action->icon().pixmap(ICON_SIZE_SETTINGS, ICON_SIZE_SETTINGS));
action_icon->setToolTip(action->toolTip()); action_icon->setToolTip(action->toolTip());

View file

@ -39,8 +39,6 @@ ShortcutButton::ShortcutButton(ShortcutCatcher* catcher, QWidget* parent)
setMinimumWidth(100); setMinimumWidth(100);
} }
ShortcutButton::~ShortcutButton() {}
void ShortcutButton::keyPressEvent(QKeyEvent* event) { void ShortcutButton::keyPressEvent(QKeyEvent* event) {
int pressed_key = event->key(); int pressed_key = event->key();
@ -48,7 +46,7 @@ void ShortcutButton::keyPressEvent(QKeyEvent* event) {
m_catcher->doneRecording(); m_catcher->doneRecording();
} }
const Qt::KeyboardModifiers new_modifiers = event->modifiers() & (Qt::SHIFT | Qt::CTRL | Qt::ALT | Qt::META); const int new_modifiers = event->modifiers() & (Qt::SHIFT | Qt::CTRL | Qt::ALT | Qt::META);
if (!m_catcher->m_isRecording && (pressed_key == Qt::Key_Return || pressed_key == Qt::Key_Space)) { if (!m_catcher->m_isRecording && (pressed_key == Qt::Key_Return || pressed_key == Qt::Key_Space)) {
return; return;
@ -78,8 +76,8 @@ void ShortcutButton::keyPressEvent(QKeyEvent* event) {
default: default:
// We now have a valid key press. // We now have a valid key press.
if (pressed_key) { if (pressed_key != 0) {
if ((pressed_key == Qt::Key_Backtab) && (m_catcher->m_modifierKeys & Qt::SHIFT)) { if ((pressed_key == Qt::Key_Backtab) && (m_catcher->m_modifierKeys & Qt::SHIFT) > 0) {
pressed_key = Qt::Key_Tab | m_catcher->m_modifierKeys; pressed_key = Qt::Key_Tab | m_catcher->m_modifierKeys;
} }
else { else {
@ -114,10 +112,9 @@ void ShortcutButton::keyReleaseEvent(QKeyEvent* event) {
} }
event->accept(); event->accept();
const Qt::KeyboardModifiers new_modifiers = event->modifiers() & const int new_modifiers = event->modifiers() & (Qt::SHIFT | Qt::CTRL | Qt::ALT | Qt::META);
(Qt::SHIFT | Qt::CTRL | Qt::ALT | Qt::META);
if (((uint) new_modifiers & m_catcher->m_modifierKeys) < m_catcher->m_modifierKeys) { if ((new_modifiers & m_catcher->m_modifierKeys) < m_catcher->m_modifierKeys) {
m_catcher->m_modifierKeys = new_modifiers; m_catcher->m_modifierKeys = new_modifiers;
m_catcher->controlModifierlessTimout(); m_catcher->controlModifierlessTimout();
m_catcher->updateDisplayShortcut(); m_catcher->updateDisplayShortcut();

View file

@ -41,8 +41,8 @@ class ShortcutButton : public QPushButton {
public: public:
// Constructors and destructors. // Constructors and destructors.
explicit ShortcutButton(ShortcutCatcher* catcher, QWidget* parent = 0); explicit ShortcutButton(ShortcutCatcher* catcher, QWidget* parent = nullptr);
virtual ~ShortcutButton(); virtual ~ShortcutButton() = default;
protected: protected:
void keyPressEvent(QKeyEvent* event); void keyPressEvent(QKeyEvent* event);

View file

@ -37,7 +37,7 @@
#include <QHBoxLayout> #include <QHBoxLayout>
ShortcutCatcher::ShortcutCatcher(QWidget* parent) ShortcutCatcher::ShortcutCatcher(QWidget* parent)
: QWidget(parent) { : QWidget(parent), m_isRecording(false), m_numKey(0), m_modifierKeys(0U) {
// Setup layout of the control // Setup layout of the control
m_layout = new QHBoxLayout(this); m_layout = new QHBoxLayout(this);
m_layout->setMargin(0); m_layout->setMargin(0);
@ -100,7 +100,7 @@ void ShortcutCatcher::doneRecording() {
} }
void ShortcutCatcher::controlModifierlessTimout() { void ShortcutCatcher::controlModifierlessTimout() {
if (m_numKey && !m_modifierKeys) { if (m_numKey != 0 && m_modifierKeys == 0) {
doneRecording(); doneRecording();
} }
} }
@ -111,24 +111,24 @@ void ShortcutCatcher::updateDisplayShortcut() {
str.replace(QL1S("&"), QL1S("&&")); str.replace(QL1S("&"), QL1S("&&"));
if (m_isRecording) { if (m_isRecording) {
if (m_modifierKeys) { if (m_modifierKeys != 0) {
if (!str.isEmpty()) { if (!str.isEmpty()) {
str.append(QSL(",")); str.append(QSL(","));
} }
if (m_modifierKeys & Qt::META) { if ((m_modifierKeys& Qt::META) > 0) {
str += QL1S("Meta + "); str += QL1S("Meta + ");
} }
if (m_modifierKeys & Qt::CTRL) { if ((m_modifierKeys& Qt::CTRL) > 0) {
str += QL1S("Ctrl + "); str += QL1S("Ctrl + ");
} }
if (m_modifierKeys & Qt::ALT) { if ((m_modifierKeys& Qt::ALT) > 0) {
str += QL1S("Alt + "); str += QL1S("Alt + ");
} }
if (m_modifierKeys & Qt::SHIFT) { if ((m_modifierKeys& Qt::SHIFT) > 0) {
str += QL1S("Shift + "); str += QL1S("Shift + ");
} }
} }

View file

@ -45,7 +45,7 @@ class ShortcutCatcher : public QWidget {
public: public:
// Constructors and destructors. // Constructors and destructors.
explicit ShortcutCatcher(QWidget* parent = 0); explicit ShortcutCatcher(QWidget* parent = nullptr);
virtual ~ShortcutCatcher(); virtual ~ShortcutCatcher();
void controlModifierlessTimout(); void controlModifierlessTimout();
@ -75,7 +75,7 @@ class ShortcutCatcher : public QWidget {
QKeySequence m_defaultSequence; QKeySequence m_defaultSequence;
bool m_isRecording; bool m_isRecording;
int m_numKey; int m_numKey;
uint m_modifierKeys; int m_modifierKeys;
}; };
#endif // KEYSEQUENCECATCHER_H #endif // KEYSEQUENCECATCHER_H

View file

@ -2,9 +2,7 @@
#include "exceptions/applicationexception.h" #include "exceptions/applicationexception.h"
ApplicationException::ApplicationException(const QString& message) : m_message(message) {} ApplicationException::ApplicationException(QString message) : m_message(std::move(message)) {}
ApplicationException::~ApplicationException() {}
QString ApplicationException::message() const { QString ApplicationException::message() const {
return m_message; return m_message;

View file

@ -7,8 +7,8 @@
class ApplicationException { class ApplicationException {
public: public:
explicit ApplicationException(const QString& message = QString()); explicit ApplicationException(QString message = QString());
virtual ~ApplicationException(); virtual ~ApplicationException() = default;
QString message() const; QString message() const;

View file

@ -3,5 +3,3 @@
#include "exceptions/ioexception.h" #include "exceptions/ioexception.h"
IOException::IOException(const QString& message) : ApplicationException(message) {} IOException::IOException(const QString& message) : ApplicationException(message) {}
IOException::~IOException() {}

View file

@ -8,7 +8,7 @@
class IOException : public ApplicationException { class IOException : public ApplicationException {
public: public:
explicit IOException(const QString& message = QString()); explicit IOException(const QString& message = QString());
virtual ~IOException(); virtual ~IOException() = default;
}; };
#endif // IOEXCEPTION_H #endif // IOEXCEPTION_H

View file

@ -92,7 +92,7 @@
<locale language="English" country="UnitedStates"/> <locale language="English" country="UnitedStates"/>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>3</number> <number>2</number>
</property> </property>
<widget class="QWidget" name="m_tabInfo"> <widget class="QWidget" name="m_tabInfo">
<attribute name="title"> <attribute name="title">

View file

@ -28,8 +28,8 @@ FormBackupDatabaseSettings::FormBackupDatabaseSettings(QWidget* parent) : QDialo
QDateTime::currentDateTime().toString(QSL("yyyyMMddHHmm"))); QDateTime::currentDateTime().toString(QSL("yyyyMMddHHmm")));
m_ui->m_lblResult->setStatus(WidgetWithStatus::Warning, tr("No operation executed yet."), tr("No operation executed yet.")); m_ui->m_lblResult->setStatus(WidgetWithStatus::Warning, tr("No operation executed yet."), tr("No operation executed yet."));
if (qApp->database()->activeDatabaseDriver() != DatabaseFactory::SQLITE && if (qApp->database()->activeDatabaseDriver() != DatabaseFactory::UsedDriver::SQLITE &&
qApp->database()->activeDatabaseDriver() != DatabaseFactory::SQLITE_MEMORY) { qApp->database()->activeDatabaseDriver() != DatabaseFactory::UsedDriver::SQLITE_MEMORY) {
m_ui->m_checkBackupDatabase->setDisabled(true); m_ui->m_checkBackupDatabase->setDisabled(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::MySQLOk: case DatabaseFactory::MySQLError::MySQLOk:
case DatabaseFactory::MySQLUnknownDatabase: case DatabaseFactory::MySQLError::MySQLUnknownDatabase:
m_ui->m_lblMysqlTestResult->setStatus(WidgetWithStatus::Ok, interpretation, interpretation); m_ui->m_lblMysqlTestResult->setStatus(WidgetWithStatus::Ok, interpretation, interpretation);
break; break;
@ -124,7 +124,7 @@ void SettingsDatabase::loadSettings() {
tr("You did not executed any connection test yet.")); tr("You did not executed any connection test yet."));
// Load SQLite. // Load SQLite.
m_ui->m_cmbDatabaseDriver->addItem(qApp->database()->humanDriverName(DatabaseFactory::SQLITE), APP_DB_SQLITE_DRIVER); m_ui->m_cmbDatabaseDriver->addItem(qApp->database()->humanDriverName(DatabaseFactory::UsedDriver::SQLITE), APP_DB_SQLITE_DRIVER);
// Load in-memory database status. // Load in-memory database status.
m_ui->m_checkSqliteUseInMemoryDatabase->setChecked(settings()->value(GROUP(Database), SETTING(Database::UseInMemory)).toBool()); m_ui->m_checkSqliteUseInMemoryDatabase->setChecked(settings()->value(GROUP(Database), SETTING(Database::UseInMemory)).toBool());
@ -136,7 +136,7 @@ void SettingsDatabase::loadSettings() {
onMysqlDatabaseChanged(QString()); onMysqlDatabaseChanged(QString());
// Load MySQL. // Load MySQL.
m_ui->m_cmbDatabaseDriver->addItem(qApp->database()->humanDriverName(DatabaseFactory::MYSQL), APP_DB_MYSQL_DRIVER); m_ui->m_cmbDatabaseDriver->addItem(qApp->database()->humanDriverName(DatabaseFactory::UsedDriver::MYSQL), APP_DB_MYSQL_DRIVER);
// Setup placeholders. // Setup placeholders.
m_ui->m_txtMysqlHostname->lineEdit()->setPlaceholderText(tr("Hostname of your MySQL server")); m_ui->m_txtMysqlHostname->lineEdit()->setPlaceholderText(tr("Hostname of your MySQL server"));

View file

@ -13,12 +13,12 @@
#include "network-web/webfactory.h" #include "network-web/webfactory.h"
#include "services/abstract/serviceroot.h" #include "services/abstract/serviceroot.h"
#include <QKeyEvent>
#include <QScrollBar> #include <QScrollBar>
#include <QToolBar> #include <QToolBar>
#include <QToolTip> #include <QToolTip>
#include <QWebEngineSettings> #include <QWebEngineSettings>
#include <QWidgetAction> #include <QWidgetAction>
#include <QKeyEvent>
WebBrowser::WebBrowser(QWidget* parent) : TabContent(parent), WebBrowser::WebBrowser(QWidget* parent) : TabContent(parent),
m_layout(new QVBoxLayout(this)), m_layout(new QVBoxLayout(this)),
@ -266,7 +266,7 @@ void WebBrowser::markMessageAsRead(int id, bool read) {
if (msg != nullptr && m_root->getParentServiceRoot()->onBeforeSetMessagesRead(m_root.data(), if (msg != nullptr && m_root->getParentServiceRoot()->onBeforeSetMessagesRead(m_root.data(),
QList<Message>() << *msg, QList<Message>() << *msg,
read ? RootItem::Read : RootItem::Unread)) { read ? RootItem::Read : RootItem::Unread)) {
DatabaseQueries::markMessagesReadUnread(qApp->database()->connection(objectName(), DatabaseFactory::FromSettings), DatabaseQueries::markMessagesReadUnread(qApp->database()->connection(objectName()),
QStringList() << QString::number(msg->m_id), QStringList() << QString::number(msg->m_id),
read ? RootItem::Read : RootItem::Unread); read ? RootItem::Read : RootItem::Unread);
m_root->getParentServiceRoot()->onAfterSetMessagesRead(m_root.data(), m_root->getParentServiceRoot()->onAfterSetMessagesRead(m_root.data(),
@ -292,7 +292,7 @@ void WebBrowser::switchMessageImportance(int id, bool checked) {
::NotImportant : ::NotImportant :
RootItem RootItem
::Important))) { ::Important))) {
DatabaseQueries::switchMessagesImportance(qApp->database()->connection(objectName(), DatabaseFactory::FromSettings), DatabaseQueries::switchMessagesImportance(qApp->database()->connection(objectName()),
QStringList() << QString::number(msg->m_id)); QStringList() << QString::number(msg->m_id));
m_root->getParentServiceRoot()->onAfterSwitchMessageImportance(m_root.data(), m_root->getParentServiceRoot()->onAfterSwitchMessageImportance(m_root.data(),
QList<ImportanceChange>() << ImportanceChange(*msg, QList<ImportanceChange>() << ImportanceChange(*msg,

View file

@ -44,7 +44,7 @@ Application::Application(const QString& id, int& argc, char** argv)
#endif #endif
m_feedReader(nullptr), m_feedReader(nullptr),
m_updateFeedsLock(new Mutex()), m_userActions(QList<QAction*>()), m_mainForm(nullptr), m_updateFeedsLock(new Mutex()), m_mainForm(nullptr),
m_trayIcon(nullptr), m_settings(Settings::setupSettings(this)), m_webFactory(new WebFactory(this)), m_trayIcon(nullptr), m_settings(Settings::setupSettings(this)), m_webFactory(new WebFactory(this)),
m_system(new SystemFactory(this)), m_skins(new SkinFactory(this)), m_system(new SystemFactory(this)), m_skins(new SkinFactory(this)),
m_localization(new Localization(this)), m_icons(new IconFactory(this)), m_localization(new Localization(this)), m_icons(new IconFactory(this)),
@ -238,8 +238,8 @@ void Application::backupDatabaseSettings(bool backup_database, bool backup_setti
} }
if (backup_database && if (backup_database &&
(database()->activeDatabaseDriver() == DatabaseFactory::SQLITE || (database()->activeDatabaseDriver() == DatabaseFactory::UsedDriver::SQLITE ||
database()->activeDatabaseDriver() == DatabaseFactory::SQLITE_MEMORY)) { database()->activeDatabaseDriver() == DatabaseFactory::UsedDriver::SQLITE_MEMORY)) {
// We need to save the database first. // We need to save the database first.
database()->saveDatabase(); database()->saveDatabase();
@ -334,11 +334,11 @@ void Application::showGuiMessage(const QString& title, const QString& message,
QSystemTrayIcon::MessageIcon message_type, QWidget* parent, QSystemTrayIcon::MessageIcon message_type, QWidget* parent,
bool show_at_least_msgbox, std::function<void()> functor) { bool show_at_least_msgbox, std::function<void()> functor) {
if (SystemTrayIcon::areNotificationsEnabled() && SystemTrayIcon::isSystemTrayActivated()) { if (SystemTrayIcon::areNotificationsEnabled() && SystemTrayIcon::isSystemTrayActivated()) {
trayIcon()->showMessage(title, message, message_type, TRAY_ICON_BUBBLE_TIMEOUT, functor); trayIcon()->showMessage(title, message, message_type, TRAY_ICON_BUBBLE_TIMEOUT, std::move(functor));
} }
else if (show_at_least_msgbox) { else if (show_at_least_msgbox) {
// Tray icon or OSD is not available, display simple text box. // Tray icon or OSD is not available, display simple text box.
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)); qDebug("Silencing GUI message: '%s'.", qPrintable(message));
@ -433,9 +433,9 @@ void Application::onFeedUpdatesProgress(const Feed* feed, int current, int total
Q_UNUSED(total) Q_UNUSED(total)
} }
void Application::onFeedUpdatesFinished(FeedDownloadResults results) { void Application::onFeedUpdatesFinished(const FeedDownloadResults& results) {
if (!results.updatedFeeds().isEmpty()) { if (!results.updatedFeeds().isEmpty()) {
// Now, inform about results via GUI message/notification. // Now, inform about results via GUI message/notification.
qApp->showGuiMessage(tr("New messages downloaded"), results.overview(10), QSystemTrayIcon::NoIcon, 0, false); qApp->showGuiMessage(tr("New messages downloaded"), results.overview(10), QSystemTrayIcon::NoIcon, nullptr, false);
} }
} }

View file

@ -136,7 +136,7 @@ class Application : public QtSingleApplication {
void onFeedUpdatesStarted(); void onFeedUpdatesStarted();
void onFeedUpdatesProgress(const Feed* feed, int current, int total); void onFeedUpdatesProgress(const Feed* feed, int current, int total);
void onFeedUpdatesFinished(FeedDownloadResults results); void onFeedUpdatesFinished(const FeedDownloadResults& results);
private: private:
void eliminateFirstRun(); void eliminateFirstRun();

View file

@ -6,8 +6,8 @@
#include <QDir> #include <QDir>
#include <QMetaObject> #include <QMetaObject>
#define AUTOSAVE_IN 1000 * 3 // seconds #define AUTOSAVE_IN (1000 * 3) // seconds
#define MAXWAIT 1000 * 15 // seconds #define MAXWAIT (1000 * 15) // seconds
AutoSaver::AutoSaver(QObject* parent) : QObject(parent) { AutoSaver::AutoSaver(QObject* parent) : QObject(parent) {
Q_ASSERT(parent); Q_ASSERT(parent);
@ -17,7 +17,7 @@ AutoSaver::~AutoSaver() {
if (m_timer.isActive()) { if (m_timer.isActive()) {
qWarning("AutoSaver: still active when destroyed, changes not saved."); qWarning("AutoSaver: still active when destroyed, changes not saved.");
if (parent() && parent()->metaObject()) { if (parent() != nullptr && parent()->metaObject() != nullptr) {
qWarning("Should call saveIfNeccessary."); qWarning("Should call saveIfNeccessary.");
} }
} }

View file

@ -10,8 +10,6 @@
DatabaseCleaner::DatabaseCleaner(QObject* parent) : QObject(parent) {} DatabaseCleaner::DatabaseCleaner(QObject* parent) : QObject(parent) {}
DatabaseCleaner::~DatabaseCleaner() {}
void DatabaseCleaner::purgeDatabaseData(const CleanerOrders& which_data) { void DatabaseCleaner::purgeDatabaseData(const CleanerOrders& which_data) {
qDebug().nospace() << "Performing database cleanup in thread: \'" << QThread::currentThreadId() << "\'."; qDebug().nospace() << "Performing database cleanup in thread: \'" << QThread::currentThreadId() << "\'.";
@ -20,7 +18,7 @@ void DatabaseCleaner::purgeDatabaseData(const CleanerOrders& which_data) {
bool result = true; bool result = true;
const int difference = 99 / 8; const int difference = 99 / 8;
int progress = 0; int progress = 0;
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
if (which_data.m_removeReadMessages) { if (which_data.m_removeReadMessages) {
progress += difference; progress += difference;

View file

@ -23,7 +23,7 @@ class DatabaseCleaner : public QObject {
// Constructors. // Constructors.
explicit DatabaseCleaner(QObject* parent = nullptr); explicit DatabaseCleaner(QObject* parent = nullptr);
virtual ~DatabaseCleaner(); virtual ~DatabaseCleaner() = default;
signals: signals:
void purgeStarted(); void purgeStarted();

View file

@ -14,6 +14,7 @@
DatabaseFactory::DatabaseFactory(QObject* parent) DatabaseFactory::DatabaseFactory(QObject* parent)
: QObject(parent), : QObject(parent),
m_activeDatabaseDriver(UsedDriver::SQLITE),
m_mysqlDatabaseInitialized(false), m_mysqlDatabaseInitialized(false),
m_sqliteFileBasedDatabaseinitialized(false), m_sqliteFileBasedDatabaseinitialized(false),
m_sqliteInMemoryDatabaseInitialized(false) { m_sqliteInMemoryDatabaseInitialized(false) {
@ -21,10 +22,8 @@ DatabaseFactory::DatabaseFactory(QObject* parent)
determineDriver(); determineDriver();
} }
DatabaseFactory::~DatabaseFactory() {}
qint64 DatabaseFactory::getDatabaseFileSize() const { qint64 DatabaseFactory::getDatabaseFileSize() const {
if (m_activeDatabaseDriver == SQLITE || m_activeDatabaseDriver == SQLITE_MEMORY) { if (m_activeDatabaseDriver == UsedDriver::SQLITE || m_activeDatabaseDriver == UsedDriver::SQLITE_MEMORY) {
return QFileInfo(sqliteDatabaseFilePath()).size(); return QFileInfo(sqliteDatabaseFilePath()).size();
} }
else { else {
@ -33,8 +32,8 @@ qint64 DatabaseFactory::getDatabaseFileSize() const {
} }
qint64 DatabaseFactory::getDatabaseDataSize() const { qint64 DatabaseFactory::getDatabaseDataSize() const {
if (m_activeDatabaseDriver == SQLITE || m_activeDatabaseDriver == SQLITE_MEMORY) { if (m_activeDatabaseDriver == UsedDriver::SQLITE || m_activeDatabaseDriver == UsedDriver::SQLITE_MEMORY) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DesiredType::FromSettings);
qint64 result = 1; qint64 result = 1;
QSqlQuery query(database); QSqlQuery query(database);
@ -56,8 +55,8 @@ qint64 DatabaseFactory::getDatabaseDataSize() const {
return result; return result;
} }
else if (m_activeDatabaseDriver == MYSQL) { else if (m_activeDatabaseDriver == UsedDriver::MYSQL) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DesiredType::FromSettings);
qint64 result = 1; qint64 result = 1;
QSqlQuery query(database); QSqlQuery query(database);
@ -97,11 +96,11 @@ DatabaseFactory::MySQLError DatabaseFactory::mysqlTestConnection(const QString&
// 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 MySQLOk; return MySQLError::MySQLOk;
} }
else { else {
database.close(); database.close();
return MySQLUnknownError; return MySQLError::MySQLUnknownError;
} }
} }
else if (database.lastError().isValid()) { else if (database.lastError().isValid()) {
@ -109,24 +108,24 @@ DatabaseFactory::MySQLError DatabaseFactory::mysqlTestConnection(const QString&
return static_cast<MySQLError>(database.lastError().number()); return static_cast<MySQLError>(database.lastError().number());
} }
else { else {
return MySQLUnknownError; return MySQLError::MySQLUnknownError;
} }
} }
QString DatabaseFactory::mysqlInterpretErrorCode(MySQLError error_code) const { QString DatabaseFactory::mysqlInterpretErrorCode(MySQLError error_code) const {
switch (error_code) { switch (error_code) {
case MySQLOk: case MySQLError::MySQLOk:
return tr("MySQL server works as expected."); return tr("MySQL server works as expected.");
case MySQLUnknownDatabase: case MySQLError::MySQLUnknownDatabase:
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 MySQLCantConnect: case MySQLError::MySQLCantConnect:
case MySQLConnectionError: case MySQLError::MySQLConnectionError:
case MySQLUnknownHost: case MySQLError::MySQLUnknownHost:
return tr("No MySQL server is running in the target destination."); return tr("No MySQL server is running in the target destination.");
case MySQLAccessDenied: case MySQLError::MySQLAccessDenied:
//: Access to MySQL server was denied. //: Access to MySQL server was denied.
return tr("Access denied. Invalid username or password used."); return tr("Access denied. Invalid username or password used.");
@ -140,8 +139,8 @@ QString DatabaseFactory::mysqlInterpretErrorCode(MySQLError error_code) const {
bool DatabaseFactory::initiateRestoration(const QString& database_backup_file_path) { bool DatabaseFactory::initiateRestoration(const QString& database_backup_file_path) {
switch (m_activeDatabaseDriver) { switch (m_activeDatabaseDriver) {
case SQLITE: case UsedDriver::SQLITE:
case SQLITE_MEMORY: case UsedDriver::SQLITE_MEMORY:
return IOFactory::copyFile(database_backup_file_path, return IOFactory::copyFile(database_backup_file_path,
m_sqliteDatabaseFilePath + QDir::separator() + m_sqliteDatabaseFilePath + QDir::separator() +
BACKUP_NAME_DATABASE + BACKUP_SUFFIX_DATABASE); BACKUP_NAME_DATABASE + BACKUP_SUFFIX_DATABASE);
@ -152,7 +151,7 @@ bool DatabaseFactory::initiateRestoration(const QString& database_backup_file_pa
} }
void DatabaseFactory::finishRestoration() { void DatabaseFactory::finishRestoration() {
if (m_activeDatabaseDriver != SQLITE && m_activeDatabaseDriver != SQLITE_MEMORY) { if (m_activeDatabaseDriver != UsedDriver::SQLITE && m_activeDatabaseDriver != UsedDriver::SQLITE_MEMORY) {
return; return;
} }
@ -231,7 +230,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeInMemoryDatabase() {
} }
// Loading messages from file-based database. // Loading messages from file-based database.
QSqlDatabase file_database = sqliteConnection(objectName(), StrictlyFileBased); QSqlDatabase file_database = sqliteConnection(objectName(), DesiredType::StrictlyFileBased);
QSqlQuery copy_contents(database); QSqlQuery copy_contents(database);
// Attach database. // Attach database.
@ -456,11 +455,11 @@ bool DatabaseFactory::mysqlUpdateDatabaseSchema(QSqlDatabase database, const QSt
QSqlDatabase DatabaseFactory::connection(const QString& connection_name, DesiredType desired_type) { QSqlDatabase DatabaseFactory::connection(const QString& connection_name, DesiredType desired_type) {
switch (m_activeDatabaseDriver) { switch (m_activeDatabaseDriver) {
case MYSQL: case UsedDriver::MYSQL:
return mysqlConnection(connection_name); return mysqlConnection(connection_name);
case SQLITE: case UsedDriver::SQLITE:
case SQLITE_MEMORY: case UsedDriver::SQLITE_MEMORY:
default: default:
return sqliteConnection(connection_name, desired_type); return sqliteConnection(connection_name, desired_type);
} }
@ -468,11 +467,11 @@ QSqlDatabase DatabaseFactory::connection(const QString& connection_name, Desired
QString DatabaseFactory::humanDriverName(DatabaseFactory::UsedDriver driver) const { QString DatabaseFactory::humanDriverName(DatabaseFactory::UsedDriver driver) const {
switch (driver) { switch (driver) {
case MYSQL: case UsedDriver::MYSQL:
return tr("MySQL/MariaDB (dedicated database)"); return tr("MySQL/MariaDB (dedicated database)");
case SQLITE: case UsedDriver::SQLITE:
case SQLITE_MEMORY: case UsedDriver::SQLITE_MEMORY:
default: default:
return tr("SQLite (embedded database)"); return tr("SQLite (embedded database)");
} }
@ -480,13 +479,13 @@ QString DatabaseFactory::humanDriverName(DatabaseFactory::UsedDriver driver) con
QString DatabaseFactory::humanDriverName(const QString& driver_code) const { QString DatabaseFactory::humanDriverName(const QString& driver_code) const {
if (driver_code == APP_DB_SQLITE_DRIVER) { if (driver_code == APP_DB_SQLITE_DRIVER) {
return humanDriverName(SQLITE); return humanDriverName(UsedDriver::SQLITE);
} }
else if (driver_code == APP_DB_MYSQL_DRIVER) { else if (driver_code == APP_DB_MYSQL_DRIVER) {
return humanDriverName(MYSQL); return humanDriverName(UsedDriver::MYSQL);
} }
else { else {
return humanDriverName(SQLITE); return humanDriverName(UsedDriver::SQLITE);
} }
} }
@ -496,7 +495,7 @@ void DatabaseFactory::removeConnection(const QString& connection_name) {
} }
QString DatabaseFactory::obtainBeginTransactionSql() const { QString DatabaseFactory::obtainBeginTransactionSql() const {
if (m_activeDatabaseDriver == DatabaseFactory::SQLITE || m_activeDatabaseDriver == DatabaseFactory::SQLITE_MEMORY) { if (m_activeDatabaseDriver == UsedDriver::SQLITE || m_activeDatabaseDriver == UsedDriver::SQLITE_MEMORY) {
return QSL("BEGIN IMMEDIATE TRANSACTION;"); return QSL("BEGIN IMMEDIATE TRANSACTION;");
} }
else { else {
@ -506,8 +505,8 @@ QString DatabaseFactory::obtainBeginTransactionSql() const {
void DatabaseFactory::sqliteSaveMemoryDatabase() { void DatabaseFactory::sqliteSaveMemoryDatabase() {
qDebug("Saving in-memory working database back to persistent file-based storage."); qDebug("Saving in-memory working database back to persistent file-based storage.");
QSqlDatabase database = sqliteConnection(objectName(), StrictlyInMemory); QSqlDatabase database = sqliteConnection(objectName(), DesiredType::StrictlyInMemory);
QSqlDatabase file_database = sqliteConnection(objectName(), StrictlyFileBased); QSqlDatabase file_database = sqliteConnection(objectName(), DesiredType::StrictlyFileBased);
QSqlQuery copy_contents(database); QSqlQuery copy_contents(database);
// Attach database. // Attach database.
@ -540,7 +539,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 = MYSQL; m_activeDatabaseDriver = UsedDriver::MYSQL;
qDebug("Working database source was as MySQL database."); qDebug("Working database source was as MySQL database.");
} }
else { else {
@ -548,12 +547,12 @@ void DatabaseFactory::determineDriver() {
// or in-memory database will be used. // or in-memory database will be used.
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 = SQLITE_MEMORY; m_activeDatabaseDriver = UsedDriver::SQLITE_MEMORY;
qDebug("Working database source was determined as SQLite in-memory database."); qDebug("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 = SQLITE; m_activeDatabaseDriver = UsedDriver::SQLITE;
qDebug("Working database source was determined as SQLite file-based database."); qDebug("Working database source was determined as SQLite file-based database.");
} }
@ -625,7 +624,7 @@ QSqlDatabase DatabaseFactory::mysqlInitializeDatabase(const QString& connection_
MessageBox::show(nullptr, QMessageBox::Critical, tr("MySQL database not available"), MessageBox::show(nullptr, QMessageBox::Critical, tr("MySQL database not available"),
tr("%1 cannot use MySQL storage, it is not available. %1 is now switching to SQLite database. Start your MySQL server " tr("%1 cannot use MySQL storage, it is not available. %1 is now switching to SQLite database. Start your MySQL server "
"and make adjustments in application settings.").arg(APP_NAME)); "and make adjustments in application settings.").arg(APP_NAME));
return connection(objectName(), FromSettings); return connection(objectName(), DesiredType::FromSettings);
} }
else { else {
QSqlQuery query_db(database); QSqlQuery query_db(database);
@ -697,8 +696,8 @@ bool DatabaseFactory::mysqlVacuumDatabase() {
} }
QSqlDatabase DatabaseFactory::sqliteConnection(const QString& connection_name, DatabaseFactory::DesiredType desired_type) { QSqlDatabase DatabaseFactory::sqliteConnection(const QString& connection_name, DatabaseFactory::DesiredType desired_type) {
if (desired_type == DatabaseFactory::StrictlyInMemory || if (desired_type == DesiredType::StrictlyInMemory ||
(desired_type == DatabaseFactory::FromSettings && m_activeDatabaseDriver == SQLITE_MEMORY)) { (desired_type == DesiredType::FromSettings && m_activeDatabaseDriver == UsedDriver::SQLITE_MEMORY)) {
// We request in-memory database (either user explicitly // We request in-memory database (either user explicitly
// needs in-memory database or it was enabled in the settings). // needs in-memory database or it was enabled in the settings).
if (!m_sqliteInMemoryDatabaseInitialized) { if (!m_sqliteInMemoryDatabaseInitialized) {
@ -768,12 +767,12 @@ QSqlDatabase DatabaseFactory::sqliteConnection(const QString& connection_name, D
bool DatabaseFactory::sqliteVacuumDatabase() { bool DatabaseFactory::sqliteVacuumDatabase() {
QSqlDatabase database; QSqlDatabase database;
if (m_activeDatabaseDriver == SQLITE) { if (m_activeDatabaseDriver == UsedDriver::SQLITE) {
database = sqliteConnection(objectName(), StrictlyFileBased); database = sqliteConnection(objectName(), DesiredType::StrictlyFileBased);
} }
else if (m_activeDatabaseDriver == SQLITE_MEMORY) { else if (m_activeDatabaseDriver == UsedDriver::SQLITE_MEMORY) {
sqliteSaveMemoryDatabase(); sqliteSaveMemoryDatabase();
database = sqliteConnection(objectName(), StrictlyFileBased); database = sqliteConnection(objectName(), DesiredType::StrictlyFileBased);
} }
else { else {
return false; return false;
@ -786,7 +785,7 @@ bool DatabaseFactory::sqliteVacuumDatabase() {
void DatabaseFactory::saveDatabase() { void DatabaseFactory::saveDatabase() {
switch (m_activeDatabaseDriver) { switch (m_activeDatabaseDriver) {
case SQLITE_MEMORY: case UsedDriver::SQLITE_MEMORY:
sqliteSaveMemoryDatabase(); sqliteSaveMemoryDatabase();
break; break;
@ -797,11 +796,11 @@ void DatabaseFactory::saveDatabase() {
bool DatabaseFactory::vacuumDatabase() { bool DatabaseFactory::vacuumDatabase() {
switch (m_activeDatabaseDriver) { switch (m_activeDatabaseDriver) {
case SQLITE_MEMORY: case UsedDriver::SQLITE_MEMORY:
case SQLITE: case UsedDriver::SQLITE:
return sqliteVacuumDatabase(); return sqliteVacuumDatabase();
case MYSQL: case UsedDriver::MYSQL:
return mysqlVacuumDatabase(); return mysqlVacuumDatabase();
default: default:

View file

@ -12,21 +12,21 @@ class DatabaseFactory : public QObject {
public: public:
// Describes available typos of database backend. // Describes available typos of database backend.
enum UsedDriver { enum class UsedDriver {
SQLITE, SQLITE,
SQLITE_MEMORY, SQLITE_MEMORY,
MYSQL MYSQL
}; };
// Describes what type of database user wants. // Describes what type of database user wants.
enum DesiredType { enum class DesiredType {
StrictlyFileBased, StrictlyFileBased,
StrictlyInMemory, StrictlyInMemory,
FromSettings FromSettings
}; };
// Describes possible MySQL-specific errors. // Describes possible MySQL-specific errors.
enum MySQLError { enum class MySQLError {
MySQLOk = 0, MySQLOk = 0,
MySQLUnknownError = 1, MySQLUnknownError = 1,
MySQLAccessDenied = 1045, MySQLAccessDenied = 1045,
@ -41,10 +41,10 @@ class DatabaseFactory : public QObject {
// //
// Constructor. // Constructor.
explicit DatabaseFactory(QObject* parent = 0); explicit DatabaseFactory(QObject* parent = nullptr);
// Destructor. // Destructor.
virtual ~DatabaseFactory(); virtual ~DatabaseFactory() = default;
// Returns size of DB file. // Returns size of DB file.
qint64 getDatabaseFileSize() const; qint64 getDatabaseFileSize() const;
@ -55,7 +55,7 @@ class DatabaseFactory : public QObject {
// If in-memory is true, then :memory: database is returned // If in-memory is true, then :memory: database is returned
// In-memory database is DEFAULT database. // In-memory database is DEFAULT database.
// NOTE: This always returns OPENED database. // NOTE: This always returns OPENED database.
QSqlDatabase connection(const QString& connection_name, DesiredType desired_type = FromSettings); QSqlDatabase connection(const QString& connection_name, DesiredType desired_type = DesiredType::FromSettings);
QString humanDriverName(UsedDriver driver) const; QString humanDriverName(UsedDriver driver) const;
QString humanDriverName(const QString& driver_code) const; QString humanDriverName(const QString& driver_code) const;

View file

@ -50,7 +50,7 @@ void Category::updateCounts(bool including_total_count) {
return; return;
} }
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
bool ok; bool ok;
QMap<QString, QPair<int, int>> counts = DatabaseQueries::getMessageCountsForCategory(database, QMap<QString, QPair<int, int>> counts = DatabaseQueries::getMessageCountsForCategory(database,

View file

@ -58,7 +58,7 @@ Feed::Feed(const Feed& other) : RootItem(other) {
Feed::~Feed() {} Feed::~Feed() {}
QList<Message> Feed::undeletedMessages() const { QList<Message> Feed::undeletedMessages() const {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
return DatabaseQueries::getUndeletedMessagesForFeed(database, customId(), getParentServiceRoot()->accountId()); return DatabaseQueries::getUndeletedMessagesForFeed(database, customId(), getParentServiceRoot()->accountId());
} }
@ -151,8 +151,8 @@ void Feed::setUrl(const QString& url) {
void Feed::updateCounts(bool including_total_count) { void Feed::updateCounts(bool including_total_count) {
bool is_main_thread = QThread::currentThread() == qApp->thread(); bool is_main_thread = QThread::currentThread() == qApp->thread();
QSqlDatabase database = is_main_thread ? QSqlDatabase database = is_main_thread ?
qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings) : qApp->database()->connection(metaObject()->className()) :
qApp->database()->connection(QSL("feed_upd"), DatabaseFactory::FromSettings); qApp->database()->connection(QSL("feed_upd"));
int account_id = getParentServiceRoot()->accountId(); int account_id = getParentServiceRoot()->accountId();
if (including_total_count) { if (including_total_count) {
@ -227,8 +227,8 @@ int Feed::updateMessages(const QList<Message>& messages, bool error_during_obtai
QString custom_id = customId(); QString custom_id = customId();
int account_id = getParentServiceRoot()->accountId(); int account_id = getParentServiceRoot()->accountId();
QSqlDatabase database = is_main_thread ? QSqlDatabase database = is_main_thread ?
qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings) : qApp->database()->connection(metaObject()->className()) :
qApp->database()->connection(QSL("feed_upd"), DatabaseFactory::FromSettings); qApp->database()->connection(QSL("feed_upd"));
updated_messages = DatabaseQueries::updateMessages(database, messages, custom_id, account_id, url(), &anything_updated, &ok); updated_messages = DatabaseQueries::updateMessages(database, messages, custom_id, account_id, url(), &anything_updated, &ok);
} }

View file

@ -38,8 +38,8 @@ int RecycleBin::countOfAllMessages() const {
void RecycleBin::updateCounts(bool update_total_count) { void RecycleBin::updateCounts(bool update_total_count) {
bool is_main_thread = QThread::currentThread() == qApp->thread(); bool is_main_thread = QThread::currentThread() == qApp->thread();
QSqlDatabase database = is_main_thread ? QSqlDatabase database = is_main_thread ?
qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings) : qApp->database()->connection(metaObject()->className()) :
qApp->database()->connection(QSL("feed_upd"), DatabaseFactory::FromSettings); qApp->database()->connection(QSL("feed_upd"));
m_unreadCount = DatabaseQueries::getMessageCountsForBin(database, getParentServiceRoot()->accountId(), false); m_unreadCount = DatabaseQueries::getMessageCountsForBin(database, getParentServiceRoot()->accountId(), false);
@ -69,13 +69,13 @@ QList<QAction*> RecycleBin::contextMenu() {
QList<Message> RecycleBin::undeletedMessages() const { QList<Message> RecycleBin::undeletedMessages() const {
const int account_id = getParentServiceRoot()->accountId(); const int account_id = getParentServiceRoot()->accountId();
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
return DatabaseQueries::getUndeletedMessagesForBin(database, account_id); return DatabaseQueries::getUndeletedMessagesForBin(database, account_id);
} }
bool RecycleBin::markAsReadUnread(RootItem::ReadStatus status) { bool RecycleBin::markAsReadUnread(RootItem::ReadStatus status) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
ServiceRoot* parent_root = getParentServiceRoot(); ServiceRoot* parent_root = getParentServiceRoot();
CacheForServiceRoot* cache = dynamic_cast<CacheForServiceRoot*>(parent_root); CacheForServiceRoot* cache = dynamic_cast<CacheForServiceRoot*>(parent_root);
@ -95,7 +95,7 @@ bool RecycleBin::markAsReadUnread(RootItem::ReadStatus status) {
} }
bool RecycleBin::cleanMessages(bool clear_only_read) { bool RecycleBin::cleanMessages(bool clear_only_read) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
ServiceRoot* parent_root = getParentServiceRoot(); ServiceRoot* parent_root = getParentServiceRoot();
if (DatabaseQueries::purgeMessagesFromBin(database, clear_only_read, parent_root->accountId())) { if (DatabaseQueries::purgeMessagesFromBin(database, clear_only_read, parent_root->accountId())) {
@ -114,7 +114,7 @@ bool RecycleBin::empty() {
} }
bool RecycleBin::restore() { bool RecycleBin::restore() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
ServiceRoot* parent_root = getParentServiceRoot(); ServiceRoot* parent_root = getParentServiceRoot();
if (DatabaseQueries::restoreBin(database, parent_root->accountId())) { if (DatabaseQueries::restoreBin(database, parent_root->accountId())) {

View file

@ -21,7 +21,7 @@ ServiceRoot::ServiceRoot(RootItem* parent) : RootItem(parent), m_recycleBin(new
ServiceRoot::~ServiceRoot() {} ServiceRoot::~ServiceRoot() {}
bool ServiceRoot::deleteViaGui() { bool ServiceRoot::deleteViaGui() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
if (DatabaseQueries::deleteAccount(database, accountId())) { if (DatabaseQueries::deleteAccount(database, accountId())) {
stop(); stop();
@ -40,7 +40,7 @@ bool ServiceRoot::markAsReadUnread(RootItem::ReadStatus status) {
cache->addMessageStatesToCache(customIDSOfMessagesForItem(this), status); cache->addMessageStatesToCache(customIDSOfMessagesForItem(this), status);
} }
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
if (DatabaseQueries::markAccountReadUnread(database, accountId(), status)) { if (DatabaseQueries::markAccountReadUnread(database, accountId(), status)) {
updateCounts(false); updateCounts(false);
@ -96,7 +96,7 @@ void ServiceRoot::updateCounts(bool including_total_count) {
return; return;
} }
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
bool ok; bool ok;
QMap<QString, QPair<int, int>> counts = DatabaseQueries::getMessageCountsForAccount(database, accountId(), including_total_count, &ok); QMap<QString, QPair<int, int>> counts = DatabaseQueries::getMessageCountsForAccount(database, accountId(), including_total_count, &ok);
@ -131,7 +131,7 @@ void ServiceRoot::completelyRemoveAllData() {
} }
void ServiceRoot::removeOldFeedTree(bool including_messages) { void ServiceRoot::removeOldFeedTree(bool including_messages) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
DatabaseQueries::deleteAccountData(database, accountId(), including_messages); DatabaseQueries::deleteAccountData(database, accountId(), including_messages);
} }
@ -145,7 +145,7 @@ void ServiceRoot::cleanAllItems() {
} }
bool ServiceRoot::cleanFeeds(QList<Feed*> items, bool clean_read_only) { bool ServiceRoot::cleanFeeds(QList<Feed*> items, bool clean_read_only) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
if (DatabaseQueries::cleanFeeds(database, textualFeedIds(items), clean_read_only, accountId())) { if (DatabaseQueries::cleanFeeds(database, textualFeedIds(items), clean_read_only, accountId())) {
// Messages are cleared, now inform model about need to reload data. // Messages are cleared, now inform model about need to reload data.
@ -173,7 +173,7 @@ bool ServiceRoot::cleanFeeds(QList<Feed*> items, bool clean_read_only) {
} }
void ServiceRoot::storeNewFeedTree(RootItem* root) { void ServiceRoot::storeNewFeedTree(RootItem* root) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
if (DatabaseQueries::storeAccountTree(database, root, accountId())) { if (DatabaseQueries::storeAccountTree(database, root, accountId())) {
RecycleBin* bin = recycleBin(); RecycleBin* bin = recycleBin();
@ -187,13 +187,13 @@ void ServiceRoot::storeNewFeedTree(RootItem* root) {
} }
void ServiceRoot::removeLeftOverMessages() { void ServiceRoot::removeLeftOverMessages() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
DatabaseQueries::purgeLeftoverMessages(database, accountId()); DatabaseQueries::purgeLeftoverMessages(database, accountId());
} }
QList<Message> ServiceRoot::undeletedMessages() const { QList<Message> ServiceRoot::undeletedMessages() const {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
return DatabaseQueries::getUndeletedMessagesForAccount(database, accountId()); return DatabaseQueries::getUndeletedMessagesForAccount(database, accountId());
} }
@ -348,21 +348,21 @@ QStringList ServiceRoot::customIDSOfMessagesForItem(RootItem* item) {
} }
case RootItemKind::ServiceRoot: { case RootItemKind::ServiceRoot: {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
list = DatabaseQueries::customIdsOfMessagesFromAccount(database, accountId()); list = DatabaseQueries::customIdsOfMessagesFromAccount(database, accountId());
break; break;
} }
case RootItemKind::Bin: { case RootItemKind::Bin: {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
list = DatabaseQueries::customIdsOfMessagesFromBin(database, accountId()); list = DatabaseQueries::customIdsOfMessagesFromBin(database, accountId());
break; break;
} }
case RootItemKind::Feed: { case RootItemKind::Feed: {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
list = DatabaseQueries::customIdsOfMessagesFromFeed(database, item->customId(), accountId()); list = DatabaseQueries::customIdsOfMessagesFromFeed(database, item->customId(), accountId());
break; break;
@ -378,7 +378,7 @@ QStringList ServiceRoot::customIDSOfMessagesForItem(RootItem* item) {
} }
bool ServiceRoot::markFeedsReadUnread(QList<Feed*> items, RootItem::ReadStatus read) { bool ServiceRoot::markFeedsReadUnread(QList<Feed*> items, RootItem::ReadStatus read) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
if (DatabaseQueries::markFeedsReadUnread(database, textualFeedIds(items), accountId(), read)) { if (DatabaseQueries::markFeedsReadUnread(database, textualFeedIds(items), accountId(), read)) {
QList<RootItem*> itemss; QList<RootItem*> itemss;

View file

@ -19,7 +19,7 @@ ServiceRoot* GmailEntryPoint::createNewRoot() const {
} }
QList<ServiceRoot*> GmailEntryPoint::initializeSubtree() const { QList<ServiceRoot*> GmailEntryPoint::initializeSubtree() const {
QSqlDatabase database = qApp->database()->connection(QSL("GmailEntryPoint"), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(QSL("GmailEntryPoint"));
return DatabaseQueries::getGmailAccounts(database); return DatabaseQueries::getGmailAccounts(database);
} }

View file

@ -58,7 +58,7 @@ void GmailServiceRoot::writeNewEmail() {
} }
void GmailServiceRoot::loadFromDatabase() { void GmailServiceRoot::loadFromDatabase() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
Assignment categories = DatabaseQueries::getCategories(database, accountId()); Assignment categories = DatabaseQueries::getCategories(database, accountId());
Assignment feeds = DatabaseQueries::getGmailFeeds(database, accountId()); Assignment feeds = DatabaseQueries::getGmailFeeds(database, accountId());
@ -77,7 +77,7 @@ void GmailServiceRoot::loadFromDatabase() {
} }
void GmailServiceRoot::saveAccountDataToDatabase() { void GmailServiceRoot::saveAccountDataToDatabase() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
if (accountId() != NO_PARENT_CATEGORY) { if (accountId() != NO_PARENT_CATEGORY) {
if (DatabaseQueries::overwriteGmailAccount(database, m_network->userName(), if (DatabaseQueries::overwriteGmailAccount(database, m_network->userName(),
@ -229,7 +229,7 @@ bool GmailServiceRoot::canBeDeleted() const {
} }
bool GmailServiceRoot::deleteViaGui() { bool GmailServiceRoot::deleteViaGui() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
if (DatabaseQueries::deleteGmailAccount(database, accountId())) { if (DatabaseQueries::deleteGmailAccount(database, accountId())) {
return ServiceRoot::deleteViaGui(); return ServiceRoot::deleteViaGui();

View file

@ -58,7 +58,7 @@ void GmailNetworkFactory::initializeOauth() {
Q_UNUSED(expires_in) Q_UNUSED(expires_in)
if (m_service != nullptr && !access_token.isEmpty() && !refresh_token.isEmpty()) { if (m_service != nullptr && !access_token.isEmpty() && !refresh_token.isEmpty()) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
DatabaseQueries::storeNewInoreaderTokens(database, refresh_token, m_service->accountId()); DatabaseQueries::storeNewInoreaderTokens(database, refresh_token, m_service->accountId());
qApp->showGuiMessage(tr("Logged in successfully"), qApp->showGuiMessage(tr("Logged in successfully"),

View file

@ -20,7 +20,7 @@ ServiceRoot* InoreaderEntryPoint::createNewRoot() const {
} }
QList<ServiceRoot*> InoreaderEntryPoint::initializeSubtree() const { QList<ServiceRoot*> InoreaderEntryPoint::initializeSubtree() const {
QSqlDatabase database = qApp->database()->connection(QSL("InoreaderEntryPoint"), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(QSL("InoreaderEntryPoint"));
return DatabaseQueries::getInoreaderAccounts(database); return DatabaseQueries::getInoreaderAccounts(database);
} }

View file

@ -49,7 +49,7 @@ void InoreaderServiceRoot::updateTitle() {
} }
void InoreaderServiceRoot::loadFromDatabase() { void InoreaderServiceRoot::loadFromDatabase() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
Assignment categories = DatabaseQueries::getCategories(database, accountId()); Assignment categories = DatabaseQueries::getCategories(database, accountId());
Assignment feeds = DatabaseQueries::getInoreaderFeeds(database, accountId()); Assignment feeds = DatabaseQueries::getInoreaderFeeds(database, accountId());
@ -63,7 +63,7 @@ void InoreaderServiceRoot::loadFromDatabase() {
} }
void InoreaderServiceRoot::saveAccountDataToDatabase() { void InoreaderServiceRoot::saveAccountDataToDatabase() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
if (accountId() != NO_PARENT_CATEGORY) { if (accountId() != NO_PARENT_CATEGORY) {
if (DatabaseQueries::overwriteInoreaderAccount(database, m_network->userName(), if (DatabaseQueries::overwriteInoreaderAccount(database, m_network->userName(),
@ -207,7 +207,7 @@ bool InoreaderServiceRoot::canBeDeleted() const {
} }
bool InoreaderServiceRoot::deleteViaGui() { bool InoreaderServiceRoot::deleteViaGui() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
if (DatabaseQueries::deleteInoreaderAccount(database, accountId())) { if (DatabaseQueries::deleteInoreaderAccount(database, accountId())) {
return ServiceRoot::deleteViaGui(); return ServiceRoot::deleteViaGui();

View file

@ -56,7 +56,7 @@ void InoreaderNetworkFactory::initializeOauth() {
Q_UNUSED(expires_in) Q_UNUSED(expires_in)
if (m_service != nullptr && !access_token.isEmpty() && !refresh_token.isEmpty()) { if (m_service != nullptr && !access_token.isEmpty() && !refresh_token.isEmpty()) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
DatabaseQueries::storeNewInoreaderTokens(database, refresh_token, m_service->accountId()); DatabaseQueries::storeNewInoreaderTokens(database, refresh_token, m_service->accountId());
qApp->showGuiMessage(tr("Logged in successfully"), qApp->showGuiMessage(tr("Logged in successfully"),

View file

@ -42,7 +42,7 @@ bool OwnCloudFeed::deleteViaGui() {
} }
bool OwnCloudFeed::editItself(OwnCloudFeed* new_feed_data) { bool OwnCloudFeed::editItself(OwnCloudFeed* new_feed_data) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
if (!DatabaseQueries::editBaseFeed(database, id(), new_feed_data->autoUpdateType(), if (!DatabaseQueries::editBaseFeed(database, id(), new_feed_data->autoUpdateType(),
new_feed_data->autoUpdateInitialInterval())) { new_feed_data->autoUpdateInitialInterval())) {
@ -57,7 +57,7 @@ bool OwnCloudFeed::editItself(OwnCloudFeed* new_feed_data) {
} }
bool OwnCloudFeed::removeItself() { bool OwnCloudFeed::removeItself() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
return DatabaseQueries::deleteFeed(database, customId().toInt(), serviceRoot()->accountId()); return DatabaseQueries::deleteFeed(database, customId().toInt(), serviceRoot()->accountId());
} }

View file

@ -17,7 +17,7 @@ ServiceRoot* OwnCloudServiceEntryPoint::createNewRoot() const {
} }
QList<ServiceRoot*> OwnCloudServiceEntryPoint::initializeSubtree() const { QList<ServiceRoot*> OwnCloudServiceEntryPoint::initializeSubtree() const {
QSqlDatabase database = qApp->database()->connection(QSL("OwnCloudServiceEntryPoint"), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(QSL("OwnCloudServiceEntryPoint"));
return DatabaseQueries::getOwnCloudAccounts(database); return DatabaseQueries::getOwnCloudAccounts(database);
} }

View file

@ -40,7 +40,7 @@ bool OwnCloudServiceRoot::editViaGui() {
} }
bool OwnCloudServiceRoot::deleteViaGui() { bool OwnCloudServiceRoot::deleteViaGui() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
if (DatabaseQueries::deleteOwnCloudAccount(database, accountId())) { if (DatabaseQueries::deleteOwnCloudAccount(database, accountId())) {
return ServiceRoot::deleteViaGui(); return ServiceRoot::deleteViaGui();
@ -132,7 +132,7 @@ void OwnCloudServiceRoot::updateTitle() {
} }
void OwnCloudServiceRoot::saveAccountDataToDatabase() { void OwnCloudServiceRoot::saveAccountDataToDatabase() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
if (accountId() != NO_PARENT_CATEGORY) { if (accountId() != NO_PARENT_CATEGORY) {
if (DatabaseQueries::overwriteOwnCloudAccount(database, m_network->authUsername(), if (DatabaseQueries::overwriteOwnCloudAccount(database, m_network->authUsername(),
@ -192,7 +192,7 @@ RootItem* OwnCloudServiceRoot::obtainNewTreeForSyncIn() const {
} }
void OwnCloudServiceRoot::loadFromDatabase() { void OwnCloudServiceRoot::loadFromDatabase() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
Assignment categories = DatabaseQueries::getCategories(database, accountId()); Assignment categories = DatabaseQueries::getCategories(database, accountId());
Assignment feeds = DatabaseQueries::getOwnCloudFeeds(database, accountId()); Assignment feeds = DatabaseQueries::getOwnCloudFeeds(database, accountId());

View file

@ -87,7 +87,7 @@ bool StandardCategory::removeItself() {
if (children_removed) { if (children_removed) {
// Children are removed, remove this standard category too. // Children are removed, remove this standard category too.
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
return DatabaseQueries::deleteCategory(database, id()); return DatabaseQueries::deleteCategory(database, id());
} }
@ -98,7 +98,7 @@ bool StandardCategory::removeItself() {
bool StandardCategory::addItself(RootItem* parent) { bool StandardCategory::addItself(RootItem* parent) {
// Now, add category to persistent storage. // Now, add category to persistent storage.
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
int new_id = DatabaseQueries::addCategory(database, parent->id(), parent->getParentServiceRoot()->accountId(), int new_id = DatabaseQueries::addCategory(database, parent->id(), parent->getParentServiceRoot()->accountId(),
title(), description(), creationDate(), icon()); title(), description(), creationDate(), icon());
@ -113,7 +113,7 @@ bool StandardCategory::addItself(RootItem* parent) {
} }
bool StandardCategory::editItself(StandardCategory* new_category_data) { bool StandardCategory::editItself(StandardCategory* new_category_data) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
StandardCategory* original_category = this; StandardCategory* original_category = this;
RootItem* new_parent = new_category_data->parent(); RootItem* new_parent = new_category_data->parent();

View file

@ -298,14 +298,14 @@ bool StandardFeed::performDragDropChange(RootItem* target_item) {
} }
bool StandardFeed::removeItself() { bool StandardFeed::removeItself() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
return DatabaseQueries::deleteFeed(database, customId().toInt(), getParentServiceRoot()->accountId()); return DatabaseQueries::deleteFeed(database, customId().toInt(), getParentServiceRoot()->accountId());
} }
bool StandardFeed::addItself(RootItem* parent) { bool StandardFeed::addItself(RootItem* parent) {
// Now, add feed to persistent storage. // Now, add feed to persistent storage.
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
bool ok; bool ok;
int new_id = DatabaseQueries::addFeed(database, parent->id(), parent->getParentServiceRoot()->accountId(), title(), int new_id = DatabaseQueries::addFeed(database, parent->id(), parent->getParentServiceRoot()->accountId(), title(),
description(), creationDate(), icon(), encoding(), url(), passwordProtected(), description(), creationDate(), icon(), encoding(), url(), passwordProtected(),
@ -324,7 +324,7 @@ bool StandardFeed::addItself(RootItem* parent) {
} }
bool StandardFeed::editItself(StandardFeed* new_feed_data) { bool StandardFeed::editItself(StandardFeed* new_feed_data) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
StandardFeed* original_feed = this; StandardFeed* original_feed = this;
RootItem* new_parent = new_feed_data->parent(); RootItem* new_parent = new_feed_data->parent();

View file

@ -33,7 +33,7 @@ QString StandardServiceEntryPoint::code() const {
ServiceRoot* StandardServiceEntryPoint::createNewRoot() const { ServiceRoot* StandardServiceEntryPoint::createNewRoot() const {
// Switch DB. // Switch DB.
QSqlDatabase database = qApp->database()->connection(QSL("StandardServiceEntryPoint"), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(QSL("StandardServiceEntryPoint"));
bool ok; bool ok;
int new_id = DatabaseQueries::createAccount(database, code(), &ok); int new_id = DatabaseQueries::createAccount(database, code(), &ok);
@ -50,7 +50,7 @@ ServiceRoot* StandardServiceEntryPoint::createNewRoot() const {
QList<ServiceRoot*> StandardServiceEntryPoint::initializeSubtree() const { QList<ServiceRoot*> StandardServiceEntryPoint::initializeSubtree() const {
// Check DB if standard account is enabled. // Check DB if standard account is enabled.
QSqlDatabase database = qApp->database()->connection(QSL("StandardServiceEntryPoint"), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(QSL("StandardServiceEntryPoint"));
return DatabaseQueries::getAccounts(database); return DatabaseQueries::getAccounts(database);
} }

View file

@ -130,7 +130,7 @@ Qt::ItemFlags StandardServiceRoot::additionalFlags() const {
} }
void StandardServiceRoot::loadFromDatabase() { void StandardServiceRoot::loadFromDatabase() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
Assignment categories = DatabaseQueries::getStandardCategories(database, accountId()); Assignment categories = DatabaseQueries::getStandardCategories(database, accountId());
Assignment feeds = DatabaseQueries::getStandardFeeds(database, accountId()); Assignment feeds = DatabaseQueries::getStandardFeeds(database, accountId());
@ -179,7 +179,7 @@ QList<QAction*> StandardServiceRoot::getContextMenuForFeed(StandardFeed* feed) {
} }
// Make connections. // Make connections.
disconnect(m_actionFeedFetchMetadata, &QAction::triggered, 0, 0); disconnect(m_actionFeedFetchMetadata, &QAction::triggered, nullptr, nullptr);
connect(m_actionFeedFetchMetadata, &QAction::triggered, feed, &StandardFeed::fetchMetadataForItself); connect(m_actionFeedFetchMetadata, &QAction::triggered, feed, &StandardFeed::fetchMetadataForItself);
return m_feedContextMenu; return m_feedContextMenu;
} }

View file

@ -54,7 +54,7 @@ bool TtRssFeed::deleteViaGui() {
} }
bool TtRssFeed::editItself(TtRssFeed* new_feed_data) { bool TtRssFeed::editItself(TtRssFeed* new_feed_data) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
if (DatabaseQueries::editBaseFeed(database, id(), new_feed_data->autoUpdateType(), if (DatabaseQueries::editBaseFeed(database, id(), new_feed_data->autoUpdateType(),
new_feed_data->autoUpdateInitialInterval())) { new_feed_data->autoUpdateInitialInterval())) {
@ -97,7 +97,7 @@ QList<Message> TtRssFeed::obtainNewMessages(bool* error_during_obtaining) {
} }
bool TtRssFeed::removeItself() { bool TtRssFeed::removeItself() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
return DatabaseQueries::deleteFeed(database, customId().toInt(), serviceRoot()->accountId()); return DatabaseQueries::deleteFeed(database, customId().toInt(), serviceRoot()->accountId());
} }

View file

@ -44,7 +44,7 @@ ServiceRoot* TtRssServiceEntryPoint::createNewRoot() const {
QList<ServiceRoot*> TtRssServiceEntryPoint::initializeSubtree() const { QList<ServiceRoot*> TtRssServiceEntryPoint::initializeSubtree() const {
// Check DB if standard account is enabled. // Check DB if standard account is enabled.
QSqlDatabase database = qApp->database()->connection(QSL("TtRssServiceEntryPoint"), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(QSL("TtRssServiceEntryPoint"));
return DatabaseQueries::getTtRssAccounts(database); return DatabaseQueries::getTtRssAccounts(database);
} }

View file

@ -59,7 +59,7 @@ bool TtRssServiceRoot::editViaGui() {
} }
bool TtRssServiceRoot::deleteViaGui() { bool TtRssServiceRoot::deleteViaGui() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
// Remove extra entry in "Tiny Tiny RSS accounts list" and then delete // Remove extra entry in "Tiny Tiny RSS accounts list" and then delete
// all the categories/feeds and messages. // all the categories/feeds and messages.
@ -172,7 +172,7 @@ TtRssNetworkFactory* TtRssServiceRoot::network() const {
} }
void TtRssServiceRoot::saveAccountDataToDatabase() { void TtRssServiceRoot::saveAccountDataToDatabase() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
if (accountId() != NO_PARENT_CATEGORY) { if (accountId() != NO_PARENT_CATEGORY) {
// We are overwritting previously saved data. // We are overwritting previously saved data.
@ -202,7 +202,7 @@ void TtRssServiceRoot::saveAccountDataToDatabase() {
} }
void TtRssServiceRoot::loadFromDatabase() { void TtRssServiceRoot::loadFromDatabase() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
Assignment categories = DatabaseQueries::getCategories(database, accountId()); Assignment categories = DatabaseQueries::getCategories(database, accountId());
Assignment feeds = DatabaseQueries::getTtRssFeeds(database, accountId()); Assignment feeds = DatabaseQueries::getTtRssFeeds(database, accountId());