2 * vim:ts=4:sw=4:et:cindent:cino=(0
7 #include <glib/gi18n-lib.h>
10 #include <hildon/hildon-picker-button.h>
11 #include <hildon/hildon-touch-selector.h>
12 #include <hildon/hildon-button.h>
13 #include <hildon/hildon-entry.h>
14 #include <hildon/hildon-pannable-area.h>
15 #include <hildon/hildon-defines.h>
17 #include <gconf/gconf-client.h>
19 #include <libprofile.h>
21 #include "libtweakr-section/tweakr-section.h"
22 #include "libtweakr-section/tweakr-module.h"
25 #define TWEAKR_TYPE_PROFILE_SECTION \
26 (tweakr_profile_section_type)
27 #define TWEAKR_PROFILE_SECTION(obj) \
28 (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
29 TWEAKR_TYPE_PROFILE_SECTION, \
30 TweakrProfileSection))
31 #define TWEAKR_PROFILE_SECTION_CLASS(k) \
32 (G_TYPE_CHECK_CLASS_CAST((k), \
33 TWEAKR_TYPE_PROFILE_SECTION, \
34 TweakrProfileSectionClass))
35 #define TWEAKR_IS_PROFILE_SECTION(obj) \
36 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
37 TWEAKR_TYPE_PROFILE_SECTION))
39 typedef struct _TweakrProfileSection TweakrProfileSection;
40 typedef struct _TweakrProfileSectionClass
41 TweakrProfileSectionClass;
43 struct _TweakrProfileSection
45 TweakrSection parent_instance;
47 GtkWidget *profile_button;
50 struct _TweakrProfileSectionClass
52 TweakrSectionClass parent_class;
56 static GType tweakr_profile_section_get_type (GTypeModule *module);
57 static void tweakr_profile_section_class_init
58 (TweakrProfileSectionClass *class);
59 static void tweakr_profile_section_init
60 (TweakrProfileSection *section);
61 static void tweakr_profile_section_dispose (GObject *obj);
63 static gboolean _save (TweakrSection *section,
64 gboolean *requires_restart);
66 static GType tweakr_profile_section_type = 0;
67 static TweakrSectionClass *
68 tweakr_profile_section_parent_class = NULL;
72 tweakr_module_load (TweakrModule *module)
74 tweakr_profile_section_get_type (G_TYPE_MODULE (module));
78 tweakr_module_unload (TweakrModule *module)
83 tweakr_profile_section_get_type (GTypeModule *module)
85 if (!tweakr_profile_section_type)
87 static const GTypeInfo section_info =
89 sizeof (TweakrProfileSectionClass),
91 (GBaseFinalizeFunc) NULL,
92 (GClassInitFunc) tweakr_profile_section_class_init,
93 NULL, /* class_finalize */
94 NULL, /* class_data */
95 sizeof (TweakrProfileSection),
97 (GInstanceInitFunc) tweakr_profile_section_init
100 tweakr_profile_section_type =
101 g_type_module_register_type (module, TWEAKR_TYPE_SECTION,
102 "TweakrProfileSection",
106 return tweakr_profile_section_type;
110 tweakr_profile_section_class_init
111 (TweakrProfileSectionClass *klass)
113 GObjectClass *object_class = G_OBJECT_CLASS (klass);
114 TweakrSectionClass *section_class =
115 TWEAKR_SECTION_CLASS (klass);
117 tweakr_profile_section_parent_class =
118 g_type_class_peek_parent (klass);
120 section_class->name = "_Profile";
121 section_class->save = _save;
123 object_class->dispose = tweakr_profile_section_dispose;
127 _build_profile_select_button (TweakrProfileSection *section)
129 GtkWidget *button, *selector;
132 char *current_profile;
134 selector = hildon_touch_selector_new_text ();
135 hildon_touch_selector_append_text
136 (HILDON_TOUCH_SELECTOR (selector),
137 _("Save current profile with new name..."));
139 profiles = profile_get_profiles ();
140 for (i = 0; profiles && profiles[i] && profiles[i] != '\0'; i++)
143 * Gotta make some l10n substitution here.
145 const gchar *p = profiles[i];
147 if (strcmp (p, "general") == 0)
151 else if (strcmp (p, "silent") == 0)
156 hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
160 current_profile = profile_get_profile ();
161 for (i = 0; profiles[i] && profiles[i] != '\0'; i++)
163 if (g_strcmp0 (profiles[i], current_profile) == 0)
165 hildon_touch_selector_set_active
166 (HILDON_TOUCH_SELECTOR (selector), 0, i + 1);
169 g_free (current_profile);
170 profile_free_profiles (profiles);
172 button = hildon_picker_button_new (HILDON_SIZE_AUTO |
173 HILDON_SIZE_FINGER_HEIGHT,
174 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
175 hildon_button_set_title (HILDON_BUTTON (button),
176 _("Use custom profile"));
177 gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f);
178 hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
179 HILDON_TOUCH_SELECTOR (selector));
181 gtk_widget_show (button);
186 tweakr_profile_section_init (TweakrProfileSection *section)
188 TweakrSection *iface;
190 iface = TWEAKR_SECTION (section);
191 iface->name = _("Profile");
192 iface->widget = gtk_vbox_new (FALSE, 0);
194 section->profile_button = _build_profile_select_button (section);
196 gtk_box_pack_start (GTK_BOX (iface->widget), section->profile_button,
201 tweakr_profile_section_dispose (GObject *obj)
203 G_OBJECT_CLASS (tweakr_profile_section_parent_class)->dispose (obj);
206 static gboolean _save (TweakrSection *section, gboolean *requires_restart)