Unified account dialog for nextcloud.

This commit is contained in:
Martin Rotter 2021-01-12 09:04:03 +01:00
parent c1286b8670
commit abaadbafda
8 changed files with 57 additions and 418 deletions

View File

@ -156,6 +156,7 @@ HEADERS += core/feeddownloader.h \
services/inoreader/network/inoreadernetworkfactory.h \
services/owncloud/definitions.h \
services/owncloud/gui/formeditowncloudaccount.h \
services/owncloud/gui/owncloudaccountdetails.h \
services/owncloud/network/owncloudnetworkfactory.h \
services/owncloud/owncloudfeed.h \
services/owncloud/owncloudserviceentrypoint.h \
@ -309,6 +310,7 @@ SOURCES += core/feeddownloader.cpp \
services/inoreader/inoreaderserviceroot.cpp \
services/inoreader/network/inoreadernetworkfactory.cpp \
services/owncloud/gui/formeditowncloudaccount.cpp \
services/owncloud/gui/owncloudaccountdetails.cpp \
services/owncloud/network/owncloudnetworkfactory.cpp \
services/owncloud/owncloudfeed.cpp \
services/owncloud/owncloudserviceentrypoint.cpp \
@ -373,8 +375,8 @@ FORMS += gui/dialogs/formabout.ui \
services/abstract/gui/formfeeddetails.ui \
services/gmail/gui/formeditgmailaccount.ui \
services/inoreader/gui/formeditinoreaderaccount.ui \
services/owncloud/gui/formeditowncloudaccount.ui \
services/abstract/gui/authenticationdetails.ui \
services/owncloud/gui/owncloudaccountdetails.ui \
services/standard/gui/formstandardcategorydetails.ui \
services/standard/gui/formstandardimportexport.ui \
services/standard/gui/standardfeeddetails.ui \

View File

