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