[longomatch] Fix fake projects scenarios



commit b87ebcf91705f4e95d106a3fe21b6084e383209d
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sun Jun 22 14:06:33 2014 +0200

    Fix fake projects scenarios

 LongoMatch.Core/Interfaces/GUI/ICapturerBin.cs     |    2 +-
 LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs       |   22 ++++--
 LongoMatch.GUI.Multimedia/Gui/PlayerCapturerBin.cs |   10 ++-
 LongoMatch.Services/Services/ProjectsManager.cs    |   17 +---
 LongoMatch.Services/Services/ToolsManager.cs       |   96 +++++++++++---------
 5 files changed, 83 insertions(+), 64 deletions(-)
---
diff --git a/LongoMatch.Core/Interfaces/GUI/ICapturerBin.cs b/LongoMatch.Core/Interfaces/GUI/ICapturerBin.cs
index 00af422..d6fa051 100644
--- a/LongoMatch.Core/Interfaces/GUI/ICapturerBin.cs
+++ b/LongoMatch.Core/Interfaces/GUI/ICapturerBin.cs
@@ -32,7 +32,7 @@ namespace LongoMatch.Interfaces.GUI
                CaptureSettings CaptureSettings {get;}
                List<string> PeriodsNames {set;}
 
-               void Run (CapturerType type, CaptureSettings settings);
+               void Run (CaptureSettings settings);
                void StartPeriod();
                void StopPeriod();
                void Stop();
diff --git a/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs b/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs
index e579689..55f705d 100644
--- a/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs
+++ b/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs
@@ -63,8 +63,17 @@ namespace LongoMatch.Gui
                        LongoMatch.Gui.Helpers.Misc.DisableFocus (vbox1);
                        videodrawingarea.CanFocus = true;
                        ConnectSignals ();
+                       ellapsedTime = new Time (0);
                }
-
+               
+               public CapturerType Mode {
+                       set {
+                               type = value;
+                               videodrawingarea.Visible = value == CapturerType.Live;
+                       }
+                       
+               }
+               
                public bool Capturing {
                        get;
                        protected set;
@@ -161,7 +170,7 @@ namespace LongoMatch.Gui
                        capturer.Stop ();
                }
 
