1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#ifndef __dasher_app_settings_h__
#define __dasher_app_settings_h__
#include <functional>
#include <map>
#include <memory>
#include <glib.h>
#include <glib-object.h>
#include "../DasherCore/Parameters.h"
#include "../Common/AppSettingsHeader.h"
#include "../Common/ModuleSettings.h"
#include "../DasherCore/SettingsStore.h"
#include "../DasherCore/Observable.h"
// Forward declarations
typedef struct _GtkDasherControl GtkDasherControl;
struct _GtkDasherControl;
// Define the number of each type of setting
#define NUM_OF_APP_BPS (END_OF_APP_BPS - END_OF_SPS)
#define NUM_OF_APP_LPS (END_OF_APP_LPS - END_OF_APP_BPS)
#define NUM_OF_APP_SPS (END_OF_APP_SPS - END_OF_APP_LPS)
// Singleton holding the settings.
class DasherAppSettings : public Observer<int> {
public:
// Returns the AppSettings singleton, 'Create' must have been called once beforehand.
static DasherAppSettings* Get() {
return instance_.get();
}
virtual ~DasherAppSettings();
// Initializes the AppSettings singleton and takes ownership of 'store'.
static void Create(Dasher::CSettingsStore* store) {
if (instance_ == nullptr) {
instance_.reset(new DasherAppSettings(store));
}
}
// 'fn' will be called each time a parameter is changed and its argument will be
// the setting id.
// The return value is used to unregister the callback.
int RegisterParameterChangeCallback(std::function<void(int)> fn);
// Use the value returned by 'RegisterParameterChangeCallback' to unregister it.
void UnregisterParameterChangeCallback(int);
void Load();
void SetWidget(GtkDasherControl *pWidget);
bool GetBool(int iParameter);
void SetBool(int iParameter, bool bValue);
gint GetLong(int iParameter);
void SetLong(int iParameter, gint iValue);
const std::string& GetString(int iParameter);
void SetString(int iParameter, const gchar *szValue);
int GetCount();
GArray *GetAllowedValues(int iParameter);
bool HaveAdvanced();
void LaunchAdvanced();
gboolean GetModuleSettings(const gchar *szValue, SModuleSettings **pSettings, gint *iCount);
const gchar * ClSet(const gchar *szKey, const gchar *szValue);
Dasher::CSettingsStore* GetStore() { return settings_store_.get(); }
private:
DasherAppSettings(Dasher::CSettingsStore* store);
// The callback for the SettingsStore notifications.
void HandleEvent(int iParameter) override;
// The object is non copyable.
DasherAppSettings(const DasherAppSettings&) = delete;
void operator=(const DasherAppSettings&) = delete;
// Holds the singleton instance.
static std::unique_ptr<DasherAppSettings> instance_;
GtkDasherControl *pDasherWidget = nullptr;
std::unique_ptr<Dasher::CSettingsStore> settings_store_ = nullptr;
std::map<int, std::function<void(int)>> change_callbacks_;
int callback_id_ = 0;
};
void option_help();
#endif
|