| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <list> |
| 4 |
#include "imodule.h" |
| 5 |
|
| 6 |
// A list containing possible values for a combo box widgets |
| 7 |
typedef std::list<std::string> ComboBoxValueList; |
| 8 |
|
| 9 |
// Common interface of all preference items (labels, combo boxes, etc.) |
| 10 |
// All of them can carry a title and a registry key |
| 11 |
class IPreferenceItemBase |
| 12 |
{ |
| 13 |
public: |
| 14 |
virtual ~IPreferenceItemBase() {} |
| 15 |
|
| 16 |
typedef std::shared_ptr<IPreferenceItemBase> Ptr; |
| 17 |
|
| 18 |
virtual const std::string& getLabel() const = 0; |
| 19 |
|
| 20 |
virtual const std::string& getRegistryKey() const = 0; |
| 21 |
|
| 22 |
virtual void setRegistryKey(const std::string& key) = 0; |
| 23 |
}; |
| 24 |
|
| 25 |
class IPreferenceLabel : |
| 26 |
public virtual IPreferenceItemBase |
| 27 |
{ |
| 28 |
public: |
| 29 |
virtual ~IPreferenceLabel() {} |
| 30 |
}; |
| 31 |
|
| 32 |
class IPreferenceEntry : |
| 33 |
public virtual IPreferenceItemBase |
| 34 |
{ |
| 35 |
public: |
| 36 |
virtual ~IPreferenceEntry() {} |
| 37 |
}; |
| 38 |
|
| 39 |
class IPreferenceCheckbox : |
| 40 |
public virtual IPreferenceItemBase |
| 41 |
{ |
| 42 |
public: |
| 43 |
virtual ~IPreferenceCheckbox() {} |
| 44 |
}; |
| 45 |
|
| 46 |
class IPreferenceCombobox : |
| 47 |
public virtual IPreferenceItemBase |
| 48 |
{ |
| 49 |
public: |
| 50 |
virtual ~IPreferenceCombobox() {} |
| 51 |
|
| 52 |
virtual const ComboBoxValueList& getValues() const = 0; |
| 53 |
virtual bool storeValueNotIndex() const = 0; |
| 54 |
}; |
| 55 |
|
| 56 |
class IPreferencePathEntry : |
| 57 |
public virtual IPreferenceItemBase |
| 58 |
{ |
| 59 |
public: |
| 60 |
virtual ~IPreferencePathEntry() {} |
| 61 |
|
| 62 |
virtual bool browseDirectories() const = 0; |
| 63 |
}; |
| 64 |
|
| 65 |
class IPreferenceSpinner : |
| 66 |
public virtual IPreferenceItemBase |
| 67 |
{ |
| 68 |
public: |
| 69 |
virtual ~IPreferenceSpinner() {} |
| 70 |
|
| 71 |
virtual double getLower() = 0; |
| 72 |
virtual double getUpper() = 0; |
| 73 |
virtual int getFraction() = 0; |
| 74 |
}; |
| 75 |
|
| 76 |
class IPreferenceSlider : |
| 77 |
public virtual IPreferenceItemBase |
| 78 |
{ |
| 79 |
public: |
| 80 |
virtual ~IPreferenceSlider() {} |
| 81 |
|
| 82 |
virtual double getLower() = 0; |
| 83 |
virtual double getUpper() = 0; |
| 84 |
virtual double getStepIncrement() = 0; |
| 85 |
virtual double getPageIncrement() = 0; |
| 86 |
virtual int getFactor() = 0; |
| 87 |
}; |
| 88 |
|
| 89 |
/* greebo: This is the interface the preference page has to provide for adding |
| 90 |
* elements to the dialog page. */ |
| 91 |
class IPreferencePage |
| 92 |
{ |
| 93 |
public: |
| 94 |
// destructor |
| 95 |
virtual ~IPreferencePage() {} |
| 96 |
|
| 97 |
// Returns the title as displayed on top of the page's area |
| 98 |
virtual const std::string& getTitle() const = 0; |
| 99 |
|
| 100 |
/** |
| 101 |
* greebo: Allows to set a custom title of this page. The default title |
| 102 |
* upon construction is "guessed" by adding a " Settings" to |
| 103 |
* the page name, "Settings/Patch" gets assigned |
| 104 |
* a "Patch Settings" as default title. |
| 105 |
* Use this method to change this to fit your needs. |
| 106 |
*/ |
| 107 |
virtual void setTitle(const std::string& title) = 0; |
| 108 |
|
| 109 |
// greebo: Returns the name (caption) of this Page (e.g. "Settings") |
| 110 |
virtual const std::string& getName() const = 0; |
| 111 |
|
| 112 |
// The preference path leading to this page |
| 113 |
virtual const std::string& getPath() const = 0; |
| 114 |
|
| 115 |
// Returns TRUE if this page doesn't hold any items |
| 116 |
virtual bool isEmpty() const = 0; |
| 117 |
|
| 118 |
virtual void foreachItem(const std::function<void(const IPreferenceItemBase::Ptr&)>& functor) const = 0; |
| 119 |
|
| 120 |
// greebo: Use this to add a checkbox to the preference dialog that is connected to a registry value |
| 121 |
virtual void appendCheckBox(const std::string& label, const std::string& registryKey) = 0; |
| 122 |
|
| 123 |
// greebo: This adds a horizontal slider and connects it to the given registryKey. |
| 124 |
virtual void appendSlider(const std::string& name, const std::string& registryKey, |
| 125 |
double lower, double upper, double step_increment, double page_increment) = 0; |
| 126 |
|
| 127 |
/** |
| 128 |
* \brief |
| 129 |
* Add a drop-down combo box to the preference page. |
| 130 |
* |
| 131 |
* \param name |
| 132 |
* The name to be displayed next to the combo box. |
| 133 |
* |
| 134 |
* \param registryKey |
| 135 |
* The registry key which stores the value of the combo box. |
| 136 |
* |
| 137 |
* \param valueList |
| 138 |
* List of strings containing the values that should be displayed in the |
| 139 |
* combo box. |
| 140 |
* |
| 141 |
* \param storeValueNotIndex |
| 142 |
* If true, store the selected text in the registry key. If false, store the |
| 143 |
* numeric index of the selected item in the registry key. The default is |
| 144 |
* false. |
| 145 |
*/ |
| 146 |
virtual void appendCombo(const std::string& name, |
| 147 |
const std::string& registryKey, |
| 148 |
const ComboBoxValueList& valueList, |
| 149 |
bool storeValueNotIndex = false) = 0; |
| 150 |
|
| 151 |
/* greebo: Appends an entry field with <name> as caption which is connected to the given registryKey |
| 152 |
*/ |
| 153 |
virtual void appendEntry(const std::string& name, const std::string& registryKey) = 0; |
| 154 |
|
| 155 |
/* greebo: Appends an entry field with spinner buttons which retrieves its value from the given |
| 156 |
* RegistryKey. The lower and upper values have to be passed as well. |
| 157 |
*/ |
| 158 |
virtual void appendSpinner(const std::string& name, const std::string& registryKey, |
| 159 |
double lower, double upper, int fraction) = 0; |
| 160 |
|
| 161 |
// greebo: Adds a PathEntry to choose files or directories (depending on the given boolean) |
| 162 |
virtual void appendPathEntry(const std::string& name, |
| 163 |
const std::string& registryKey, |
| 164 |
bool browseDirectories) = 0; |
| 165 |
|
| 166 |
// Appends a static label (to add some text to the preference page) |
| 167 |
virtual void appendLabel(const std::string& caption) = 0; |
| 168 |
}; |
| 169 |
|
| 170 |
const char* const MODULE_PREFERENCESYSTEM("PreferenceSystem"); |
| 171 |
|
| 172 |
class IPreferenceSystem : |
| 173 |
public RegisterableModule |
| 174 |
{ |
| 175 |
public: |
| 176 |
/** |
| 177 |
* greebo: Retrieves the page for the given path. If the page |
| 178 |
* doesn't exist yet, it will be created at the given path, for example: |
| 179 |
* |
| 180 |
* "Settings/Patch Settings" |
| 181 |
* (spaces are ok, slashes are treated as delimiters, don't use them in the page name) |
| 182 |
* |
| 183 |
* Use the page interface to add widgets and connect them to registry keys. |
| 184 |
|
| 185 |
* @path: The path to lookup/create |
| 186 |
* @returns: the IPreferencePage reference. |
| 187 |
*/ |
| 188 |
virtual IPreferencePage& getPage(const std::string& path) = 0; |
| 189 |
|
| 190 |
/** |
| 191 |
* Visit each page, covering the whole tree |
| 192 |
*/ |
| 193 |
virtual void foreachPage(const std::function<void(IPreferencePage&)>& functor) = 0; |
| 194 |
}; |
| 195 |
|
| 196 |
inline IPreferenceSystem& GlobalPreferenceSystem() |
| 197 |
{ |
| 198 |
static module::InstanceReference<IPreferenceSystem> _reference(MODULE_PREFERENCESYSTEM); |
| 199 |
return _reference; |
| 200 |
} |