Use Film/Playlist for SPL management rather than special classes.
[dcpomatic.git] / src / wx / wx_util.cc
index 7edcabf40e379305d1c336f8e3702610d438d15f..98d69e0db1a1082f1b169042b2b94a83d2c3a31c 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 #include "wx_util.h"
 #include "file_picker_ctrl.h"
 #include "lib/config.h"
+#include "lib/job_manager.h"
 #include "lib/util.h"
 #include "lib/cross.h"
+#include "lib/job.h"
 #include <dcp/locale_convert.h>
 #include <wx/spinctrl.h>
 #include <wx/splash.h>
+#include <wx/progdlg.h>
+#include <wx/filepicker.h>
 #include <boost/thread.hpp>
 
-using namespace std;
-using namespace boost;
+using std::string;
+using std::vector;
+using std::pair;
+using boost::shared_ptr;
+using boost::optional;
 using dcp::locale_convert;
 
 wxStaticText *
@@ -129,7 +136,9 @@ error_dialog (wxWindow* parent, wxString m, optional<wxString> e)
 {
        wxMessageDialog* d = new wxMessageDialog (parent, m, _("DCP-o-matic"), wxOK | wxICON_ERROR);
        if (e) {
-               d->SetExtendedMessage (*e);
+               wxString em = *e;
+               em[0] = wxToupper (em[0]);
+               d->SetExtendedMessage (em);
        }
        d->ShowModal ();
        d->Destroy ();
@@ -195,6 +204,20 @@ checked_set (FilePickerCtrl* widget, boost::filesystem::path value)
        }
 }
 
+void
+checked_set (wxDirPickerCtrl* widget, boost::filesystem::path value)
+{
+       if (widget->GetPath() != std_to_wx (value.string())) {
+               if (value.empty()) {
+                       /* Hack to make wxWidgets clear the control when we are passed
+                          an empty value.
+                       */
+                       value = " ";
+               }
+               widget->SetPath (std_to_wx (value.string()));
+       }
+}
+
 void
 checked_set (wxSpinCtrl* widget, int value)
 {
@@ -446,12 +469,6 @@ maybe_show_splash ()
        return splash;
 }
 
-boost::filesystem::path
-path_from_file_dialog (wxFileDialog* dialog, string extension)
-{
-       return boost::filesystem::path(wx_to_std(dialog->GetPath())).replace_extension(extension);
-}
-
 double
 calculate_mark_interval (double mark_interval)
 {
@@ -474,3 +491,45 @@ calculate_mark_interval (double mark_interval)
 
        return mark_interval;
 }
+
+
+/** @return false if the task was cancelled */
+bool
+display_progress (wxString title, wxString task)
+{
+       JobManager* jm = JobManager::instance ();
+
+       wxProgressDialog progress (title, task, 100, 0, wxPD_CAN_ABORT);
+
+       bool ok = true;
+
+       while (jm->work_to_do()) {
+               dcpomatic_sleep (1);
+               if (!progress.Pulse()) {
+                       /* user pressed cancel */
+                       BOOST_FOREACH (shared_ptr<Job> i, jm->get()) {
+                               i->cancel();
+                       }
+                       ok = false;
+                       break;
+               }
+       }
+
+       return ok;
+}
+
+bool
+report_errors_from_last_job (wxWindow* parent)
+{
+       JobManager* jm = JobManager::instance ();
+
+       DCPOMATIC_ASSERT (!jm->get().empty());
+
+       shared_ptr<Job> last = jm->get().back();
+       if (last->finished_in_error()) {
+               error_dialog(parent, std_to_wx(last->error_summary()) + ".\n", std_to_wx(last->error_details()));
+               return false;
+       }
+
+       return true;
+}