[longomatch] Fix more events passing with the events broker



commit 036a4988c8cd87bbfe699d9e007a2724a48a5a97
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Tue Jun 10 11:10:52 2014 +0200

    Fix more events passing with the events  broker

 LongoMatch.Core/Common/EventsBroker.cs             |   31 ++++++++++--
 LongoMatch.Core/Handlers/Handlers.cs               |    2 +
 LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs         |    6 ++
 .../Gui/Component/AnalysisTemplateEditor.cs        |    5 ++-
 LongoMatch.GUI/Gui/Component/CodingWidget.cs       |   15 +-----
 LongoMatch.GUI/Gui/Component/NotesWidget.cs        |    1 +
 .../Gui/Component/PlaysCoordinatesTagger.cs        |    1 +
 .../Gui/Component/PlaysSelectionWidget.cs          |    3 +-
 LongoMatch.Services/Services/EventsManager.cs      |    2 +-
 LongoMatch.Services/Services/PlaylistManager.cs    |   16 +++---
 LongoMatch.Services/Services/ProjectsManager.cs    |   53 ++++++++++++++++++++
 11 files changed, 109 insertions(+), 26 deletions(-)
---
diff --git a/LongoMatch.Core/Common/EventsBroker.cs b/LongoMatch.Core/Common/EventsBroker.cs
index 3b7f0c7..5265f66 100644
--- a/LongoMatch.Core/Common/EventsBroker.cs
+++ b/LongoMatch.Core/Common/EventsBroker.cs
@@ -38,12 +38,12 @@ namespace LongoMatch.Common
                public event PlayListNodeAddedHandler PlayListNodeAdded;
                public event TimeNodeChangedHandler TimeNodeChanged;
                public event SnapshotSeriesHandler SnapshotSeries;
-               public event RenderPlaylistHandler RenderPlaylist;
                public event TagPlayHandler TagPlay;
                public event DuplicatePlayHandler DuplicatePlay;
+               public event TeamsTagsChangedHandler TeamTagsChanged;
                
                /* Playlist */
-               public event RenderPlaylistHandler RenderPlaylistEvent;
+               public event RenderPlaylistHandler RenderPlaylist;
                public event PlayListNodeAddedHandler PlayListNodeAddedEvent;
                public event PlayListNodeSelectedHandler PlayListNodeSelectedEvent;
                public event OpenPlaylistHandler OpenPlaylistEvent;
@@ -60,8 +60,6 @@ namespace LongoMatch.Common
                public event ShowProjectStats ShowProjectStatsEvent;
                public event TagSubcategoriesChangedHandler TagSubcategoriesChangedEvent;
                
-               /* Main controller */
-               
                /* IMainController */
                public event NewProjectHandler NewProjectEvent;
                public event OpenNewProjectHandler OpenNewProjectEvent;
@@ -80,6 +78,10 @@ namespace LongoMatch.Common
                
                public event OpenedProjectChangedHandler OpenedProjectChanged;
                
+               public event TickHandler Tick;
+               public event ErrorHandler MultimediaError;
+               public event SegmentClosedHandler SegmentClosed;
+               
                
                public EventsBroker ()
                {
@@ -295,6 +297,27 @@ namespace LongoMatch.Common
                                OpenedProjectChanged (project, projectType, filter, analysisWindow);
                        }
                }
+
+               public void EmitTick (Time currentTime, Time streamLength, double currentPosition)
+               {
+                       if (Tick != null) {
+                               Tick (currentTime, streamLength, currentPosition);
+                       }
+               }
+               
+               public void EmitSegmentClosed ()
+               {
+                       if (SegmentClosed != null) {
+                               SegmentClosed ();
+                       }
+               }
+               
+               public void EmitTeamTagsChanged ()
+               {
+                       if (TeamTagsChanged != null) {
+                               TeamTagsChanged ();
+                       }
+               }
        }
 }
 
