Esempio n. 1
0
        public override async Task <bool> LoadState(dynamic data)
        {
            LMProjectVM projectVM = data.Project;

            // FIXME: Load project asynchronously
            if (!projectVM.Model.IsLoaded)
            {
                try {
                    IBusyDialog busy = App.Current.Dialogs.BusyDialog(Catalog.GetString("Loading project..."), null);
                    busy.ShowSync(() => {
                        try {
                            projectVM.Model.Load();
                        } catch (Exception ex) {
                            Log.Exception(ex);
                            throw;
                        }
                    });
                } catch (Exception ex) {
                    Log.Exception(ex);
                    App.Current.Dialogs.ErrorMessage(Catalog.GetString("Could not load project:") + "\n" + ex.Message);
                    return(false);
                }
            }

            if (!await Initialize(data))
            {
                return(false);
            }

            return(await LoadProject());
        }
        void SaveLoadedProject(bool force)
        {
            if (loadedProject != null)
            {
                bool save = edited;

                if (edited && !force)
                {
                    string msg = Catalog.GetString("Do you want to save the current project?");
                    if (!App.Current.Dialogs.QuestionMessage(msg, null, this).Result)
                    {
                        save = false;
                    }
                }
                if (save)
                {
                    try {
                        IBusyDialog busy = App.Current.Dialogs.BusyDialog(Catalog.GetString("Saving project..."), null);
                        busy.ShowSync(() => DB.Store <LMProject> (loadedProject));
                        projectlistwidget1.UpdateProject(loadedProject);
                        edited = false;
                    } catch (Exception ex) {
                        Log.Exception(ex);
                        App.Current.Dialogs.ErrorMessage(Catalog.GetString("Error saving project:") + "\n" + ex.Message);
                        return;
                    }
                }
            }
        }
Esempio n. 3
0
 protected virtual async Task <bool> Save(TViewModel project, bool force)
 {
     if (!project.Edited)
     {
         return(false);
     }
     if (!force)
     {
         string msg = Catalog.GetString("Do you want to save the current project?");
         if (!(await App.Current.Dialogs.QuestionMessage(msg, null, this)))
         {
             ViewModel.LoadedProject.FileSet.Model.MediaFiles.Reset(originalMediaFileSet.MediaFiles);
             return(false);
         }
     }
     try {
         IBusyDialog busy = App.Current.Dialogs.BusyDialog(Catalog.GetString("Saving project..."), null);
         busy.ShowSync(() => {
             project.CommitState();
             App.Current.DatabaseManager.ActiveDB.Store(project.Model);
             project.IsChanged       = false;
             project.Model.IsChanged = false;
         });
         ViewModel.SaveCommand.EmitCanExecuteChanged();
         return(true);
     } catch (Exception ex) {
         Log.Exception(ex);
         App.Current.Dialogs.ErrorMessage(Catalog.GetString("Error saving project:") + "\n" + ex.Message);
         return(false);
     }
 }
Esempio n. 4
0
        protected virtual async Task HandleDelete(DeleteEvent <TModel> evt)
        {
            TModel project = evt.Object;

            if (project == null)
            {
                return;
            }

            string msg = Catalog.GetString("Do you really want to delete:") + "\n" + project.ShortDescription;

            if (await App.Current.Dialogs.QuestionMessage(msg, null))
            {
                IBusyDialog busy    = App.Current.Dialogs.BusyDialog(Catalog.GetString("Deleting project..."), null);
                bool        success = true;
                busy.ShowSync(() => {
                    try {
                        App.Current.DatabaseManager.ActiveDB.Delete <TModel> (project);
                    } catch (StorageException ex) {
                        success = false;
                        App.Current.Dialogs.ErrorMessage(ex.Message);
                    }
                });
                if (success)
                {
                    ViewModel.Model.Remove(project);
                    ViewModel.Select(ViewModel.Model.FirstOrDefault());
                    evt.ReturnValue = true;
                }
            }
        }
