[gnome-weather/wip/gjs-experiments: 2/6] Util: deal with resources, not path names



commit af0f62dd5ead35a6a4cf084e052880a39322d788
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Wed Mar 6 20:28:10 2013 +0100

    Util: deal with resources, not path names
    
    Now that we have resource support in package, it's reasonable to expect
    that UI and style lives in resources, so we should optimize for that in Util.

 src/main.js |    5 ++---
 src/util.js |   13 ++++---------
 2 files changed, 6 insertions(+), 12 deletions(-)
---
diff --git a/src/main.js b/src/main.js
index 0ca33cb..ffcf3f3 100644
--- a/src/main.js
+++ b/src/main.js
@@ -49,8 +49,7 @@ const Application = new Lang.Class({
     },
 
     _initAppMenu: function() {
-        let builder = new Gtk.Builder();
-        builder.add_from_resource('/org/gnome/weather/app-menu.ui');
+        let builder = Util.loadUI('/org/gnome/weather/app-menu.ui');
 
         let menu = builder.get_object('app-menu');
         this.set_app_menu(menu);
@@ -61,7 +60,7 @@ const Application = new Lang.Class({
 
         pkg.loadResource();
 
-        Util.loadStyleSheet(Gio.file_new_for_uri('resource:///org/gnome/weather/application.css'));
+        Util.loadStyleSheet('/org/gnome/weather/application.css');
 
         let settings = Gtk.Settings.get_for_screen(Gdk.Screen.get_default());
         settings.gtk_application_prefer_dark_theme = true;
diff --git a/src/util.js b/src/util.js
index 6d82688..f4dcf26 100644
--- a/src/util.js
+++ b/src/util.js
@@ -24,19 +24,14 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-function loadUI(file) {
-    file = file || 'main.ui';
-
+function loadUI(resource) {
     let ui = new Gtk.Builder();
-    ui.add_from_file(GLib.build_filenamev([pkg.pkgdatadir,
-                                           file]));
+    ui.add_from_resource(resource);
     return ui;
 }
 
-function loadStyleSheet(file) {
-    file = file || Gio.file_new_for_path(GLib.build_filenamev([pkg.pkgdatadir,
-                                                               'application.css']));
-
+function loadStyleSheet(resource) {
+    let file = Gio.file_new_for_uri('resource://' + resource);
     let provider = new Gtk.CssProvider();
     provider.load_from_file(file);
     Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),


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