Basics of in-place i18n with support for wxStaticText and wxCheckBox.
[dcpomatic.git] / src / wx / wx_util.cc
index db63400315e899cb1488705dffa3dda15adad12d..354297d49549f17d522b9771482775db75beb879 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 "static_text.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 *
@@ -49,7 +56,7 @@ create_label (wxWindow* p, wxString t, bool)
                t += wxT (":");
        }
 #endif
-       return new wxStaticText (p, wxID_ANY, t);
+       return new StaticText (p, t);
 }
 
 /** Add a wxStaticText to a wxSizer, aligning it at vertical centre.
@@ -463,17 +470,6 @@ maybe_show_splash ()
        return splash;
 }
 
-optional<boost::filesystem::path>
-path_from_file_dialog (wxFileDialog* dialog, string extension)
-{
-       boost::filesystem::path p(wx_to_std(dialog->GetPath()));
-       p.replace_extension(extension);
-       if (boost::filesystem::is_regular_file(p) && !confirm_dialog(dialog, wxString::Format(_("A file named %s already exists.  Do you want to replace it?"), std_to_wx(p.filename().string())))) {
-               return optional<boost::filesystem::path>();
-       }
-       return p;
-}
-
 double
 calculate_mark_interval (double mark_interval)
 {
@@ -496,3 +492,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;
+}