[gnome-contacts] Move loading an ui file to an util



commit bcb610d1190576b1c98d241b80e910c81515ca62
Author: Paolo Borelli <pborelli gnome org>
Date:   Thu Apr 25 10:52:27 2013 +0200

    Move loading an ui file to an util
    
    Loading from a resource cannot fail, so hide the try/catch in an util.
    Also remove the custom vapi and setting the translation domain since
    they are not needed anymore.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=698831

 src/contacts-app.vala   |   10 ++--------
 src/contacts-utils.vala |   10 ++++++++++
 vapi/custom.vapi        |    6 ------
 3 files changed, 12 insertions(+), 14 deletions(-)
---
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index 4fd50f4..1a3a998 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -271,14 +271,8 @@ public class Contacts.App : Gtk.Application {
         settings.set_value ("view-subset", parameter);
       });
 
-    var builder = new Builder ();
-    builder.set_translation_domain (Config.GETTEXT_PACKAGE);
-    try {
-      Gtk.my_builder_add_from_resource (builder, "/org/gnome/contacts/app-menu.ui");
-      set_app_menu ((MenuModel)builder.get_object ("app-menu"));
-    } catch {
-      warning ("Failed to parsing ui file");
-    }
+    var builder = load_ui ("app-menu.ui");
+    set_app_menu ((MenuModel)builder.get_object ("app-menu"));
 
     window = new Contacts.Window (this);
     window.set_application (this);
diff --git a/src/contacts-utils.vala b/src/contacts-utils.vala
index 6754d1f..90b7c3a 100644
--- a/src/contacts-utils.vala
+++ b/src/contacts-utils.vala
@@ -25,6 +25,16 @@ namespace Contacts {
   private static bool is_set (string? str) {
     return str != null && str != "";
   }
+
+  public Gtk.Builder load_ui (string ui) {
+    var builder = new Gtk.Builder ();
+    try {
+        builder.add_from_resource ("/org/gnome/contacts/".concat (ui, null));
+    } catch (GLib.Error e) {
+        error ("loading ui file: %s", e.message);
+    }
+    return builder;
+  }
 }
 
 
diff --git a/vapi/custom.vapi b/vapi/custom.vapi
index caf4be8..8313caa 100644
--- a/vapi/custom.vapi
+++ b/vapi/custom.vapi
@@ -39,12 +39,6 @@ namespace Contacts {
        public static E.SourceRegistry eds_source_registry;
 }
 
-[CCode (cprefix = "Gtk", lower_case_cprefix = "gtk_", cheader_filename = "gtk/gtk.h")]
-namespace Gtk {
-       [CCode (cname = "gtk_builder_add_from_resource")]
-       public static unowned uint my_builder_add_from_resource (Gtk.Builder builder, string path) throws 
GLib.Error;
-}
-
 [CCode (cprefix = "Um", lower_case_cprefix = "um_", cheader_filename = "um-crop-area.h")]
 namespace Um {
        public class CropArea : Gtk.DrawingArea {


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