Remove required Film from content examine.
[dcpomatic.git] / src / tools / dcpomatic_playlist.cc
index 04beb0250f2962cd55d10c4c284f25d9bed86835..2bb9ec2a70408df5d1f5fe84bf28e54773e9d281 100644 (file)
 #include "../lib/cross.h"
 #include "../lib/film.h"
 #include "../lib/dcp_content.h"
+#include "../lib/spl_entry.h"
+#include "../lib/spl.h"
 #include <wx/wx.h>
 #include <wx/listctrl.h>
 #include <wx/imaglist.h>
 
 using std::exception;
 using std::cout;
+using std::string;
 using boost::optional;
 using boost::shared_ptr;
 using boost::weak_ptr;
 using boost::bind;
 using boost::dynamic_pointer_cast;
 
-class PlaylistEntry
-{
-public:
-       PlaylistEntry (boost::shared_ptr<Content> content)
-               : skippable (false)
-               , disable_timeline (false)
-               , stop_after_play (false)
-       {
-               shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (content);
-               if (dcp) {
-                       name = dcp->name ();
-                       cpl_id = dcp->cpl().get_value_or("");
-                       kind = dcp->content_kind().get_value_or(dcp::FEATURE);
-                       type = DCP;
-                       encrypted = dcp->encrypted ();
-               } else {
-                       name = content->path(0).filename().string();
-                       type = ECINEMA;
-               }
-       }
-
-       std::string name;
-       std::string cpl_id;
-       dcp::ContentKind kind;
-       enum Type {
-               DCP,
-               ECINEMA
-       };
-       Type type;
-       bool encrypted;
-       bool skippable;
-       bool disable_timeline;
-       bool stop_after_play;
-};
-
-class ContentDialog : public wxDialog
+class ContentDialog : public wxDialog, public ContentStore
 {
 public:
        ContentDialog (wxWindow* parent, weak_ptr<Film> film)
                : wxDialog (parent, wxID_ANY, _("Add content"), wxDefaultPosition, wxSize(800, 640))
-               , _content_view (new ContentView(this, film))
+               , _content_view (new ContentView(this))
        {
                _content_view->update ();
 
@@ -100,6 +68,11 @@ public:
                return _content_view->selected ();
        }
 
+       shared_ptr<Content> get (string digest) const
+       {
+               return _content_view->get (digest);
+       }
+
 private:
        ContentView* _content_view;
 };
@@ -175,19 +148,21 @@ public:
                _down->Bind (wxEVT_BUTTON, bind(&DOMFrame::down_clicked, this));
                _add->Bind (wxEVT_BUTTON, bind(&DOMFrame::add_clicked, this));
                _remove->Bind (wxEVT_BUTTON, bind(&DOMFrame::remove_clicked, this));
+               _save->Bind (wxEVT_BUTTON, bind(&DOMFrame::save_clicked, this));
+               _load->Bind (wxEVT_BUTTON, bind(&DOMFrame::load_clicked, this));
 
                setup_sensitivity ();
        }
 
 private:
 
-       void add (PlaylistEntry e)
+       void add (SPLEntry e)
        {
                wxListItem item;
                item.SetId (_list->GetItemCount());
                long const N = _list->InsertItem (item);
                set_item (N, e);
-               _playlist.push_back (e);
+               _playlist.add (e);
        }
 
        void selection_changed ()
@@ -195,12 +170,12 @@ private:
                setup_sensitivity ();
        }
 
-       void set_item (long N, PlaylistEntry e)
+       void set_item (long N, SPLEntry e)
        {
                _list->SetItem (N, 0, std_to_wx(e.name));
-               _list->SetItem (N, 1, std_to_wx(e.cpl_id));
+               _list->SetItem (N, 1, std_to_wx(e.id));
                _list->SetItem (N, 2, std_to_wx(dcp::content_kind_to_string(e.kind)));
-               _list->SetItem (N, 3, e.type == PlaylistEntry::DCP ? _("DCP") : _("E-cinema"));
+               _list->SetItem (N, 3, e.type == SPLEntry::DCP ? _("DCP") : _("E-cinema"));
                _list->SetItem (N, 4, e.encrypted ? _("Y") : _("N"));
                _list->SetItem (N, COLUMN_SKIPPABLE, wxEmptyString, e.skippable ? 0 : 1);
                _list->SetItem (N, COLUMN_DISABLE_TIMELINE, wxEmptyString, e.disable_timeline ? 0 : 1);
@@ -256,7 +231,7 @@ private:
                if (r == wxID_OK) {
                        shared_ptr<Content> content = _content_dialog->selected ();
                        if (content) {
-                               add (PlaylistEntry(content));
+                               add (SPLEntry(content));
                        }
                }
        }
@@ -268,7 +243,7 @@ private:
                        return;
                }
 
-               PlaylistEntry tmp = _playlist[s];
+               SPLEntry tmp = _playlist[s];
                _playlist[s] = _playlist[s-1];
                _playlist[s-1] = tmp;
 
@@ -283,7 +258,7 @@ private:
                        return;
                }
 
-               PlaylistEntry tmp = _playlist[s];
+               SPLEntry tmp = _playlist[s];
                _playlist[s] = _playlist[s+1];
                _playlist[s+1] = tmp;
 
@@ -298,10 +273,29 @@ private:
                        return;
                }
 
-               _playlist.erase (_playlist.begin() + s);
+               _playlist.remove (s);
                _list->DeleteItem (s);
        }
 
+       void save_clicked ()
+       {
+               wxFileDialog* d = new wxFileDialog (this, _("Select playlist file"), wxEmptyString, wxEmptyString, wxT("XML files (*.xml)|*.xml"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
+               if (d->ShowModal() == wxID_OK) {
+                       _playlist.write (wx_to_std(d->GetPath()));
+               }
+       }
+
+       void load_clicked ()
+       {
+               wxFileDialog* d = new wxFileDialog (this, _("Select playlist file"), wxEmptyString, wxEmptyString, wxT("XML files (*.xml)|*.xml"));
+               if (d->ShowModal() == wxID_OK) {
+                       _list->DeleteAllItems ();
+                       if (_playlist.read (wx_to_std(d->GetPath()), _content_dialog)) {
+                               error_dialog (this, _("Some content in this playlist was not found."));
+                       }
+               }
+       }
+
        wxListCtrl* _list;
        wxButton* _up;
        wxButton* _down;
@@ -310,7 +304,7 @@ private:
        wxButton* _save;
        wxButton* _load;
        boost::shared_ptr<Film> _film;
-       std::vector<PlaylistEntry> _playlist;
+       SPL _playlist;
        ContentDialog* _content_dialog;
 
        enum {