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))
42 SNAP_LARGE_VALUE = 16,
46 static gint snap_values [] = {
53 typedef struct _MaemoTweaksDesktopSection MaemoTweaksDesktopSection;
54 typedef struct _MaemoTweaksDesktopSectionClass
55 MaemoTweaksDesktopSectionClass;
57 struct _MaemoTweaksDesktopSection
59 MaemoTweaksSection parent_instance;
62 GtkWidget *snap_button;
65 struct _MaemoTweaksDesktopSectionClass
67 MaemoTweaksSectionClass parent_class;
71 static GType maemo_tweaks_desktop_section_get_type (GTypeModule *module);
72 static void maemo_tweaks_desktop_section_class_init
73 (MaemoTweaksDesktopSectionClass *class);
74 static void maemo_tweaks_desktop_section_init
75 (MaemoTweaksDesktopSection *section);
76 static void maemo_tweaks_desktop_section_dispose (GObject *obj);
78 static gboolean _save (MaemoTweaksSection *section,
79 gboolean *requires_restart);
81 static GType maemo_tweaks_desktop_section_type = 0;
82 static MaemoTweaksSectionClass *
83 maemo_tweaks_desktop_section_parent_class = NULL;
87 maemo_tweaks_module_load (MaemoTweaksModule *module)
89 maemo_tweaks_desktop_section_get_type (G_TYPE_MODULE (module));
93 maemo_tweaks_module_unload (MaemoTweaksModule *module)
98 maemo_tweaks_desktop_section_get_type (GTypeModule *module)
100 if (!maemo_tweaks_desktop_section_type)
102 static const GTypeInfo section_info =
104 sizeof (MaemoTweaksDesktopSectionClass),
105 (GBaseInitFunc) NULL,
106 (GBaseFinalizeFunc) NULL,
107 (GClassInitFunc) maemo_tweaks_desktop_section_class_init,
108 NULL, /* class_finalize */
109 NULL, /* class_data */
110 sizeof (MaemoTweaksDesktopSection),
112 (GInstanceInitFunc) maemo_tweaks_desktop_section_init
115 maemo_tweaks_desktop_section_type =
116 g_type_module_register_type (module, MAEMO_TWEAKS_TYPE_SECTION,
117 "MaemoTweaksDesktopSection",
121 return maemo_tweaks_desktop_section_type;
125 maemo_tweaks_desktop_section_class_init
126 (MaemoTweaksDesktopSectionClass *klass)
128 GObjectClass *object_class = G_OBJECT_CLASS (klass);
129 MaemoTweaksSectionClass *section_class =
130 MAEMO_TWEAKS_SECTION_CLASS (klass);
132 maemo_tweaks_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 = maemo_tweaks_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 maemo_tweaks_desktop_section_init (MaemoTweaksDesktopSection *section)
171 MaemoTweaksSection *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 = MAEMO_TWEAKS_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 maemo_tweaks_desktop_section_dispose (GObject *obj)
222 MaemoTweaksDesktopSection *section = MAEMO_TWEAKS_DESKTOP_SECTION (obj);
225 g_key_file_free (section->ini);
229 G_OBJECT_CLASS (maemo_tweaks_desktop_section_parent_class)->dispose
234 static gboolean _save (MaemoTweaksSection *section,
235 gboolean *requires_restart)
240 active = hildon_picker_button_get_active
241 (HILDON_PICKER_BUTTON (MAEMO_TWEAKS_DESKTOP_SECTION
242 (section)->snap_button));
244 argv[0] = g_strdup ("/usr/bin/maemo-tweaks-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);