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 #include <MediaFile.h> 40 #include <MediaNode.h> 41 #include <MediaRoster.h> 42 #include <MediaTrack.h> 43 #include <TimeCode.h> 44 45 __USE_CORTEX_NAMESPACE 46 47 #include <Debug.h> 48 #define D_METHOD(x) //PRINT (x) 49 50 // -------------------------------------------------------- // 51 // *** ctor/dtor (public) 52 // -------------------------------------------------------- // 53 54 FileNodeInfoView::FileNodeInfoView( 55 const NodeRef *ref) 56 : LiveNodeInfoView(ref) 57 { 58 D_METHOD(("FileNodeInfoView::FileNodeInfoView()\n")); 59 60 // adjust view properties 61 setSideBarWidth(be_plain_font->StringWidth(" File Format ") + 2 * InfoView::M_H_MARGIN); 62 setSubTitle("Live File-Interface Node"); 63 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) 72 { 73 BMediaFile file(&nodeFile); 74 if (file.InitCheck() == B_OK) 75 { 76 // add separator field 77 addField("", ""); 78 79 // add "File Format" fields 80 media_file_format format; 81 if (file.GetFileFormatInfo(&format) == B_OK) 82 { 83 s = ""; 84 s << format.pretty_name << " (" << format.mime_type << ")"; 85 addField("File Format", s); 86 } 87 88 // add "Copyright" field 89 const char *copyRight = file.Copyright(); 90 if (copyRight) 91 { 92 s = copyRight; 93 addField("Copyright", s); 94 } 95 96 // add "Tracks" list 97 if (file.CountTracks() > 0) 98 { 99 addField("Tracks", ""); 100 for (int32 i = 0; i < file.CountTracks(); i++) 101 { 102 BString label; 103 label << "(" << i + 1 << ")"; 104 BMediaTrack *track = file.TrackAt(i); 105 106 // add format 107 media_format format; 108 if (track->EncodedFormat(&format) == B_OK) 109 { 110 s = MediaString::getStringFor(format, false); 111 } 112 113 if ((format.type == B_MEDIA_ENCODED_AUDIO) 114 || (format.type == B_MEDIA_ENCODED_VIDEO)) 115 { 116 // add codec 117 media_codec_info codec; 118 if (track->GetCodecInfo(&codec) == B_OK) 119 { 120 s << "\n- Codec: " << codec.pretty_name; 121 if (codec.id > 0) 122 { 123 s << " (ID: " << codec.id << ")"; 124 } 125 } 126 } 127 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; 135 136 // add quality 137 float quality; 138 if (track->GetQuality(&quality) == B_OK) 139 { 140 s << "\n- Quality: " << quality; 141 } 142 addField(label, s); 143 } 144 } 145 } 146 // set title 147 BEntry entry(&nodeFile); 148 char fileName[B_FILE_NAME_LENGTH]; 149 entry.GetName(fileName); 150 title = fileName; 151 } 152 else 153 { 154 // set title 155 title = ref->name(); 156 title += " (no file)"; 157 } 158 setTitle(title); 159 } 160 161 FileNodeInfoView::~FileNodeInfoView() 162 { 163 D_METHOD(("FileNodeInfoView::~FileNodeInfoView()\n")); 164 } 165 166 // END -- FileNodeInfoView.cpp -- 167