[banshee] Performance improvements for Notification Area



commit 2a1a86bbab917d5b6354e4f67203b3e37d115335
Author: Aaron Bockover <abockover novell com>
Date:   Fri Apr 24 21:58:27 2009 -0400

    Performance improvements for Notification Area
    
    This patch delays the creation of the context menu until it is requested,
    which yields a small gain, and delays the showing of the actual notification
    area for one second to allow it to be processed after setting in an idle
    handler, which yields about 0.3s startup gain.
---
 .../GtkNotificationAreaBox.cs                      |   11 +++
 .../INotificationAreaBox.cs                        |    3 +
 .../NotificationAreaService.cs                     |   91 ++++++++++++-------
 .../X11NotificationAreaBox.cs                      |    2 +-
 4 files changed, 72 insertions(+), 35 deletions(-)

diff --git a/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/GtkNotificationAreaBox.cs b/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/GtkNotificationAreaBox.cs
index ff16d0e..2c385b6 100644
--- a/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/GtkNotificationAreaBox.cs
+++ b/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/GtkNotificationAreaBox.cs
@@ -58,6 +58,7 @@ namespace Banshee.NotificationArea
         
         public GtkNotificationAreaBox (BaseClientWindow window)
         {
+            Visible = false;
             IconName = Banshee.ServiceStack.Application.IconName;
             
             Tooltip = window.Title;
@@ -72,6 +73,16 @@ namespace Banshee.NotificationArea
         public void OnPlayerEvent (PlayerEventArgs args)
         {
         }
+        
+        public void Show ()
+        {
+            Visible = true;
+        }
+        
+        public void Hide ()
+        {
+            Visible = false;
+        }
     }
 }
 
diff --git a/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/INotificationAreaBox.cs b/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/INotificationAreaBox.cs
index 2d91010..b089886 100644
--- a/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/INotificationAreaBox.cs
+++ b/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/INotificationAreaBox.cs
@@ -43,5 +43,8 @@ namespace Banshee.NotificationArea
         void OnPlayerEvent (PlayerEventArgs args);
         
         Widget Widget { get; }
+        
+        void Show ();
+        void Hide ();
     }
 }
diff --git a/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs b/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs
index afe1b1c..2019b15 100644
--- a/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs
+++ b/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs
@@ -58,9 +58,10 @@ namespace Banshee.NotificationArea
         private Menu menu;
         private RatingMenuItem rating_menu_item;
         private BansheeActionGroup actions;
-        private uint ui_manager_id;
-
         private bool? actions_supported;
+        
+        private int ui_manager_id;
+        
         private bool show_notifications;
         private string notify_last_title;
         private string notify_last_artist;
@@ -107,6 +108,13 @@ namespace Banshee.NotificationArea
                 return false;
             }
             
+            GLib.Timeout.Add (1000, delegate {
+                if (notif_area != null) {
+                    notif_area.Show ();
+                }
+                return false;
+            });
+            
             return true;
         }
         
@@ -127,37 +135,8 @@ namespace Banshee.NotificationArea
             
             interface_action_service.AddActionGroup (actions);
             
-            ui_manager_id = interface_action_service.UIManager.AddUiFromResource ("NotificationAreaMenu.xml");      
-            menu = (Menu)interface_action_service.UIManager.GetWidget("/NotificationAreaIconMenu");
-            menu.Show ();
+            ui_manager_id = -1;
             
-            for (int i = 0; i < menu.Children.Length; i++) {
-                if (menu.Children[i].Name == "Previous") {
-                    int j = i;
-                    PlaybackRepeatActions repeat_group = interface_action_service.FindActionGroup ("PlaybackRepeat")
-                         as PlaybackRepeatActions;
-                    if (repeat_group != null) {
-                        menu.Insert (repeat_group.CreateSubmenu (), i++ + 2);
-                    }
-                    
-                    PlaybackShuffleActions shuffle_group = interface_action_service.FindActionGroup ("PlaybackShuffle")
-                         as PlaybackShuffleActions;
-                    if (shuffle_group != null) {
-                        menu.Insert (shuffle_group.CreateSubmenu (), i++ + 2);
-                    }
-                    
-                    if (j != i) {
-                        menu.Insert (new SeparatorMenuItem (), i++ + 2);
-                    }
-                    
-                    rating_menu_item = new RatingMenuItem ();
-                    rating_menu_item.Activated += OnRatingChanged;
-                    ToggleRatingMenuSensitive ();
-                    menu.Insert (rating_menu_item, i + 2);
-                    break;
-                }
-            }
-
             ServiceManager.PlayerEngine.ConnectEvent (OnPlayerEvent,
                PlayerEvent.StartOfStream |
                PlayerEvent.EndOfStream |
@@ -192,8 +171,11 @@ namespace Banshee.NotificationArea
                 interface_action_service.GlobalActions.Remove (close_action);
             }
             
