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