static VALUE bf_get_title(VALUE self, VALUE uri) { GError *error = NULL; gchar* ret = g_bookmark_file_get_title(_SELF(self), (const gchar *)RVAL2CSTR(uri), &error); if (error) RAISE_GERROR(error); return CSTR2RVAL_FREE(ret); }
static void _gth_browser_update_bookmark_list (GthBrowser *browser) { BrowserData *data; GBookmarkFile *bookmarks; char **uris; int i; data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY); g_return_if_fail (data != NULL); g_menu_remove_all (data->bookmarks_menu); bookmarks = gth_main_get_default_bookmarks (); uris = g_bookmark_file_get_uris (bookmarks, NULL); for (i = 0; uris[i] != NULL; i++) { GFile *file; char *name; GMenuItem *item; file = g_file_new_for_uri (uris[i]); name = g_bookmark_file_get_title (bookmarks, uris[i], NULL); item = _g_menu_item_new_for_file (file, name); g_menu_item_set_action_and_target (item, "win.go-to-location", "s", uris[i]); g_menu_append_item (data->bookmarks_menu, item); g_object_unref (item); g_free (name); g_object_unref (file); } _gth_browser_update_system_bookmark_list (browser); g_strfreev (uris); }
static void ide_recent_projects_load_recent (IdeRecentProjects *self) { g_autoptr(GBookmarkFile) projects_file; g_autoptr(GError) error = NULL; 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: 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); project_file = g_file_new_for_uri (uri); 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); }
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; }
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); }