diff --git a/qnapi.pro b/qnapi.pro index 1f042aa..659f456 100644 --- a/qnapi.pro +++ b/qnapi.pro @@ -27,6 +27,7 @@ SOURCES += src/main.cpp \ src/forms/frmabout.cpp \ src/forms/frmnapiprojektconfig.cpp \ src/forms/frmopensubtitlesconfig.cpp \ + src/forms/frmnapisy24config.cpp \ src/qcumber/qmanagedrequest.cpp \ src/qcumber/qmanagedsocket.cpp \ src/qcumber/qsingleapplication.cpp \ @@ -53,7 +54,6 @@ SOURCES += src/main.cpp \ src/forms/subdatawidget.cpp \ src/qnapisubtitleinfo.cpp - HEADERS += src/engines/qnapiabstractengine.h \ src/engines/qnapiprojektengine.h \ src/engines/qnapisy24engine.h \ @@ -66,6 +66,7 @@ HEADERS += src/engines/qnapiabstractengine.h \ src/forms/frmabout.h \ src/forms/frmnapiprojektconfig.h \ src/forms/frmopensubtitlesconfig.h \ + src/forms/frmnapisy24config.h \ src/qcumber/qmanagedrequest.h \ src/qcumber/qmanagedsocket.h \ src/qcumber/qsingleapplication.h \ @@ -106,6 +107,7 @@ FORMS += ui/frmprogress.ui \ ui/frmabout.ui \ ui/napiprojekt/frmnapiprojektconfig.ui \ ui/opensubtitles/frmopensubtitlesconfig.ui \ + ui/napisy24/frmnapisy24config.ui \ ui/frmconvert.ui \ ui/subDataWidget.ui diff --git a/src/engines/qnapiabstractengine.h b/src/engines/qnapiabstractengine.h index 09e67cf..8fb9ff7 100644 --- a/src/engines/qnapiabstractengine.h +++ b/src/engines/qnapiabstractengine.h @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -58,6 +59,8 @@ class QNapiAbstractEngine virtual bool isConfigurable() = 0; // wywoluje okienko konfiguracji virtual void configure(QWidget * parent) = 0; + // rejestracja uzytkownika + virtual QUrl registrationUrl() const = 0; // czysci wewnetrzne listy znalezionych napisow w silniku virtual void clearSubtitlesList(); diff --git a/src/engines/qnapiprojektengine.h b/src/engines/qnapiprojektengine.h index de5c72d..f91fe2e 100644 --- a/src/engines/qnapiprojektengine.h +++ b/src/engines/qnapiprojektengine.h @@ -47,6 +47,9 @@ class QNapiProjektEngine : public QNapiAbstractEngine // wywoluje okienko konfiguracji void configure(QWidget * parent); + QUrl registrationUrl() const { + return QUrl("http://www.napiprojekt.pl/rejestracja"); + } QString checksum(QString filename = ""); bool lookForSubtitles(QString lang); diff --git a/src/engines/qnapisy24engine.cpp b/src/engines/qnapisy24engine.cpp index 3d5844b..65e8c64 100644 --- a/src/engines/qnapisy24engine.cpp +++ b/src/engines/qnapisy24engine.cpp @@ -14,6 +14,7 @@ *****************************************************************************/ #include "qnapisy24engine.h" +#include "forms/frmnapisy24config.h" #include #include #include @@ -323,12 +324,13 @@ QIcon QNapisy24Engine::engineIcon() bool QNapisy24Engine::isConfigurable() { - return false; + return true; } void QNapisy24Engine::configure(QWidget * parent) { - Q_UNUSED(parent); + frmNapisy24Config config(parent); + config.exec(); } QString QNapisy24Engine::checksum(QString filename) @@ -357,10 +359,12 @@ bool QNapisy24Engine::lookForSubtitles(QString lang) const QUrl url = QUrl("http://napisy24.pl/run/CheckSubAgent.php"); + auto credentials = getCredentials(); + QUrlQuery params(url); params.addQueryItem("postAction", "CheckSub"); - params.addQueryItem("ua", "tantalosus"); - params.addQueryItem("ap", "susolatnat"); + params.addQueryItem("ua", credentials.first); + params.addQueryItem("ap", credentials.second); params.addQueryItem("fh", checkSum); params.addQueryItem("fs", QString::number(fileSize)); params.addQueryItem("fn", QFileInfo(movie).fileName()); @@ -480,3 +484,15 @@ void QNapisy24Engine::cleanup() if(QFile::exists(subtitlesTmp)) QFile::remove(subtitlesTmp); } + +QPair QNapisy24Engine::getCredentials() const +{ + QString configLogin = GlobalConfig().nick("Napisy24"); + QString configPass = GlobalConfig().pass("Napisy24"); + + if(!configLogin.isEmpty() && !configPass.isEmpty()) { + return qMakePair(configLogin, configPass); + } else { + return qMakePair(QString("tantalosus"), QString("susolatnat")); + } +} diff --git a/src/engines/qnapisy24engine.h b/src/engines/qnapisy24engine.h index 2991c9c..5511d2c 100644 --- a/src/engines/qnapisy24engine.h +++ b/src/engines/qnapisy24engine.h @@ -30,6 +30,10 @@ class QNapisy24Engine : public QNapiAbstractEngine bool isConfigurable(); void configure(QWidget * parent); + QUrl registrationUrl() const { + return QUrl("http://napisy24.pl/cb-registration/registers"); + } + QString checksum(QString filename = ""); bool lookForSubtitles(QString lang); QList listSubtitles(); @@ -38,6 +42,8 @@ class QNapisy24Engine : public QNapiAbstractEngine void cleanup(); private: + QPair getCredentials() const; + quint64 fileSize; QString p7zipPath; }; diff --git a/src/engines/qopensubtitlesengine.h b/src/engines/qopensubtitlesengine.h index 55ab981..f5b50e6 100644 --- a/src/engines/qopensubtitlesengine.h +++ b/src/engines/qopensubtitlesengine.h @@ -38,6 +38,10 @@ class QOpenSubtitlesEngine : public QNapiAbstractEngine // wywoluje okienko konfiguracji void configure(QWidget * parent); + QUrl registrationUrl() const { + return QUrl("http://www.opensubtitles.org/newuser"); + } + // oblicza sume kontrolna pliku filmowego QString checksum(QString filename = ""); // szuka napisow diff --git a/src/forms/frmnapiprojektconfig.cpp b/src/forms/frmnapiprojektconfig.cpp index f29d14a..efe74e4 100644 --- a/src/forms/frmnapiprojektconfig.cpp +++ b/src/forms/frmnapiprojektconfig.cpp @@ -41,8 +41,7 @@ void frmNapiProjektConfig::accept() void frmNapiProjektConfig::pbRegisterClicked() { - ((QNapiApp*)qApp)->showNPCreateUser(); - load(); + ((QNapiApp*)qApp)->showCreateAccount("NapiProjekt"); } void frmNapiProjektConfig::load() diff --git a/src/forms/frmnapisy24config.cpp b/src/forms/frmnapisy24config.cpp new file mode 100644 index 0000000..f706a45 --- /dev/null +++ b/src/forms/frmnapisy24config.cpp @@ -0,0 +1,52 @@ + +/***************************************************************************** +** QNapi +** Copyright (C) 2008-2015 Piotr Krzemiński +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +*****************************************************************************/ + +#include "frmnapisy24config.h" +#include "../qnapi.h" + +frmNapisy24Config::frmNapisy24Config(QWidget *parent, Qt::WindowFlags f) + : QDialog(parent, f) +{ + ui.setupUi(this); + QNapi q; + q.addEngines(q.enumerateEngines()); + setWindowIcon(q.engineByName("Napisy24")->engineIcon()); + + load(); + + connect(ui.pbRegister, SIGNAL(clicked()), this, SLOT(pbRegisterClicked())); + + QRect position = frameGeometry(); + position.moveCenter(QDesktopWidget().availableGeometry().center()); + move(position.topLeft()); +} + +void frmNapisy24Config::accept() +{ + GlobalConfig().setNick("Napisy24", ui.leNick->text()); + GlobalConfig().setPass("Napisy24", ui.lePass->text()); + QDialog::accept(); +} + +void frmNapisy24Config::pbRegisterClicked() +{ + ((QNapiApp*)qApp)->showCreateAccount("Napisy24"); +} + +void frmNapisy24Config::load() +{ + ui.leNick->setText(GlobalConfig().nick("Napisy24")); + ui.lePass->setText(GlobalConfig().pass("Napisy24")); +} diff --git a/src/forms/frmnapisy24config.h b/src/forms/frmnapisy24config.h new file mode 100644 index 0000000..7ba42be --- /dev/null +++ b/src/forms/frmnapisy24config.h @@ -0,0 +1,47 @@ +/***************************************************************************** +** QNapi +** Copyright (C) 2008-2015 Piotr Krzemiński +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +*****************************************************************************/ + +#ifndef __FRMNAPISY24CONFIG__H__ +#define __FRMNAPISY24CONFIG__H__ + +#include +#include "ui_frmnapisy24config.h" + +#include "qnapiconfig.h" +#include "qnapiapp.h" + +class frmNapisy24Config : public QDialog +{ +Q_OBJECT + + public: + + frmNapisy24Config(QWidget *parent = 0, Qt::WindowFlags f = 0); + ~frmNapisy24Config() {} + + public slots: + + void accept(); + void pbRegisterClicked(); + + private: + Ui::frmNapisy24Config ui; + + void load(); + +}; + + + +#endif diff --git a/src/forms/frmopensubtitlesconfig.cpp b/src/forms/frmopensubtitlesconfig.cpp index 5292275..114b001 100644 --- a/src/forms/frmopensubtitlesconfig.cpp +++ b/src/forms/frmopensubtitlesconfig.cpp @@ -44,7 +44,7 @@ void frmOpenSubtitlesConfig::accept() void frmOpenSubtitlesConfig::pbRegisterClicked() { - ((QNapiApp*)qApp)->showOSCreateUser(); + ((QNapiApp*)qApp)->showCreateAccount("OpenSubtitles"); } void frmOpenSubtitlesConfig::load() diff --git a/src/qnapiapp.cpp b/src/qnapiapp.cpp index 7bf3b63..e934a46 100644 --- a/src/qnapiapp.cpp +++ b/src/qnapiapp.cpp @@ -96,25 +96,25 @@ void QNapiApp::createTrayIcon() connect(convertAction, SIGNAL(triggered()), this, SLOT(showConvertDialog())); napiGetAction = new QAction(tr("Pobierz napisy"), 0); - connect(napiGetAction, SIGNAL(triggered()), this, SLOT(showNPGetDialog())); + connect(napiGetAction, &QAction::triggered, [this] { showOpenDialog("NapiProjekt"); }); napiCreateUserAction = new QAction(tr("Załóż konto"), 0); - connect(napiCreateUserAction, SIGNAL(triggered()), this, SLOT(showNPCreateUser())); + connect(napiCreateUserAction, &QAction::triggered, [this] { showCreateAccount("NapiProjekt"); }); osGetAction = new QAction(tr("Pobierz napisy"), 0); - connect(osGetAction, SIGNAL(triggered()), this, SLOT(showOSGetDialog())); + connect(osGetAction, &QAction::triggered, [this] { showOpenDialog("OpenSubtitles"); }); osAddAction = new QAction(tr("Dodaj napisy"), 0); connect(osAddAction, SIGNAL(triggered()), this, SLOT(showOSUploadDialog())); osCreateUserAction = new QAction(tr("Załóż konto"), 0); - connect(osCreateUserAction, SIGNAL(triggered()), this, SLOT(showOSCreateUser())); + connect(osCreateUserAction, &QAction::triggered, [this] { showCreateAccount("OpenSubtitles"); }); napisy24GetAction = new QAction(tr("Pobierz napisy"), 0); - connect(napisy24GetAction, SIGNAL(triggered()), this, SLOT(showNapisy24GetDialog())); + connect(napisy24GetAction, &QAction::triggered, [this] { showOpenDialog("Napisy24"); }); napisy24CreateUserAction = new QAction(tr("Załóż konto"), 0); - connect(napisy24CreateUserAction, SIGNAL(triggered()), this, SLOT(showNapisy24CreateUser())); + connect(napisy24CreateUserAction, &QAction::triggered, [this] { showCreateAccount("OpenSNapisy24ubtitles"); }); settingsAction = new QAction(tr("Opcje"), 0); connect(settingsAction, SIGNAL(triggered()), this, SLOT(showSettings())); @@ -270,19 +270,11 @@ void QNapiApp::showConvertDialog() f_scan = 0; } -void QNapiApp::showNPGetDialog() +void QNapiApp::showCreateAccount(QString engine) { - showOpenDialog("NapiProjekt"); -} - -void QNapiApp::showNPCreateUser() -{ - QDesktopServices::openUrl(QUrl("http://www.napiprojekt.pl/rejestracja")); -} - -void QNapiApp::showOSGetDialog() -{ - showOpenDialog("OpenSubtitles"); + QNapi n; + n.addEngine(engine); + QDesktopServices::openUrl(n.engineByName(engine)->registrationUrl()); } void QNapiApp::showOSUploadDialog() @@ -290,21 +282,6 @@ void QNapiApp::showOSUploadDialog() QDesktopServices::openUrl(QUrl("http://www.opensubtitles.org/upload")); } -void QNapiApp::showOSCreateUser() -{ - QDesktopServices::openUrl(QUrl("http://www.opensubtitles.org/newuser")); -} - -void QNapiApp::showNapisy24GetDialog() -{ - showOpenDialog("Napisy24"); -} - -void QNapiApp::showNapisy24CreateUser() -{ - QDesktopServices::openUrl(QUrl("http://napisy24.pl/cb-registration/registers")); -} - void QNapiApp::showSettings() { if(!f_options) diff --git a/src/qnapiapp.h b/src/qnapiapp.h index 191b805..19365b7 100644 --- a/src/qnapiapp.h +++ b/src/qnapiapp.h @@ -55,17 +55,8 @@ class QNapiApp : public QSingleApplication bool showOpenDialog(QString engine = ""); bool showScanDialog(QString init_dir = ""); void showConvertDialog(); - - void showNPGetDialog(); - void showNPCreateUser(); - - void showOSGetDialog(); + void showCreateAccount(QString engine); void showOSUploadDialog(); - void showOSCreateUser(); - - void showNapisy24GetDialog(); - void showNapisy24CreateUser(); - void showSettings(); void showAbout(); void tryQuit(); diff --git a/ui/napisy24/frmnapisy24config.ui b/ui/napisy24/frmnapisy24config.ui new file mode 100644 index 0000000..dac993d --- /dev/null +++ b/ui/napisy24/frmnapisy24config.ui @@ -0,0 +1,177 @@ + + frmNapisy24Config + + + + 0 + 0 + 360 + 150 + + + + + 330 + 130 + + + + + 450 + 180 + + + + Napisy24 - konfiguracja + + + + + + Login: + + + + + + + + + + + + + + Hasło: + + + + + + + + + + QLineEdit::Password + + + + + + + Qt::Vertical + + + + 318 + 41 + + + + + + + + Załóż konto + + + + + + + Qt::Horizontal + + + + 108 + 20 + + + + + + + + Anuluj + + + + + + + Zapisz + + + + + + + + + + + pbCancel + clicked() + frmNapisy24Config + reject() + + + 236 + 101 + + + 164 + 59 + + + + + pbSave + clicked() + frmNapisy24Config + accept() + + + 300 + 101 + + + 164 + 59 + + + + + leNick + returnPressed() + frmNapisy24Config + accept() + + + 220 + 18 + + + 164 + 59 + + + + + lePass + returnPressed() + frmNapisy24Config + accept() + + + 220 + 51 + + + 164 + 59 + + + + +