2 Copyright (C) 2013 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/wx_ui_signaller.h"
32 #include "wx/job_manager_view.h"
35 using boost::shared_ptr;
37 static std::string film_to_load;
46 setup_menu (wxMenuBar* m)
48 wxMenu* file = new wxMenu;
49 file->Append (ID_file_add_film, _("&Add Film..."));
50 file->Append (ID_file_quit, _("&Quit"));
52 wxMenu* help = new wxMenu;
53 help->Append (ID_help_about, _("About"));
55 m->Append (file, _("&File"));
56 m->Append (help, _("&Help"));
59 class Frame : public wxFrame
62 Frame (wxString const & title)
63 : wxFrame (NULL, -1, title)
65 wxMenuBar* bar = new wxMenuBar;
69 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_add_film, this), ID_file_add_film);
70 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_quit, this), ID_file_quit);
71 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::help_about, this), ID_help_about);
73 wxPanel* panel = new wxPanel (this);
74 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
75 s->Add (panel, 1, wxEXPAND);
78 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
80 JobManagerView* job_manager_view = new JobManagerView (panel, JobManagerView::PAUSE);
81 sizer->Add (job_manager_view, 1, wxALL | wxEXPAND, 6);
83 wxSizer* buttons = new wxBoxSizer (wxHORIZONTAL);
84 wxButton* add = new wxButton (panel, wxID_ANY, _("Add Film..."));
85 add->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&Frame::add_film, this));
86 buttons->Add (add, 1, wxALL, 6);
88 sizer->Add (buttons, 0, wxALL, 6);
90 panel->SetSizer (sizer);
92 Bind (wxEVT_CLOSE_WINDOW, boost::bind (&Frame::close, this, _1));
98 if (!JobManager::instance()->work_to_do ()) {
102 wxMessageDialog* d = new wxMessageDialog (
104 _("There are unfinished jobs; are you sure you want to quit?"),
105 _("Unfinished jobs"),
106 wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION
109 bool const r = d->ShowModal() == wxID_YES;
114 void close (wxCloseEvent& ev)
116 if (!should_close ()) {
124 void file_add_film ()
131 if (should_close ()) {
138 wxAboutDialogInfo info;
139 info.SetName (_("DCP-o-matic Batch Converter"));
140 if (strcmp (dcpomatic_git_commit, "release") == 0) {
141 info.SetVersion (std_to_wx (String::compose ("version %1", dcpomatic_version)));
143 info.SetVersion (std_to_wx (String::compose ("version %1 git %2", dcpomatic_version, dcpomatic_git_commit)));
145 info.SetDescription (_("Free, open-source DCP generation from almost anything."));
146 info.SetCopyright (_("(C) 2012-2013 Carl Hetherington, Terrence Meiczinger, Paul Davis, Ole Laursen"));
148 wxArrayString authors;
149 authors.Add (wxT ("Carl Hetherington"));
150 authors.Add (wxT ("Terrence Meiczinger"));
151 authors.Add (wxT ("Paul Davis"));
152 authors.Add (wxT ("Ole Laursen"));
153 info.SetDevelopers (authors);
155 wxArrayString translators;
156 translators.Add (wxT ("Olivier Perriere"));
157 translators.Add (wxT ("Lilian Lefranc"));
158 translators.Add (wxT ("Thierry Journet"));
159 translators.Add (wxT ("Massimiliano Broggi"));
160 translators.Add (wxT ("Manuel AC"));
161 translators.Add (wxT ("Adam Klotblixt"));
162 info.SetTranslators (translators);
164 info.SetWebSite (wxT ("http://carlh.net/software/dcpomatic"));
170 wxDirDialog* c = new wxDirDialog (this, _("Select film to open"), wxStandardPaths::Get().GetDocumentsDir(), wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
172 c->SetPath (std_to_wx (_last_parent.get().string ()));
178 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
179 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
187 shared_ptr<Film> film (new Film (wx_to_std (c->GetPath ())));
188 film->read_metadata ();
190 } catch (std::exception& e) {
191 wxString p = c->GetPath ();
192 wxCharBuffer b = p.ToUTF8 ();
193 error_dialog (this, wxString::Format (_("Could not open film at %s (%s)"), p.data(), std_to_wx (e.what()).data()));
197 _last_parent = boost::filesystem::path (wx_to_std (c->GetPath ())).parent_path ();
202 boost::optional<boost::filesystem::path> _last_parent;
205 static const wxCmdLineEntryDesc command_line_description[] = {
206 { wxCMD_LINE_PARAM, 0, 0, "film to load", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
207 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
210 class App : public wxApp
214 if (!wxApp::OnInit()) {
218 #ifdef DCPOMATIC_LINUX
219 unsetenv ("UBUNTU_MENUPROXY");
222 /* Enable i18n; this will create a Config object
223 to look for a force-configured language. This Config
224 object will be wrong, however, because dcpomatic_setup
225 hasn't yet been called and there aren't any scalers, filters etc.
228 dcpomatic_setup_i18n ();
230 /* Set things up, including scalers / filters etc.
231 which will now be internationalised correctly.
235 /* Force the configuration to be re-loaded correctly next
240 Frame* f = new Frame (_("DCP-o-matic Batch Converter"));
245 ui_signaller = new wxUISignaller (this);
246 this->Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
248 shared_ptr<Film> film;
249 if (!film_to_load.empty() && boost::filesystem::is_directory (film_to_load)) {
251 film.reset (new Film (film_to_load));
252 film->read_metadata ();
254 } catch (exception& e) {
255 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load film %1 (%2)")), film_to_load, e.what())));
264 ui_signaller->ui_idle ();
267 void OnInitCmdLine (wxCmdLineParser& parser)
269 parser.SetDesc (command_line_description);
270 parser.SetSwitchChars (wxT ("-"));
273 bool OnCmdLineParsed (wxCmdLineParser& parser)
275 if (parser.GetParamCount() > 0) {
276 film_to_load = wx_to_std (parser.GetParam(0));