source: smplayer/trunk/src/findsubtitles/findsubtitleswindow.cpp@ 124

Last change on this file since 124 was 124, checked in by Silvan Scherrer, 13 years ago

SMPlayer: 0.7.1 trunk update

  • Property svn:eol-style set to LF
File size: 21.4 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2012 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 "findsubtitleswindow.h"
20#include "findsubtitlesconfigdialog.h"
21#include "simplehttp.h"
22#include "osparser.h"
23#include "languages.h"
24#include <QStandardItemModel>
25#include <QSortFilterProxyModel>
26#include <QHeaderView>
27#include <QMessageBox>
28#include <QDesktopServices>
29#include <QUrl>
30#include <QMap>
31#include <QMenu>
32#include <QAction>
33#include <QClipboard>
34#include <QSettings>
35
36#ifdef DOWNLOAD_SUBS
37#include "filedownloader.h"
38#include "subchooserdialog.h"
39#include "quazip.h"
40#include "quazipfile.h"
41#include <QTemporaryFile>
42#include <QBuffer>
43#endif
44
45//#define NO_SMPLAYER_SUPPORT
46
47#ifndef NO_SMPLAYER_SUPPORT
48#include "images.h"
49#endif
50
51#define COL_LANG 0
52#define COL_NAME 1
53#define COL_FORMAT 2
54#define COL_FILES 3
55#define COL_DATE 4
56#define COL_USER 5
57
58FindSubtitlesWindow::FindSubtitlesWindow( QWidget * parent, Qt::WindowFlags f )
59 : QDialog(parent,f)
60{
61 setupUi(this);
62
63 set = 0; // settings
64
65 subtitles_for_label->setBuddy(file_chooser);
66
67 progress->hide();
68
69 connect( file_chooser, SIGNAL(fileChanged(QString)),
70 this, SLOT(setMovie(QString)) );
71 connect( file_chooser, SIGNAL(textChanged(const QString &)),
72 this, SLOT(updateRefreshButton()) );
73
74 connect( refresh_button, SIGNAL(clicked()),
75 this, SLOT(refresh()) );
76
77 connect( download_button, SIGNAL(clicked()),
78 this, SLOT(download()) );
79
80 /*
81 connect( language_filter, SIGNAL(editTextChanged(const QString &)),
82 this, SLOT(applyFilter(const QString &)) );
83 */
84 connect( language_filter, SIGNAL(activated(int)),
85 this, SLOT(applyCurrentFilter()) );
86
87 table = new QStandardItemModel(this);
88 table->setColumnCount(COL_USER + 1);
89
90 proxy_model = new QSortFilterProxyModel(this);
91 proxy_model->setSourceModel(table);
92 proxy_model->setFilterKeyColumn(COL_LANG);
93 proxy_model->setFilterRole(Qt::UserRole);
94
95 view->setModel(proxy_model);
96 view->setRootIsDecorated(false);
97 view->setSortingEnabled(true);
98 view->setAlternatingRowColors(true);
99 view->header()->setSortIndicator(COL_LANG, Qt::AscendingOrder);
100 view->setEditTriggers(QAbstractItemView::NoEditTriggers);
101 view->setContextMenuPolicy( Qt::CustomContextMenu );
102
103 connect(view, SIGNAL(activated(const QModelIndex &)),
104 this, SLOT(itemActivated(const QModelIndex &)) );
105 connect(view->selectionModel(), SIGNAL(currentChanged(const QModelIndex &,const QModelIndex &)),
106 this, SLOT(currentItemChanged(const QModelIndex &,const QModelIndex &)) );
107
108 connect(view, SIGNAL(customContextMenuRequested(const QPoint &)),
109 this, SLOT(showContextMenu(const QPoint &)) );
110
111 downloader = new SimpleHttp(this);
112
113 connect( downloader, SIGNAL(downloadFailed(QString)),
114 this, SLOT(showError(QString)) );
115 connect( downloader, SIGNAL(downloadFinished(QByteArray)),
116 this, SLOT(downloadFinished()) );
117 connect( downloader, SIGNAL(downloadFinished(QByteArray)),
118 this, SLOT(parseInfo(QByteArray)) );
119 connect( downloader, SIGNAL(stateChanged(int)),
120 this, SLOT(updateRefreshButton()) );
121
122 connect( downloader, SIGNAL(connecting(QString)),
123 this, SLOT(connecting(QString)) );
124 connect( downloader, SIGNAL(dataReadProgress(int, int)),
125 this, SLOT(updateDataReadProgress(int, int)) );
126
127#ifdef DOWNLOAD_SUBS
128 include_lang_on_filename = true;
129
130 file_downloader = new FileDownloader(this);
131 file_downloader->setModal(false);
132 connect( file_downloader, SIGNAL(downloadFailed(QString)),
133 this, SLOT(showError(QString)), Qt::QueuedConnection );
134 connect( file_downloader, SIGNAL(downloadFinished(const QByteArray &)),
135 this, SLOT(archiveDownloaded(const QByteArray &)), Qt::QueuedConnection );
136#endif
137
138 // Actions
139 downloadAct = new QAction(this);
140 downloadAct->setEnabled(false);
141 connect( downloadAct, SIGNAL(triggered()), this, SLOT(download()) );
142
143 copyLinkAct = new QAction(this);
144 copyLinkAct->setEnabled(false);
145 connect( copyLinkAct, SIGNAL(triggered()), this, SLOT(copyLink()) );
146
147 context_menu = new QMenu(this);
148 context_menu->addAction(downloadAct);
149 context_menu->addAction(copyLinkAct);
150
151 retranslateStrings();
152
153 language_filter->setCurrentIndex(0);
154
155 // Opensubtitles server
156 os_server = "http://www.opensubtitles.org";
157
158 // Proxy
159 use_proxy = false;
160 proxy_type = QNetworkProxy::HttpProxy;
161 proxy_host = "";
162 proxy_port = 0;
163 proxy_username = "";
164 proxy_password = "";
165
166 setupProxy();
167}
168
169FindSubtitlesWindow::~FindSubtitlesWindow() {
170 if (set) saveSettings();
171}
172
173void FindSubtitlesWindow::setSettings(QSettings * settings) {
174 set = settings;
175 loadSettings();
176 setupProxy();
177}
178
179void FindSubtitlesWindow::setProxy(QNetworkProxy proxy) {
180 downloader->abort();
181 downloader->setProxy(proxy);
182
183#ifdef DOWNLOAD_SUBS
184 file_downloader->setProxy(proxy);
185#endif
186
187 qDebug("FindSubtitlesWindow::setProxy: host: '%s' port: %d type: %d",
188 proxy.hostName().toUtf8().constData(), proxy.port(), proxy.type());
189}
190
191void FindSubtitlesWindow::retranslateStrings() {
192 retranslateUi(this);
193
194 QStringList labels;
195 labels << tr("Language") << tr("Name") << tr("Format")
196 << tr("Files") << tr("Date") << tr("Uploaded by");
197
198 table->setHorizontalHeaderLabels( labels );
199
200 // Language combobox
201 //int language_index = language_filter->currentIndex();
202 QString current_language = language_filter->itemData(language_filter->currentIndex()).toString();
203 language_filter->clear();
204
205 QMap<QString,QString> l = Languages::list();
206 QMapIterator<QString, QString> i(l);
207 while (i.hasNext()) {
208 i.next();
209 language_filter->addItem( i.value() + " (" + i.key() + ")", i.key() );
210 }
211 language_filter->model()->sort(0);
212 language_filter->insertItem( 0, tr("All"), "*" );
213 //language_filter->setCurrentIndex(language_index);
214 language_filter->setCurrentIndex(language_filter->findData(current_language));
215
216#if QT_VERSION < 0x040300
217 QPushButton * close_button = buttonBox->button(QDialogButtonBox::Close);
218 close_button->setText( tr("Close") );
219#endif
220
221 // Actions
222 downloadAct->setText( tr("&Download") );
223 copyLinkAct->setText( tr("&Copy link to clipboard") );
224
225 // Icons
226#ifndef NO_SMPLAYER_SUPPORT
227 download_button->setIcon( Images::icon("download") );
228 configure_button->setIcon( Images::icon("prefs") );
229 refresh_button->setIcon( Images::icon("refresh") );
230
231 downloadAct->setIcon( Images::icon("download") );
232 copyLinkAct->setIcon( Images::icon("copy") );
233#endif
234}
235
236void FindSubtitlesWindow::setMovie(QString filename) {
237 qDebug("FindSubtitlesWindow::setMovie: '%s'", filename.toLatin1().constData());
238
239 if (filename == last_file) {
240 return;
241 }
242
243 file_chooser->setText(filename);
244 table->setRowCount(0);
245
246 QString hash = OSParser::calculateHash(filename);
247 if (hash.isEmpty()) {
248 qWarning("FindSubtitlesWindow::setMovie: hash invalid. Doing nothing.");
249 } else {
250 QString link = os_server + "/search/sublanguageid-all/moviehash-" + hash + "/simplexml";
251 qDebug("FindSubtitlesWindow::setMovie: link: '%s'", link.toLatin1().constData());
252 downloader->download(link);
253 last_file = filename;
254 }
255}
256
257void FindSubtitlesWindow::refresh() {
258 last_file = "";
259 setMovie(file_chooser->text());
260}
261
262void FindSubtitlesWindow::updateRefreshButton() {
263 qDebug("FindSubtitlesWindow::updateRefreshButton: state: %d", downloader->state());
264/*
265 QString file = file_chooser->lineEdit()->text();
266 bool enabled = ( (!file.isEmpty()) && (QFile::exists(file)) &&
267 (downloader->state()==QHttp::Unconnected) );
268 refresh_button->setEnabled(enabled);
269*/
270 refresh_button->setEnabled(true);
271}
272
273void FindSubtitlesWindow::currentItemChanged(const QModelIndex & current, const QModelIndex & /*previous*/) {
274 qDebug("FindSubtitlesWindow::currentItemChanged: row: %d, col: %d", current.row(), current.column());
275 download_button->setEnabled(current.isValid());
276 downloadAct->setEnabled(current.isValid());
277 copyLinkAct->setEnabled(current.isValid());
278}
279
280void FindSubtitlesWindow::applyFilter(const QString & filter) {
281 proxy_model->setFilterWildcard(filter);
282}
283
284void FindSubtitlesWindow::applyCurrentFilter() {
285 //proxy_model->setFilterWildcard(language_filter->currentText());
286 QString filter = language_filter->itemData( language_filter->currentIndex() ).toString();
287 applyFilter(filter);
288}
289
290void FindSubtitlesWindow::setLanguage(const QString & lang) {
291 int idx = language_filter->findData(lang);
292 if (idx < 0) idx = 0;
293 language_filter->setCurrentIndex(idx);
294}
295
296QString FindSubtitlesWindow::language() {
297 int idx = language_filter->currentIndex();
298 return language_filter->itemData(idx).toString();
299}
300
301void FindSubtitlesWindow::showError(QString error) {
302 status->setText( tr("Download failed") );
303
304 QMessageBox::information(this, tr("Error"),
305 tr("Download failed: %1.")
306 .arg(error));
307}
308
309void FindSubtitlesWindow::connecting(QString host) {
310 status->setText( tr("Connecting to %1...").arg(host) );
311}
312
313void FindSubtitlesWindow::updateDataReadProgress(int done, int total) {
314 qDebug("FindSubtitlesWindow::updateDataReadProgress: %d, %d", done, total);
315
316 status->setText( tr("Downloading...") );
317
318 if (!progress->isVisible()) progress->show();
319 progress->setMaximum(total);
320 progress->setValue(done);
321}
322
323void FindSubtitlesWindow::downloadFinished() {
324 status->setText( tr("Done.") );
325 progress->setMaximum(1);
326 progress->setValue(0);
327 progress->hide();
328}
329
330void FindSubtitlesWindow::parseInfo(QByteArray xml_text) {
331 OSParser osparser;
332 bool ok = osparser.parseXml(xml_text);
333
334 table->setRowCount(0);
335
336 QMap <QString,QString> language_list = Languages::list();
337
338 if (ok) {
339 QList<OSSubtitle> l = osparser.subtitleList();
340 for (int n=0; n < l.count(); n++) {
341
342 QString title_name = l[n].movie;
343 if (!l[n].releasename.isEmpty()) {
344 title_name += " - " + l[n].releasename;
345 }
346
347 QStandardItem * i_name = new QStandardItem(title_name);
348 i_name->setData( l[n].link );
349 #if QT_VERSION < 0x040400
350 i_name->setToolTip( l[n].link );
351 #endif
352
353 QStandardItem * i_lang = new QStandardItem(l[n].language);
354 i_lang->setData(l[n].iso639, Qt::UserRole);
355 #if QT_VERSION < 0x040400
356 i_lang->setToolTip(l[n].iso639);
357 #endif
358 if (language_list.contains(l[n].iso639)) {
359 i_lang->setText( language_list[ l[n].iso639 ] );
360 }
361
362 table->setItem(n, COL_LANG, i_lang);
363 table->setItem(n, COL_NAME, i_name);
364 table->setItem(n, COL_FORMAT, new QStandardItem(l[n].format));
365 table->setItem(n, COL_FILES, new QStandardItem(l[n].files));
366 table->setItem(n, COL_DATE, new QStandardItem(l[n].date));
367 table->setItem(n, COL_USER, new QStandardItem(l[n].user));
368
369 }
370 status->setText( tr("%1 files available").arg(l.count()) );
371 applyCurrentFilter();
372
373 qDebug("sort column: %d", view->header()->sortIndicatorSection());
374 qDebug("sort indicator: %d", view->header()->sortIndicatorOrder());
375
376 table->sort( view->header()->sortIndicatorSection(),
377 view->header()->sortIndicatorOrder() );
378 } else {
379 status->setText( tr("Failed to parse the received data.") );
380 }
381
382 view->resizeColumnToContents(COL_NAME);
383}
384
385void FindSubtitlesWindow::itemActivated(const QModelIndex & index ) {
386 qDebug("FindSubtitlesWindow::itemActivated: row: %d, col %d", proxy_model->mapToSource(index).row(), proxy_model->mapToSource(index).column());
387
388 QString download_link = table->item(proxy_model->mapToSource(index).row(), COL_NAME)->data().toString();
389
390 qDebug("FindSubtitlesWindow::itemActivated: download link: '%s'", download_link.toLatin1().constData());
391
392#ifdef DOWNLOAD_SUBS
393 file_downloader->download( QUrl(download_link) );
394 file_downloader->show();
395#else
396 QDesktopServices::openUrl( QUrl(download_link) );
397#endif
398}
399
400void FindSubtitlesWindow::download() {
401 qDebug("FindSubtitlesWindow::download");
402 if (view->currentIndex().isValid()) {
403 itemActivated(view->currentIndex());
404 }
405}
406
407void FindSubtitlesWindow::copyLink() {
408 qDebug("FindSubtitlesWindow::copyLink");
409 if (view->currentIndex().isValid()) {
410 const QModelIndex & index = view->currentIndex();
411 QString download_link = table->item(proxy_model->mapToSource(index).row(), COL_NAME)->data().toString();
412 qDebug("FindSubtitlesWindow::copyLink: link: '%s'", download_link.toLatin1().constData());
413 qApp->clipboard()->setText(download_link);
414 }
415}
416
417void FindSubtitlesWindow::showContextMenu(const QPoint & pos) {
418 qDebug("FindSubtitlesWindow::showContextMenu");
419
420 context_menu->move( view->viewport()->mapToGlobal(pos) );
421 context_menu->show();
422}
423
424// Language change stuff
425void FindSubtitlesWindow::changeEvent(QEvent *e) {
426 if (e->type() == QEvent::LanguageChange) {
427 retranslateStrings();
428 } else {
429 QWidget::changeEvent(e);
430 }
431}
432
433#ifdef DOWNLOAD_SUBS
434void FindSubtitlesWindow::archiveDownloaded(const QByteArray & buffer) {
435 qDebug("FindSubtitlesWindow::archiveDownloaded");
436
437 QString temp_dir = QDir::tempPath();
438 if (!temp_dir.endsWith("/")) temp_dir += "/";
439
440 QTemporaryFile file(temp_dir + "archive_XXXXXX.zip");
441 file.setAutoRemove(false);
442
443 qDebug("FindSubtitlesWindow::archiveDownloaded: a temporary file will be saved in folder '%s'", temp_dir.toUtf8().constData());
444
445 if (file.open()) {
446 QString filename = file.fileName();
447 file.write( buffer );
448 file.close();
449
450 qDebug("FindSubtitlesWindow::archiveDownloaded: file saved as: %s", filename.toUtf8().constData());
451
452 /*
453 QMessageBox::information(this, tr("Downloaded"), tr("File saved as %1").arg(filename));
454 return;
455 */
456
457 status->setText(tr("Temporary file %1").arg(filename));
458
459 QString lang = "unknown";
460 QString extension = "unknown";
461 if (view->currentIndex().isValid()) {
462 const QModelIndex & index = view->currentIndex();
463 lang = table->item(proxy_model->mapToSource(index).row(), COL_LANG)->data(Qt::UserRole).toString();
464 extension = table->item(proxy_model->mapToSource(index).row(), COL_FORMAT)->text();
465 }
466
467 QFileInfo fi(file_chooser->text());
468 QString output_name = fi.completeBaseName();
469 if (include_lang_on_filename) output_name += "_"+ lang;
470 output_name += "." + extension;
471
472 if (!uncompressZip(filename, fi.absolutePath(), output_name)) {
473 status->setText(tr("Download failed"));
474 }
475 file.remove();
476 }
477 else {
478 qWarning("FindSubtitlesWindow::archiveDownloaded: can't write temporary file");
479 QMessageBox::warning(this, tr("Error saving file"),
480 tr("It wasn't possible to save the downloaded\n"
481 "file in folder %1\n"
482 "Please check the permissions of that folder.").arg(temp_dir));
483 }
484}
485
486
487bool FindSubtitlesWindow::uncompressZip(const QString & filename, const QString & output_path, const QString & preferred_output_name) {
488 qDebug("FindSubtitlesWindow::uncompressZip: zip file '%s', output_path '%s', save subtitle as '%s'",
489 filename.toUtf8().constData(), output_path.toUtf8().constData(),
490 preferred_output_name.toUtf8().constData());
491
492 QuaZip zip(filename);
493
494 if (!zip.open(QuaZip::mdUnzip)) {
495 qWarning("FindSubtitlesWindow::uncompressZip: open zip failed: %d", zip.getZipError());
496 return false;
497 }
498
499 zip.setFileNameCodec("IBM866");
500 qDebug("FindSubtitlesWindow::uncompressZip: %d entries", zip.getEntriesCount());
501 qDebug("FindSubtitlesWindow::uncompressZip: global comment: '%s'", zip.getComment().toUtf8().constData());
502
503 QStringList sub_files;
504 QuaZipFileInfo info;
505
506 for (bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) {
507 if (!zip.getCurrentFileInfo(&info)) {
508 qWarning("FindSubtitlesWindow::uncompressZip: getCurrentFileInfo(): %d\n", zip.getZipError());
509 return false;
510 }
511 qDebug("FindSubtitlesWindow::uncompressZip: file '%s'", info.name.toUtf8().constData());
512 if (QFileInfo(info.name).suffix() != "nfo") sub_files.append(info.name);
513 }
514
515 qDebug("FindSubtitlesWindow::uncompressZip: list of subtitle files:");
516 for (int n=0; n < sub_files.count(); n++) {
517 qDebug("FindSubtitlesWindow::uncompressZip: subtitle file %d '%s'", n, sub_files[n].toUtf8().constData());
518 }
519
520 if (sub_files.count() == 1) {
521 // If only one file, just extract it
522 QString output_name = output_path +"/"+ preferred_output_name;
523 if (extractFile(zip, sub_files[0], output_name )) {
524 status->setText(tr("Subtitle saved as %1").arg(preferred_output_name));
525 emit subtitleDownloaded(output_name);
526 } else {
527 return false;
528 }
529 } else {
530 // More than one file
531 SubChooserDialog d(this);
532
533 for (int n=0; n < sub_files.count(); n++) {
534 d.addFile(sub_files[n]);
535 }
536
537 if (d.exec() == QDialog::Rejected) return false;
538
539 QStringList files_to_extract = d.selectedFiles();
540 int extracted_count = 0;
541 for (int n=0; n < files_to_extract.count(); n++) {
542 QString file = files_to_extract[n];
543 bool ok = extractFile(zip, file, output_path +"/"+ file);
544 qDebug("FindSubtitlesWindow::uncompressZip: extracted %s ok: %d", file.toUtf8().constData(), ok);
545 if (ok) extracted_count++;
546 }
547 status->setText(tr("%1 subtitle(s) extracted","", extracted_count).arg(extracted_count));
548 if (extracted_count > 0) {
549 emit subtitleDownloaded( output_path +"/"+ files_to_extract[0] );
550 }
551 }
552
553 zip.close();
554 return true;
555}
556
557bool FindSubtitlesWindow::extractFile(QuaZip & zip, const QString & filename, const QString & output_name) {
558 qDebug("FindSubtitlesWindow::extractFile: '%s', save as '%s'", filename.toUtf8().constData(), output_name.toUtf8().constData());
559
560 if (QFile::exists(output_name)) {
561 if (QMessageBox::question(this, tr("Overwrite?"),
562 tr("The file %1 already exits, overwrite?").arg(output_name), QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
563 {
564 return false;
565 }
566 }
567
568 if (!zip.setCurrentFile(filename)) {
569 qDebug("FindSubtitlesWindow::extractFile: can't select file %s", filename.toUtf8().constData());
570 return false;
571 }
572
573 // Saving
574 char c;
575 QuaZipFile file(&zip);
576 QFile out(output_name);
577
578 if (!file.open(QIODevice::ReadOnly)) {
579 qWarning("FindSubtitlesWindow::extractFile: can't open file for reading: %d", file.getZipError());
580 return false;
581 }
582
583 if (out.open(QIODevice::WriteOnly)) {
584 // Slow like hell (on GNU/Linux at least), but it is not my fault.
585 // Not ZIP/UNZIP package's fault either.
586 // The slowest thing here is out.putChar(c).
587 while(file.getChar(&c)) out.putChar(c);
588 out.close();
589
590 file.close();
591 } else {
592 qWarning("FindSubtitlesWindow::extractFile: can't open %s for writing", output_name.toUtf8().constData());
593 return false;
594 }
595
596 return true;
597}
598
599#endif
600
601void FindSubtitlesWindow::on_configure_button_clicked() {
602 qDebug("FindSubtitlesWindow::on_configure_button_clicked");
603
604 FindSubtitlesConfigDialog d(this);
605
606 d.setServer( os_server );
607 d.setUseProxy( use_proxy );
608 d.setProxyHostname( proxy_host );
609 d.setProxyPort( proxy_port );
610 d.setProxyUsername( proxy_username );
611 d.setProxyPassword( proxy_password );
612 d.setProxyType( proxy_type );
613
614 if (d.exec() == QDialog::Accepted) {
615 os_server = d.server();
616 use_proxy = d.useProxy();
617 proxy_host = d.proxyHostname();
618 proxy_port = d.proxyPort();
619 proxy_username = d.proxyUsername();
620 proxy_password = d.proxyPassword();
621 proxy_type = d.proxyType();
622
623 setupProxy();
624 }
625}
626
627void FindSubtitlesWindow::setupProxy() {
628 QNetworkProxy proxy;
629
630 if ( (use_proxy) && (!proxy_host.isEmpty()) ) {
631 proxy.setType((QNetworkProxy::ProxyType) proxy_type);
632 proxy.setHostName(proxy_host);
633 proxy.setPort(proxy_port);
634 if ( (!proxy_username.isEmpty()) && (!proxy_password.isEmpty()) ) {
635 proxy.setUser(proxy_username);
636 proxy.setPassword(proxy_password);
637 }
638 qDebug("FindSubtitlesWindow::userProxy: using proxy: host: %s, port: %d, type: %d",
639 proxy_host.toUtf8().constData(), proxy_port, proxy_type);
640 } else {
641 // No proxy
642 proxy.setType(QNetworkProxy::NoProxy);
643 qDebug("FindSubtitlesDialog::userProxy: no proxy");
644 }
645
646 setProxy(proxy);
647}
648
649void FindSubtitlesWindow::saveSettings() {
650 qDebug("FindSubtitlesWindow::saveSettings");
651
652 set->beginGroup("findsubtitles");
653
654 set->setValue("server", os_server);
655 set->setValue("language", language());
656#ifdef DOWNLOAD_SUBS
657 set->setValue("include_lang_on_filename", includeLangOnFilename());
658#endif
659 set->setValue("proxy/use_proxy", use_proxy);
660 set->setValue("proxy/type", proxy_type);
661 set->setValue("proxy/host", proxy_host);
662 set->setValue("proxy/port", proxy_port);
663 set->setValue("proxy/username", proxy_username);
664 set->setValue("proxy/password", proxy_password);
665
666 set->endGroup();
667}
668
669void FindSubtitlesWindow::loadSettings() {
670 qDebug("FindSubtitlesWindow::loadSettings");
671
672 set->beginGroup("findsubtitles");
673
674 os_server = set->value("server", os_server).toString();
675 setLanguage( set->value("language", language()).toString() );
676#ifdef DOWNLOAD_SUBS
677 setIncludeLangOnFilename( set->value("include_lang_on_filename", includeLangOnFilename()).toBool() );
678#endif
679 use_proxy = set->value("proxy/use_proxy", use_proxy).toBool();
680 proxy_type = set->value("proxy/type", proxy_type).toInt();
681 proxy_host = set->value("proxy/host", proxy_host).toString();
682 proxy_port = set->value("proxy/port", proxy_port).toInt();
683 proxy_username = set->value("proxy/username", proxy_username).toString();
684 proxy_password = set->value("proxy/password", proxy_password).toString();
685
686 set->endGroup();
687}
688
689#include "moc_findsubtitleswindow.cpp"
690
Note: See TracBrowser for help on using the repository browser.