source: smplayer/vendor/current/src/infofile.cpp@ 168

Last change on this file since 168 was 168, checked in by Silvan Scherrer, 11 years ago

SMPlayer: update vendor to 14.9.0

File size: 7.6 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2014 Ricardo Villalba <rvm@users.sourceforge.net>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19#include "infofile.h"
20#include <QFileInfo>
21#include <QCoreApplication>
22#include "discname.h"
23#include "images.h"
24
25
26InfoFile::InfoFile() {
27 row = 0;
28}
29
30InfoFile::~InfoFile() {
31}
32
33QString InfoFile::getInfo(MediaData md) {
34 QString s;
35
36 // General
37 QFileInfo fi(md.filename);
38
39 QString icon;
40 switch (md.type) {
41 case TYPE_FILE : if (md.novideo)
42 icon = "type_audio.png";
43 else
44 icon = "type_video.png";
45 break;
46 case TYPE_DVD : icon = "type_dvd.png"; break;
47 case TYPE_VCD : icon = "type_vcd.png"; break;
48 case TYPE_AUDIO_CD : icon = "type_vcd.png"; break;
49 case TYPE_TV : icon = "type_tv.png"; break;
50 case TYPE_STREAM : icon = "type_url.png"; break;
51#ifdef BLURAY_SUPPORT
52 case TYPE_BLURAY : icon = "type_bluray.png"; break;
53#endif
54 default : icon = "type_unknown.png";
55 }
56 icon = icon.replace(".png", ""); // FIXME
57 icon = "<img src=\"" + Images::file(icon) + "\"> ";
58
59#ifdef BLURAY_SUPPORT
60 if (md.type == TYPE_DVD || md.type == TYPE_BLURAY)
61#else
62 if (md.type == TYPE_DVD)
63#endif
64 {
65 DiscData disc_data = DiscName::split(md.filename);
66 s += title( icon + disc_data.protocol + "://" + QString::number(disc_data.title) );
67 } else {
68 s += title( icon + md.displayName() );
69 }
70
71 s += openPar( tr("General") );
72 if (fi.exists()) {
73 //s += addItem( tr("Path"), fi.dirPath() );
74 s += addItem( tr("File"), fi.absoluteFilePath() );
75 s += addItem( tr("Size"), tr("%1 KB (%2 MB)").arg(fi.size()/1024)
76 .arg(fi.size()/1048576) );
77 } else {
78 QString url = md.filename;
79 s += addItem( tr("URL"), url );
80 }
81 s += addItem( tr("Length"), Helper::formatTime((int)md.duration) );
82 s += addItem( tr("Demuxer"), md.demuxer );
83 s += closePar();
84
85 // Clip info
86 QString c;
87 if (!md.clip_name.isEmpty()) c+= addItem( tr("Name"), md.clip_name );
88 if (!md.clip_artist.isEmpty()) c+= addItem( tr("Artist"), md.clip_artist );
89 if (!md.clip_author.isEmpty()) c+= addItem( tr("Author"), md.clip_author );
90 if (!md.clip_album.isEmpty()) c+= addItem( tr("Album"), md.clip_album );
91 if (!md.clip_genre.isEmpty()) c+= addItem( tr("Genre"), md.clip_genre );
92 if (!md.clip_date.isEmpty()) c+= addItem( tr("Date"), md.clip_date );
93 if (!md.clip_track.isEmpty()) c+= addItem( tr("Track"), md.clip_track );
94 if (!md.clip_copyright.isEmpty()) c+= addItem( tr("Copyright"), md.clip_copyright );
95 if (!md.clip_comment.isEmpty()) c+= addItem( tr("Comment"), md.clip_comment );
96 if (!md.clip_software.isEmpty()) c+= addItem( tr("Software"), md.clip_software );
97 if (!md.stream_title.isEmpty()) c+= addItem( tr("Stream title"), md.stream_title );
98 if (!md.stream_url.isEmpty()) c+= addItem( tr("Stream URL"), md.stream_url );
99
100 if (!c.isEmpty()) {
101 s += openPar( tr("Clip info") );
102 s += c;
103 s += closePar();
104 }
105
106 // Video info
107 if (!md.novideo) {
108 s += openPar( tr("Video") );
109 s += addItem( tr("Resolution"), QString("%1 x %2").arg(md.video_width).arg(md.video_height) );
110 s += addItem( tr("Aspect ratio"), QString::number(md.video_aspect) );
111 s += addItem( tr("Format"), md.video_format );
112 s += addItem( tr("Bitrate"), tr("%1 kbps").arg(md.video_bitrate / 1000) );
113 s += addItem( tr("Frames per second"), md.video_fps );
114 s += addItem( tr("Selected codec"), md.video_codec );
115 s += closePar();
116 }
117
118 // Audio info
119 s += openPar( tr("Initial Audio Stream") );
120 s += addItem( tr("Format"), md.audio_format );
121 s += addItem( tr("Bitrate"), tr("%1 kbps").arg(md.audio_bitrate / 1000) );
122 s += addItem( tr("Rate"), tr("%1 Hz").arg(md.audio_rate) );
123 s += addItem( tr("Channels"), QString::number(md.audio_nch) );
124 s += addItem( tr("Selected codec"), md.audio_codec );
125 s += closePar();
126
127 // Audio Tracks
128 if (md.audios.numItems() > 0) {
129 s += openPar( tr("Audio Streams") );
130 row++;
131 s += openItem();
132 s += "<td>" + tr("#", "Info for translators: this is a abbreviation for number") + "</td><td>" +
133 tr("Language") + "</td><td>" + tr("Name") +"</td><td>" +
134 tr("ID", "Info for translators: this is a identification code") + "</td>";
135 s += closeItem();
136 for (int n = 0; n < md.audios.numItems(); n++) {
137 row++;
138 s += openItem();
139 QString lang = md.audios.itemAt(n).lang();
140 if (lang.isEmpty()) lang = "<i>&lt;"+tr("empty")+"&gt;</i>";
141 QString name = md.audios.itemAt(n).name();
142 if (name.isEmpty()) name = "<i>&lt;"+tr("empty")+"&gt;</i>";
143 s += QString("<td>%1</td><td>%2</td><td>%3</td><td>%4</td>")
144 .arg(n).arg(lang).arg(name)
145 .arg(md.audios.itemAt(n).ID());
146 s += closeItem();
147 }
148 s += closePar();
149 }
150
151 // Subtitles
152 if (md.subs.numItems() > 0) {
153 s += openPar( tr("Subtitles") );
154 row++;
155 s += openItem();
156 s += "<td>" + tr("#", "Info for translators: this is a abbreviation for number") + "</td><td>" +
157 tr("Type") + "</td><td>" +
158 tr("Language") + "</td><td>" + tr("Name") +"</td><td>" +
159 tr("ID", "Info for translators: this is a identification code") + "</td>";
160 s += closeItem();
161 for (int n = 0; n < md.subs.numItems(); n++) {
162 row++;
163 s += openItem();
164 QString t;
165 switch (md.subs.itemAt(n).type()) {
166 case SubData::File: t = "FILE_SUB"; break;
167 case SubData::Vob: t = "VOB"; break;
168 default: t = "SUB";
169 }
170 QString lang = md.subs.itemAt(n).lang();
171 if (lang.isEmpty()) lang = "<i>&lt;"+tr("empty")+"&gt;</i>";
172 QString name = md.subs.itemAt(n).name();
173 if (name.isEmpty()) name = "<i>&lt;"+tr("empty")+"&gt;</i>";
174 /*
175 s += QString("<td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td>")
176 .arg(n).arg(t).arg(lang).arg(name)
177 .arg(md.subs.itemAt(n).ID());
178 */
179 s += "<td>" + QString::number(n) + "</td><td>" + t +
180 "</td><td>" + lang + "</td><td>" + name +
181 "</td><td>" + QString::number(md.subs.itemAt(n).ID()) + "</td>";
182 s += closeItem();
183 }
184 s += closePar();
185 }
186
187 return "<html><body bgcolor=\"white\"><font color=\"black\">"+ s + "</font></body></html>";
188}
189
190QString InfoFile::title(QString text) {
191 return "<h1>" + text + "</h1>";
192}
193
194QString InfoFile::openPar(QString text) {
195 return "<h2>" + text + "</h2>"
196 "<table width=\"100%\">";
197}
198
199QString InfoFile::closePar() {
200 row = 0;
201 return "</table>";
202}
203
204QString InfoFile::openItem() {
205 if (row % 2 == 1)
206 return "<tr bgcolor=\"lavender\">";
207 else
208 return "<tr bgcolor=\"powderblue\">";
209}
210
211QString InfoFile::closeItem() {
212 return "</tr>";
213}
214
215QString InfoFile::addItem( QString tag, QString value ) {
216 row++;
217 return openItem() +
218 "<td><b>" + tag + "</b></td>" +
219 "<td>" + value + "</td>" +
220 closeItem();
221}
222
223
224inline QString InfoFile::tr( const char * sourceText, const char * comment, int n ) {
225#if QT_VERSION >= 0x050000
226 return QCoreApplication::translate("InfoFile", sourceText, comment, n );
227#else
228 return QCoreApplication::translate("InfoFile", sourceText, comment, QCoreApplication::CodecForTr, n );
229#endif
230}
231
Note: See TracBrowser for help on using the repository browser.