mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
profile wasn't saved on first start
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3133 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
4dc30963cb
commit
927f8639b7
@ -21,6 +21,7 @@
|
|||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
#include <rshare.h>
|
#include <rshare.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "rsettings.h"
|
#include "rsettings.h"
|
||||||
#include "rsiface/rsinit.h"
|
#include "rsiface/rsinit.h"
|
||||||
@ -32,6 +33,9 @@
|
|||||||
RSettings::RSettings(const QString settingsGroup)
|
RSettings::RSettings(const QString settingsGroup)
|
||||||
: QSettings(QString::fromStdString(SETTINGS_FILE), QSettings::IniFormat)
|
: QSettings(QString::fromStdString(SETTINGS_FILE), QSettings::IniFormat)
|
||||||
{
|
{
|
||||||
|
std::string sPreferedId;
|
||||||
|
m_bValid = RsInit::getPreferedAccountId(sPreferedId);
|
||||||
|
|
||||||
if (!settingsGroup.isEmpty())
|
if (!settingsGroup.isEmpty())
|
||||||
beginGroup(settingsGroup);
|
beginGroup(settingsGroup);
|
||||||
}
|
}
|
||||||
@ -39,6 +43,7 @@ RSettings::RSettings(const QString settingsGroup)
|
|||||||
RSettings::RSettings(std::string fileName, const QString settingsGroup)
|
RSettings::RSettings(std::string fileName, const QString settingsGroup)
|
||||||
: QSettings(QString::fromStdString(fileName), QSettings::IniFormat)
|
: QSettings(QString::fromStdString(fileName), QSettings::IniFormat)
|
||||||
{
|
{
|
||||||
|
m_bValid = true;
|
||||||
if (!settingsGroup.isEmpty())
|
if (!settingsGroup.isEmpty())
|
||||||
beginGroup(settingsGroup);
|
beginGroup(settingsGroup);
|
||||||
}
|
}
|
||||||
@ -50,14 +55,21 @@ RSettings::RSettings(std::string fileName, const QString settingsGroup)
|
|||||||
QVariant
|
QVariant
|
||||||
RSettings::value(const QString &key, const QVariant &defaultVal) const
|
RSettings::value(const QString &key, const QVariant &defaultVal) const
|
||||||
{
|
{
|
||||||
return QSettings::value(key, defaultVal.isNull() ? defaultValue(key)
|
if (m_bValid == false) {
|
||||||
: defaultVal);
|
// return only default value
|
||||||
|
return defaultVal.isNull() ? defaultValue(key) : defaultVal;
|
||||||
|
}
|
||||||
|
return QSettings::value(key, defaultVal.isNull() ? defaultValue(key) : defaultVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets the value associated with <b>key</b> to <b>val</b>. */
|
/** Sets the value associated with <b>key</b> to <b>val</b>. */
|
||||||
void
|
void
|
||||||
RSettings::setValue(const QString &key, const QVariant &val)
|
RSettings::setValue(const QString &key, const QVariant &val)
|
||||||
{
|
{
|
||||||
|
if (m_bValid == false) {
|
||||||
|
std::cerr << "RSettings::setValue() Calling on invalid object, key = " << key.toStdString() << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (val == defaultValue(key))
|
if (val == defaultValue(key))
|
||||||
QSettings::remove(key);
|
QSettings::remove(key);
|
||||||
else if (val != value(key))
|
else if (val != value(key))
|
||||||
|
@ -59,6 +59,8 @@ public:
|
|||||||
virtual void setValueToGroup(const QString &group, const QString &key, const QVariant &val);
|
virtual void setValueToGroup(const QString &group, const QString &key, const QVariant &val);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool m_bValid; // is valid - dependent on RsInit::getPreferedAccountId
|
||||||
|
|
||||||
/** Sets the default setting for <b>key</b> to <b>val</b>. */
|
/** Sets the default setting for <b>key</b> to <b>val</b>. */
|
||||||
void setDefault(const QString &key, const QVariant &val);
|
void setDefault(const QString &key, const QVariant &val);
|
||||||
/** Returns the default setting value associated with <b>key</b>. If
|
/** Returns the default setting value associated with <b>key</b>. If
|
||||||
|
@ -74,13 +74,19 @@ RshareSettings *Settings = NULL;
|
|||||||
|
|
||||||
/*static*/ void RshareSettings::Create ()
|
/*static*/ void RshareSettings::Create ()
|
||||||
{
|
{
|
||||||
|
if (Settings && Settings->m_bValid == false) {
|
||||||
|
// recreate with correct path
|
||||||
|
delete (Settings);
|
||||||
|
Settings = NULL;
|
||||||
|
}
|
||||||
if (Settings == NULL) {
|
if (Settings == NULL) {
|
||||||
Settings = new RshareSettings ();
|
Settings = new RshareSettings ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Default Constructor */
|
/** Default Constructor */
|
||||||
RshareSettings::RshareSettings() {
|
RshareSettings::RshareSettings()
|
||||||
|
{
|
||||||
initSettings();
|
initSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,9 @@ int main(int argc, char *argv[])
|
|||||||
RsInit::InitRsConfig();
|
RsInit::InitRsConfig();
|
||||||
bool okStart = RsInit::InitRetroShare(argc, argv);
|
bool okStart = RsInit::InitRetroShare(argc, argv);
|
||||||
|
|
||||||
/* create global settings object */
|
/* create global settings object
|
||||||
|
path maybe wrong, when no profile exist
|
||||||
|
in this case it can be use only for default values */
|
||||||
RshareSettings::Create ();
|
RshareSettings::Create ();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -132,6 +134,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
rsicontrol->StartupRetroShare();
|
rsicontrol->StartupRetroShare();
|
||||||
|
|
||||||
|
/* recreate global settings object, now with correct path */
|
||||||
|
RshareSettings::Create ();
|
||||||
|
|
||||||
MainWindow *w = MainWindow::Create ();
|
MainWindow *w = MainWindow::Create ();
|
||||||
|
|
||||||
// I'm using a signal to transfer the hashing info to the mainwindow, because Qt schedules signals properly to
|
// I'm using a signal to transfer the hashing info to the mainwindow, because Qt schedules signals properly to
|
||||||
|
Loading…
Reference in New Issue
Block a user