greader now supports feed adding, modifying and deleting

This commit is contained in:
Martin Rotter 2023-11-14 08:34:41 +01:00
parent 4f8b4c1e6b
commit 854f6ea92e
5 changed files with 59 additions and 64 deletions

View file

@ -71,7 +71,7 @@ set(APP_AUTHOR "Martin Rotter")
set(APP_COPYRIGHT "\\251 2011-${YEAR} ${APP_AUTHOR}")
set(APP_REVERSE_NAME "io.github.martinrotter.rssguard")
set(APP_DONATE_URL "https://github.com/sponsors/martinrotter")
set(APP_VERSION "4.5.4")
set(APP_VERSION "4.5.5")
set(APP_URL "https://github.com/martinrotter/rssguard")
set(APP_URL_DOCUMENTATION "https://rssguard.readthedocs.io")

View file

@ -2062,33 +2062,17 @@ QtWebEngine cache folder -&gt; &quot;%7&quot;</source>
<context>
<name>FormGreaderFeedDetails</name>
<message>
<location filename="../src/librssguard/services/greader/gui/formgreaderfeeddetails.cpp" line="40"/>
<source>Feed NOT updated</source>
<location filename="../src/librssguard/services/greader/gui/formgreaderfeeddetails.cpp" line="51"/>
<source>Feed NOT updated or added</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/librssguard/services/greader/gui/formgreaderfeeddetails.cpp" line="41"/>
<location filename="../src/librssguard/services/greader/gui/formgreaderfeeddetails.cpp" line="73"/>
<location filename="../src/librssguard/services/greader/gui/formgreaderfeeddetails.cpp" line="52"/>
<source>Error: %1</source>
<translation type="unfinished">Error: %1</translation>
</message>
<message>
<location filename="../src/librssguard/services/greader/gui/formgreaderfeeddetails.cpp" line="65"/>
<source>Feed added</source>
<translation type="unfinished">Feed added</translation>
</message>
<message>
<location filename="../src/librssguard/services/greader/gui/formgreaderfeeddetails.cpp" line="66"/>
<source>Feed was added, obtaining new tree of feeds now.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/librssguard/services/greader/gui/formgreaderfeeddetails.cpp" line="72"/>
<source>Feed NOT added</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/librssguard/services/greader/gui/formgreaderfeeddetails.cpp" line="86"/>
<location filename="../src/librssguard/services/greader/gui/formgreaderfeeddetails.cpp" line="83"/>
<source>General</source>
<translation type="unfinished">General</translation>
</message>

View file

