diff --git a/src/librssguard/services/standard/gui/formdiscoverfeeds.cpp b/src/librssguard/services/standard/gui/formdiscoverfeeds.cpp index 0d25d6ff3..ce2be1637 100644 --- a/src/librssguard/services/standard/gui/formdiscoverfeeds.cpp +++ b/src/librssguard/services/standard/gui/formdiscoverfeeds.cpp @@ -3,6 +3,7 @@ #include "services/standard/gui/formdiscoverfeeds.h" #include "3rd-party/boolinq/boolinq.h" +#include "database/databasequeries.h" #include "gui/guiutilities.h" #include "miscellaneous/application.h" #include "miscellaneous/iconfactory.h" @@ -201,15 +202,40 @@ void FormDiscoverFeeds::addSingleFeed() { return; } + auto idx = m_ui.m_tvFeeds->currentIndex(); + QScopedPointer form_pointer(new FormStandardFeedDetails(m_serviceRoot, targetParent(), fd->source(), qApp->mainFormWidget())); - form_pointer->addEditFeed(); + if (form_pointer->addEditFeed() != nullptr) { + // Feed was added, remove from list. + if (m_discoveredModel->removeItem(idx) != nullptr) { + // Feed was guessed by the dialog, we do not need this object. + fd->deleteLater(); + } + } } -void FormDiscoverFeeds::importSelectedFeeds() {} +void FormDiscoverFeeds::importSelectedFeeds() { + for (RootItem* it : m_discoveredModel->checkedItems()) { + Feed* std_feed = it->toFeed(); + RootItem* parent = targetParent(); + QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className()); + + try { + DatabaseQueries::createOverwriteFeed(database, std_feed, m_serviceRoot->accountId(), parent->id()); + + m_discoveredModel->removeItem(std_feed); + m_serviceRoot->requestItemReassignment(std_feed, parent); + m_serviceRoot->itemChanged({std_feed}); + } + catch (const ApplicationException& ex) { + qFatal("Cannot save feed: '%s'.", qPrintable(ex.message())); + } + } +} void FormDiscoverFeeds::onFeedSelectionChanged() { m_ui.m_btnAddIndividually->setEnabled(selectedFeed() != nullptr); @@ -280,3 +306,31 @@ void FormDiscoverFeeds::closeEvent(QCloseEvent* event) { QDialog::closeEvent(event); } + +RootItem* DiscoveredFeedsModel::removeItem(RootItem* it) { + auto idx = indexForItem(it); + + if (it == nullptr || it == m_rootItem || it->parent() == nullptr) { + return nullptr; + } + + beginRemoveRows(idx.parent(), idx.row(), idx.row()); + it->parent()->removeChild(it); + endRemoveRows(); + + return it; +} + +RootItem* DiscoveredFeedsModel::removeItem(const QModelIndex& idx) { + RootItem* it = itemForIndex(idx); + + if (it == nullptr || it == m_rootItem || it->parent() == nullptr) { + return nullptr; + } + + beginRemoveRows(idx.parent(), idx.row(), idx.row()); + it->parent()->removeChild(it); + endRemoveRows(); + + return it; +} diff --git a/src/librssguard/services/standard/gui/formdiscoverfeeds.h b/src/librssguard/services/standard/gui/formdiscoverfeeds.h index 69dc8a2af..2832a4ab4 100644 --- a/src/librssguard/services/standard/gui/formdiscoverfeeds.h +++ b/src/librssguard/services/standard/gui/formdiscoverfeeds.h @@ -25,6 +25,9 @@ class DiscoveredFeedsModel : public AccountCheckModel { virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; virtual int columnCount(const QModelIndex& parent) const; virtual QVariant data(const QModelIndex& index, int role) const; + + RootItem* removeItem(RootItem *it); + RootItem* removeItem(const QModelIndex& idx); }; class FormDiscoverFeeds : public QDialog { diff --git a/src/librssguard/services/standard/parsers/atomparser.cpp b/src/librssguard/services/standard/parsers/atomparser.cpp index 413726607..a89785d07 100644 --- a/src/librssguard/services/standard/parsers/atomparser.cpp +++ b/src/librssguard/services/standard/parsers/atomparser.cpp @@ -169,7 +169,7 @@ QList AtomParser::discoverFeeds(ServiceRoot* root, const QUrl& ur auto mtch = QRegularExpression(QSL(GITHUB_URL_REGEX)).match(my_url); - if (mtch.isValid()) { + if (mtch.isValid() && mtch.hasMatch()) { QStringList github_feeds = {QSL("releases.atom"), QSL("commits.atom"), QSL("tags.atom")}; QString gh_username = mtch.captured(1); QString gh_repo = mtch.captured(2);