filebrowser: Support new location of gtk bookmarks file
Also remove an old bit of code that was left over when some of the ifdef's for
windows and mac specific code was removed.
54d69eb93c
This commit is contained in:
parent
1e2e106d70
commit
44f60af7a7
|
@ -234,23 +234,23 @@ init_special_directories (XedFileBookmarksStore * model)
|
||||||
g_object_unref (file);
|
g_object_unref (file);
|
||||||
}
|
}
|
||||||
|
|
||||||
path = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
|
// path = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
|
||||||
if (path != NULL)
|
// if (path != NULL)
|
||||||
{
|
// {
|
||||||
file = g_file_new_for_path (path);
|
// file = g_file_new_for_path (path);
|
||||||
add_file (model, file, NULL, XED_FILE_BOOKMARKS_STORE_IS_DESKTOP |
|
// add_file (model, file, NULL, XED_FILE_BOOKMARKS_STORE_IS_DESKTOP |
|
||||||
XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL);
|
// XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL);
|
||||||
g_object_unref (file);
|
// g_object_unref (file);
|
||||||
}
|
// }
|
||||||
|
|
||||||
path = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
|
// path = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
|
||||||
if (path != NULL)
|
// if (path != NULL)
|
||||||
{
|
// {
|
||||||
file = g_file_new_for_path (path);
|
// file = g_file_new_for_path (path);
|
||||||
add_file (model, file, NULL, XED_FILE_BOOKMARKS_STORE_IS_DOCUMENTS |
|
// add_file (model, file, NULL, XED_FILE_BOOKMARKS_STORE_IS_DOCUMENTS |
|
||||||
XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL);
|
// XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL);
|
||||||
g_object_unref (file);
|
// g_object_unref (file);
|
||||||
}
|
// }
|
||||||
|
|
||||||
file = g_file_new_for_uri ("file:///");
|
file = g_file_new_for_uri ("file:///");
|
||||||
add_file (model, file, _("File System"), XED_FILE_BOOKMARKS_STORE_IS_ROOT, NULL);
|
add_file (model, file, _("File System"), XED_FILE_BOOKMARKS_STORE_IS_ROOT, NULL);
|
||||||
|
@ -514,21 +514,37 @@ add_bookmark (XedFileBookmarksStore * model,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static gchar *
|
||||||
init_bookmarks (XedFileBookmarksStore * model)
|
get_bookmarks_file (void)
|
||||||
|
{
|
||||||
|
return g_build_filename (g_get_user_config_dir (), "gtk-3.0", "bookmarks", NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gchar *
|
||||||
|
get_legacy_bookmarks_file (void)
|
||||||
|
{
|
||||||
|
return g_build_filename (g_get_home_dir (), ".gtk-bookmarks", NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
parse_bookmarks_file (XedFileBookmarksStore *model,
|
||||||
|
const gchar *bookmarks,
|
||||||
|
gboolean *added)
|
||||||
|
|
||||||
{
|
{
|
||||||
gchar *bookmarks;
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gchar *contents;
|
gchar *contents;
|
||||||
gchar **lines;
|
gchar **lines;
|
||||||
gchar **line;
|
gchar **line;
|
||||||
gboolean added = FALSE;
|
|
||||||
|
|
||||||
/* Read the bookmarks file */
|
if (!g_file_get_contents (bookmarks, &contents, NULL, &error))
|
||||||
bookmarks = g_build_filename (g_get_home_dir (), ".gtk-bookmarks", NULL);
|
|
||||||
|
|
||||||
if (g_file_get_contents (bookmarks, &contents, NULL, &error))
|
|
||||||
{
|
{
|
||||||
|
/* The bookmarks file doesn't exist (which is perfectly fine) */
|
||||||
|
g_error_free (error);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
lines = g_strsplit (contents, "\n", 0);
|
lines = g_strsplit (contents, "\n", 0);
|
||||||
|
|
||||||
for (line = lines; *line; ++line)
|
for (line = lines; *line; ++line)
|
||||||
|
@ -536,6 +552,7 @@ init_bookmarks (XedFileBookmarksStore * model)
|
||||||
if (**line)
|
if (**line)
|
||||||
{
|
{
|
||||||
GFile *location;
|
GFile *location;
|
||||||
|
|
||||||
gchar *pos;
|
gchar *pos;
|
||||||
gchar *name;
|
gchar *name;
|
||||||
|
|
||||||
|
@ -557,7 +574,7 @@ init_bookmarks (XedFileBookmarksStore * model)
|
||||||
location = g_file_new_for_uri (*line);
|
location = g_file_new_for_uri (*line);
|
||||||
if (xed_utils_is_valid_location (location))
|
if (xed_utils_is_valid_location (location))
|
||||||
{
|
{
|
||||||
added |= add_bookmark (model, name, *line);
|
*added |= add_bookmark (model, name, *line);
|
||||||
}
|
}
|
||||||
g_object_unref (location);
|
g_object_unref (location);
|
||||||
}
|
}
|
||||||
|
@ -576,13 +593,27 @@ init_bookmarks (XedFileBookmarksStore * model)
|
||||||
g_object_unref (file);
|
g_object_unref (file);
|
||||||
|
|
||||||
g_signal_connect (model->priv->bookmarks_monitor, "changed",
|
g_signal_connect (model->priv->bookmarks_monitor, "changed",
|
||||||
(GCallback)on_bookmarks_file_changed, model);
|
G_CALLBACK (on_bookmarks_file_changed), model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
static void
|
||||||
|
init_bookmarks (XedFileBookmarksStore *model)
|
||||||
{
|
{
|
||||||
/* The bookmarks file doesn't exist (which is perfectly fine) */
|
gchar *bookmarks;
|
||||||
g_error_free (error);
|
gboolean added = FALSE;
|
||||||
|
|
||||||
|
bookmarks = get_bookmarks_file ();
|
||||||
|
|
||||||
|
if (!parse_bookmarks_file (model, bookmarks, &added))
|
||||||
|
{
|
||||||
|
g_free (bookmarks);
|
||||||
|
|
||||||
|
/* try the old location (gtk <= 3.4) */
|
||||||
|
bookmarks = get_legacy_bookmarks_file ();
|
||||||
|
parse_bookmarks_file (model, bookmarks, &added);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (added)
|
if (added)
|
||||||
|
|
Loading…
Reference in New Issue