BOOST_FOREACH.
[dcpomatic.git] / src / tools / dcpomatic_playlist.cc
index 7751fc1b31ff671df783a9bf90efd025bb4e72e0..1dca8c182f53e19d0320b911c86e971b7c41d105 100644 (file)
@@ -23,7 +23,7 @@
 #include "../wx/content_view.h"
 #include "../wx/dcpomatic_button.h"
 #include "../wx/about_dialog.h"
-#include "../wx/player_config_dialog.h"
+#include "../wx/playlist_editor_config_dialog.h"
 #include "../lib/util.h"
 #include "../lib/config.h"
 #include "../lib/cross.h"
 #include <wx/imaglist.h>
 #include <wx/spinctrl.h>
 #include <wx/preferences.h>
-#ifdef __WXOSX__
-#include <ApplicationServices/ApplicationServices.h>
-#endif
-#include <boost/foreach.hpp>
 
 using std::exception;
 using std::cout;
@@ -48,10 +44,13 @@ using std::map;
 using std::make_pair;
 using std::vector;
 using boost::optional;
-using boost::shared_ptr;
-using boost::weak_ptr;
+using std::shared_ptr;
+using std::weak_ptr;
 using boost::bind;
-using boost::dynamic_pointer_cast;
+using std::dynamic_pointer_cast;
+#if BOOST_VERSION >= 106100
+using namespace boost::placeholders;
+#endif
 
 class ContentDialog : public wxDialog, public ContentStore
 {
@@ -73,6 +72,8 @@ public:
                }
 
                overall_sizer->Layout ();
+
+               _config_changed_connection = Config::instance()->Changed.connect(boost::bind(&ContentView::update, _content_view));
        }
 
        shared_ptr<Content> selected () const
@@ -87,6 +88,7 @@ public:
 
 private:
        ContentView* _content_view;
+       boost::signals2::scoped_connection _config_changed_connection;
 };
 
 
@@ -134,19 +136,19 @@ public:
                return _sizer;
        }
 
-       shared_ptr<SPL> first_playlist () const
+       shared_ptr<SignalSPL> first_playlist () const
        {
                if (_playlists.empty()) {
-                       return shared_ptr<SPL>();
+                       return shared_ptr<SignalSPL>();
                }
 
                return _playlists.front ();
        }
 
-       boost::signals2::signal<void (shared_ptr<SPL>)> Edit;
+       boost::signals2::signal<void (shared_ptr<SignalSPL>)> Edit;
 
 private:
-       void add_playlist_to_view (shared_ptr<const SPL> playlist)
+       void add_playlist_to_view (shared_ptr<const SignalSPL> playlist)
        {
                wxListItem item;
                item.SetId (_list->GetItemCount());
@@ -154,21 +156,21 @@ private:
                _list->SetItem (N, 0, std_to_wx(playlist->name()));
        }
 
-       void add_playlist_to_model (shared_ptr<SPL> playlist)
+       void add_playlist_to_model (shared_ptr<SignalSPL> playlist)
        {
                _playlists.push_back (playlist);
-               playlist->NameChanged.connect (bind(&PlaylistList::name_changed, this, weak_ptr<SPL>(playlist)));
+               playlist->NameChanged.connect (bind(&PlaylistList::name_changed, this, weak_ptr<SignalSPL>(playlist)));
        }
 
