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 #include "findsubtitlesconfigdialog.h"
20 #include "osclient.h"
21 #include <QNetworkProxy>
22 
FindSubtitlesConfigDialog(QWidget * parent,Qt::WindowFlags f)23 FindSubtitlesConfigDialog::FindSubtitlesConfigDialog( QWidget* parent, Qt::WindowFlags f )
24 	: QDialog(parent, f)
25 {
26 	setupUi(this);
27 
28 	search_method_combo->addItem(tr("Hash"), OSClient::Hash);
29 	search_method_combo->addItem(tr("Filename"), OSClient::Filename);
30 	search_method_combo->addItem(tr("Hash and filename"), OSClient::HashAndFilename);
31 
32 #ifdef FS_USE_PROXY
33 	proxy_type_combo->addItem( tr("HTTP"), QNetworkProxy::HttpProxy);
34 	proxy_type_combo->addItem( tr("SOCKS5"), QNetworkProxy::Socks5Proxy);
35 
36 	use_proxy_check->setWhatsThis( tr("Enable/disable the use of the proxy.") );
37 	proxy_hostname_edit->setWhatsThis( tr("The host name of the proxy.") );
38 	proxy_port_spin->setWhatsThis( tr("The port of the proxy.") );
39 	proxy_username_edit->setWhatsThis( tr("If the proxy requires authentication, this sets the username.") );
40 	proxy_password_edit->setWhatsThis(
41         tr("The password for the proxy. <b>Warning:</b> the password will be saved "
42            "as plain text in the configuration file.") );
43 	proxy_type_combo->setWhatsThis( tr("Select the proxy type to be used.") );
44 #else
45 	proxy_group->hide();
46 #endif
47 
48 #ifndef OS_SEARCH_WORKAROUND
49 	retries_label->hide();
50 	retries_spin->hide();
51 #endif
52 
53 #ifndef DOWNLOAD_SUBS
54 	misc_group->hide();
55 #endif
56 
57 #ifndef FS_USE_SERVER_CONFIG
58 	server_label->hide();
59 	server_edit->hide();
60 #endif
61 
62 #if !defined(FS_USE_SERVER_CONFIG) && !defined(OS_SEARCH_WORKAROUND)
63 	server_group->hide();
64 #endif
65 
66 	layout()->setSizeConstraint(QLayout::SetFixedSize);
67 }
68 
~FindSubtitlesConfigDialog()69 FindSubtitlesConfigDialog::~FindSubtitlesConfigDialog() {
70 }
71 
72 #ifdef FS_USE_SERVER_CONFIG
setServer(QString server)73 void FindSubtitlesConfigDialog::setServer(QString server) {
74 	server_edit->setText(server);
75 }
76 
server()77 QString FindSubtitlesConfigDialog::server() {
78 	return server_edit->text();
79 }
80 #endif
81 
setSearchMethod(int m)82 void FindSubtitlesConfigDialog::setSearchMethod(int m) {
83 	int pos = search_method_combo->findData(m);
84 	if (pos == -1) pos = 0;
85 	search_method_combo->setCurrentIndex(pos);
86 }
87 
searchMethod()88 int FindSubtitlesConfigDialog::searchMethod() {
89 	return search_method_combo->itemData(search_method_combo->currentIndex()).toInt();
90 }
91 
setUsername(QString username)92 void FindSubtitlesConfigDialog::setUsername(QString username) {
93 	os_username_edit->setText(username);
94 }
95 
username()96 QString FindSubtitlesConfigDialog::username() {
97 	return os_username_edit->text();
98 }
99 
setPassword(QString password)100 void FindSubtitlesConfigDialog::setPassword(QString password) {
101 	os_password_edit->setText(password);
102 }
103 
password()104 QString FindSubtitlesConfigDialog::password() {
105 	return os_password_edit->text();
106 }
107 
108 #ifdef OS_SEARCH_WORKAROUND
setRetries(int n)109 void FindSubtitlesConfigDialog::setRetries(int n) {
110 	retries_spin->setValue(n);
111 }
112 
retries()113 int FindSubtitlesConfigDialog::retries() {
114 	return retries_spin->value();
115 }
116 #endif
117 
118 #ifdef DOWNLOAD_SUBS
setAppendLang(bool b)119 void FindSubtitlesConfigDialog::setAppendLang(bool b) {
120 	addlang_check->setChecked(b);
121 }
122 
appendLang()123 bool FindSubtitlesConfigDialog::appendLang() {
124 	return addlang_check->isChecked();
125 }
126 #endif
127 
128 #ifdef FS_USE_PROXY
setUseProxy(bool b)129 void FindSubtitlesConfigDialog::setUseProxy(bool b) {
130 	use_proxy_check->setChecked(b);
131 }
132 
useProxy()133 bool FindSubtitlesConfigDialog::useProxy() {
134 	return 	use_proxy_check->isChecked();
135 }
136 
setProxyHostname(QString host)137 void FindSubtitlesConfigDialog::setProxyHostname(QString host) {
138 	proxy_hostname_edit->setText(host);
139 }
140 
proxyHostname()141 QString FindSubtitlesConfigDialog::proxyHostname() {
142 	return proxy_hostname_edit->text();
143 }
144 
setProxyPort(int port)145 void FindSubtitlesConfigDialog::setProxyPort(int port) {
146 	proxy_port_spin->setValue(port);
147 }
148 
proxyPort()149 int FindSubtitlesConfigDialog::proxyPort() {
150 	return proxy_port_spin->value();
151 }
152 
setProxyUsername(QString username)153 void FindSubtitlesConfigDialog::setProxyUsername(QString username) {
154 	proxy_username_edit->setText(username);
155 }
156 
proxyUsername()157 QString FindSubtitlesConfigDialog::proxyUsername() {
158 	return proxy_username_edit->text();
159 }
160 
setProxyPassword(QString password)161 void FindSubtitlesConfigDialog::setProxyPassword(QString password) {
162 	proxy_password_edit->setText(password);
163 }
164 
proxyPassword()165 QString FindSubtitlesConfigDialog::proxyPassword() {
166 	return proxy_password_edit->text();
167 }
168 
setProxyType(int type)169 void FindSubtitlesConfigDialog::setProxyType(int type) {
170 	int index = proxy_type_combo->findData(type);
171 	if (index == -1) index = 0;
172 	proxy_type_combo->setCurrentIndex(index);
173 }
174 
proxyType()175 int FindSubtitlesConfigDialog::proxyType() {
176 	int index = proxy_type_combo->currentIndex();
177 	return proxy_type_combo->itemData(index).toInt();
178 }
179 #endif
180 
181 #include "moc_findsubtitlesconfigdialog.cpp"
182