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

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

SMPlayer: update trunk to latest 0.8.7

  • Property svn:eol-style set to LF
File size: 7.5 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 = "<img src=\"" + Images::file(icon) + "\"> ";
57
58#ifdef BLURAY_SUPPORT
59 if (md.type == TYPE_DVD || md.type == TYPE_BLURAY)
60#else
61 if (md.type == TYPE_DVD)
62#endif
63 {
64 DiscData disc_data = DiscName::split(md.filename);
65 s += title( icon + disc_data.protocol + "://" + QString::number(disc_data.title) );
66 } else {
67 s += title( icon + md.displayName() );
68 }
69
70 s += openPar( tr("General") );
71 if (fi.exists()) {
72 //s += addItem( tr("Path"), fi.dirPath() );
73 s += addItem( tr("File"), fi.absoluteFilePath() );
74 s += addItem( tr("Size"), tr("%1 KB (%2 MB)").arg(fi.size()/1024)
75 .arg(fi.size()/1048576) );
76 } else {
77 QString url = md.filename;
78 s += addItem( tr("URL"), url );
79 }
80 s += addItem( tr("Length"), Helper::formatTime((int)md.duration) );
81 s += addItem( tr("Demuxer"), md.demuxer );
82 s += closePar();
83
84 // Clip info
85 QString c;
86 if (!md.clip_name.isEmpty()) c+= addItem( tr("Name"), md.clip_name );
87 if (!md.clip_artist.isEmpty()) c+= addItem( tr("Artist"), md.clip_artist );
88 if (!md.clip_author.isEmpty()) c+= addItem( tr("Author"), md.clip_author );
89 if (!md.clip_album.isEmpty()) c+= addItem( tr("Album"), md.clip_album );
90 if (!md.clip_genre.isEmpty()) c+= addItem( tr("Genre"), md.clip_genre );
91 if (!md.clip_date.isEmpty()) c+= addItem( tr("Date"), md.clip_date );
92 if (!md.clip_track.isEmpty()) c+= addItem( tr("Track"), md.clip_track );
93 if (!md.clip_copyright.isEmpty()) c+= addItem( tr("Copyright"), md.clip_copyright );
94 if (!md.clip_comment.isEmpty()) c+= addItem( tr("Comment"), md.clip_comment );
95 if (!md.clip_software.isEmpty()) c+= addItem( tr("Software"), md.clip_software );
96 if (!md.stream_title.isEmpty()) c+= addItem( tr("Stream title"), md.stream_title );
97 if (!md.stream_url.isEmpty()) c+= addItem( tr("Stream URL"), md.stream_url );
98
99 if (!c.isEmpty()) {
100 s += openPar( tr("Clip info") );
101 s += c;
102 s += closePar();
103 }
104
105 // Video info
106 if (!md.novideo) {
107 s += openPar( tr("Video") );
108 s += addItem( tr("Resolution"), QString("%1 x %2").arg(md.video_width).arg(md.video_height) );
109 s += addItem( tr("Aspect ratio"), QString::number(md.video_aspect) );
110 s += addItem( tr("Format"), md.video_format );
111 s += addItem( tr("Bitrate"), tr("%1 kbps").arg(md.video_bitrate / 1000) );
112 s += addItem( tr("Frames per second"), md.video_fps );
113 s += addItem( tr("Selected codec"), md.video_codec );
114 s += closePar();
115 }
116
117 // Audio info
118 s += openPar( tr("Initial Audio Stream") );
119 s += addItem( tr("Format"), md.audio_format );
120 s += addItem( tr("Bitrate"), tr("%1 kbps").arg(md.audio_bitrate / 1000) );
121 s += addItem( tr("Rate"), tr("%1 Hz").arg(md.audio_rate) );
122 s += addItem( tr("Channels"), QString::number(md.audio_nch) );
123 s += addItem( tr("Selected codec"), md.audio_codec );
124 s += closePar();
125
126 // Audio Tracks
127 if (md.audios.numItems() > 0) {
128 s += openPar( tr("Audio Streams") );
129 row++;
130 s += openItem();
131 s += "<td>" + tr("#", "Info for translators: this is a abbreviation for number") + "</td><td>" +
132 tr("Language") + "</td><td>" + tr("Name") +"</td><td>" +
133 tr("ID", "Info for translators: this is a identification code") + "</td>";
134 s += closeItem();
135 for (int n = 0; n < md.audios.numItems(); n++) {
136 row++;
137 s += openItem();
138 QString lang = md.audios.itemAt(n).lang();
139 if (lang.isEmpty()) lang = "<i>&lt;"+tr("empty")+"&gt;</i>";
140 QString name = md.audios.itemAt(n).name();
141 if (name.isEmpty()) name = "<i>&lt;"+tr("empty")+"&gt;</i>";
142 s += QString("<td>%1</td><td>%2</td><td>%3</td><td>%4</td>")
143 .arg(n).arg(lang).arg(name)
144 .arg(md.audios.itemAt(n).ID());
145 s += closeItem();
146 }
147 s += closePar();
148 }
149
150 // Subtitles
151 if (md.subs.numItems() > 0) {
152 s += openPar( tr("Subtitles") );
153 row++;
154 s += openItem();
155 s += "<td>" + tr("#", "Info for translators: this is a abbreviation for number") + "</td><td>" +
156 tr("Type") + "</td><td>" +
157 tr("Language") + "</td><td>" + tr("Name") +"</td><td>" +
158 tr("ID", "Info for translators: this is a identification code") + "</td>";
159 s += closeItem();
160 for (int n = 0; n < md.subs.numItems(); n++) {
161 row++;
162 s += openItem();
163 QString t;
164 switch (md.subs.itemAt(n).type()) {
165 case SubData::File: t = "FILE_SUB"; break;
166 case SubData::Vob: t = "VOB"; break;
167 default: t = "SUB";
168 }
169 QString lang = md.subs.itemAt(n).lang();
170 if (lang.isEmpty()) lang = "<i>&lt;"+tr("empty")+"&gt;</i>";
171 QString name = md.subs.itemAt(n).name();
172 if (name.isEmpty()) name = "<i>&lt;"+tr("empty")+"&gt;</i>";
173 /*
174 s += QString("<td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td>")
175 .arg(n).arg(t).arg(lang).arg(name)
176 .arg(md.subs.itemAt(n).ID());
177 */
178 s += "<td>" + QString::number(n) + "</td><td>" + t +
179 "</td><td>" + lang + "</td><td>" + name +
180 "</td><td>" + QString::number(md.subs.itemAt(n).ID()) + "</td>";
181 s += closeItem();
182 }
183 s += closePar();
184 }
185
186 return "<html><body bgcolor=\"white\"><font color=\"black\">"+ s + "</font></body></html>";
187}
188
189QString InfoFile::title(QString text) {
190 return "<h1>" + text + "</h1>";
191}
192
193QString InfoFile::openPar(QString text) {
194 return "<h2>" + text + "</h2>"
195 "<table width=\"100%\">";
196}
197
198QString InfoFile::closePar() {
199 row = 0;
200 return "</table>";
201}
202
203QString InfoFile::openItem() {
204 if (row % 2 == 1)
205 return "<tr bgcolor=\"lavender\">";
206 else
207 return "<tr bgcolor=\"powderblue\">";
208}
209
210QString InfoFile::closeItem() {
211 return "</tr>";
212}
213
214QString InfoFile::addItem( QString tag, QString value ) {
215 row++;
216 return openItem() +
217 "<td><b>" + tag + "</b></td>" +
218 "<td>" + value + "</td>" +
219 closeItem();
220}
221
222
223inline QString InfoFile::tr( const char * sourceText, const char * comment, int n ) {
224#if QT_VERSION >= 0x050000
225 return QCoreApplication::translate("InfoFile", sourceText, comment, n );
226#else
227 return QCoreApplication::translate("InfoFile", sourceText, comment, QCoreApplication::CodecForTr, n );
228#endif
229}
230
Note: See TracBrowser for help on using the repository browser.