/** * 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 VALUE bf_remove_item(VALUE self, VALUE uri) { GError *error = NULL; gboolean ret = g_bookmark_file_remove_item(_SELF(self), (const gchar *)RVAL2CSTR(uri), &error); if (! ret) RAISE_GERROR(error); return self; }
static gboolean test_modify (GBookmarkFile *bookmark) { gchar *text; guint count; time_t stamp; GError *error = NULL; g_print ("\t=> check global title/description..."); g_bookmark_file_set_title (bookmark, NULL, "a file"); g_bookmark_file_set_description (bookmark, NULL, "a bookmark file"); text = g_bookmark_file_get_title (bookmark, NULL, &error); test_assert_empty_error (&error); test_assert_str_equal (text, "a file"); g_free (text); text = g_bookmark_file_get_description (bookmark, NULL, &error); test_assert_empty_error (&error); test_assert_str_equal (text, "a bookmark file"); g_free (text); g_print ("ok\n"); g_print ("\t=> check bookmark title/description..."); g_bookmark_file_set_title (bookmark, TEST_URI_0, "a title"); g_bookmark_file_set_description (bookmark, TEST_URI_0, "a description"); text = g_bookmark_file_get_title (bookmark, TEST_URI_0, &error); test_assert_empty_error (&error); test_assert_str_equal (text, "a title"); g_free (text); g_print ("ok\n"); g_print ("\t=> check non existing bookmark..."); g_bookmark_file_get_description (bookmark, TEST_URI_1, &error); test_assert_not_empty_error (&error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND); g_print ("ok\n"); g_print ("\t=> check application..."); g_bookmark_file_set_mime_type (bookmark, TEST_URI_0, TEST_MIME); g_bookmark_file_add_application (bookmark, TEST_URI_0, TEST_APP_NAME, TEST_APP_EXEC); g_assert (g_bookmark_file_has_application (bookmark, TEST_URI_0, TEST_APP_NAME, NULL) == TRUE); g_bookmark_file_get_app_info (bookmark, TEST_URI_0, TEST_APP_NAME, &text, &count, &stamp, &error); test_assert_empty_error (&error); g_assert (count == 1); g_assert (stamp == g_bookmark_file_get_modified (bookmark, TEST_URI_0, NULL)); g_free (text); g_bookmark_file_get_app_info (bookmark, TEST_URI_0, "fail", &text, &count, &stamp, &error); test_assert_not_empty_error (&error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_APP_NOT_REGISTERED); g_print ("ok\n"); g_print ("\t=> check groups..."); g_bookmark_file_add_group (bookmark, TEST_URI_1, "Test"); g_assert (g_bookmark_file_has_group (bookmark, TEST_URI_1, "Test", NULL) == TRUE); g_assert (g_bookmark_file_has_group (bookmark, TEST_URI_1, "Fail", NULL) == FALSE); g_print ("ok\n"); g_print ("\t=> check remove..."); g_assert (g_bookmark_file_remove_item (bookmark, TEST_URI_1, &error) == TRUE); test_assert_empty_error (&error); g_assert (g_bookmark_file_remove_item (bookmark, TEST_URI_1, &error) == FALSE); test_assert_not_empty_error (&error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND); g_print ("ok\n"); return 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_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); }