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

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

smplayer: update trunk to version 16.4

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