/*
- Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2013 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <wx/generic/aboutdlgg.h>
#include <wx/stdpaths.h>
#include <wx/cmdline.h>
-#include <quickmail.h>
-#include <zip.h>
#include "wx/film_viewer.h"
#include "wx/film_editor.h"
#include "wx/job_manager_view.h"
#include "wx/wx_ui_signaller.h"
#include "wx/about_dialog.h"
#include "wx/kdm_dialog.h"
+#include "wx/servers_list_dialog.h"
+#include "wx/hints_dialog.h"
#include "lib/film.h"
#include "lib/config.h"
#include "lib/util.h"
#include "lib/transcode_job.h"
#include "lib/exceptions.h"
#include "lib/cinema.h"
+#include "lib/kdm.h"
using std::cout;
using std::string;
using std::make_pair;
using std::list;
using std::exception;
-using std::ofstream;
using boost::shared_ptr;
using boost::dynamic_pointer_cast;
#define ALWAYS 0x0
#define NEEDS_FILM 0x1
#define NOT_DURING_DCP_CREATION 0x2
+#define NEEDS_DCP 0x4
map<wxMenuItem*, int> menu_items;
while (i != jobs.end() && dynamic_pointer_cast<TranscodeJob> (*i) == 0) {
++i;
}
- bool const dcp_creation = (i != jobs.end ());
+ bool const dcp_creation = (i != jobs.end ()) && !(*i)->finished ();
+ bool const have_dcp = film && !film->dcps().empty ();
for (map<wxMenuItem*, int>::iterator j = menu_items.begin(); j != menu_items.end(); ++j) {
if ((j->second & NOT_DURING_DCP_CREATION) && dcp_creation) {
enabled = false;
}
+
+ if ((j->second & NEEDS_DCP) && !have_dcp) {
+ enabled = false;
+ }
j->first->Enable (enabled);
}
ID_jobs_make_kdms,
ID_jobs_send_dcp_to_tms,
ID_jobs_show_dcp,
+ ID_tools_hints,
+ ID_tools_encoding_servers,
};
void
jobs_menu = new wxMenu;
add_item (jobs_menu, _("&Make DCP"), ID_jobs_make_dcp, NEEDS_FILM | NOT_DURING_DCP_CREATION);
- add_item (jobs_menu, _("Make &KDMs..."), ID_jobs_make_kdms, NEEDS_FILM);
- add_item (jobs_menu, _("&Send DCP to TMS"), ID_jobs_send_dcp_to_tms, NEEDS_FILM | NOT_DURING_DCP_CREATION);
- add_item (jobs_menu, _("S&how DCP"), ID_jobs_show_dcp, NEEDS_FILM | NOT_DURING_DCP_CREATION);
+ add_item (jobs_menu, _("Make &KDMs..."), ID_jobs_make_kdms, NEEDS_FILM | NEEDS_DCP);
+ add_item (jobs_menu, _("&Send DCP to TMS"), ID_jobs_send_dcp_to_tms, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_DCP);
+ add_item (jobs_menu, _("S&how DCP"), ID_jobs_show_dcp, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_DCP);
+
+ wxMenu* tools = new wxMenu;
+ add_item (tools, _("Hints..."), ID_tools_hints, 0);
+ add_item (tools, _("Encoding Servers..."), ID_tools_encoding_servers, 0);
wxMenu* help = new wxMenu;
#ifdef __WXOSX__
m->Append (edit, _("&Edit"));
#endif
m->Append (jobs_menu, _("&Jobs"));
+ m->Append (tools, _("&Tools"));
m->Append (help, _("&Help"));
}
-struct ScreenKDM
-{
- ScreenKDM (shared_ptr<Screen> s, libdcp::KDM k)
- : screen (s)
- , kdm (k)
- {}
-
- shared_ptr<Screen> screen;
- libdcp::KDM kdm;
-};
-
-/* Not complete but sufficient for our purposes (we're using
- ScreenKDM in a list where all the screens will be unique).
-*/
-bool operator== (ScreenKDM const & a, ScreenKDM const & b)
-{
- return a.screen == b.screen;
-}
-
class Frame : public wxFrame
{
public:
Frame (wxString const & title)
: wxFrame (NULL, -1, title)
+ , _servers_list_dialog (0)
{
+#ifdef DCPOMATIC_WINDOWS_CONSOLE
+ AllocConsole();
+
+ HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
+ int hCrt = _open_osfhandle((intptr_t) handle_out, _O_TEXT);
+ FILE* hf_out = _fdopen(hCrt, "w");
+ setvbuf(hf_out, NULL, _IONBF, 1);
+ *stdout = *hf_out;
+
+ HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
+ hCrt = _open_osfhandle((intptr_t) handle_in, _O_TEXT);
+ FILE* hf_in = _fdopen(hCrt, "r");
+ setvbuf(hf_in, NULL, _IONBF, 128);
+ *stdin = *hf_in;
+#endif
+
wxMenuBar* bar = new wxMenuBar;
setup_menu (bar);
SetMenuBar (bar);
- Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_new, this), ID_file_new);
- Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_open, this), ID_file_open);
- Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_save, this), ID_file_save);
- Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_properties, this), ID_file_properties);
- Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_exit, this), wxID_EXIT);
- Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::edit_preferences, this), wxID_PREFERENCES);
- Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_make_dcp, this), ID_jobs_make_dcp);
- Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_make_kdms, this), ID_jobs_make_kdms);
- Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_send_dcp_to_tms, this), ID_jobs_send_dcp_to_tms);
- Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_show_dcp, this), ID_jobs_show_dcp);
- Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::help_about, this), wxID_ABOUT);
-
- Bind (wxEVT_MENU_OPEN, boost::bind (&Frame::menu_opened, this, _1));
+ Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_new, this), ID_file_new);
+ Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_open, this), ID_file_open);
+ Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_save, this), ID_file_save);
+ Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_properties, this), ID_file_properties);
+ Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_exit, this), wxID_EXIT);
+ Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::edit_preferences, this), wxID_PREFERENCES);
+ Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_make_dcp, this), ID_jobs_make_dcp);
+ Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_make_kdms, this), ID_jobs_make_kdms);
+ Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_send_dcp_to_tms, this), ID_jobs_send_dcp_to_tms);
+ Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_show_dcp, this), ID_jobs_show_dcp);
+ Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::tools_hints, this), ID_tools_hints);
+ Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::tools_encoding_servers, this), ID_tools_encoding_servers);
+ Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::help_about, this), wxID_ABOUT);
+
Bind (wxEVT_CLOSE_WINDOW, boost::bind (&Frame::close, this, _1));
/* Use a panel as the only child of the Frame so that we avoid
private:
- void menu_opened (wxMenuEvent& ev)
- {
- if (ev.GetMenu() != jobs_menu) {
- return;
- }
-
- bool const have_dcp = false;//film && film->have_dcp();
- jobs_menu->Enable (ID_jobs_send_dcp_to_tms, have_dcp);
- jobs_menu->Enable (ID_jobs_show_dcp, have_dcp);
- }
-
void set_film ()
{
film_viewer->set_film (film);
set_menu_sensitivity ();
}
- void file_changed (string f)
+ void file_changed (boost::filesystem::path f)
{
stringstream s;
s << wx_to_std (_("DCP-o-matic"));
if (!f.empty ()) {
- s << " - " << f;
+ s << " - " << f.string ();
}
SetTitle (std_to_wx (s.str()));
std_to_wx (
String::compose (wx_to_std (_("The directory %1 already exists and is not empty. "
"Are you sure you want to use it?")),
- d->get_path().c_str())
+ d->get_path().string().c_str())
)
)) {
return;
void file_open ()
{
- wxDirDialog* c = new wxDirDialog (this, _("Select film to open"), wxStandardPaths::Get().GetDocumentsDir(), wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
+ wxDirDialog* c = new wxDirDialog (
+ this,
+ _("Select film to open"),
+ std_to_wx (Config::instance()->default_directory_or (wx_to_std (wxStandardPaths::Get().GetDocumentsDir())).string ()),
+ wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
+ );
+
int r;
while (1) {
r = c->ShowModal ();
return;
}
- KDMDialog* d = new KDMDialog (this);
+ KDMDialog* d = new KDMDialog (this, film);
if (d->ShowModal () != wxID_OK) {
d->Destroy ();
return;
}
-
+
try {
- list<shared_ptr<Screen> > screens = d->screens ();
- list<libdcp::KDM> kdms = film->make_kdms (
- screens,
- d->from (),
- d->until ()
- );
-
- list<ScreenKDM> screen_kdms;
-
- list<shared_ptr<Screen> >::iterator i = screens.begin ();
- list<libdcp::KDM>::iterator j = kdms.begin ();
- while (i != screens.end() && j != kdms.end ()) {
- screen_kdms.push_back (ScreenKDM (*i, *j));
- ++i;
- ++j;
- }
-
if (d->write_to ()) {
- /* Write KDMs to the specified directory */
- for (list<ScreenKDM>::iterator i = screen_kdms.begin(); i != screen_kdms.end(); ++i) {
- boost::filesystem::path out = d->directory ();
- out /= tidy_for_filename (i->screen->cinema->name) + "_" + tidy_for_filename (i->screen->name) + ".kdm.xml";
- i->kdm.as_xml (out);
- }
+ write_kdm_files (film, d->screens (), d->dcp (), d->from (), d->until (), d->directory ());
} else {
- while (!screen_kdms.empty ()) {
-
- /* Get all the screens from a single cinema */
-
- shared_ptr<Cinema> cinema;
- list<ScreenKDM> cinema_screen_kdms;
-
- list<ScreenKDM>::iterator i = screen_kdms.begin ();
- cinema = i->screen->cinema;
- cinema_screen_kdms.push_back (*i);
- list<ScreenKDM>::iterator j = i;
- ++i;
- screen_kdms.remove (*j);
-
- while (i != screen_kdms.end ()) {
- if (i->screen->cinema == cinema) {
- cinema_screen_kdms.push_back (*i);
- list<ScreenKDM>::iterator j = i;
- ++i;
- screen_kdms.remove (*j);
- } else {
- ++i;
- }
- }
-
- /* Make a ZIP file of this cinema's KDMs */
-
- boost::filesystem::path zip_file = boost::filesystem::temp_directory_path ();
- zip_file /= boost::filesystem::unique_path().string() + ".zip";
- struct zip* zip = zip_open (zip_file.string().c_str(), ZIP_CREATE | ZIP_EXCL, 0);
- if (!zip) {
- throw FileError ("could not create ZIP file", zip_file);
- }
-
- list<shared_ptr<string> > kdm_strings;
-
- for (list<ScreenKDM>::const_iterator i = cinema_screen_kdms.begin(); i != cinema_screen_kdms.end(); ++i) {
- shared_ptr<string> kdm (new string (i->kdm.as_xml ()));
- kdm_strings.push_back (kdm);
-
- struct zip_source* source = zip_source_buffer (zip, kdm->c_str(), kdm->length(), 0);
- if (!source) {
- throw StringError ("could not create ZIP source");
- }
-
- string const name = tidy_for_filename (i->screen->cinema->name) + "_" +
- tidy_for_filename (i->screen->name) + ".kdm.xml";
-
- if (zip_add (zip, name.c_str(), source) == -1) {
- throw StringError ("failed to add KDM to ZIP archive");
- }
- }
-
- if (zip_close (zip) == -1) {
- throw StringError ("failed to close ZIP archive");
- }
-
- /* Send email */
-
- quickmail_initialize ();
- quickmail mail = quickmail_create (Config::instance()->kdm_from().c_str(), "KDM delivery");
- quickmail_add_to (mail, cinema->email.c_str ());
-
- string body = Config::instance()->kdm_email().c_str();
- boost::algorithm::replace_all (body, "$DCP_NAME", film->dcp_name ());
-
- quickmail_set_body (mail, body.c_str());
- quickmail_add_attachment_file (mail, zip_file.string().c_str());
- char const* error = quickmail_send (mail, Config::instance()->mail_server().c_str(), 25, "", "");
- if (error) {
- quickmail_destroy (mail);
- throw StringError (String::compose ("Failed to send KDM email (%1)", error));
- }
- quickmail_destroy (mail);
-
- film->log()->log (String::compose ("Send KDM email to %1", cinema->email));
- }
+ email_kdms (film, d->screens (), d->dcp (), d->from (), d->until ());
}
-
} catch (KDMError& e) {
error_dialog (this, e.what ());
}
void jobs_show_dcp ()
{
#ifdef __WXMSW__
- string d = film->directory();
+ string d = film->directory().string ();
wstring w;
w.assign (d.begin(), d.end());
ShellExecute (0, L"open", w.c_str(), 0, 0, SW_SHOWDEFAULT);
#else
int r = system ("which nautilus");
if (WEXITSTATUS (r) == 0) {
- r = system (string ("nautilus " + film->directory()).c_str ());
+ r = system (string ("nautilus " + film->directory().string()).c_str ());
if (WEXITSTATUS (r)) {
error_dialog (this, _("Could not show DCP (could not run nautilus)"));
}
} else {
int r = system ("which konqueror");
if (WEXITSTATUS (r) == 0) {
- r = system (string ("konqueror " + film->directory()).c_str ());
+ r = system (string ("konqueror " + film->directory().string()).c_str ());
if (WEXITSTATUS (r)) {
error_dialog (this, _("Could not show DCP (could not run konqueror)"));
}
#endif
}
+ void tools_hints ()
+ {
+ if (!_hints_dialog) {
+ _hints_dialog = new HintsDialog (this, film);
+ }
+
+ _hints_dialog->Show ();
+ }
+
+ void tools_encoding_servers ()
+ {
+ if (!_servers_list_dialog) {
+ _servers_list_dialog = new ServersListDialog (this);
+ }
+
+ _servers_list_dialog->Show ();
+ }
+
void help_about ()
{
AboutDialog* d = new AboutDialog (this);
}
ev.Skip ();
- }
+ }
+
+ HintsDialog* _hints_dialog;
+ ServersListDialog* _servers_list_dialog;
};
-#if wxMINOR_VERSION == 9
static const wxCmdLineEntryDesc command_line_description[] = {
{ wxCMD_LINE_OPTION, "l", "log", "set log level (silent, verbose or timing)", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_SWITCH, "n", "new", "create new film", wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_PARAM, 0, 0, "film to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
};
-#else
-static const wxCmdLineEntryDesc command_line_description[] = {
- { wxCMD_LINE_OPTION, wxT("l"), wxT("log"), wxT("set log level (silent, verbose or timing)"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
- { wxCMD_LINE_SWITCH, wxT("n"), wxT("new"), wxT("create new film"), wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
- { wxCMD_LINE_PARAM, 0, 0, wxT("film to load or create"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
- { wxCMD_LINE_NONE, wxT(""), wxT(""), wxT(""), wxCmdLineParamType (0), 0 }
-};
-#endif
class App : public wxApp
{
bool OnInit ()
try
{
+ SetAppName (_("DCP-o-matic"));
+
if (!wxApp::OnInit()) {
return false;
}