source: smplayer/trunk/src/infofile.cpp@ 182

Last change on this file since 182 was 181, checked in by Silvan Scherrer, 9 years ago

smplayer: update trunk to version 16.8.0

  • Property svn:eol-style set to LF
File size: 9.2 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2016 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 s += addItem( tr("Length"), Helper::formatTime((int)md.duration) );
89 s += addItem( tr("Demuxer"), md.demuxer );
90 s += closePar();
91
92 // Clip info
93 QString c;
94 if (!md.clip_name.isEmpty()) c+= addItem( tr("Name"), md.clip_name );
95 if (!md.clip_artist.isEmpty()) c+= addItem( tr("Artist"), md.clip_artist );
96 if (!md.clip_author.isEmpty()) c+= addItem( tr("Author"), md.clip_author );
97 if (!md.clip_album.isEmpty()) c+= addItem( tr("Album"), md.clip_album );
98 if (!md.clip_genre.isEmpty()) c+= addItem( tr("Genre"), md.clip_genre );
99 if (!md.clip_date.isEmpty()) {
100 QString s = md.clip_date;
101 QDateTime d = QDateTime::fromString(md.clip_date, Qt::ISODate);
102 if (d.isValid()) {
103 s = d.toString("yyyy-MM-dd hh:mm:ss");
104 /* s = QLocale::system().toString(d, QLocale::ShortFormat); */
105 }
106 c+= addItem( tr("Date"), s );
107 }
108 if (!md.clip_track.isEmpty()) c+= addItem( tr("Track"), md.clip_track );
109 if (!md.clip_copyright.isEmpty()) c+= addItem( tr("Copyright"), md.clip_copyright );
110 if (!md.clip_comment.isEmpty()) c+= addItem( tr("Comment"), md.clip_comment );
111 if (!md.clip_software.isEmpty()) c+= addItem( tr("Software"), md.clip_software );
112 if (!md.stream_title.isEmpty()) c+= addItem( tr("Stream title"), md.stream_title );
113 if (!md.stream_url.isEmpty()) c+= addItem( tr("Stream URL"), md.stream_url );
114
115 if (!c.isEmpty()) {
116 s += openPar( tr("Clip info") );
117 s += c;
118 s += closePar();
119 }
120
121 // Video info
122 if (!md.novideo) {
123 s += openPar( tr("Video") );
124 s += addItem( tr("Resolution"), QString("%1 x %2").arg(md.video_width).arg(md.video_height) );
125 s += addItem( tr("Aspect ratio"), QString::number(md.video_aspect) );
126 s += addItem( tr("Format"), md.video_format );
127 s += addItem( tr("Bitrate"), tr("%1 kbps").arg(md.video_bitrate / 1000) );
128 s += addItem( tr("Frames per second"), md.video_fps );
129 s += addItem( tr("Selected codec"), md.video_codec );
130 s += closePar();
131 }
132
133 // Audio info
134 s += openPar( tr("Initial Audio Stream") );
135 s += addItem( tr("Format"), md.audio_format );
136 s += addItem( tr("Bitrate"), tr("%1 kbps").arg(md.audio_bitrate / 1000) );
137 s += addItem( tr("Rate"), tr("%1 Hz").arg(md.audio_rate) );
138 s += addItem( tr("Channels"), QString::number(md.audio_nch) );
139 s += addItem( tr("Selected codec"), md.audio_codec );
140 s += closePar();
141
142 // Audio Tracks
143 if (md.audios.numItems() > 0) {
144 s += openPar( tr("Audio Streams") );
145 s += addTrackColumns( QStringList() << "#" << tr("Language") << tr("Name") << "ID" );
146
147 for (int n = 0; n < md.audios.numItems(); n++) {
148 #ifndef INFO_SIMPLE_LAYOUT
149 row++;
150 #endif
151 s += openItem();
152 QString lang = md.audios.itemAt(n).lang();
153 if (lang.isEmpty()) lang = "<i>&lt;"+tr("undefined")+"&gt;</i>";
154 QString name = md.audios.itemAt(n).name();
155 if (name.isEmpty()) name = "<i>&lt;"+tr("undefined")+"&gt;</i>";
156 s += addTrack(n, lang, name, md.audios.itemAt(n).ID());
157 s += closeItem();
158 }
159 s += closePar();
160 }
161
162 // Subtitles
163 if (md.subs.numItems() > 0) {
164 s += openPar( tr("Subtitles") );
165 s += addTrackColumns( QStringList() << "#" << tr("Type") << tr("Language") << tr("Name") << "ID" );
166 for (int n = 0; n < md.subs.numItems(); n++) {
167 #ifndef INFO_SIMPLE_LAYOUT
168 row++;
169 #endif
170 s += openItem();
171 QString t;
172 switch (md.subs.itemAt(n).type()) {
173 case SubData::File: t = "FILE_SUB"; break;
174 case SubData::Vob: t = "VOB"; break;
175 default: t = "SUB";
176 }
177 QString lang = md.subs.itemAt(n).lang();
178 if (lang.isEmpty()) lang = "<i>&lt;"+tr("undefined")+"&gt;</i>";
179 QString name = md.subs.itemAt(n).name();
180 if (name.isEmpty()) name = "<i>&lt;"+tr("undefined")+"&gt;</i>";
181 s += addTrack(n, lang, name, md.subs.itemAt(n).ID(), t);
182 s += closeItem();
183 }
184 s += closePar();
185 }
186
187 QString page = "<html><head><style type=\"text/css\">" + style() + "</style></head><body>"+ s + "</body></html>";
188 //qDebug() << "InfoFile::getInfo:" << page;
189 return page;
190}
191
192
193#ifdef INFO_SIMPLE_LAYOUT
194QString InfoFile::title(QString text, QString /* icon */) {
195 return QString("<h1>%1</h1>").arg(text);
196}
197
198QString InfoFile::openPar(QString text) {
199 return "<h2>" + text + "</h2><ul>";
200}
201
202QString InfoFile::closePar() {
203 return "</ul>";
204}
205
206QString InfoFile::openItem() {
207 return "<li>";
208}
209
210QString InfoFile::closeItem() {
211 return "</li>";
212}
213
214QString InfoFile::addItem( QString tag, QString value ) {
215 return openItem() + QString("<b>%1</b>: %2").arg(tag).arg(value) + closeItem();
216}
217
218QString InfoFile::addTrackColumns(QStringList /* l */) {
219 return "";
220}
221
222QString InfoFile::addTrack(int n, QString lang, QString name, int ID, QString type) {
223 QString s = "<b>" + tr("Track %1").arg(n) + "</b>";
224 #if 1
225 s += "<ul>";
226 s += "<li>" + tr("Language: %1").arg(lang) + "</li>";
227 s += "<li>" + tr("Name: %1").arg(name) + "</li>";
228 s += "<li>" + tr("ID: %1").arg(ID) + "</li>";
229 if (!type.isEmpty()) {
230 s += "<li>" + tr("Type: %1").arg(type) + "</li>";
231 }
232 s += "</ul>";
233 #else
234 s += "<br>&nbsp;&bull; " + tr("Language: %1").arg(lang);
235 s += "<br>&nbsp;&bull; " + tr("Name: %1").arg(name);
236 s += "<br>&nbsp;&bull; " + tr("ID: %1").arg(ID);
237 if (!type.isEmpty()) {
238 s += "<br>&nbsp;&bull; " + tr("Type: %1").arg(type);
239 }
240 #endif
241 return s;
242}
243
244QString InfoFile::defaultStyle() {
245 return
246 "ul { margin: 0px; }"
247 //"body { background-color: gray; }"
248 "h2 { background-color: whitesmoke; color: navy;}"
249 ;
250}
251
252#else
253
254QString InfoFile::title(QString text, QString icon) {
255 return QString("<h1><img src=\"%1\">%2</h1>").arg(Images::file(icon)).arg(text);
256}
257
258QString InfoFile::openPar(QString text) {
259 return "<h2>" + text + "</h2>"
260 "<table width=\"100%\">";
261}
262
263QString InfoFile::closePar() {
264 row = 0;
265 return "</table>";
266}
267
268QString InfoFile::openItem() {
269 if (row % 2 == 1)
270 return "<tr bgcolor=\"lavender\">";
271 else
272 return "<tr bgcolor=\"powderblue\">";
273}
274
275QString InfoFile::closeItem() {
276 return "</tr>";
277}
278
279QString InfoFile::addTrackColumns(QStringList l) {
280 row = 0;
281 QString s = openItem();
282 foreach(QString i, l) { s += "<td>" + i + "</td>"; }
283 s += closeItem();
284 return s;
285}
286
287QString InfoFile::addItem( QString tag, QString value ) {
288 row++;
289 return openItem() +
290 "<td><b>" + tag + "</b></td>" +
291 "<td>" + value + "</td>" +
292 closeItem();
293}
294
295QString InfoFile::addTrack(int n, QString lang, QString name, int ID, QString type) {
296 QString s = "<td>" + QString::number(n) + "</td>";
297 if (!type.isEmpty()) s += "<td>" + type + "</td>";
298 s += QString("<td>%1</td><td>%2</td><td>%3</td>").arg(lang).arg(name).arg(ID);
299 return s;
300}
301
302QString InfoFile::defaultStyle() {
303 return "";
304}
305#endif
306
307QString InfoFile::style() {
308 QString s = defaultStyle();
309
310 QString stylesheet_file = Images::file("infofile.css");
311 qDebug() << "InfoFile::style: stylesheet_file:" << stylesheet_file;
312
313 QFile file(stylesheet_file);
314 if (file.exists() && file.open(QIODevice::ReadOnly | QIODevice::Text)) {
315 s = file.readAll();
316 }
317
318 return s;
319}
320
321#include "moc_infofile.cpp"
Note: See TracBrowser for help on using the repository browser.