[banshee/stable-2.6] Notifications: improve null check before AttachToWidget() (bgo#723889)



commit 67361bf91d6ccf9c823f04170227be59158d4652
Author: Andrés G. Aragoneses <knocte gmail com>
Date:   Sat Feb 8 13:53:37 2014 +0100

    Notifications: improve null check before AttachToWidget() (bgo#723889)
    
    GtkNotificationArea class returns null always for its Widget property,
    which means that every user of INotificationAreaBox should check if
    it's null before dereferencing it, not only check if the object is
    null.
    
    This was not happening and was causing an apparently harmless warning
    to be printed in the console. The warning didn't have enough info
    about the exception so now the .Exception() method is used instead,
    which prints the whole stacktrace. (This has been changed in
    SoundMenuService as well, for consistency.)
    
    This didn't seem to happen in the stable branch because in there the
    class used as an INotificationAreaBox is X11NotificationAreaBox, which
    seems to be deprecated in master. Nonetheless, this fix should be
    backported too because X11NotificationAreaBox seemed to be only used
    in the Linux platform, so by backporting it we may be fixing the
    issue in other platforms.
    
    Conflicts:
        src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs

 .../NotificationAreaService.cs                     |    6 ++++--
 .../Notifications/Notification.cs                  |    4 ++++
 .../Banshee.SoundMenu/SoundMenuService.cs          |    2 +-
 3 files changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs 
b/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs
index 2e3ce0e..87d2562 100644
--- a/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs
+++ b/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs
@@ -475,7 +475,9 @@ namespace Banshee.NotificationArea
                     current_nf.Summary = current_track.DisplayTrackTitle;
                     current_nf.Body = message;
                     current_nf.IconName = image;
-                    current_nf.AttachToWidget (notif_area.Widget);
+                    if (notif_area != null && notif_area.Widget != null) {
+                        current_nf.AttachToWidget (notif_area.Widget);
+                    }
                 }
                 current_nf.Urgency = Urgency.Low;
                 current_nf.Timeout = 4500;
@@ -484,7 +486,7 @@ namespace Banshee.NotificationArea
                 }
                 current_nf.Show ();
             } catch (Exception e) {
-                Hyena.Log.Warning (Catalog.GetString ("Cannot show notification"), e.Message, false);
+                Hyena.Log.Exception (Catalog.GetString ("Cannot show notification"), e);
             }
         }
 
diff --git a/src/Extensions/Banshee.NotificationArea/Notifications/Notification.cs 
b/src/Extensions/Banshee.NotificationArea/Notifications/Notification.cs
index c7afafd..8da977e 100644
--- a/src/Extensions/Banshee.NotificationArea/Notifications/Notification.cs
+++ b/src/Extensions/Banshee.NotificationArea/Notifications/Notification.cs
@@ -262,6 +262,10 @@ namespace Notifications {
                }
 
                public void AttachToWidget (Gtk.Widget widget) {
+            if (widget == null) {
+                throw new ArgumentNullException ("widget");
+            }
+
                        int x, y;
 
                        widget.GdkWindow.GetOrigin (out x, out y);
diff --git a/src/Extensions/Banshee.SoundMenu/Banshee.SoundMenu/SoundMenuService.cs 
b/src/Extensions/Banshee.SoundMenu/Banshee.SoundMenu/SoundMenuService.cs
index 2b971a1..8796ed4 100644
--- a/src/Extensions/Banshee.SoundMenu/Banshee.SoundMenu/SoundMenuService.cs
+++ b/src/Extensions/Banshee.SoundMenu/Banshee.SoundMenu/SoundMenuService.cs
@@ -328,7 +328,7 @@ namespace Banshee.SoundMenu
                 current_nf.Show ();
 
             } catch (Exception e) {
-                Log.Warning ("Cannot show notification", e.Message, false);
+                Log.Exception ("Cannot show notification", e);
             }
         }
 


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