source: smplayer/trunk/src/prefnetwork.cpp@ 189

Last change on this file since 189 was 188, checked in by Silvan Scherrer, 8 years ago

SMPlayer: update trunk to version 17.1.0

File size: 8.8 KB
Line 
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 "prefnetwork.h"
20#include "preferences.h"
21#include "images.h"
22#include <QNetworkProxy>
23
24#ifdef YOUTUBE_SUPPORT
25#include "retrieveyoutubeurl.h"
26#endif
27
28#ifdef CHROMECAST_SUPPORT
29#include "chromecast.h"
30#endif
31
32PrefNetwork::PrefNetwork(QWidget * parent, Qt::WindowFlags f)
33 : PrefWidget(parent, f )
34{
35 setupUi(this);
36
37 proxy_type_combo->addItem( tr("HTTP"), QNetworkProxy::HttpProxy);
38 proxy_type_combo->addItem( tr("SOCKS5"), QNetworkProxy::Socks5Proxy);
39
40#ifdef YOUTUBE_SUPPORT
41 yt_quality_combo->addItem( "240p (flv)", RetrieveYoutubeUrl::FLV_240p );
42
43 yt_quality_combo->addItem( "360p (flv)", RetrieveYoutubeUrl::FLV_360p );
44 yt_quality_combo->addItem( "360p (mp4)", RetrieveYoutubeUrl::MP4_360p );
45 yt_quality_combo->addItem( "360p (webm)", RetrieveYoutubeUrl::WEBM_360p );
46
47 yt_quality_combo->addItem( "480p (flv)", RetrieveYoutubeUrl::FLV_480p );
48 yt_quality_combo->addItem( "480p (webm)", RetrieveYoutubeUrl::WEBM_480p );
49
50 yt_quality_combo->addItem( "720p (mp4)", RetrieveYoutubeUrl::MP4_720p );
51 yt_quality_combo->addItem( "720p (webm)", RetrieveYoutubeUrl::WEBM_720p );
52
53 yt_quality_combo->addItem( "1080p (mp4)", RetrieveYoutubeUrl::MP4_1080p );
54 yt_quality_combo->addItem( "1080p (webm)", RetrieveYoutubeUrl::WEBM_1080p );
55#endif
56
57 connect(streaming_type_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(streaming_type_combo_changed(int)));
58
59#ifndef YOUTUBE_SUPPORT
60 youtube_box->hide();
61#endif
62
63 retranslateStrings();
64}
65
66PrefNetwork::~PrefNetwork()
67{
68}
69
70QString PrefNetwork::sectionName() {
71 return tr("Network");
72}
73
74QPixmap PrefNetwork::sectionIcon() {
75 return Images::icon("pref_network");
76}
77
78void PrefNetwork::retranslateStrings() {
79 retranslateUi(this);
80
81 int streaming_item = streaming_type_combo->currentIndex();
82 streaming_type_combo->clear();
83 streaming_type_combo->addItem(tr("Disabled"), Preferences::NoStreaming);
84 #ifdef MPV_SUPPORT
85 streaming_type_combo->addItem(tr("Auto"), Preferences::StreamingAuto);
86 #endif
87 #ifdef YOUTUBE_SUPPORT
88 streaming_type_combo->addItem("YouTube", Preferences::StreamingYT);
89 #endif
90 #ifdef MPV_SUPPORT
91 streaming_type_combo->addItem("mpv + youtube-dl", Preferences::StreamingYTDL);
92 #endif
93 streaming_type_combo->setCurrentIndex(streaming_item);
94
95 createHelp();
96}
97
98void PrefNetwork::setData(Preferences * pref) {
99 use_proxy_check->setChecked(pref->use_proxy);
100 proxy_hostname_edit->setText(pref->proxy_host);
101 proxy_port_spin->setValue(pref->proxy_port);
102 proxy_username_edit->setText(pref->proxy_username);
103 proxy_password_edit->setText(pref->proxy_password);
104
105 setProxyType(pref->proxy_type);
106
107 setStreamingType(pref->streaming_type);
108#ifdef YOUTUBE_SUPPORT
109 setYTQuality( pref->yt_quality );
110 yt_user_agent_edit->setText( pref->yt_user_agent );
111#endif
112
113#ifdef CHROMECAST_SUPPORT
114 Chromecast * cc = Chromecast::instance();
115 setLocalIP(cc->localAddress(), cc->localAddresses());
116 port_spin->setValue(cc->serverPort());
117 directory_listing_check->setChecked(cc->directoryListing());
118#endif
119}
120
121void PrefNetwork::getData(Preferences * pref) {
122 requires_restart = false;
123
124 pref->use_proxy = use_proxy_check->isChecked();
125 pref->proxy_host = proxy_hostname_edit->text();
126 pref->proxy_port = proxy_port_spin->value();
127 pref->proxy_username = proxy_username_edit->text();
128 pref->proxy_password = proxy_password_edit->text();
129
130 pref->proxy_type = proxyType();
131
132 pref->streaming_type = streamingType();
133#ifdef YOUTUBE_SUPPORT
134 pref->yt_quality = YTQuality();
135 pref->yt_user_agent = yt_user_agent_edit->text();
136#endif
137
138#ifdef CHROMECAST_SUPPORT
139 Chromecast * cc = Chromecast::instance();
140 cc->setLocalAddress(localIP());
141 cc->setServerPort(port_spin->value());
142 cc->setDirectoryListing(directory_listing_check->isChecked());
143#endif
144}
145
146void PrefNetwork::setProxyType(int type) {
147 int index = proxy_type_combo->findData(type);
148 if (index == -1) index = 0;
149 proxy_type_combo->setCurrentIndex(index);
150}
151
152int PrefNetwork::proxyType() {
153 int index = proxy_type_combo->currentIndex();
154 return proxy_type_combo->itemData(index).toInt();
155}
156
157#ifdef YOUTUBE_SUPPORT
158void PrefNetwork::setYTQuality(int q) {
159 yt_quality_combo->setCurrentIndex(yt_quality_combo->findData(q));
160}
161
162int PrefNetwork::YTQuality() {
163 int index = yt_quality_combo->currentIndex();
164 return yt_quality_combo->itemData(index).toInt();
165}
166#endif
167
168void PrefNetwork::setStreamingType(int type) {
169 int i = streaming_type_combo->findData(type);
170 if (i < 0) i = 0;
171 streaming_type_combo->setCurrentIndex(i);
172}
173
174int PrefNetwork::streamingType() {
175 int i = streaming_type_combo->currentIndex();
176 return streaming_type_combo->itemData(i).toInt();
177}
178
179void PrefNetwork::streaming_type_combo_changed(int i) {
180 //qDebug() << "PrefNetwork::streaming_type_combo_changed:" << i;
181 youtube_box->setEnabled(i == Preferences::StreamingYT || i == Preferences::StreamingAuto);
182}
183
184#ifdef CHROMECAST_SUPPORT
185void PrefNetwork::setLocalIP(const QString & ip, const QStringList & values) {
186 local_ip_combo->clear();
187 local_ip_combo->addItem(tr("Auto"));
188 local_ip_combo->addItems(values);
189
190 if (ip.isEmpty()) {
191 local_ip_combo->setCurrentIndex(0);
192 } else {
193 int pos = local_ip_combo->findText(ip);
194 if (pos > -1) {
195 local_ip_combo->setCurrentIndex(pos);
196 } else {
197 local_ip_combo->setEditText(ip);
198 }
199 }
200}
201
202QString PrefNetwork::localIP() {
203 if (local_ip_combo->currentIndex() == 0) {
204 return "";
205 } else {
206 return local_ip_combo->currentText();
207 }
208}
209#endif
210
211void PrefNetwork::createHelp() {
212 clearHelp();
213
214 addSectionTitle(tr("YouTube"));
215
216 setWhatsThis(streaming_type_combo, tr("Support for video sites"),
217 "<ul>"
218 "<li><b>" + tr("Disabled") +":</b> " + tr("support for video sites is turned off") +"</li>"+
219 #ifdef MPV_SUPPORT
220 "<li><b>" + tr("Auto") +":</b> " + tr("it will try to use mpv + youtube-dl only for the sites that require it") +"</li>"+
221 #endif
222 #ifdef YOUTUBE_SUPPORT
223 "<li><b>YouTube:</b> " + tr("only the internal support for YouTube will be used") +"</li>"+
224 #endif
225 #ifdef MPV_SUPPORT
226 "<li><b>mpv + youtube-dl:</b> " +tr("uses mpv + youtube-dl for all sites") +"</li>"+
227 #endif
228 "</ul>"
229 );
230
231 /*
232 setWhatsThis(yt_support_check, tr("Enable Youtube internal support"),
233 tr("If this option is checked, SMPlayer will try to play videos from Youtube URLs.") );
234 */
235
236 setWhatsThis(yt_quality_combo, tr("Playback quality"),
237 tr("Select the preferred quality for YouTube videos.") );
238
239 setWhatsThis(yt_user_agent_edit, tr("User agent"),
240 tr("Set the user agent that SMPlayer will use when connecting to YouTube.") );
241
242#ifdef MPV_SUPPORT
243 /*
244 setWhatsThis(streaming_check, tr("Enable mpv's support for streaming sites"),
245 tr("If this option is checked, SMPlayer will try to play videos from "
246 "streaming sites like Youtube, Dailymotion, Vimeo, Vevo, etc.") + "<br>"+
247 tr("Requires mpv and youtube-dl.") );
248 */
249#endif
250
251#ifdef CHROMECAST_SUPPORT
252 addSectionTitle(tr("Chromecast"));
253
254 setWhatsThis(local_ip_combo, tr("Local IP"),
255 tr("The local IP address of this computer. It will be passed to Chromecast "
256 "so that it can access the files from this computer.") );
257
258 setWhatsThis(port_spin, tr("Port"),
259 tr("The port that the web server will use.") );
260
261 setWhatsThis(directory_listing_check, tr("Directory listing"),
262 tr("When the web server is running, any device in your network can access the "
263 "files from this computer. If this option is on, any device can get a listing "
264 "of the files in this computer. "
265 "If this option is off, the list won't be available.") );
266#endif
267
268 addSectionTitle(tr("Proxy"));
269
270 setWhatsThis(use_proxy_check, tr("Enable proxy"),
271 tr("Enable/disable the use of the proxy.") );
272
273 setWhatsThis(proxy_hostname_edit, tr("Host"),
274 tr("The host name of the proxy.") );
275
276 setWhatsThis(proxy_port_spin, tr("Port"),
277 tr("The port of the proxy.") );
278
279 setWhatsThis(proxy_username_edit, tr("Username"),
280 tr("If the proxy requires authentication, this sets the username.") );
281
282 setWhatsThis(proxy_password_edit, tr("Password"),
283 tr("The password for the proxy. <b>Warning:</b> the password will be saved "
284 "as plain text in the configuration file.") );
285
286 setWhatsThis(proxy_type_combo, tr("Type"),
287 tr("Select the proxy type to be used.") );
288
289}
290
291#include "moc_prefnetwork.cpp"
Note: See TracBrowser for help on using the repository browser.