Logging improvements to allow prettier displays in the server GUI.
[dcpomatic.git] / src / lib / dcp_content_type.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/content_type.cc
21  *  @brief A description of the type of content for a DCP (e.g. feature, trailer etc.)
22  */
23
24 #include "dcp_content_type.h"
25 #include "dcpomatic_assert.h"
26 #include <cassert>
27
28 #include "i18n.h"
29
30 using namespace std;
31
32 vector<DCPContentType const *> DCPContentType::_dcp_content_types;
33
34 DCPContentType::DCPContentType (string p, dcp::ContentKind k, string d)
35         : _pretty_name (p)
36         , _libdcp_kind (k)
37         , _isdcf_name (d)
38 {
39
40 }
41
42 void
43 DCPContentType::setup_dcp_content_types ()
44 {
45         _dcp_content_types.push_back (new DCPContentType (_("Feature"), dcp::FEATURE, N_("FTR")));
46         _dcp_content_types.push_back (new DCPContentType (_("Short"), dcp::SHORT, N_("SHR")));
47         _dcp_content_types.push_back (new DCPContentType (_("Trailer"), dcp::TRAILER, N_("TLR")));
48         _dcp_content_types.push_back (new DCPContentType (_("Test"), dcp::TEST, N_("TST")));
49         _dcp_content_types.push_back (new DCPContentType (_("Transitional"), dcp::TRANSITIONAL, N_("XSN")));
50         _dcp_content_types.push_back (new DCPContentType (_("Rating"), dcp::RATING, N_("RTG")));
51         _dcp_content_types.push_back (new DCPContentType (_("Teaser"), dcp::TEASER, N_("TSR")));
52         _dcp_content_types.push_back (new DCPContentType (_("Policy"), dcp::POLICY, N_("POL")));
53         _dcp_content_types.push_back (new DCPContentType (_("Public Service Announcement"), dcp::PUBLIC_SERVICE_ANNOUNCEMENT, N_("PSA")));
54         _dcp_content_types.push_back (new DCPContentType (_("Advertisement"), dcp::ADVERTISEMENT, N_("ADV")));
55 }
56
57 DCPContentType const *
58 DCPContentType::from_pretty_name (string n)
59 {
60         for (vector<DCPContentType const *>::const_iterator i = _dcp_content_types.begin(); i != _dcp_content_types.end(); ++i) {
61                 if ((*i)->pretty_name() == n) {
62                         return *i;
63                 }
64         }
65
66         return 0;
67 }
68
69 DCPContentType const *
70 DCPContentType::from_isdcf_name (string n)
71 {
72         for (vector<DCPContentType const *>::const_iterator i = _dcp_content_types.begin(); i != _dcp_content_types.end(); ++i) {
73                 if ((*i)->isdcf_name() == n) {
74                         return *i;
75                 }
76         }
77
78         return 0;
79 }
80
81 DCPContentType const *
82 DCPContentType::from_index (int n)
83 {
84         DCPOMATIC_ASSERT (n >= 0 && n < int (_dcp_content_types.size ()));
85         return _dcp_content_types[n];
86 }
87
88 int
89 DCPContentType::as_index (DCPContentType const * c)
90 {
91         vector<DCPContentType*>::size_type i = 0;
92         while (i < _dcp_content_types.size() && _dcp_content_types[i] != c) {
93                 ++i;
94         }
95
96         if (i == _dcp_content_types.size ()) {
97                 return -1;
98         }
99
100         return i;
101 }
102
103 vector<DCPContentType const *>
104 DCPContentType::all ()
105 {
106         return _dcp_content_types;
107 }