diff options
author | Steve Zesch <[email protected]> | 2012-11-24 20:51:23 -0500 |
---|---|---|
committer | Steve Zesch <[email protected]> | 2012-11-24 20:51:23 -0500 |
commit | 90225e87811feb654e9a3c71734d0e6844f987ed (patch) | |
tree | 58030b0c20f6555d5387c7e0824b68fa9f242ba8 | |
parent | f2afbc975e249e765ee7d7452165912f1b4b479b (diff) | |
download | mate-calc-90225e87811feb654e9a3c71734d0e6844f987ed.tar.bz2 mate-calc-90225e87811feb654e9a3c71734d0e6844f987ed.tar.xz |
Fixed gsettings.
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/mate-calc.c | 163 | ||||
-rw-r--r-- | src/math-buttons.c | 4 | ||||
-rw-r--r-- | src/math-equation.c | 14 | ||||
-rw-r--r-- | src/math-preferences.c | 7 | ||||
-rw-r--r-- | src/math-window.c | 2 | ||||
-rw-r--r-- | src/utility.h | 8 |
7 files changed, 46 insertions, 155 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 03dbb78..3098879 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -60,7 +60,8 @@ mate_calc_SOURCES = \ parserfunc.c \ parserfunc.h \ parser.c \ - parser.h + parser.h \ + utility.h mate_calc_LDADD = \ $(MATE_CALC_LIBS) diff --git a/src/mate-calc.c b/src/mate-calc.c index f23ff38..39c7f23 100644 --- a/src/mate-calc.c +++ b/src/mate-calc.c @@ -19,8 +19,9 @@ #include "math-preferences.h" #include "mp-equation.h" #include "unit-manager.h" +#include "utility.h" -static GSettings *settings = NULL; +GSettings *g_settings_var = NULL; static MathWindow *window; @@ -170,132 +171,12 @@ get_options(int argc, char *argv[]) } } - -static void -accuracy_cb(MathEquation *equation, GParamSpec *spec) -{ - g_settings_set_int(settings, "accuracy", math_equation_get_accuracy(equation)); -} - - -static void -word_size_cb(MathEquation *equation, GParamSpec *spec) -{ - g_settings_set_int(settings, "word-size", math_equation_get_word_size(equation)); -} - - -static void -show_thousands_separators_cb(MathEquation *equation, GParamSpec *spec) -{ - g_settings_set_boolean(settings, "show-thousands", math_equation_get_show_thousands_separators(equation)); -} - - -static void -show_trailing_zeroes_cb(MathEquation *equation, GParamSpec *spec) -{ - g_settings_set_boolean(settings, "show-zeroes", math_equation_get_show_trailing_zeroes(equation)); -} - - -static void -number_format_cb(MathEquation *equation, GParamSpec *spec) -{ - g_settings_set_enum(settings, "number-format", math_equation_get_number_format(equation)); -} - - -static void -angle_unit_cb(MathEquation *equation, GParamSpec *spec) -{ - g_settings_set_enum(settings, "angle-units", math_equation_get_angle_units(equation)); -} - - -static void -source_currency_cb(MathEquation *equation, GParamSpec *spec) -{ - g_settings_set_string(settings, "source-currency", math_equation_get_source_currency(equation)); -} - - -static void -target_currency_cb(MathEquation *equation, GParamSpec *spec) -{ - g_settings_set_string(settings, "target-currency", math_equation_get_target_currency(equation)); -} - - -static void -source_units_cb(MathEquation *equation, GParamSpec *spec) -{ - g_settings_set_string(settings, "source-units", math_equation_get_source_units(equation)); -} - - -static void -target_units_cb(MathEquation *equation, GParamSpec *spec) -{ - g_settings_set_string(settings, "target-units", math_equation_get_target_units(equation)); -} - - -static void -programming_base_cb(MathButtons *buttons, GParamSpec *spec) -{ - g_settings_set_int(settings, "base", math_buttons_get_programming_base(buttons)); -} - - -/*static void -mode_cb(MathButtons *buttons, GParamSpec *spec) -{ - g_settings_set_enum(settings, "button-mode", math_buttons_get_mode(buttons)); - - switch(math_buttons_get_mode(buttons)) - { - default: - case BASIC: - state = "basic"; - //FIXME: Should it revert to decimal mode? math_equation_set_number_format(window->priv->equation, DEC); - break; - - case ADVANCED: - state = "advanced"; - break; - - case FINANCIAL: - state = "financial"; - break; - - case PROGRAMMING: - state = "programming"; - break; - } -}*/ - - static void quit_cb(MathWindow *window) { gtk_main_quit(); } - -/*static GActionEntry app_entries[] = { - { "copy", copy_cb, NULL, NULL, NULL }, - { "paste", paste_cb, NULL, NULL, NULL }, - { "undo", undo_cb, NULL, NULL, NULL }, - { "redo", redo_cb, NULL, NULL, NULL }, - { "mode", mode_changed_cb, "s", "\"basic\"", NULL }, - { "preferences", show_preferences_cb, NULL, NULL, NULL }, - { "help", help_cb, NULL, NULL, NULL }, - { "about", about_cb, NULL, NULL, NULL }, - { "quit", quit_cb, NULL, NULL, NULL }, -};*/ - - int main(int argc, char **argv) { MathEquation *equation; @@ -318,19 +199,19 @@ int main(int argc, char **argv) /* Seed random number generator. */ srand48((long) time((time_t *) 0)); - settings = g_settings_new ("org.mate.calc"); - accuracy = g_settings_get_int(settings, "accuracy"); - word_size = g_settings_get_int(settings, "word-size"); - base = g_settings_get_int(settings, "base"); - show_tsep = g_settings_get_boolean(settings, "show-thousands"); - show_zeroes = g_settings_get_boolean(settings, "show-zeroes"); - number_format = g_settings_get_enum(settings, "number-format"); - angle_units = g_settings_get_enum(settings, "angle-units"); - button_mode = g_settings_get_enum(settings, "button-mode"); - source_currency = g_settings_get_string(settings, "source-currency"); - target_currency = g_settings_get_string(settings, "target-currency"); - source_units = g_settings_get_string(settings, "source-units"); - target_units = g_settings_get_string(settings, "target-units"); + g_settings_var = g_settings_new ("org.mate.calc"); + accuracy = g_settings_get_int(g_settings_var, "accuracy"); + word_size = g_settings_get_int(g_settings_var, "word-size"); + base = g_settings_get_int(g_settings_var, "base"); + show_tsep = g_settings_get_boolean(g_settings_var, "show-thousands"); + show_zeroes = g_settings_get_boolean(g_settings_var, "show-zeroes"); + number_format = g_settings_get_enum(g_settings_var, "number-format"); + angle_units = g_settings_get_enum(g_settings_var, "angle-units"); + button_mode = g_settings_get_enum(g_settings_var, "button-mode"); + source_currency = g_settings_get_string(g_settings_var, "source-currency"); + target_currency = g_settings_get_string(g_settings_var, "target-currency"); + source_units = g_settings_get_string(g_settings_var, "source-units"); + target_units = g_settings_get_string(g_settings_var, "target-units"); equation = math_equation_new(); math_equation_set_accuracy(equation, accuracy); @@ -348,17 +229,6 @@ int main(int argc, char **argv) g_free(source_units); g_free(target_units); - g_signal_connect(equation, "notify::accuracy", G_CALLBACK(accuracy_cb), NULL); - g_signal_connect(equation, "notify::word-size", G_CALLBACK(word_size_cb), NULL); - g_signal_connect(equation, "notify::show-thousands-separators", G_CALLBACK(show_thousands_separators_cb), NULL); - g_signal_connect(equation, "notify::show-trailing-zeroes", G_CALLBACK(show_trailing_zeroes_cb), NULL); - g_signal_connect(equation, "notify::number-format", G_CALLBACK(number_format_cb), NULL); - g_signal_connect(equation, "notify::angle-units", G_CALLBACK(angle_unit_cb), NULL); - g_signal_connect(equation, "notify::source-currency", G_CALLBACK(source_currency_cb), NULL); - g_signal_connect(equation, "notify::target-currency", G_CALLBACK(target_currency_cb), NULL); - g_signal_connect(equation, "notify::source-units", G_CALLBACK(source_units_cb), NULL); - g_signal_connect(equation, "notify::target-units", G_CALLBACK(target_units_cb), NULL); - get_options(argc, argv); gtk_init(&argc, &argv); @@ -370,9 +240,6 @@ int main(int argc, char **argv) g_signal_connect(G_OBJECT(window), "quit", G_CALLBACK(quit_cb), NULL); math_buttons_set_programming_base(buttons, base); math_buttons_set_mode(buttons, button_mode); // FIXME: We load the basic buttons even if we immediately switch to the next type - g_signal_connect(buttons, "notify::programming-base", G_CALLBACK(programming_base_cb), NULL); - //g_signal_connect(buttons, "notify::mode", G_CALLBACK(mode_cb), NULL); - //mode_cb (buttons, NULL); gtk_widget_show(GTK_WIDGET(window)); gtk_main(); diff --git a/src/math-buttons.c b/src/math-buttons.c index a64c27f..ade7efc 100644 --- a/src/math-buttons.c +++ b/src/math-buttons.c @@ -15,6 +15,7 @@ #include "math-variable-popup.h" #include "financial.h" #include "mp-serializer.h" +#include "utility.h" enum { PROP_0, @@ -753,7 +754,8 @@ math_buttons_set_programming_base(MathButtons *buttons, gint base) return; buttons->priv->programming_base = base; - g_object_notify(G_OBJECT(buttons), "programming-base"); + + g_settings_set_int(g_settings_var, "base", math_buttons_get_programming_base(buttons)); if (buttons->priv->mode == PROGRAMMING) math_equation_set_base(buttons->priv->equation, base); diff --git a/src/math-equation.c b/src/math-equation.c index 5bcae64..323db0f 100644 --- a/src/math-equation.c +++ b/src/math-equation.c @@ -25,7 +25,7 @@ #include "mp-serializer.h" #include "mp-enums.h" #include "unit-manager.h" - +#include "utility.h" enum { PROP_0, @@ -671,7 +671,8 @@ math_equation_set_source_currency(MathEquation *equation, const gchar *currency) return; g_free(equation->priv->source_currency); equation->priv->source_currency = g_strdup(currency); - g_object_notify(G_OBJECT(equation), "source-currency"); + g_settings_set_string(g_settings_var, "source-currency", + math_equation_get_source_currency(equation)); } @@ -693,7 +694,8 @@ math_equation_set_target_currency(MathEquation *equation, const gchar *currency) return; g_free(equation->priv->target_currency); equation->priv->target_currency = g_strdup(currency); - g_object_notify(G_OBJECT(equation), "target-currency"); + g_settings_set_string(g_settings_var, "target-currency", + math_equation_get_target_currency(equation)); } @@ -716,7 +718,8 @@ math_equation_set_source_units(MathEquation *equation, const gchar *units) g_free(equation->priv->source_units); equation->priv->source_units = g_strdup(units); - g_object_notify(G_OBJECT(equation), "source-units"); + g_settings_set_string(g_settings_var, "source-units", + math_equation_get_source_units(equation)); } const gchar * @@ -738,7 +741,8 @@ math_equation_set_target_units(MathEquation *equation, const gchar *units) g_free(equation->priv->target_units); equation->priv->target_units = g_strdup(units); - g_object_notify(G_OBJECT(equation), "target-units"); + g_settings_set_string(g_settings_var, "target-units", + math_equation_get_target_units(equation)); } diff --git a/src/math-preferences.c b/src/math-preferences.c index 07190de..d6f4e25 100644 --- a/src/math-preferences.c +++ b/src/math-preferences.c @@ -12,6 +12,7 @@ #include <gtk/gtk.h> #include "math-preferences.h" +#include "utility.h" G_DEFINE_TYPE (MathPreferencesDialog, math_preferences, GTK_TYPE_DIALOG); @@ -167,6 +168,7 @@ accuracy_cb(MathEquation *equation, GParamSpec *spec, MathPreferencesDialog *dia { gtk_spin_button_set_value(GTK_SPIN_BUTTON(gtk_builder_get_object(dialog->priv->ui, "decimal_places_spin")), math_equation_get_accuracy(equation)); + g_settings_set_int(g_settings_var, "accuracy", math_equation_get_accuracy(equation)); } @@ -175,6 +177,7 @@ show_thousands_separators_cb(MathEquation *equation, GParamSpec *spec, MathPrefe { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtk_builder_get_object(dialog->priv->ui, "thousands_separator_check")), math_equation_get_show_thousands_separators(equation)); + g_settings_set_boolean(g_settings_var, "show-thousands", math_equation_get_show_thousands_separators(equation)); } @@ -183,6 +186,7 @@ show_trailing_zeroes_cb(MathEquation *equation, GParamSpec *spec, MathPreference { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtk_builder_get_object(dialog->priv->ui, "trailing_zeroes_check")), math_equation_get_show_trailing_zeroes(equation)); + g_settings_set_boolean(g_settings_var, "show-zeroes", math_equation_get_show_trailing_zeroes(equation)); } @@ -190,6 +194,7 @@ static void number_format_cb(MathEquation *equation, GParamSpec *spec, MathPreferencesDialog *dialog) { set_combo_box_from_int(GET_WIDGET(dialog->priv->ui, "number_format_combobox"), math_equation_get_number_format(equation)); + g_settings_set_enum(g_settings_var, "number-format", math_equation_get_number_format(equation)); } @@ -197,6 +202,7 @@ static void word_size_cb(MathEquation *equation, GParamSpec *spec, MathPreferencesDialog *dialog) { set_combo_box_from_int(GET_WIDGET(dialog->priv->ui, "word_size_combobox"), math_equation_get_word_size(equation)); + g_settings_set_int(g_settings_var, "word-size", math_equation_get_word_size(equation)); } @@ -204,6 +210,7 @@ static void angle_unit_cb(MathEquation *equation, GParamSpec *spec, MathPreferencesDialog *dialog) { set_combo_box_from_int(GET_WIDGET(dialog->priv->ui, "angle_unit_combobox"), math_equation_get_angle_units(equation)); + g_settings_set_enum(g_settings_var, "angle-units", math_equation_get_angle_units(equation)); } diff --git a/src/math-window.c b/src/math-window.c index 4692ec8..164a457 100644 --- a/src/math-window.c +++ b/src/math-window.c @@ -14,6 +14,7 @@ #include <gdk/gdkkeysyms.h> #include "math-window.h" +#include "utility.h" enum { PROP_0, @@ -295,6 +296,7 @@ static void button_mode_changed_cb(MathButtons *buttons, GParamSpec *spec, MathW } gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), TRUE); + g_settings_set_enum(g_settings_var, "button-mode", math_buttons_get_mode(buttons)); } static GtkWidget *add_menu(GtkWidget *menu_bar, const gchar *name) diff --git a/src/utility.h b/src/utility.h new file mode 100644 index 0000000..91745ed --- /dev/null +++ b/src/utility.h @@ -0,0 +1,8 @@ +#ifndef UTILITY_H +#define UTILITY_H + +#include <glib/gi18n.h> + +extern GSettings *g_settings_var; + +#endif |