1c284bb0fSMatt Madia /*
2c284bb0fSMatt Madia * Copyright (c) 1999-2000, Eric Moon.
3c284bb0fSMatt Madia * All rights reserved.
4c284bb0fSMatt Madia *
5c284bb0fSMatt Madia * Redistribution and use in source and binary forms, with or without
6c284bb0fSMatt Madia * modification, are permitted provided that the following conditions
7c284bb0fSMatt Madia * are met:
8c284bb0fSMatt Madia *
9c284bb0fSMatt Madia * 1. Redistributions of source code must retain the above copyright
10c284bb0fSMatt Madia * notice, this list of conditions, and the following disclaimer.
11c284bb0fSMatt Madia *
12c284bb0fSMatt Madia * 2. Redistributions in binary form must reproduce the above copyright
13c284bb0fSMatt Madia * notice, this list of conditions, and the following disclaimer in the
14c284bb0fSMatt Madia * documentation and/or other materials provided with the distribution.
15c284bb0fSMatt Madia *
16c284bb0fSMatt Madia * 3. The name of the author may not be used to endorse or promote products
17c284bb0fSMatt Madia * derived from this software without specific prior written permission.
18c284bb0fSMatt Madia *
19c284bb0fSMatt Madia * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20c284bb0fSMatt Madia * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21c284bb0fSMatt Madia * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22c284bb0fSMatt Madia * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23c284bb0fSMatt Madia * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24c284bb0fSMatt Madia * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25c284bb0fSMatt Madia * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26c284bb0fSMatt Madia * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27c284bb0fSMatt Madia * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28c284bb0fSMatt Madia * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29c284bb0fSMatt Madia */
30c284bb0fSMatt Madia
31c284bb0fSMatt Madia
32a0795c6fSMarcus Overhagen // FileNodeInfoView.cpp
33a0795c6fSMarcus Overhagen
34a0795c6fSMarcus Overhagen #include "FileNodeInfoView.h"
35a0795c6fSMarcus Overhagen #include "MediaIcon.h"
36a0795c6fSMarcus Overhagen #include "MediaString.h"
37a0795c6fSMarcus Overhagen #include "NodeRef.h"
38a0795c6fSMarcus Overhagen
392cba2d56SDancsó Róbert #undef B_CATALOG
402cba2d56SDancsó Róbert #define B_CATALOG (&sCatalog)
412cba2d56SDancsó Róbert #include <Catalog.h>
42a0795c6fSMarcus Overhagen #include <MediaFile.h>
43a0795c6fSMarcus Overhagen #include <MediaNode.h>
44a0795c6fSMarcus Overhagen #include <MediaRoster.h>
45a0795c6fSMarcus Overhagen #include <MediaTrack.h>
46a0795c6fSMarcus Overhagen #include <TimeCode.h>
47a0795c6fSMarcus Overhagen
482cba2d56SDancsó Róbert #undef B_TRANSLATION_CONTEXT
492cba2d56SDancsó Róbert #define B_TRANSLATION_CONTEXT "FileNodeInfoView"
502cba2d56SDancsó Róbert
51a0795c6fSMarcus Overhagen __USE_CORTEX_NAMESPACE
52a0795c6fSMarcus Overhagen
53a0795c6fSMarcus Overhagen #include <Debug.h>
54a0795c6fSMarcus Overhagen #define D_METHOD(x) //PRINT (x)
55a0795c6fSMarcus Overhagen
56*bf6a2a2bSNiels Sascha Reedijk static BCatalog sCatalog("x-vnd.Cortex.InfoView");
572cba2d56SDancsó Róbert
58a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
59a0795c6fSMarcus Overhagen // *** ctor/dtor (public)
60a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
61a0795c6fSMarcus Overhagen
FileNodeInfoView(const NodeRef * ref)62a0795c6fSMarcus Overhagen FileNodeInfoView::FileNodeInfoView(
63a0795c6fSMarcus Overhagen const NodeRef *ref)
64a0795c6fSMarcus Overhagen : LiveNodeInfoView(ref)
65a0795c6fSMarcus Overhagen {
66a0795c6fSMarcus Overhagen D_METHOD(("FileNodeInfoView::FileNodeInfoView()\n"));
67a0795c6fSMarcus Overhagen
68a0795c6fSMarcus Overhagen // adjust view properties
692cba2d56SDancsó Róbert setSideBarWidth(be_plain_font->StringWidth(B_TRANSLATE("File format"))
702cba2d56SDancsó Róbert + 2 * InfoView::M_H_MARGIN);
712cba2d56SDancsó Róbert setSubTitle(B_TRANSLATE("Live file-interface node"));
72a0795c6fSMarcus Overhagen
73a0795c6fSMarcus Overhagen // if a ref is set for this file-interface display some info
74a0795c6fSMarcus Overhagen // thru MediaFile and set the title appropriatly
75a0795c6fSMarcus Overhagen BString title;
76a0795c6fSMarcus Overhagen BString s;
77a0795c6fSMarcus Overhagen entry_ref nodeFile;
78a0795c6fSMarcus Overhagen status_t error;
79a0795c6fSMarcus Overhagen error = BMediaRoster::Roster()->GetRefFor(ref->node(), &nodeFile);
80a0795c6fSMarcus Overhagen if (!error)
81a0795c6fSMarcus Overhagen {
82a0795c6fSMarcus Overhagen BMediaFile file(&nodeFile);
83a0795c6fSMarcus Overhagen if (file.InitCheck() == B_OK)
84a0795c6fSMarcus Overhagen {
85a0795c6fSMarcus Overhagen // add separator field
86a0795c6fSMarcus Overhagen addField("", "");
87a0795c6fSMarcus Overhagen
88a0795c6fSMarcus Overhagen // add "File Format" fields
89a0795c6fSMarcus Overhagen media_file_format format;
90a0795c6fSMarcus Overhagen if (file.GetFileFormatInfo(&format) == B_OK)
91a0795c6fSMarcus Overhagen {
92a0795c6fSMarcus Overhagen s = "";
93a0795c6fSMarcus Overhagen s << format.pretty_name << " (" << format.mime_type << ")";
942cba2d56SDancsó Róbert addField(B_TRANSLATE("File format"), s);
95a0795c6fSMarcus Overhagen }
96a0795c6fSMarcus Overhagen
97a0795c6fSMarcus Overhagen // add "Copyright" field
98a0795c6fSMarcus Overhagen const char *copyRight = file.Copyright();
99a0795c6fSMarcus Overhagen if (copyRight)
100a0795c6fSMarcus Overhagen {
101a0795c6fSMarcus Overhagen s = copyRight;
1022cba2d56SDancsó Róbert addField(B_TRANSLATE("Copyright"), s);
103a0795c6fSMarcus Overhagen }
104a0795c6fSMarcus Overhagen
105a0795c6fSMarcus Overhagen // add "Tracks" list
106a0795c6fSMarcus Overhagen if (file.CountTracks() > 0)
107a0795c6fSMarcus Overhagen {
1082cba2d56SDancsó Róbert addField(B_TRANSLATE("Tracks"), "");
109a0795c6fSMarcus Overhagen for (int32 i = 0; i < file.CountTracks(); i++)
110a0795c6fSMarcus Overhagen {
111a0795c6fSMarcus Overhagen BString label;
112a0795c6fSMarcus Overhagen label << "(" << i + 1 << ")";
113a0795c6fSMarcus Overhagen BMediaTrack *track = file.TrackAt(i);
114a0795c6fSMarcus Overhagen
115a0795c6fSMarcus Overhagen // add format
116a0795c6fSMarcus Overhagen media_format format;
117a0795c6fSMarcus Overhagen if (track->EncodedFormat(&format) == B_OK)
118a0795c6fSMarcus Overhagen {
119a0795c6fSMarcus Overhagen s = MediaString::getStringFor(format, false);
120a0795c6fSMarcus Overhagen }
121a0795c6fSMarcus Overhagen
122a0795c6fSMarcus Overhagen if ((format.type == B_MEDIA_ENCODED_AUDIO)
123a0795c6fSMarcus Overhagen || (format.type == B_MEDIA_ENCODED_VIDEO))
124a0795c6fSMarcus Overhagen {
125a0795c6fSMarcus Overhagen // add codec
126a0795c6fSMarcus Overhagen media_codec_info codec;
127a0795c6fSMarcus Overhagen if (track->GetCodecInfo(&codec) == B_OK)
128a0795c6fSMarcus Overhagen {
1292cba2d56SDancsó Róbert s << B_TRANSLATE("\n- Codec:") << " "
1302cba2d56SDancsó Róbert << codec.pretty_name;
131a0795c6fSMarcus Overhagen if (codec.id > 0)
132a0795c6fSMarcus Overhagen {
1332cba2d56SDancsó Róbert s << " (" << B_TRANSLATE("ID:") << " "
1342cba2d56SDancsó Róbert << codec.id << ")";
135a0795c6fSMarcus Overhagen }
136a0795c6fSMarcus Overhagen }
137a0795c6fSMarcus Overhagen }
138a0795c6fSMarcus Overhagen
139a0795c6fSMarcus Overhagen // add duration
140a0795c6fSMarcus Overhagen bigtime_t duration = track->Duration();
141a0795c6fSMarcus Overhagen int hours, minutes, seconds, frames;
142a0795c6fSMarcus Overhagen us_to_timecode(duration, &hours, &minutes, &seconds, &frames);
143a0795c6fSMarcus Overhagen char buffer[64];
144a0795c6fSMarcus Overhagen sprintf(buffer, "%02d:%02d:%02d:%02d", hours, minutes, seconds, frames);
1452cba2d56SDancsó Róbert s << B_TRANSLATE("\n- Duration:") << " " << buffer;
146a0795c6fSMarcus Overhagen
147a0795c6fSMarcus Overhagen // add quality
148a0795c6fSMarcus Overhagen float quality;
149a0795c6fSMarcus Overhagen if (track->GetQuality(&quality) == B_OK)
150a0795c6fSMarcus Overhagen {
1512cba2d56SDancsó Róbert s << B_TRANSLATE("\n- Quality:") << " " << quality;
152a0795c6fSMarcus Overhagen }
153a0795c6fSMarcus Overhagen addField(label, s);
154a0795c6fSMarcus Overhagen }
155a0795c6fSMarcus Overhagen }
156a0795c6fSMarcus Overhagen }
157a0795c6fSMarcus Overhagen // set title
158a0795c6fSMarcus Overhagen BEntry entry(&nodeFile);
159a0795c6fSMarcus Overhagen char fileName[B_FILE_NAME_LENGTH];
160a0795c6fSMarcus Overhagen entry.GetName(fileName);
161a0795c6fSMarcus Overhagen title = fileName;
162a0795c6fSMarcus Overhagen }
163a0795c6fSMarcus Overhagen else
164a0795c6fSMarcus Overhagen {
165a0795c6fSMarcus Overhagen // set title
166a0795c6fSMarcus Overhagen title = ref->name();
1672cba2d56SDancsó Róbert title += " ";
1682cba2d56SDancsó Róbert title += B_TRANSLATE("(no file)");
169a0795c6fSMarcus Overhagen }
170a0795c6fSMarcus Overhagen setTitle(title);
171a0795c6fSMarcus Overhagen }
172a0795c6fSMarcus Overhagen
~FileNodeInfoView()173a0795c6fSMarcus Overhagen FileNodeInfoView::~FileNodeInfoView()
174a0795c6fSMarcus Overhagen {
175a0795c6fSMarcus Overhagen D_METHOD(("FileNodeInfoView::~FileNodeInfoView()\n"));
176a0795c6fSMarcus Overhagen }
177a0795c6fSMarcus Overhagen
178a0795c6fSMarcus Overhagen // END -- FileNodeInfoView.cpp --
179