diff --git a/LongoMatch.Core/Handlers/Handlers.cs b/LongoMatch.Core/Handlers/Handlers.cs
index c825e4d..52754de 100644
--- a/LongoMatch.Core/Handlers/Handlers.cs
+++ b/LongoMatch.Core/Handlers/Handlers.cs
@@ -52,6 +52,8 @@ namespace LongoMatch.Handlers
        /* DUplicate play */
        public delegate void DuplicatePlayHandler (Play play);
        
+       public delegate void TeamsTagsChangedHandler ();
+       
        /* Project Events */
        public delegate void SaveProjectHandler(Project project, ProjectType projectType);
        public delegate void OpenedProjectChangedHandler(Project project, ProjectType projectType, 
PlaysFilter filter,
diff --git a/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs b/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs
index bb30733..2a80f6c 100644
--- a/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs
+++ b/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs
@@ -222,6 +222,7 @@ namespace LongoMatch.Gui
                }
                
                public void Close() {
+                       player.Tick -= tickHandler;
                        player.Close();
                        filename = null;
                        timescale.Value = 0;
@@ -324,6 +325,11 @@ namespace LongoMatch.Gui
                        drawbutton.Clicked += OnDrawButtonClicked;
                        timescale.ValueChanged += OnTimescaleValueChanged;
                        timescale.AdjustBounds += OnTimescaleAdjustBounds;
+                       vscale1.FormatValue += OnVscale1FormatValue;
+                       vscale1.ValueChanged += OnVscale1ValueChanged;
+                       drawbutton.Clicked += OnDrawButtonClicked;
+                       volumebutton.Clicked += OnVolumebuttonClicked;
+
                }
                
                void LoadSegment (string filename, Time start, Time stop, Time seekTime,
diff --git a/LongoMatch.GUI/Gui/Component/AnalysisTemplateEditor.cs 
b/LongoMatch.GUI/Gui/Component/AnalysisTemplateEditor.cs
index f158ca8..c114034 100644
--- a/LongoMatch.GUI/Gui/Component/AnalysisTemplateEditor.cs
+++ b/LongoMatch.GUI/Gui/Component/AnalysisTemplateEditor.cs
@@ -24,17 +24,20 @@ namespace LongoMatch.Gui.Component
        public partial class AnalysisTemplateEditor : Gtk.Bin
        {
                bool edited;
+               Categories template;
 
                public AnalysisTemplateEditor ()
                {
                        this.Build ();
                        buttonswidget.Mode = LongoMatch.Common.TagMode.Predifined;
-                       //buttonswidget.NewMarkEvent += HandleNewMarkEvent;
+                       Config.EventsBroker.NewTagEvent += HandleCategorySelected;
                        categoryproperties.Visible = false;
+                       savebutton.Clicked += HandleSaveClicked;
                }
 
                public Categories Template {
                        set {
+                               template = value;
                                buttonswidget.UpdateCategories (value);
                        }
                }
diff --git a/LongoMatch.GUI/Gui/Component/CodingWidget.cs b/LongoMatch.GUI/Gui/Component/CodingWidget.cs
index e334639..927786b 100644
--- a/LongoMatch.GUI/Gui/Component/CodingWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/CodingWidget.cs
@@ -45,6 +45,9 @@ namespace LongoMatch.Gui.Component
 
                        drawingarea1.HeightRequest = 200;
                        drawingarea1.WidthRequest = 300;
+                       
+                       Config.EventsBroker.Tick += (t, l, p) => timeline.CurrentTime = t;
+                       Config.EventsBroker.PlaySelected += (play) => timeline.SelectedTimeNode = play;
                }
                
                public void SetProject (Project project, bool isLive, PlaysFilter filter) {
@@ -71,18 +74,6 @@ namespace LongoMatch.Gui.Component
                        timeline.RemovePlays(plays);
                }
 
-               public Time CurrentTime {
-                       set {
-                               timeline.CurrentTime = value;
-                       }
-               }               
-
-               public Play SelectedPlay {
-                       set {
-                               timeline.SelectedTimeNode = value;
-                       }
-               }
-               
                public void UpdateCategories () {
                        buttonswidget.Project = project;
                }
diff --git a/LongoMatch.GUI/Gui/Component/NotesWidget.cs b/LongoMatch.GUI/Gui/Component/NotesWidget.cs
index ead37b1..4602386 100644
--- a/LongoMatch.GUI/Gui/Component/NotesWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/NotesWidget.cs
@@ -38,6 +38,7 @@ namespace LongoMatch.Gui.Component
                        this.Build();
                        this.buf = textview1.Buffer;
                        buf.Changed += new EventHandler(OnEdition);
+                       Config.EventsBroker.PlaySelected += (play) => {Play = play;};
 
                }
 
