[gnome-shell] notificationDaemon: Merge two pieces of similar code



commit 1bd349485f8fc8b45715367ea53f8161b03f690d
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sun Dec 30 11:45:43 2012 -0500

    notificationDaemon: Merge two pieces of similar code
    
    Use the same code for parsing notification data to handle both
    icons and images.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=680414

 js/ui/notificationDaemon.js |   39 +++++++++++++++++++--------------------
 1 files changed, 19 insertions(+), 20 deletions(-)
---
diff --git a/js/ui/notificationDaemon.js b/js/ui/notificationDaemon.js
index 1b24883..295024c 100644
--- a/js/ui/notificationDaemon.js
+++ b/js/ui/notificationDaemon.js
@@ -127,6 +127,18 @@ const NotificationDaemon = new Lang.Class({
         this._trayManager.manage_stage(global.stage, Main.messageTray.actor);
     },
 
+    _imageForNotificationData: function(hints) {
+        if (hints['image-data']) {
+            let [width, height, rowStride, hasAlpha,
+                 bitsPerSample, nChannels, data] = hints['image-data'];
+            return Shell.util_create_pixbuf_from_data(data, GdkPixbuf.Colorspace.RGB, hasAlpha,
+                                                      bitsPerSample, width, height, rowStride);
+        } else if (hints['image-path']) {
+            return new Gio.FileIcon({ file: Gio.File.new_for_path(hints['image-path']) });
+        }
+        return null;
+    },
+
     _iconForNotificationData: function(icon, hints) {
         // If an icon is not specified, we use 'image-data' or 'image-path' hint for an icon
         // and don't show a large image. There are currently many applications that use
@@ -143,13 +155,8 @@ const NotificationDaemon = new Lang.Class({
                 return new Gio.FileIcon({ file: Gio.File.new_for_path(icon) });
             else
                 return new Gio.ThemedIcon({ name: icon });
-        } else if (hints['image-data']) {
-            let [width, height, rowStride, hasAlpha,
-                 bitsPerSample, nChannels, data] = hints['image-data'];
-            return Shell.util_create_pixbuf_from_data(data, GdkPixbuf.Colorspace.RGB, hasAlpha,
-                                                      bitsPerSample, width, height, rowStride);
-        } else if (hints['image-path']) {
-            return new Gio.FileIcon({ file: Gio.File.new_for_path(hints['image-path']) });
+        } else if (hints['image-data'] || hints['image-path']) {
+            return this._imageForNotificationData(hints);
         } else {
             let stockIcon;
             switch (hints.urgency) {
@@ -388,19 +395,11 @@ const NotificationDaemon = new Lang.Class({
                                              clear: true });
 
         // We only display a large image if an icon is also specified.
-        let image = null;
-        if (icon && (hints['image-data'] || hints['image-path'])) {
-            if (hints['image-data']) {
-                let [width, height, rowStride, hasAlpha,
-                 bitsPerSample, nChannels, data] = hints['image-data'];
-                image = St.TextureCache.get_default().load_from_raw(data, hasAlpha,
-                                                                    width, height, rowStride, notification.IMAGE_SIZE);
-            } else if (hints['image-path']) {
-                image = St.TextureCache.get_default().load_uri_async(GLib.filename_to_uri(hints['image-path'], null),
-                                                                     notification.IMAGE_SIZE,
-                                                                     notification.IMAGE_SIZE);
-            }
-        }
+        let image;
+        if (icon && (hints['image-data'] || hints['image-path']))
+            image = new St.Icon({ gicon: this._imageForNotificationData(hints) });
+        else
+            image = null;
         notification.setImage(image);
 
         if (actions.length) {



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