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-entry.h>
13 #include <hildon/hildon-defines.h>
14 #include <hildon/hildon-banner.h>
16 #include <gconf/gconf-client.h>
18 #include <libprofile.h>
20 #include "libtweakr-section/tweakr-section.h"
21 #include "libtweakr-section/tweakr-module.h"
24 #define TWEAKR_TYPE_PROFILE_SECTION \
25 (tweakr_profile_section_type)
26 #define TWEAKR_PROFILE_SECTION(obj) \
27 (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
28 TWEAKR_TYPE_PROFILE_SECTION, \
29 TweakrProfileSection))
30 #define TWEAKR_PROFILE_SECTION_CLASS(k) \
31 (G_TYPE_CHECK_CLASS_CAST((k), \
32 TWEAKR_TYPE_PROFILE_SECTION, \
33 TweakrProfileSectionClass))
34 #define TWEAKR_IS_PROFILE_SECTION(obj) \
35 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
36 TWEAKR_TYPE_PROFILE_SECTION))
38 #define GCONF_PATH "/system/tweakr"
40 typedef struct _TweakrProfileSection TweakrProfileSection;
41 typedef struct _TweakrProfileSectionClass
42 TweakrProfileSectionClass;
44 struct _TweakrProfileSection
46 TweakrSection parent_instance;
48 GtkWidget *preset_button;
51 struct _TweakrProfileSectionClass
53 TweakrSectionClass parent_class;
57 static GType tweakr_profile_section_get_type (GTypeModule *module);
58 static void tweakr_profile_section_class_init
59 (TweakrProfileSectionClass *class);
60 static void tweakr_profile_section_init
61 (TweakrProfileSection *section);
62 static void tweakr_profile_section_dispose (GObject *obj);
64 static gboolean _save (TweakrSection *section,
65 gboolean *requires_restart);
67 static GType tweakr_profile_section_type = 0;
68 static TweakrSectionClass *
69 tweakr_profile_section_parent_class = NULL;
73 tweakr_module_load (TweakrModule *module)
75 tweakr_profile_section_get_type (G_TYPE_MODULE (module));
79 tweakr_module_unload (TweakrModule *module)
84 tweakr_profile_section_get_type (GTypeModule *module)
86 if (!tweakr_profile_section_type)
88 static const GTypeInfo section_info =
90 sizeof (TweakrProfileSectionClass),
92 (GBaseFinalizeFunc) NULL,
93 (GClassInitFunc) tweakr_profile_section_class_init,
94 NULL, /* class_finalize */
95 NULL, /* class_data */
96 sizeof (TweakrProfileSection),
98 (GInstanceInitFunc) tweakr_profile_section_init
101 tweakr_profile_section_type =
102 g_type_module_register_type (module, TWEAKR_TYPE_SECTION,
103 "TweakrProfileSection",
107 return tweakr_profile_section_type;
111 tweakr_profile_section_class_init
112 (TweakrProfileSectionClass *klass)
114 GObjectClass *object_class = G_OBJECT_CLASS (klass);
115 TweakrSectionClass *section_class =
116 TWEAKR_SECTION_CLASS (klass);
118 tweakr_profile_section_parent_class =
119 g_type_class_peek_parent (klass);
121 section_class->name = "_Profile";
122 section_class->save = _save;
124 object_class->dispose = tweakr_profile_section_dispose;
128 _save_preset_clicked (HildonPickerButton *button,
129 TweakrProfileSection *section)
132 GtkWidget *dialog, *entry;
133 const gchar* text = NULL;
135 parent = GTK_WINDOW (gtk_widget_get_ancestor (tweakr_section_get_widget
136 (TWEAKR_SECTION (section)),
138 dialog = gtk_dialog_new_with_buttons
141 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
142 GTK_STOCK_OK, GTK_RESPONSE_OK,
145 entry = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT);
146 gtk_widget_show (entry);
148 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), entry,
150 while (text == NULL || text [0] == '\0')
154 ret = gtk_dialog_run (GTK_DIALOG (dialog));
155 if (ret == GTK_RESPONSE_OK)
158 profileval_t *values, *values_iter;
161 text = hildon_entry_get_text (HILDON_ENTRY (entry));
162 if (text == NULL || text[0] == '\0')
166 banner = hildon_banner_show_information
167 (dialog, NULL, _("Enter the name first."));
172 /* Save the settings to our own gconf directory. */
174 gconf = gconf_client_get_default ();
175 gconf_client_set_string (gconf, GCONF_PATH "/current-preset",
177 values = profile_get_values ("general");
178 for (values_iter = values;
179 values_iter->pv_key != NULL;
184 g_snprintf (key, 128, "%s/%s/%s", GCONF_PATH, text,
185 values_iter->pv_key);
186 gconf_client_set_string (gconf, key, values_iter->pv_val,
189 profile_free_values (values);
190 g_object_unref (gconf);
192 banner = hildon_banner_show_information
193 (GTK_WIDGET (parent), NULL,
194 _("Preset saved. Use the status menu to select it."));
198 gtk_widget_destroy (dialog);
201 gtk_widget_destroy (dialog);
206 _build_save_preset_button (TweakrProfileSection *section)
210 button = hildon_button_new (HILDON_SIZE_AUTO |
211 HILDON_SIZE_FINGER_HEIGHT,
212 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
213 hildon_button_set_title (HILDON_BUTTON (button),
214 _("Save current General profile to new preset"));
215 gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f);
217 g_signal_connect (G_OBJECT (button), "clicked",
218 G_CALLBACK (_save_preset_clicked), section);
220 gtk_widget_show (button);
225 tweakr_profile_section_init (TweakrProfileSection *section)
227 TweakrSection *iface;
229 iface = TWEAKR_SECTION (section);
230 iface->name = _("Profile presets");
231 iface->widget = gtk_vbox_new (FALSE, 0);
233 section->preset_button = _build_save_preset_button (section);
235 gtk_box_pack_start (GTK_BOX (iface->widget), section->preset_button,
240 tweakr_profile_section_dispose (GObject *obj)
242 G_OBJECT_CLASS (tweakr_profile_section_parent_class)->dispose (obj);
245 static gboolean _save (TweakrSection *section, gboolean *requires_restart)