diff --git a/LongoMatch.GUI/Gui/Component/PlaysCoordinatesTagger.cs 
b/LongoMatch.GUI/Gui/Component/PlaysCoordinatesTagger.cs
index 2effe62..a151378 100644
--- a/LongoMatch.GUI/Gui/Component/PlaysCoordinatesTagger.cs
+++ b/LongoMatch.GUI/Gui/Component/PlaysCoordinatesTagger.cs
@@ -41,6 +41,7 @@ namespace LongoMatch.Gui.Component
                {
                        this.Build ();
                        SetMode (true);
+                       Config.EventsBroker.PlaySelected += (play) => LoadPlay (play, false);
                }
                
                public bool CoordinatesSensitive {
diff --git a/LongoMatch.GUI/Gui/Component/PlaysSelectionWidget.cs 
b/LongoMatch.GUI/Gui/Component/PlaysSelectionWidget.cs
index 6b73c35..3be419b 100644
--- a/LongoMatch.GUI/Gui/Component/PlaysSelectionWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/PlaysSelectionWidget.cs
@@ -42,7 +42,7 @@ namespace LongoMatch.Gui.Component
                        localPlayersList.Team = Team.LOCAL;
                        visitorPlayersList.Team = Team.VISITOR;
                        AddFilters();
-                       Config.EventsBroker.TagPlay += (Play play) => {UpdateTeamsModels();};
+                       Config.EventsBroker.TeamTagsChanged += UpdateTeamsModels;
                }
                
                #region Plubic Methods
@@ -70,6 +70,7 @@ namespace LongoMatch.Gui.Component
                        playsList.Project = null;
                        localPlayersList.Clear();
                        visitorPlayersList.Clear();
