mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-06 04:14:22 +01:00
Portable settings, now including local database.
This commit is contained in:
parent
6762b2b48e
commit
73def1cfcc
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "core/defs.h"
|
#include "core/defs.h"
|
||||||
#include "core/databasefactory.h"
|
#include "core/databasefactory.h"
|
||||||
|
#include "core/settings.h"
|
||||||
|
|
||||||
|
|
||||||
QPointer<DatabaseFactory> DatabaseFactory::s_instance;
|
QPointer<DatabaseFactory> DatabaseFactory::s_instance;
|
||||||
@ -27,8 +28,13 @@ DatabaseFactory *DatabaseFactory::getInstance() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseFactory::assemblyDatabaseFilePath() {
|
void DatabaseFactory::assemblyDatabaseFilePath() {
|
||||||
m_databasePath = QDir::homePath() + QDir::separator() + APP_LOW_H_NAME +
|
if (Settings::getInstance()->type() == Settings::Portable) {
|
||||||
QDir::separator() + APP_DB_PATH;
|
m_databasePath = qApp->applicationDirPath() + QDir::separator() + APP_DB_PATH;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_databasePath = QDir::homePath() + QDir::separator() + APP_LOW_H_NAME +
|
||||||
|
QDir::separator() + APP_DB_PATH;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DatabaseFactory::getDatabasePath() {
|
QString DatabaseFactory::getDatabasePath() {
|
||||||
|
@ -1,22 +1,3 @@
|
|||||||
/*
|
|
||||||
This file is part of Qonverter.
|
|
||||||
|
|
||||||
Qonverter is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
Qonverter is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with Qonverter. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Copyright 2012 - 2013 Martin Rotter
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@ -29,8 +10,9 @@
|
|||||||
|
|
||||||
QPointer<Settings> Settings::s_instance;
|
QPointer<Settings> Settings::s_instance;
|
||||||
|
|
||||||
Settings::Settings(const QString &file_name, Format format, QObject *parent)
|
Settings::Settings(const QString &file_name, Format format,
|
||||||
: QSettings(file_name, format, parent) {
|
const Type &status, QObject *parent)
|
||||||
|
: QSettings(file_name, format, parent), m_initializationStatus(status) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings::~Settings() {
|
Settings::~Settings() {
|
||||||
@ -38,6 +20,11 @@ Settings::~Settings() {
|
|||||||
qDebug("Deleting Settings instance.");
|
qDebug("Deleting Settings instance.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Settings::Type Settings::type() const {
|
||||||
|
return m_initializationStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QSettings::Status Settings::checkSettings() {
|
QSettings::Status Settings::checkSettings() {
|
||||||
qDebug("Syncing settings.");
|
qDebug("Syncing settings.");
|
||||||
sync();
|
sync();
|
||||||
@ -77,8 +64,10 @@ QSettings::Status Settings::setupSettings() {
|
|||||||
// Check if portable settings are available.
|
// Check if portable settings are available.
|
||||||
if (QFile(app_path_file).exists()) {
|
if (QFile(app_path_file).exists()) {
|
||||||
// Portable settings are available, use them.
|
// Portable settings are available, use them.
|
||||||
s_instance = new Settings(app_path_file, QSettings::IniFormat, qApp);
|
s_instance = new Settings(app_path_file, QSettings::IniFormat,
|
||||||
|
Settings::Portable, qApp);
|
||||||
|
|
||||||
|
// TODO: Separate web settings into another unit.
|
||||||
// Construct icon cache in the same path.
|
// Construct icon cache in the same path.
|
||||||
QString web_path = app_path + QDir::separator() + APP_CFG_WEB_PATH;
|
QString web_path = app_path + QDir::separator() + APP_CFG_WEB_PATH;
|
||||||
QDir(web_path).mkpath(web_path);
|
QDir(web_path).mkpath(web_path);
|
||||||
@ -94,8 +83,10 @@ QSettings::Status Settings::setupSettings() {
|
|||||||
APP_LOW_H_NAME;
|
APP_LOW_H_NAME;
|
||||||
QString home_path_file = home_path + relative_path;
|
QString home_path_file = home_path + relative_path;
|
||||||
|
|
||||||
s_instance = new Settings(home_path_file, QSettings::IniFormat, qApp);
|
s_instance = new Settings(home_path_file, QSettings::IniFormat,
|
||||||
|
Settings::NonPortable, qApp);
|
||||||
|
|
||||||
|
// Construct icon cache in the same path.
|
||||||
QString web_path = home_path + QDir::separator() + APP_CFG_WEB_PATH;
|
QString web_path = home_path + QDir::separator() + APP_CFG_WEB_PATH;
|
||||||
QDir(web_path).mkpath(web_path);
|
QDir(web_path).mkpath(web_path);
|
||||||
QWebSettings::setIconDatabasePath(web_path);
|
QWebSettings::setIconDatabasePath(web_path);
|
||||||
|
@ -8,23 +8,20 @@
|
|||||||
class Settings : public QSettings {
|
class Settings : public QSettings {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
|
||||||
// Constructor.
|
|
||||||
Settings(const QString & file_name, Format format, QObject * parent = 0);
|
|
||||||
|
|
||||||
// Creates settings file in correct location.
|
|
||||||
static QSettings::Status setupSettings();
|
|
||||||
|
|
||||||
// Private singleton value.
|
|
||||||
static QPointer<Settings> s_instance;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum Type {
|
||||||
|
Portable,
|
||||||
|
NonPortable
|
||||||
|
};
|
||||||
|
|
||||||
// Singleton getter.
|
// Singleton getter.
|
||||||
static Settings *getInstance();
|
static Settings *getInstance();
|
||||||
|
|
||||||
// Destructor.
|
// Destructor.
|
||||||
virtual ~Settings();
|
virtual ~Settings();
|
||||||
|
|
||||||
|
Type type() const;
|
||||||
|
|
||||||
// Getter/setter for settings values.
|
// Getter/setter for settings values.
|
||||||
QVariant value(const QString §ion,
|
QVariant value(const QString §ion,
|
||||||
const QString &key,
|
const QString &key,
|
||||||
@ -36,6 +33,19 @@ class Settings : public QSettings {
|
|||||||
|
|
||||||
// Synchronises settings.
|
// Synchronises settings.
|
||||||
QSettings::Status checkSettings();
|
QSettings::Status checkSettings();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Constructor.
|
||||||
|
Settings(const QString & file_name, Format format,
|
||||||
|
const Type &type, QObject * parent = 0);
|
||||||
|
|
||||||
|
Type m_initializationStatus;
|
||||||
|
|
||||||
|
// Creates settings file in correct location.
|
||||||
|
static QSettings::Status setupSettings();
|
||||||
|
|
||||||
|
// Private singleton value.
|
||||||
|
static QPointer<Settings> s_instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SETTINGS_H
|
#endif // SETTINGS_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user