static gboolean test_query (GBookmarkFile *bookmark) { gint size; gchar **uris; gsize uris_len, i; gboolean res = TRUE; size = g_bookmark_file_get_size (bookmark); uris = g_bookmark_file_get_uris (bookmark, &uris_len); if (uris_len != size) { g_print ("URI/size mismatch: URI count is %d (should be %d)\n", uris_len, size); res = FALSE; } for (i = 0; i < uris_len; i++) if (!g_bookmark_file_has_item (bookmark, uris[i])) { g_print ("URI/bookmark mismatch: bookmark for '%s' does not exist\n", uris[i]); res = FALSE; } g_strfreev (uris); return res; }
gchar * ide_recent_projects_find_by_directory (IdeRecentProjects *self, const gchar *directory) { g_autoptr(GBookmarkFile) bookmarks = NULL; g_auto(GStrv) uris = NULL; gsize len = 0; g_return_val_if_fail (IDE_IS_RECENT_PROJECTS (self), NULL); g_return_val_if_fail (directory, NULL); if (!g_file_test (directory, G_FILE_TEST_IS_DIR)) return NULL; if (!(bookmarks = ide_recent_projects_get_bookmarks (self, NULL))) return NULL; uris = g_bookmark_file_get_uris (bookmarks, &len); for (gsize i = 0; i < len; i++) { /* TODO: Make a better compare that deals with trailing / */ if (g_str_has_prefix (uris[i], directory)) return g_strdup (uris[i]); } return NULL; }
static VALUE bf_get_uris(VALUE self) { int i; gsize len; VALUE ary = rb_ary_new(); gchar** ret = g_bookmark_file_get_uris(_SELF(self), &len); for (i = 0; i < len; i++){ rb_ary_push(ary, CSTR2RVAL(ret[i])); } g_strfreev(ret); return ary; }
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 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); }