xref: /haiku/src/apps/cortex/InfoView/FileNodeInfoView.cpp (revision 2f470aec1c92ce6917b8a903e343795dc77af41f)
1 // FileNodeInfoView.cpp
2 
3 #include "FileNodeInfoView.h"
4 #include "MediaIcon.h"
5 #include "MediaString.h"
6 #include "NodeRef.h"
7 
8 #include <MediaFile.h>
9 #include <MediaNode.h>
10 #include <MediaRoster.h>
11 #include <MediaTrack.h>
12 #include <TimeCode.h>
13 
14 __USE_CORTEX_NAMESPACE
15 
16 #include <Debug.h>
17 #define D_METHOD(x) //PRINT (x)
18 
19 // -------------------------------------------------------- //
20 // *** ctor/dtor (public)
21 // -------------------------------------------------------- //
22 
23 FileNodeInfoView::FileNodeInfoView(
24 	const NodeRef *ref)
25 	: LiveNodeInfoView(ref)
26 {
27 	D_METHOD(("FileNodeInfoView::FileNodeInfoView()\n"));
28 
29 	// adjust view properties
30 	setSideBarWidth(be_plain_font->StringWidth(" File Format ") + 2 * InfoView::M_H_MARGIN);
31 	setSubTitle("Live File-Interface Node");
32 
33 	// if a ref is set for this file-interface display some info
34 	// thru MediaFile and set the title appropriatly
35 	BString title;
36 	BString s;
37 	entry_ref nodeFile;
38 	status_t error;
39 	error = BMediaRoster::Roster()->GetRefFor(ref->node(), &nodeFile);
40 	if (!error)
41 	{
42 		BMediaFile file(&nodeFile);
43 		if (file.InitCheck() == B_OK)
44 		{
45 			// add separator field
46 			addField("", "");
47 
48 			// add "File Format" fields
49 			media_file_format format;
50 			if (file.GetFileFormatInfo(&format) == B_OK)
51 			{
52 				s = "";
53 				s << format.pretty_name << " (" << format.mime_type << ")";
54 				addField("File Format", s);
55 			}
56 
57 			// add "Copyright" field
58 			const char *copyRight = file.Copyright();
59 			if (copyRight)
60 			{
61 				s = copyRight;
62 				addField("Copyright", s);
63 			}
64 
65 			// add "Tracks" list
66 			if (file.CountTracks() > 0)
67 			{
68 				addField("Tracks", "");
69 				for (int32 i = 0; i < file.CountTracks(); i++)
70 				{
71 					BString label;
72 					label << "(" << i + 1 << ")";
73 					BMediaTrack *track = file.TrackAt(i);
74 
75 					// add format
76 					media_format format;
77 					if (track->EncodedFormat(&format) == B_OK)
78 					{
79 						s = MediaString::getStringFor(format, false);
80 					}
81 
82 					if ((format.type == B_MEDIA_ENCODED_AUDIO)
83 					 || (format.type == B_MEDIA_ENCODED_VIDEO))
84 					{
85 						// add codec
86 						media_codec_info codec;
87 						if (track->GetCodecInfo(&codec) == B_OK)
88 						{
89 							s << "\n- Codec: " << codec.pretty_name;
90 							if (codec.id > 0)
91 							{
92 								s << " (ID: " << codec.id << ")";
93 							}
94 						}
95 					}
96 
97 					// add duration
98 					bigtime_t duration = track->Duration();
99 					int hours, minutes, seconds, frames;
100 					us_to_timecode(duration, &hours, &minutes, &seconds, &frames);
101 					char buffer[64];
102 					sprintf(buffer, "%02d:%02d:%02d:%02d", hours, minutes, seconds, frames);
103 					s << "\n- Duration: " << buffer;
104 
105 					// add quality
106 					float quality;
107 					if (track->GetQuality(&quality) == B_OK)
108 					{
109 						s << "\n- Quality: " << quality;
110 					}
111 					addField(label, s);
112 				}
113 			}
114 		}
115 		// set title
116 		BEntry entry(&nodeFile);
117 		char fileName[B_FILE_NAME_LENGTH];
118 		entry.GetName(fileName);
119 		title = fileName;
120 	}
121 	else
122 	{
123 		// set title
124 		title = ref->name();
125 		title += " (no file)";
126 	}
127 	setTitle(title);
128 }
129 
130 FileNodeInfoView::~FileNodeInfoView()
131 {
132 	D_METHOD(("FileNodeInfoView::~FileNodeInfoView()\n"));
133 }
134 
135 // END -- FileNodeInfoView.cpp --
136