/* Work around crashes in the file open dialog in some Gtk+ versions if no * .recently-used.xbel is present. */ static void ensure_gtk_recently_used(void) { static gboolean ensured = FALSE; gchar *filename = NULL; if (ensured) return; /* Gtk+ 2.12 implies GBookmarkFile is also available. */ #if (GTK_CHECK_VERSION(2,12,0)) filename = g_build_filename(g_get_user_data_dir(), ".recently-used.xbel", NULL); if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { GBookmarkFile *bookmarkfile = g_bookmark_file_new(); GError *error = NULL; if (!g_bookmark_file_to_file(bookmarkfile, filename, &error)) { g_warning("Failed to create %s: %s", filename, error->message); g_clear_error(&error); } g_bookmark_file_free(bookmarkfile); } #endif g_free(filename); ensured = TRUE; }
/** * ide_recent_projects_remove: * @self: An #IdeRecentProjects * @project_infos: (transfer none) (element-type IdeProjectInfo): A #GList of #IdeProjectInfo. * * Removes the provided projects from the recent projects file. */ void ide_recent_projects_remove (IdeRecentProjects *self, GList *project_infos) { g_autoptr(GBookmarkFile) projects_file = NULL; g_autoptr(GError) error = NULL; GList *liter; g_return_if_fail (IDE_IS_RECENT_PROJECTS (self)); projects_file = ide_recent_projects_get_bookmarks (self, &error); if (projects_file == NULL) { g_warning ("Failed to load bookmarks file: %s", error->message); return; } for (liter = project_infos; liter; liter = liter->next) { IdeProjectInfo *project_info = liter->data; g_autofree gchar *file_uri = NULL; GSequenceIter *iter; GFile *file; g_assert (IDE_IS_PROJECT_INFO (liter->data)); iter = g_sequence_lookup (self->projects, project_info, (GCompareDataFunc)ide_project_info_compare, NULL); if (iter == NULL) { g_warning ("Project \"%s\" was not found, cannot remove.", ide_project_info_get_name (project_info)); g_clear_error (&error); continue; } file = ide_project_info_get_file (project_info); file_uri = g_file_get_uri (file); if (!g_bookmark_file_remove_item (projects_file, file_uri, &error)) { g_warning ("Failed to remove recent project: %s", error->message); g_clear_error (&error); continue; } g_sequence_remove (iter); } if (!g_bookmark_file_to_file (projects_file, self->file_uri, &error)) { g_warning ("Failed to save recent projects file: %s", error->message); return; } }
static gboolean go_to_server_cb (NautilusWindow *window, GFile *location, GError *error, gpointer user_data) { gboolean retval; if (error == NULL) { GBookmarkFile *bookmarks; GError *error = NULL; char *datadir; char *filename; char *uri; char *title; NautilusFile *file; gboolean safe_to_save = TRUE; file = nautilus_file_get_existing (location); bookmarks = g_bookmark_file_new (); datadir = g_build_filename (g_get_user_config_dir (), "nautilus", NULL); filename = g_build_filename (datadir, "servers", NULL); g_mkdir_with_parents (datadir, 0700); g_free (datadir); g_bookmark_file_load_from_file (bookmarks, filename, &error); if (error != NULL) { if (! g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { /* only warn if the file exists */ g_warning ("Unable to open server bookmarks: %s", error->message); safe_to_save = FALSE; } g_error_free (error); } if (safe_to_save) { uri = nautilus_file_get_uri (file); title = nautilus_file_get_display_name (file); g_bookmark_file_set_title (bookmarks, uri, title); g_bookmark_file_set_visited (bookmarks, uri, -1); g_bookmark_file_add_application (bookmarks, uri, NULL, NULL); g_free (uri); g_free (title); g_bookmark_file_to_file (bookmarks, filename, NULL); } g_free (filename); g_bookmark_file_free (bookmarks); retval = TRUE; } else { retval = FALSE; } return retval; }
static VALUE bf_to_file(VALUE self, VALUE filename) { GError* error = NULL; gboolean ret = g_bookmark_file_to_file(_SELF(self), RVAL2CSTRFILENAME(filename), &error); if (!ret) RAISE_GERROR(error); return self; }
/** * ide_recent_projects_remove: * @self: An #IdeRecentProjects * @project_infos: (transfer none) (element-type IdeProjectInfo): A #GList of #IdeProjectInfo. * * Removes the provided projects from the recent projects file. */ void ide_recent_projects_remove (IdeRecentProjects *self, GList *project_infos) { g_autoptr(GBookmarkFile) projects_file = NULL; g_autoptr(GError) error = NULL; GList *liter; g_return_if_fail (IDE_IS_RECENT_PROJECTS (self)); projects_file = ide_recent_projects_get_bookmarks (self, &error); if (projects_file == NULL) { g_warning ("Failed to load bookmarks file: %s", error->message); return; } for (liter = project_infos; liter; liter = liter->next) { IdeProjectInfo *project_info = liter->data; g_autofree gchar *file_uri = NULL; GSequenceIter *iter; GFile *file; g_assert (IDE_IS_PROJECT_INFO (liter->data)); iter = g_sequence_lookup (self->projects, project_info, (GCompareDataFunc)ide_project_info_compare, NULL); if (iter == NULL) { g_warning ("Project \"%s\" was not found, cannot remove.", ide_project_info_get_name (project_info)); g_clear_error (&error); continue; } file = ide_project_info_get_file (project_info); file_uri = g_file_get_uri (file); if (!g_bookmark_file_remove_item (projects_file, file_uri, &error)) { g_autofree gchar *with_slash = g_strdup_printf ("%s/", file_uri); /* Sometimes we don't get a match because the directory is missing a * trailing slash. Annoying, I know. See the following for the * upstream bug filed in GLib. * * https://bugzilla.gnome.org/show_bug.cgi?id=765449 */ if (!g_bookmark_file_remove_item (projects_file, with_slash, NULL)) { g_warning ("Failed to remove recent project: %s", error->message); g_clear_error (&error); continue; } g_clear_error (&error); } g_sequence_remove (iter); } if (!g_bookmark_file_to_file (projects_file, self->file_uri, &error)) { g_warning ("Failed to save recent projects file: %s", error->message); return; } }
static void ide_recent_projects_load_recent (IdeRecentProjects *self) { g_autoptr(GBookmarkFile) projects_file = NULL; g_autoptr(GError) error = NULL; gboolean needs_sync = FALSE; gchar **uris; gssize z; g_assert (IDE_IS_RECENT_PROJECTS (self)); projects_file = ide_recent_projects_get_bookmarks (self, &error); if (projects_file == NULL) { g_warning ("Unable to open recent projects file: %s", error->message); return; } uris = g_bookmark_file_get_uris (projects_file, NULL); for (z = 0; uris[z]; z++) { g_autoptr(GDateTime) last_modified_at = NULL; g_autoptr(GFile) project_file = NULL; g_autoptr(GFile) directory = NULL; g_autoptr(GPtrArray) languages = NULL; g_autoptr(IdeProjectInfo) project_info = NULL; const gchar *description; const gchar *uri = uris[z]; const gchar *name; time_t modified; gchar **groups; gsize len; gsize i; groups = g_bookmark_file_get_groups (projects_file, uri, &len, NULL); for (i = 0; i < len; i++) { if (g_str_equal (groups [i], IDE_RECENT_PROJECTS_GROUP)) goto is_project; } continue; is_project: project_file = g_file_new_for_uri (uri); if (g_file_is_native (project_file) && !g_file_query_exists (project_file, NULL)) { g_bookmark_file_remove_item (projects_file, uri, NULL); needs_sync = TRUE; continue; } name = g_bookmark_file_get_title (projects_file, uri, NULL); description = g_bookmark_file_get_description (projects_file, uri, NULL); modified = g_bookmark_file_get_modified (projects_file, uri, NULL); last_modified_at = g_date_time_new_from_unix_local (modified); directory = g_file_get_parent (project_file); languages = g_ptr_array_new (); for (i = 0; i < len; i++) { if (g_str_has_prefix (groups [i], IDE_RECENT_PROJECTS_LANGUAGE_GROUP_PREFIX)) g_ptr_array_add (languages, groups [i] + strlen (IDE_RECENT_PROJECTS_LANGUAGE_GROUP_PREFIX)); } g_ptr_array_add (languages, NULL); project_info = g_object_new (IDE_TYPE_PROJECT_INFO, "description", description, "directory", directory, "file", project_file, "is-recent", TRUE, "languages", (gchar **)languages->pdata, "last-modified-at", last_modified_at, "name", name, NULL); ide_recent_projects_added (self, project_info); g_hash_table_insert (self->recent_uris, g_strdup (uri), NULL); } g_strfreev (uris); if (needs_sync) g_bookmark_file_to_file (projects_file, self->file_uri, NULL); }
static void ide_recent_projects_load_recent (IdeRecentProjects *self) { g_autoptr(GBookmarkFile) projects_file = NULL; g_autoptr(GError) error = NULL; gboolean needs_sync = FALSE; gchar **uris; g_assert (IDE_IS_RECENT_PROJECTS (self)); if (!(projects_file = ide_recent_projects_get_bookmarks (self, &error))) { g_warning ("Unable to open recent projects file: %s", error->message); return; } uris = g_bookmark_file_get_uris (projects_file, NULL); for (gsize z = 0; uris[z]; z++) { g_autoptr(GDateTime) last_modified_at = NULL; g_autoptr(GFile) project_file = NULL; g_autoptr(GFile) directory = NULL; g_autoptr(GPtrArray) languages = NULL; g_autoptr(IdeProjectInfo) project_info = NULL; g_autofree gchar *name = NULL; g_autofree gchar *description = NULL; const gchar *build_system_hint = NULL; const gchar *build_system_name = NULL; const gchar *uri = uris[z]; const gchar *diruri = NULL; time_t modified; g_auto(GStrv) groups = NULL; gsize len; groups = g_bookmark_file_get_groups (projects_file, uri, &len, NULL); for (gsize i = 0; i < len; i++) { if (g_str_equal (groups [i], IDE_RECENT_PROJECTS_GROUP)) goto is_project; } continue; is_project: project_file = g_file_new_for_uri (uri); if (g_file_is_native (project_file) && !g_file_query_exists (project_file, NULL)) { g_bookmark_file_remove_item (projects_file, uri, NULL); needs_sync = TRUE; continue; } name = g_bookmark_file_get_title (projects_file, uri, NULL); description = g_bookmark_file_get_description (projects_file, uri, NULL); modified = g_bookmark_file_get_modified (projects_file, uri, NULL); last_modified_at = g_date_time_new_from_unix_local (modified); for (gsize i = 0; i < len; i++) { if (g_str_has_prefix (groups [i], IDE_RECENT_PROJECTS_DIRECTORY)) diruri = groups [i] + strlen (IDE_RECENT_PROJECTS_DIRECTORY); } if (diruri == NULL) { /* If the old project was a plain-ol'-directory, then we don't want * it's parent (which might be ~/Projects), instead reuse the project * file as the directory too. */ if (g_file_query_file_type (project_file, 0, NULL) == G_FILE_TYPE_DIRECTORY) directory = g_file_dup (project_file); else directory = g_file_get_parent (project_file); } else directory = g_file_new_for_uri (diruri); languages = g_ptr_array_new_with_free_func (g_free); for (gsize i = 0; i < len; i++) { if (g_str_has_prefix (groups [i], IDE_RECENT_PROJECTS_LANGUAGE_GROUP_PREFIX)) g_ptr_array_add (languages, g_strdup (groups [i] + strlen (IDE_RECENT_PROJECTS_LANGUAGE_GROUP_PREFIX))); else if (g_str_has_prefix (groups [i], IDE_RECENT_PROJECTS_BUILD_SYSTEM_GROUP_PREFIX)) build_system_name = groups [i] + strlen (IDE_RECENT_PROJECTS_BUILD_SYSTEM_GROUP_PREFIX); else if (g_str_has_prefix (groups [i], IDE_RECENT_PROJECTS_BUILD_SYSTEM_HINT_GROUP_PREFIX)) build_system_hint = groups [i] + strlen (IDE_RECENT_PROJECTS_BUILD_SYSTEM_HINT_GROUP_PREFIX); } /* Cleanup any extra space */ for (guint i = 0; i < languages->len; i++) g_strstrip ((gchar *)g_ptr_array_index (languages, i)); g_ptr_array_add (languages, NULL); project_info = g_object_new (IDE_TYPE_PROJECT_INFO, "build-system-hint", build_system_hint, "build-system-name", build_system_name, "description", description, "directory", directory, "file", project_file, "is-recent", TRUE, "languages", (gchar **)languages->pdata, "last-modified-at", last_modified_at, "name", name, NULL); ide_recent_projects_added (self, project_info); g_hash_table_insert (self->recent_uris, g_strdup (uri), NULL); } g_strfreev (uris); if (needs_sync) g_bookmark_file_to_file (projects_file, self->file_uri, NULL); }