repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / cortex / InfoView / FileNodeInfoView.cpp
blob1922d92be39c1cf1163dc47d4220890eb399d027
1 /*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
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.
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.
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.
32 // FileNodeInfoView.cpp
34 #include "FileNodeInfoView.h"
35 #include "MediaIcon.h"
36 #include "MediaString.h"
37 #include "NodeRef.h"
39 #include <MediaFile.h>
40 #include <MediaNode.h>
41 #include <MediaRoster.h>
42 #include <MediaTrack.h>
43 #include <TimeCode.h>
45 __USE_CORTEX_NAMESPACE
47 #include <Debug.h>
48 #define D_METHOD(x) //PRINT (x)
50 // -------------------------------------------------------- //
51 // *** ctor/dtor (public)
52 // -------------------------------------------------------- //
54 FileNodeInfoView::FileNodeInfoView(
55 const NodeRef *ref)
56 : LiveNodeInfoView(ref)
58 D_METHOD(("FileNodeInfoView::FileNodeInfoView()\n"));
60 // adjust view properties
61 setSideBarWidth(be_plain_font->StringWidth(" File Format ") + 2 * InfoView::M_H_MARGIN);
62 setSubTitle("Live File-Interface Node");
64 // if a ref is set for this file-interface display some info
65 // thru MediaFile and set the title appropriatly
66 BString title;
67 BString s;
68 entry_ref nodeFile;
69 status_t error;
70 error = BMediaRoster::Roster()->GetRefFor(ref->node(), &nodeFile);
71 if (!error)
73 BMediaFile file(&nodeFile);
74 if (file.InitCheck() == B_OK)
76 // add separator field
77 addField("", "");
79 // add "File Format" fields
80 media_file_format format;
81 if (file.GetFileFormatInfo(&format) == B_OK)
83 s = "";
84 s << format.pretty_name << " (" << format.mime_type << ")";
85 addField("File Format", s);
88 // add "Copyright" field
89 const char *copyRight = file.Copyright();
90 if (copyRight)
92 s = copyRight;
93 addField("Copyright", s);
96 // add "Tracks" list
97 if (file.CountTracks() > 0)
99 addField("Tracks", "");
100 for (int32 i = 0; i < file.CountTracks(); i++)
102 BString label;
103 label << "(" << i + 1 << ")";
104 BMediaTrack *track = file.TrackAt(i);
106 // add format
107 media_format format;
108 if (track->EncodedFormat(&format) == B_OK)
110 s = MediaString::getStringFor(format, false);
113 if ((format.type == B_MEDIA_ENCODED_AUDIO)
114 || (format.type == B_MEDIA_ENCODED_VIDEO))
116 // add codec
117 media_codec_info codec;
118 if (track->GetCodecInfo(&codec) == B_OK)
120 s << "\n- Codec: " << codec.pretty_name;
121 if (codec.id > 0)
123 s << " (ID: " << codec.id << ")";
128 // add duration
129 bigtime_t duration = track->Duration();
130 int hours, minutes, seconds, frames;
131 us_to_timecode(duration, &hours, &minutes, &seconds, &frames);
132 char buffer[64];
133 sprintf(buffer, "%02d:%02d:%02d:%02d", hours, minutes, seconds, frames);
134 s << "\n- Duration: " << buffer;
136 // add quality
137 float quality;
138 if (track->GetQuality(&quality) == B_OK)
140 s << "\n- Quality: " << quality;
142 addField(label, s);
146 // set title
147 BEntry entry(&nodeFile);
148 char fileName[B_FILE_NAME_LENGTH];
149 entry.GetName(fileName);
150 title = fileName;
152 else
154 // set title
155 title = ref->name();
156 title += " (no file)";
158 setTitle(title);
161 FileNodeInfoView::~FileNodeInfoView()
163 D_METHOD(("FileNodeInfoView::~FileNodeInfoView()\n"));
166 // END -- FileNodeInfoView.cpp --