* Copyright (C) 2003, Red Hat, Inc.
* Copyright (C) 2007-2008 Carlos Garnacho
*
- * This program is free software; you can redistribute it and/or modify
+ * This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Carlos Garnacho <carlos@imendio.com>
*/
}
static GFile *
-get_bookmarks_file (void)
+get_legacy_bookmarks_file (void)
{
GFile *file;
gchar *filename;
return file;
}
+static GFile *
+get_bookmarks_file (void)
+{
+ GFile *file;
+ gchar *filename;
+
+ filename = g_build_filename (g_get_user_config_dir (), "gtk-3.0", "bookmarks", NULL);
+ file = g_file_new_for_path (filename);
+ g_free (filename);
+
+ return file;
+}
+
static GSList *
read_bookmarks (GFile *file)
{
GError *error = NULL;
GString *contents;
GSList *l;
+ GFile *parent_file;
+ gchar *path;
contents = g_string_new ("");
g_free (uri);
}
- if (!g_file_replace_contents (bookmarks_file,
- contents->str,
- strlen (contents->str),
- NULL, FALSE, 0, NULL,
- NULL, &error))
+ parent_file = g_file_get_parent (bookmarks_file);
+ path = g_file_get_path (parent_file);
+ if (g_mkdir_with_parents (path, 0700) == 0)
{
- g_critical ("%s", error->message);
- g_error_free (error);
+ if (!g_file_replace_contents (bookmarks_file,
+ contents->str,
+ strlen (contents->str),
+ NULL, FALSE, 0, NULL,
+ NULL, &error))
+ {
+ g_critical ("%s", error->message);
+ g_error_free (error);
+ }
}
-
+ g_free (path);
+ g_object_unref (parent_file);
g_string_free (contents, TRUE);
}
/* Bookmarks */
bookmarks_file = get_bookmarks_file ();
priv->bookmarks = read_bookmarks (bookmarks_file);
+ if (!priv->bookmarks)
+ {
+ GFile *legacy_bookmarks_file;
+
+ /* Read the legacy one and write it to the new one */
+ legacy_bookmarks_file = get_legacy_bookmarks_file ();
+ priv->bookmarks = read_bookmarks (legacy_bookmarks_file);
+ save_bookmarks (bookmarks_file, priv->bookmarks);
+
+ g_object_unref (legacy_bookmarks_file);
+ }
+
priv->bookmarks_monitor = g_file_monitor_file (bookmarks_file,
G_FILE_MONITOR_NONE,
NULL, &error);
return g_slist_reverse (files);
}
-static gboolean
-is_valid_scheme_character (char c)
-{
- return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
-}
-
-static gboolean
-has_uri_scheme (const char *str)
-{
- const char *p;
-
- p = str;
-
- if (!is_valid_scheme_character (*p))
- return FALSE;
-
- do
- p++;
- while (is_valid_scheme_character (*p));
-
- return (strncmp (p, "://", 3) == 0);
-}
-
-gboolean
-_gtk_file_system_parse (GtkFileSystem *file_system,
- GFile *base_file,
- const gchar *str,
- GFile **folder,
- gchar **file_part,
- GError **error)
-{
- GFile *file;
- gboolean result = FALSE;
- gboolean is_dir = FALSE;
- gchar *last_slash = NULL;
- gboolean is_uri;
-
- DEBUG ("parse");
-
- if (str && *str)
- is_dir = (str [strlen (str) - 1] == G_DIR_SEPARATOR);
-
- last_slash = strrchr (str, G_DIR_SEPARATOR);
-
- is_uri = has_uri_scheme (str);
-
- if (is_uri)
- {
- const char *colon;
- const char *slash_after_hostname;
-
- colon = strchr (str, ':');
- g_assert (colon != NULL);
- g_assert (strncmp (colon, "://", 3) == 0);
-
- slash_after_hostname = strchr (colon + 3, '/');
-
- if (slash_after_hostname == NULL)
- {
- /* We don't have a full hostname yet. So, don't switch the folder
- * until we have seen a full hostname. Otherwise, completion will
- * happen for every character the user types for the hostname.
- */
-
- *folder = NULL;
- *file_part = NULL;
- g_set_error (error,
- GTK_FILE_CHOOSER_ERROR,
- GTK_FILE_CHOOSER_ERROR_INCOMPLETE_HOSTNAME,
- "Incomplete hostname");
- return FALSE;
- }
- }
-
- if (str[0] == '~' || g_path_is_absolute (str) || is_uri)
- file = g_file_parse_name (str);
- else
- {
- if (base_file)
- file = g_file_resolve_relative_path (base_file, str);
- else
- {
- *folder = NULL;
- *file_part = NULL;
- g_set_error (error,
- GTK_FILE_CHOOSER_ERROR,
- GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
- _("Invalid path"));
- return FALSE;
- }
- }
-
- if (base_file && g_file_equal (base_file, file))
- {
- /* this is when user types '.', could be the
- * beginning of a hidden file, ./ or ../
- */
- *folder = g_object_ref (file);
- *file_part = g_strdup (str);
- result = TRUE;
- }
- else if (is_dir)
- {
- /* it's a dir, or at least it ends with the dir separator */
- *folder = g_object_ref (file);
- *file_part = g_strdup ("");
- result = TRUE;
- }
- else
- {
- GFile *parent_file;
-
- parent_file = g_file_get_parent (file);
-
- if (!parent_file)
- {
- g_set_error (error,
- GTK_FILE_CHOOSER_ERROR,
- GTK_FILE_CHOOSER_ERROR_NONEXISTENT,
- "Could not get parent file");
- *folder = NULL;
- *file_part = NULL;
- }
- else
- {
- *folder = parent_file;
- result = TRUE;
-
- if (last_slash)
- *file_part = g_strdup (last_slash + 1);
- else
- *file_part = g_strdup (str);
- }
- }
-
- g_object_unref (file);
-
- return result;
-}
-
static void
free_async_data (AsyncFuncData *async_data)
{
return NULL;
pixbuf = gtk_icon_info_load_icon (icon_info, error);
- gtk_icon_info_free (icon_info);
+ g_object_unref (icon_info);
return pixbuf;
}
type == G_FILE_TYPE_SHORTCUT);
}
+gboolean
+_gtk_file_has_native_path (GFile *file)
+{
+ char *local_file_path;
+ gboolean has_native_path;
+
+ /* Don't use g_file_is_native(), as we want to support FUSE paths if available */
+ local_file_path = g_file_get_path (file);
+ has_native_path = (local_file_path != NULL);
+ g_free (local_file_path);
+
+ return has_native_path;
+}