-       void name_changed (weak_ptr<SPL> wp)
+       void name_changed (weak_ptr<SignalSPL> wp)
        {
-               shared_ptr<SPL> playlist = wp.lock ();
+               shared_ptr<SignalSPL> playlist = wp.lock ();
                if (!playlist) {
                        return;
                }
 
                int N = 0;
-               BOOST_FOREACH (shared_ptr<SPL> i, _playlists) {
+               for (auto i: _playlists) {
                        if (i == playlist) {
                                _list->SetItem (N, 0, std_to_wx(i->name()));
                        }
@@ -186,21 +188,21 @@ private:
                _list->DeleteAllItems ();
                _playlists.clear ();
                for (boost::filesystem::directory_iterator i(*path); i != boost::filesystem::directory_iterator(); ++i) {
-                       shared_ptr<SPL> spl(new SPL);
+                       shared_ptr<SignalSPL> spl(new SignalSPL);
                        try {
                                spl->read (*i, _content_store);
                                add_playlist_to_model (spl);
                        } catch (...) {}
                }
 
-               BOOST_FOREACH (shared_ptr<SPL> i, _playlists) {
+               for (auto i: _playlists) {
                        add_playlist_to_view (i);
                }
        }
 
        void new_playlist ()
        {
-               shared_ptr<SPL> spl (new SPL(wx_to_std(_("New Playlist"))));
+               shared_ptr<SignalSPL> spl (new SignalSPL(wx_to_std(_("New Playlist"))));
                add_playlist_to_model (spl);
                add_playlist_to_view (spl);
                _list->SetItemState (_list->GetItemCount() - 1, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
@@ -222,14 +224,14 @@ private:
                _list->DeleteItem (selected);
                _playlists.erase (_playlists.begin() + selected);
 
-               Edit (shared_ptr<SPL>());
+               Edit (shared_ptr<SignalSPL>());
        }
 
        void selection_changed ()
        {
                long int selected = _list->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
                if (selected < 0 || selected >= int(_playlists.size())) {
-                       Edit (shared_ptr<SPL>());
+                       Edit (shared_ptr<SignalSPL>());
                } else {
                        Edit (_playlists[selected]);
                }
@@ -239,7 +241,7 @@ private:
        wxListCtrl* _list;
        wxButton* _new;
        wxButton* _delete;
-       vector<shared_ptr<SPL> > _playlists;
+       vector<shared_ptr<SignalSPL> > _playlists;
        ContentStore* _content_store;
 };
 
@@ -273,15 +275,8 @@ public:
                wxImageList* images = new wxImageList (16, 16);
                wxIcon tick_icon;
                wxIcon no_tick_icon;
-#ifdef DCPOMATIC_OSX
-               tick_icon.LoadFile ("tick.png", wxBITMAP_TYPE_PNG_RESOURCE);
-               no_tick_icon.LoadFile ("no_tick.png", wxBITMAP_TYPE_PNG_RESOURCE);
-#else
-               boost::filesystem::path tick_path = shared_path() / "tick.png";
-               tick_icon.LoadFile (std_to_wx(tick_path.string()));
-               boost::filesystem::path no_tick_path = shared_path() / "no_tick.png";
-               no_tick_icon.LoadFile (std_to_wx(no_tick_path.string()));
-#endif
+               tick_icon.LoadFile (bitmap_path("tick"), wxBITMAP_TYPE_PNG);
+               no_tick_icon.LoadFile (bitmap_path("no_tick"), wxBITMAP_TYPE_PNG);
                images->Add (tick_icon);
                images->Add (no_tick_icon);
 
@@ -317,12 +312,12 @@ public:
                return _sizer;
        }
 
-       void set (shared_ptr<SPL> playlist)
+       void set (shared_ptr<SignalSPL> playlist)
        {
                _playlist = playlist;
                _list->DeleteAllItems ();
                if (_playlist) {
-                       BOOST_FOREACH (SPLEntry i, _playlist->get()) {
+                       for (auto i: _playlist->get()) {
                                add (i);
                        }
                        _name->SetValue (std_to_wx(_playlist->name()));
@@ -332,7 +327,7 @@ public:
                setup_sensitivity ();
        }
 
-       shared_ptr<SPL> playlist () const
+       shared_ptr<SignalSPL> playlist () const
        {
                return _playlist;
        }
@@ -443,7 +438,7 @@ private:
        wxButton* _down;
        wxButton* _add;
        wxButton* _remove;
-       shared_ptr<SPL> _playlist;
+       shared_ptr<SignalSPL> _playlist;
 };
 
 
@@ -453,6 +448,7 @@ public:
        explicit DOMFrame (wxString const & title)
                : wxFrame (0, -1, title)
                , _content_dialog (new ContentDialog(this))
+               , _config_dialog (0)
        {
                wxMenuBar* bar = new wxMenuBar;
                setup_menu (bar);
@@ -479,6 +475,8 @@ public:
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
+
+               _config_changed_connection = Config::instance()->Changed.connect(boost::bind(&DOMFrame::config_changed, this));
        }
 
 private:
@@ -499,25 +497,25 @@ private:
        void edit_preferences ()
        {
                if (!_config_dialog) {
-                       _config_dialog = create_player_config_dialog ();
+                       _config_dialog = create_playlist_editor_config_dialog ();
                }
                _config_dialog->Show (this);
        }
 
-       void change_playlist (shared_ptr<SPL> playlist)
+       void change_playlist (shared_ptr<SignalSPL> playlist)
        {
-               shared_ptr<SPL> old = _playlist_content->playlist ();
+               shared_ptr<SignalSPL> old = _playlist_content->playlist ();
                if (old) {
                        save_playlist (old);
                }
                _playlist_content->set (playlist);
        }
 
-       void save_playlist (shared_ptr<SPL> playlist)
+       void save_playlist (shared_ptr<SignalSPL> playlist)
        {
                optional<boost::filesystem::path> dir = Config::instance()->player_playlist_directory();
                if (!dir) {
-                       error_dialog (this, _("No playlist folder is specified in preferences.  Please set on and then try again."));
+                       error_dialog (this, _("No playlist folder is specified in preferences.  Please set one and then try again."));
                        return;
                }
                playlist->write (*dir / (playlist->id() + ".xml"));
@@ -551,10 +549,28 @@ private:
                m->Append (help, _("&Help"));
        }
 
+
+       void config_changed ()
+       {
+               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()
+                                       )
+                               );
+               }
+       }
+
+
        ContentDialog* _content_dialog;
        PlaylistList* _playlist_list;
        PlaylistContent* _playlist_content;
        wxPreferencesEditor* _config_dialog;
+       boost::signals2::scoped_connection _config_changed_connection;
 };
 
 /** @class App
@@ -573,7 +589,8 @@ private:
        bool OnInit ()
        try
        {
-               SetAppName (_("DCP-o-matic KDM Creator"));
+               wxInitAllImageHandlers ();
+               SetAppName (_("DCP-o-matic Playlist Editor"));
 
                if (!wxApp::OnInit()) {
                        return false;
@@ -583,10 +600,8 @@ private:
                unsetenv ("UBUNTU_MENUPROXY");
 #endif
 
-#ifdef __WXOSX__
-               ProcessSerialNumber serial;
-               GetCurrentProcess (&serial);
-               TransformProcessType (&serial, kProcessTransformToForegroundApplication);
+#ifdef DCPOMATIC_OSX
+               make_foreground_application ();
 #endif
 
                dcpomatic_setup_path_encoding ();