[longomatch] Refactor to clean up MainWindow
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Refactor to clean up MainWindow
- Date: Thu, 25 Mar 2010 20:49:34 +0000 (UTC)
commit 09ae6fd47226ddc99e345d7b85378e837724c0ec
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Mon Mar 15 22:36:12 2010 +0100
Refactor to clean up MainWindow
LongoMatch/Common/Constants.cs | 4 +
LongoMatch/Gui/Dialog/ProjectsManager.cs | 12 +-
LongoMatch/Gui/MainWindow.cs | 454 +++++++++---------------------
LongoMatch/LongoMatch.mdp | 2 +
LongoMatch/Makefile.am | 3 +-
LongoMatch/Utils/ProjectUtils.cs | 269 ++++++++++++++++++
6 files changed, 415 insertions(+), 329 deletions(-)
---
diff --git a/LongoMatch/Common/Constants.cs b/LongoMatch/Common/Constants.cs
index 32f5d1a..be085be 100644
--- a/LongoMatch/Common/Constants.cs
+++ b/LongoMatch/Common/Constants.cs
@@ -29,6 +29,10 @@ namespace LongoMatch.Common
Mario Blättermann (de)
Pavel Bárta (cs)
Matej UrbanÄ?iÄ? (sl)";
+
+ public const int THUMBNAIL_MAX_WIDTH = 100;
+
+ public const int THUMBNAIL_MAX_HEIGHT = 100;
}
diff --git a/LongoMatch/Gui/Dialog/ProjectsManager.cs b/LongoMatch/Gui/Dialog/ProjectsManager.cs
index e1a7ad6..9675213 100644
--- a/LongoMatch/Gui/Dialog/ProjectsManager.cs
+++ b/LongoMatch/Gui/Dialog/ProjectsManager.cs
@@ -34,11 +34,13 @@ namespace LongoMatch.Gui.Dialog
public partial class ProjectsManager : Gtk.Dialog
{
- private string originalFilePath;
+ private string originalFilePath;
+ private Project openedProject;
- public ProjectsManager()
+ public ProjectsManager(Project openedProject)
{
- this.Build();
+ this.Build();
+ this.openedProject = openedProject;
this.Fill();
this.projectdetails.Use = ProjectType.EditProject;
projectdetails.Edited = false;
@@ -95,7 +97,7 @@ namespace LongoMatch.Gui.Dialog
{
ProjectDescription selectedProject = projectlistwidget1.GetSelection();
if (selectedProject != null) {
- if (MainWindow.OpenedProject() != null &&selectedProject.File == MainWindow.OpenedProject().File.FilePath) {
+ if (openedProject != null && selectedProject.File == openedProject.File.FilePath) {
MessagePopup.PopupMessage(this, MessageType.Warning,
Catalog.GetString("This Project is actually in use.")+"\n"+
Catalog.GetString("Close it first to allow its removal from the database"));
@@ -138,7 +140,7 @@ namespace LongoMatch.Gui.Dialog
PromptToSaveEditedProject();
}
- if (MainWindow.OpenedProject() != null && project.File == MainWindow.OpenedProject().File.FilePath) {
+ if (openedProject != null && project.File == openedProject.File.FilePath) {
MessagePopup.PopupMessage(this, MessageType.Warning,
Catalog.GetString("The Project you are trying to load is actually in use.")+"\n" +Catalog.GetString("Close it first to edit it"));
diff --git a/LongoMatch/Gui/MainWindow.cs b/LongoMatch/Gui/MainWindow.cs
index c6b06e9..af2bee2 100644
--- a/LongoMatch/Gui/MainWindow.cs
+++ b/LongoMatch/Gui/MainWindow.cs
@@ -35,6 +35,7 @@ using LongoMatch.Video.Capturer;
using LongoMatch.Video.Player;
using LongoMatch.Video.Utils;
using LongoMatch.Updates;
+using LongoMatch.Utils;
using LongoMatch.IO;
using LongoMatch.Handlers;
using System.Reflection;
@@ -105,8 +106,6 @@ namespace LongoMatch.Gui
}
#endregion
-
-
#region Private Methods
private void SetProject(Project project, ProjectType projectType) {
@@ -120,10 +119,10 @@ namespace LongoMatch.Gui
// Check if the file associated to the project exists
if (!File.Exists(project.File.FilePath)) {
MessagePopup.PopupMessage(this, MessageType.Warning,
- Catalog.GetString("The file associated to this project doesn't exist.")+"\n"+Catalog.GetString("If the location of the file has changed try to edit it with the database manager."));
+ Catalog.GetString("The file associated to this project doesn't exist.")+"\n"
+ +Catalog.GetString("If the location of the file has changed try to edit it with the database manager."));
CloseOpenedProject(true);
- }
- else {
+ } else {
Title = System.IO.Path.GetFileNameWithoutExtension(project.File.FilePath) + " - LongoMatch";
try {
playerbin1.Open(project.File.FilePath);
@@ -188,8 +187,7 @@ namespace LongoMatch.Gui
eManager.Capturer = null;
if (capturerBin != null)
capturerBin.Destroy();
- }
- else {
+ } else {
playerbin1.Close();
playerbin1.LogoMode = true;
}
@@ -249,9 +247,9 @@ namespace LongoMatch.Gui
private void SaveProject() {
if (openedProject != null && projectType == ProjectType.NewFileProject) {
- MainClass.DB.UpdateProject(OpenedProject());
+ MainClass.DB.UpdateProject(openedProject);
} else if (projectType == ProjectType.NewFakeCaptureProject)
- SaveFakeLiveProject(openedProject);
+ ProjectUtils.SaveFakeLiveProject(openedProject, this);
}
private bool PromptCloseProject(){
@@ -273,77 +271,40 @@ namespace LongoMatch.Gui
if (res == (int)EndCaptureResponse.Quit){
CloseOpenedProject(false);
return true;
- }
- /* Close and save project */
- else if (res == (int)EndCaptureResponse.Save){
+ } else if (res == (int)EndCaptureResponse.Save){
+ /* Close and save project */
CloseOpenedProject(true);
return true;
- }
- else
+ } else
/* Continue with the current project */
return false;
}
- private void SaveFakeLiveProject(Project project){
- MessageDialog md = new MessageDialog((Gtk.Window)this.Toplevel, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok,
- Catalog.GetString("The project will be saved to a file. You can insert it later into the database using the "+
- "\"Import project\" function once you copied the video file to your computer"));
- if (md.Run() == (int)ResponseType.Cancel){
- md.Destroy();
+ private void CloseAndQuit(){
+ if (!PromptCloseProject())
return;
- }else
- md.Destroy();
-
- FileChooserDialog fChooser = new FileChooserDialog(Catalog.GetString("Save Project"),
- (Gtk.Window)Toplevel,
- FileChooserAction.Save,
- "gtk-cancel",ResponseType.Cancel,
- "gtk-save",ResponseType.Accept);
- fChooser.SetCurrentFolder(MainClass.HomeDir());
- FileFilter filter = new FileFilter();
- filter.Name = "LongoMatch Project";
- filter.AddPattern("*.lpr");
-
- fChooser.AddFilter(filter);
- if (fChooser.Run() == (int)ResponseType.Accept) {
- Project.Export(project, fChooser.Filename);
- MessagePopup.PopupMessage(this.Toplevel, MessageType.Info,
- Catalog.GetString("Project saved successfully."));
- }
- fChooser.Destroy();
- }
-
- #endregion
-
- #region Public Methods
- public static Project OpenedProject() {
- return openedProject;
- }
-
- #endregion
-
- #region Callbacks
-
- protected virtual void OnUnrealized(object sender, System.EventArgs e) {
- Destroy();
+ playlistwidget2.StopEdition();
+ SaveProject();
+ playerbin1.Dispose();
Application.Quit();
}
+ #endregion
-
- protected virtual void OnSectionsTemplatesManagerActivated(object sender, System.EventArgs e)
- {
- TemplatesManager tManager = new TemplatesManager(TemplatesManager.UseType.SectionsTemplate);
- tManager.TransientFor = this;
- tManager.Show();
- }
-
- protected virtual void OnTeamsTemplatesManagerActionActivated(object sender, System.EventArgs e)
+ #region Callbacks
+ #region File
+ protected virtual void OnNewActivated(object sender, System.EventArgs e)
{
- TemplatesManager tManager = new TemplatesManager(TemplatesManager.UseType.TeamTemplate);
- tManager.TransientFor = this;
- tManager.Show();
+ Project project;
+ ProjectType projectType;
+
+ if (!PromptCloseProject())
+ return;
+
+ ProjectUtils.CreateNewProject(this, out project, out projectType);
+ if (project != null)
+ SetProject(project, projectType);
}
-
+
protected virtual void OnOpenActivated(object sender, System.EventArgs e)
{
if (!PromptCloseProject())
@@ -359,56 +320,12 @@ namespace LongoMatch.Gui
if (project != null)
SetProject(MainClass.DB.GetProject(project.File), ProjectType.NewFileProject);
}
-
- protected virtual void OnNewActivated(object sender, System.EventArgs e)
+
+ protected virtual void OnSaveProjectActionActivated(object sender, System.EventArgs e)
{
- Project project;
- ProjectType type;
- ProjectSelectionDialog psd;
- NewProjectDialog npd;
-
- if (!PromptCloseProject())
- return;
-
- // Show the project selection dialog
- psd = new ProjectSelectionDialog();
- psd.TransientFor = this;
- if (psd.Run() != (int)ResponseType.Ok){
- psd.Destroy();
- return;
- }
- type = psd.Type;
- psd.Destroy();
-
- // Show the new project dialog and wait the get a valid project or for the
- // the user cancelling the creation of a new project;
- npd = new NewProjectDialog();
- npd.TransientFor = this;
- npd.Use = type;
- int response = npd.Run();
- while (response == (int)ResponseType.Ok && npd.Project == null) {
- MessagePopup.PopupMessage(this, MessageType.Info,
- Catalog.GetString("Please, select a video file."));
- response=npd.Run();
- }
- npd.Destroy();
- // Si se cumplen las condiciones y se ha pulsado el botón aceptar continuamos
- if (response ==(int)ResponseType.Ok) {
- project = npd.Project;
- if (type == ProjectType.NewFileProject) {
- try {
- MainClass.DB.AddProject(project);
- }
- catch {
- MessagePopup.PopupMessage(this, MessageType.Error,
- Catalog.GetString("This file is already used in a Project.")+"\n"+Catalog.GetString("Open the project, please."));
- return;
- }
- }
- SetProject(project, type);
- }
+ SaveProject();
}
-
+
protected virtual void OnCloseActivated(object sender, System.EventArgs e)
{
PromptCloseProject();
@@ -416,113 +333,47 @@ namespace LongoMatch.Gui
protected virtual void OnImportProjectActionActivated (object sender, System.EventArgs e)
{
- NewProjectDialog npd=null;
- FileChooserDialog fChooser = new FileChooserDialog(Catalog.GetString("Import Project"),
- (Gtk.Window)Toplevel,
- FileChooserAction.Open,
- "gtk-cancel",ResponseType.Cancel,
- "gtk-open",ResponseType.Accept);
- fChooser.SetCurrentFolder(MainClass.HomeDir());
- FileFilter filter = new FileFilter();
- filter.Name = "LongoMatch Project";
- filter.AddPattern("*.lpr");
-
- fChooser.AddFilter(filter);
- if (fChooser.Run() == (int)ResponseType.Accept) {
- Project project;
- string fileName = fChooser.Filename;
- fChooser.Destroy();
- try{
- project = Project.Import(fileName);
- }
- catch (Exception ex){
- MessagePopup.PopupMessage(this, MessageType.Error, ex.Message);
- return;
- }
- // If it's a fake live project prompt for a video file and
- // create a new PreviewMediaFile for this project
- if (project.File.FilePath == Constants.FAKE_PROJECT){
- project.File = null;
- npd = new NewProjectDialog();
- npd.TransientFor = this;
- npd.Use = ProjectType.EditProject;
- npd.Project = project;
- int response = npd.Run();
- while (response == (int)ResponseType.Ok && npd.Project == null) {
- MessagePopup.PopupMessage(this, MessageType.Info,
- Catalog.GetString("Please, select a video file."));
- response=npd.Run();
- }
- if (response ==(int)ResponseType.Ok) {
- project = npd.Project;
- npd.Destroy();
- } else {
- npd.Destroy();
- return;
- }
- }
- // Try to add the project to the database and warn if a project
- // already exists in the database with the same file path
- if (!MainClass.DB.Exists(project)){
- MainClass.DB.AddProject(project);
- MessagePopup.PopupMessage(this, MessageType.Info,
- Catalog.GetString("Project successfully imported."));
- }
- else{
- MessageDialog md = new MessageDialog((Gtk.Window)this.Toplevel,
- DialogFlags.Modal,
- MessageType.Question,
- Gtk.ButtonsType.YesNo,
- Catalog.GetString("A project already exists for the file:")+project.File.FilePath+
- "\n"+Catalog.GetString("Do you want to overwrite it?"));
- md.Icon=Stetic.IconLoader.LoadIcon(this, "longomatch", Gtk.IconSize.Dialog, 48);
- if (md.Run() == (int)ResponseType.Yes){
- MainClass.DB.UpdateProject(project);
- }
- md.Destroy();
-
- }
- } else
- fChooser.Destroy();
+ ProjectUtils.ImportProject(this);
}
-
+
+ protected virtual void OnQuitActivated(object sender, System.EventArgs e)
+ {
+ CloseAndQuit();
+ }
+ #endregion
+ #region Tools
protected virtual void OnDatabaseManagerActivated(object sender, System.EventArgs e)
{
- ProjectsManager pm = new ProjectsManager();
+ ProjectsManager pm = new ProjectsManager(openedProject);
pm.TransientFor = this;
pm.Show();
}
-
- protected virtual void OnTimeprecisionadjustwidget1SizeRequested(object o, Gtk.SizeRequestedArgs args)
+
+ protected virtual void OnSectionsTemplatesManagerActivated(object sender, System.EventArgs e)
{
- if (args.Requisition.Width>= hpaned.Position)
- hpaned.Position = args.Requisition.Width;
+ TemplatesManager tManager = new TemplatesManager(TemplatesManager.UseType.SectionsTemplate);
+ tManager.TransientFor = this;
+ tManager.Show();
}
- protected virtual void OnDeleteEvent(object o, Gtk.DeleteEventArgs args)
+ protected virtual void OnTeamsTemplatesManagerActionActivated(object sender, System.EventArgs e)
{
- if (!PromptCloseProject())
- return;
- playlistwidget2.StopEdition();
- SaveProject();
- // We never know...
- System.Threading.Thread.Sleep(1000);
- playerbin1.Dispose();
- Application.Quit();
+ TemplatesManager tManager = new TemplatesManager(TemplatesManager.UseType.TeamTemplate);
+ tManager.TransientFor = this;
+ tManager.Show();
}
-
- protected virtual void OnQuitActivated(object sender, System.EventArgs e)
+
+ protected virtual void OnExportProjectToCSVFileActionActivated(object sender, System.EventArgs e)
{
- if (!PromptCloseProject())
- return;
- playlistwidget2.StopEdition();
- SaveProject();
- // We never know...
- System.Threading.Thread.Sleep(1000);
- playerbin1.Dispose();
- Application.Quit();
+ ProjectUtils.ExportToCSV(this, openedProject);
}
-
+ #endregion
+ #region View
+ protected virtual void OnFullScreenActionToggled(object sender, System.EventArgs e)
+ {
+ playerbin1.FullScreen = ((Gtk.ToggleAction)sender).Active;
+ }
+
protected virtual void OnPlaylistActionToggled(object sender, System.EventArgs e)
{
bool visible = ((Gtk.ToggleAction)sender).Active;
@@ -537,37 +388,21 @@ namespace LongoMatch.Gui
else if (visible) {
rightvbox.Visible = true;
}
- }
-
- protected virtual void OnOpenPlaylistActionActivated(object sender, System.EventArgs e)
+ }
+
+ protected virtual void OnHideAllWidgetsActionToggled(object sender, System.EventArgs e)
{
- FileChooserDialog fChooser = new FileChooserDialog(Catalog.GetString("Open playlist"),
- (Gtk.Window)Toplevel,
- FileChooserAction.Open,
- "gtk-cancel",ResponseType.Cancel,
- "gtk-open",ResponseType.Accept);
- fChooser.SetCurrentFolder(MainClass.PlayListDir());
- FileFilter filter = new FileFilter();
- filter.Name = "LGM playlist";
- filter.AddPattern("*.lgm");
-
- fChooser.AddFilter(filter);
- if (fChooser.Run() == (int)ResponseType.Accept) {
- if (openedProject != null)
- CloseOpenedProject(true);
- playlistwidget2.Load(fChooser.Filename);
- PlaylistAction.Active = true;
+ if (openedProject != null) {
+ leftbox.Visible = !((Gtk.ToggleAction)sender).Active;
+ timelinewidget1.Visible = !((Gtk.ToggleAction)sender).Active && AnalyzeModeAction.Active;
+ buttonswidget1.Visible = !((Gtk.ToggleAction)sender).Active && CaptureModeAction.Active;
+ if (((Gtk.ToggleAction)sender).Active)
+ rightvbox.Visible = false;
+ else if (!((Gtk.ToggleAction)sender).Active && (playlistwidget2.Visible || noteswidget1.Visible))
+ rightvbox.Visible = true;
}
- fChooser.Destroy();
- }
-
- protected virtual void OnPlayerbin1Error(object o,LongoMatch.Video.Handlers.ErrorArgs args)
- {
- MessagePopup.PopupMessage(this, MessageType.Info,
- Catalog.GetString("The actual project will be closed due to an error in the media player:")+"\n" +args.Message);
- CloseOpenedProject(true);
}
-
+
protected virtual void OnCaptureModeActionToggled(object sender, System.EventArgs e)
{
if (((Gtk.ToggleAction)sender).Active) {
@@ -578,55 +413,16 @@ namespace LongoMatch.Gui
buttonswidget1.Hide();
timelinewidget1.Show();
}
- }
-
- protected virtual void OnFullScreenActionToggled(object sender, System.EventArgs e)
- {
- playerbin1.FullScreen = ((Gtk.ToggleAction)sender).Active;
- }
-
- protected virtual void OnSaveProjectActionActivated(object sender, System.EventArgs e)
- {
- SaveProject();
- }
-
- protected override bool OnKeyPressEvent(EventKey evnt)
- {
- if (openedProject != null && evnt.State == ModifierType.None) {
- Gdk.Key key = evnt.Key;
- if (key == Gdk.Key.z)
- playerbin1.SeekToPreviousFrame(selectedTimeNode != null);
- if (key == Gdk.Key.x)
- playerbin1.SeekToNextFrame(selectedTimeNode != null);
- }
- return base.OnKeyPressEvent(evnt);
- }
-
- protected virtual void OnTimeNodeSelected(LongoMatch.TimeNodes.MediaTimeNode tNode)
- {
- rightvbox.Visible=true;
- }
-
- protected virtual void OnSegmentClosedEvent()
- {
- if (!playlistwidget2.Visible)
- rightvbox.Visible=false;
- }
-
- protected virtual void OnUpdate(Version version, string URL) {
- LongoMatch.Gui.Dialog.UpdateDialog updater = new LongoMatch.Gui.Dialog.UpdateDialog();
- updater.Fill(version, URL);
- updater.TransientFor = this;
- updater.Run();
- updater.Destroy();
- }
-
- protected virtual void OnDrawingToolActionToggled(object sender, System.EventArgs e)
+ }
+ #endregion
+ #region Help
+ protected virtual void OnHelpAction1Activated(object sender, System.EventArgs e)
{
- drawingtoolbox1.Visible = DrawingToolAction.Active;
- drawingtoolbox1.DrawingVisibility = DrawingToolAction.Active;
+ try {
+ System.Diagnostics.Process.Start("http://www.longomatch.ylatuya.es/documentation/manual.html");
+ } catch {}
}
-
+
protected virtual void OnAboutActionActivated(object sender, System.EventArgs e)
{
Version version = Assembly.GetExecutingAssembly().GetName().Version;
@@ -648,7 +444,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.";
about.Authors = new string[] {"Andoni Morales Alastruey"};
about.Artists = new string[] {"Bencomo González Marrero"};
- about.TranslatorCredits = Constants.TRANSLATORS;
+ about.TranslatorCredits = Constants.TRANSLATORS;
about.TransientFor = this;
Gtk.AboutDialog.SetUrlHook(delegate(AboutDialog dialog,string url) {
try {
@@ -659,54 +455,66 @@ GNU General Public License for more details.";
about.Destroy();
}
+ #endregion
- protected virtual void OnExportProjectToCSVFileActionActivated(object sender, System.EventArgs e)
+ protected virtual void OnTimeprecisionadjustwidget1SizeRequested(object o, Gtk.SizeRequestedArgs args)
{
- FileChooserDialog fChooser = new FileChooserDialog(Catalog.GetString("Select Export File"),
- (Gtk.Window)Toplevel,
- FileChooserAction.Save,
- "gtk-cancel",ResponseType.Cancel,
- "gtk-save",ResponseType.Accept);
- fChooser.SetCurrentFolder(MainClass.HomeDir());
- fChooser.DoOverwriteConfirmation = true;
- FileFilter filter = new FileFilter();
- filter.Name = "CSV File";
- filter.AddPattern("*.csv");
- fChooser.AddFilter(filter);
- if (fChooser.Run() == (int)ResponseType.Accept) {
- string outputFile=fChooser.Filename;
- outputFile = System.IO.Path.ChangeExtension(outputFile,"csv");
- CSVExport export = new CSVExport(openedProject, outputFile);
- export.WriteToFile();
- }
- fChooser.Destroy();
+ if (args.Requisition.Width>= hpaned.Position)
+ hpaned.Position = args.Requisition.Width;
+ }
+ protected virtual void OnPlayerbin1Error(object o,LongoMatch.Video.Handlers.ErrorArgs args)
+ {
+ MessagePopup.PopupMessage(this, MessageType.Info,
+ Catalog.GetString("The actual project will be closed due to an error in the media player:")+"\n" +args.Message);
+ CloseOpenedProject(true);
}
- protected override bool OnConfigureEvent(Gdk.EventConfigure evnt)
+ protected override bool OnKeyPressEvent(EventKey evnt)
{
- return base.OnConfigureEvent(evnt);
+ if (openedProject != null && evnt.State == ModifierType.None) {
+ Gdk.Key key = evnt.Key;
+ if (key == Gdk.Key.z)
+ playerbin1.SeekToPreviousFrame(selectedTimeNode != null);
+ if (key == Gdk.Key.x)
+ playerbin1.SeekToNextFrame(selectedTimeNode != null);
+ }
+ return base.OnKeyPressEvent(evnt);
}
- protected virtual void OnHideAllWidgetsActionToggled(object sender, System.EventArgs e)
+ protected virtual void OnTimeNodeSelected(LongoMatch.TimeNodes.MediaTimeNode tNode)
{
- if (openedProject != null) {
- leftbox.Visible = !((Gtk.ToggleAction)sender).Active;
- timelinewidget1.Visible = !((Gtk.ToggleAction)sender).Active && AnalyzeModeAction.Active;
- buttonswidget1.Visible = !((Gtk.ToggleAction)sender).Active && CaptureModeAction.Active;
- if (((Gtk.ToggleAction)sender).Active)
- rightvbox.Visible = false;
- else if (!((Gtk.ToggleAction)sender).Active && (playlistwidget2.Visible || noteswidget1.Visible))
- rightvbox.Visible = true;
- }
+ rightvbox.Visible=true;
}
- protected virtual void OnHelpAction1Activated(object sender, System.EventArgs e)
+
+ protected virtual void OnSegmentClosedEvent()
{
- try {
- System.Diagnostics.Process.Start("http://www.longomatch.ylatuya.es/documentation/manual.html");
- } catch {}
+ if (!playlistwidget2.Visible)
+ rightvbox.Visible=false;
+ }
+
+ protected virtual void OnUpdate(Version version, string URL) {
+ LongoMatch.Gui.Dialog.UpdateDialog updater = new LongoMatch.Gui.Dialog.UpdateDialog();
+ updater.Fill(version, URL);
+ updater.TransientFor = this;
+ updater.Run();
+ updater.Destroy();
}
- #endregion}
+ protected virtual void OnDrawingToolActionToggled(object sender, System.EventArgs e)
+ {
+ drawingtoolbox1.Visible = DrawingToolAction.Active;
+ drawingtoolbox1.DrawingVisibility = DrawingToolAction.Active;
+ }
+
+ protected virtual void OnUnrealized(object sender, System.EventArgs e) {
+ CloseAndQuit();
+ }
+
+ protected virtual void OnDeleteEvent(object o, Gtk.DeleteEventArgs args)
+ {
+ CloseAndQuit();
+ }
+ #endregion
}
-}
+}
\ No newline at end of file
diff --git a/LongoMatch/LongoMatch.mdp b/LongoMatch/LongoMatch.mdp
index 6a8da4f..177552e 100644
--- a/LongoMatch/LongoMatch.mdp
+++ b/LongoMatch/LongoMatch.mdp
@@ -181,6 +181,8 @@
<File name="Gui/Dialog/ProjectSelectionDialog.cs" subtype="Code" buildaction="Compile" />
<File name="Gui/Dialog/EndCaptureDialog.cs" subtype="Code" buildaction="Compile" />
<File name="gtk-gui/LongoMatch.Gui.Dialog.EndCaptureDialog.cs" subtype="Code" buildaction="Compile" />
+ <File name="Utils" subtype="Directory" buildaction="Compile" />
+ <File name="Utils/ProjectUtils.cs" subtype="Code" buildaction="Compile" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
diff --git a/LongoMatch/Makefile.am b/LongoMatch/Makefile.am
index c37191e..679028a 100644
--- a/LongoMatch/Makefile.am
+++ b/LongoMatch/Makefile.am
@@ -215,7 +215,8 @@ FILES = \
Time/Time.cs \
Time/TimeNode.cs \
Updates/Updater.cs \
- Updates/XmlUpdateParser.cs
+ Updates/XmlUpdateParser.cs \
+ Utils/ProjectUtils.cs
DATA_FILES =
diff --git a/LongoMatch/Utils/ProjectUtils.cs b/LongoMatch/Utils/ProjectUtils.cs
new file mode 100644
index 0000000..a8c4f5e
--- /dev/null
+++ b/LongoMatch/Utils/ProjectUtils.cs
@@ -0,0 +1,269 @@
+//
+// Copyright (C) 2010 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+
+using System;
+using System.Collections.Generic;
+using Gtk;
+using Mono.Unix;
+using LongoMatch.Common;
+using LongoMatch.DB;
+using LongoMatch.Gui;
+using LongoMatch.Gui.Dialog;
+using LongoMatch.IO;
+using LongoMatch.TimeNodes;
+using LongoMatch.Video;
+using LongoMatch.Video.Utils;
+
+namespace LongoMatch.Utils
+{
+
+
+ public class ProjectUtils
+ {
+
+ public static void SaveFakeLiveProject (Project project, Window window){
+ int response;
+ MessageDialog md = new MessageDialog(window, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok,
+ Catalog.GetString("The project will be saved to a file. You can insert it later into the database using the "+
+ "\"Import project\" function once you copied the video file to your computer"));
+ response = md.Run();
+ md.Destroy();
+ if (response == (int)ResponseType.Cancel)
+ return;
+
+ FileChooserDialog fChooser = new FileChooserDialog(Catalog.GetString("Save Project"),
+ window,
+ FileChooserAction.Save,
+ "gtk-cancel",ResponseType.Cancel,
+ "gtk-save",ResponseType.Accept);
+ fChooser.SetCurrentFolder(MainClass.HomeDir());
+ FileFilter filter = new FileFilter();
+ filter.Name = "LongoMatch Project";
+ filter.AddPattern("*.lpr");
+
+ fChooser.AddFilter(filter);
+ if (fChooser.Run() == (int)ResponseType.Accept) {
+ Project.Export(project, fChooser.Filename);
+ MessagePopup.PopupMessage(window, MessageType.Info,
+ Catalog.GetString("Project saved successfully."));
+ }
+ fChooser.Destroy();
+ }
+
+ public static void ImportProject(Window window){
+ Project project;
+ bool isFake, exists;
+ int res;
+ string fileName;
+ FileFilter filter;
+ NewProjectDialog npd;
+ FileChooserDialog fChooser;
+
+ /* Show a file chooser dialog to select the file to import */
+ fChooser = new FileChooserDialog(Catalog.GetString("Import Project"),
+ window,
+ FileChooserAction.Open,
+ "gtk-cancel",ResponseType.Cancel,
+ "gtk-open",ResponseType.Accept);
+ fChooser.SetCurrentFolder(MainClass.HomeDir());
+ filter = new FileFilter();
+ filter.Name = "LongoMatch Project";
+ filter.AddPattern("*.lpr");
+ fChooser.AddFilter(filter);
+
+
+ res = fChooser.Run();
+ fileName = fChooser.Filename;
+ fChooser.Destroy();
+ /* return if the user cancelled */
+ if (res != (int)ResponseType.Accept)
+ return;
+
+ /* try to import the project and show a message error is the file
+ * is not a valid project */
+ try{
+ project = Project.Import(fileName);
+ }
+ catch (Exception ex){
+ MessagePopup.PopupMessage(window, MessageType.Error,
+ Catalog.GetString("Error importing project:")+
+ "\n"+ex.Message);
+ return;
+ }
+
+ isFake = (project.File.FilePath == Constants.FAKE_PROJECT);
+
+ /* If it's a fake live project prompt for a video file and
+ * create a new PreviewMediaFile for this project */
+ if (isFake){
+ project.File = null;
+ npd = new NewProjectDialog();
+ npd.TransientFor = window;
+ npd.Use = ProjectType.EditProject;
+ npd.Project = project;
+ int response = npd.Run();
+ while (true){
+ if (response != (int)ResponseType.Ok){
+ npd.Destroy();
+ return;
+ } else if (npd.Project == null) {
+ MessagePopup.PopupMessage(window, MessageType.Info,
+ Catalog.GetString("Please, select a video file."));
+ response=npd.Run();
+ } else {
+ project = npd.Project;
+ npd.Destroy();
+ break;
+ }
+ }
+ }
+
+ /* If the project exists ask if we want to overwrite it */
+ if (MainClass.DB.Exists(project)){
+ MessageDialog md = new MessageDialog(window,
+ DialogFlags.Modal,
+ MessageType.Question,
+ Gtk.ButtonsType.YesNo,
+ Catalog.GetString("A project already exists for the file:")+project.File.FilePath+
+ "\n"+Catalog.GetString("Do you want to overwrite it?"));
+ md.Icon=Stetic.IconLoader.LoadIcon(window, "longomatch", Gtk.IconSize.Dialog, 48);
+ res = md.Run();
+ md.Destroy();
+ if (res != (int)ResponseType.Yes)
+ return;
+ exists = true;
+ } else
+ exists = false;
+
+ if (isFake)
+ CreateThumbnails(window, project);
+ if (exists)
+ MainClass.DB.UpdateProject(project);
+ else
+ MainClass.DB.AddProject(project);
+
+
+ MessagePopup.PopupMessage(window, MessageType.Info,
+ Catalog.GetString("Project successfully imported."));
+ }
+
+ public static void CreateNewProject(Window window, out Project project, out ProjectType projectType){
+ ProjectSelectionDialog psd;
+ NewProjectDialog npd;
+ int response;
+
+ /* The out parameters must be set before leaving the method */
+ project = null;
+ projectType = ProjectType.None;
+
+ /* Show the project selection dialog */
+ psd = new ProjectSelectionDialog();
+ psd.TransientFor = window;
+ response = psd.Run();
+ psd.Destroy();
+ if (response != (int)ResponseType.Ok)
+ return;
+ projectType = psd.Type;
+
+ /* Show the new project dialog and wait to get a valid project
+ * or quit if the user cancel it.*/
+ npd = new NewProjectDialog();
+ npd.TransientFor = window;
+ npd.Use = projectType;
+ response = npd.Run();
+ while (true) {
+ /* User cancelled: quit */
+ if (response != (int)ResponseType.Ok){
+ npd.Destroy();
+ return;
+ }
+ /* No file chosen: display the dialog again */
+ if (npd.Project == null)
+ MessagePopup.PopupMessage(window, MessageType.Info,
+ Catalog.GetString("Please, select a video file."));
+ /* If a project with the same file path exists show a warning */
+ else if (MainClass.DB.Exists(npd.Project))
+ MessagePopup.PopupMessage(window, MessageType.Error,
+ Catalog.GetString("This file is already used in another Project.")+"\n"+
+ Catalog.GetString("Select a different one to continue."));
+
+ else {
+ /* We are now ready to create the new project */
+ project = npd.Project;
+ npd.Destroy();
+ break;
+ }
+ response = npd.Run();
+ }
+ if (projectType == ProjectType.NewFileProject)
+ /* We can safelly add the project since we already checked if
+ * it can can added */
+ MainClass.DB.AddProject(project);
+ }
+
+ public static void ExportToCSV(Window window, Project project){
+ FileChooserDialog fChooser;
+ FileFilter filter;
+ string outputFile;
+ CSVExport export;
+
+ fChooser = new FileChooserDialog(Catalog.GetString("Select Export File"),
+ window,
+ FileChooserAction.Save,
+ "gtk-cancel",ResponseType.Cancel,
+ "gtk-save",ResponseType.Accept);
+ fChooser.SetCurrentFolder(MainClass.HomeDir());
+ fChooser.DoOverwriteConfirmation = true;
+ filter = new FileFilter();
+ filter.Name = "CSV File";
+ filter.AddPattern("*.csv");
+ fChooser.AddFilter(filter);
+ if (fChooser.Run() == (int)ResponseType.Accept) {
+ outputFile=fChooser.Filename;
+ outputFile = System.IO.Path.ChangeExtension(outputFile,"csv");
+ export = new CSVExport(project, outputFile);
+ export.WriteToFile();
+ }
+ fChooser.Destroy();
+ }
+
+ public static void CreateThumbnails(Project project){
+ MultimediaFactory factory;
+ IFramesCapturer capturer;
+
+ /* Create all the thumbnails */
+ factory = new MultimediaFactory();
+ capturer = factory.getFramesCapturer();
+ capturer.Open (project.File.FilePath);
+ foreach (List<MediaTimeNode> list in project.GetDataArray()){
+ foreach (MediaTimeNode play in list){
+ try{
+ capturer.SeekTime(play.Start.MSeconds + ((play.Stop - play.Start).MSeconds/2),
+ true);
+ play.Miniature = capturer.GetCurrentFrame(Constants.THUMBNAIL_MAX_WIDTH,
+ Constants.THUMBNAIL_MAX_HEIGHT);
+
+ } catch {
+ /* FIXME: Add log */
+ }
+ }
+ }
+ capturer.Dispose();
+ }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]