Only edit desktop bookmarks that are on some view.
[tweakr] / modules / tweakr-desktop.c
index e66b296..c814cff 100644 (file)
@@ -34,6 +34,8 @@
         TWEAKR_TYPE_DESKTOP_SECTION))
 
 #define GCONF_BOOKMARKS "/apps/osso/hildon-home/bookmarks"
+#define GCONF_APPLETS   "/apps/osso/hildon-desktop/applets"
+
 enum
 {
     SNAP_NONE,
@@ -255,35 +257,55 @@ _add_bookmark (gchar *bookmark, TweakrDesktopSection *section)
     gchar *title, *value, *url;
     GtkWidget *button;
 
+    gchar *bookmark_name;
+    gchar *applet_path;
+    gchar *view_path;
+
     b = g_new0 (bookmark_t, 1);
     b->path = g_strconcat (bookmark, "/label", NULL);
 
     url   = g_strconcat (bookmark, "/url",   NULL);
     title = gconf_client_get_string (section->gconf, b->path, NULL);
-    value = gconf_client_get_string (section->gconf, url,   NULL);
+    value = gconf_client_get_string (section->gconf, url,     NULL);
 
     g_free (url);
 
-    button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,
-                                          HILDON_BUTTON_ARRANGEMENT_VERTICAL,
-                                          title, value);
-    gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f);
-    gtk_box_pack_start (GTK_BOX (section->bookmarks_box), button,
-                        FALSE, FALSE, 0);
+    bookmark_name = g_path_get_basename (bookmark);
+    applet_path = g_strconcat (GCONF_APPLETS, "/BookmarkShortcut:",
+                               bookmark_name, NULL);
+    view_path = g_strconcat (applet_path, "/view", NULL);
+    if (applet_path &&
+        gconf_client_dir_exists (section->gconf, applet_path, NULL) &&
+        gconf_client_get_int (section->gconf, view_path, NULL) != 0)
+    {
+        button = hildon_button_new_with_text
+            (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL,
+             title, value);
+        gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f);
+        gtk_box_pack_start (GTK_BOX (section->bookmarks_box), button,
+                            FALSE, FALSE, 0);
 
-    g_signal_connect (button, "clicked", G_CALLBACK (_bookmark_clicked),
-                                          section);
+        g_signal_connect (button, "clicked", G_CALLBACK (_bookmark_clicked),
+                                              section);
 
-    if (section->bookmarks_table == NULL)
+        if (section->bookmarks_table == NULL)
+        {
+            section->bookmarks_table = g_hash_table_new_full
+                (g_direct_hash, g_direct_equal, NULL,
+                 (GDestroyNotify) _bookmark_t_destroy);
+        }
+        g_hash_table_insert (section->bookmarks_table, button, b);
+    }
+    else
     {
-        section->bookmarks_table = g_hash_table_new_full
-            (g_direct_hash, g_direct_equal, NULL,
-             (GDestroyNotify) _bookmark_t_destroy);
+        _bookmark_t_destroy (b);
     }
-    g_hash_table_insert (section->bookmarks_table, button, b);
 
     g_free (title);
     g_free (value);
+    g_free (bookmark_name);
+    g_free (applet_path);
+    g_free (view_path);
 }
 
 static void
@@ -298,43 +320,45 @@ _edit_bookmarks_clicked (GtkButton *button, TweakrDesktopSection *section)
         GtkWidget *panarea;
         gint ret;
 
-        section->bookmarks_dialog = gtk_dialog_new_with_buttons
-            (_("Edit bookmark labels"),
-             GTK_WINDOW (gtk_widget_get_ancestor
-                         (tweakr_section_get_widget
-                          (TWEAKR_SECTION (section)),
-                          GTK_TYPE_WINDOW)),
-             GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
-             GTK_STOCK_OK, GTK_RESPONSE_OK,
-             NULL);
-
-        panarea = hildon_pannable_area_new ();
-        section->bookmarks_box = gtk_vbox_new (FALSE, 0);
-        hildon_pannable_area_add_with_viewport
-            (HILDON_PANNABLE_AREA (panarea), section->bookmarks_box);
-        g_object_set (G_OBJECT (panarea), "height-request",
-                      MIN (350, g_slist_length (bookmarks) * 70), NULL);
-
-        g_slist_foreach (bookmarks, (GFunc) _add_bookmark, section);
-
-        gtk_box_pack_start
-            (GTK_BOX (GTK_DIALOG (section->bookmarks_dialog)->vbox),
-             panarea, TRUE, TRUE, 0);
-
+        if (section->bookmarks_dialog == NULL)
+        {
+            section->bookmarks_dialog = gtk_dialog_new_with_buttons
+                (_("Edit desktop bookmarks"),
+                 GTK_WINDOW (gtk_widget_get_ancestor
+                             (tweakr_section_get_widget
+                              (TWEAKR_SECTION (section)),
+                              GTK_TYPE_WINDOW)),
+                 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
+                 GTK_STOCK_OK, GTK_RESPONSE_OK,
+                 NULL);
+
+            panarea = hildon_pannable_area_new ();
+            section->bookmarks_box = gtk_vbox_new (FALSE, 0);
+            hildon_pannable_area_add_with_viewport
+                (HILDON_PANNABLE_AREA (panarea), section->bookmarks_box);
+            g_object_set (G_OBJECT (panarea), "height-request",
+                          MIN (350, g_slist_length (bookmarks) * 70), NULL);
+
+            g_slist_foreach (bookmarks, (GFunc) _add_bookmark, section);
+
+            gtk_box_pack_start
+                (GTK_BOX (GTK_DIALOG (section->bookmarks_dialog)->vbox),
+                 panarea, TRUE, TRUE, 0);
+        }
         gtk_widget_show_all (GTK_DIALOG (section->bookmarks_dialog)->vbox);
         ret = gtk_dialog_run (GTK_DIALOG (section->bookmarks_dialog));
         if (ret == GTK_RESPONSE_OK)
         {
             section->save_bookmarks = TRUE;
         }
