OS X build fix.
[dcpomatic.git] / src / tools / dcpomatic_player.cc
index 567440f8809013343fae99c75ebf0aeef2786be5..2dd29c3edb6874ba7d094151e08d4386039a7704 100644 (file)
 #include "wx/film_viewer.h"
 #include "wx/player_information.h"
 #include "wx/update_dialog.h"
+#include "wx/player_config_dialog.h"
 #include <wx/wx.h>
 #include <wx/stdpaths.h>
 #include <wx/splash.h>
 #include <wx/cmdline.h>
+#include <wx/preferences.h>
+#ifdef __WXOSX__
+#include <ApplicationServices/ApplicationServices.h>
+#endif
 #include <boost/bind.hpp>
 #include <iostream>
 
+#ifdef check
+#undef check
+#endif
+
 using std::string;
 using std::cout;
 using std::exception;
@@ -64,6 +73,9 @@ public:
        DOMFrame ()
                : wxFrame (0, -1, _("DCP-o-matic Player"))
                , _update_news_requested (false)
+               , _info (0)
+               , _config_dialog (0)
+               , _viewer (0)
        {
 
 #if defined(DCPOMATIC_WINDOWS)
@@ -79,8 +91,11 @@ public:
                SetIcon (wxIcon (std_to_wx ("id")));
 #endif
 
+               _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this));
+
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
+               Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>()), ID_view_scale_appropriate);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
@@ -136,7 +151,7 @@ public:
                }
 
                _viewer->set_film (_film);
-               _info->update ();
+               _info->triggered_update ();
        }
 
 private:
@@ -216,6 +231,14 @@ private:
                Close ();
        }
 
+       void edit_preferences ()
+       {
+               if (!_config_dialog) {
+                       _config_dialog = create_player_config_dialog ();
+               }
+               _config_dialog->Show (this);
+       }
+
        void tools_check_for_updates ()
        {
                UpdateChecker::instance()->run ();
@@ -266,10 +289,28 @@ private:
                _update_news_requested = false;
        }
 
+       void config_changed ()
+       {
+               /* Instantly save any config changes when using the player GUI */
+               try {
+                       Config::instance()->write_config();
+               } catch (exception& e) {
+                       error_dialog (
+                               this,
+                               wxString::Format (
+                                       _("Could not write to config file at %s.  Your changes have not been saved."),
+                                       std_to_wx (Config::instance()->cinemas_file().string()).data()
+                                       )
+                               );
+               }
+       }
+
        bool _update_news_requested;
        PlayerInformation* _info;
+       wxPreferencesEditor* _config_dialog;
        FilmViewer* _viewer;
        boost::shared_ptr<Film> _film;
+       boost::signals2::scoped_connection _config_changed_connection;
 };
 
 static const wxCmdLineEntryDesc command_line_description[] = {