From baed0f37f3cb3375f39b8d44f01eadb8796eb0d5 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 11:34:09 +0100 Subject: Generalise the Changed message from SPL. --- src/lib/spl.h | 9 +++++++-- src/tools/dcpomatic_playlist.cc | 16 +++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/lib/spl.h b/src/lib/spl.h index 9637f6189..fa8f38105 100644 --- a/src/lib/spl.h +++ b/src/lib/spl.h @@ -93,6 +93,11 @@ private: class SignalSPL : public SPL { public: + enum class Change { + NAME, + CONTENT, + }; + SignalSPL () {} SignalSPL (std::string name) @@ -101,10 +106,10 @@ public: void set_name (std::string name) { SPL::set_name (name); - NameChanged (); + Changed(Change::NAME); } - boost::signals2::signal NameChanged; + boost::signals2::signal Changed; }; #endif diff --git a/src/tools/dcpomatic_playlist.cc b/src/tools/dcpomatic_playlist.cc index c327a8603..9eada8b38 100644 --- a/src/tools/dcpomatic_playlist.cc +++ b/src/tools/dcpomatic_playlist.cc @@ -166,22 +166,24 @@ private: void add_playlist_to_model (shared_ptr playlist) { _playlists.push_back (playlist); - playlist->NameChanged.connect (bind(&PlaylistList::name_changed, this, weak_ptr(playlist))); + playlist->Changed.connect(bind(&PlaylistList::changed, this, weak_ptr(playlist), _1)); } - void name_changed (weak_ptr wp) + void changed(weak_ptr wp, SignalSPL::Change change) { auto playlist = wp.lock (); if (!playlist) { return; } - int N = 0; - for (auto i: _playlists) { - if (i == playlist) { - _list->SetItem (N, 0, std_to_wx(i->name())); + if (change == SignalSPL::Change::NAME) { + int N = 0; + for (auto i: _playlists) { + if (i == playlist) { + _list->SetItem (N, 0, std_to_wx(i->name())); + } + ++N; } - ++N; } } -- cgit v1.2.3 From 0c5f0e48080a28d3cfa9f8e2f4948bbc57bc0307 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 11:51:54 +0100 Subject: Cleanup: white space. --- src/lib/spl.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib/spl.h b/src/lib/spl.h index fa8f38105..49eb93df2 100644 --- a/src/lib/spl.h +++ b/src/lib/spl.h @@ -18,15 +18,18 @@ */ + #ifndef DCPOMATIC_SPL_H #define DCPOMATIC_SPL_H + #include "spl_entry.h" #include #include class ContentStore; + class SPL { public: -- cgit v1.2.3 From bf471e4e6d2502bb3b4e2eb4b1309d87e1003070 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 11:52:33 +0100 Subject: Add and use SPL::swap(). --- src/lib/spl.h | 4 ++++ src/tools/dcpomatic_playlist.cc | 8 ++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/spl.h b/src/lib/spl.h index 49eb93df2..d7c746d1e 100644 --- a/src/lib/spl.h +++ b/src/lib/spl.h @@ -26,6 +26,8 @@ #include "spl_entry.h" #include #include +#include + class ContentStore; @@ -63,6 +65,8 @@ public: SPLEntry const & operator[] (std::size_t index) const { return _spl[index]; + void swap(size_t a, size_t b) { + std::iter_swap(_spl.begin() + a, _spl.begin() + b); } void read (boost::filesystem::path path, ContentStore* store); diff --git a/src/tools/dcpomatic_playlist.cc b/src/tools/dcpomatic_playlist.cc index 9eada8b38..5a8ee9126 100644 --- a/src/tools/dcpomatic_playlist.cc +++ b/src/tools/dcpomatic_playlist.cc @@ -402,9 +402,7 @@ private: DCPOMATIC_ASSERT (_playlist); - auto tmp = (*_playlist)[s]; - (*_playlist)[s] = (*_playlist)[s-1]; - (*_playlist)[s-1] = tmp; + _playlist->swap(s, s - 1); set_item (s - 1, (*_playlist)[s-1]); set_item (s, (*_playlist)[s]); @@ -419,9 +417,7 @@ private: DCPOMATIC_ASSERT (_playlist); - auto tmp = (*_playlist)[s]; - (*_playlist)[s] = (*_playlist)[s+1]; - (*_playlist)[s+1] = tmp; + _playlist->swap(s, s + 1); set_item (s + 1, (*_playlist)[s+1]); set_item (s, (*_playlist)[s]); -- cgit v1.2.3 From 704e1112538d809fd55bd7f25385eaa5d064966c Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 11:52:54 +0100 Subject: Remove unnecessary non-const operator[]. --- src/lib/spl.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib/spl.h b/src/lib/spl.h index d7c746d1e..b002a0882 100644 --- a/src/lib/spl.h +++ b/src/lib/spl.h @@ -59,12 +59,10 @@ public: return _spl; } - SPLEntry & operator[] (std::size_t index) { + SPLEntry const & operator[] (std::size_t index) const { return _spl[index]; } - SPLEntry const & operator[] (std::size_t index) const { - return _spl[index]; void swap(size_t a, size_t b) { std::iter_swap(_spl.begin() + a, _spl.begin() + b); } -- cgit v1.2.3 From a733da8088152a2487691629753fe8a2addfa5a3 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 20:00:09 +0100 Subject: Save playlist when content is added, moved or removed. --- src/lib/spl.h | 15 +++++++++++++++ src/tools/dcpomatic_playlist.cc | 11 ++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/lib/spl.h b/src/lib/spl.h index b002a0882..f55a9fe1f 100644 --- a/src/lib/spl.h +++ b/src/lib/spl.h @@ -114,6 +114,21 @@ public: Changed(Change::NAME); } + void add(SPLEntry e) { + SPL::add(e); + Changed(Change::CONTENT); + } + + void remove(std::size_t index) { + SPL::remove(index); + Changed(Change::CONTENT); + } + + void swap(size_t a, size_t b) { + SPL::swap(a, b); + Changed(Change::CONTENT); + } + boost::signals2::signal Changed; }; diff --git a/src/tools/dcpomatic_playlist.cc b/src/tools/dcpomatic_playlist.cc index 5a8ee9126..5368cb3af 100644 --- a/src/tools/dcpomatic_playlist.cc +++ b/src/tools/dcpomatic_playlist.cc @@ -176,7 +176,9 @@ private: return; } - if (change == SignalSPL::Change::NAME) { + switch (change) { + case SignalSPL::Change::NAME: + { int N = 0; for (auto i: _playlists) { if (i == playlist) { @@ -184,6 +186,13 @@ private: } ++N; } + break; + } + case SignalSPL::Change::CONTENT: + if (auto dir = Config::instance()->player_playlist_directory()) { + playlist->write(*dir / (playlist->id() + ".xml")); + } + break; } } -- cgit v1.2.3 From 76e340c36a7c0da70b145c0437b5758eaa7134dc Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 20:02:09 +0100 Subject: Don't display first playlist on startup. --- src/tools/dcpomatic_playlist.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tools/dcpomatic_playlist.cc b/src/tools/dcpomatic_playlist.cc index 5368cb3af..bc1f78dc3 100644 --- a/src/tools/dcpomatic_playlist.cc +++ b/src/tools/dcpomatic_playlist.cc @@ -484,8 +484,6 @@ public: _playlist_list->Edit.connect (bind(&DOMFrame::change_playlist, this, _1)); - _playlist_content->set (_playlist_list->first_playlist()); - 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); -- cgit v1.2.3 From 7709de3a8d94aa00e01d7f86504cab7a5c77e564 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 20:04:32 +0100 Subject: Setup editor sensitivity on startup. --- src/tools/dcpomatic_playlist.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tools/dcpomatic_playlist.cc b/src/tools/dcpomatic_playlist.cc index bc1f78dc3..05dea1f33 100644 --- a/src/tools/dcpomatic_playlist.cc +++ b/src/tools/dcpomatic_playlist.cc @@ -323,6 +323,8 @@ public: _down->Bind (wxEVT_BUTTON, bind(&PlaylistContent::down_clicked, this)); _add->Bind (wxEVT_BUTTON, bind(&PlaylistContent::add_clicked, this)); _remove->Bind (wxEVT_BUTTON, bind(&PlaylistContent::remove_clicked, this)); + + setup_sensitivity(); } wxSizer* sizer () -- cgit v1.2.3 From 05fff51f80d5a2d5728fd40472d1c1e0f9e00300 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 20:12:56 +0100 Subject: Extract selected(). --- src/tools/dcpomatic_playlist.cc | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/tools/dcpomatic_playlist.cc b/src/tools/dcpomatic_playlist.cc index 05dea1f33..835582c09 100644 --- a/src/tools/dcpomatic_playlist.cc +++ b/src/tools/dcpomatic_playlist.cc @@ -226,10 +226,20 @@ private: _list->SetItemState (_list->GetItemCount() - 1, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); } - void delete_playlist () + boost::optional selected() const { - long int selected = _list->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + long int selected = _list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (selected < 0 || selected >= int(_playlists.size())) { + return {}; + } + + return selected; + } + + void delete_playlist () + { + auto index = selected(); + if (!index) { return; } @@ -238,11 +248,11 @@ private: return; } - boost::filesystem::remove (*dir / (_playlists[selected]->id() + ".xml")); - _list->DeleteItem (selected); - _playlists.erase (_playlists.begin() + selected); + boost::filesystem::remove(*dir / (_playlists[*index]->id() + ".xml")); + _list->DeleteItem(*index); + _playlists.erase(_playlists.begin() + *index); - Edit (shared_ptr()); + Edit(shared_ptr()); } void selection_changed () -- cgit v1.2.3 From 9319f03bb4efd1182a710864f69a1d64c4ec9920 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 20:13:14 +0100 Subject: Set Delete button sensitivity correctly. --- src/tools/dcpomatic_playlist.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/tools/dcpomatic_playlist.cc b/src/tools/dcpomatic_playlist.cc index 835582c09..3e3bd0266 100644 --- a/src/tools/dcpomatic_playlist.cc +++ b/src/tools/dcpomatic_playlist.cc @@ -136,6 +136,8 @@ public: _list->Bind (wxEVT_COMMAND_LIST_ITEM_DESELECTED, bind(&PlaylistList::selection_changed, this)); _new->Bind (wxEVT_BUTTON, bind(&PlaylistList::new_playlist, this)); _delete->Bind (wxEVT_BUTTON, bind(&PlaylistList::delete_playlist, this)); + + setup_sensitivity(); } wxSizer* sizer () @@ -155,6 +157,11 @@ public: boost::signals2::signal)> Edit; private: + void setup_sensitivity() + { + _delete->Enable(static_cast(selected())); + } + void add_playlist_to_view (shared_ptr playlist) { wxListItem item; @@ -263,6 +270,8 @@ private: } else { Edit (_playlists[selected]); } + + setup_sensitivity(); } wxBoxSizer* _sizer; -- cgit v1.2.3 From 62c03e3d3493df8a31361b3281c443cac35decb0 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 20:16:28 +0100 Subject: Add bind(). --- src/wx/dcpomatic_button.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/wx/dcpomatic_button.h b/src/wx/dcpomatic_button.h index 902c85666..6de8b60f4 100644 --- a/src/wx/dcpomatic_button.h +++ b/src/wx/dcpomatic_button.h @@ -28,6 +28,7 @@ LIBDCP_DISABLE_WARNINGS #include LIBDCP_ENABLE_WARNINGS +#include class Button : public wxButton, public I18NHook @@ -37,6 +38,11 @@ public: void set_text (wxString text) override; wxString get_text () const override; + + template + void bind(Args... args) { + Bind(wxEVT_BUTTON, boost::bind(std::forward(args)...)); + } }; -- cgit v1.2.3 From 986a681d008c432f68a4ff67d44e7a019ceab1a5 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 20:24:56 +0100 Subject: Check for playlist directory on new playlist, rather than save. --- src/tools/dcpomatic_playlist.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/tools/dcpomatic_playlist.cc b/src/tools/dcpomatic_playlist.cc index 3e3bd0266..4a4407b02 100644 --- a/src/tools/dcpomatic_playlist.cc +++ b/src/tools/dcpomatic_playlist.cc @@ -106,6 +106,7 @@ public: PlaylistList (wxPanel* parent, ContentStore* content_store) : _sizer (new wxBoxSizer(wxVERTICAL)) , _content_store (content_store) + , _parent(parent) { auto label = new wxStaticText (parent, wxID_ANY, wxEmptyString); label->SetLabelMarkup (_("Playlists")); @@ -227,6 +228,12 @@ private: void new_playlist () { + auto dir = Config::instance()->player_playlist_directory(); + if (!dir) { + error_dialog(_parent, _("No playlist folder is specified in preferences. Please set one and then try again.")); + return; + } + shared_ptr spl (new SignalSPL(wx_to_std(_("New Playlist")))); add_playlist_to_model (spl); add_playlist_to_view (spl); @@ -280,6 +287,7 @@ private: wxButton* _delete; vector> _playlists; ContentStore* _content_store; + wxWindow* _parent; }; @@ -546,12 +554,9 @@ private: void save_playlist (shared_ptr playlist) { - auto dir = Config::instance()->player_playlist_directory(); - if (!dir) { - error_dialog (this, _("No playlist folder is specified in preferences. Please set one and then try again.")); - return; + if (auto dir = Config::instance()->player_playlist_directory()) { + playlist->write(*dir / (playlist->id() + ".xml")); } - playlist->write (*dir / (playlist->id() + ".xml")); } void setup_menu (wxMenuBar* m) -- cgit v1.2.3 From 5c444b35b60c34654ccef73c47e1e1bdda1f44ee Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 20:29:07 +0100 Subject: Extract save_playlist(). --- src/tools/dcpomatic_playlist.cc | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/tools/dcpomatic_playlist.cc b/src/tools/dcpomatic_playlist.cc index 4a4407b02..636a50f8a 100644 --- a/src/tools/dcpomatic_playlist.cc +++ b/src/tools/dcpomatic_playlist.cc @@ -59,6 +59,16 @@ using namespace boost::placeholders; #endif +static +void +save_playlist(shared_ptr playlist) +{ + if (auto dir = Config::instance()->player_playlist_directory()) { + playlist->write(*dir / (playlist->id() + ".xml")); + } +} + + class ContentDialog : public wxDialog, public ContentStore { public: @@ -197,9 +207,7 @@ private: break; } case SignalSPL::Change::CONTENT: - if (auto dir = Config::instance()->player_playlist_directory()) { - playlist->write(*dir / (playlist->id() + ".xml")); - } + save_playlist(playlist); break; } } @@ -552,13 +560,6 @@ private: _playlist_content->set (playlist); } - void save_playlist (shared_ptr playlist) - { - if (auto dir = Config::instance()->player_playlist_directory()) { - playlist->write(*dir / (playlist->id() + ".xml")); - } - } - void setup_menu (wxMenuBar* m) { auto file = new wxMenu; -- cgit v1.2.3 From 68397475b07181446d9593ca65c88c6261934afd Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 20:35:39 +0100 Subject: Add save button for playlist name. --- src/tools/dcpomatic_playlist.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/tools/dcpomatic_playlist.cc b/src/tools/dcpomatic_playlist.cc index 636a50f8a..175eafac7 100644 --- a/src/tools/dcpomatic_playlist.cc +++ b/src/tools/dcpomatic_playlist.cc @@ -312,6 +312,8 @@ public: title->Add (label, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, DCPOMATIC_SIZER_GAP); _name = new wxTextCtrl (parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(400, -1)); title->Add (_name, 0, wxRIGHT, DCPOMATIC_SIZER_GAP); + _save_name = new Button(parent, _("Save")); + title->Add(_save_name); _sizer->Add (title, 0, wxTOP | wxLEFT, DCPOMATIC_SIZER_GAP * 2); auto list = new wxBoxSizer (wxHORIZONTAL); @@ -354,6 +356,7 @@ public: _list->Bind (wxEVT_COMMAND_LIST_ITEM_SELECTED, bind(&PlaylistContent::setup_sensitivity, this)); _list->Bind (wxEVT_COMMAND_LIST_ITEM_DESELECTED, bind(&PlaylistContent::setup_sensitivity, this)); _name->Bind (wxEVT_TEXT, bind(&PlaylistContent::name_changed, this)); + _save_name->bind(&PlaylistContent::save_name_clicked, this); _up->Bind (wxEVT_BUTTON, bind(&PlaylistContent::up_clicked, this)); _down->Bind (wxEVT_BUTTON, bind(&PlaylistContent::down_clicked, this)); _add->Bind (wxEVT_BUTTON, bind(&PlaylistContent::add_clicked, this)); @@ -389,11 +392,18 @@ public: private: - void name_changed () + void save_name_clicked() { if (_playlist) { - _playlist->set_name (wx_to_std(_name->GetValue())); + _playlist->set_name(wx_to_std(_name->GetValue())); + save_playlist(_playlist); } + setup_sensitivity(); + } + + void name_changed () + { + setup_sensitivity(); } void add (SPLEntry e) @@ -418,6 +428,7 @@ private: int const num_selected = _list->GetSelectedItemCount (); long int selected = _list->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); _name->Enable (have_list); + _save_name->Enable(_playlist && _playlist->name() != wx_to_std(_name->GetValue())); _list->Enable (have_list); _up->Enable (have_list && selected > 0); _down->Enable (have_list && selected != -1 && selected < (_list->GetItemCount() - 1)); @@ -484,6 +495,7 @@ private: ContentDialog* _content_dialog; wxBoxSizer* _sizer; wxTextCtrl* _name; + Button* _save_name; wxListCtrl* _list; wxButton* _up; wxButton* _down; -- cgit v1.2.3 From ff3e116f48298bbee68a3f5679bffd509930c19b Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 20:43:23 +0100 Subject: Double-click on content list adds the content. --- src/tools/dcpomatic_playlist.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/dcpomatic_playlist.cc b/src/tools/dcpomatic_playlist.cc index 175eafac7..96dff56ed 100644 --- a/src/tools/dcpomatic_playlist.cc +++ b/src/tools/dcpomatic_playlist.cc @@ -90,6 +90,7 @@ public: overall_sizer->Layout (); + _content_view->Bind(wxEVT_LIST_ITEM_ACTIVATED, boost::bind(&ContentDialog::EndModal, this, wxID_OK)); _config_changed_connection = Config::instance()->Changed.connect(boost::bind(&ContentView::update, _content_view)); } -- cgit v1.2.3