Fix hildon-desktop crashing if snap-grid == 0, and bump values up a bit.
[tweakr] / modules / tweakr-desktop.c
index b012091..e07412a 100644 (file)
@@ -46,10 +46,10 @@ enum
 
 enum
 {
-    SNAP_NONE_VALUE,
-    SNAP_SMALL_VALUE = 8,
-    SNAP_LARGE_VALUE = 16,
-    SNAP_HUGE_VALUE = 32
+    SNAP_NONE_VALUE = 4,
+    SNAP_SMALL_VALUE = 16,
+    SNAP_LARGE_VALUE = 32,
+    SNAP_HUGE_VALUE = 48
 };
 
 static gint snap_values [] = {
@@ -259,6 +259,7 @@ _add_bookmark (gchar *bookmark, TweakrDesktopSection *section)
 
     gchar *bookmark_name;
     gchar *applet_path;
+    gchar *view_path;
 
     b = g_new0 (bookmark_t, 1);
     b->path = g_strconcat (bookmark, "/label", NULL);
@@ -272,8 +273,10 @@ _add_bookmark (gchar *bookmark, TweakrDesktopSection *section)
     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_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,
@@ -302,6 +305,7 @@ _add_bookmark (gchar *bookmark, TweakrDesktopSection *section)
     g_free (value);
     g_free (bookmark_name);
     g_free (applet_path);
+    g_free (view_path);
 }
 
 static void
@@ -319,7 +323,7 @@ _edit_bookmarks_clicked (GtkButton *button, TweakrDesktopSection *section)
         if (section->bookmarks_dialog == NULL)
         {
             section->bookmarks_dialog = gtk_dialog_new_with_buttons
-                (_("Edit bookmark labels"),
+                (_("Edit desktop bookmarks"),
                  GTK_WINDOW (gtk_widget_get_ancestor
                              (tweakr_section_get_widget
                               (TWEAKR_SECTION (section)),
@@ -354,7 +358,7 @@ _edit_bookmarks_clicked (GtkButton *button, TweakrDesktopSection *section)
     }
 }
 
-GtkWidget *
+static GtkWidget *
 _build_bookmarks_button (TweakrDesktopSection *section)
 {
     GtkWidget *button;
@@ -366,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);
 
@@ -383,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,
@@ -394,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)
-    {
-        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)
+    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_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),