BOOST_FOREACH.
[dcpomatic.git] / src / wx / content_properties_dialog.cc
1 /*
2     Copyright (C) 2015-2018 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 #include "content_properties_dialog.h"
22 #include "wx_util.h"
23 #include "static_text.h"
24 #include "lib/content.h"
25 #include "lib/video_content.h"
26 #include "lib/audio_content.h"
27 #include <boost/algorithm/string.hpp>
28
29 using std::string;
30 using std::list;
31 using std::pair;
32 using std::map;
33 using std::shared_ptr;
34 using std::dynamic_pointer_cast;
35
36 ContentPropertiesDialog::ContentPropertiesDialog (wxWindow* parent, shared_ptr<const Film> film, shared_ptr<Content> content)
37         : TableDialog (parent, _("Content Properties"), 2, 1, false)
38 {
39         map<UserProperty::Category, list<UserProperty> > grouped;
40         for (auto i: content->user_properties(film)) {
41                 if (grouped.find(i.category) == grouped.end()) {
42                         grouped[i.category] = list<UserProperty> ();
43                 }
44                 grouped[i.category].push_back (i);
45         }
46
47         maybe_add_group (grouped, UserProperty::GENERAL);
48         maybe_add_group (grouped, UserProperty::VIDEO);
49         maybe_add_group (grouped, UserProperty::AUDIO);
50         maybe_add_group (grouped, UserProperty::LENGTH);
51
52         /* Nasty hack to stop the bottom property being cut off on Windows / OS X */
53         add (wxString (), false);
54         add (wxString (), false);
55
56         layout ();
57 }
58
59 void
60 ContentPropertiesDialog::maybe_add_group (map<UserProperty::Category, list<UserProperty> > const & groups, UserProperty::Category category)
61 {
62         map<UserProperty::Category, list<UserProperty> >::const_iterator i = groups.find (category);
63         if (i == groups.end()) {
64                 return;
65         }
66
67         wxString category_name;
68         switch (i->first) {
69         case UserProperty::GENERAL:
70                 category_name = _("General");
71                 break;
72         case UserProperty::VIDEO:
73                 category_name = _("Video");
74                 break;
75         case UserProperty::AUDIO:
76                 category_name = _("Audio");
77                 break;
78         case UserProperty::LENGTH:
79                 category_name = _("Length");
80                 break;
81         }
82
83         wxStaticText* m = new StaticText (this, category_name);
84         wxFont font (*wxNORMAL_FONT);
85         font.SetWeight (wxFONTWEIGHT_BOLD);
86         m->SetFont (font);
87
88         add_spacer ();
89         add_spacer ();
90         add (m, false);
91         add_spacer ();
92
93         for (auto j: i->second) {
94                 add (std_to_wx (j.key), true);
95                 add (new StaticText (this, std_to_wx (j.value + " " + j.unit)));
96         }
97 }