Skip to content

Commit

Permalink
Client|libdeng2: Persistently store setting profiles
Browse files Browse the repository at this point in the history
SettingsRegister can now optionally be configured to work in
persistent mode, where the profiles and their values are stored in
an Info file under /home/configs/.

The Renderer Settings dialog can now be used to manipulate the
appearance profiles.

Also, de::File now uses the as/is template methods.
  • Loading branch information
skyjake committed Sep 9, 2013
1 parent 84af052 commit c8a6875
Show file tree
Hide file tree
Showing 8 changed files with 453 additions and 44 deletions.
48 changes: 40 additions & 8 deletions doomsday/client/include/settingsregister.h
Expand Up @@ -20,6 +20,7 @@
#define DENG_SETTINGSREGISTER_H

#include <de/String>
#include <de/Observers>
#include <QVariant>
#include <QList>

Expand All @@ -36,26 +37,40 @@
* The current profile is simply whatever values the identified cvars/variables
* presently hold. These current values get stored persistently in the app's
* Config (and via con_config) as usual. SettingsRegister is responsible for
* storing the non-current profiles persistently.
* storing the non-current profiles persistently. The (de)serialization occurs
* whenever the game is (un)loaded, as all cvars are presently game-specific.
*
* @todo It should be possible to install new profiles via resource packs.
* Also, any built-in profiles (e.g., "Developer" or "Debugging") should be
* defined in resource packs and not hardcoded in code.
* It is possible to install new profiles via resource packs. The profiles should
* be placed to /data/profiles/(persistentName)/.
*/
class SettingsRegister
{
public:
enum SettingType
{
enum SettingType {
IntCVar,
FloatCVar,
StringCVar,
ConfigVariable ///< Default value gotten from Config.setDefaults().
};

DENG2_DEFINE_AUDIENCE(ProfileChange, void currentProfileChanged(de::String const &name))

public:
SettingsRegister();

/**
* Sets the name this register will use for storing profiles persistently.
* By default the register has no persistent name and thus will not be
* stored persistently.
*
* In the Config, there will be a record called "Config.(persistentName)"
* containing relevant information.
*
* @param name Persistent name for the register. Must be file name and
* script variable name friendly.
*/
void setPersistentName(de::String const &name);

/**
* Defines a new setting in the profile.
*
Expand All @@ -71,14 +86,27 @@ class SettingsRegister

de::String currentProfile() const;

/**
* Determines if a profile should be considered read-only. The UI should
* not let the user modify profiles that are read-only.
*
* @param name Profile name.
*
* @return @c true, if the profile is read-only.
*/
bool isReadOnlyProfile(de::String const &name) const;

/**
* Current values of the settings are saved as a profile. If there is a
* profile with the same name, it will be replaced. The current profile is
* not changed.
*
* @param name Name of the profile.
*
* @return @c true if a new profile was created. @c false, if the operation
* failed (e.g., name already in use).
*/
void saveAsProfile(de::String const &name);
bool saveAsProfile(de::String const &name);

/**
* Changes the current settings profile.
Expand All @@ -103,8 +131,10 @@ class SettingsRegister
* Renames the current profile.
*
* @param name New name of the profile.
*
* @return @c true, if renamed successfully.
*/
void rename(de::String const &name);
bool rename(de::String const &name);

/**
* Deletes a profile. The current profile cannot be deleted.
Expand All @@ -118,6 +148,8 @@ class SettingsRegister
*/
QList<de::String> profiles() const;

int profileCount() const;

private:
DENG2_PRIVATE(d)
};
Expand Down
Expand Up @@ -41,7 +41,7 @@ protected slots:
void renameProfile();
void duplicateProfile();
void deleteProfile();
void showEditor();
void applySelectedAppearance();

private:
DENG2_PRIVATE(d)
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/src/clientapp.cpp
Expand Up @@ -211,6 +211,7 @@ DENG2_PIMPL(ClientApp)
.define(SReg::IntCVar, "rend-dev-vertex-show-indices", 0)
.define(SReg::IntCVar, "rend-dev-generator-show-indices", 0);

rendererAppearanceSettings.setPersistentName("renderer");
rendererAppearanceSettings
.define(SReg::IntCVar, "rend-light", 1)
.define(SReg::IntCVar, "rend-light-decor", 1)
Expand Down

0 comments on commit c8a6875

Please sign in to comment.