Merge branch 'warnings' into v2.15.x.
[dcpomatic.git] / src / tools / dcpomatic_disk.cc
index b2678ce42a788409480ad110f80f20085d704055..b94d4bf941016c4deb5e898040c7e50995c88fe5 100644 (file)
 #include "lib/job_manager.h"
 #include "lib/disk_writer_messages.h"
 #include "lib/version.h"
+#include "lib/warnings.h"
 #include <wx/wx.h>
+DCPOMATIC_DISABLE_WARNINGS
 #include <boost/process.hpp>
+DCPOMATIC_ENABLE_WARNINGS
 #ifdef DCPOMATIC_WINDOWS
 #include <boost/process/windows.hpp>
 #endif
 #ifdef DCPOMATIC_OSX
-#include <ApplicationServices/ApplicationServices.h>
 #include <notify.h>
 #endif
 
@@ -118,7 +120,8 @@ public:
 
                drive_refresh ();
 
-               Bind (wxEVT_SIZE, boost::bind (&DOMFrame::sized, this, _1));
+               Bind (wxEVT_SIZE, boost::bind(&DOMFrame::sized, this, _1));
+               Bind (wxEVT_CLOSE_WINDOW, boost::bind(&DOMFrame::close, this, _1));
 
                JobManager::instance()->ActiveJobsChanged.connect(boost::bind(&DOMFrame::setup_sensitivity, this));
 
@@ -129,8 +132,12 @@ public:
 #endif
 
 #ifdef DCPOMATIC_LINUX
-               LOG_DISK("Starting writer process %1", disk_writer_path().string());
-               _writer = new boost::process::child (disk_writer_path());
+               if (getenv("DCPOMATIC_NO_START_WRITER")) {
+                       LOG_DISK_NC("Not starting writer process as DCPOMATIC_NO_START_WRITER is set");
+               } else {
+                       LOG_DISK("Starting writer process %1", disk_writer_path().string());
+                       _writer = new boost::process::child (disk_writer_path());
+               }
 #endif
 
 #ifdef DCPOMATIC_OSX
@@ -151,6 +158,37 @@ private:
                ev.Skip ();
        }
 
+
+       bool should_close ()
+       {
+               if (!JobManager::instance()->work_to_do()) {
+                       return true;
+               }
+
+               wxMessageDialog* d = new wxMessageDialog (
+                       0,
+                       _("There are unfinished jobs; are you sure you want to quit?"),
+                       _("Unfinished jobs"),
+                       wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION
+                       );
+
+               bool const r = d->ShowModal() == wxID_YES;
+               d->Destroy ();
+               return r;
+       }
+
+
+       void close (wxCloseEvent& ev)
+       {
+               if (!should_close()) {
+                       ev.Veto ();
+                       return;
+               }
+
+               ev.Skip ();
+       }
+
+
        void open ()
        {
                wxDirDialog* d = new wxDirDialog (this, _("Choose a DCP folder"), wxT(""), wxDD_DIR_MUST_EXIST);
@@ -281,10 +319,8 @@ public:
                        unsetenv ("UBUNTU_MENUPROXY");
 #endif
 
-#ifdef __WXOSX__
-                       ProcessSerialNumber serial;
-                       GetCurrentProcess (&serial);
-                       TransformProcessType (&serial, kProcessTransformToForegroundApplication);
+#ifdef DCPOMATIC_OSX
+                       make_foreground_application ();
 #endif
 
                        dcpomatic_setup_path_encoding ();
@@ -312,6 +348,7 @@ public:
                        if (!warning->confirmed()) {
                                return false;
                        }
+                       warning->Destroy ();
 
                        _frame = new DOMFrame (_("DCP-o-matic Disk Writer"));
                        SetTopWindow (_frame);