~elementary-pantheon/pantheon-notify/pantheon-notify-trunk

« back to all changes in this revision

Viewing changes to src/notification.vala

  • Committer: Tom Beckmann
  • Date: 2013-06-13 18:48:55 UTC
  • mfrom: (25.1.1 pantheon-notify)
  • Revision ID: tomjonabc@gmail.com-20130613184855-ojutv71vkgv6isdn
Properly load image corresponding to "image_data". Also add support for "image-data" since the former has been deprecated. Fixes lp:991557

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
 
 
3
2
public class Notification : Clutter.Group {
4
3
        
5
4
        public enum Urgency {
232
231
        
233
232
        public void set_pix (HashTable<string, Variant> hints, string app, string icon) {
234
233
                /*decide on the icon, order:
235
 
                 image-data
 
234
                 image-data (also supports deprecated version: image_data)
236
235
                 image-path
237
236
                 app_icon
238
237
                 icon_data
239
238
                 from app name?
240
239
                 fallback to dialog-information
241
240
                */
242
 
                if (hints.contains ("image_data")) {                                            /*image-data*/
 
241
                if (hints.contains ("image_data") || hints.contains ("image-data")) {
243
242
                        debug ("Using image_data");
244
 
                        
245
 
                        int width;
246
 
                        int height;
247
 
                        int rowstride;
 
243
 
 
244
                        var image_data = hints.lookup ("image_data");
 
245
                        if (image_data == null)
 
246
                                image_data = hints.lookup ("image-data");       
 
247
 
 
248
                        return_if_fail (image_data != null);
 
249
 
 
250
                        weak uchar[] dummy_data;
248
251
                        bool has_alpha;
249
 
                        int bits_per_sample;
250
 
                        int channels;
251
 
                        weak Array<uint8> data;
252
 
                        //weak uint8 [] pixel;
253
 
                        
254
 
                        hints.lookup ("image_data").get ("(iiibiiay)", out width, out height, out rowstride, out has_alpha, out bits_per_sample, out channels, out data, uint.MAX);
255
 
                        
256
 
                        /*var size = (height - 1) * rowstride + width * ((channels * bits_per_sample + 7) / 8);
257
 
                        pixel = (uint8[])GLib.Memory.dup (data, size);*/
258
 
                        
259
 
                        debug ("datalen: %u, width: %i, height: %i\n", data.length, width, height);
260
 
                        
261
 
                        var pix = new Gdk.Pixbuf.from_data ((uint8[])data, Gdk.Colorspace.RGB, has_alpha, bits_per_sample, width, height, rowstride, null).scale_simple (48, 48, Gdk.InterpType.HYPER);
 
252
                        int width, height, rowstride, bits_per_sample, n_channels;
 
253
 
 
254
                        image_data.get ("(iiibiiay)", out width, out height, out rowstride,
 
255
                                out has_alpha, out bits_per_sample, out n_channels, out dummy_data);
 
256
 
 
257
                        var pixels = image_data.get_child_value (6);
 
258
                        weak uchar[] pixel_data = (uchar[]) pixels.get_data ();
 
259
 
 
260
                        var pix = new Gdk.Pixbuf.from_data (pixel_data, Gdk.Colorspace.RGB,
 
261
                                has_alpha, bits_per_sample, width, height, rowstride, null);
 
262
 
 
263
                        var scaled_pix = pix.scale_simple (48, 48, Gdk.InterpType.HYPER);
 
264
 
262
265
                        try {
263
 
                                tex.set_from_pixbuf (pix);
 
266
                                tex.set_from_pixbuf (scaled_pix);
264
267
                        } catch (Error e) { warning (e.message); }
265
268
                } else if (hints.contains ("image-path")) {                              /*image-path*/
266
269
                        debug ("Using image-path");