2 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <wx/dirdlg.h>
22 #include "lib/playlist.h"
24 #include "lib/moving_image_content.h"
25 #include "lib/content_factory.h"
26 #include "lib/examine_content_job.h"
27 #include "lib/job_manager.h"
28 #include "content_menu.h"
29 #include "repeat_dialog.h"
33 using boost::shared_ptr;
34 using boost::weak_ptr;
35 using boost::dynamic_pointer_cast;
43 ContentMenu::ContentMenu (shared_ptr<Film> f, wxWindow* p)
48 _repeat = _menu->Append (ID_repeat, _("Repeat..."));
49 _find_missing = _menu->Append (ID_find_missing, _("Find missing..."));
50 _menu->AppendSeparator ();
51 _remove = _menu->Append (ID_remove, _("Remove"));
53 _parent->Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&ContentMenu::repeat, this), ID_repeat);
54 _parent->Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&ContentMenu::find_missing, this), ID_find_missing);
55 _parent->Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&ContentMenu::remove, this), ID_remove);
58 ContentMenu::~ContentMenu ()
64 ContentMenu::popup (ContentList c, wxPoint p)
67 _repeat->Enable (!_content.empty ());
68 _find_missing->Enable (_content.size() == 1 && !_content.front()->path_valid ());
69 _remove->Enable (!_content.empty ());
70 _parent->PopupMenu (_menu, p);
74 ContentMenu::repeat ()
76 if (_content.empty ()) {
80 RepeatDialog* d = new RepeatDialog (_parent);
81 if (d->ShowModal() != wxID_OK) {
86 shared_ptr<const Film> film = _film.lock ();
91 film->playlist()->repeat (_content, d->number ());
98 ContentMenu::remove ()
100 if (_content.empty ()) {
104 shared_ptr<const Film> film = _film.lock ();
109 film->playlist()->remove (_content);
115 ContentMenu::find_missing ()
117 if (_content.size() != 1) {
121 shared_ptr<const Film> film = _film.lock ();
126 shared_ptr<Content> content;
128 /* XXX: a bit nasty */
129 if (dynamic_pointer_cast<MovingImageContent> (_content.front ())) {
130 wxDirDialog* d = new wxDirDialog (0, _("Choose a folder"), wxT (""), wxDD_DIR_MUST_EXIST);
131 int const r = d->ShowModal ();
133 content.reset (new MovingImageContent (film, boost::filesystem::path (wx_to_std (d->GetPath ()))));
137 wxFileDialog* d = new wxFileDialog (0, _("Choose a file"), wxT (""), wxT (""), wxT ("*.*"), wxFD_MULTIPLE);
138 int const r = d->ShowModal ();
140 content = content_factory (film, wx_to_std (d->GetPath ()));
149 shared_ptr<Job> j (new ExamineContentJob (film, content));
151 j->Finished.connect (
153 &ContentMenu::maybe_found_missing,
155 boost::weak_ptr<Job> (j),
156 boost::weak_ptr<Content> (_content.front ()),
157 boost::weak_ptr<Content> (content)
161 JobManager::instance()->add (j);
165 ContentMenu::maybe_found_missing (weak_ptr<Job> j, weak_ptr<Content> oc, weak_ptr<Content> nc)
167 shared_ptr<Job> job = j.lock ();
168 if (!job || !job->finished_ok ()) {
172 shared_ptr<Content> old_content = oc.lock ();
173 shared_ptr<Content> new_content = nc.lock ();
174 assert (old_content);
175 assert (new_content);
177 if (new_content->digest() != old_content->digest()) {
178 error_dialog (0, _("The content file(s) you specified are not the same as those that are missing. Either try again with the correct content file or remove the missing content."));
182 old_content->set_path (new_content->path ());