Update Turkish translation
[dasher.git] / Src / Gtk2 / DasherAppSettings.cpp
blob36ec440dcec9395ae9dd4c85d473de4bd4c9fcf1
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
5 #include <cstring>
6 #include "DasherAppSettings.h"
7 #include "../Common/AppSettingsData.h"
9 // FIXME - not sure that we're loading parameters from the registry at startup right now
11 // FIXME - shouldn't need to include this, but for now we need access to the global pointer to the dasher control.
13 #include "dasher.h"
14 #include "GtkDasherControl.h"
16 // TODO: Rename this file to fit in with naming conventions
18 using namespace Dasher::Settings;
20 std::unique_ptr<DasherAppSettings> DasherAppSettings::instance_;
22 DasherAppSettings::DasherAppSettings(Dasher::CSettingsStore* settings_store) {
23 settings_store_.reset(settings_store);
24 Load();
27 DasherAppSettings::~DasherAppSettings() {
28 settings_store_->Unregister(this);
31 int DasherAppSettings::RegisterParameterChangeCallback(std::function<void(int)> fn) {
32 int id = ++callback_id_;
33 change_callbacks_[id] = fn;
34 return id;
37 void DasherAppSettings::UnregisterParameterChangeCallback(int callback_id) {
38 change_callbacks_.erase(callback_id);
41 void DasherAppSettings::Load() {
42 settings_store_->AddParameters(app_boolparamtable, NUM_OF_APP_BPS);
43 settings_store_->AddParameters(app_longparamtable, NUM_OF_APP_LPS);
44 settings_store_->AddParameters(app_stringparamtable, NUM_OF_APP_SPS);
45 settings_store_->Register(this);
48 bool DasherAppSettings::GetBool(int iParameter) {
49 return settings_store_->GetBoolParameter(iParameter);
52 void DasherAppSettings::SetBool(int iParameter, bool bValue) {
53 settings_store_->SetBoolParameter(iParameter, bValue);
56 gint DasherAppSettings::GetLong(int iParameter) {
57 return settings_store_->GetLongParameter(iParameter);
60 void DasherAppSettings::SetLong(int iParameter, gint iValue) {
61 return settings_store_->SetLongParameter(iParameter, iValue);
64 const std::string& DasherAppSettings::GetString(int iParameter) {
65 return settings_store_->GetStringParameter(iParameter);
68 void DasherAppSettings::SetString(int iParameter, const gchar *szValue) {
69 return settings_store_->SetStringParameter(iParameter, szValue);
72 int DasherAppSettings::GetCount() {
73 return END_OF_APP_SPS;
76 bool DasherAppSettings::HaveAdvanced() {
77 return (g_find_program_in_path("gconf-editor") != NULL);
80 void DasherAppSettings::LaunchAdvanced() {
81 gchar *szArgs[3];
83 szArgs[0] = g_strdup("gconf-editor");
84 szArgs[1] = g_strdup("/apps/dasher4");
85 szArgs[2] = NULL;
87 GError *pError;
89 if(!g_spawn_async(NULL, szArgs, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &pError)) {
90 g_warning("Could not launch gconf-editor: %s", pError->message);
92 g_strfreev(szArgs);
95 void DasherAppSettings::SetWidget(GtkDasherControl *pWidget) {
96 pDasherWidget = pWidget;
99 GArray *DasherAppSettings::GetAllowedValues(int iParameter) {
100 return gtk_dasher_control_get_allowed_values(pDasherWidget, iParameter);
103 gboolean DasherAppSettings::GetModuleSettings(const gchar *szValue,
104 SModuleSettings **pSettings,
105 gint *iCount) {
106 return gtk_dasher_control_get_module_settings(pDasherWidget, szValue, pSettings, iCount);
109 // Set the option szKey to szValue. Return NULL if everything worked, a
110 // (literal) error string for unrecognized or illegal values.
111 const gchar * DasherAppSettings::ClSet(const gchar *szKey, const gchar *szValue) {
112 return settings_store_->ClSet(szKey, szValue);
115 void DasherAppSettings::HandleEvent(int iParameter) {
116 for (const auto& f : change_callbacks_) {
117 f.second(iParameter);
121 void option_help()
123 g_print("\n");
124 g_print("%-30s %-12s %s\n", _("Boolean parameters"), _("Default"), _("Description"));
125 g_print("%-30s %-12s %s\n", "------------------------------", "------------", "------------------------------");
126 for(unsigned int i=0; i < sizeof(app_boolparamtable)/sizeof(app_boolparamtable[0]); ++i) {
127 g_print("%-30s %-12s %s\n", app_boolparamtable[i].regName, (app_boolparamtable[i].defaultValue ? _("true") : _("false")), app_boolparamtable[i].humanReadable);
130 for(unsigned int i = 0; i < sizeof(boolparamtable)/sizeof(boolparamtable[0]); i++) {
131 g_print("%-30s %-12s %s\n", boolparamtable[i].regName, (boolparamtable[i].defaultValue ? _("true") : _("false")), boolparamtable[i].humanReadable);
134 g_print("\n");
135 g_print("%-30s %-12s %s\n", _("Integer parameters"), _("Default"), _("Description"));
136 g_print("%-30s %-12s %s\n", "------------------------------", "------------", "------------------------------");
137 for(unsigned int i=0; i < sizeof(app_longparamtable)/sizeof(app_longparamtable[0]); ++i) {
138 g_print("%-30s %12li %s\n", app_longparamtable[i].regName, app_longparamtable[i].defaultValue, app_longparamtable[i].humanReadable);
141 for(unsigned int i = 0; i < sizeof(longparamtable)/sizeof(longparamtable[0]); i++) {
142 g_print("%-30s %12li %s\n", longparamtable[i].regName, longparamtable[i].defaultValue, longparamtable[i].humanReadable);
145 g_print("\n");
146 g_print("%-30s %-12s %s\n", _("String parameters"), _("Default"), _("Description"));
147 g_print("%-30s %-12s %s\n", "------------------------------", "------------", "------------------------------");
148 for(unsigned int i=0; i < sizeof(app_stringparamtable)/sizeof(app_stringparamtable[0]); ++i) {
149 g_print("%-30s %-12s %s\n", app_stringparamtable[i].regName, app_stringparamtable[i].defaultValue, app_stringparamtable[i].humanReadable);
152 for(unsigned int i = 0; i < sizeof(stringparamtable)/sizeof(stringparamtable[0]); i++) {
153 g_print("%-30s %-12s %s\n", stringparamtable[i].regName, stringparamtable[i].defaultValue, stringparamtable[i].humanReadable);
157 void option_version()
159 g_print("\n");
160 // Note to translators: This is the version keyword showing for the command line option "--version"
161 g_print("%-30s %-30s \n", _("Version"), PACKAGE_VERSION);
162 // Note to translators: This is the license keyword showing for the command line option "--version"
163 g_print("%-30s %-30s\n", _("License"), "GPL 2+");