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