1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2017 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 "tvlist.h"
|
---|
20 | #include "favoriteeditor.h"
|
---|
21 | #include "images.h"
|
---|
22 |
|
---|
23 | #include <QFile>
|
---|
24 | #include <QDir>
|
---|
25 | #include <QTextStream>
|
---|
26 |
|
---|
27 | TVList::TVList(bool check_channels_conf, Services services, QString filename, QWidget * parent)
|
---|
28 | : Favorites(filename,parent)
|
---|
29 | {
|
---|
30 | #ifndef Q_OS_WIN
|
---|
31 | if (check_channels_conf) {
|
---|
32 | /* f_list.clear(); */
|
---|
33 | parse_channels_conf(services);
|
---|
34 | updateMenu();
|
---|
35 | }
|
---|
36 | #endif
|
---|
37 | }
|
---|
38 |
|
---|
39 | TVList::~TVList() {
|
---|
40 | }
|
---|
41 |
|
---|
42 | Favorites * TVList::createNewObject(QString filename, QWidget * parent) {
|
---|
43 | return new TVList(false, TV, filename, parent);
|
---|
44 | }
|
---|
45 |
|
---|
46 | #ifndef Q_OS_WIN
|
---|
47 | void TVList::parse_channels_conf(Services services) {
|
---|
48 | qDebug("TVList::parse_channels_conf");
|
---|
49 |
|
---|
50 | QString file = QDir::homePath() + "/.mplayer/channels.conf.ter";
|
---|
51 |
|
---|
52 | if (!QFile::exists(file)) {
|
---|
53 | qDebug("VList::parse_channels_conf: %s doesn't exist", file.toUtf8().constData());
|
---|
54 | file = QDir::homePath() + "/.mplayer/channels.conf";
|
---|
55 | }
|
---|
56 |
|
---|
57 | QFile f( file );
|
---|
58 | if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
---|
59 | qDebug("TVList::parse_channels_conf: can't open %s", file.toUtf8().constData());
|
---|
60 | return;
|
---|
61 | }
|
---|
62 |
|
---|
63 | QTextStream in(&f);
|
---|
64 | while (!in.atEnd()) {
|
---|
65 | QString line = in.readLine();
|
---|
66 | qDebug("TVList::parse_channels_conf: '%s'", line.toUtf8().constData());
|
---|
67 | QString channel = line.section(':', 0, 0);
|
---|
68 | QString video_pid = line.section(':', 10, 10);
|
---|
69 | QString audio_pid = line.section(':', 11, 11);
|
---|
70 | bool is_radio = (video_pid == "0" && audio_pid != "0");
|
---|
71 | bool is_data = (video_pid == "0" && audio_pid == "0");
|
---|
72 | bool is_tv = (!is_radio && !is_data);
|
---|
73 | if (!channel.isEmpty()) {
|
---|
74 | qDebug("TVList::parse_channels_conf: channel: '%s' video_pid: %s audio_pid: %s", channel.toUtf8().constData(),video_pid.toUtf8().constData(),audio_pid.toUtf8().constData());
|
---|
75 | QString channel_id = "dvb://"+channel;
|
---|
76 | if (findFile(channel_id) == -1) {
|
---|
77 | if ( (services.testFlag(TVList::TV) && is_tv) ||
|
---|
78 | (services.testFlag(TVList::Radio) && is_radio) ||
|
---|
79 | (services.testFlag(TVList::Data) && is_data) )
|
---|
80 | {
|
---|
81 | f_list.append( Favorite(channel, channel_id) );
|
---|
82 | }
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | QString TVList::findChannelsFile() {
|
---|
89 | QString channels_file;
|
---|
90 |
|
---|
91 | QString file = QDir::homePath() + "/.mplayer/channels.conf.ter";
|
---|
92 | if (QFile::exists(file)) return file;
|
---|
93 |
|
---|
94 | file = QDir::homePath() + "/.mplayer/channels.conf";
|
---|
95 | if (QFile::exists(file)) return file;
|
---|
96 |
|
---|
97 | file = QDir::homePath() + "/.config/mpv/channels.conf.ter";
|
---|
98 | if (QFile::exists(file)) return file;
|
---|
99 |
|
---|
100 | file = QDir::homePath() + "/.config/mpv/channels.conf";
|
---|
101 | if (QFile::exists(file)) return file;
|
---|
102 |
|
---|
103 | return QString::null;
|
---|
104 | }
|
---|
105 | #endif
|
---|
106 |
|
---|
107 | void TVList::edit() {
|
---|
108 | qDebug("TVList::edit");
|
---|
109 |
|
---|
110 | FavoriteEditor e(parent_widget);
|
---|
111 |
|
---|
112 | e.setWindowTitle( tr("Channel editor") );
|
---|
113 | e.setCaption( tr("TV/Radio list") );
|
---|
114 | e.setDialogIcon( Images::icon("open_tv", 64) );
|
---|
115 |
|
---|
116 | e.setData(f_list);
|
---|
117 | e.setStorePath( QFileInfo(_filename).absolutePath() );
|
---|
118 |
|
---|
119 | if (e.exec() == QDialog::Accepted) {
|
---|
120 | f_list = e.data();
|
---|
121 | updateMenu();
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | #include "moc_tvlist.cpp"
|
---|