1 /*****************************************************************************
2 ** QNapi
3 ** Copyright (C) 2008-2017 Piotr Krzemiński <pio.krzeminski@gmail.com>
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12 **
13 *****************************************************************************/
14
15 #include <QDesktopServices>
16 #include <QDesktopWidget>
17
18 #include "engines/opensubtitlesdownloadengine.h"
19 #include "frmopensubtitlesconfig.h"
20
frmOpenSubtitlesConfig(const EngineConfig & config,QWidget * parent,Qt::WindowFlags f)21 frmOpenSubtitlesConfig::frmOpenSubtitlesConfig(const EngineConfig &config,
22 QWidget *parent,
23 Qt::WindowFlags f)
24 : QDialog(parent, f), config(config) {
25 ui.setupUi(this);
26
27 ui.leNick->setText(config.nick());
28 ui.lePass->setText(config.password());
29
30 QIcon openSubtitlesIcon =
31 QIcon(QPixmap(OpenSubtitlesDownloadEngine::pixmapData));
32 setWindowIcon(openSubtitlesIcon);
33
34 connect(ui.pbRegister, SIGNAL(clicked()), this, SLOT(pbRegisterClicked()));
35
36 QRect position = frameGeometry();
37 position.moveCenter(QDesktopWidget().availableGeometry().center());
38 move(position.topLeft());
39 }
40
getConfig() const41 EngineConfig frmOpenSubtitlesConfig::getConfig() const { return config; }
42
accept()43 void frmOpenSubtitlesConfig::accept() {
44 config = config.setNick(ui.leNick->text()).setPassword(ui.lePass->text());
45 QDialog::accept();
46 }
47
pbRegisterClicked()48 void frmOpenSubtitlesConfig::pbRegisterClicked() {
49 Maybe<QUrl> maybeRegistrationUrl =
50 OpenSubtitlesDownloadEngine::metadata.registrationUrl();
51
52 if (maybeRegistrationUrl) {
53 QDesktopServices::openUrl(maybeRegistrationUrl.value());
54 }
55 }
56