static VALUE bf_get_groups(VALUE self, VALUE uri) { gsize length; VALUE ary; gint i; GError* error = NULL; gchar** ret = g_bookmark_file_get_groups(_SELF(self), (const gchar *)RVAL2CSTR(uri), &length, &error); if (error) RAISE_GERROR(error); ary = rb_ary_new(); for(i = 0; i < length; i++){ rb_ary_push(ary, CSTR2RVAL(ret[i])); } g_strfreev(ret); return ary; }
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); }