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

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

smplayer: update trunk to version 16.4

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