From a41fa81cc6fc94f33e7524bee141163c4f1121eb Mon Sep 17 00:00:00 2001 From: Salvatore Iovene Date: Sun, 6 Dec 2009 17:43:51 +0200 Subject: [PATCH] Reading and writing the snap_grid_size. --- modules/Makefile.am | 3 +- modules/maemo-tweaks-desktop.c | 90 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 87 insertions(+), 6 deletions(-) diff --git a/modules/Makefile.am b/modules/Makefile.am index 9201d8c..5da1f12 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -4,7 +4,8 @@ libmaemo_tweaks_section = \ AM_CPPFLAGS = \ -I$(top_srcdir) \ $(GTK_CFLAGS) \ - $(HILDON_CFLAGS) + $(HILDON_CFLAGS) \ + -DTRANSITIONS=\"/usr/share/hildon-desktop/transitions.ini\" modulesdir = $(libdir)/maemo-tweaks/modules diff --git a/modules/maemo-tweaks-desktop.c b/modules/maemo-tweaks-desktop.c index c5b26ed..39754c5 100644 --- a/modules/maemo-tweaks-desktop.c +++ b/modules/maemo-tweaks-desktop.c @@ -27,6 +27,26 @@ MAEMO_TWEAKS_TYPE_DESKTOP_SECTION)) +enum +{ + SNAP_NONE, + SNAP_SMALL, + SNAP_LARGE +}; + +enum +{ + SNAP_NONE_VALUE, + SNAP_SMALL_VALUE = 8, + SNAP_LARGE_VALUE = 16 +}; + +static gint snap_values [] = { + SNAP_NONE_VALUE, + SNAP_SMALL_VALUE, + SNAP_LARGE_VALUE +}; + typedef struct _MaemoTweaksDesktopSection MaemoTweaksDesktopSection; typedef struct _MaemoTweaksDesktopSectionClass MaemoTweaksDesktopSectionClass; @@ -34,6 +54,9 @@ typedef struct _MaemoTweaksDesktopSectionClass struct _MaemoTweaksDesktopSection { MaemoTweaksSection parent_instance; + + GKeyFile *ini; + GtkWidget *snap_button; }; struct _MaemoTweaksDesktopSectionClass @@ -47,6 +70,7 @@ static void maemo_tweaks_desktop_section_class_init (MaemoTweaksDesktopSectionClass *class); static void maemo_tweaks_desktop_section_init (MaemoTweaksDesktopSection *section); +static void maemo_tweaks_desktop_section_dispose (GObject *obj); static void _save (MaemoTweaksSection *section); @@ -97,6 +121,7 @@ static void maemo_tweaks_desktop_section_class_init (MaemoTweaksDesktopSectionClass *klass) { + GObjectClass *object_class = G_OBJECT_CLASS (klass); MaemoTweaksSectionClass *section_class = MAEMO_TWEAKS_SECTION_CLASS (klass); @@ -105,11 +130,13 @@ maemo_tweaks_desktop_section_class_init section_class->name = "_Desktop"; section_class->save = _save; + + object_class->dispose = maemo_tweaks_desktop_section_dispose; } GtkWidget * _build_snap_to_grid (void) { - const gchar *options[] = {"Default", "Small grid", "Large grid", NULL}; + const gchar *options[] = {"None", "Small grid", "Large grid", NULL}; gint i = 0; GtkWidget *button, *selector; @@ -136,18 +163,71 @@ GtkWidget * _build_snap_to_grid (void) static void maemo_tweaks_desktop_section_init (MaemoTweaksDesktopSection *section) { - GtkWidget * snap_button; MaemoTweaksSection *iface; - snap_button = _build_snap_to_grid (); - iface = MAEMO_TWEAKS_SECTION (section); + gint snap_value = SNAP_NONE_VALUE; + + section->snap_button = _build_snap_to_grid (); + + section->ini = g_key_file_new (); + + if (!g_key_file_load_from_file (section->ini, TRANSITIONS, + G_KEY_FILE_NONE, NULL)) + { + g_warning ("%s: failed to load %s", G_STRFUNC, TRANSITIONS); + return; + } + + snap_value = g_key_file_get_integer (section->ini, "edit_mode", + "snap_grid_size", NULL); + if (snap_value < SNAP_SMALL_VALUE) + { + hildon_picker_button_set_active + (HILDON_PICKER_BUTTON (section->snap_button), SNAP_NONE); + } + else if (snap_value < SNAP_LARGE_VALUE) + { + hildon_picker_button_set_active + (HILDON_PICKER_BUTTON (section->snap_button), SNAP_SMALL); + } + else + { + hildon_picker_button_set_active + (HILDON_PICKER_BUTTON (section->snap_button), SNAP_LARGE); + } + + + iface = MAEMO_TWEAKS_SECTION (section); iface->widget = gtk_vbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (iface->widget), snap_button, + gtk_box_pack_start (GTK_BOX (iface->widget), section->snap_button, TRUE, TRUE, 0); } +static void +maemo_tweaks_desktop_section_dispose (GObject *obj) +{ + MaemoTweaksDesktopSection *section = MAEMO_TWEAKS_DESKTOP_SECTION (obj); + if (section->ini) + { + g_key_file_free (section->ini); + section->ini = NULL; + } + + G_OBJECT_CLASS (maemo_tweaks_desktop_section_parent_class)->dispose + (obj); +} + + static void _save (MaemoTweaksSection *section) { + gint active = + hildon_picker_button_get_active + (HILDON_PICKER_BUTTON + (MAEMO_TWEAKS_DESKTOP_SECTION (section)->snap_button)); + + g_key_file_set_integer (MAEMO_TWEAKS_DESKTOP_SECTION (section)->ini, + "edit_mode", "snap_grid_size", + snap_values [active]); } -- 1.7.9.5