[gcalctool] Only write to GSettings when settings change, don't sync on exit
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool] Only write to GSettings when settings change, don't sync on exit
- Date: Wed, 20 Apr 2011 00:41:16 +0000 (UTC)
commit c8a001bd791bdd8a7ec05c199e4cb7253eaf5e7f
Author: Robert Ancell <robert ancell canonical com>
Date: Wed Apr 20 10:41:11 2011 +1000
Only write to GSettings when settings change, don't sync on exit
NEWS | 2 +
src/gcalctool.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++------
src/math-buttons.c | 25 ++++++++++++-
3 files changed, 115 insertions(+), 13 deletions(-)
---
diff --git a/NEWS b/NEWS
index 7a9c4b3..ad04e76 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,8 @@ Overview of changes in gcalctool 6.1.0
* Use nmi as label for nautical mile, use nm for nanometers (Bug #644682)
* Mark strings for translation that were missed
(Kjartan Maraas, Bug #646093)
+ * Only write to GSettings when settings change, don't sync on exit
+ (Bug #647327)
Overview of changes in gcalctool 6.0.0
diff --git a/src/gcalctool.c b/src/gcalctool.c
index 3c03670..c3349b3 100644
--- a/src/gcalctool.c
+++ b/src/gcalctool.c
@@ -171,28 +171,92 @@ get_options(int argc, char *argv[])
static void
-quit_cb(MathWindow *window)
+accuracy_cb(MathEquation *equation, GParamSpec *spec)
{
- MathEquation *equation;
- MathButtons *buttons;
+ g_settings_set_int(settings, "accuracy", math_equation_get_accuracy(equation));
+}
- equation = math_window_get_equation(window);
- buttons = math_window_get_buttons(window);
- 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));
- g_settings_set_int(settings, "base", math_buttons_get_programming_base(buttons));
+}
+
+
+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));
- g_settings_set_enum(settings, "button-mode", math_buttons_get_mode(buttons));
+}
+
+
+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));
- g_settings_sync();
+}
+
+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));
+}
+
+
+static void
+quit_cb(MathWindow *window)
+{
gtk_main_quit();
}
@@ -201,6 +265,7 @@ int
main(int argc, char **argv)
{
MathEquation *equation;
+ MathButtons *buttons;
int accuracy = 9, word_size = 64, base = 10;
gboolean show_tsep = FALSE, show_zeroes = FALSE;
MpDisplayFormat number_format;
@@ -251,12 +316,26 @@ 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);
+
gtk_init(&argc, &argv);
window = math_window_new(equation);
+ buttons = math_window_get_buttons(window);
g_signal_connect(G_OBJECT(window), "quit", G_CALLBACK(quit_cb), NULL);
- math_buttons_set_programming_base(math_window_get_buttons(window), base);
- math_buttons_set_mode(math_window_get_buttons(window), button_mode); // FIXME: We load the basic buttons even if we immediately switch to the next type
+ 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);
gtk_widget_show(GTK_WIDGET(window));
gtk_main();
diff --git a/src/math-buttons.c b/src/math-buttons.c
index 7b52cdf..d09b6db 100644
--- a/src/math-buttons.c
+++ b/src/math-buttons.c
@@ -19,7 +19,8 @@
enum {
PROP_0,
PROP_EQUATION,
- PROP_MODE
+ PROP_MODE,
+ PROP_PROGRAMMING_BASE
};
static GType button_mode_type;
@@ -455,7 +456,7 @@ base_combobox_changed_cb(GtkWidget *combo, MathButtons *buttons)
gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter);
gtk_tree_model_get(model, &iter, 1, &value, -1);
- math_equation_set_base(buttons->priv->equation, value);
+ math_buttons_set_programming_base(buttons, value);
}
@@ -790,7 +791,14 @@ math_buttons_get_mode(MathButtons *buttons)
void
math_buttons_set_programming_base(MathButtons *buttons, gint base)
{
+ if (base == buttons->priv->programming_base)
+ return;
+
buttons->priv->programming_base = base;
+ g_object_notify(G_OBJECT(buttons), "programming-base");
+
+ if (buttons->priv->mode == PROGRAMMING)
+ math_equation_set_base(buttons->priv->equation, base);
}
@@ -1315,6 +1323,9 @@ math_buttons_set_property(GObject *object,
case PROP_MODE:
math_buttons_set_mode(self, g_value_get_int(value));
break;
+ case PROP_PROGRAMMING_BASE:
+ math_buttons_set_programming_base(self, g_value_get_int(value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
@@ -1339,6 +1350,9 @@ math_buttons_get_property(GObject *object,
case PROP_MODE:
g_value_set_int(value, self->priv->mode);
break;
+ case PROP_PROGRAMMING_BASE:
+ g_value_set_int(value, math_buttons_get_programming_base(self));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
@@ -1381,6 +1395,13 @@ math_buttons_class_init(MathButtonsClass *klass)
button_mode_type,
BASIC,
G_PARAM_READWRITE));
+ g_object_class_install_property(object_class,
+ PROP_PROGRAMMING_BASE,
+ g_param_spec_int("programming-base",
+ "programming-base",
+ "Base to use in programming mode",
+ 2, 16, 10,
+ G_PARAM_READWRITE));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]