Move feeds authentication to standard plugin.

This commit is contained in:
Martin Rotter 2020-11-30 12:26:04 +01:00
parent 03684f5d88
commit 74c583413e
9 changed files with 170 additions and 118 deletions

View File

@ -160,6 +160,7 @@ HEADERS += core/feeddownloader.h \
services/owncloud/owncloudserviceroot.h \
services/standard/atomparser.h \
services/standard/feedparser.h \
services/standard/gui/authenticationdetails.h \
services/standard/gui/formstandardcategorydetails.h \
services/standard/gui/formstandardfeeddetails.h \
services/standard/gui/formstandardimportexport.h \
@ -307,6 +308,7 @@ SOURCES += core/feeddownloader.cpp \
services/owncloud/owncloudserviceroot.cpp \
services/standard/atomparser.cpp \
services/standard/feedparser.cpp \
services/standard/gui/authenticationdetails.cpp \
services/standard/gui/formstandardcategorydetails.cpp \
services/standard/gui/formstandardfeeddetails.cpp \
services/standard/gui/formstandardimportexport.cpp \
@ -361,6 +363,7 @@ FORMS += gui/dialogs/formabout.ui \
services/gmail/gui/formeditgmailaccount.ui \
services/inoreader/gui/formeditinoreaderaccount.ui \
services/owncloud/gui/formeditowncloudaccount.ui \
services/standard/gui/authenticationdetails.ui \
services/standard/gui/formstandardcategorydetails.ui \
services/standard/gui/formstandardimportexport.ui \
services/standard/gui/standardfeeddetails.ui \

View File

