No-op; fix GPL address and use the explicit-program-name version.
[dcpomatic.git] / src / wx / filter_editor.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 /** @file  src/filter_editor.cc
22  *  @brief A panel to select FFmpeg filters.
23  */
24
25 #include <iostream>
26 #include <algorithm>
27 #include "lib/filter.h"
28 #include "filter_editor.h"
29 #include "wx_util.h"
30
31 using namespace std;
32
33 FilterEditor::FilterEditor (wxWindow* parent, vector<Filter const *> const & active)
34         : wxPanel (parent)
35 {
36         wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
37         SetSizer (sizer);
38
39         vector<Filter const *> filters = Filter::all ();
40
41         typedef map<string, list<Filter const *> > CategoryMap;
42         CategoryMap categories;
43
44         for (vector<Filter const *>::iterator i = filters.begin(); i != filters.end(); ++i) {
45                 CategoryMap::iterator j = categories.find ((*i)->category ());
46                 if (j == categories.end ()) {
47                         list<Filter const *> c;
48                         c.push_back (*i);
49                         categories[(*i)->category()] = c;
50                 } else {
51                         j->second.push_back (*i);
52                 }
53         }
54
55         for (CategoryMap::iterator i = categories.begin(); i != categories.end(); ++i) {
56
57                 wxStaticText* c = new wxStaticText (this, wxID_ANY, std_to_wx (i->first));
58                 wxFont font = c->GetFont();
59                 font.SetWeight(wxFONTWEIGHT_BOLD);
60                 c->SetFont(font);
61                 sizer->Add (c);
62
63                 for (list<Filter const *>::iterator j = i->second.begin(); j != i->second.end(); ++j) {
64                         wxCheckBox* b = new wxCheckBox (this, wxID_ANY, std_to_wx ((*j)->name ()));
65                         bool const a = find (active.begin(), active.end(), *j) != active.end ();
66                         b->SetValue (a);
67                         _filters[*j] = b;
68                         b->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&FilterEditor::filter_toggled, this));
69                         sizer->Add (b);
70                 }
71
72                 sizer->AddSpacer (6);
73         }
74 }
75
76 void
77 FilterEditor::filter_toggled ()
78 {
79         ActiveChanged ();
80 }
81
82 vector<Filter const*>
83 FilterEditor::active () const
84 {
85         vector<Filter const *> active;
86         for (map<Filter const *, wxCheckBox*>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
87                 if (i->second->IsChecked ()) {
88                         active.push_back (i->first);
89                 }
90         }
91
92         return active;
93 }