@ -81,6 +81,7 @@ bool BaseToastNotification::eventFilter(QObject* watched, QEvent* event) {
if (event->type() == QEvent::Type::MouseButtonPress) {
if (dynamic_cast<QMouseEvent*>(event)->button() == Qt::MouseButton::RightButton) {
event->ignore();
close();
}
}

View file

@ -2,6 +2,7 @@
#include "services/greader/gui/formgreaderfeeddetails.h"
#include "database/databasequeries.h"
#include "exceptions/applicationexception.h"
#include "miscellaneous/application.h"
#include "services/greader/definitions.h"
@ -21,60 +22,66 @@ FormGreaderFeedDetails::FormGreaderFeedDetails(ServiceRoot* service_root,
m_urlToProcess(url) {}
void FormGreaderFeedDetails::apply() {
if (!m_creatingNew) {
if (!m_isBatchEdit) {
GreaderFeed* fd = feed<GreaderFeed>();
RootItem* parent = m_feedDetails->ui.m_cmbParentCategory->currentData().value<RootItem*>();
const QString category_id = parent->kind() == RootItem::Kind::ServiceRoot ? QString() : parent->customId();
GreaderFeed* fd = feed<GreaderFeed>();
GreaderServiceRoot* root = qobject_cast<GreaderServiceRoot*>(m_serviceRoot);
RootItem* parent =
m_feedDetails != nullptr ? m_feedDetails->ui.m_cmbParentCategory->currentData().value<RootItem*>() : nullptr;
try {
fd->serviceRoot()->network()->subscriptionEdit(QSL(GREADER_API_EDIT_SUBSCRIPTION_MODIFY),
fd->customId(),
m_feedDetails->ui.m_txtTitle->lineEdit()->text(),
category_id,
{},
m_serviceRoot->networkProxy());
}
catch (const ApplicationException& ex) {
qApp->showGuiMessage(Notification::Event::GeneralEvent,
{tr("Feed NOT updated"),
tr("Error: %1").arg(ex.message()),
QSystemTrayIcon::MessageIcon::Critical},
GuiMessageDestination(true, true));
}
}
// NOTE: We can only edit base properties, therefore
// base method is fine.
FormFeedDetails::apply();
}
else {
RootItem* parent = m_feedDetails->ui.m_cmbParentCategory->currentData().value<RootItem*>();
auto* root = qobject_cast<GreaderServiceRoot*>(parent->getParentServiceRoot());
const QString category_id = parent->kind() == RootItem::Kind::ServiceRoot ? QString() : parent->customId();
if (m_creatingNew || !m_isBatchEdit) {
QString feed_id = m_creatingNew ? (QSL("feed/") + m_feedDetails->ui.m_txtUrl->lineEdit()->text()) : fd->customId();
QString category_to_add = parent->kind() == RootItem::Kind::ServiceRoot ? QString() : parent->customId();
QString category_to_remove =
(!m_creatingNew && fd->parent()->customId() != category_to_add) ? fd->parent()->customId() : QString();
try {
root->network()->subscriptionEdit(QSL(GREADER_API_EDIT_SUBSCRIPTION_ADD),
QSL("feed/") + m_feedDetails->ui.m_txtUrl->lineEdit()->text(),
// Change online
root->network()->subscriptionEdit(m_creatingNew ? QSL(GREADER_API_EDIT_SUBSCRIPTION_ADD)
: QSL(GREADER_API_EDIT_SUBSCRIPTION_MODIFY),
feed_id,
m_feedDetails->ui.m_txtTitle->lineEdit()->text(),
category_id,
{},
QUrl::toPercentEncoding(category_to_add),
QUrl::toPercentEncoding(category_to_remove),
m_serviceRoot->networkProxy());
qApp->showGuiMessage(Notification::Event::GeneralEvent,
{tr("Feed added"),
tr("Feed was added, obtaining new tree of feeds now."),
QSystemTrayIcon::MessageIcon::Information});
QTimer::singleShot(300, root, &GreaderServiceRoot::syncIn);
if (m_creatingNew) {
qApp->showGuiMessage(Notification::Event::GeneralEvent,
{tr("Feed added"),
tr("Feed was added, refreshing feed tree..."),
QSystemTrayIcon::MessageIcon::Information});
QTimer::singleShot(300, root, &GreaderServiceRoot::syncIn);
// NOTE: Feed object was not used, delete.
fd->deleteLater();
return;
}
else {
fd->setTitle(m_feedDetails->ui.m_txtTitle->lineEdit()->text());
}
}
catch (const ApplicationException& ex) {
qApp->showGuiMessage(Notification::Event::GeneralEvent,
{tr("Feed NOT added"),
{tr("Feed NOT updated or added"),
tr("Error: %1").arg(ex.message()),
QSystemTrayIcon::MessageIcon::Critical},
GuiMessageDestination(true, true));
return;
}
}
FormFeedDetails::apply();
if (!m_isBatchEdit) {
try {
QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());
DatabaseQueries::createOverwriteFeed(database, fd, m_serviceRoot->accountId(), parent->id());
}
catch (const ApplicationException& ex) {
qFatal("Cannot save feed: '%s'.", qPrintable(ex.message()));
}
m_serviceRoot->requestItemReassignment(fd, parent);
m_serviceRoot->itemChanged({fd});
}
}
void FormGreaderFeedDetails::loadFeedData() {
@ -102,7 +109,10 @@ void FormGreaderFeedDetails::loadFeedData() {
}
else {
m_feedDetails->ui.m_txtTitle->lineEdit()->setText(fd->title());
m_feedDetails->ui.m_txtUrl->lineEdit()->setText(fd->source());
// NOTE: User cannot edit URL.
m_feedDetails->ui.m_lblUrl->hide();
m_feedDetails->ui.m_txtUrl->hide();
}
}
}

View file

@ -41,7 +41,7 @@
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<widget class="QLabel" name="m_lblUrl">
<property name="text">
<string>URL</string>
</property>
@ -57,7 +57,7 @@
<widget class="LineEditWithStatus" name="m_txtTitle" native="true"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="m_lblTitle">
<property name="text">
<string>Title</string>
</property>