15#include <q3textstream.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";
bool getBool(QString group, QString key)
Fetch bool setting.
~Configuration()
Destructor saves settings to disk.
QString settingsFilename
Settings filename.
double getDouble(QString group, QString key)
Fetch double setting.
void removeGroup(QString group)
Removes an entire group of settings.
SettingGroup * curGroup
pointer to currently selected group
SettingGroup * lastGroup
pointer to last group
float getFloat(QString group, QString key)
Fetch float setting.
void setInt(QString group, QString key, int val)
Set int setting.
Configuration()
Creates configuration variables using default values, then attempts to load settings from disk.
SettingGroup * firstGroup
pointer to first group
void setBool(QString group, QString key, bool val)
Set bool setting.
bool loadSettings()
Loads settings.
bool saveSettings()
Saves 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 resetSetting(QString group, QString key)
Resets a setting to it's default value.
static bool constructSettingsDirectory()
Constructs any necessary directories for loading and saving user settings, returns false if unsuccess...
QString getString(QString group, QString key)
Fetch string setting.
int getInt(QString group, QString key)
Fetch int setting.
SettingGroup contains settings which are releated.
QString getValue(QString key)
Returns a setting value.
void resetSetting(QString key)
resets a setting to its default value
void setNext(SettingGroup *next)
sets the next group setting
void setValue(QString key, QString value)
Sets a setting value, create new setting if setting not found.
QString getName()
Returns group's name.
SettingGroup * getNext()
returns the next groupsetting
void saveSettings(Q3TextStream &stream)
writes out this group to file
void loadSettings(QDomNode &node)
#define ALBUMSHAPER_VERSION