[gitg] Do not assume external gsettings schemas exist



commit bf021dcadd8b5113884e85f7d97212315b0124d5
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Wed Jan 8 14:32:13 2014 +0100

    Do not assume external gsettings schemas exist
    
    The problem with GSettings is that it errors when a schema is not found
    causing the application to abort. We now check for schema existence of
    external schemas that we optionally want to use.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=721748

 libgitg/gitg-diff-view.vala   |   37 +++++++++++++++++++++++++++++--------
 plugins/files/gitg-files.vala |   25 +++++++++++++++++++++----
 2 files changed, 50 insertions(+), 12 deletions(-)
---
diff --git a/libgitg/gitg-diff-view.vala b/libgitg/gitg-diff-view.vala
index 067f501..34ca96d 100644
--- a/libgitg/gitg-diff-view.vala
+++ b/libgitg/gitg-diff-view.vala
@@ -47,7 +47,7 @@ namespace Gitg
 
                private Ggit.Diff? d_diff;
                private Commit? d_commit;
-               private Settings d_fontsettings;
+               private Settings? d_fontsettings;
                private bool d_has_selection;
 
                private static Gee.HashMap<string, DiffView> s_diff_map;
@@ -276,6 +276,23 @@ namespace Gitg
                        settings.default_monospace_font_size = fsize;
                }
 
+               private Settings? try_settings(string schema_id)
+               {
+                       var source = SettingsSchemaSource.get_default();
+
+                       if (source == null)
+                       {
+                               return null;
+                       }
+
+                       if (source.lookup(schema_id, true) != null)
+                       {
+                               return new Settings(schema_id);
+                       }
+
+                       return null;
+               }
+
                protected override void constructed()
                {
                        base.constructed();
@@ -293,18 +310,22 @@ namespace Gitg
                        settings.javascript_can_access_clipboard = true;
                        settings.enable_page_cache = false;
 
-                       d_fontsettings = new Settings("org.gnome.desktop.interface");
                        set_settings(settings);
 
-                       update_font_settings();
+                       d_fontsettings = try_settings("org.gnome.desktop.interface");
 
-                       d_fontsettings.changed["monospace-font-name"].connect((s, k) => {
+                       if (d_fontsettings != null)
+                       {
                                update_font_settings();
-                       });
 
-                       d_fontsettings.changed["font-name"].connect((s, k) => {
-                               update_font_settings();
-                       });
+                               d_fontsettings.changed["monospace-font-name"].connect((s, k) => {
+                                       update_font_settings();
+                               });
+
+                               d_fontsettings.changed["font-name"].connect((s, k) => {
+                                       update_font_settings();
+                               });
+                       }
 
                        ++s_diff_id;
                        s_diff_map[s_diff_id.to_string()] = this;
diff --git a/plugins/files/gitg-files.vala b/plugins/files/gitg-files.vala
index b9bd702..5127cb6 100644
--- a/plugins/files/gitg-files.vala
+++ b/plugins/files/gitg-files.vala
@@ -30,8 +30,8 @@ namespace GitgFiles
                private TreeStore d_model;
                private Gtk.Paned d_paned;
                private GtkSource.View d_source;
-               private Settings d_fontsettings;
-               private Settings d_stylesettings;
+               private Settings? d_fontsettings;
+               private Settings? d_stylesettings;
 
                private Gtk.ScrolledWindow d_scrolled_files;
                private Gtk.ScrolledWindow d_scrolled;
@@ -98,6 +98,23 @@ namespace GitgFiles
                        }
                }
 
+               private Settings? try_settings(string schema_id)
+               {
+                       var source = SettingsSchemaSource.get_default();
+
+                       if (source == null)
+                       {
+                               return null;
+                       }
+
+                       if (source.lookup(schema_id, true) != null)
+                       {
+                               return new Settings(schema_id);
+                       }
+
+                       return null;
+               }
+
                private void build_ui()
                {
                        var ret = GitgExt.UI.from_builder("files/view-files.ui",
@@ -122,7 +139,7 @@ namespace GitgFiles
                        d_imagevp.add(d_image);
                        d_imagevp.show_all();
 
-                       d_fontsettings = new Settings("org.gnome.desktop.interface");
+                       d_fontsettings = try_settings("org.gnome.desktop.interface");
 
                        if (d_fontsettings != null)
                        {
@@ -133,7 +150,7 @@ namespace GitgFiles
                                update_font();
                        }
 
-                       d_stylesettings = new Settings("org.gnome.gedit.preferences.editor");
+                       d_stylesettings = try_settings("org.gnome.gedit.preferences.editor");
 
                        if (d_stylesettings != null)
                        {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]