Move things round a bit.
[dcpomatic.git] / src / gtk / filter_view.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 /** @file  src/filter_view.cc
21  *  @brief A widget to select FFmpeg filters.
22  */
23
24 #include <iostream>
25 #include "lib/filter.h"
26 #include "filter_view.h"
27
28 using namespace std;
29
30 FilterView::FilterView (vector<Filter const *> const & active)
31 {
32         _box.set_spacing (4);
33         
34         vector<Filter const *> filters = Filter::all ();
35
36         for (vector<Filter const *>::iterator i = filters.begin(); i != filters.end(); ++i) {
37                 Gtk::CheckButton* b = Gtk::manage (new Gtk::CheckButton ((*i)->name()));
38                 bool const a = find (active.begin(), active.end(), *i) != active.end ();
39                 b->set_active (a);
40                 _filters[*i] = a;
41                 b->signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &FilterView::filter_toggled), *i));
42                 _box.pack_start (*b, false, false);
43         }
44
45         _box.show_all ();
46 }
47
48 Gtk::Widget &
49 FilterView::widget ()
50 {
51         return _box;
52 }
53
54 void
55 FilterView::filter_toggled (Filter const * f)
56 {
57         _filters[f] = !_filters[f];
58         ActiveChanged ();
59 }
60
61 vector<Filter const*>
62 FilterView::active () const
63 {
64         vector<Filter const *> active;
65         for (map<Filter const *, bool>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
66                 if (i->second) {
67                         active.push_back (i->first);
68                 }
69         }
70
71         return active;
72 }