-            interface_action_service.RemoveActionGroup ("NotificationArea");
-            interface_action_service.UIManager.RemoveUi (ui_manager_id);
+            if (ui_manager_id >= 0) {
+                interface_action_service.RemoveActionGroup ("NotificationArea");
+                interface_action_service.UIManager.RemoveUi ((uint)ui_manager_id);
+                ui_manager_id = -1;
+            }
             
             actions = null;
             elements_service = null;
@@ -252,6 +234,44 @@ namespace Banshee.NotificationArea
             }
         }
         
+        private void BuildContextMenu ()
+        {
+            if (menu != null) {
+                return;
+            }
+            
+            ui_manager_id = (int)interface_action_service.UIManager.AddUiFromResource ("NotificationAreaMenu.xml");
+            menu = (Menu)interface_action_service.UIManager.GetWidget("/NotificationAreaIconMenu");
+            menu.Show ();
+            
+            for (int i = 0; i < menu.Children.Length; i++) {
+                if (menu.Children[i].Name == "Previous") {
+                    int j = i;
+                    PlaybackRepeatActions repeat_group = interface_action_service.FindActionGroup ("PlaybackRepeat")
+                         as PlaybackRepeatActions;
+                    if (repeat_group != null) {
+                        menu.Insert (repeat_group.CreateSubmenu (), i++ + 2);
+                    }
+                    
+                    PlaybackShuffleActions shuffle_group = interface_action_service.FindActionGroup ("PlaybackShuffle")
+                         as PlaybackShuffleActions;
+                    if (shuffle_group != null) {
+                        menu.Insert (shuffle_group.CreateSubmenu (), i++ + 2);
+                    }
+                    
+                    if (j != i) {
+                        menu.Insert (new SeparatorMenuItem (), i++ + 2);
+                    }
+                    
+                    rating_menu_item = new RatingMenuItem ();
+                    rating_menu_item.Activated += OnRatingChanged;
+                    ToggleRatingMenuSensitive ();
+                    menu.Insert (rating_menu_item, i + 2);
+                    break;
+                }
+            }
+        }
+        
         private void RegisterCloseHandler ()
         {
             if (elements_service.PrimaryWindowClose == null) {
@@ -286,6 +306,8 @@ namespace Banshee.NotificationArea
         
         private void OnNotificationAreaPopupMenuEvent (object o, PopupMenuArgs args)
         {
+            BuildContextMenu ();
+
             if (rating_menu_item.Visible) {
                 TrackInfo track = ServiceManager.PlayerEngine.CurrentTrack;
                 if (track != null) {
@@ -295,6 +317,7 @@ namespace Banshee.NotificationArea
                     rating_menu_item.Reset (track.Rating);
                 }
             }
+
             menu.Popup (null, null, notif_area.PositionMenu, 3, Gtk.Global.CurrentEventTime);
         }
         
diff --git a/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/X11NotificationAreaBox.cs b/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/X11NotificationAreaBox.cs
index 275e1df..16d587c 100644
--- a/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/X11NotificationAreaBox.cs
+++ b/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/X11NotificationAreaBox.cs
@@ -76,7 +76,7 @@ namespace Banshee.NotificationArea
             event_box.LeaveNotifyEvent += OnLeaveNotifyEvent;
             event_box.ScrollEvent += OnMouseScroll;
             
-            ShowAll ();
+            event_box.ShowAll ();
         }
         
         public override void Dispose ()



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