Attempt to rationalise menu IDs and avoid duplicates.
[dcpomatic.git] / src / tools / dcpomatic_server.cc
index 80d4046a494a9283c7952258e0d08b2494608bfa..9bdc688c8f0e4bda214e48b7f61c37703cd41815 100644 (file)
 
 */
 
-#include "wx/wx_util.h"
-#include "wx/wx_signal_manager.h"
+#include "wx/id.h"
 #include "wx/static_text.h"
-#include "lib/util.h"
-#include "lib/encoded_log_entry.h"
-#include "lib/encode_server.h"
+#include "wx/wx_signal_manager.h"
+#include "wx/wx_util.h"
 #include "lib/config.h"
-#include "lib/log.h"
-#include "lib/signaller.h"
 #include "lib/cross.h"
 #include "lib/dcpomatic_log.h"
-#include "lib/warnings.h"
-DCPOMATIC_DISABLE_WARNINGS
-#include <wx/taskbar.h>
-#include <wx/splash.h>
+#include "lib/encode_server.h"
+#include "lib/encoded_log_entry.h"
+#include "lib/log.h"
+#include "lib/signaller.h"
+#include "lib/util.h"
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
 #include <wx/icon.h>
-DCPOMATIC_ENABLE_WARNINGS
+#include <wx/splash.h>
+#include <wx/taskbar.h>
+LIBDCP_ENABLE_WARNINGS
 #include <boost/thread.hpp>
 #include <boost/optional.hpp>
 #include <iostream>
 
+
 using std::cout;
-using std::string;
+using std::dynamic_pointer_cast;
 using std::exception;
-using std::list;
 using std::fixed;
+using std::list;
 using std::setprecision;
 using std::shared_ptr;
-using boost::thread;
+using std::string;
 using boost::bind;
 using boost::optional;
-using std::dynamic_pointer_cast;
+using boost::thread;
 #if BOOST_VERSION >= 106100
 using namespace boost::placeholders;
 #endif
 
+
 enum {
-       ID_status = 1,
+       ID_status = DCPOMATIC_MAIN_MENU,
        ID_quit,
        ID_timer
 };
@@ -87,7 +90,7 @@ public:
        boost::signals2::signal<void(int)> Removed;
 
 private:
-       void do_log (shared_ptr<const LogEntry> entry)
+       void do_log (shared_ptr<const LogEntry> entry) override
        {
                time_t const s = entry->seconds ();
                struct tm* local = localtime (&s);
@@ -211,26 +214,22 @@ private:
        std::shared_ptr<wxTimer> _timer;
 };
 
+
+static StatusDialog* status_dialog = nullptr;
+
+
 class TaskBarIcon : public wxTaskBarIcon
 {
 public:
        TaskBarIcon ()
        {
-#ifdef DCPOMATIC_WINDOWS
-               wxIcon icon (std_to_wx ("id"));
-#else
-               wxBitmap bitmap (bitmap_path("dcpomatic_small_black"), wxBITMAP_TYPE_PNG);
-               wxIcon icon;
-               icon.CopyFromBitmap (bitmap);
-#endif
-
-               SetIcon (icon, std_to_wx ("DCP-o-matic Encode Server"));
+               set_icon ();
 
                Bind (wxEVT_MENU, boost::bind (&TaskBarIcon::status, this), ID_status);
                Bind (wxEVT_MENU, boost::bind (&TaskBarIcon::quit, this), ID_quit);
        }
 
-       wxMenu* CreatePopupMenu ()
+       wxMenu* CreatePopupMenu () override
        {
                auto menu = new wxMenu;
                menu->Append (ID_status, std_to_wx ("Status..."));
@@ -238,21 +237,33 @@ public:
                return menu;
        }
 
+       void set_icon ()
+       {
+#ifdef DCPOMATIC_WINDOWS
+               wxIcon icon (std_to_wx("id"));
+#else
+               string const colour = gui_is_dark() ? "white" : "black";
+               wxBitmap bitmap (
+                       bitmap_path(String::compose("dcpomatic_small_%1.png", colour)),
+                       wxBITMAP_TYPE_PNG
+                       );
+               wxIcon icon;
+               icon.CopyFromBitmap (bitmap);
+#endif
+
+               SetIcon (icon, std_to_wx ("DCP-o-matic Encode Server"));
+       }
+
 private:
        void status ()
        {
-               if (!_status) {
-                       _status = new StatusDialog ();
-               }
-               _status->Show ();
+               status_dialog->Show ();
        }
 
        void quit ()
        {
                wxTheApp->ExitMainLoop ();
        }
-
-       StatusDialog* _status;
 };
 
 
@@ -265,7 +276,7 @@ public:
 
 private:
 
-       bool OnInit ()
+       bool OnInit () override
        {
                if (!wxApp::OnInit()) {
                        return false;
@@ -277,7 +288,7 @@ private:
                server_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR);
                dcpomatic_log = server_log;
 
-               Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
+               Config::FailedToLoad.connect(boost::bind(&App::config_failed_to_load, this, _1));
                Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
 
                auto splash = maybe_show_splash ();
@@ -297,11 +308,12 @@ private:
                */
                Config::instance();
 
+               status_dialog = new StatusDialog ();
 #ifdef DCPOMATIC_LINUX
-               StatusDialog* d = new StatusDialog ();
-               d->Show ();
+               status_dialog->Show ();
 #else
                _icon = new TaskBarIcon;
+               status_dialog->Bind (wxEVT_SYS_COLOUR_CHANGED, boost::bind(&TaskBarIcon::set_icon, _icon));
 #endif
                _thread = thread (bind (&App::main_thread, this));
 
@@ -318,7 +330,7 @@ private:
                return true;
        }
 
-       int OnExit ()
+       int OnExit () override
        {
                delete _icon;
                return wxApp::OnExit ();
@@ -350,9 +362,9 @@ private:
                signal_manager->ui_idle ();
        }
 
-       void config_failed_to_load ()
+       void config_failed_to_load(Config::LoadFailure what)
        {
-               message_dialog (nullptr, _("The existing configuration failed to load.  Default values will be used instead.  These may take a short time to create."));
+               report_config_load_failure(nullptr, what);
        }
 
        void config_warning (string m)