Esempio n. 5
0
        public static MediaFile DiscoverFile(string filename, object parent)
        {
            MediaFile   mediaFile = null;
            IBusyDialog busy      = null;

            try {
                Exception ex = null;
                busy = Config.GUIToolkit.BusyDialog(Catalog.GetString("Analyzing video file:") + "\n" +
                                                    filename, parent);
                Task task = new Task(() => {
                    try {
                        mediaFile = Config.MultimediaToolkit.DiscoverFile(filename);
                    } catch (Exception e) {
                        ex = e;
                    }
                    Config.GUIToolkit.Invoke(delegate {
                        busy.Destroy();
                    });
                });
                task.Start();
                busy.ShowSync();

                if (ex != null)
                {
                    throw ex;
                }
                else if (mediaFile == null)
                {
                    throw new Exception(Catalog.GetString("Timeout parsing file."));
                }
                else if (!mediaFile.HasVideo || mediaFile.VideoCodec == "")
                {
                    throw new Exception(Catalog.GetString("This file doesn't contain a video stream."));
                }
                else if (mediaFile.HasVideo && mediaFile.Duration.MSeconds == 0)
                {
                    throw new Exception(Catalog.GetString("This file contains a video stream but its length is 0."));
                }
            } catch (Exception ex) {
                busy.Destroy();
                Config.GUIToolkit.ErrorMessage(ex.Message, parent);
                return(null);
            }
            return(mediaFile);
        }
        public Project ImportProject()
        {
            LMProject project = null;

            string filename = App.Current.Dialogs.OpenFile(Catalog.GetString("Import project"), null, App.Current.HomeDir,
                                                           FilterName, FilterExtensions);

            if (filename == null)
            {
                return(null);
            }

            IBusyDialog busy = App.Current.Dialogs.BusyDialog(Catalog.GetString("Importing project..."));

            busy.ShowSync(() => {
                project = Project.Import(filename) as LMProject;
            });
            return(project);
        }
Esempio n. 7
0
        public static MediaFile DiscoverFile(string filename, object parent)
        {
            MediaFile   mediaFile = null;
            IBusyDialog busy      = null;

            try {
                Exception ex = null;
                busy = App.Current.Dialogs.BusyDialog(Catalog.GetString("Analyzing video file:") + "\n" +
                                                      filename, parent);
                System.Action action = () => {
                    try {
                        mediaFile = App.Current.MultimediaToolkit.DiscoverFile(filename);
                    } catch (Exception e) {
                        ex = e;
                    }
                };
                busy.ShowSync(action);

                if (ex != null)
                {
                    throw ex;
                }
                else if (mediaFile == null)
                {
                    throw new Exception(Catalog.GetString("Timeout parsing file."));
                }
                else if (!mediaFile.HasVideo || mediaFile.VideoCodec == "")
                {
                    throw new Exception(Catalog.GetString("This file doesn't contain a video stream."));
                }
                else if (mediaFile.HasVideo && mediaFile.Duration.MSeconds == 0)
                {
                    throw new Exception(Catalog.GetString("This file contains a video stream but its length is 0."));
                }
            } catch (Exception ex) {
                busy.Destroy();
                App.Current.Dialogs.ErrorMessage(ex.Message, parent);
                return(null);
            }
            return(mediaFile);
        }
        void HandleDeleteClicked(object sender, EventArgs e)
        {
            List <LMProject> deletedProjects;

            if (selectedProjects == null)
            {
                return;
            }

            deletedProjects = new List <LMProject> ();
            foreach (LMProject selectedProject in selectedProjects)
            {
                string msg = Catalog.GetString("Do you really want to delete:") + "\n" +
                             selectedProject.Description.Title;
                if (Helpers.MessagesHelpers.QuestionMessage(this, msg))
                {
                    // Unload first
                    if (loadedProject != null && loadedProject.ID == selectedProject.ID)
                    {
                        loadedProject = null;
                    }
                    IBusyDialog busy = App.Current.Dialogs.BusyDialog(Catalog.GetString("Deleting project..."), null);
                    busy.ShowSync(() => {
                        try {
                            DB.Delete <LMProject> (selectedProject);
                        } catch (StorageException ex) {
                            App.Current.Dialogs.ErrorMessage(ex.Message);
                        }
                    });
                    deletedProjects.Add(selectedProject);
                }
            }
            projectlistwidget1.RemoveProjects(deletedProjects);

            // In the case where there are no projects left we need to clear the project desc widget
            if (DB.Count <LMProject> () == 0)
            {
                rbox.Visible = false;
            }
        }
Esempio n. 9
0
        void HandleRescanClicked(object sender, EventArgs e)
        {
            IDatabase db = SelectedDB;

            if (db != null)
            {
                IBusyDialog busy = Config.GUIToolkit.BusyDialog(Catalog.GetString("Scanning database..."), this);
                Task        task = new Task(() => {
                    try {
                        db.Reload();
                    } catch (Exception ex) {
                        Log.Exception(ex);
                    }
                    Config.GUIToolkit.Invoke(delegate {
                        busy.Destroy();
                    });
                });
                task.Start();
                busy.ShowSync();
                Config.GUIToolkit.InfoMessage(Catalog.GetString("Database scanned succesfully."));
            }
        }