[Xfce4-commits] <thunar:jannis/new-shortcuts-pane> Implementing loading the ~/.gtk-bookmarks file. No monitoring yet.
Jannis Pohlmann
noreply at xfce.org
Tue Jun 7 03:36:01 CEST 2011
Updating branch refs/heads/jannis/new-shortcuts-pane
to 1eaa6f6886d8c1a52a314aa21917c8e3f0cc4709 (commit)
from 5c9fd4e93a227b0efd31c3f086428e419d920613 (commit)
commit 1eaa6f6886d8c1a52a314aa21917c8e3f0cc4709
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Tue Jun 7 03:32:14 2011 +0200
Implementing loading the ~/.gtk-bookmarks file. No monitoring yet.
This implementation also loads remote URIs and doesn't check whether
any of the items are folders. I assume that this conflicts with
GtkFileChooser, so maybe we need to use our own bookmark storage for
remote locations.
thunar/thunar-shortcuts-model.c | 118 +++++++++++++++++++++++++++++++++++++++
1 files changed, 118 insertions(+), 0 deletions(-)
diff --git a/thunar/thunar-shortcuts-model.c b/thunar/thunar-shortcuts-model.c
index e31cf43..1d74b60 100644
--- a/thunar/thunar-shortcuts-model.c
+++ b/thunar/thunar-shortcuts-model.c
@@ -129,6 +129,8 @@ static gboolean thunar_shortcuts_model_find_category (Thu
static void thunar_shortcuts_model_add_shortcut (ThunarShortcutsModel *model,
ThunarShortcut *shortcut);
static gboolean thunar_shortcuts_model_load_system_shortcuts (gpointer user_data);
+static gboolean thunar_shortcuts_model_load_user_dirs (gpointer user_data);
+static gboolean thunar_shortcuts_model_load_bookmarks (gpointer user_data);
static gboolean thunar_shortcuts_model_load_volumes (gpointer user_data);
static ThunarShortcutCategory *thunar_shortcut_category_new (ThunarShortcutCategoryType type);
static void thunar_shortcut_category_free (ThunarShortcutCategory *category);
@@ -1049,6 +1051,122 @@ thunar_shortcuts_model_load_system_shortcuts (gpointer user_data)
/* add the shortcut */
thunar_shortcuts_model_add_shortcut (model, shortcut);
+ /* load rest of the user dirs next */
+ model->load_idle_id = g_idle_add (thunar_shortcuts_model_load_user_dirs, model);
+
+ return FALSE;
+}
+
+
+
+static gboolean
+thunar_shortcuts_model_load_user_dirs (gpointer user_data)
+{
+ ThunarShortcutsModel *model = THUNAR_SHORTCUTS_MODEL (user_data);
+
+ _thunar_return_val_if_fail (THUNAR_IS_SHORTCUTS_MODEL (model), FALSE);
+
+ /* load GTK+ bookmarks next */
+ model->load_idle_id = g_idle_add (thunar_shortcuts_model_load_bookmarks, model);
+
+ return FALSE;
+}
+
+
+
+static gboolean
+thunar_shortcuts_model_load_bookmarks (gpointer user_data)
+{
+ ThunarShortcutsModel *model = THUNAR_SHORTCUTS_MODEL (user_data);
+ ThunarShortcut *shortcut;
+ gboolean is_local;
+ GFile *bookmarks_file;
+ GFile *home_file;
+ gchar *bookmarks_path;
+ gchar line[2048];
+ gchar *name;
+ gchar *unescaped_uri;
+ FILE *fp;
+
+ _thunar_return_val_if_fail (THUNAR_IS_SHORTCUTS_MODEL (model), FALSE);
+
+ /* resolve the bookmarks file */
+ home_file = thunar_g_file_new_for_home ();
+ bookmarks_file = g_file_resolve_relative_path (home_file, ".gtk-bookmarks");
+ bookmarks_path = g_file_get_path (bookmarks_file);
+ g_object_unref (bookmarks_file);
+ g_object_unref (home_file);
+
+ /* TODO remove all existing bookmarks */
+
+ /* open the GTK+ bookmarks file for reading */
+ fp = fopen (bookmarks_path, "r");
+ if (fp != NULL)
+ {
+ while (fgets (line, sizeof (line), fp) != NULL)
+ {
+ /* strip leading and trailing whitespace */
+ g_strstrip (line);
+
+ /* skip over the URI */
+ for (name = line; *name != '\0' && !g_ascii_isspace (*name); ++name);
+
+ /* zero-terminate the URI */
+ *name++ = '\0';
+
+ /* check if we have a name */
+ for (; g_ascii_isspace (*name); ++name);
+
+ /* check if we have something that looks like a URI */
+ if (exo_str_looks_like_an_uri (line))
+ {
+
+ /* create a shortcut for the desktop folder */
+ shortcut = g_slice_new0 (ThunarShortcut);
+ shortcut->file = g_file_new_for_uri (line);
+
+ if (*name != '\0')
+ {
+ shortcut->name = g_strdup (name);
+ }
+ else
+ {
+ unescaped_uri = g_uri_unescape_string (line, NULL);
+ shortcut->name = g_filename_display_basename (unescaped_uri);
+ g_free (unescaped_uri);
+ }
+
+ is_local = g_file_has_uri_scheme (shortcut->file, "file");
+
+ if (is_local)
+ {
+ shortcut->icon = g_themed_icon_new ("folder");
+ shortcut->type = THUNAR_SHORTCUT_LOCAL_FILE;
+ }
+ else
+ {
+ shortcut->icon = g_themed_icon_new ("folder-remote");
+ shortcut->type = THUNAR_SHORTCUT_REMOTE_FILE;
+ }
+
+ shortcut->visible = TRUE;
+ shortcut->mutable = FALSE;
+ shortcut->persistent = TRUE;
+
+ /* add the shortcut */
+ thunar_shortcuts_model_add_shortcut (model, shortcut);
+ }
+ }
+
+ /* close the file handle */
+ fclose (fp);
+ }
+
+ /* free the bookmarks file path */
+ g_free (bookmarks_path);
+
+ /* TODO monitor the bookmarks file for changes */
+
/* load volumes next */
model->load_idle_id = g_idle_add (thunar_shortcuts_model_load_volumes, model);
More information about the Xfce4-commits
mailing list