Custom usernames.

This commit is contained in:
Martin Rotter 2017-09-22 12:54:53 +02:00
parent d4d186b951
commit 1bb112d346
5 changed files with 100 additions and 47 deletions

View File

@ -32,6 +32,11 @@ FormEditInoreaderAccount::FormEditInoreaderAccount(QWidget* parent) : QDialog(pa
tr("Not tested yet."),
tr("Not tested yet."));
m_ui.m_lblTestResult->label()->setWordWrap(true);
m_ui.m_txtUsername->lineEdit()->setPlaceholderText(tr("User-visible username"));
setTabOrder(m_ui.m_txtUsername->lineEdit(), m_ui.m_spinLimitMessages);
setTabOrder(m_ui.m_spinLimitMessages, m_ui.m_btnTestSetup);
setTabOrder(m_ui.m_btnTestSetup, m_ui.m_buttonBox);
connect(m_ui.m_spinLimitMessages, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [=](int value) {
if (value <= 0) {
@ -41,10 +46,14 @@ FormEditInoreaderAccount::FormEditInoreaderAccount(QWidget* parent) : QDialog(pa
m_ui.m_spinLimitMessages->setSuffix(QSL(" ") + tr("messages"));
}
});
m_ui.m_spinLimitMessages->setValue(INOREADER_DEFAULT_BATCH_SIZE);
m_ui.m_spinLimitMessages->setMinimum(INOREADER_UNLIMITED_BATCH_SIZE);
connect(m_ui.m_txtUsername->lineEdit(), &BaseLineEdit::textChanged, [this](QString text) {
if (text.isEmpty()) {
m_ui.m_txtUsername->setStatus(WidgetWithStatus::StatusType::Error, tr("No username entered."));
}
else {
m_ui.m_txtUsername->setStatus(WidgetWithStatus::StatusType::Ok, tr("Some username entered."));
}
});
connect(m_ui.m_btnTestSetup, &QPushButton::clicked, this, &FormEditInoreaderAccount::testSetup);
connect(m_ui.m_buttonBox, &QDialogButtonBox::accepted, this, &FormEditInoreaderAccount::onClickedOk);
connect(m_ui.m_buttonBox, &QDialogButtonBox::rejected, this, &FormEditInoreaderAccount::onClickedCancel);
@ -63,6 +72,9 @@ FormEditInoreaderAccount::FormEditInoreaderAccount(QWidget* parent) : QDialog(pa
tr("There is error. %1").arg(err),
tr("There was error during testing."));
});
m_ui.m_spinLimitMessages->setValue(INOREADER_DEFAULT_BATCH_SIZE);
m_ui.m_spinLimitMessages->setMinimum(INOREADER_UNLIMITED_BATCH_SIZE);
}
FormEditInoreaderAccount::~FormEditInoreaderAccount() {}
@ -91,10 +103,7 @@ void FormEditInoreaderAccount::onClickedOk() {
editing_account = false;
}
if (m_editableRoot->network()->userName().isEmpty()) {
m_editableRoot->network()->setUsername(tr("uknown"));
}
m_editableRoot->network()->setUsername(m_ui.m_txtUsername->lineEdit()->text());
m_editableRoot->network()->setBatchSize(m_ui.m_spinLimitMessages->value());
m_editableRoot->saveAccountDataToDatabase();
accept();
@ -114,3 +123,11 @@ InoreaderServiceRoot* FormEditInoreaderAccount::execForCreate() {
exec();
return m_editableRoot;
}
void FormEditInoreaderAccount::execForEdit(InoreaderServiceRoot* existing_root) {
setWindowTitle(tr("Edit existing Inoreader account"));
m_editableRoot = existing_root;
m_ui.m_txtUsername->lineEdit()->setText(existing_root->network()->userName());
m_ui.m_spinLimitMessages->setValue(existing_root->network()->batchSize());
exec();
}

View File

@ -40,6 +40,8 @@ class FormEditInoreaderAccount : public QDialog {
InoreaderServiceRoot* execForCreate();
void execForEdit(InoreaderServiceRoot* existing_root);
private slots:
void testSetup();
void onClickedOk();

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>180</height>
<width>377</width>
<height>211</height>
</rect>
</property>
<property name="windowTitle">
@ -15,35 +15,59 @@
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<widget class="QLabel" name="m_lblUsername">
<property name="text">
<string>Only download newest X messages per feed</string>
</property>
</widget>
</item>
<item row="0" 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>
<string>Username</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Only download newest X messages per feed</string>
</property>
</widget>
</item>
<item row="0" 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>
</layout>
</item>
<item row="3" 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>120</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" colspan="2">
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QPushButton" name="m_btnTestSetup">
@ -67,7 +91,7 @@
</item>
</layout>
</item>
<item row="3" column="0" colspan="2">
<item row="4" column="0" colspan="2">
<widget class="QDialogButtonBox" name="m_buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -77,18 +101,8 @@
</property>
</widget>
</item>
<item row="2" 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>90</height>
</size>
</property>
</spacer>
<item row="0" column="1">
<widget class="LineEditWithStatus" name="m_txtUsername" native="true"/>
</item>
</layout>
</widget>
@ -99,6 +113,12 @@
<header>labelwithstatus.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>LineEditWithStatus</class>
<extends>QWidget</extends>
<header>lineeditwithstatus.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>m_spinLimitMessages</tabstop>

View File

@ -21,6 +21,7 @@
#include "miscellaneous/application.h"
#include "miscellaneous/databasequeries.h"
#include "services/inoreader/gui/formeditinoreaderaccount.h"
#include "services/inoreader/inoreaderentrypoint.h"
#include "services/inoreader/network/inoreadernetworkfactory.h"
@ -69,6 +70,17 @@ void InoreaderServiceRoot::saveAccountDataToDatabase() {
}
}
bool InoreaderServiceRoot::canBeEdited() const {
return true;
}
bool InoreaderServiceRoot::editViaGui() {
FormEditInoreaderAccount form_pointer(qApp->mainFormWidget());
form_pointer.execForEdit(this);
return true;
}
bool InoreaderServiceRoot::supportsFeedAdding() const {
return true;
}

View File

@ -36,6 +36,8 @@ class InoreaderServiceRoot : public ServiceRoot {
void setNetwork(InoreaderNetworkFactory* network);
InoreaderNetworkFactory* network() const;
bool canBeEdited() const;
bool editViaGui();
bool supportsFeedAdding() const;
bool supportsCategoryAdding() const;
void start(bool freshly_activated);