2 Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <wx/aboutdlg.h>
21 #include <wx/stdpaths.h>
22 #include <wx/cmdline.h>
24 #include "lib/version.h"
25 #include "lib/compose.hpp"
26 #include "lib/config.h"
29 #include "lib/job_manager.h"
30 #include "wx/wx_util.h"
31 #include "wx/about_dialog.h"
32 #include "wx/wx_ui_signaller.h"
33 #include "wx/job_manager_view.h"
36 using boost::shared_ptr;
38 static std::string film_to_load;
47 setup_menu (wxMenuBar* m)
49 wxMenu* file = new wxMenu;
50 file->Append (ID_file_add_film, _("&Add Film..."));
51 file->Append (ID_file_quit, _("&Quit"));
53 wxMenu* help = new wxMenu;
54 help->Append (ID_help_about, _("About"));
56 m->Append (file, _("&File"));
57 m->Append (help, _("&Help"));
60 class Frame : public wxFrame
63 Frame (wxString const & title)
64 : wxFrame (NULL, -1, title)
66 wxMenuBar* bar = new wxMenuBar;
70 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_add_film, this), ID_file_add_film);
71 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_quit, this), ID_file_quit);
72 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::help_about, this), ID_help_about);
74 wxPanel* panel = new wxPanel (this);
75 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
76 s->Add (panel, 1, wxEXPAND);
79 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
81 JobManagerView* job_manager_view = new JobManagerView (panel, JobManagerView::PAUSE);
82 sizer->Add (job_manager_view, 1, wxALL | wxEXPAND, 6);
84 wxSizer* buttons = new wxBoxSizer (wxHORIZONTAL);
85 wxButton* add = new wxButton (panel, wxID_ANY, _("Add Film..."));
86 add->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&Frame::add_film, this));
87 buttons->Add (add, 1, wxALL, 6);
89 sizer->Add (buttons, 0, wxALL, 6);
91 panel->SetSizer (sizer);
93 Bind (wxEVT_CLOSE_WINDOW, boost::bind (&Frame::close, this, _1));
99 if (!JobManager::instance()->work_to_do ()) {
103 wxMessageDialog* d = new wxMessageDialog (
105 _("There are unfinished jobs; are you sure you want to quit?"),
106 _("Unfinished jobs"),
107 wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION
110 bool const r = d->ShowModal() == wxID_YES;
115 void close (wxCloseEvent& ev)
117 if (!should_close ()) {
125 void file_add_film ()
132 if (should_close ()) {
139 AboutDialog* d = new AboutDialog (this);
146 wxDirDialog* c = new wxDirDialog (this, _("Select film to open"), wxStandardPaths::Get().GetDocumentsDir(), wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
148 c->SetPath (std_to_wx (_last_parent.get().string ()));
154 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
155 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
163 shared_ptr<Film> film (new Film (wx_to_std (c->GetPath ())));
164 film->read_metadata ();
166 } catch (std::exception& e) {
167 wxString p = c->GetPath ();
168 wxCharBuffer b = p.ToUTF8 ();
169 error_dialog (this, wxString::Format (_("Could not open film at %s (%s)"), p.data(), std_to_wx (e.what()).data()));
173 _last_parent = boost::filesystem::path (wx_to_std (c->GetPath ())).parent_path ();
178 boost::optional<boost::filesystem::path> _last_parent;
181 static const wxCmdLineEntryDesc command_line_description[] = {
182 { wxCMD_LINE_PARAM, 0, 0, "film to load", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
183 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
186 class App : public wxApp
190 if (!wxApp::OnInit()) {
194 #ifdef DCPOMATIC_LINUX
195 unsetenv ("UBUNTU_MENUPROXY");
198 /* Enable i18n; this will create a Config object
199 to look for a force-configured language. This Config
200 object will be wrong, however, because dcpomatic_setup
201 hasn't yet been called and there aren't any scalers, filters etc.
204 dcpomatic_setup_i18n ();
206 /* Set things up, including scalers / filters etc.
207 which will now be internationalised correctly.
211 /* Force the configuration to be re-loaded correctly next
216 Frame* f = new Frame (_("DCP-o-matic Batch Converter"));
221 ui_signaller = new wxUISignaller (this);
222 this->Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
224 shared_ptr<Film> film;
225 if (!film_to_load.empty() && boost::filesystem::is_directory (film_to_load)) {
227 film.reset (new Film (film_to_load));
228 film->read_metadata ();
230 } catch (exception& e) {
231 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load film %1 (%2)")), film_to_load, e.what())));
240 ui_signaller->ui_idle ();
243 void OnInitCmdLine (wxCmdLineParser& parser)
245 parser.SetDesc (command_line_description);
246 parser.SetSwitchChars (wxT ("-"));
249 bool OnCmdLineParsed (wxCmdLineParser& parser)
251 if (parser.GetParamCount() > 0) {
252 film_to_load = wx_to_std (parser.GetParam(0));