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/databasefactory.h"
|
||||
#include "core/settings.h"
|
||||
|
||||
|
||||
QPointer<DatabaseFactory> DatabaseFactory::s_instance;
|
||||
@ -27,8 +28,13 @@ DatabaseFactory *DatabaseFactory::getInstance() {
|
||||
}
|
||||
|
||||
void DatabaseFactory::assemblyDatabaseFilePath() {
|
||||
m_databasePath = QDir::homePath() + QDir::separator() + APP_LOW_H_NAME +
|
||||
QDir::separator() + APP_DB_PATH;
|
||||
if (Settings::getInstance()->type() == Settings::Portable) {
|
||||
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() {
|
||||
|
@ -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 <QDebug>
|
||||
#include <QDir>
|
||||
@ -29,8 +10,9 @@
|
||||
|
||||
QPointer<Settings> Settings::s_instance;
|
||||
|
||||
Settings::Settings(const QString &file_name, Format format, QObject *parent)
|
||||
: QSettings(file_name, format, parent) {
|
||||
Settings::Settings(const QString &file_name, Format format,
|
||||
const Type &status, QObject *parent)
|
||||
: QSettings(file_name, format, parent), m_initializationStatus(status) {
|
||||
}
|
||||
|
||||
Settings::~Settings() {
|
||||
@ -38,6 +20,11 @@ Settings::~Settings() {
|
||||
qDebug("Deleting Settings instance.");
|
||||
}
|
||||
|
||||
Settings::Type Settings::type() const {
|
||||
return m_initializationStatus;
|
||||
}
|
||||
|
||||
|
||||
QSettings::Status Settings::checkSettings() {
|
||||
qDebug("Syncing settings.");
|
||||
sync();
|
||||
@ -77,8 +64,10 @@ QSettings::Status Settings::setupSettings() {
|
||||
// Check if portable settings are available.
|
||||
if (QFile(app_path_file).exists()) {
|
||||
// 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.
|
||||
QString web_path = app_path + QDir::separator() + APP_CFG_WEB_PATH;
|
||||
QDir(web_path).mkpath(web_path);
|
||||
@ -94,8 +83,10 @@ QSettings::Status Settings::setupSettings() {
|
||||
APP_LOW_H_NAME;
|
||||
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;
|
||||
QDir(web_path).mkpath(web_path);
|
||||
QWebSettings::setIconDatabasePath(web_path);
|
||||
|
@ -8,23 +8,20 @@
|
||||
class Settings : public QSettings {
|
||||
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:
|
||||
enum Type {
|
||||
Portable,
|
||||
NonPortable
|
||||
};
|
||||
|
||||
// Singleton getter.
|
||||
static Settings *getInstance();
|
||||
|
||||
// Destructor.
|
||||
virtual ~Settings();
|
||||
|
||||
Type type() const;
|
||||
|
||||
// Getter/setter for settings values.
|
||||
QVariant value(const QString §ion,
|
||||
const QString &key,
|
||||
@ -36,6 +33,19 @@ class Settings : public QSettings {
|
||||
|
||||
// Synchronises settings.
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user