From 854f6ea92ee39e30848f9cbb2788c4275221bb54 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Tue, 14 Nov 2023 08:34:41 +0100 Subject: [PATCH] greader now supports feed adding, modifying and deleting --- CMakeLists.txt | 2 +- localization/rssguard_en.ts | 24 +---- .../notifications/basetoastnotification.cpp | 1 + .../greader/gui/formgreaderfeeddetails.cpp | 92 ++++++++++--------- .../greader/gui/greaderfeeddetails.ui | 4 +- 5 files changed, 59 insertions(+), 64 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8af7ff39..9c38a8c16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") diff --git a/localization/rssguard_en.ts b/localization/rssguard_en.ts index f2ec6c2a7..d492a7598 100644 --- a/localization/rssguard_en.ts +++ b/localization/rssguard_en.ts @@ -2062,33 +2062,17 @@ QtWebEngine cache folder -> "%7" FormGreaderFeedDetails - - Feed NOT updated + + Feed NOT updated or added - - + Error: %1 Error: %1 - - Feed added - Feed added - - - - Feed was added, obtaining new tree of feeds now. - - - - - Feed NOT added - - - - + General General diff --git a/src/librssguard/gui/notifications/basetoastnotification.cpp b/src/librssguard/gui/notifications/basetoastnotification.cpp index c90ae1342..1eaf4fbed 100644 --- a/src/librssguard/gui/notifications/basetoastnotification.cpp +++ b/src/librssguard/gui/notifications/basetoastnotification.cpp @@ -81,6 +81,7 @@ bool BaseToastNotification::eventFilter(QObject* watched, QEvent* event) { if (event->type() == QEvent::Type::MouseButtonPress) { if (dynamic_cast(event)->button() == Qt::MouseButton::RightButton) { + event->ignore(); close(); } } diff --git a/src/librssguard/services/greader/gui/formgreaderfeeddetails.cpp b/src/librssguard/services/greader/gui/formgreaderfeeddetails.cpp index 0de207f44..5fcc83788 100644 --- a/src/librssguard/services/greader/gui/formgreaderfeeddetails.cpp +++ b/src/librssguard/services/greader/gui/formgreaderfeeddetails.cpp @@ -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(); - RootItem* parent = m_feedDetails->ui.m_cmbParentCategory->currentData().value(); - const QString category_id = parent->kind() == RootItem::Kind::ServiceRoot ? QString() : parent->customId(); + GreaderFeed* fd = feed(); + GreaderServiceRoot* root = qobject_cast(m_serviceRoot); + RootItem* parent = + m_feedDetails != nullptr ? m_feedDetails->ui.m_cmbParentCategory->currentData().value() : 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(); - auto* root = qobject_cast(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(); } } } diff --git a/src/librssguard/services/greader/gui/greaderfeeddetails.ui b/src/librssguard/services/greader/gui/greaderfeeddetails.ui index c65701c6a..d188a9eeb 100644 --- a/src/librssguard/services/greader/gui/greaderfeeddetails.ui +++ b/src/librssguard/services/greader/gui/greaderfeeddetails.ui @@ -41,7 +41,7 @@ - + URL @@ -57,7 +57,7 @@ - + Title