15 #include <q3textstream.h> 25 #include "../config.h" 26 #include "../backend/tools/xmlTools.h" 27 #include "../backend/tools/fileTools.h" 35 #if defined(Q_OS_MACX) 39 #elif defined(Q_OS_WIN) 40 bool configDirMade =
true;
44 if( !getWindowsFolderLocation(LOCAL_SETTINGS_APPLICATION_DATA, folderLoc) )
46 folderLoc = getenv(
"USERPROFILE") + QString(
"/Local Settings/Application Data");
48 QDir dataDir( folderLoc );
49 if(!dataDir.exists(
"Album Shaper"))
51 configDirMade = dataDir.mkdir(
"Album Shaper");
57 bool configDirMade =
true;
58 QDir homeDir( QDir::homeDirPath() );
59 if(!homeDir.exists(
".albumShaper"))
61 configDirMade = homeDir.mkdir(
".albumShaper");
77 #if defined(Q_OS_MACX) 78 settingsFilename = QDir::homeDirPath() + QString(
"/Library/Preferences/net.sourceforge.albumshaper.xml");
81 #elif defined(Q_OS_WIN) 84 if( !getWindowsFolderLocation(LOCAL_SETTINGS_APPLICATION_DATA, tmp) )
86 tmp = getenv(
"USERPROFILE") + QString(
"/Local Settings/Application Data");
88 settingsFilename = QDir::convertSeparators( tmp +
"/Album Shaper/settings.xml" );
92 settingsFilename = QDir::homeDirPath() + QString(
"/.albumShaper/settings.xml");
150 setString( group, key, (val ?
"1" :
"0" ) );
155 setString( group, key, QString(
"%1").arg(val) );
208 return (
getString(group,key).compare(
"1") == 0 );
273 if( !settingsFile.open( QIODevice::ReadOnly ) )
277 if( !DOM.setContent( &settingsFile ) )
280 settingsFile.close();
287 QDomElement root = DOM.documentElement();
288 QDomNode node = root.firstChild();
290 while( !node.isNull() )
292 if( node.isElement() && node.nodeName() ==
"group" )
295 QDomNamedNodeMap attributes = node.attributes();
296 if(attributes.namedItem(
"name").isNull())
298 node = node.nextSibling();
306 if(
curGroup->
getName().compare( attributes.namedItem(
"name").nodeValue()) == 0)
315 if(cur->
getName().compare( attributes.namedItem(
"name").nodeValue()) == 0)
325 if(loadedGroup == NULL)
327 loadedGroup =
new SettingGroup( attributes.namedItem(
"name").nodeValue() );
338 node = node.nextSibling();
349 if(file.open(QIODevice::WriteOnly))
353 stream.setDevice( &file );
354 stream.setEncoding( Q3TextStream::UnicodeUTF8 );
368 stream <<
"</settings>\n";
void removeGroup(QString group)
Removes an entire group of settings.
void setInt(QString group, QString key, int val)
Set int setting.
SettingGroup * lastGroup
pointer to last group
float getFloat(QString group, QString key)
Fetch float setting.
QString getString(QString group, QString key)
Fetch string setting.
bool getBool(QString group, QString key)
Fetch bool setting.
void resetSetting(QString group, QString key)
Resets a setting to it's default value.
bool loadSettings()
Loads settings.
void setString(QString group, QString key, QString value)
Sets a setting value, if group does not exist it is created, if setting does not exist it is also cre...
void setBool(QString group, QString key, bool val)
Set bool setting.
QString getValue(QString key)
Returns a setting value.
int getInt(QString group, QString key)
Fetch int setting.
Configuration()
Creates configuration variables using default values, then attempts to load settings from disk...
static bool constructSettingsDirectory()
Constructs any necessary directories for loading and saving user settings, returns false if unsuccess...
bool saveSettings()
Saves settings.
QString getName()
Returns group's name.
SettingGroup * firstGroup
pointer to first group
SettingGroup * curGroup
pointer to currently selected group
void loadSettings(QDomNode &node)
void setNext(SettingGroup *next)
sets the next group setting
#define ALBUMSHAPER_VERSION
SettingGroup * getNext()
returns the next groupsetting
double getDouble(QString group, QString key)
Fetch double setting.
void resetSetting(QString key)
resets a setting to its default value
void saveSettings(Q3TextStream &stream)
writes out this group to file
~Configuration()
Destructor saves settings to disk.
void setValue(QString key, QString value)
Sets a setting value, create new setting if setting not found.
QString settingsFilename
Settings filename.
SettingGroup contains settings which are releated.