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

Last change on this file since 184 was 181, checked in by Silvan Scherrer, 9 years ago

smplayer: update trunk to version 16.8.0

File size: 7.1 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2016 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
28PrefNetwork::PrefNetwork(QWidget * parent, Qt::WindowFlags f)
29 : PrefWidget(parent, f )
30{
31 setupUi(this);
32
33 proxy_type_combo->addItem( tr("HTTP"), QNetworkProxy::HttpProxy);
34 proxy_type_combo->addItem( tr("SOCKS5"), QNetworkProxy::Socks5Proxy);
35
36#ifdef YOUTUBE_SUPPORT
37 yt_quality_combo->addItem( "240p (flv)", RetrieveYoutubeUrl::FLV_240p );
38
39 yt_quality_combo->addItem( "360p (flv)", RetrieveYoutubeUrl::FLV_360p );
40 yt_quality_combo->addItem( "360p (mp4)", RetrieveYoutubeUrl::MP4_360p );
41 yt_quality_combo->addItem( "360p (webm)", RetrieveYoutubeUrl::WEBM_360p );
42
43 yt_quality_combo->addItem( "480p (flv)", RetrieveYoutubeUrl::FLV_480p );
44 yt_quality_combo->addItem( "480p (webm)", RetrieveYoutubeUrl::WEBM_480p );
45
46 yt_quality_combo->addItem( "720p (mp4)", RetrieveYoutubeUrl::MP4_720p );
47 yt_quality_combo->addItem( "720p (webm)", RetrieveYoutubeUrl::WEBM_720p );
48
49 yt_quality_combo->addItem( "1080p (mp4)", RetrieveYoutubeUrl::MP4_1080p );
50 yt_quality_combo->addItem( "1080p (webm)", RetrieveYoutubeUrl::WEBM_1080p );
51#endif
52
53 connect(streaming_type_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(streaming_type_combo_changed(int)));
54
55#ifndef YOUTUBE_SUPPORT
56 youtube_box->hide();
57#endif
58
59 retranslateStrings();
60}
61
62PrefNetwork::~PrefNetwork()
63{
64}
65
66QString PrefNetwork::sectionName() {
67 return tr("Network");
68}
69
70QPixmap PrefNetwork::sectionIcon() {
71 return Images::icon("pref_network");
72}
73
74void PrefNetwork::retranslateStrings() {
75 retranslateUi(this);
76
77 int streaming_item = streaming_type_combo->currentIndex();
78 streaming_type_combo->clear();
79 streaming_type_combo->addItem(tr("Disabled"), Preferences::NoStreaming);
80 #ifdef MPV_SUPPORT
81 streaming_type_combo->addItem(tr("Auto"), Preferences::StreamingAuto);
82 #endif
83 #ifdef YOUTUBE_SUPPORT
84 streaming_type_combo->addItem("YouTube", Preferences::StreamingYT);
85 #endif
86 #ifdef MPV_SUPPORT
87 streaming_type_combo->addItem("mpv + youtube-dl", Preferences::StreamingYTDL);
88 #endif
89 streaming_type_combo->setCurrentIndex(streaming_item);
90
91 createHelp();
92}
93
94void PrefNetwork::setData(Preferences * pref) {
95 use_proxy_check->setChecked(pref->use_proxy);
96 proxy_hostname_edit->setText(pref->proxy_host);
97 proxy_port_spin->setValue(pref->proxy_port);
98 proxy_username_edit->setText(pref->proxy_username);
99 proxy_password_edit->setText(pref->proxy_password);
100
101 setProxyType(pref->proxy_type);
102
103 setStreamingType(pref->streaming_type);
104#ifdef YOUTUBE_SUPPORT
105 setYTQuality( pref->yt_quality );
106 yt_user_agent_edit->setText( pref->yt_user_agent );
107#endif
108}
109
110void PrefNetwork::getData(Preferences * pref) {
111 requires_restart = false;
112
113 pref->use_proxy = use_proxy_check->isChecked();
114 pref->proxy_host = proxy_hostname_edit->text();
115 pref->proxy_port = proxy_port_spin->value();
116 pref->proxy_username = proxy_username_edit->text();
117 pref->proxy_password = proxy_password_edit->text();
118
119 pref->proxy_type = proxyType();
120
121 pref->streaming_type = streamingType();
122#ifdef YOUTUBE_SUPPORT
123 pref->yt_quality = YTQuality();
124 pref->yt_user_agent = yt_user_agent_edit->text();
125#endif
126}
127
128void PrefNetwork::setProxyType(int type) {
129 int index = proxy_type_combo->findData(type);
130 if (index == -1) index = 0;
131 proxy_type_combo->setCurrentIndex(index);
132}
133
134int PrefNetwork::proxyType() {
135 int index = proxy_type_combo->currentIndex();
136 return proxy_type_combo->itemData(index).toInt();
137}
138
139#ifdef YOUTUBE_SUPPORT
140void PrefNetwork::setYTQuality(int q) {
141 yt_quality_combo->setCurrentIndex(yt_quality_combo->findData(q));
142}
143
144int PrefNetwork::YTQuality() {
145 int index = yt_quality_combo->currentIndex();
146 return yt_quality_combo->itemData(index).toInt();
147}
148#endif
149
150void PrefNetwork::setStreamingType(int type) {
151 int i = streaming_type_combo->findData(type);
152 if (i < 0) i = 0;
153 streaming_type_combo->setCurrentIndex(i);
154}
155
156int PrefNetwork::streamingType() {
157 int i = streaming_type_combo->currentIndex();
158 return streaming_type_combo->itemData(i).toInt();
159}
160
161void PrefNetwork::streaming_type_combo_changed(int i) {
162 //qDebug() << "PrefNetwork::streaming_type_combo_changed:" << i;
163 youtube_box->setEnabled(i == Preferences::StreamingYT || i == Preferences::StreamingAuto);
164}
165
166void PrefNetwork::createHelp() {
167 clearHelp();
168
169 addSectionTitle(tr("YouTube"));
170
171 setWhatsThis(streaming_type_combo, tr("Support for video sites"),
172 "<ul>"
173 "<li><b>" + tr("Disabled") +":</b> " + tr("support for video sites is turned off") +"</li>"+
174 #ifdef MPV_SUPPORT
175 "<li><b>" + tr("Auto") +":</b> " + tr("it will try to use mpv + youtube-dl only for the sites that require it") +"</li>"+
176 #endif
177 #ifdef YOUTUBE_SUPPORT
178 "<li><b>YouTube:</b> " + tr("only the internal support for YouTube will be used") +"</li>"+
179 #endif
180 #ifdef MPV_SUPPORT
181 "<li><b>mpv + youtube-dl:</b> " +tr("uses mpv + youtube-dl for all sites") +"</li>"+
182 #endif
183 "</ul>"
184 );
185
186 /*
187 setWhatsThis(yt_support_check, tr("Enable Youtube internal support"),
188 tr("If this option is checked, SMPlayer will try to play videos from Youtube URLs.") );
189 */
190
191 setWhatsThis(yt_quality_combo, tr("Playback quality"),
192 tr("Select the preferred quality for YouTube videos.") );
193
194 setWhatsThis(yt_user_agent_edit, tr("User agent"),
195 tr("Set the user agent that SMPlayer will use when connecting to YouTube.") );
196
197#ifdef MPV_SUPPORT
198 /*
199 setWhatsThis(streaming_check, tr("Enable mpv's support for streaming sites"),
200 tr("If this option is checked, SMPlayer will try to play videos from "
201 "streaming sites like Youtube, Dailymotion, Vimeo, Vevo, etc.") + "<br>"+
202 tr("Requires mpv and youtube-dl.") );
203 */
204#endif
205
206 addSectionTitle(tr("Proxy"));
207
208 setWhatsThis(use_proxy_check, tr("Enable proxy"),
209 tr("Enable/disable the use of the proxy.") );
210
211 setWhatsThis(proxy_hostname_edit, tr("Host"),
212 tr("The host name of the proxy.") );
213
214 setWhatsThis(proxy_port_spin, tr("Port"),
215 tr("The port of the proxy.") );
216
217 setWhatsThis(proxy_username_edit, tr("Username"),
218 tr("If the proxy requires authentication, this sets the username.") );
219
220 setWhatsThis(proxy_password_edit, tr("Password"),
221 tr("The password for the proxy. <b>Warning:</b> the password will be saved "
222 "as plain text in the configuration file.") );
223
224 setWhatsThis(proxy_type_combo, tr("Type"),
225 tr("Select the proxy type to be used.") );
226
227}
228
229#include "moc_prefnetwork.cpp"
Note: See TracBrowser for help on using the repository browser.