From 738dbbe5c655d9ad2164f17ef96eed64a9e44ab4 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Tue, 17 Dec 2013 17:43:22 +0100 Subject: [PATCH] Fixed desktop entry path and systemfactory made singleton. --- CMakeLists.txt | 3 ++- src/core/feedsmodel.cpp | 2 -- src/core/messagesmodel.cpp | 2 +- src/core/systemfactory.cpp | 18 +++++++++++++++++- src/core/systemfactory.h | 21 +++++++++++++++++---- src/gui/formsettings.cpp | 8 ++++---- 6 files changed, 41 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b6ed7f75..1c646ea85 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,7 +108,7 @@ if(UNIX) ${PROJECT_SOURCE_DIR}/resources/desktop/rssguard.desktop.in ${CMAKE_CURRENT_BINARY_DIR}/resources/desktop/rssguard.desktop ) - set(DESKTOP_ENTRY ${CMAKE_INSTALL_PREFIX}/share/applications) + set(DESKTOP_ENTRY_PATH ${CMAKE_INSTALL_PREFIX}/share/applications) endif(UNIX) # Configure internal C++ defines. @@ -319,6 +319,7 @@ set(APP_HEADERS src/core/basenetworkaccessmanager.h src/core/webbrowsernetworkaccessmanager.h src/core/basewebpage.h + src/core/systemfactory.h src/core/databasefactory.h src/core/messagesmodel.h src/core/messagesproxymodel.h diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index b44732406..5ee2c295f 100644 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -24,8 +24,6 @@ FeedsModel::FeedsModel(QObject *parent) : QAbstractItemModel(parent) { loadFromDatabase(); - loadFromDatabase(); - /* FeedsModelStandardCategory *cat1 = new FeedsModelStandardCategory(); FeedsModelStandardCategory *cat2 = new FeedsModelStandardCategory(); diff --git a/src/core/messagesmodel.cpp b/src/core/messagesmodel.cpp index abd6e7a6c..b57ad1198 100644 --- a/src/core/messagesmodel.cpp +++ b/src/core/messagesmodel.cpp @@ -429,7 +429,7 @@ bool MessagesModel::setAllMessagesRead(int read) { QSqlQuery query_read_msg(db_handle); if (!query_read_msg.prepare(QString("UPDATE messages SET read = :read " - "WHERE feed IN (%1) AND deleted = 0").arg(textualFeeds().join(", ")))) { + "WHERE feed IN (%1) AND deleted = 0").arg(textualFeeds().join(", ")))) { qWarning("Query preparation failed for message read change."); db_handle.rollback(); diff --git a/src/core/systemfactory.cpp b/src/core/systemfactory.cpp index bcb1987c8..19464a7a0 100644 --- a/src/core/systemfactory.cpp +++ b/src/core/systemfactory.cpp @@ -1,5 +1,6 @@ #include #include +#include #if defined(Q_OS_WIN) #include @@ -10,9 +11,16 @@ #include "core/defs.h" -SystemFactory::SystemFactory() { +QPointer SystemFactory::s_instance; + +SystemFactory::SystemFactory(QObject *parent) : QObject(parent) { } +SystemFactory::~SystemFactory() { + qDebug("Destroying SystemFactory instance."); +} + + SystemFactory::AutoStartStatus SystemFactory::getAutoStartStatus() { // User registry way to auto-start the application on Windows. #if defined(Q_OS_WIN) @@ -78,6 +86,14 @@ QString SystemFactory::getAutostartDesktopFileLocation() { // No location found, return empty string. return desktop_file_location; } + +SystemFactory *SystemFactory::getInstance() { + if (s_instance.isNull()) { + s_instance = new SystemFactory(qApp); + } + + return s_instance; +} #endif bool SystemFactory::setAutoStartStatus(const AutoStartStatus &new_status) { diff --git a/src/core/systemfactory.h b/src/core/systemfactory.h index 45cbaaa43..6c08f74e1 100644 --- a/src/core/systemfactory.h +++ b/src/core/systemfactory.h @@ -1,12 +1,19 @@ #ifndef SYSTEMFACTORY_H #define SYSTEMFACTORY_H +#include +#include + + +class SystemFactory : public QObject { + Q_OBJECT -class SystemFactory { private: - explicit SystemFactory(); + explicit SystemFactory(QObject *parent = 0); public: + virtual ~SystemFactory(); + // Specifies possible states of auto-start functionality. enum AutoStartStatus { Enabled, @@ -15,18 +22,24 @@ class SystemFactory { }; // Returns current status of auto-start function. - static SystemFactory::AutoStartStatus getAutoStartStatus(); + SystemFactory::AutoStartStatus getAutoStartStatus(); // Sets new status for auto-start function. // Function returns false if setting of // new status failed. - static bool setAutoStartStatus(const SystemFactory::AutoStartStatus &new_status); + bool setAutoStartStatus(const SystemFactory::AutoStartStatus &new_status); #if defined(Q_OS_LINUX) // Returns standard location where auto-start .desktop files // should be placed. static QString getAutostartDesktopFileLocation(); #endif + + // Singleton getter. + static SystemFactory *getInstance(); + + private: + static QPointer s_instance; }; #endif // SYSTEMFACTORY_H diff --git a/src/gui/formsettings.cpp b/src/gui/formsettings.cpp index 3d597f3e3..39b3f6e59 100755 --- a/src/gui/formsettings.cpp +++ b/src/gui/formsettings.cpp @@ -406,7 +406,7 @@ void FormSettings::saveShortcuts() { void FormSettings::loadGeneral() { // Load auto-start status. - SystemFactory::AutoStartStatus autostart_status = SystemFactory::getAutoStartStatus(); + SystemFactory::AutoStartStatus autostart_status = SystemFactory::getInstance()->getAutoStartStatus(); switch (autostart_status) { case SystemFactory::Enabled: m_ui->m_checkAutostart->setChecked(true); @@ -425,12 +425,12 @@ void FormSettings::loadGeneral() { void FormSettings::saveGeneral() { // If auto-start feature is available and user wants // to turn it on, then turn it on. - if (SystemFactory::getAutoStartStatus() != SystemFactory::Unavailable) { + if (SystemFactory::getInstance()->getAutoStartStatus() != SystemFactory::Unavailable) { if (m_ui->m_checkAutostart->isChecked()) { - SystemFactory::setAutoStartStatus(SystemFactory::Enabled); + SystemFactory::getInstance()->setAutoStartStatus(SystemFactory::Enabled); } else { - SystemFactory::setAutoStartStatus(SystemFactory::Disabled); + SystemFactory::getInstance()->setAutoStartStatus(SystemFactory::Disabled); } } }