Example #1
0
        private void CreateNewProject(out Project project, out ProjectType projectType,
                                      out CaptureSettings captureSettings)
        {
            ProjectSelectionDialog psd;
            NewProjectDialog       npd;
            List <Device>          devices = null;
            int response;

            Log.Debug("Creating new project");
            /* The out parameters must be set before leaving the method */
            project         = null;
            projectType     = ProjectType.None;
            captureSettings = new CaptureSettings();

            /* Show the project selection dialog */
            psd = new ProjectSelectionDialog();
            psd.TransientFor = mainWindow;
            response         = psd.Run();
            psd.Destroy();
            if (response != (int)ResponseType.Ok)
            {
                return;
            }
            projectType = psd.ProjectType;

            if (projectType == ProjectType.CaptureProject)
            {
                devices = VideoDevice.ListVideoDevices();
                if (devices.Count == 0)
                {
                    MessagePopup.PopupMessage(mainWindow, MessageType.Error,
                                              Catalog.GetString("No capture devices were found."));
                    return;
                }
            }

            /* Show the new project dialog and wait to get a valid project
             * or quit if the user cancel it.*/
            npd = new NewProjectDialog();
            npd.TransientFor     = mainWindow;
            npd.Use              = projectType;
            npd.TemplatesService = Core.TemplatesService;
            if (projectType == ProjectType.CaptureProject)
            {
                npd.Devices = devices;
            }
            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(mainWindow, MessageType.Info,
                                              Catalog.GetString("Please, select a video file."));
                }
                /* If a project with the same file path exists show a warning */
                else if (Core.DB.Exists(npd.Project))
                {
                    MessagePopup.PopupMessage(mainWindow, 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;
                    if (projectType == ProjectType.CaptureProject)
                    {
                        captureSettings = npd.CaptureSettings;
                    }
                    npd.Destroy();
                    break;
                }
                response = npd.Run();
            }
            if (projectType == ProjectType.FileProject)
            {
                /* We can safelly add the project since we already checked if
                 * it can can added */
                Core.DB.AddProject(project);
            }
        }