Merge 1.0
[dcpomatic.git] / src / tools / dcpomatic.cc
index 5d21579223647f04d68170a89bfe5246d7c23b75..891c4623ca9b6e1ea1ac995d41108d119468e72f 100644 (file)
@@ -53,6 +53,8 @@
 #include "lib/exceptions.h"
 #include "lib/cinema.h"
 #include "lib/kdm.h"
+#include "lib/send_kdm_email_job.h"
+#include "lib/server_finder.h"
 
 using std::cout;
 using std::string;
@@ -244,8 +246,25 @@ class Frame : public wxFrame
 public:
        Frame (wxString const & title)
                : wxFrame (NULL, -1, title)
+               , _hints_dialog (0)
                , _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);
@@ -331,7 +350,7 @@ private:
                                            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;
@@ -442,7 +461,9 @@ private:
                        if (d->write_to ()) {
                                write_kdm_files (film, d->screens (), d->dcp (), d->from (), d->until (), d->directory ());
                        } else {
-                               email_kdms (film, d->screens (), d->dcp (), d->from (), d->until ());
+                               JobManager::instance()->add (
+                                       shared_ptr<Job> (new SendKDMEmailJob (film, d->screens (), d->dcp (), d->from (), d->until ()))
+                                       );
                        }
                } catch (KDMError& e) {
                        error_dialog (this, e.what ());
@@ -532,6 +553,8 @@ private:
                        return;
                }
 
+               maybe_save_then_delete_film ();
+
                ev.Skip ();
        }
 
@@ -610,8 +633,12 @@ class App : public wxApp
                f->Show ();
 
                ui_signaller = new wxUISignaller (this);
-               this->Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
+               Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
 
+               Bind (wxEVT_TIMER, boost::bind (&App::check, this));
+               _timer.reset (new wxTimer (this));
+               _timer->Start (1000);
+               
                return true;
        }
        catch (exception& e)
@@ -648,6 +675,17 @@ class App : public wxApp
        {
                ui_signaller->ui_idle ();
        }
+
+       void check ()
+       {
+               try {
+                       ServerFinder::instance()->rethrow ();
+               } catch (exception& e) {
+                       error_dialog (0, std_to_wx (e.what ()));
+               }
+       }
+
+       shared_ptr<wxTimer> _timer;
 };
 
 IMPLEMENT_APP (App)