[gnome-builder] recent-projects: Ditch GtkRecentManager in favor of GBookmarkFile
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] recent-projects: Ditch GtkRecentManager in favor of GBookmarkFile
- Date: Wed, 13 May 2015 00:54:34 +0000 (UTC)
commit c1d45d6fe4c9193507126eec41d6466e26eaf216
Author: Dimitris Zenios <dimitris zenios gmail com>
Date: Wed May 13 03:23:39 2015 +0300
recent-projects: Ditch GtkRecentManager in favor of GBookmarkFile
https://bugzilla.gnome.org/show_bug.cgi?id=749211
libide/ide-context.c | 52 +++++++++++++++++++++++++---------
libide/ide-recent-projects.c | 62 +++++++++++++++++++++++++-----------------
libide/ide-recent-projects.h | 4 +++
3 files changed, 79 insertions(+), 39 deletions(-)
---
diff --git a/libide/ide-context.c b/libide/ide-context.c
index 8e0210b..bc71b3a 100644
--- a/libide/ide-context.c
+++ b/libide/ide-context.c
@@ -43,6 +43,7 @@
#include "ide-unsaved-file.h"
#include "ide-unsaved-files.h"
#include "ide-vcs.h"
+#include "ide-recent-projects.h"
#include "doap/ide-doap.h"
@@ -64,6 +65,7 @@ struct _IdeContext
IdeProject *project;
GFile *project_file;
gchar *root_build_dir;
+ gchar *recent_projects_uri;
GHashTable *services;
IdeUnsavedFiles *unsaved_files;
IdeVcs *vcs;
@@ -536,6 +538,7 @@ ide_context_finalize (GObject *object)
g_clear_pointer (&self->services, g_hash_table_unref);
g_clear_pointer (&self->root_build_dir, g_free);
+ g_clear_pointer (&self->recent_projects_uri, g_free);
g_clear_object (&self->build_system);
g_clear_object (&self->device_manager);
@@ -752,6 +755,11 @@ ide_context_init (IdeContext *self)
"builds",
NULL);
+ self->recent_projects_uri = g_build_filename (g_get_user_data_dir (),
+ ide_get_program_name (),
+ IDE_RECENT_PROJECTS_BOOKMARK_FILENAME,
+ NULL);
+
self->back_forward_list = g_object_new (IDE_TYPE_BACK_FORWARD_LIST,
"context", self,
NULL);
@@ -1308,9 +1316,10 @@ ide_context_init_add_recent (gpointer source_object,
gpointer user_data)
{
IdeContext *self = source_object;
- GtkRecentData recent_data = { 0 };
+ g_autoptr(GBookmarkFile) projects_file = NULL;
g_autoptr(GPtrArray) groups = NULL;
g_autoptr(GTask) task = NULL;
+ g_autoptr(GError) error = NULL;
g_autofree gchar *uri = NULL;
g_autofree gchar *app_exec = NULL;
@@ -1321,23 +1330,38 @@ ide_context_init_add_recent (gpointer source_object,
task = g_task_new (self, cancellable, callback, user_data);
+ projects_file = g_bookmark_file_new ();
+ g_bookmark_file_load_from_file (projects_file, self->recent_projects_uri, &error);
+ /*
+ * If there was an error loading the file and the error is not "File does not exist"
+ * then stop saving operation
+ */
+ if (error != NULL && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
+ {
+ g_warning ("Unable to open recent projects %s file: %s", self->recent_projects_uri, error->message);
+
+ g_task_return_boolean (task, TRUE);
+
+ IDE_EXIT;
+ }
+
+
+
uri = g_file_get_uri (self->project_file);
app_exec = g_strdup_printf ("%s -p %%p", ide_get_program_name ());
- recent_data.display_name = (gchar *)ide_project_get_name (self->project);
- recent_data.description = NULL;
- recent_data.mime_type = "application/x-builder-project";
- recent_data.app_name = (gchar *)ide_get_program_name ();
- recent_data.app_exec = app_exec;
- recent_data.is_private = FALSE;
+ g_bookmark_file_set_title (projects_file, uri, (gchar *)ide_project_get_name (self->project));
+ g_bookmark_file_set_mime_type (projects_file, uri, "application/x-builder-project");
+ g_bookmark_file_add_application (projects_file, uri, (gchar *)ide_get_program_name (), app_exec);
+ g_bookmark_file_set_is_private (projects_file, uri, FALSE);
/* attach project description to recent info */
if (self->doap != NULL)
- recent_data.description = (gchar *)ide_doap_get_shortdesc (self->doap);
+ g_bookmark_file_set_description (projects_file, uri, (gchar *)ide_doap_get_shortdesc (self->doap));
/* attach discovered languages to recent info */
groups = g_ptr_array_new_with_free_func (g_free);
- g_ptr_array_add (groups, g_strdup ("X-GNOME-Builder-Project"));
+ g_ptr_array_add (groups, g_strdup (IDE_RECENT_PROJECTS_GROUP));
if (self->doap != NULL)
{
gchar **languages;
@@ -1347,16 +1371,16 @@ ide_context_init_add_recent (gpointer source_object,
{
for (i = 0; languages [i]; i++)
g_ptr_array_add (groups,
- g_strdup_printf ("X-GNOME-Builder-Language:%s", languages [i]));
+ g_strdup_printf ("%s%s", IDE_RECENT_PROJECTS_LANGUAGE_GROUP_PREFIX, languages
[i]));
}
}
- g_ptr_array_add (groups, NULL);
- recent_data.groups = (gchar **)groups->pdata;
+
+ g_bookmark_file_set_groups (projects_file, uri, (const gchar **)groups->pdata, groups->len);
IDE_TRACE_MSG ("Registering %s as recent project.", uri);
- if (!gtk_recent_manager_add_full (self->recent_manager, uri, &recent_data))
- g_warning ("Failed to add %s to GtkRecentManager", uri);
+ if (!g_bookmark_file_to_file (projects_file, self->recent_projects_uri, &error) && error != NULL)
+ g_warning ("Unable to save recent projects %s file: %s", self->recent_projects_uri, error->message);
g_task_return_boolean (task, TRUE);
diff --git a/libide/ide-recent-projects.c b/libide/ide-recent-projects.c
index ecac3fc..dc70ebf 100644
--- a/libide/ide-recent-projects.c
+++ b/libide/ide-recent-projects.c
@@ -19,12 +19,10 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
+#include "ide-global.h"
#include "ide-project-miner.h"
#include "ide-recent-projects.h"
-#define PROJECT_GROUP "X-GNOME-Builder-Project"
-#define LANGUAGE_GROUP_PREFIX "X-GNOME-Builder-Language:"
-
struct _IdeRecentProjects
{
GObject parent_instance;
@@ -127,57 +125,74 @@ ide_recent_projects_add_miner (IdeRecentProjects *self,
}
static void
-ide_recent_projects_load_recent (IdeRecentProjects *self,
- GtkRecentManager *recent_manager)
+ide_recent_projects_load_recent (IdeRecentProjects *self)
{
- GList *iter;
- GList *list;
+ g_autoptr(GBookmarkFile) projects_file;
+ g_autoptr(GError) error = NULL;
+ g_autofree gchar *file_uri = NULL;
+ gchar **uris;
+ gssize z;
+
g_assert (IDE_IS_RECENT_PROJECTS (self));
- g_assert (GTK_IS_RECENT_MANAGER (recent_manager));
- list = gtk_recent_manager_get_items (recent_manager);
+ file_uri = g_build_filename (g_get_user_data_dir (),
+ ide_get_program_name (),
+ IDE_RECENT_PROJECTS_BOOKMARK_FILENAME,
+ NULL);
+
+ projects_file = g_bookmark_file_new ();
+ g_bookmark_file_load_from_file (projects_file, file_uri, &error);
+ /*
+ * If there was an error loading the file and the error is not "File does not exist"
+ * then stop saving operation
+ */
+ if (error != NULL && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
+ {
+ g_warning ("Unable to open recent projects %s file: %s", file_uri, error->message);
+ return;
+ }
+
+ uris = g_bookmark_file_get_uris (projects_file, NULL);
- for (iter = list; iter; iter = iter->next)
+ 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;
- GtkRecentInfo *recent_info = iter->data;
const gchar *description;
- const gchar *uri;
+ const gchar *uri = uris[z];
const gchar *name;
time_t modified;
gchar **groups;
gsize len;
gsize i;
- groups = gtk_recent_info_get_groups (recent_info, &len);
+ groups = g_bookmark_file_get_groups (projects_file, uri, &len, NULL);
for (i = 0; i < len; i++)
{
- if (g_str_equal (groups [i], PROJECT_GROUP))
+ if (g_str_equal (groups [i], IDE_RECENT_PROJECTS_GROUP))
goto is_project;
}
continue;
is_project:
- name = gtk_recent_info_get_display_name (recent_info);
- description = gtk_recent_info_get_description (recent_info);
- modified = gtk_recent_info_get_modified (recent_info);
+ 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);
- uri = gtk_recent_info_get_uri (recent_info);
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], LANGUAGE_GROUP_PREFIX))
- g_ptr_array_add (languages, groups [i] + strlen (LANGUAGE_GROUP_PREFIX));
+ 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);
@@ -195,8 +210,7 @@ ide_recent_projects_load_recent (IdeRecentProjects *self,
g_hash_table_insert (self->recent_uris, g_strdup (uri), NULL);
}
-
- g_list_free_full (list, (GDestroyNotify)gtk_recent_info_unref);
+ g_strfreev (uris);
}
static GType
@@ -329,7 +343,6 @@ ide_recent_projects_discover_async (IdeRecentProjects *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GtkRecentManager *recent_manager;
g_autoptr(GTask) task = NULL;
gsize i;
@@ -350,8 +363,7 @@ ide_recent_projects_discover_async (IdeRecentProjects *self,
self->discovered = TRUE;
- recent_manager = gtk_recent_manager_get_default ();
- ide_recent_projects_load_recent (self, recent_manager);
+ ide_recent_projects_load_recent (self);
self->active = self->miners->len;
diff --git a/libide/ide-recent-projects.h b/libide/ide-recent-projects.h
index e5951e0..37ef432 100644
--- a/libide/ide-recent-projects.h
+++ b/libide/ide-recent-projects.h
@@ -25,6 +25,10 @@ G_BEGIN_DECLS
#define IDE_TYPE_RECENT_PROJECTS (ide_recent_projects_get_type())
+#define IDE_RECENT_PROJECTS_GROUP "X-GNOME-Builder-Project"
+#define IDE_RECENT_PROJECTS_LANGUAGE_GROUP_PREFIX "X-GNOME-Builder-Language:"
+#define IDE_RECENT_PROJECTS_BOOKMARK_FILENAME "recent-projects.xbel"
+
G_DECLARE_FINAL_TYPE (IdeRecentProjects, ide_recent_projects, IDE, RECENT_PROJECTS, GObject)
IdeRecentProjects *ide_recent_projects_new (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]