+                       Config.EventsBroker.TeamTagsChanged -= UpdateTeamsModels;
                }
                
                public bool PlayListLoaded {
diff --git a/LongoMatch.Services/Services/EventsManager.cs b/LongoMatch.Services/Services/EventsManager.cs
index 2ac91ce..314144a 100644
--- a/LongoMatch.Services/Services/EventsManager.cs
+++ b/LongoMatch.Services/Services/EventsManager.cs
@@ -148,7 +148,6 @@ namespace LongoMatch.Services
                void LoadPlay (Play play, Time seekTime, bool playing) {
                        player.LoadPlay (openedProject.Description.File.FilePath, play,
                                         seekTime, playing);
-                       analysisWindow.UpdateSelectedPlay(play);
                        loadedPlay = play;
                        if (playing) {
                                player.Play ();
@@ -288,6 +287,7 @@ namespace LongoMatch.Services
                                           openedProject.LocalTeamTemplate,
                                           openedProject.VisitorTeamTemplate,
                                           showAllTags);
+                       Config.EventsBroker.EmitTeamTagsChanged ();
                }
 
                void HandlePlaybackRateChanged (float rate)
diff --git a/LongoMatch.Services/Services/PlaylistManager.cs b/LongoMatch.Services/Services/PlaylistManager.cs
index 4178abe..8b71f98 100644
--- a/LongoMatch.Services/Services/PlaylistManager.cs
+++ b/LongoMatch.Services/Services/PlaylistManager.cs
@@ -87,15 +87,17 @@ namespace LongoMatch.Services
                        Config.EventsBroker.SavePlaylistEvent += OnSavePlaylist;
                        Config.EventsBroker.PlayListNodeAddedEvent += OnPlayListNodeAdded;
                        Config.EventsBroker.PlayListNodeSelectedEvent += LoadPlaylistPlay;
-                       Config.EventsBroker.RenderPlaylistEvent += OnRenderPlaylistEvent;
+                       Config.EventsBroker.RenderPlaylist += OnRenderPlaylistEvent;
+                       Config.EventsBroker.SegmentClosed += () => {selectedTimeNode = null;};
                        
                        /* Handle Next/Prev from the player */
-                       analysisWindow.Player.SegmentClosedEvent += () => {selectedTimeNode = null;};
-                       analysisWindow.Player.Next += () => {Next();};
-                       analysisWindow.Player.Prev += () => {
-                               if(selectedTimeNode is PlayListPlay)
-                                       Prev();
-                       };
+                       if (analysisWindow.Player != null) {
+                               analysisWindow.Player.Next += () => {Next();};
+                               analysisWindow.Player.Prev += () => {
+                                       if(selectedTimeNode is PlayListPlay)
+                                               Prev();
+                               };
+                       }
                }
                
                private void Add(List<Play> plays) {
diff --git a/LongoMatch.Services/Services/ProjectsManager.cs b/LongoMatch.Services/Services/ProjectsManager.cs
index 7f8d39d..837d952 100644
--- a/LongoMatch.Services/Services/ProjectsManager.cs
+++ b/LongoMatch.Services/Services/ProjectsManager.cs
@@ -57,6 +57,7 @@ namespace LongoMatch.Services
                        Config.EventsBroker.OpenNewProjectEvent += OpenNewProject;
                        Config.EventsBroker.CloseOpenedProjectEvent += () => PromptCloseProject();
                        Config.EventsBroker.SaveProjectEvent += SaveProject;
+                       Config.EventsBroker.KeyPressed += HandleKeyPressed;
                }
 
                public Project OpenedProject {
@@ -369,5 +370,57 @@ namespace LongoMatch.Services
                        }
                        SetProject(project, ProjectType.FileProject, new CaptureSettings());
                }
+
+               void HandleMultimediaError (string message)
+               {
+                       guiToolkit.ErrorMessage (Catalog.GetString("The following error happened and" +
+                               " the current project will be closed:")+"\n" + message);
+                       CloseOpenedProject (true);
+               }
+               
+               void HandleKeyPressed (object sender, int key, int modifier)
+               {
+                       if(OpenedProject == null)
+                               return;
+
+                       if(OpenedProjectType != ProjectType.CaptureProject &&
+                          OpenedProjectType != ProjectType.URICaptureProject &&
+                          OpenedProjectType != ProjectType.FakeCaptureProject) {
+                               if (Player == null)
+                                       return;
+
+                               switch(key) {
+                               case Constants.SEEK_FORWARD:
+                                       if(modifier == Constants.STEP)
+                                               Player.StepForward();
+                                       else
+                                               Player.SeekToNextFrame();
+                                       break;
+                               case Constants.SEEK_BACKWARD:
+                                       if(modifier == Constants.STEP)
+                                               Player.StepBackward();
+                                       else
+                                               Player.SeekToPreviousFrame();
+                                       break;
+                               case Constants.FRAMERATE_UP:
+                                       Player.FramerateUp();
+                                       break;
+                               case Constants.FRAMERATE_DOWN:
+                                       Player.FramerateDown();
+                                       break;
+                               case Constants.TOGGLE_PLAY:
+                                       Player.TogglePlay();
+                                       break;
+                               }
+                       } else {
+                               if (Capturer == null)
+                                       return;
+                               switch(key) {
+                               case Constants.TOGGLE_PLAY:
+                                       Capturer.TogglePause();
+                                       break;
+                               }
+                       }
+               }
        }
 }


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