diff options
author | Cosimo Cecchi <cosimoc@gnome.org> | 2019-07-15 23:53:59 +0200 |
---|---|---|
committer | Cosimo Cecchi <cosimoc@gnome.org> | 2019-07-15 23:55:28 +0200 |
commit | 4568ceafe6e072f40ab1f410d1e298046cd52792 (patch) | |
tree | 899ce80e86b130621f3f74a8d10c705fddfd4913 | |
parent | 0bdf183663a1ee9dc4d748fb1baf5e0bb472cdb7 (diff) | |
download | gnome-font-viewer-4568ceafe6e072f40ab1f410d1e298046cd52792.tar.gz |
Use a GFile in FontViewModelItem
Instead of storing the path; this saves a few roundtrips to create a
GFile, since most of the operations we performs need a GFile anyway.
-rw-r--r-- | src/font-model.c | 27 | ||||
-rw-r--r-- | src/font-model.h | 2 | ||||
-rw-r--r-- | src/font-utils.c | 5 | ||||
-rw-r--r-- | src/font-utils.h | 4 | ||||
-rw-r--r-- | src/font-view.c | 22 |
5 files changed, 26 insertions, 34 deletions
diff --git a/src/font-model.c b/src/font-model.c index ab299db..658cba8 100644 --- a/src/font-model.c +++ b/src/font-model.c @@ -59,7 +59,7 @@ struct _FontViewModelItem gchar *collation_key; gchar *font_name; - gchar *path; + GFile *file; int face_index; }; @@ -72,7 +72,7 @@ font_view_model_item_finalize (GObject *obj) g_clear_pointer (&self->collation_key, g_free); g_clear_pointer (&self->font_name, g_free); - g_clear_pointer (&self->path, g_free); + g_clear_object (&self->file); G_OBJECT_CLASS (font_view_model_item_parent_class)->finalize (obj); } @@ -91,14 +91,14 @@ font_view_model_item_init (FontViewModelItem *self) static FontViewModelItem * font_view_model_item_new (const gchar *font_name, - const gchar *path, + GFile *file, int face_index) { FontViewModelItem *item = g_object_new (FONT_VIEW_TYPE_MODEL_ITEM, NULL); item->collation_key = g_utf8_collate_key (font_name, -1); item->font_name = g_strdup (font_name); - item->path = g_strdup (path); + item->file = g_object_ref (file); item->face_index = face_index; return item; @@ -116,10 +116,10 @@ font_view_model_item_get_font_name (FontViewModelItem *self) return self->font_name; } -const gchar * -font_view_model_item_get_font_path (FontViewModelItem *self) +GFile * +font_view_model_item_get_font_file (FontViewModelItem *self) { - return self->path; + return self->file; } gint @@ -175,26 +175,25 @@ load_font_infos (GTask *task, for (i = 0; i < n_fonts; i++) { FontViewModelItem *item; - FcChar8 *file; + FcChar8 *path; int index; g_autofree gchar *font_name = NULL; + g_autoptr(GFile) file = NULL; if (g_task_return_error_if_cancelled (task)) return; g_mutex_lock (&self->font_list_mutex); - FcPatternGetString (self->font_list->fonts[i], FC_FILE, 0, &file); + FcPatternGetString (self->font_list->fonts[i], FC_FILE, 0, &path); FcPatternGetInteger (self->font_list->fonts[i], FC_INDEX, 0, &index); g_mutex_unlock (&self->font_list_mutex); - font_name = font_utils_get_font_name_for_file (self->library, - (const gchar *) file, - index); - + file = g_file_new_for_path ((const gchar *) path); + font_name = font_utils_get_font_name_for_file (self->library, file, index); if (!font_name) continue; - item = font_view_model_item_new (font_name, (const gchar *) file, index); + item = font_view_model_item_new (font_name, file, index); g_ptr_array_add (items, item); } diff --git a/src/font-model.h b/src/font-model.h index 0b33a0b..68edf6a 100644 --- a/src/font-model.h +++ b/src/font-model.h @@ -57,8 +57,8 @@ G_DECLARE_FINAL_TYPE (FontViewModelItem, font_view_model_item, gint font_view_model_item_get_face_index (FontViewModelItem *self); const gchar *font_view_model_item_get_collation_key (FontViewModelItem *self); +GFile *font_view_model_item_get_font_file (FontViewModelItem *self); const gchar *font_view_model_item_get_font_name (FontViewModelItem *self); -const gchar *font_view_model_item_get_font_path (FontViewModelItem *self); G_END_DECLS diff --git a/src/font-utils.c b/src/font-utils.c index 3cdd3c2..5a75fb3 100644 --- a/src/font-utils.c +++ b/src/font-utils.c @@ -33,18 +33,15 @@ font_utils_get_font_name (FT_Face face) gchar * font_utils_get_font_name_for_file (FT_Library library, - const gchar *path, + GFile *file, gint face_index) { g_autoptr(GError) error = NULL; - g_autoptr(GFile) file = NULL; g_autofree gchar *uri = NULL, *contents = NULL; gchar *name = NULL; FT_Face face; - file = g_file_new_for_path (path); uri = g_file_get_uri (file); - face = sushi_new_ft_face_from_uri (library, uri, face_index, &contents, &error); if (error != NULL) { diff --git a/src/font-utils.h b/src/font-utils.h index 2dfe786..6f73bb4 100644 --- a/src/font-utils.h +++ b/src/font-utils.h @@ -23,11 +23,11 @@ #include <ft2build.h> #include FT_FREETYPE_H -#include <glib.h> +#include <gio/gio.h> gchar * font_utils_get_font_name (FT_Face face); gchar * font_utils_get_font_name_for_file (FT_Library library, - const gchar *path, + GFile *file, gint face_index); #endif /* __FONT_UTILS_H__ */ diff --git a/src/font-view.c b/src/font-view.c index c775182..506743a 100644 --- a/src/font-view.c +++ b/src/font-view.c @@ -237,25 +237,23 @@ font_view_item_load_thumbnail_job (GTask *task, gint scale_factor = GPOINTER_TO_INT (task_data); g_autoptr(GdkPixbuf) pixbuf = NULL; g_autoptr(GError) error = NULL; - g_autoptr(GFile) file = NULL; g_autofree gchar *thumb_path = NULL, *thumb_uri = NULL, *file_uri = NULL; gint face_index; - const gchar *font_path; + GFile *font_file; if (g_task_return_error_if_cancelled (task)) return; face_index = font_view_model_item_get_face_index (item); - font_path = font_view_model_item_get_font_path (item); - file = g_file_new_for_path (font_path); - file_uri = g_file_get_uri (file); + font_file = font_view_model_item_get_font_file (item); + file_uri = g_file_get_uri (font_file); if (face_index == 0) { g_autoptr(GFileInfo) info = NULL; gboolean thumb_failed; thumb_uri = g_strdup (file_uri); - info = g_file_query_info (file, + info = g_file_query_info (font_file, ATTRIBUTES_FOR_EXISTING_THUMBNAIL, G_FILE_QUERY_INFO_NONE, NULL, &error); @@ -311,7 +309,7 @@ font_view_item_load_thumbnail_job (GTask *task, return; } } else { - pixbuf = create_thumbnail (file, thumb_uri, scale_factor); + pixbuf = create_thumbnail (font_file, thumb_uri, scale_factor); } if (pixbuf != NULL) @@ -1220,16 +1218,14 @@ view_child_activated_cb (GtkFlowBox *flow_box, FontViewApplication *self = user_data; FontViewItem *view_item = FONT_VIEW_ITEM (child); FontViewModelItem *item = view_item->item; - const gchar *font_path; + GFile *font_file; gint face_index; - font_path = font_view_model_item_get_font_path (item); + font_file = font_view_model_item_get_font_file (item); face_index = font_view_model_item_get_face_index (item); - if (font_path != NULL) { - g_autoptr(GFile) file = g_file_new_for_path (font_path); - font_view_application_do_open (self, file, face_index); - } + if (font_file != NULL) + font_view_application_do_open (self, font_file, face_index); } static void |