2 * vim:ts=4:sw=4:et:cindent:cino=(0
6 #include <glib/gi18n-lib.h>
9 #include <hildon/hildon-picker-button.h>
10 #include <hildon/hildon-touch-selector.h>
12 #include "libtweakr-section/tweakr-section.h"
13 #include "libtweakr-section/tweakr-module.h"
16 #define TWEAKR_TYPE_DESKTOP_SECTION \
17 (tweakr_desktop_section_type)
18 #define TWEAKR_DESKTOP_SECTION(obj) \
19 (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
20 TWEAKR_TYPE_DESKTOP_SECTION, \
21 TweakrDesktopSection))
22 #define TWEAKR_DESKTOP_SECTION_CLASS(k) \
23 (G_TYPE_CHECK_CLASS_CAST((k), \
24 TWEAKR_TYPE_DESKTOP_SECTION, \
25 TweakrDesktopSectionClass))
26 #define TWEAKR_IS_DESKTOP_SECTION(obj) \
27 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
28 TWEAKR_TYPE_DESKTOP_SECTION))
43 SNAP_LARGE_VALUE = 16,
47 static gint snap_values [] = {
54 typedef struct _TweakrDesktopSection TweakrDesktopSection;
55 typedef struct _TweakrDesktopSectionClass
56 TweakrDesktopSectionClass;
58 struct _TweakrDesktopSection
60 TweakrSection parent_instance;
63 GtkWidget *snap_button;
66 struct _TweakrDesktopSectionClass
68 TweakrSectionClass parent_class;
72 static GType tweakr_desktop_section_get_type (GTypeModule *module);
73 static void tweakr_desktop_section_class_init
74 (TweakrDesktopSectionClass *class);
75 static void tweakr_desktop_section_init
76 (TweakrDesktopSection *section);
77 static void tweakr_desktop_section_dispose (GObject *obj);
79 static gboolean _save (TweakrSection *section,
80 gboolean *requires_restart);
82 static GType tweakr_desktop_section_type = 0;
83 static TweakrSectionClass *
84 tweakr_desktop_section_parent_class = NULL;
88 tweakr_module_load (TweakrModule *module)
90 tweakr_desktop_section_get_type (G_TYPE_MODULE (module));
94 tweakr_module_unload (TweakrModule *module)
99 tweakr_desktop_section_get_type (GTypeModule *module)
101 if (!tweakr_desktop_section_type)
103 static const GTypeInfo section_info =
105 sizeof (TweakrDesktopSectionClass),
106 (GBaseInitFunc) NULL,
107 (GBaseFinalizeFunc) NULL,
108 (GClassInitFunc) tweakr_desktop_section_class_init,
109 NULL, /* class_finalize */
110 NULL, /* class_data */
111 sizeof (TweakrDesktopSection),
113 (GInstanceInitFunc) tweakr_desktop_section_init
116 tweakr_desktop_section_type =
117 g_type_module_register_type (module, TWEAKR_TYPE_SECTION,
118 "TweakrDesktopSection",
122 return tweakr_desktop_section_type;
126 tweakr_desktop_section_class_init
127 (TweakrDesktopSectionClass *klass)
129 GObjectClass *object_class = G_OBJECT_CLASS (klass);
130 TweakrSectionClass *section_class =
131 TWEAKR_SECTION_CLASS (klass);
133 tweakr_desktop_section_parent_class =
134 g_type_class_peek_parent (klass);
136 section_class->name = "_Desktop";
137 section_class->save = _save;
139 object_class->dispose = tweakr_desktop_section_dispose;
142 GtkWidget * _build_snap_to_grid (void)
144 const gchar *options[] =
153 GtkWidget *button, *selector;
155 selector = hildon_touch_selector_new_text ();
156 while (options[i] && options[i] != '\0')
158 hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
162 button = hildon_picker_button_new (HILDON_SIZE_AUTO,
163 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
164 hildon_gtk_widget_set_theme_size (button, HILDON_SIZE_FINGER_HEIGHT);
166 hildon_button_set_title (HILDON_BUTTON (button),
167 _("Snap icons to grid"));
168 gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f);
169 hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
170 HILDON_TOUCH_SELECTOR (selector));
172 gtk_widget_show (button);
177 tweakr_desktop_section_init (TweakrDesktopSection *section)
179 TweakrSection *iface;
181 gint snap_value = SNAP_NONE_VALUE;
183 section->snap_button = _build_snap_to_grid ();
185 section->ini = g_key_file_new ();
187 if (!g_key_file_load_from_file (section->ini, TRANSITIONS,
188 G_KEY_FILE_NONE, NULL))
190 g_warning ("%s: failed to load %s", G_STRFUNC, TRANSITIONS);
194 snap_value = g_key_file_get_integer (section->ini, "edit_mode",
195 "snap_grid_size", NULL);
197 if (snap_value < SNAP_SMALL_VALUE)
199 hildon_picker_button_set_active
200 (HILDON_PICKER_BUTTON (section->snap_button), SNAP_NONE);
202 else if (snap_value < SNAP_LARGE_VALUE)
204 hildon_picker_button_set_active
205 (HILDON_PICKER_BUTTON (section->snap_button), SNAP_SMALL);
207 else if (snap_value < SNAP_HUGE_VALUE)
209 hildon_picker_button_set_active
210 (HILDON_PICKER_BUTTON (section->snap_button), SNAP_LARGE);
214 hildon_picker_button_set_active
215 (HILDON_PICKER_BUTTON (section->snap_button), SNAP_HUGE);
220 iface = TWEAKR_SECTION (section);
221 iface->name = _("Desktop");
222 iface->widget = gtk_vbox_new (FALSE, 0);
223 gtk_box_pack_start (GTK_BOX (iface->widget), section->snap_button,
228 tweakr_desktop_section_dispose (GObject *obj)
230 TweakrDesktopSection *section = TWEAKR_DESKTOP_SECTION (obj);
233 g_key_file_free (section->ini);
237 G_OBJECT_CLASS (tweakr_desktop_section_parent_class)->dispose
242 static gboolean _save (TweakrSection *section,
243 gboolean *requires_restart)
248 active = hildon_picker_button_get_active
249 (HILDON_PICKER_BUTTON (TWEAKR_DESKTOP_SECTION
250 (section)->snap_button));
252 argv[0] = g_strdup ("/usr/bin/tweakr-desktop-save");
253 argv[1] = g_strdup_printf ("%d", snap_values[active]);
256 g_spawn_sync ("/home/user", argv, NULL,
257 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
258 NULL, NULL, NULL, NULL, NULL, NULL);