X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Ftools%2Fdcpomatic_playlist.cc;h=b16a2be68338ed85a0195e8d174f49e4d3d120c0;hb=15b24b1cc77f6f612f0d900c258e5a520e666ca8;hp=5a8ee91267a9cb27aa65dbc42f828a36fe6257fd;hpb=bf471e4e6d2502bb3b4e2eb4b1309d87e1003070;p=dcpomatic.git diff --git a/src/tools/dcpomatic_playlist.cc b/src/tools/dcpomatic_playlist.cc index 5a8ee9126..b16a2be68 100644 --- a/src/tools/dcpomatic_playlist.cc +++ b/src/tools/dcpomatic_playlist.cc @@ -26,12 +26,13 @@ #include "wx/wx_signal_manager.h" #include "wx/wx_util.h" #include "lib/config.h" +#include "lib/constants.h" #include "lib/cross.h" #include "lib/dcp_content.h" #include "lib/film.h" #include "lib/spl.h" #include "lib/spl_entry.h" -#include "lib/util.h" +#include #include LIBDCP_DISABLE_WARNINGS #include @@ -59,6 +60,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: @@ -80,6 +91,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)); } @@ -106,6 +118,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")); @@ -136,6 +149,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 +170,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; @@ -176,7 +196,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 +206,11 @@ private: } ++N; } + break; + } + case SignalSPL::Change::CONTENT: + save_playlist(playlist); + break; } } @@ -196,13 +223,15 @@ private: _list->DeleteAllItems (); _playlists.clear (); - for (auto i: boost::filesystem::directory_iterator(*path)) { - auto spl = make_shared(); - try { - spl->read (i, _content_store); - add_playlist_to_model (spl); - } catch (...) {} - } + try { + for (auto i: dcp::filesystem::directory_iterator(*path)) { + auto spl = make_shared(); + try { + spl->read (i, _content_store); + add_playlist_to_model (spl); + } catch (...) {} + } + } catch (...) {} for (auto i: _playlists) { add_playlist_to_view (i); @@ -211,16 +240,32 @@ 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); _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; } @@ -229,11 +274,11 @@ private: return; } - boost::filesystem::remove (*dir / (_playlists[selected]->id() + ".xml")); - _list->DeleteItem (selected); - _playlists.erase (_playlists.begin() + selected); + dcp::filesystem::remove(*dir / (_playlists[*index]->id() + ".xml")); + _list->DeleteItem(*index); + _playlists.erase(_playlists.begin() + *index); - Edit (shared_ptr()); + Edit(shared_ptr()); } void selection_changed () @@ -244,6 +289,8 @@ private: } else { Edit (_playlists[selected]); } + + setup_sensitivity(); } wxBoxSizer* _sizer; @@ -252,6 +299,7 @@ private: wxButton* _delete; vector> _playlists; ContentStore* _content_store; + wxWindow* _parent; }; @@ -268,6 +316,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); @@ -281,16 +331,6 @@ public: _list->AppendColumn (_("Type"), wxLIST_FORMAT_LEFT, 100); _list->AppendColumn (_("Encrypted"), wxLIST_FORMAT_CENTRE, 90); - auto images = new wxImageList (16, 16); - wxIcon tick_icon; - wxIcon no_tick_icon; - tick_icon.LoadFile (bitmap_path("tick.png"), wxBITMAP_TYPE_PNG); - no_tick_icon.LoadFile (bitmap_path("no_tick.png"), wxBITMAP_TYPE_PNG); - images->Add (tick_icon); - images->Add (no_tick_icon); - - _list->SetImageList (images, wxIMAGE_LIST_SMALL); - list->Add (_list, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP); auto button_sizer = new wxBoxSizer (wxVERTICAL); @@ -310,10 +350,13 @@ 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)); _remove->Bind (wxEVT_BUTTON, bind(&PlaylistContent::remove_clicked, this)); + + setup_sensitivity(); } wxSizer* sizer () @@ -343,11 +386,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) @@ -372,6 +422,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)); @@ -438,6 +489,7 @@ private: ContentDialog* _content_dialog; wxBoxSizer* _sizer; wxTextCtrl* _name; + Button* _save_name; wxListCtrl* _list; wxButton* _up; wxButton* _down; @@ -475,8 +527,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); @@ -494,9 +544,8 @@ private: void help_about () { - auto d = new AboutDialog (this); + auto d = make_wx(this); d->ShowModal (); - d->Destroy (); } void edit_preferences () @@ -516,45 +565,38 @@ private: _playlist_content->set (playlist); } - void save_playlist (shared_ptr playlist) + void setup_menu (wxMenuBar* m) { - 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; +#ifdef DCPOMATIC_OSX + auto help = new wxMenu; + /* These just need to be appended somewhere, it seems - they magically + * get moved to the right place. + */ + if (!Config::instance()->playlist_editor_restricted_menus()) { + help->Append(wxID_PREFERENCES, _("&Preferences...\tCtrl-,")); } - playlist->write (*dir / (playlist->id() + ".xml")); - } + help->Append(wxID_EXIT, _("&Exit")); + help->Append(wxID_ABOUT, _("About DCP-o-matic")); - void setup_menu (wxMenuBar* m) - { - auto file = new wxMenu; -#ifdef __WXOSX__ - file->Append (wxID_EXIT, _("&Exit")); + m->Append(help, _("&Help")); #else - file->Append (wxID_EXIT, _("&Quit")); -#endif + auto file = new wxMenu; + file->Append(wxID_EXIT, _("&Quit")); -#ifndef __WXOSX__ auto edit = new wxMenu; - edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P")); -#endif + edit->Append(wxID_PREFERENCES, _("&Preferences...\tCtrl-P")); auto help = new wxMenu; -#ifdef __WXOSX__ - help->Append (wxID_ABOUT, _("About DCP-o-matic")); -#else - help->Append (wxID_ABOUT, _("About")); -#endif + help->Append(wxID_ABOUT, _("About")); - m->Append (file, _("&File")); -#ifndef __WXOSX__ - m->Append (edit, _("&Edit")); + m->Append(file, _("&File")); + if (!Config::instance()->playlist_editor_restricted_menus()) { + m->Append(edit, _("&Edit")); + m->Append(help, _("&Help")); + } #endif - m->Append (help, _("&Help")); } - void config_changed () { try {