Support deletion of presets.
authorSalvatore Iovene <salvatore@iovene.com>
Sun, 20 Dec 2009 20:41:12 +0000 (22:41 +0200)
committerSalvatore Iovene <salvatore@iovene.com>
Sun, 20 Dec 2009 20:41:12 +0000 (22:41 +0200)
modules/tweakr-profile.c
po/en_GB.po
po/it_IT.po

index b24864d..128035c 100644 (file)
@@ -12,6 +12,7 @@
 #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>
 
@@ -46,6 +47,10 @@ struct _TweakrProfileSection
     TweakrSection parent_instance;
 
     GtkWidget *preset_button;
+    GtkWidget *delete_button;
+    GtkWidget *delete_dialog;
+    GtkWidget *delete_box;
+    GConfClient *gconf;
 };
 
 struct _TweakrProfileSectionClass
@@ -222,6 +227,113 @@ _build_save_preset_button (TweakrProfileSection *section)
 }
 
 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;
@@ -231,14 +343,25 @@ tweakr_profile_section_init (TweakrProfileSection *section)
     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);
 }
 
index 2a2342d..6bba378 100644 (file)
@@ -117,6 +117,15 @@ msgstr "Preset saved. Use the status menu to select it."
 msgid  "Save current General profile to new preset"
 msgstr "Save current General profile to new preset"
 
+msgid  "Preset deleted."
+msgstr "Preset deleted."
+
+msgid  "Select preset"
+msgstr "Select preset"
+
+msgid  "Delete a profile preset"
+msgstr "Delete a profile preset"
+
 # tweakr-profile-status-menu-widget.c
 msgid  "Preset activated."
 msgstr "Preset activated."
@@ -129,3 +138,4 @@ msgstr "Profile preset"
 
 msgid  "None"
 msgstr "None"
+
index ee4945d..649d4d7 100644 (file)
@@ -117,6 +117,15 @@ msgstr "Variante del profilo salvata. Puoi selezionarla nel menu di stato."
 msgid  "Save current General profile to new preset"
 msgstr "Nuova variante del profilo Generale"
 
+msgid  "Preset deleted."
+msgstr "Variante eliminata."
+
+msgid  "Select preset"
+msgstr "Seleziona una variante"
+
+msgid  "Delete a profile preset"
+msgstr "Elimina una variante di profilo"
+
 # tweakr-profile-status-menu-widget.c
 msgid  "Preset activated."
 msgstr "Variante attivata."