@ -6,192 +6,68 @@
#include "miscellaneous/iconfactory.h"
#include "network-web/networkfactory.h"
#include "services/owncloud/definitions.h"
#include "services/owncloud/gui/owncloudaccountdetails.h"
#include "services/owncloud/network/owncloudnetworkfactory.h"
#include "services/owncloud/owncloudserviceroot.h"
FormEditOwnCloudAccount::FormEditOwnCloudAccount(QWidget* parent)
: QDialog(parent), m_ui(new Ui::FormEditOwnCloudAccount), m_editableRoot(nullptr) {
m_ui->setupUi(this);
m_btnOk = m_ui->m_buttonBox->button(QDialogButtonBox::Ok);
: FormAccountDetails(qApp->icons()->miscIcon(QSL("nextcloud")), parent), m_details(new OwnCloudAccountDetails(this)) {
insertCustomTab(m_details, tr("Server setup"), 0);
activateTab(0);
GuiUtilities::applyDialogProperties(*this, qApp->icons()->miscIcon(QSL("nextcloud")));
m_ui->m_lblTestResult->label()->setWordWrap(true);
m_ui->m_lblServerSideUpdateInformation->setText(tr("Leaving this option on causes that updates "
"of feeds will be probably much slower and may time-out often."));
m_ui->m_txtPassword->lineEdit()->setPlaceholderText(tr("Password for your Nextcloud account"));
m_ui->m_txtUsername->lineEdit()->setPlaceholderText(tr("Username for your Nextcloud account"));
m_ui->m_txtUrl->lineEdit()->setPlaceholderText(tr("URL of your Nextcloud server, without any API path"));
m_ui->m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Information,
tr("No test done yet."),
tr("Here, results of connection test are shown."));
m_ui->m_lblLimitMessages->setText(
tr("Limiting number of downloaded messages per feed makes updating of feeds faster but if your feed contains "
"bigger number of messages than specified limit, then some messages might not be downloaded during feed update."));
connect(m_ui->m_spinLimitMessages, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, [=](int value) {
if (value <= 0) {
m_ui->m_spinLimitMessages->setSuffix(QSL(" ") + tr("= unlimited"));
}
else {
m_ui->m_spinLimitMessages->setSuffix(QSL(" ") + tr("messages"));
}
});
GuiUtilities::setLabelAsNotice(*m_ui->m_lblLimitMessages, false);
GuiUtilities::setLabelAsNotice(*m_ui->m_lblServerSideUpdateInformation, false);
setTabOrder(m_ui->m_txtUrl->lineEdit(), m_ui->m_checkServerSideUpdate);
setTabOrder(m_ui->m_checkServerSideUpdate, m_ui->m_spinLimitMessages);
setTabOrder(m_ui->m_spinLimitMessages, 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, &QCheckBox::toggled, this, &FormEditOwnCloudAccount::displayPassword);
connect(m_ui->m_buttonBox, &QDialogButtonBox::accepted, this, &FormEditOwnCloudAccount::onClickedOk);
connect(m_ui->m_buttonBox, &QDialogButtonBox::rejected, this, &FormEditOwnCloudAccount::onClickedCancel);
connect(m_ui->m_txtPassword->lineEdit(), &BaseLineEdit::textChanged, this, &FormEditOwnCloudAccount::onPasswordChanged);
connect(m_ui->m_txtUsername->lineEdit(), &BaseLineEdit::textChanged, this, &FormEditOwnCloudAccount::onUsernameChanged);
connect(m_ui->m_txtUrl->lineEdit(), &BaseLineEdit::textChanged, this, &FormEditOwnCloudAccount::onUrlChanged);
connect(m_ui->m_txtPassword->lineEdit(), &BaseLineEdit::textChanged, this, &FormEditOwnCloudAccount::checkOkButton);
connect(m_ui->m_txtUsername->lineEdit(), &BaseLineEdit::textChanged, this, &FormEditOwnCloudAccount::checkOkButton);
connect(m_ui->m_txtUrl->lineEdit(), &BaseLineEdit::textChanged, this, &FormEditOwnCloudAccount::checkOkButton);
connect(m_ui->m_btnTestSetup, &QPushButton::clicked, this, &FormEditOwnCloudAccount::performTest);
onPasswordChanged();
onUsernameChanged();
onUrlChanged();
checkOkButton();
displayPassword(false);
m_details->m_ui.m_txtUrl->setFocus();
}
FormEditOwnCloudAccount::~FormEditOwnCloudAccount() = default;
OwnCloudServiceRoot* FormEditOwnCloudAccount::execForCreate() {
setWindowTitle(tr("Add new Nextcloud News account"));
exec();
return m_editableRoot;
}
void FormEditOwnCloudAccount::execForEdit(OwnCloudServiceRoot* existing_root) {
setWindowTitle(tr("Edit existing Nextcloud News account"));
m_editableRoot = existing_root;
m_ui->m_txtUsername->lineEdit()->setText(existing_root->network()->authUsername());
m_ui->m_txtPassword->lineEdit()->setText(existing_root->network()->authPassword());
m_ui->m_txtUrl->lineEdit()->setText(existing_root->network()->url());
m_ui->m_checkDownloadOnlyUnreadMessages->setChecked(existing_root->network()->downloadOnlyUnreadMessages());
m_ui->m_checkServerSideUpdate->setChecked(existing_root->network()->forceServerSideUpdate());
m_ui->m_spinLimitMessages->setValue(existing_root->network()->batchSize());
exec();
}
void FormEditOwnCloudAccount::displayPassword(bool display) {
m_ui->m_txtPassword->lineEdit()->setEchoMode(display ? QLineEdit::Normal : QLineEdit::Password);
}
void FormEditOwnCloudAccount::performTest() {
OwnCloudNetworkFactory factory;
factory.setAuthUsername(m_ui->m_txtUsername->lineEdit()->text());
factory.setAuthPassword(m_ui->m_txtPassword->lineEdit()->text());
factory.setUrl(m_ui->m_txtUrl->lineEdit()->text());
factory.setForceServerSideUpdate(m_ui->m_checkServerSideUpdate->isChecked());
OwnCloudStatusResponse result = factory.status();
if (result.networkError() != QNetworkReply::NetworkError::NoError) {
m_ui->m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Error,
tr("Network error: '%1'.").arg(NetworkFactory::networkErrorText(result.networkError())),
tr("Network error, have you entered correct Nextcloud endpoint and password?"));
}
else if (result.isLoaded()) {
if (!SystemFactory::isVersionEqualOrNewer(result.version(), OWNCLOUD_MIN_VERSION)) {
m_ui->m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Error,
tr("Installed version: %1, required at least: %2.").arg(result.version(), OWNCLOUD_MIN_VERSION),
tr("Selected Nextcloud News server is running unsupported version."));
}
else {
m_ui->m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Ok,
tr("Installed version: %1, required at least: %2.").arg(result.version(), OWNCLOUD_MIN_VERSION),
tr("Nextcloud News server is okay."));
}
OwnCloudServiceRoot* FormEditOwnCloudAccount::addEditAccount(OwnCloudServiceRoot* account_to_edit) {
if (account_to_edit == nullptr) {
// User is adding new TT-RSS account.
setWindowTitle(tr("Add new Nextcloud News account"));
}
else {
m_ui->m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Error,
tr("Unspecified error, did you enter correct URL?"),
tr("Unspecified error, did you enter correct URL?"));
setEditableAccount(account_to_edit);
}
exec();
return account<OwnCloudServiceRoot>();
}
void FormEditOwnCloudAccount::onClickedOk() {
void FormEditOwnCloudAccount::apply() {
FormAccountDetails::apply();
bool editing_account = true;
if (m_editableRoot == nullptr) {
if (m_account == nullptr) {
// We want to confirm newly created account.
// So save new account into DB, setup its properties.
m_editableRoot = new OwnCloudServiceRoot();
m_account = new OwnCloudServiceRoot();
editing_account = false;
}
m_editableRoot->network()->setUrl(m_ui->m_txtUrl->lineEdit()->text());
m_editableRoot->network()->setAuthUsername(m_ui->m_txtUsername->lineEdit()->text());
m_editableRoot->network()->setAuthPassword(m_ui->m_txtPassword->lineEdit()->text());
m_editableRoot->network()->setForceServerSideUpdate(m_ui->m_checkServerSideUpdate->isChecked());
m_editableRoot->network()->setBatchSize(m_ui->m_spinLimitMessages->value());
m_editableRoot->network()->setDownloadOnlyUnreadMessages(m_ui->m_checkDownloadOnlyUnreadMessages->isChecked());
account<OwnCloudServiceRoot>()->network()->setUrl(m_details->m_ui.m_txtUrl->lineEdit()->text());
account<OwnCloudServiceRoot>()->network()->setAuthUsername(m_details->m_ui.m_txtUsername->lineEdit()->text());
account<OwnCloudServiceRoot>()->network()->setAuthPassword(m_details->m_ui.m_txtPassword->lineEdit()->text());
account<OwnCloudServiceRoot>()->network()->setForceServerSideUpdate(m_details->m_ui.m_checkServerSideUpdate->isChecked());
account<OwnCloudServiceRoot>()->network()->setBatchSize(m_details->m_ui.m_spinLimitMessages->value());
account<OwnCloudServiceRoot>()->network()->setDownloadOnlyUnreadMessages(m_details->m_ui.m_checkDownloadOnlyUnreadMessages->isChecked());
m_editableRoot->saveAccountDataToDatabase();
account<OwnCloudServiceRoot>()->saveAccountDataToDatabase();
accept();
if (editing_account) {
m_editableRoot->completelyRemoveAllData();
m_editableRoot->syncIn();
account<OwnCloudServiceRoot>()->completelyRemoveAllData();
account<OwnCloudServiceRoot>()->syncIn();
}
}
void FormEditOwnCloudAccount::onClickedCancel() {
reject();
}
void FormEditOwnCloudAccount::onUsernameChanged() {
const QString username = m_ui->m_txtUsername->lineEdit()->text();
if (username.isEmpty()) {
m_ui->m_txtUsername->setStatus(WidgetWithStatus::StatusType::Error, tr("Username cannot be empty."));
}
else {
m_ui->m_txtUsername->setStatus(WidgetWithStatus::StatusType::Ok, tr("Username is okay."));
}
}
void FormEditOwnCloudAccount::onPasswordChanged() {
const QString password = m_ui->m_txtPassword->lineEdit()->text();
if (password.isEmpty()) {
m_ui->m_txtPassword->setStatus(WidgetWithStatus::StatusType::Error, tr("Password cannot be empty."));
}
else {
m_ui->m_txtPassword->setStatus(WidgetWithStatus::StatusType::Ok, tr("Password is okay."));
}
}
void FormEditOwnCloudAccount::onUrlChanged() {
const QString url = m_ui->m_txtUrl->lineEdit()->text();
if (url.isEmpty()) {
m_ui->m_txtUrl->setStatus(WidgetWithStatus::StatusType::Error, tr("URL cannot be empty."));
}
else {
m_ui->m_txtUrl->setStatus(WidgetWithStatus::StatusType::Ok, tr("URL is okay."));
}
}
void FormEditOwnCloudAccount::checkOkButton() {
m_btnOk->setEnabled(!m_ui->m_txtUsername->lineEdit()->text().isEmpty() &&
!m_ui->m_txtPassword->lineEdit()->text().isEmpty() &&
!m_ui->m_txtUrl->lineEdit()->text().isEmpty());
void FormEditOwnCloudAccount::setEditableAccount(ServiceRoot* editable_account) {
FormAccountDetails::setEditableAccount(editable_account);
OwnCloudServiceRoot* existing_root = account<OwnCloudServiceRoot>();
m_details->m_ui.m_txtUsername->lineEdit()->setText(existing_root->network()->authUsername());
m_details->m_ui.m_txtPassword->lineEdit()->setText(existing_root->network()->authPassword());
m_details->m_ui.m_txtUrl->lineEdit()->setText(existing_root->network()->url());
m_details->m_ui.m_checkDownloadOnlyUnreadMessages->setChecked(existing_root->network()->downloadOnlyUnreadMessages());
m_details->m_ui.m_checkServerSideUpdate->setChecked(existing_root->network()->forceServerSideUpdate());
m_details->m_ui.m_spinLimitMessages->setValue(existing_root->network()->batchSize());
}

View File

@ -3,42 +3,27 @@
#ifndef FORMEDITOWNCLOUDACCOUNT_H
#define FORMEDITOWNCLOUDACCOUNT_H
#include <QDialog>
#include "ui_formeditowncloudaccount.h"
namespace Ui {
class FormEditAccount;
}
#include "services/abstract/gui/formaccountdetails.h"
class OwnCloudAccountDetails;
class OwnCloudServiceRoot;
class FormEditOwnCloudAccount : public QDialog {
class FormEditOwnCloudAccount : public FormAccountDetails {
Q_OBJECT
public:
explicit FormEditOwnCloudAccount(QWidget* parent = 0);
virtual ~FormEditOwnCloudAccount();
explicit FormEditOwnCloudAccount(QWidget* parent = nullptr);
OwnCloudServiceRoot* execForCreate();
OwnCloudServiceRoot* addEditAccount(OwnCloudServiceRoot* account_to_edit = nullptr);
void execForEdit(OwnCloudServiceRoot* existing_root);
protected slots:
virtual void apply();
private slots:
void displayPassword(bool display);
void performTest();
void onClickedOk();
void onClickedCancel();
void onUsernameChanged();
void onPasswordChanged();
void onUrlChanged();
void checkOkButton();
protected:
virtual void setEditableAccount(ServiceRoot* editable_account);
private:
QScopedPointer<Ui::FormEditOwnCloudAccount> m_ui;
OwnCloudServiceRoot* m_editableRoot;
QPushButton* m_btnOk;
OwnCloudAccountDetails* m_details;
};
#endif // FORMEDITOWNCLOUDACCOUNT_H

View File

@ -1,227 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FormEditOwnCloudAccount</class>
<widget class="QDialog" name="FormEditOwnCloudAccount">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>552</width>
<height>453</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<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>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="m_checkServerSideUpdate">
<property name="text">
<string>Force execution of server-side update when updating feeds from RSS Guard</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="m_lblServerSideUpdateInformation">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Limit number of downloaded messages per feed</string>
</property>
<property name="buddy">
<cstring>m_spinLimitMessages</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="m_spinLimitMessages">
<property name="maximumSize">
<size>
<width>140</width>
<height>16777215</height>
</size>
</property>
<property name="suffix">
<string> = unlimited</string>
</property>
<property name="minimum">
<number>-1</number>
</property>
<property name="maximum">
<number>1000</number>
</property>
<property name="value">
<number>-1</number>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QLabel" name="m_lblLimitMessages">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<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>Authentication</string>
</property>
<property name="flat">
<bool>false</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="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>
<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="7" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="m_btnTestSetup">
<property name="text">
<string>&amp;Test setup</string>
</property>
</widget>
</item>
<item>
<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>
</layout>
</item>
<item row="8" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="m_checkDownloadOnlyUnreadMessages">
<property name="text">
<string>Download only unread messages</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="m_buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LineEditWithStatus</class>
<extends>QWidget</extends>
<header>lineeditwithstatus.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>LabelWithStatus</class>
<extends>QWidget</extends>
<header>labelwithstatus.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>m_checkDownloadOnlyUnreadMessages</tabstop>
<tabstop>m_checkServerSideUpdate</tabstop>
<tabstop>m_spinLimitMessages</tabstop>
<tabstop>m_checkShowPassword</tabstop>
<tabstop>m_btnTestSetup</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@ -13,7 +13,7 @@
ServiceRoot* OwnCloudServiceEntryPoint::createNewRoot() const {
FormEditOwnCloudAccount form_acc(qApp->mainFormWidget());
return form_acc.execForCreate();
return form_acc.addEditAccount();
}
QList<ServiceRoot*> OwnCloudServiceEntryPoint::initializeSubtree() const {

View File

@ -39,7 +39,7 @@ bool OwnCloudServiceRoot::canBeDeleted() const {
bool OwnCloudServiceRoot::editViaGui() {
QScopedPointer<FormEditOwnCloudAccount> form_pointer(new FormEditOwnCloudAccount(qApp->mainFormWidget()));
form_pointer->execForEdit(this);
form_pointer->addEditAccount(this);
return true;
}

View File

@ -12,6 +12,8 @@ FormEditTtRssAccount::FormEditTtRssAccount(QWidget* parent)
: FormAccountDetails(qApp->icons()->miscIcon(QSL("tt-rss")), parent), m_details(new TtRssAccountDetails(this)) {
insertCustomTab(m_details, tr("Server setup"), 0);
activateTab(0);
m_details->m_ui.m_txtUrl->setFocus();
}
TtRssServiceRoot* FormEditTtRssAccount::addEditAccount(TtRssServiceRoot* account_to_edit) {

View File

@ -26,7 +26,8 @@ TtRssAccountDetails::TtRssAccountDetails(QWidget* parent) : QWidget(parent) {
GuiUtilities::setLabelAsNotice(*m_ui.m_lblDescription, false);
GuiUtilities::setLabelAsNotice(*m_ui.m_lblServerSideUpdateInformation, false);
setTabOrder(m_ui.m_txtUrl->lineEdit(), m_ui.m_checkServerSideUpdate);
setTabOrder(m_ui.m_txtUrl->lineEdit(), m_ui.m_checkDownloadOnlyUnreadMessages);
setTabOrder(m_ui.m_checkDownloadOnlyUnreadMessages, m_ui.m_checkServerSideUpdate);
setTabOrder(m_ui.m_checkServerSideUpdate, 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);