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