-               public void Run (CapturerType type, CaptureSettings settings) {
+               public void Run (CaptureSettings settings) {
                        /* Close any previous instance of the capturer */
                        Close ();
 
@@ -175,7 +184,7 @@ namespace LongoMatch.Gui
                        } else {
                                videodrawingarea.DoubleBuffered = false;
                        }
-                       if (videodrawingarea.IsRealized) {
+                       if (type == CapturerType.Fake || videodrawingarea.IsRealized) {
                                Configure();
                                capturer.Run();
                        } else {
@@ -192,7 +201,6 @@ namespace LongoMatch.Gui
                        finishbutton.Visible = false;
                        recbutton.Visible = false;
                        Capturing = false;
-                       OnTick(new Time (0));
 
                        if(capturer == null)
                                return;
@@ -260,7 +268,7 @@ namespace LongoMatch.Gui
                
                void Configure () {
                        VideoMuxerType muxer;
-                       IntPtr windowHandle;
+                       IntPtr windowHandle = IntPtr.Zero;
                        
                        if(capturer == null)
                                return;
@@ -272,7 +280,9 @@ namespace LongoMatch.Gui
                                settings.EncodingSettings.EncodingProfile.Muxer = VideoMuxerType.Matroska;
                        }
                                
-                       windowHandle = GtkHelpers.GetWindowHandle (videodrawingarea.GdkWindow);
+                       if (type == CapturerType.Live) {
+                               windowHandle = GtkHelpers.GetWindowHandle (videodrawingarea.GdkWindow);
+                       }
                        capturer.Configure (settings, windowHandle); 
                        delayStart = false;
                }
diff --git a/LongoMatch.GUI.Multimedia/Gui/PlayerCapturerBin.cs 
b/LongoMatch.GUI.Multimedia/Gui/PlayerCapturerBin.cs
index 9223e50..960a9a3 100644
--- a/LongoMatch.GUI.Multimedia/Gui/PlayerCapturerBin.cs
+++ b/LongoMatch.GUI.Multimedia/Gui/PlayerCapturerBin.cs
@@ -36,6 +36,7 @@ namespace LongoMatch.Gui
                public enum PlayerOperationMode {
                        Player,
                        Capturer,
+                       FakeCapturer,
                        PreviewCapturer,
                }
                
@@ -54,6 +55,11 @@ namespace LongoMatch.Gui
                                if (mode == PlayerOperationMode.Player) {
                                        ShowPlayer();
                                } else {
+                                       if (value == PlayerOperationMode.FakeCapturer) {
+                                               capturerbin.Mode = CapturerType.Fake;
+                                       } else {
+                                               capturerbin.Mode = CapturerType.Live;
+                                       }
                                        ShowCapturer();
                                }
                                backtolivebutton.Visible = false;
@@ -138,8 +144,8 @@ namespace LongoMatch.Gui
                        capturerbin.Stop ();
                }
                
-               public void Run (CapturerType type, CaptureSettings settings) {
-                       capturerbin.Run (type, settings);
+               public void Run (CaptureSettings settings) {
+                       capturerbin.Run (settings);
                }
 #endregion
                
diff --git a/LongoMatch.Services/Services/ProjectsManager.cs b/LongoMatch.Services/Services/ProjectsManager.cs
index c5ba731..d19721d 100644
--- a/LongoMatch.Services/Services/ProjectsManager.cs
+++ b/LongoMatch.Services/Services/ProjectsManager.cs
@@ -204,10 +204,12 @@ namespace LongoMatch.Services
                                }
 
                        } else if (projectType == ProjectType.CaptureProject ||
-                                  projectType == ProjectType.URICaptureProject) {
+                                  projectType == ProjectType.URICaptureProject ||
+                                  projectType == ProjectType.FakeCaptureProject) {
                                try {
-                                       Capturer.Run (CapturerType.Live, props);
+                                       Capturer.Run (props);
                                } catch(Exception ex) {
+                                       Log.Exception (ex);
                                        guiToolkit.ErrorMessage(ex.Message);
                                        CloseOpenedProject (false);
                                        return false;
@@ -357,16 +359,7 @@ namespace LongoMatch.Services
                                /* If it's a fake live project prompt for a video file and
                                 * create a new PreviewMediaFile for this project and recreate the thumbnails 
*/
                                Log.Debug ("Importing fake live project");
-                               project.Description.File = null;
-                               
-                               guiToolkit.InfoMessage(
-                                       Catalog.GetString("You are opening a live project without any video 
file associated yet.") +
-                                       "\n" + Catalog.GetString("Select a video file in the next step."));
-                               
-                               guiToolkit.CreateNewProject (project);
-                               if (project == null)
-                                       return;
-                               ToolsManager.CreateThumbnails(project, guiToolkit, 
multimediaToolkit.GetFramesCapturer());
+                               ToolsManager.AddVideoFile (project);
                        }
                        SetProject(project, ProjectType.FileProject, new CaptureSettings());
                }
diff --git a/LongoMatch.Services/Services/ToolsManager.cs b/LongoMatch.Services/Services/ToolsManager.cs
index 138ff89..4ad07ce 100644
--- a/LongoMatch.Services/Services/ToolsManager.cs
+++ b/LongoMatch.Services/Services/ToolsManager.cs
@@ -63,7 +63,59 @@ namespace LongoMatch.Services {
                        Config.EventsBroker.ImportProjectEvent += ImportProject;
                        Config.EventsBroker.ExportProjectEvent += ExportProject;
                }
+
+               public static void AddVideoFile (Project project)
+               {
+                       string videofile;
+                       IGUIToolkit guiToolkit = Config.GUIToolkit;
+                       IMultimediaToolkit multimediaToolkit = Config.MultimediaToolkit;
+
+                       guiToolkit.InfoMessage (Catalog.GetString ("This project doesn't have any file 
associated.\n" +
+                                                                  "Select one in the next window"));
+                       videofile = guiToolkit.OpenFile (Catalog.GetString ("Select a video file"), null,
+                                                        Config.HomeDir, null, null);
+                       if (videofile == null) {
+                               guiToolkit.ErrorMessage (Catalog.GetString ("Could not import project, you 
need a video file"));
+                               return;
+                       }
+                       else {
+                               try {
+                                       project.Description.File = multimediaToolkit.DiscoverFile (videofile);
+                               }
+                               catch (Exception ex) {
+                                       guiToolkit.ErrorMessage (ex.Message);
+                                       return;
+                               }
+                               CreateThumbnails (project, guiToolkit, multimediaToolkit.GetFramesCapturer 
());
+                       }
+               }
                
+               public static void CreateThumbnails(Project project, IGUIToolkit guiToolkit, IFramesCapturer 
capturer) {
+                       IBusyDialog dialog;
+
+                       dialog = guiToolkit.BusyDialog(Catalog.GetString("Creating video thumbnails. This can 
take a while."));
+                       dialog.Show();
+                       dialog.Pulse();
+
+                       /* Create all the thumbnails */
+                       capturer.Open(project.Description.File.FilePath);
+                       foreach(Play play in project.Timeline) {
+                               try {
+                                       capturer.Seek (play.Start + ((play.Stop - play.Start) / 2),
+                                                         true);
+                                       play.Miniature = capturer.GetCurrentFrame (
+                                               Constants.MAX_THUMBNAIL_SIZE,
+                                               Constants.MAX_THUMBNAIL_SIZE);
+                                       dialog.Pulse();
+
+                               } catch (Exception ex) {
+                                       Log.Exception(ex);
+                               }
+                       }
+                       capturer.Dispose();
+                       dialog.Destroy();
+               }
+
                void ExportProject (Project project) {
                        if (project == null) {
                                Log.Warning("Opened project is null and can't be exported");
@@ -113,24 +165,7 @@ namespace LongoMatch.Services {
                        }
 
                        if (requiresNewFile) {
-                               string videofile;
-                               
-                               guiToolkit.InfoMessage (Catalog.GetString ("This project doesn't have any 
file associated.\n" +
-                                                                          "Select one in the next window"));
-                               videofile = guiToolkit.OpenFile (Catalog.GetString ("Select a video file"), 
null,
-                                                                Config.HomeDir, null, null);
-                               if (videofile == null) {
-                                       guiToolkit.ErrorMessage (Catalog.GetString ("Could not import 
project, you need a video file"));
-                                       return;
-                               } else {
-                                       try {
-                                               project.Description.File = multimediaToolkit.DiscoverFile 
(videofile);
-                                       } catch (Exception ex) {
-                                               guiToolkit.ErrorMessage (ex.Message);
-                                               return;
-                                       }
-                                       CreateThumbnails (project, guiToolkit, 
multimediaToolkit.GetFramesCapturer());
-                               }
+                               AddVideoFile (project);
                        }
                        
                        /* If the project exists ask if we want to overwrite it */
@@ -147,31 +182,6 @@ namespace LongoMatch.Services {
                        guiToolkit.InfoMessage(Catalog.GetString("Project successfully imported."));
                }
                
-               public static void CreateThumbnails(Project project, IGUIToolkit guiToolkit, IFramesCapturer 
capturer) {
-                       IBusyDialog dialog;
-
-                       dialog = guiToolkit.BusyDialog(Catalog.GetString("Creating video thumbnails. This can 
take a while."));
-                       dialog.Show();
-                       dialog.Pulse();
-
-                       /* Create all the thumbnails */
-                       capturer.Open(project.Description.File.FilePath);
-                       foreach(Play play in project.Timeline) {
-                               try {
-                                       capturer.Seek (play.Start + ((play.Stop - play.Start) / 2),
-                                                         true);
-                                       play.Miniature = capturer.GetCurrentFrame (
-                                               Constants.MAX_THUMBNAIL_SIZE,
-                                               Constants.MAX_THUMBNAIL_SIZE);
-                                       dialog.Pulse();
-
-                               } catch (Exception ex) {
-                                       Log.Exception(ex);
-                               }
-                       }
-                       capturer.Dispose();
-                       dialog.Destroy();
-               }
        }
 }
 


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