1 /* smplayer, GUI front-end for mplayer. 2 Copyright (C) 2006-2021 Ricardo Villalba <ricardo@smplayer.info> 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 20 #ifndef SUBTRACKS_H 21 #define SUBTRACKS_H 22 23 #include <QString> 24 #include <QFileInfo> 25 #include <QList> 26 27 #include "config.h" 28 29 class QSettings; 30 31 class SubData { 32 33 public: 34 enum Type { None = -1, Vob = 0, Sub = 1, File = 2 }; 35 SubData()36 SubData() { _ID=-1; _lang=""; _name=""; _filename=""; _type = None; }; ~SubData()37 ~SubData() {}; 38 setType(Type t)39 void setType( Type t ) { _type = t; }; setID(int id)40 void setID(int id) { _ID = id; }; setLang(QString lang)41 void setLang(QString lang) { _lang = lang; }; setName(QString name)42 void setName(QString name) { _name = name; }; setFilename(QString f)43 void setFilename(QString f) { _filename = f; }; 44 type()45 Type type() { return _type; }; ID()46 int ID() { return _ID; }; lang()47 QString lang() { return _lang; }; name()48 QString name() { return _name; }; filename()49 QString filename() { return _filename; }; 50 displayName()51 QString displayName() { 52 QString dname=""; 53 54 if (!_name.isEmpty()) { 55 dname = _name; 56 if (!_lang.isEmpty()) { 57 dname += " ["+ _lang + "]"; 58 } 59 } 60 else 61 if (!_lang.isEmpty()) { 62 dname = _lang; 63 } 64 else 65 if (!_filename.isEmpty()) { 66 QFileInfo f(_filename); 67 dname = f.fileName(); 68 } 69 else 70 dname = QString::number(_ID); 71 72 return dname; 73 }; 74 75 protected: 76 Type _type; 77 int _ID; 78 QString _lang; 79 QString _name; 80 QString _filename; 81 }; 82 83 typedef QList <SubData> SubList; 84 85 86 class SubTracks 87 { 88 public: 89 enum ParseResult { SubtitleUnchanged = 0, SubtitleAdded = 1, SubtitleChanged = 2 }; 90 91 SubTracks(); 92 ~SubTracks(); 93 94 void clear(); 95 int find( SubData::Type t, int ID ); 96 97 void add( SubData::Type t, int ID ); 98 bool changeLang( SubData::Type t, int ID, QString lang ); 99 bool changeName( SubData::Type t, int ID, QString name ); 100 bool changeFilename( SubData::Type t, int ID, QString filename ); 101 102 int numItems(); 103 bool existsItemAt(int n); 104 105 SubData itemAt(int n); 106 SubData findItem( SubData::Type t, int ID ); 107 108 int IDAt(int n); 109 110 #if !SIMPLE_TRACK_SELECTION 111 int findLang(QString expr); 112 int selectOne(QString preferred_lang, int default_sub=0); 113 #endif 114 115 //! Parses a line from mplayer output with subtitle info 116 ParseResult parse(QString text); 117 118 void list(); 119 void listNames(); 120 /* void test(); */ 121 122 void save(QSettings * set, const QString & name); 123 void load(QSettings * set, const QString & name); 124 125 protected: 126 SubList subs; 127 int index; 128 }; 129 130 #endif 131