#include <hildon/hildon-entry.h>
#include <hildon/hildon-defines.h>
#include <hildon/hildon-banner.h>
+#include <hildon/hildon-pannable-area.h>
#include <gconf/gconf-client.h>
TweakrSection parent_instance;
GtkWidget *preset_button;
+ GtkWidget *delete_button;
+ GtkWidget *delete_dialog;
+ GtkWidget *delete_box;
+ GConfClient *gconf;
};
struct _TweakrProfileSectionClass
}
static void
+_preset_clicked (HildonButton *button, TweakrProfileSection *section)
+{
+ const gchar *path = g_object_get_data (G_OBJECT (button), "path");
+ gchar *basename;
+ gchar *current;
+
+ current = gconf_client_get_string (section->gconf,
+ GCONF_PATH "/current-preset",
+ NULL);
+ basename = g_path_get_basename (path);
+ if (g_strcmp0 (current, basename) == 0)
+ {
+ gconf_client_set_string (section->gconf,
+ GCONF_PATH "/current-preset", _("None"),
+ NULL);
+ }
+
+ gconf_client_recursive_unset (section->gconf, path, 0, NULL);
+ g_free (basename);
+ g_free (current);
+
+ gtk_dialog_response (GTK_DIALOG (section->delete_dialog),
+ GTK_RESPONSE_OK);
+ hildon_banner_show_information (NULL, NULL,
+ _("Preset deleted."));
+}
+
+static void
+_add_preset (gchar *preset, TweakrProfileSection *section)
+{
+ GtkWidget *button;
+ gchar *basename;
+
+ basename = g_path_get_basename (preset);
+ button = hildon_button_new_with_text
+ (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL,
+ basename, NULL);
+ gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f);
+ gtk_box_pack_start (GTK_BOX (section->delete_box), button, FALSE, FALSE,
+ 0);
+ g_object_set_data_full (G_OBJECT (button), "path", preset,
+ (GDestroyNotify) g_free);
+ g_signal_connect (button, "clicked", G_CALLBACK (_preset_clicked),
+ section);
+}
+
+static void
+_delete_preset_clicked (HildonButton *b, TweakrProfileSection *section)
+{
+ GtkWidget *panarea;
+ gint ret;
+ GSList *presets;
+ GtkWidget *parent;
+
+ parent = gtk_widget_get_ancestor (GTK_WIDGET (b), GTK_TYPE_WINDOW);
+
+ section->delete_dialog = gtk_dialog_new ();
+ gtk_window_set_modal (GTK_WINDOW (section->delete_dialog), TRUE);
+ gtk_window_set_title (GTK_WINDOW (section->delete_dialog),
+ _("Select preset"));
+
+ panarea = hildon_pannable_area_new ();
+ section->delete_box = gtk_vbox_new (FALSE, 0);
+
+ hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (panarea),
+ section->delete_box);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (section->delete_dialog)->vbox),
+ panarea, TRUE, TRUE, 0);
+
+ if (section->gconf == NULL)
+ {
+ section->gconf = gconf_client_get_default ();
+ }
+ presets = gconf_client_all_dirs (section->gconf, GCONF_PATH, NULL);
+
+ g_object_set (G_OBJECT (panarea), "height-request",
+ MIN (350, g_slist_length (presets) * 70), NULL);
+
+ g_slist_foreach (presets, (GFunc) _add_preset, section);
+
+ gtk_widget_show_all (GTK_DIALOG (section->delete_dialog)->vbox);
+ ret = gtk_dialog_run (GTK_DIALOG (section->delete_dialog));
+ gtk_widget_destroy (section->delete_dialog);
+
+ g_slist_free (presets);
+}
+
+static GtkWidget *
+_build_delete_preset_button (TweakrProfileSection *section)
+{
+ GtkWidget *button;
+
+ button = hildon_button_new (HILDON_SIZE_AUTO |
+ HILDON_SIZE_FINGER_HEIGHT,
+ HILDON_BUTTON_ARRANGEMENT_VERTICAL);
+ hildon_button_set_title (HILDON_BUTTON (button),
+ _("Delete a profile preset"));
+ gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f);
+
+ g_signal_connect (G_OBJECT (button), "clicked",
+ G_CALLBACK (_delete_preset_clicked), section);
+
+ gtk_widget_show (button);
+ return button;
+}
+
+static void
tweakr_profile_section_init (TweakrProfileSection *section)
{
TweakrSection *iface;
iface->widget = gtk_vbox_new (FALSE, 0);
section->preset_button = _build_save_preset_button (section);
+ section->delete_button = _build_delete_preset_button (section);
gtk_box_pack_start (GTK_BOX (iface->widget), section->preset_button,
FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (iface->widget), section->delete_button,
+ FALSE, FALSE, 0);
}
static void
tweakr_profile_section_dispose (GObject *obj)
{
+ TweakrProfileSection *section = TWEAKR_PROFILE_SECTION (obj);
+
+ if (section->gconf != NULL)
+ {
+ g_object_unref (section->gconf);
+ section->gconf = NULL;
+ }
+
G_OBJECT_CLASS (tweakr_profile_section_parent_class)->dispose (obj);
}