[banshee/stable] Performance improvements for Notification Area



commit 8f6fab46680d622d58b85a2e55f7cd5f7950a339
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                     |   88 ++++++++++++-------
 .../X11NotificationAreaBox.cs                      |    2 +-
 4 files changed, 70 insertions(+), 34 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 2d19826..0b4e2aa 100644
--- a/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs
+++ b/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs
@@ -58,7 +58,7 @@ namespace Banshee.NotificationArea
         private Menu menu;
         private RatingMenuItem rating_menu_item;
         private BansheeActionGroup actions;
-        private uint ui_manager_id;
+        private int ui_manager_id;
         
         private bool show_notifications;
         private string notify_last_title;
@@ -106,6 +106,13 @@ namespace Banshee.NotificationArea
                 return false;
             }
             
+            GLib.Timeout.Add (1000, delegate {
+                if (notif_area != null) {
+                    notif_area.Show ();
+                }
+                return false;
+            });
+            
             return true;
         }
         
@@ -126,37 +133,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 |
@@ -191,8 +169,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;
@@ -240,6 +221,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) {
@@ -274,6 +293,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) {
@@ -283,6 +304,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 7cc52cf..4d9ff6d 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]