2 * vim:ts=4:sw=4:et:cindent:cino=(0
8 #include <hildon/hildon-picker-button.h>
9 #include <hildon/hildon-touch-selector.h>
11 #include "libmaemo-tweaks-section/maemo-tweaks-section.h"
12 #include "libmaemo-tweaks-section/maemo-tweaks-module.h"
15 #define MAEMO_TWEAKS_TYPE_DESKTOP_SECTION \
16 (maemo_tweaks_desktop_section_type)
17 #define MAEMO_TWEAKS_DESKTOP_SECTION(obj) \
18 (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
19 MAEMO_TWEAKS_TYPE_DESKTOP_SECTION, \
20 MaemoTweaksDesktopSection))
21 #define MAEMO_TWEAKS_DESKTOP_SECTION_CLASS(k) \
22 (G_TYPE_CHECK_CLASS_CAST((k), \
23 MAEMO_TWEAKS_TYPE_DESKTOP_SECTION, \
24 MaemoTweaksDesktopSectionClass))
25 #define MAEMO_TWEAKS_IS_DESKTOP_SECTION(obj) \
26 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
27 MAEMO_TWEAKS_TYPE_DESKTOP_SECTION))
44 static gint snap_values [] = {
50 typedef struct _MaemoTweaksDesktopSection MaemoTweaksDesktopSection;
51 typedef struct _MaemoTweaksDesktopSectionClass
52 MaemoTweaksDesktopSectionClass;
54 struct _MaemoTweaksDesktopSection
56 MaemoTweaksSection parent_instance;
59 GtkWidget *snap_button;
62 struct _MaemoTweaksDesktopSectionClass
64 MaemoTweaksSectionClass parent_class;
68 static GType maemo_tweaks_desktop_section_get_type (GTypeModule *module);
69 static void maemo_tweaks_desktop_section_class_init
70 (MaemoTweaksDesktopSectionClass *class);
71 static void maemo_tweaks_desktop_section_init
72 (MaemoTweaksDesktopSection *section);
73 static void maemo_tweaks_desktop_section_dispose (GObject *obj);
75 static void _save (MaemoTweaksSection *section);
77 static GType maemo_tweaks_desktop_section_type = 0;
78 static MaemoTweaksSectionClass *
79 maemo_tweaks_desktop_section_parent_class = NULL;
83 maemo_tweaks_module_load (MaemoTweaksModule *module)
85 maemo_tweaks_desktop_section_get_type (G_TYPE_MODULE (module));
89 maemo_tweaks_module_unload (MaemoTweaksModule *module)
94 maemo_tweaks_desktop_section_get_type (GTypeModule *module)
96 if (!maemo_tweaks_desktop_section_type)
98 static const GTypeInfo section_info =
100 sizeof (MaemoTweaksDesktopSectionClass),
101 (GBaseInitFunc) NULL,
102 (GBaseFinalizeFunc) NULL,
103 (GClassInitFunc) maemo_tweaks_desktop_section_class_init,
104 NULL, /* class_finalize */
105 NULL, /* class_data */
106 sizeof (MaemoTweaksDesktopSection),
108 (GInstanceInitFunc) maemo_tweaks_desktop_section_init
111 maemo_tweaks_desktop_section_type =
112 g_type_module_register_type (module, MAEMO_TWEAKS_TYPE_SECTION,
113 "MaemoTweaksDesktopSection",
117 return maemo_tweaks_desktop_section_type;
121 maemo_tweaks_desktop_section_class_init
122 (MaemoTweaksDesktopSectionClass *klass)
124 GObjectClass *object_class = G_OBJECT_CLASS (klass);
125 MaemoTweaksSectionClass *section_class =
126 MAEMO_TWEAKS_SECTION_CLASS (klass);
128 maemo_tweaks_desktop_section_parent_class =
129 g_type_class_peek_parent (klass);
131 section_class->name = "_Desktop";
132 section_class->save = _save;
134 object_class->dispose = maemo_tweaks_desktop_section_dispose;
137 GtkWidget * _build_snap_to_grid (void)
139 const gchar *options[] = {"None", "Small grid", "Large grid", NULL};
141 GtkWidget *button, *selector;
143 selector = hildon_touch_selector_new_text ();
144 while (options[i] && options[i] != '\0')
146 hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
150 button = hildon_picker_button_new (HILDON_SIZE_AUTO,
151 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
153 hildon_button_set_title (HILDON_BUTTON (button),
154 "Snap desktop icons to grid");
155 gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f);
156 hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
157 HILDON_TOUCH_SELECTOR (selector));
159 gtk_widget_show (button);
164 maemo_tweaks_desktop_section_init (MaemoTweaksDesktopSection *section)
166 MaemoTweaksSection *iface;
168 gint snap_value = SNAP_NONE_VALUE;
170 section->snap_button = _build_snap_to_grid ();
172 section->ini = g_key_file_new ();
174 if (!g_key_file_load_from_file (section->ini, TRANSITIONS,
175 G_KEY_FILE_NONE, NULL))
177 g_warning ("%s: failed to load %s", G_STRFUNC, TRANSITIONS);
181 snap_value = g_key_file_get_integer (section->ini, "edit_mode",
182 "snap_grid_size", NULL);
184 if (snap_value < SNAP_SMALL_VALUE)
186 hildon_picker_button_set_active
187 (HILDON_PICKER_BUTTON (section->snap_button), SNAP_NONE);
189 else if (snap_value < SNAP_LARGE_VALUE)
191 hildon_picker_button_set_active
192 (HILDON_PICKER_BUTTON (section->snap_button), SNAP_SMALL);
196 hildon_picker_button_set_active
197 (HILDON_PICKER_BUTTON (section->snap_button), SNAP_LARGE);
201 iface = MAEMO_TWEAKS_SECTION (section);
202 iface->widget = gtk_vbox_new (FALSE, 0);
203 gtk_box_pack_start (GTK_BOX (iface->widget), section->snap_button,
208 maemo_tweaks_desktop_section_dispose (GObject *obj)
210 MaemoTweaksDesktopSection *section = MAEMO_TWEAKS_DESKTOP_SECTION (obj);
213 g_key_file_free (section->ini);
217 G_OBJECT_CLASS (maemo_tweaks_desktop_section_parent_class)->dispose
222 static void _save (MaemoTweaksSection *section)
227 active = hildon_picker_button_get_active
228 (HILDON_PICKER_BUTTON (MAEMO_TWEAKS_DESKTOP_SECTION
229 (section)->snap_button));
231 argv[0] = g_strdup ("/usr/bin/maemo-tweaks-desktop-save");
232 argv[1] = g_strdup_printf ("%d", snap_values[active]);
234 g_spawn_sync ("/home/user", argv, NULL,
235 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
236 NULL, NULL, NULL, NULL, NULL, NULL);