> Should I add a gconf key to adjust this for the power users that want
> to (this will not be easy, but hey, I can try, can't I)?

Okay, so after a bit of thinking, I guess this is not possible, since
gtk doesn't use gconf, and we certainly don't want it to depend on it.
So whatever the choice is, I got a patch ready that will make the
filechooser to open by default in ~/Documents if it exists, and in ~/
otherwise.
I am attaching it, so let me know if you see obvious (or non-obvious)
mistakes in it.

--
Alain Perry
--- gtk+-2.8.9.orig/gtk/gtkfilechooserdefault.c	2005-12-06 04:11:51.000000000 +0100
+++ gtk+-2.8.9/gtk/gtkfilechooserdefault.c	2005-12-27 07:44:04.000000000 +0100
@@ -222,6 +222,7 @@
 
   GtkTooltips *tooltips;
 
+  gboolean has_documents;
   gboolean has_home;
   gboolean has_desktop;
 
@@ -343,6 +344,7 @@
 
 /* Interesting places in the shortcuts bar */
 typedef enum {
+  SHORTCUTS_DOCUMENTS,
   SHORTCUTS_HOME,
   SHORTCUTS_DESKTOP,
   SHORTCUTS_VOLUMES,
@@ -1476,6 +1478,37 @@
   profile_end ("end", NULL);
 }
 
+/* Appends the ~/Documents directory to the shortcuts model */
+static void
+shortcuts_append_documents (GtkFileChooserDefault *impl)
+{
+  char *name;
+  const char *home;
+  GtkFilePath *path;
+
+  profile_start ("start", NULL);
+
+  home=g_get_home_dir ();
+  if (home == NULL)
+    {
+      profile_end ("end - no home directory!?", NULL);
+      return;
+    }
+  
+  name = g_build_filename (home, "Documents", NULL);
+  path = gtk_file_system_filename_to_path (impl->file_system, name);
+  g_free (name);
+
+  impl->has_documents = shortcuts_insert_path (impl, -1, FALSE, NULL, path, _("Documents"), FALSE, NULL);
+  /* We do not actually pop up an error dialog if there is no documents directory
+   * because some people may really not want to have one.
+   */
+
+  gtk_file_path_free (path);
+
+  profile_end ("end", NULL);
+}
+
 /* Appends a list of GtkFilePath to the shortcuts model; returns how many were inserted */
 static int
 shortcuts_append_paths (GtkFileChooserDefault *impl,
@@ -1527,6 +1560,11 @@
 
   n = 0;
 
+  if (where == SHORTCUTS_DOCUMENTS)
+    goto out;
+
+  n += impl->has_documents ? 1 : 0;
+  
   if (where == SHORTCUTS_HOME)
     goto out;
 
@@ -1875,6 +1913,7 @@
 
   if (impl->file_system)
     {
+      shortcuts_append_documents (impl);
       shortcuts_append_home (impl);
       shortcuts_append_desktop (impl);
       shortcuts_add_volumes (impl);
@@ -4773,7 +4812,8 @@
 gtk_file_chooser_default_map (GtkWidget *widget)
 {
   GtkFileChooserDefault *impl;
-  char *current_working_dir;
+  char *default_dir;
+  const char* home;
 
   profile_start ("start", NULL);
 
@@ -4784,10 +4824,18 @@
   switch (impl->reload_state)
     {
     case RELOAD_EMPTY:
-      /* The user didn't explicitly give us a folder to display, so we'll use the cwd */
-      current_working_dir = g_get_current_dir ();
-      gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), current_working_dir);
-      g_free (current_working_dir);
+      /* The user didn't explicitly give us a folder to display, so we'll use ~/Documents, or the cwd */
+      if (impl->has_documents)
+        {
+          home = g_get_home_dir ();
+          default_dir = g_build_filename (home, "Documents", NULL);
+        }
+      else
+        {
+          default_dir = g_get_current_dir ();
+        }
+      gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), default_dir);
+      g_free (default_dir);
       break;
 
     case RELOAD_HAS_FOLDER:
@@ -5443,16 +5491,25 @@
 
   if (impl->reload_state == RELOAD_EMPTY)
     {
-      char *current_working_dir;
+      char *default_dir;
+      const char *home;
       GtkFilePath *path;
 
-      /* We are unmapped, or we had an error while loading the last folder.  We'll return
-       * the $cwd since once we get (re)mapped, we'll load $cwd anyway unless the caller
-       * explicitly calls set_current_folder() on us.
+      /* We are unmapped, or we had an error while loading the last folder.  We'll do the
+       * same as in the map method, since that's what will happen when we get (re)mapped,
+       * unless the caller explicitly calls set_current_folder() on us.
        */
-      current_working_dir = g_get_current_dir ();
-      path = gtk_file_system_filename_to_path (impl->file_system, current_working_dir);
-      g_free (current_working_dir);
+      if (impl->has_documents)
+        {
+          home = g_get_home_dir ();
+          default_dir = g_build_filename (home, "Documents", NULL);
+        }
+      else
+        {
+          default_dir = g_get_current_dir ();
+        }
+      path = gtk_file_system_filename_to_path (impl->file_system, default_dir);
+      g_free (default_dir);
       return path;
     }
 
-- 
ubuntu-desktop mailing list
[email protected]
http://lists.ubuntu.com/mailman/listinfo/ubuntu-desktop

Reply via email to