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 gboolean _save (MaemoTweaksSection *section,
76 gboolean *requires_restart);
78 static GType maemo_tweaks_desktop_section_type = 0;
79 static MaemoTweaksSectionClass *
80 maemo_tweaks_desktop_section_parent_class = NULL;
84 maemo_tweaks_module_load (MaemoTweaksModule *module)
86 maemo_tweaks_desktop_section_get_type (G_TYPE_MODULE (module));
90 maemo_tweaks_module_unload (MaemoTweaksModule *module)
95 maemo_tweaks_desktop_section_get_type (GTypeModule *module)
97 if (!maemo_tweaks_desktop_section_type)
99 static const GTypeInfo section_info =
101 sizeof (MaemoTweaksDesktopSectionClass),
102 (GBaseInitFunc) NULL,
103 (GBaseFinalizeFunc) NULL,
104 (GClassInitFunc) maemo_tweaks_desktop_section_class_init,
105 NULL, /* class_finalize */
106 NULL, /* class_data */
107 sizeof (MaemoTweaksDesktopSection),
109 (GInstanceInitFunc) maemo_tweaks_desktop_section_init
112 maemo_tweaks_desktop_section_type =
113 g_type_module_register_type (module, MAEMO_TWEAKS_TYPE_SECTION,
114 "MaemoTweaksDesktopSection",
118 return maemo_tweaks_desktop_section_type;
122 maemo_tweaks_desktop_section_class_init
123 (MaemoTweaksDesktopSectionClass *klass)
125 GObjectClass *object_class = G_OBJECT_CLASS (klass);
126 MaemoTweaksSectionClass *section_class =
127 MAEMO_TWEAKS_SECTION_CLASS (klass);
129 maemo_tweaks_desktop_section_parent_class =
130 g_type_class_peek_parent (klass);
132 section_class->name = "_Desktop";
133 section_class->save = _save;
135 object_class->dispose = maemo_tweaks_desktop_section_dispose;
138 GtkWidget * _build_snap_to_grid (void)
140 const gchar *options[] = {"None", "Small grid", "Large grid", NULL};
142 GtkWidget *button, *selector;
144 selector = hildon_touch_selector_new_text ();
145 while (options[i] && options[i] != '\0')
147 hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
151 button = hildon_picker_button_new (HILDON_SIZE_AUTO,
152 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
154 hildon_button_set_title (HILDON_BUTTON (button),
155 "Snap desktop icons to grid");
156 gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f);
157 hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
158 HILDON_TOUCH_SELECTOR (selector));
160 gtk_widget_show (button);
165 maemo_tweaks_desktop_section_init (MaemoTweaksDesktopSection *section)
167 MaemoTweaksSection *iface;
169 gint snap_value = SNAP_NONE_VALUE;
171 section->snap_button = _build_snap_to_grid ();
173 section->ini = g_key_file_new ();
175 if (!g_key_file_load_from_file (section->ini, TRANSITIONS,
176 G_KEY_FILE_NONE, NULL))
178 g_warning ("%s: failed to load %s", G_STRFUNC, TRANSITIONS);
182 snap_value = g_key_file_get_integer (section->ini, "edit_mode",
183 "snap_grid_size", NULL);
185 if (snap_value < SNAP_SMALL_VALUE)
187 hildon_picker_button_set_active
188 (HILDON_PICKER_BUTTON (section->snap_button), SNAP_NONE);
190 else if (snap_value < SNAP_LARGE_VALUE)
192 hildon_picker_button_set_active
193 (HILDON_PICKER_BUTTON (section->snap_button), SNAP_SMALL);
197 hildon_picker_button_set_active
198 (HILDON_PICKER_BUTTON (section->snap_button), SNAP_LARGE);
202 iface = MAEMO_TWEAKS_SECTION (section);
203 iface->name = "Desktop";
204 iface->widget = gtk_vbox_new (FALSE, 0);
205 gtk_box_pack_start (GTK_BOX (iface->widget), section->snap_button,
210 maemo_tweaks_desktop_section_dispose (GObject *obj)
212 MaemoTweaksDesktopSection *section = MAEMO_TWEAKS_DESKTOP_SECTION (obj);
215 g_key_file_free (section->ini);
219 G_OBJECT_CLASS (maemo_tweaks_desktop_section_parent_class)->dispose
224 static gboolean _save (MaemoTweaksSection *section,
225 gboolean *requires_restart)
230 active = hildon_picker_button_get_active
231 (HILDON_PICKER_BUTTON (MAEMO_TWEAKS_DESKTOP_SECTION
232 (section)->snap_button));
234 argv[0] = g_strdup ("/usr/bin/maemo-tweaks-desktop-save");
235 argv[1] = g_strdup_printf ("%d", snap_values[active]);
238 g_spawn_sync ("/home/user", argv, NULL,
239 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
240 NULL, NULL, NULL, NULL, NULL, NULL);