-        gtk_widget_destroy (section->bookmarks_dialog);
+        gtk_widget_hide (section->bookmarks_dialog);
 
         g_slist_foreach (bookmarks, (GFunc) g_free, NULL);
         g_slist_free (bookmarks);
     }
 }
 
-GtkWidget *
+static GtkWidget *
 _build_bookmarks_button (TweakrDesktopSection *section)
 {
     GtkWidget *button;
@@ -346,7 +370,7 @@ _build_bookmarks_button (TweakrDesktopSection *section)
 
     button = hildon_button_new_with_text (HILDON_SIZE_AUTO,
                                           HILDON_BUTTON_ARRANGEMENT_VERTICAL,
-                                          _("Edit bookmarks labels"), "");
+                                          _("Edit desktop bookmarks"), "");
     gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f);
     hildon_gtk_widget_set_theme_size (button, HILDON_SIZE_FINGER_HEIGHT);
 
@@ -363,8 +387,6 @@ tweakr_desktop_section_init (TweakrDesktopSection *section)
 
     gint snap_value = SNAP_NONE_VALUE;
 
-    section->snap_button = _build_snap_to_grid ();
-
     section->ini = g_key_file_new ();
 
     if (!g_key_file_load_from_file (section->ini, TRANSITIONS,
@@ -374,38 +396,47 @@ tweakr_desktop_section_init (TweakrDesktopSection *section)
         return;
     }
 
-    snap_value = g_key_file_get_integer (section->ini, "edit_mode",
-                                         "snap_grid_size", NULL);
-
-    if (snap_value < SNAP_SMALL_VALUE)
+    if (g_key_file_has_key (section->ini, "edit_mode", "snap_grid_size",
+                            NULL))
     {
-        hildon_picker_button_set_active
-            (HILDON_PICKER_BUTTON (section->snap_button), SNAP_NONE);
-    }
-    else if (snap_value < SNAP_LARGE_VALUE)
-    {
-        hildon_picker_button_set_active
-            (HILDON_PICKER_BUTTON (section->snap_button), SNAP_SMALL);
-    }
-    else if (snap_value < SNAP_HUGE_VALUE)
-    {
-        hildon_picker_button_set_active
-            (HILDON_PICKER_BUTTON (section->snap_button), SNAP_LARGE);
-    }
-    else
-    {
-        hildon_picker_button_set_active
-            (HILDON_PICKER_BUTTON (section->snap_button), SNAP_HUGE);
-    }
+        section->snap_button = _build_snap_to_grid ();
+
+        snap_value = g_key_file_get_integer (section->ini, "edit_mode",
+                                             "snap_grid_size", NULL);
 
+        if (snap_value < SNAP_SMALL_VALUE)
+        {
+            hildon_picker_button_set_active
+                (HILDON_PICKER_BUTTON (section->snap_button), SNAP_NONE);
+        }
+        else if (snap_value < SNAP_LARGE_VALUE)
+        {
+            hildon_picker_button_set_active
+                (HILDON_PICKER_BUTTON (section->snap_button), SNAP_SMALL);
+        }
+        else if (snap_value < SNAP_HUGE_VALUE)
+        {
+            hildon_picker_button_set_active
+                (HILDON_PICKER_BUTTON (section->snap_button), SNAP_LARGE);
+        }
+        else
+        {
+            hildon_picker_button_set_active
+                (HILDON_PICKER_BUTTON (section->snap_button), SNAP_HUGE);
+        }
+    }
     section->gconf = gconf_client_get_default ();
     section->bookmarks_button = _build_bookmarks_button (section);
 
     iface = TWEAKR_SECTION (section);
     iface->name = _("Desktop");
     iface->widget = gtk_vbox_new (FALSE, 0);
-    gtk_box_pack_start (GTK_BOX (iface->widget), section->snap_button,
-                        FALSE, FALSE, 0);
+
+    if (section->snap_button)
+    {
+        gtk_box_pack_start (GTK_BOX (iface->widget), section->snap_button,
+                            FALSE, FALSE, 0);
+    }
     if (section->bookmarks_button)
     {
         gtk_box_pack_start (GTK_BOX (iface->widget),