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

Last change on this file was 186, checked in by Silvan Scherrer, 8 years ago

SMPlayer: update vendor to 17.1.0

File size: 9.3 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2017 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 "discname.h"
21#include "images.h"
22
23#include <QFileInfo>
24#include <QCoreApplication>
25#include <QFile>
26#include <QDateTime>
27#include <QDebug>
28
29InfoFile::InfoFile(QObject * parent)
30 : QObject(parent)
31#ifndef INFO_SIMPLE_LAYOUT
32 , row(0)
33#endif
34{
35}
36
37InfoFile::~InfoFile() {
38}
39
40QString InfoFile::getInfo(MediaData md) {
41 QString s;
42
43 // General
44 QFileInfo fi(md.filename);
45
46 QString icon;
47 switch (md.type) {
48 case TYPE_FILE : if (md.novideo)
49 icon = "type_audio.png";
50 else
51 icon = "type_video.png";
52 break;
53 case TYPE_DVD : icon = "type_dvd.png"; break;
54 case TYPE_VCD : icon = "type_vcd.png"; break;
55 case TYPE_AUDIO_CD : icon = "type_vcd.png"; break;
56 case TYPE_TV : icon = "type_tv.png"; break;
57 case TYPE_STREAM : icon = "type_url.png"; break;
58#ifdef BLURAY_SUPPORT
59 case TYPE_BLURAY : icon = "type_bluray.png"; break;
60#endif
61 default : icon = "type_unknown.png";
62 }
63 icon = icon.replace(".png", ""); // FIXME
64 //icon = "<img src=\"" + Images::file(icon) + "\"> ";
65
66#ifdef BLURAY_SUPPORT
67 if (md.type == TYPE_DVD || md.type == TYPE_BLURAY)
68#else
69 if (md.type == TYPE_DVD)
70#endif
71 {
72 DiscData disc_data = DiscName::split(md.filename);
73 s += title(disc_data.protocol + "://" + QString::number(disc_data.title), icon);
74 } else {
75 s += title(md.displayName(), icon);
76 }
77
78 s += openPar( tr("General") );
79 if (fi.exists()) {
80 //s += addItem( tr("Path"), fi.dirPath() );
81 s += addItem( tr("File"), fi.absoluteFilePath() );
82 s += addItem( tr("Size"), tr("%1 KB (%2 MB)").arg(fi.size()/1024)
83 .arg(fi.size()/1048576) );
84 } else {
85 QString url = md.filename;
86 s += addItem( tr("URL"), url );
87 /*
88 if (!md.stream_path.isEmpty() && md.stream_path != url) {
89 s += addItem( tr("Video URL"), md.stream_path );
90 }
91 */
92 }
93 s += addItem( tr("Length"), Helper::formatTime((int)md.duration) );
94 s += addItem( tr("Demuxer"), md.demuxer );
95 s += closePar();
96
97 // Clip info
98 QString c;
99 if (!md.clip_name.isEmpty()) c+= addItem( tr("Name"), md.clip_name );
100 if (!md.clip_artist.isEmpty()) c+= addItem( tr("Artist"), md.clip_artist );
101 if (!md.clip_author.isEmpty()) c+= addItem( tr("Author"), md.clip_author );
102 if (!md.clip_album.isEmpty()) c+= addItem( tr("Album"), md.clip_album );
103 if (!md.clip_genre.isEmpty()) c+= addItem( tr("Genre"), md.clip_genre );
104 if (!md.clip_date.isEmpty()) {
105 QString s = md.clip_date;
106 QDateTime d = QDateTime::fromString(md.clip_date, Qt::ISODate);
107 if (d.isValid()) {
108 s = d.toString("yyyy-MM-dd hh:mm:ss");
109 /* s = QLocale::system().toString(d, QLocale::ShortFormat); */
110 }
111 c+= addItem( tr("Date"), s );
112 }
113 if (!md.clip_track.isEmpty()) c+= addItem( tr("Track"), md.clip_track );
114 if (!md.clip_copyright.isEmpty()) c+= addItem( tr("Copyright"), md.clip_copyright );
115 if (!md.clip_comment.isEmpty()) c+= addItem( tr("Comment"), md.clip_comment );
116 if (!md.clip_software.isEmpty()) c+= addItem( tr("Software"), md.clip_software );
117 if (!md.stream_title.isEmpty()) c+= addItem( tr("Stream title"), md.stream_title );
118 if (!md.stream_url.isEmpty()) c+= addItem( tr("Stream URL"), md.stream_url );
119
120 if (!c.isEmpty()) {
121 s += openPar( tr("Clip info") );
122 s += c;
123 s += closePar();
124 }
125
126 // Video info
127 if (!md.novideo) {
128 s += openPar( tr("Video") );
129 s += addItem( tr("Resolution"), QString("%1 x %2").arg(md.video_width).arg(md.video_height) );
130 s += addItem( tr("Aspect ratio"), QString::number(md.video_aspect) );
131 s += addItem( tr("Format"), md.video_format );
132 s += addItem( tr("Bitrate"), tr("%1 kbps").arg(md.video_bitrate / 1000) );
133 s += addItem( tr("Frames per second"), md.video_fps );
134 s += addItem( tr("Selected codec"), md.video_codec );
135 s += closePar();
136 }
137
138 // Audio info
139 s += openPar( tr("Initial Audio Stream") );
140 s += addItem( tr("Format"), md.audio_format );
141 s += addItem( tr("Bitrate"), tr("%1 kbps").arg(md.audio_bitrate / 1000) );
142 s += addItem( tr("Rate"), tr("%1 Hz").arg(md.audio_rate) );
143 s += addItem( tr("Channels"), QString::number(md.audio_nch) );
144 s += addItem( tr("Selected codec"), md.audio_codec );
145 s += closePar();
146
147 // Audio Tracks
148 if (md.audios.numItems() > 0) {
149 s += openPar( tr("Audio Streams") );
150 s += addTrackColumns( QStringList() << "#" << tr("Language") << tr("Name") << "ID" );
151
152 for (int n = 0; n < md.audios.numItems(); n++) {
153 #ifndef INFO_SIMPLE_LAYOUT
154 row++;
155 #endif
156 s += openItem();
157 QString lang = md.audios.itemAt(n).lang();
158 if (lang.isEmpty()) lang = "<i>&lt;"+tr("undefined")+"&gt;</i>";
159 QString name = md.audios.itemAt(n).name();
160 if (name.isEmpty()) name = "<i>&lt;"+tr("undefined")+"&gt;</i>";
161 s += addTrack(n, lang, name, md.audios.itemAt(n).ID());
162 s += closeItem();
163 }
164 s += closePar();
165 }
166
167 // Subtitles
168 if (md.subs.numItems() > 0) {
169 s += openPar( tr("Subtitles") );
170 s += addTrackColumns( QStringList() << "#" << tr("Type") << tr("Language") << tr("Name") << "ID" );
171 for (int n = 0; n < md.subs.numItems(); n++) {
172 #ifndef INFO_SIMPLE_LAYOUT
173 row++;
174 #endif
175 s += openItem();
176 QString t;
177 switch (md.subs.itemAt(n).type()) {
178 case SubData::File: t = "FILE_SUB"; break;
179 case SubData::Vob: t = "VOB"; break;
180 default: t = "SUB";
181 }
182 QString lang = md.subs.itemAt(n).lang();
183 if (lang.isEmpty()) lang = "<i>&lt;"+tr("undefined")+"&gt;</i>";
184 QString name = md.subs.itemAt(n).name();
185 if (name.isEmpty()) name = "<i>&lt;"+tr("undefined")+"&gt;</i>";
186 s += addTrack(n, lang, name, md.subs.itemAt(n).ID(), t);
187 s += closeItem();
188 }
189 s += closePar();
190 }
191
192 QString page = "<html><head><style type=\"text/css\">" + style() + "</style></head><body>"+ s + "</body></html>";
193 //qDebug() << "InfoFile::getInfo:" << page;
194 return page;
195}
196
197
198#ifdef INFO_SIMPLE_LAYOUT
199QString InfoFile::title(QString text, QString /* icon */) {
200 return QString("<h1>%1</h1>").arg(text);
201}
202
203QString InfoFile::openPar(QString text) {
204 return "<h2>" + text + "</h2><ul>";
205}
206
207QString InfoFile::closePar() {
208 return "</ul>";
209}
210
211QString InfoFile::openItem() {
212 return "<li>";
213}
214
215QString InfoFile::closeItem() {
216 return "</li>";
217}
218
219QString InfoFile::addItem( QString tag, QString value ) {
220 return openItem() + QString("<b>%1</b>: %2").arg(tag).arg(value) + closeItem();
221}
222
223QString InfoFile::addTrackColumns(QStringList /* l */) {
224 return "";
225}
226
227QString InfoFile::addTrack(int n, QString lang, QString name, int ID, QString type) {
228 QString s = "<b>" + tr("Track %1").arg(n) + "</b>";
229 #if 1
230 s += "<ul>";
231 s += "<li>" + tr("Language: %1").arg(lang) + "</li>";
232 s += "<li>" + tr("Name: %1").arg(name) + "</li>";
233 s += "<li>" + tr("ID: %1").arg(ID) + "</li>";
234 if (!type.isEmpty()) {
235 s += "<li>" + tr("Type: %1").arg(type) + "</li>";
236 }
237 s += "</ul>";
238 #else
239 s += "<br>&nbsp;&bull; " + tr("Language: %1").arg(lang);
240 s += "<br>&nbsp;&bull; " + tr("Name: %1").arg(name);
241 s += "<br>&nbsp;&bull; " + tr("ID: %1").arg(ID);
242 if (!type.isEmpty()) {
243 s += "<br>&nbsp;&bull; " + tr("Type: %1").arg(type);
244 }
245 #endif
246 return s;
247}
248
249QString InfoFile::defaultStyle() {
250 return
251 "ul { margin: 0px; }"
252 //"body { background-color: gray; }"
253 "h2 { background-color: whitesmoke; color: navy;}"
254 ;
255}
256
257#else
258
259QString InfoFile::title(QString text, QString icon) {
260 return QString("<h1><img src=\"%1\">%2</h1>").arg(Images::file(icon)).arg(text);
261}
262
263QString InfoFile::openPar(QString text) {
264 return "<h2>" + text + "</h2>"
265 "<table width=\"100%\">";
266}
267
268QString InfoFile::closePar() {
269 row = 0;
270 return "</table>";
271}
272
273QString InfoFile::openItem() {
274 if (row % 2 == 1)
275 return "<tr bgcolor=\"lavender\">";
276 else
277 return "<tr bgcolor=\"powderblue\">";
278}
279
280QString InfoFile::closeItem() {
281 return "</tr>";
282}
283
284QString InfoFile::addTrackColumns(QStringList l) {
285 row = 0;
286 QString s = openItem();
287 foreach(QString i, l) { s += "<td>" + i + "</td>"; }
288 s += closeItem();
289 return s;
290}
291
292QString InfoFile::addItem( QString tag, QString value ) {
293 row++;
294 return openItem() +
295 "<td><b>" + tag + "</b></td>" +
296 "<td>" + value + "</td>" +
297 closeItem();
298}
299
300QString InfoFile::addTrack(int n, QString lang, QString name, int ID, QString type) {
301 QString s = "<td>" + QString::number(n) + "</td>";
302 if (!type.isEmpty()) s += "<td>" + type + "</td>";
303 s += QString("<td>%1</td><td>%2</td><td>%3</td>").arg(lang).arg(name).arg(ID);
304 return s;
305}
306
307QString InfoFile::defaultStyle() {
308 return "";
309}
310#endif
311
312QString InfoFile::style() {
313 QString s = defaultStyle();
314
315 QString stylesheet_file = Images::file("infofile.css");
316 qDebug() << "InfoFile::style: stylesheet_file:" << stylesheet_file;
317
318 QFile file(stylesheet_file);
319 if (file.exists() && file.open(QIODevice::ReadOnly | QIODevice::Text)) {
320 s = file.readAll();
321 }
322
323 return s;
324}
325
326#include "moc_infofile.cpp"
Note: See TracBrowser for help on using the repository browser.