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