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 "libtweakr-section/tweakr-section.h"
12 #include "libtweakr-section/tweakr-module.h"
15 #define TWEAKR_TYPE_DESKTOP_SECTION \
16 (tweakr_desktop_section_type)
17 #define TWEAKR_DESKTOP_SECTION(obj) \
18 (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
19 TWEAKR_TYPE_DESKTOP_SECTION, \
20 TweakrDesktopSection))
21 #define TWEAKR_DESKTOP_SECTION_CLASS(k) \
22 (G_TYPE_CHECK_CLASS_CAST((k), \
23 TWEAKR_TYPE_DESKTOP_SECTION, \
24 TweakrDesktopSectionClass))
25 #define TWEAKR_IS_DESKTOP_SECTION(obj) \
26 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
27 TWEAKR_TYPE_DESKTOP_SECTION))
42 SNAP_LARGE_VALUE = 16,
46 static gint snap_values [] = {
53 typedef struct _TweakrDesktopSection TweakrDesktopSection;
54 typedef struct _TweakrDesktopSectionClass
55 TweakrDesktopSectionClass;
57 struct _TweakrDesktopSection
59 TweakrSection parent_instance;
62 GtkWidget *snap_button;
65 struct _TweakrDesktopSectionClass
67 TweakrSectionClass parent_class;
71 static GType tweakr_desktop_section_get_type (GTypeModule *module);
72 static void tweakr_desktop_section_class_init
73 (TweakrDesktopSectionClass *class);
74 static void tweakr_desktop_section_init
75 (TweakrDesktopSection *section);
76 static void tweakr_desktop_section_dispose (GObject *obj);
78 static gboolean _save (TweakrSection *section,
79 gboolean *requires_restart);
81 static GType tweakr_desktop_section_type = 0;
82 static TweakrSectionClass *
83 tweakr_desktop_section_parent_class = NULL;
87 tweakr_module_load (TweakrModule *module)
89 tweakr_desktop_section_get_type (G_TYPE_MODULE (module));
93 tweakr_module_unload (TweakrModule *module)
98 tweakr_desktop_section_get_type (GTypeModule *module)
100 if (!tweakr_desktop_section_type)
102 static const GTypeInfo section_info =
104 sizeof (TweakrDesktopSectionClass),
105 (GBaseInitFunc) NULL,
106 (GBaseFinalizeFunc) NULL,
107 (GClassInitFunc) tweakr_desktop_section_class_init,
108 NULL, /* class_finalize */
109 NULL, /* class_data */
110 sizeof (TweakrDesktopSection),
112 (GInstanceInitFunc) tweakr_desktop_section_init
115 tweakr_desktop_section_type =
116 g_type_module_register_type (module, TWEAKR_TYPE_SECTION,
117 "TweakrDesktopSection",
121 return tweakr_desktop_section_type;
125 tweakr_desktop_section_class_init
126 (TweakrDesktopSectionClass *klass)
128 GObjectClass *object_class = G_OBJECT_CLASS (klass);
129 TweakrSectionClass *section_class =
130 TWEAKR_SECTION_CLASS (klass);
132 tweakr_desktop_section_parent_class =
133 g_type_class_peek_parent (klass);
135 section_class->name = "_Desktop";
136 section_class->save = _save;
138 object_class->dispose = tweakr_desktop_section_dispose;
141 GtkWidget * _build_snap_to_grid (void)
143 const gchar *options[] = {"No", "Small", "Large", "Huge", NULL};
145 GtkWidget *button, *selector;
147 selector = hildon_touch_selector_new_text ();
148 while (options[i] && options[i] != '\0')
150 hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
154 button = hildon_picker_button_new (HILDON_SIZE_AUTO,
155 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
156 hildon_gtk_widget_set_theme_size (button, HILDON_SIZE_FINGER_HEIGHT);
158 hildon_button_set_title (HILDON_BUTTON (button),
159 "Snap icons to grid");
160 gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f);
161 hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
162 HILDON_TOUCH_SELECTOR (selector));
164 gtk_widget_show (button);
169 tweakr_desktop_section_init (TweakrDesktopSection *section)
171 TweakrSection *iface;
173 gint snap_value = SNAP_NONE_VALUE;
175 section->snap_button = _build_snap_to_grid ();
177 section->ini = g_key_file_new ();
179 if (!g_key_file_load_from_file (section->ini, TRANSITIONS,
180 G_KEY_FILE_NONE, NULL))
182 g_warning ("%s: failed to load %s", G_STRFUNC, TRANSITIONS);
186 snap_value = g_key_file_get_integer (section->ini, "edit_mode",
187 "snap_grid_size", NULL);
189 if (snap_value < SNAP_SMALL_VALUE)
191 hildon_picker_button_set_active
192 (HILDON_PICKER_BUTTON (section->snap_button), SNAP_NONE);
194 else if (snap_value < SNAP_LARGE_VALUE)
196 hildon_picker_button_set_active
197 (HILDON_PICKER_BUTTON (section->snap_button), SNAP_SMALL);
199 else if (snap_value < SNAP_HUGE_VALUE)
201 hildon_picker_button_set_active
202 (HILDON_PICKER_BUTTON (section->snap_button), SNAP_LARGE);
206 hildon_picker_button_set_active
207 (HILDON_PICKER_BUTTON (section->snap_button), SNAP_HUGE);
212 iface = TWEAKR_SECTION (section);
213 iface->name = "Desktop";
214 iface->widget = gtk_vbox_new (FALSE, 0);
215 gtk_box_pack_start (GTK_BOX (iface->widget), section->snap_button,
220 tweakr_desktop_section_dispose (GObject *obj)
222 TweakrDesktopSection *section = TWEAKR_DESKTOP_SECTION (obj);
225 g_key_file_free (section->ini);
229 G_OBJECT_CLASS (tweakr_desktop_section_parent_class)->dispose
234 static gboolean _save (TweakrSection *section,
235 gboolean *requires_restart)
240 active = hildon_picker_button_get_active
241 (HILDON_PICKER_BUTTON (TWEAKR_DESKTOP_SECTION
242 (section)->snap_button));
244 argv[0] = g_strdup ("/usr/bin/tweakr-desktop-save");
245 argv[1] = g_strdup_printf ("%d", snap_values[active]);
248 g_spawn_sync ("/home/user", argv, NULL,
249 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
250 NULL, NULL, NULL, NULL, NULL, NULL);