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>
23 #include "lib/version.h"
24 #include "lib/compose.hpp"
25 #include "lib/config.h"
28 #include "lib/job_manager.h"
29 #include "wx/wx_util.h"
30 #include "wx/wx_ui_signaller.h"
31 #include "wx/job_manager_view.h"
33 using boost::shared_ptr;
42 setup_menu (wxMenuBar* m)
44 wxMenu* file = new wxMenu;
45 file->Append (ID_file_add_film, _("&Add Film..."));
46 file->Append (ID_file_quit, _("&Quit"));
48 wxMenu* help = new wxMenu;
49 help->Append (ID_help_about, _("About"));
51 m->Append (file, _("&File"));
52 m->Append (help, _("&Help"));
55 class Frame : public wxFrame
58 Frame (wxString const & title)
59 : wxFrame (NULL, -1, title)
61 wxMenuBar* bar = new wxMenuBar;
65 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_add_film, this), ID_file_add_film);
66 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_quit, this), ID_file_quit);
67 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::help_about, this), ID_help_about);
69 wxPanel* panel = new wxPanel (this);
70 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
71 s->Add (panel, 1, wxEXPAND);
74 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
76 JobManagerView* job_manager_view = new JobManagerView (panel, JobManagerView::PAUSE);
77 sizer->Add (job_manager_view, 1, wxALL | wxEXPAND, 6);
79 wxSizer* buttons = new wxBoxSizer (wxHORIZONTAL);
80 wxButton* add = new wxButton (panel, wxID_ANY, _("Add Film..."));
81 add->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&Frame::add_film, this));
82 buttons->Add (add, 1, wxALL, 6);
84 sizer->Add (buttons, 0, wxALL, 6);
86 panel->SetSizer (sizer);
88 Bind (wxEVT_CLOSE_WINDOW, boost::bind (&Frame::close, this, _1));
94 if (!JobManager::instance()->work_to_do ()) {
98 wxMessageDialog* d = new wxMessageDialog (
100 _("There are unfinished jobs; are you sure you want to quit?"),
101 _("Unfinished jobs"),
102 wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION
105 bool const r = d->ShowModal() == wxID_YES;
110 void close (wxCloseEvent& ev)
112 if (!should_close ()) {
120 void file_add_film ()
127 if (should_close ()) {
134 wxAboutDialogInfo info;
135 info.SetName (_("DCP-o-matic Batch Converter"));
136 if (strcmp (dcpomatic_git_commit, "release") == 0) {
137 info.SetVersion (std_to_wx (String::compose ("version %1", dcpomatic_version)));
139 info.SetVersion (std_to_wx (String::compose ("version %1 git %2", dcpomatic_version, dcpomatic_git_commit)));
141 info.SetDescription (_("Free, open-source DCP generation from almost anything."));
142 info.SetCopyright (_("(C) 2012-2013 Carl Hetherington, Terrence Meiczinger, Paul Davis, Ole Laursen"));
144 wxArrayString authors;
145 authors.Add (wxT ("Carl Hetherington"));
146 authors.Add (wxT ("Terrence Meiczinger"));
147 authors.Add (wxT ("Paul Davis"));
148 authors.Add (wxT ("Ole Laursen"));
149 info.SetDevelopers (authors);
151 wxArrayString translators;
152 translators.Add (wxT ("Olivier Perriere"));
153 translators.Add (wxT ("Lilian Lefranc"));
154 translators.Add (wxT ("Thierry Journet"));
155 translators.Add (wxT ("Massimiliano Broggi"));
156 translators.Add (wxT ("Manuel AC"));
157 translators.Add (wxT ("Adam Klotblixt"));
158 info.SetTranslators (translators);
160 info.SetWebSite (wxT ("http://carlh.net/software/dcpomatic"));
166 wxDirDialog* c = new wxDirDialog (this, _("Select film to open"), wxStandardPaths::Get().GetDocumentsDir(), wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
170 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
171 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
179 shared_ptr<Film> film (new Film (wx_to_std (c->GetPath ())));
180 film->read_metadata ();
182 } catch (std::exception& e) {
183 wxString p = c->GetPath ();
184 wxCharBuffer b = p.ToUTF8 ();
185 error_dialog (this, wxString::Format (_("Could not open film at %s (%s)"), p.data(), std_to_wx (e.what()).data()));
193 class App : public wxApp
197 if (!wxApp::OnInit()) {
201 #ifdef DCPOMATIC_LINUX
202 unsetenv ("UBUNTU_MENUPROXY");
205 /* Enable i18n; this will create a Config object
206 to look for a force-configured language. This Config
207 object will be wrong, however, because dcpomatic_setup
208 hasn't yet been called and there aren't any scalers, filters etc.
211 dcpomatic_setup_i18n ();
213 /* Set things up, including scalers / filters etc.
214 which will now be internationalised correctly.
218 /* Force the configuration to be re-loaded correctly next
223 Frame* f = new Frame (_("DCP-o-matic Batch Converter"));
228 ui_signaller = new wxUISignaller (this);
229 this->Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
236 ui_signaller->ui_idle ();