X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fwx_util.cc;h=98d69e0db1a1082f1b169042b2b94a83d2c3a31c;hb=fad8d13cd779a6237feed2c855a46e1a7c66e0ad;hp=7edcabf40e379305d1c336f8e3702610d438d15f;hpb=33a2c1355cc52372565835638bea0dab1e3f85a1;p=dcpomatic.git diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc index 7edcabf40..98d69e0db 100644 --- a/src/wx/wx_util.cc +++ b/src/wx/wx_util.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2016 Carl Hetherington + Copyright (C) 2012-2018 Carl Hetherington This file is part of DCP-o-matic. @@ -25,15 +25,22 @@ #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 #include #include +#include +#include #include -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 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 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 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; +}