summaryrefslogtreecommitdiff
path: root/font-viewer
diff options
context:
space:
mode:
authorraveit65 <[email protected]>2017-01-08 20:23:45 +0100
committerraveit65 <[email protected]>2017-02-17 12:28:22 +0100
commit18b8eb2fc6785183068eaaa8d6fa1dda86793bfe (patch)
tree197864f803d7134eb2e88c0f8646be534f6e0348 /font-viewer
parent5cd279624ad264c97895a64c56946b5790b44390 (diff)
downloadmate-control-center-18b8eb2fc6785183068eaaa8d6fa1dda86793bfe.tar.bz2
mate-control-center-18b8eb2fc6785183068eaaa8d6fa1dda86793bfe.tar.xz
Fontviewer: don't crash when opening a non-existing file
This is only a problem from the command line. taken from: https://git.gnome.org/browse/gnome-font-viewer/commit/?id=baef02a
Diffstat (limited to 'font-viewer')
-rw-r--r--font-viewer/font-view.c60
1 files changed, 49 insertions, 11 deletions
diff --git a/font-viewer/font-view.c b/font-viewer/font-view.c
index 379f4f95..c82126da 100644
--- a/font-viewer/font-view.c
+++ b/font-viewer/font-view.c
@@ -421,10 +421,14 @@ font_widget_loaded_cb (SushiFontWidget *font_widget,
{
FontViewApplication *self = user_data;
FT_Face face = sushi_font_widget_get_ft_face (font_widget);
+ const gchar *uri;
if (face == NULL)
return;
+ uri = sushi_font_widget_get_uri (font_widget);
+ self->font_file = g_file_new_for_uri (uri);
+
gd_main_toolbar_set_labels (GD_MAIN_TOOLBAR (self->toolbar),
face->family_name, face->style_name);
@@ -466,10 +470,21 @@ info_button_clicked_cb (GtkButton *button,
}
static void
-font_view_application_do_open (FontViewApplication *self)
+font_view_ensure_model (FontViewApplication *self)
+{
+ self->model = font_view_model_new ();
+ g_signal_connect (self->model, "config-changed",
+ G_CALLBACK (font_model_config_changed_cb), self);
+}
+
+static void
+font_view_application_do_open (FontViewApplication *self,
+ GFile *file)
{
gchar *uri;
+ font_view_ensure_model (self);
+
self->info_button = gd_main_toolbar_add_button (GD_MAIN_TOOLBAR (self->toolbar),
NULL, _("Info"),
FALSE);
@@ -491,7 +506,8 @@ font_view_application_do_open (FontViewApplication *self)
gtk_widget_set_vexpand (self->toolbar, FALSE);
- uri = g_file_get_uri (self->font_file);
+ uri = g_file_get_uri (file);
+
if (self->font_widget == NULL) {
GdkRGBA white = { 1.0, 1.0, 1.0, 1.0 };
GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 };
@@ -531,6 +547,7 @@ icon_view_release_cb (GtkWidget *widget,
GtkTreePath *path;
GtkTreeIter iter;
gchar *font_path;
+ GFile *file;
/* eat double/triple click events */
if (event->type != GDK_BUTTON_RELEASE)
@@ -546,8 +563,9 @@ icon_view_release_cb (GtkWidget *widget,
-1);
if (font_path != NULL) {
- self->font_file = g_file_new_for_path (font_path);
- font_view_application_do_open (self);
+ file = g_file_new_for_path (font_path);
+ font_view_application_do_open (self, file);
+ g_object_unref (file);
}
gtk_tree_path_free (path);
g_free (font_path);
@@ -576,6 +594,8 @@ font_view_application_do_overview (FontViewApplication *self)
self->install_button = NULL;
}
+ font_view_ensure_model (self);
+
gd_main_toolbar_set_labels (GD_MAIN_TOOLBAR (self->toolbar), _("All Fonts"), NULL);
if (self->icon_view == NULL) {
@@ -622,15 +642,37 @@ font_view_application_do_overview (FontViewApplication *self)
}
static void
+query_info_ready_cb (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ FontViewApplication *self = user_data;
+ GFileInfo *info;
+ GError *error = NULL;
+
+ info = g_file_query_info_finish (G_FILE (object), res, &error);
+ if (error != NULL) {
+ font_view_application_do_overview (self);
+ font_view_show_font_error (self, error->message);
+ g_error_free (error);
+ } else {
+ font_view_application_do_open (self, G_FILE (object));
+ }
+
+ g_clear_object (&info);
+}
+
+static void
font_view_application_open (GApplication *application,
GFile **files,
gint n_files,
const gchar *hint)
{
FontViewApplication *self = FONT_VIEW_APPLICATION (application);
-
- self->font_file = g_object_ref (files[0]);
- font_view_application_do_open (self);
+ g_file_query_info_async (files[0], G_FILE_ATTRIBUTE_STANDARD_NAME,
+ G_FILE_QUERY_INFO_NONE,
+ G_PRIORITY_DEFAULT, NULL,
+ query_info_ready_cb, self);
}
static void
@@ -693,10 +735,6 @@ font_view_application_startup (GApplication *application)
g_object_unref (builder);
g_object_unref (menu);
- self->model = font_view_model_new ();
- g_signal_connect (self->model, "config-changed",
- G_CALLBACK (font_model_config_changed_cb), self);
-
self->main_window = window = gtk_application_window_new (GTK_APPLICATION (application));
gtk_window_set_resizable (GTK_WINDOW (window), TRUE);
gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);