Work on TT-RSS network/edit edialog.
This commit is contained in:
parent
e4358722a6
commit
5ea57062dc
@ -440,6 +440,7 @@ set(APP_SOURCES
|
||||
src/services/tt-rss/ttrssserviceentrypoint.cpp
|
||||
src/services/tt-rss/ttrssserviceroot.cpp
|
||||
src/services/tt-rss/gui/formeditaccount.cpp
|
||||
src/services/tt-rss/network/ttrssnetworkfactory.cpp
|
||||
|
||||
# NETWORK-WEB sources.
|
||||
src/network-web/basenetworkaccessmanager.cpp
|
||||
|
2
src/gui/labelwithstatus.cpp
Normal file → Executable file
2
src/gui/labelwithstatus.cpp
Normal file → Executable file
@ -26,6 +26,8 @@ LabelWithStatus::LabelWithStatus(QWidget *parent)
|
||||
: WidgetWithStatus(parent) {
|
||||
m_wdgInput = new QLabel(this);
|
||||
|
||||
qobject_cast<QLabel*>(m_wdgInput)->setWordWrap(true);
|
||||
|
||||
// Set correct size for the tool button.
|
||||
int label_height = m_wdgInput->sizeHint().height();
|
||||
m_btnStatus->setFixedSize(label_height, label_height);
|
||||
|
@ -1,6 +1,9 @@
|
||||
#ifndef DEFINITIONS_H
|
||||
#define DEFINITIONS_H
|
||||
|
||||
#define MINIMAL_API_LEVEL 10
|
||||
#define CONTENT_TYPE "application/json; charset=utf-8"
|
||||
|
||||
// Error when user needs to login before making an operation.
|
||||
#define NOT_LOGGED_IN "NOT_LOGGED_IN"
|
||||
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include "services/tt-rss/gui/formeditaccount.h"
|
||||
|
||||
#include "services/tt-rss/ttrssserviceroot.h"
|
||||
#include "services/tt-rss/network/ttrssnetworkfactory.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
|
||||
|
||||
FormEditAccount::FormEditAccount(QWidget *parent)
|
||||
@ -26,13 +28,23 @@ FormEditAccount::FormEditAccount(QWidget *parent)
|
||||
m_ui->setupUi(this);
|
||||
m_btnOk = m_ui->m_buttonBox->button(QDialogButtonBox::Ok);
|
||||
|
||||
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint);
|
||||
setWindowIcon(qApp->icons()->fromTheme(QSL("application-ttrss")));
|
||||
|
||||
m_ui->m_txtPassword->lineEdit()->setPlaceholderText(tr("Password for your TT-RSS account."));
|
||||
m_ui->m_txtUsername->lineEdit()->setPlaceholderText(tr("Username for your TT-RSS account."));
|
||||
m_ui->m_txtUrl->lineEdit()->setPlaceholderText(tr("URL of your TT-RSS instance WITHOUT trailing \"/api/\" string."));
|
||||
m_ui->m_txtUrl->lineEdit()->setPlaceholderText(tr("FULL URL of your TT-RSS instance WITH trailing \"/api/\" string."));
|
||||
m_ui->m_lblTestResult->setStatus(WidgetWithStatus::Information,
|
||||
tr("No test done yet."),
|
||||
tr("Here, results of connection test are shown."));
|
||||
|
||||
setTabOrder(m_ui->m_txtUrl->lineEdit(), m_ui->m_txtUsername->lineEdit());
|
||||
setTabOrder(m_ui->m_txtUsername->lineEdit(), m_ui->m_txtPassword->lineEdit());
|
||||
setTabOrder(m_ui->m_txtPassword->lineEdit(), m_ui->m_checkShowPassword);
|
||||
setTabOrder(m_ui->m_checkShowPassword, m_ui->m_btnTestSetup);
|
||||
setTabOrder(m_ui->m_btnTestSetup, m_ui->m_buttonBox);
|
||||
|
||||
connect(m_ui->m_checkShowPassword, SIGNAL(toggled(bool)), this, SLOT(displayPassword(bool)));
|
||||
connect(m_ui->m_buttonBox, SIGNAL(accepted()), this, SLOT(onClickedOk()));
|
||||
connect(m_ui->m_buttonBox, SIGNAL(rejected()), this, SLOT(onClickedCancel()));
|
||||
connect(m_ui->m_txtPassword->lineEdit(), SIGNAL(textEdited(QString)), this, SLOT(onPasswordChanged()));
|
||||
@ -47,6 +59,7 @@ FormEditAccount::FormEditAccount(QWidget *parent)
|
||||
onUsernameChanged();
|
||||
onUrlChanged();
|
||||
checkOkButton();
|
||||
displayPassword(false);
|
||||
}
|
||||
|
||||
FormEditAccount::~FormEditAccount() {
|
||||
@ -65,8 +78,27 @@ void FormEditAccount::execForEdit(TtRssServiceRoot *existing_root) {
|
||||
exec();
|
||||
}
|
||||
|
||||
void FormEditAccount::performTest() {
|
||||
void FormEditAccount::displayPassword(bool display) {
|
||||
m_ui->m_txtPassword->lineEdit()->setEchoMode(display ? QLineEdit::Normal : QLineEdit::Password);
|
||||
}
|
||||
|
||||
void FormEditAccount::performTest() {
|
||||
TtRssNetworkFactory factory;
|
||||
|
||||
factory.setUsername(m_ui->m_txtUsername->lineEdit()->text());
|
||||
factory.setPassword(m_ui->m_txtPassword->lineEdit()->text());
|
||||
factory.setUrl(m_ui->m_txtUrl->lineEdit()->text());
|
||||
|
||||
LoginResult result = factory.login();
|
||||
|
||||
if (result.first == QNetworkReply::NoError) {
|
||||
|
||||
}
|
||||
else {
|
||||
m_ui->m_lblTestResult->setStatus(WidgetWithStatus::Error,
|
||||
tr("Network error, have you entered correct Tiny Tiny RSS API endpoint?"),
|
||||
tr("Network error, have you entered correct Tiny Tiny RSS API endpoint?"));
|
||||
}
|
||||
}
|
||||
|
||||
void FormEditAccount::onClickedOk() {
|
||||
|
@ -41,6 +41,7 @@ class FormEditAccount : public QDialog {
|
||||
void execForEdit(TtRssServiceRoot *existing_root);
|
||||
|
||||
private slots:
|
||||
void displayPassword(bool display);
|
||||
void performTest();
|
||||
void onClickedOk();
|
||||
void onClickedCancel();
|
||||
|
@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<width>465</width>
|
||||
<height>235</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -16,19 +16,6 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="m_lblTitle">
|
||||
<property name="text">
|
||||
<string>URL</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>m_txtUrl</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="LineEditWithStatus" name="m_txtUrl" native="true"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="m_btnTestSetup">
|
||||
<property name="text">
|
||||
@ -36,6 +23,19 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="LabelWithStatus" name="m_lblTestResult" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::RightToLeft</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="m_gbAuthentication">
|
||||
<property name="toolTip">
|
||||
@ -77,21 +77,32 @@
|
||||
<item row="0" column="1">
|
||||
<widget class="LineEditWithStatus" name="m_txtUsername" native="true"/>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QCheckBox" name="m_checkShowPassword">
|
||||
<property name="text">
|
||||
<string>Show password</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="LabelWithStatus" name="m_lblTestResult" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::RightToLeft</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="m_lblTitle">
|
||||
<property name="text">
|
||||
<string>URL</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>m_txtUrl</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="LineEditWithStatus" name="m_txtUrl" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
|
142
src/services/tt-rss/network/ttrssnetworkfactory.cpp
Executable file
142
src/services/tt-rss/network/ttrssnetworkfactory.cpp
Executable file
@ -0,0 +1,142 @@
|
||||
// This file is part of RSS Guard.
|
||||
//
|
||||
// Copyright (C) 2011-2015 by Martin Rotter <rotter.martinos@gmail.com>
|
||||
//
|
||||
// RSS Guard 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// RSS Guard is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "services/tt-rss/network/ttrssnetworkfactory.h"
|
||||
|
||||
#include "definitions/definitions.h"
|
||||
#include "services/tt-rss/definitions.h"
|
||||
#include "network-web/networkfactory.h"
|
||||
|
||||
|
||||
TtRssNetworkFactory::TtRssNetworkFactory() : m_url(QString()) {
|
||||
}
|
||||
|
||||
TtRssNetworkFactory::~TtRssNetworkFactory() {
|
||||
}
|
||||
|
||||
QString TtRssNetworkFactory::url() const {
|
||||
return m_url;
|
||||
}
|
||||
|
||||
void TtRssNetworkFactory::setUrl(const QString &url) {
|
||||
m_url = url;
|
||||
}
|
||||
|
||||
QString TtRssNetworkFactory::username() const {
|
||||
return m_username;
|
||||
}
|
||||
|
||||
void TtRssNetworkFactory::setUsername(const QString &username) {
|
||||
m_username = username;
|
||||
}
|
||||
|
||||
QString TtRssNetworkFactory::password() const {
|
||||
return m_password;
|
||||
}
|
||||
|
||||
void TtRssNetworkFactory::setPassword(const QString &password) {
|
||||
m_password = password;
|
||||
}
|
||||
|
||||
LoginResult TtRssNetworkFactory::login() {
|
||||
QtJson::JsonObject json;
|
||||
json["op"] = "login";
|
||||
json["user"] = m_username;
|
||||
json["password"] = m_password;
|
||||
|
||||
QByteArray result;
|
||||
NetworkResult res = NetworkFactory::uploadData(m_url, DOWNLOAD_TIMEOUT, QtJson::serialize(json), CONTENT_TYPE, result);
|
||||
|
||||
if (res.first != QNetworkReply::NoError) {
|
||||
return LoginResult(res.first, TtRssLoginResponse());
|
||||
}
|
||||
else {
|
||||
return LoginResult(res.first, TtRssLoginResponse(QString::fromUtf8(result)));
|
||||
}
|
||||
}
|
||||
|
||||
TtRssResponse::TtRssResponse(const QString &raw_content) {
|
||||
m_rawContent = QtJson::parse(raw_content).toMap();
|
||||
}
|
||||
|
||||
TtRssResponse::~TtRssResponse() {
|
||||
}
|
||||
|
||||
bool TtRssResponse::isLoaded() const {
|
||||
return !m_rawContent.empty();
|
||||
}
|
||||
|
||||
int TtRssResponse::seq() const {
|
||||
if (!isLoaded()) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return m_rawContent["seq"].toInt();
|
||||
}
|
||||
}
|
||||
|
||||
int TtRssResponse::status() const {
|
||||
if (!isLoaded()) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return m_rawContent["status"].toInt();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TtRssLoginResponse::TtRssLoginResponse(const QString &raw_content) : TtRssResponse(raw_content) {
|
||||
}
|
||||
|
||||
TtRssLoginResponse::~TtRssLoginResponse() {
|
||||
}
|
||||
|
||||
int TtRssLoginResponse::apiLevel() const {
|
||||
if (!isLoaded()) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return m_rawContent["content"].toMap()["api_level"].toInt();
|
||||
}
|
||||
}
|
||||
|
||||
QString TtRssLoginResponse::sessionId() const {
|
||||
if (!isLoaded()) {
|
||||
return QString();
|
||||
}
|
||||
else {
|
||||
return m_rawContent["content"].toMap()["session_id"].toString();
|
||||
}
|
||||
}
|
||||
|
||||
QString TtRssLoginResponse::error() const {
|
||||
if (!isLoaded()) {
|
||||
return QString();
|
||||
}
|
||||
else {
|
||||
return m_rawContent["content"].toMap()["error"].toString();
|
||||
}
|
||||
}
|
||||
|
||||
bool TtRssLoginResponse::hasError() const {
|
||||
if (!isLoaded()) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return m_rawContent["content"].toMap().contains("error");
|
||||
}
|
||||
}
|
78
src/services/tt-rss/network/ttrssnetworkfactory.h
Executable file
78
src/services/tt-rss/network/ttrssnetworkfactory.h
Executable file
@ -0,0 +1,78 @@
|
||||
// This file is part of RSS Guard.
|
||||
//
|
||||
// Copyright (C) 2011-2015 by Martin Rotter <rotter.martinos@gmail.com>
|
||||
//
|
||||
// RSS Guard 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// RSS Guard is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef TTRSSNETWORKFACTORY_H
|
||||
#define TTRSSNETWORKFACTORY_H
|
||||
|
||||
#include "qt-json/json.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QPair>
|
||||
#include <QNetworkReply>
|
||||
|
||||
|
||||
class TtRssResponse {
|
||||
public:
|
||||
explicit TtRssResponse(const QString &raw_content = QString());
|
||||
virtual ~TtRssResponse();
|
||||
|
||||
bool isLoaded() const;
|
||||
|
||||
int seq() const;
|
||||
int status() const;
|
||||
|
||||
protected:
|
||||
QtJson::JsonObject m_rawContent;
|
||||
};
|
||||
|
||||
class TtRssLoginResponse : public TtRssResponse {
|
||||
public:
|
||||
explicit TtRssLoginResponse(const QString &raw_content = QString());
|
||||
virtual ~TtRssLoginResponse();
|
||||
|
||||
int apiLevel() const;
|
||||
QString sessionId() const;
|
||||
QString error() const;
|
||||
bool hasError() const;
|
||||
};
|
||||
|
||||
typedef QPair<QNetworkReply::NetworkError,TtRssLoginResponse> LoginResult;
|
||||
|
||||
class TtRssNetworkFactory {
|
||||
public:
|
||||
explicit TtRssNetworkFactory();
|
||||
virtual ~TtRssNetworkFactory();
|
||||
|
||||
QString url() const;
|
||||
void setUrl(const QString &url);
|
||||
|
||||
QString username() const;
|
||||
void setUsername(const QString &username);
|
||||
|
||||
QString password() const;
|
||||
void setPassword(const QString &password);
|
||||
|
||||
// Operations.
|
||||
LoginResult login();
|
||||
|
||||
private:
|
||||
QString m_url;
|
||||
QString m_username;
|
||||
QString m_password;
|
||||
};
|
||||
|
||||
#endif // TTRSSNETWORKFACTORY_H
|
Loading…
x
Reference in New Issue
Block a user