@ -27,10 +27,6 @@ FormFeedDetails::FormFeedDetails(ServiceRoot* service_root, QWidget* parent)
m_serviceRoot(service_root) {
initialize();
createConnections();
// Initialize that shit.
onUsernameChanged(QString());
onPasswordChanged(QString());
}
int FormFeedDetails::editBaseFeed(Feed* input_feed) {
@ -52,9 +48,6 @@ void FormFeedDetails::apply() {
Feed new_feed;
// Setup data for new_feed.
new_feed.setPasswordProtected(m_ui->m_gbAuthentication->isChecked());
new_feed.setUsername(m_ui->m_txtUsername->lineEdit()->text());
new_feed.setPassword(m_ui->m_txtPassword->lineEdit()->text());
new_feed.setAutoUpdateType(static_cast<Feed::AutoUpdateType>(m_ui->m_cmbAutoUpdateType->itemData(
m_ui->m_cmbAutoUpdateType->currentIndex()).toInt()));
new_feed.setAutoUpdateInitialInterval(int(m_ui->m_spinAutoUpdateInterval->value()));
@ -77,33 +70,6 @@ void FormFeedDetails::apply() {
}
}
void FormFeedDetails::onUsernameChanged(const QString& new_username) {
bool is_username_ok = !m_ui->m_gbAuthentication->isChecked() || !new_username.simplified().isEmpty();
m_ui->m_txtUsername->setStatus(is_username_ok ?
LineEditWithStatus::StatusType::Ok :
LineEditWithStatus::StatusType::Warning,
is_username_ok ?
tr("Username is ok or it is not needed.") :
tr("Username is empty."));
}
void FormFeedDetails::onPasswordChanged(const QString& new_password) {
bool is_password_ok = !m_ui->m_gbAuthentication->isChecked() || !new_password.simplified().isEmpty();
m_ui->m_txtPassword->setStatus(is_password_ok ?
LineEditWithStatus::StatusType::Ok :
LineEditWithStatus::StatusType::Warning,
is_password_ok ?
tr("Password is ok or it is not needed.") :
tr("Password is empty."));
}
void FormFeedDetails::onAuthenticationSwitched() {
onUsernameChanged(m_ui->m_txtUsername->lineEdit()->text());
onPasswordChanged(m_ui->m_txtPassword->lineEdit()->text());
}
void FormFeedDetails::onAutoUpdateTypeChanged(int new_index) {
Feed::AutoUpdateType auto_update_type = static_cast<Feed::AutoUpdateType>(m_ui->m_cmbAutoUpdateType->itemData(new_index).toInt());
@ -121,9 +87,6 @@ void FormFeedDetails::onAutoUpdateTypeChanged(int new_index) {
void FormFeedDetails::createConnections() {
// General connections.
connect(m_ui->m_buttonBox, &QDialogButtonBox::accepted, this, &FormFeedDetails::apply);
connect(m_ui->m_txtUsername->lineEdit(), &BaseLineEdit::textChanged, this, &FormFeedDetails::onUsernameChanged);
connect(m_ui->m_txtPassword->lineEdit(), &BaseLineEdit::textChanged, this, &FormFeedDetails::onPasswordChanged);
connect(m_ui->m_gbAuthentication, &QGroupBox::toggled, this, &FormFeedDetails::onAuthenticationSwitched);
connect(m_ui->m_cmbAutoUpdateType, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&FormFeedDetails::onAutoUpdateTypeChanged);
}
@ -133,10 +96,6 @@ void FormFeedDetails::setEditableFeed(Feed* editable_feed) {
m_editableFeed = editable_feed;
m_ui->m_gbAuthentication->setChecked(editable_feed->passwordProtected());
m_ui->m_txtUsername->lineEdit()->setText(editable_feed->username());
m_ui->m_txtPassword->lineEdit()->setText(editable_feed->password());
m_ui->m_cmbAutoUpdateType->setCurrentIndex(m_ui->m_cmbAutoUpdateType->findData(QVariant::fromValue((int) editable_feed->autoUpdateType())));
m_ui->m_spinAutoUpdateInterval->setValue(editable_feed->autoUpdateInitialInterval());
}
@ -149,12 +108,6 @@ void FormFeedDetails::initialize() {
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint);
setWindowIcon(qApp->icons()->fromTheme(QSL("application-rss+xml")));
// Set text boxes.
m_ui->m_txtUsername->lineEdit()->setPlaceholderText(tr("Username"));
m_ui->m_txtUsername->lineEdit()->setToolTip(tr("Set username to access the feed."));
m_ui->m_txtPassword->lineEdit()->setPlaceholderText(tr("Password"));
m_ui->m_txtPassword->lineEdit()->setToolTip(tr("Set password to access the feed."));
// Setup auto-update options.
m_ui->m_spinAutoUpdateInterval->setValue(DEFAULT_AUTO_UPDATE_INTERVAL);
m_ui->m_cmbAutoUpdateType->addItem(tr("Auto-update using global interval"),

View File

@ -35,9 +35,6 @@ class FormFeedDetails : public QDialog {
// base implementation must be called first.
virtual void apply();
void onUsernameChanged(const QString& new_username);
void onPasswordChanged(const QString& new_password);
void onAuthenticationSwitched();
void onAutoUpdateTypeChanged(int new_index);
protected:

View File

@ -54,60 +54,6 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tabNetwork">
<attribute name="title">
<string>Network</string>
</attribute>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QGroupBox" name="m_gbAuthentication">
<property name="toolTip">
<string>Some feeds require authentication, including GMail feeds. BASIC, NTLM-2 and DIGEST-MD5 authentication schemes are supported.</string>
</property>
<property name="title">
<string>Requires HTTP authentication</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Username</string>
</property>
<property name="buddy">
<cstring>m_txtUsername</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="LineEditWithStatus" name="m_txtUsername" native="true"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Password</string>
</property>
<property name="buddy">
<cstring>m_txtPassword</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="LineEditWithStatus" name="m_txtPassword" native="true"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
@ -126,12 +72,6 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LineEditWithStatus</class>
<extends>QWidget</extends>
<header>lineeditwithstatus.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>TimeSpinBox</class>
<extends>QDoubleSpinBox</extends>

View File

@ -0,0 +1,47 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#include "services/standard/gui/authenticationdetails.h"
AuthenticationDetails::AuthenticationDetails(QWidget* parent) : QWidget(parent) {
ui.setupUi(this);
// Set text boxes.
ui.m_txtUsername->lineEdit()->setPlaceholderText(tr("Username"));
ui.m_txtUsername->lineEdit()->setToolTip(tr("Set username to access the feed."));
ui.m_txtPassword->lineEdit()->setPlaceholderText(tr("Password"));
ui.m_txtPassword->lineEdit()->setToolTip(tr("Set password to access the feed."));
connect(ui.m_txtUsername->lineEdit(), &BaseLineEdit::textChanged, this, &AuthenticationDetails::onUsernameChanged);
connect(ui.m_txtPassword->lineEdit(), &BaseLineEdit::textChanged, this, &AuthenticationDetails::onPasswordChanged);
connect(ui.m_gbAuthentication, &QGroupBox::toggled, this, &AuthenticationDetails::onAuthenticationSwitched);
onUsernameChanged(QString());
onPasswordChanged(QString());
}
void AuthenticationDetails::onUsernameChanged(const QString& new_username) {
bool is_username_ok = !ui.m_gbAuthentication->isChecked() || !new_username.simplified().isEmpty();
ui.m_txtUsername->setStatus(is_username_ok ?
LineEditWithStatus::StatusType::Ok :
LineEditWithStatus::StatusType::Warning,
is_username_ok ?
tr("Username is ok or it is not needed.") :
tr("Username is empty."));
}
void AuthenticationDetails::onPasswordChanged(const QString& new_password) {
bool is_password_ok = !ui.m_gbAuthentication->isChecked() || !new_password.simplified().isEmpty();
ui.m_txtPassword->setStatus(is_password_ok ?
LineEditWithStatus::StatusType::Ok :
LineEditWithStatus::StatusType::Warning,
is_password_ok ?
tr("Password is ok or it is not needed.") :
tr("Password is empty."));
}
void AuthenticationDetails::onAuthenticationSwitched() {
onUsernameChanged(ui.m_txtUsername->lineEdit()->text());
onPasswordChanged(ui.m_txtPassword->lineEdit()->text());
}

View File

@ -0,0 +1,27 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#ifndef AUTHENTICATIONDETAILS_H
#define AUTHENTICATIONDETAILS_H
#include <QWidget>
#include "ui_authenticationdetails.h"
class AuthenticationDetails : public QWidget {
Q_OBJECT
friend class FormStandardFeedDetails;
public:
explicit AuthenticationDetails(QWidget* parent = nullptr);
private slots:
void onUsernameChanged(const QString& new_username);
void onPasswordChanged(const QString& new_password);
void onAuthenticationSwitched();
private:
Ui::AuthenticationDetails ui;
};
#endif // AUTHENTICATIONDETAILS_H

View File

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AuthenticationDetails</class>
<widget class="QWidget" name="AuthenticationDetails">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QGroupBox" name="m_gbAuthentication">
<property name="toolTip">
<string>Some feeds require authentication, including GMail feeds. BASIC, NTLM-2 and DIGEST-MD5 authentication schemes are supported.</string>
</property>
<property name="title">
<string>Requires HTTP authentication</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Username</string>
</property>
<property name="buddy">
<cstring>m_txtUsername</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="LineEditWithStatus" name="m_txtUsername" native="true"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Password</string>
</property>
<property name="buddy">
<cstring>m_txtPassword</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="LineEditWithStatus" name="m_txtPassword" native="true"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LineEditWithStatus</class>
<extends>QWidget</extends>
<header>lineeditwithstatus.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -7,6 +7,7 @@
#include "network-web/networkfactory.h"
#include "services/abstract/category.h"
#include "services/abstract/serviceroot.h"
#include "services/standard/gui/authenticationdetails.h"
#include "services/standard/gui/standardfeeddetails.h"
#include "services/standard/standardfeed.h"
@ -14,8 +15,10 @@
#include <QTextCodec>
FormStandardFeedDetails::FormStandardFeedDetails(ServiceRoot* service_root, QWidget* parent)
: FormFeedDetails(service_root, parent), m_standardFeedDetails(new StandardFeedDetails(this)) {
: FormFeedDetails(service_root, parent), m_standardFeedDetails(new StandardFeedDetails(this)),
m_authDetails(new AuthenticationDetails(this)) {
insertCustomTab(m_standardFeedDetails, tr("General"), 0);
insertCustomTab(m_authDetails, tr("Network"), 2);
activateTab(0);
connect(m_standardFeedDetails->ui.m_btnFetchMetadata, &QPushButton::clicked, this, &FormStandardFeedDetails::guessFeed);
@ -41,14 +44,14 @@ int FormStandardFeedDetails::addEditFeed(Feed* input_feed, RootItem* parent_to_s
void FormStandardFeedDetails::guessFeed() {
m_standardFeedDetails->guessFeed(m_standardFeedDetails->ui.m_txtUrl->lineEdit()->text(),
m_ui->m_txtUsername->lineEdit()->text(),
m_ui->m_txtPassword->lineEdit()->text());
m_authDetails->ui.m_txtUsername->lineEdit()->text(),
m_authDetails->ui.m_txtPassword->lineEdit()->text());
}
void FormStandardFeedDetails::guessIconOnly() {
m_standardFeedDetails->guessIconOnly(m_standardFeedDetails->ui.m_txtUrl->lineEdit()->text(),
m_ui->m_txtUsername->lineEdit()->text(),
m_ui->m_txtPassword->lineEdit()->text());
m_authDetails->ui.m_txtUsername->lineEdit()->text(),
m_authDetails->ui.m_txtPassword->lineEdit()->text());
}
void FormStandardFeedDetails::apply() {
@ -68,9 +71,9 @@ void FormStandardFeedDetails::apply() {
new_feed->setEncoding(m_standardFeedDetails->ui.m_cmbEncoding->currentText());
new_feed->setType(type);
new_feed->setUrl(m_standardFeedDetails->ui.m_txtUrl->lineEdit()->text());
new_feed->setPasswordProtected(m_ui->m_gbAuthentication->isChecked());
new_feed->setUsername(m_ui->m_txtUsername->lineEdit()->text());
new_feed->setPassword(m_ui->m_txtPassword->lineEdit()->text());
new_feed->setPasswordProtected(m_authDetails->ui.m_gbAuthentication->isChecked());
new_feed->setUsername(m_authDetails->ui.m_txtUsername->lineEdit()->text());
new_feed->setPassword(m_authDetails->ui.m_txtPassword->lineEdit()->text());
new_feed->setAutoUpdateType(static_cast<Feed::AutoUpdateType>(m_ui->m_cmbAutoUpdateType->itemData(
m_ui->m_cmbAutoUpdateType->currentIndex()).toInt()));
new_feed->setAutoUpdateInitialInterval(int(m_ui->m_spinAutoUpdateInterval->value()));
@ -110,5 +113,9 @@ void FormStandardFeedDetails::apply() {
void FormStandardFeedDetails::setEditableFeed(Feed* editable_feed) {
FormFeedDetails::setEditableFeed(editable_feed);
m_standardFeedDetails->setExistingFeed(qobject_cast<StandardFeed*>(editable_feed));
m_authDetails->ui.m_gbAuthentication->setChecked(editable_feed->passwordProtected());
m_authDetails->ui.m_txtUsername->lineEdit()->setText(editable_feed->username());
m_authDetails->ui.m_txtPassword->lineEdit()->setText(editable_feed->password());
}

View File

@ -6,6 +6,7 @@
#include "services/abstract/gui/formfeeddetails.h"
class StandardFeedDetails;
class AuthenticationDetails;
class FormStandardFeedDetails : public FormFeedDetails {
Q_OBJECT
@ -27,6 +28,7 @@ class FormStandardFeedDetails : public FormFeedDetails {
private:
StandardFeedDetails* m_standardFeedDetails;
AuthenticationDetails* m_authDetails;
};
#endif // FORMSSFEEDDETAILS_H