Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Napisy24 engine configuration #88

Merged
merged 2 commits into from
Oct 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion qnapi.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand All @@ -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 \
Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions src/engines/qnapiabstractengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <QFile>
#include <QIcon>
#include <QPixmap>
#include <QUrl>

#include <ctime>

Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/engines/qnapiprojektengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 20 additions & 4 deletions src/engines/qnapisy24engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*****************************************************************************/

#include "qnapisy24engine.h"
#include "forms/frmnapisy24config.h"
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrl>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -480,3 +484,15 @@ void QNapisy24Engine::cleanup()
if(QFile::exists(subtitlesTmp))
QFile::remove(subtitlesTmp);
}

QPair<QString, QString> 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"));
}
}
6 changes: 6 additions & 0 deletions src/engines/qnapisy24engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QNapiSubtitleInfo> listSubtitles();
Expand All @@ -38,6 +42,8 @@ class QNapisy24Engine : public QNapiAbstractEngine
void cleanup();

private:
QPair<QString, QString> getCredentials() const;

quint64 fileSize;
QString p7zipPath;
};
Expand Down
4 changes: 4 additions & 0 deletions src/engines/qopensubtitlesengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/forms/frmnapiprojektconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ void frmNapiProjektConfig::accept()

void frmNapiProjektConfig::pbRegisterClicked()
{
((QNapiApp*)qApp)->showNPCreateUser();
load();
((QNapiApp*)qApp)->showCreateAccount("NapiProjekt");
}

void frmNapiProjektConfig::load()
Expand Down
52 changes: 52 additions & 0 deletions src/forms/frmnapisy24config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

/*****************************************************************************
** QNapi
** Copyright (C) 2008-2015 Piotr Krzemiński <[email protected]>
**
** 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"));
}
47 changes: 47 additions & 0 deletions src/forms/frmnapisy24config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*****************************************************************************
** QNapi
** Copyright (C) 2008-2015 Piotr Krzemiński <[email protected]>
**
** 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 <QDialog>
#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
2 changes: 1 addition & 1 deletion src/forms/frmopensubtitlesconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void frmOpenSubtitlesConfig::accept()

void frmOpenSubtitlesConfig::pbRegisterClicked()
{
((QNapiApp*)qApp)->showOSCreateUser();
((QNapiApp*)qApp)->showCreateAccount("OpenSubtitles");
}

void frmOpenSubtitlesConfig::load()
Expand Down
43 changes: 10 additions & 33 deletions src/qnapiapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -270,41 +270,18 @@ 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()
{
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)
Expand Down
11 changes: 1 addition & 10 deletions src/qnapiapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading