fix false regex matching!

This commit is contained in:
Martin Rotter 2023-10-20 12:58:28 +02:00
parent 66017be265
commit 7699105e8f
3 changed files with 60 additions and 3 deletions

View File

@ -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<FormStandardFeedDetails> form_pointer(new FormStandardFeedDetails(m_serviceRoot,
targetParent(),
fd->source(),
qApp->mainFormWidget()));
form_pointer->addEditFeed<StandardFeed>();
if (form_pointer->addEditFeed<StandardFeed>() != 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;
}

View File

@ -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 {

View File

@ -169,7 +169,7 @@ QList<StandardFeed*> 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);