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 <iostream>
|
||||
|
||||
#include "rsettings.h"
|
||||
#include "rsiface/rsinit.h"
|
||||
@ -32,13 +33,17 @@
|
||||
RSettings::RSettings(const QString settingsGroup)
|
||||
: QSettings(QString::fromStdString(SETTINGS_FILE), QSettings::IniFormat)
|
||||
{
|
||||
if (!settingsGroup.isEmpty())
|
||||
beginGroup(settingsGroup);
|
||||
std::string sPreferedId;
|
||||
m_bValid = RsInit::getPreferedAccountId(sPreferedId);
|
||||
|
||||
if (!settingsGroup.isEmpty())
|
||||
beginGroup(settingsGroup);
|
||||
}
|
||||
|
||||
RSettings::RSettings(std::string fileName, const QString settingsGroup)
|
||||
: QSettings(QString::fromStdString(fileName), QSettings::IniFormat)
|
||||
{
|
||||
m_bValid = true;
|
||||
if (!settingsGroup.isEmpty())
|
||||
beginGroup(settingsGroup);
|
||||
}
|
||||
@ -50,18 +55,25 @@ RSettings::RSettings(std::string fileName, const QString settingsGroup)
|
||||
QVariant
|
||||
RSettings::value(const QString &key, const QVariant &defaultVal) const
|
||||
{
|
||||
return QSettings::value(key, defaultVal.isNull() ? defaultValue(key)
|
||||
: defaultVal);
|
||||
if (m_bValid == false) {
|
||||
// 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>. */
|
||||
void
|
||||
RSettings::setValue(const QString &key, const QVariant &val)
|
||||
{
|
||||
if (val == defaultValue(key))
|
||||
QSettings::remove(key);
|
||||
else if (val != value(key))
|
||||
QSettings::setValue(key, val);
|
||||
if (m_bValid == false) {
|
||||
std::cerr << "RSettings::setValue() Calling on invalid object, key = " << key.toStdString() << std::endl;
|
||||
return;
|
||||
}
|
||||
if (val == defaultValue(key))
|
||||
QSettings::remove(key);
|
||||
else if (val != value(key))
|
||||
QSettings::setValue(key, val);
|
||||
}
|
||||
|
||||
QVariant RSettings::valueFromGroup(const QString &group, const QString &key, const QVariant &defaultVal)
|
||||
|
@ -59,6 +59,8 @@ public:
|
||||
virtual void setValueToGroup(const QString &group, const QString &key, const QVariant &val);
|
||||
|
||||
protected:
|
||||
bool m_bValid; // is valid - dependent on RsInit::getPreferedAccountId
|
||||
|
||||
/** Sets the default setting for <b>key</b> to <b>val</b>. */
|
||||
void setDefault(const QString &key, const QVariant &val);
|
||||
/** Returns the default setting value associated with <b>key</b>. If
|
||||
|
@ -74,13 +74,19 @@ RshareSettings *Settings = NULL;
|
||||
|
||||
/*static*/ void RshareSettings::Create ()
|
||||
{
|
||||
if (Settings && Settings->m_bValid == false) {
|
||||
// recreate with correct path
|
||||
delete (Settings);
|
||||
Settings = NULL;
|
||||
}
|
||||
if (Settings == NULL) {
|
||||
Settings = new RshareSettings ();
|
||||
}
|
||||
}
|
||||
|
||||
/** Default Constructor */
|
||||
RshareSettings::RshareSettings() {
|
||||
RshareSettings::RshareSettings()
|
||||
{
|
||||
initSettings();
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,9 @@ int main(int argc, char *argv[])
|
||||
RsInit::InitRsConfig();
|
||||
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 ();
|
||||
|
||||
/*
|
||||
@ -132,6 +134,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
rsicontrol->StartupRetroShare();
|
||||
|
||||
/* recreate global settings object, now with correct path */
|
||||
RshareSettings::Create ();
|
||||
|
||||
MainWindow *w = MainWindow::Create ();
|
||||
|
||||
// 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