diff --git a/src/librssguard/database/databasequeries.cpp b/src/librssguard/database/databasequeries.cpp index 776aa88a3..f395b437e 100644 --- a/src/librssguard/database/databasequeries.cpp +++ b/src/librssguard/database/databasequeries.cpp @@ -1987,28 +1987,31 @@ void DatabaseQueries::createOverwriteCategory(const QSqlDatabase& db, Category* } } -void DatabaseQueries::createOverwriteFeed(const QSqlDatabase& db, Feed* feed, int account_id, int parent_id) { +void DatabaseQueries::createOverwriteFeed(const QSqlDatabase& db, Feed* feed, int account_id, int new_parent_id) { QSqlQuery q(db); + int next_sort_order; + + if ((feed->id() <= 0 && feed->sortOrder() < 0) || + (feed->parent() != nullptr && feed->parent()->id() != new_parent_id)) { + // We either insert completely new feed or we move feed + // to new parent. Get new viable sort order. + q.prepare(QSL("SELECT MAX(ordr) FROM Feeds WHERE account_id = :account_id AND category = :category;")); + q.bindValue(QSL(":account_id"), account_id); + q.bindValue(QSL(":category"), new_parent_id); + + if (!q.exec() || !q.next()) { + throw ApplicationException(q.lastError().text()); + } + + next_sort_order = (q.value(0).isNull() ? -1 : q.value(0).toInt()) + 1; + q.finish(); + } + else { + next_sort_order = feed->sortOrder(); + } if (feed->id() <= 0) { // We need to insert feed first. - if (feed->sortOrder() < 0) { - q.prepare(QSL("SELECT MAX(ordr) FROM Feeds WHERE account_id = :account_id AND category = :category;")); - q.bindValue(QSL(":account_id"), account_id); - q.bindValue(QSL(":category"), parent_id); - - if (!q.exec()) { - throw ApplicationException(q.lastError().text()); - } - - q.next(); - - int next_order = (q.value(0).isNull() ? -1 : q.value(0).toInt()) + 1; - - feed->setSortOrder(next_order); - q.finish(); - } - q.prepare(QSL("INSERT INTO " "Feeds (title, ordr, date_created, category, update_type, update_interval, account_id, custom_id) " "VALUES ('new', 0, 0, 0, 0, 1, %1, 'new');").arg(QString::number(account_id))); @@ -2024,9 +2027,18 @@ void DatabaseQueries::createOverwriteFeed(const QSqlDatabase& db, Feed* feed, in } } } + else if (feed->parent() != nullptr && feed->parent()->id() != new_parent_id) { + // Feed is moving between categories. + // 1. Move feed to bottom of current category. + // 2. Assign proper new sort order. + // + // NOTE: The feed will get reassigned to new parent usually after this method + // completes by the caller. + moveItem(feed, false, true, {}, db); + } - // TODO: pokus se kanál přesouvá mezi kategoriemi či rootem - // je třeba nejdříve kanál přesunout na dno a pak ho vložit do nové kategorie + // Restore to correct sort order. + feed->setSortOrder(next_sort_order); q.prepare("UPDATE Feeds " "SET title = :title, ordr = :ordr, description = :description, date_created = :date_created, " @@ -2038,7 +2050,7 @@ void DatabaseQueries::createOverwriteFeed(const QSqlDatabase& db, Feed* feed, in q.bindValue(QSL(":description"), feed->description()); q.bindValue(QSL(":date_created"), feed->creationDate().toMSecsSinceEpoch()); q.bindValue(QSL(":icon"), qApp->icons()->toByteArray(feed->icon())); - q.bindValue(QSL(":category"), parent_id); + q.bindValue(QSL(":category"), new_parent_id); q.bindValue(QSL(":source"), feed->source()); q.bindValue(QSL(":update_type"), int(feed->autoUpdateType())); q.bindValue(QSL(":update_interval"), feed->autoUpdateInitialInterval()); diff --git a/src/librssguard/database/databasequeries.h b/src/librssguard/database/databasequeries.h index 23840db34..17b6e4ab1 100644 --- a/src/librssguard/database/databasequeries.h +++ b/src/librssguard/database/databasequeries.h @@ -122,7 +122,7 @@ class DatabaseQueries { static bool cleanUnreadMessages(const QSqlDatabase& db, int account_id); static bool cleanFeeds(const QSqlDatabase& db, const QStringList& ids, bool clean_read_only, int account_id); static void storeAccountTree(const QSqlDatabase& db, RootItem* tree_root, int account_id); - static void createOverwriteFeed(const QSqlDatabase& db, Feed* feed, int account_id, int parent_id); + static void createOverwriteFeed(const QSqlDatabase& db, Feed* feed, int account_id, int new_parent_id); static void createOverwriteCategory(const QSqlDatabase& db, Category* category, int account_id, int parent_id); static bool deleteFeed(const QSqlDatabase& db, Feed* feed, int account_id); static bool deleteCategory(const QSqlDatabase& db, int id); diff --git a/src/librssguard/services/standard/standardfeed.cpp b/src/librssguard/services/standard/standardfeed.cpp index 1ab40953e..5bbaa5e15 100644 --- a/src/librssguard/services/standard/standardfeed.cpp +++ b/src/librssguard/services/standard/standardfeed.cpp @@ -196,6 +196,7 @@ void StandardFeed::fetchMetadataForItself() { setType(metadata->type()); setEncoding(metadata->encoding()); setIcon(metadata->icon()); + metadata->deleteLater(); QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className()); diff --git a/src/librssguard/services/standard/standardserviceroot.cpp b/src/librssguard/services/standard/standardserviceroot.cpp index 5754131bf..f9a2e6698 100644 --- a/src/librssguard/services/standard/standardserviceroot.cpp +++ b/src/librssguard/services/standard/standardserviceroot.cpp @@ -55,9 +55,9 @@ void StandardServiceRoot::start(bool freshly_activated) { if (freshly_activated && getSubTreeFeeds().isEmpty()) { // In other words, if there are no feeds or categories added. if (MsgBox::show(qApp->mainFormWidget(), QMessageBox::Question, QObject::tr("Load initial set of feeds"), - tr("This new account does not include any feeds. You can now add default set of feeds."), - tr("Do you want to load initial set of feeds?"), - QString(), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + tr("This new account does not include any feeds. You can now add default set of feeds."), + tr("Do you want to load initial set of feeds?"), + QString(), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { QString target_opml_file = APP_INITIAL_FEEDS_PATH + QDir::separator() + FEED_INITIAL_OPML_PATTERN; QString current_locale = qApp->localization()->loadedLanguage(); QString file_to_load; @@ -270,7 +270,7 @@ QList StandardServiceRoot::obtainNewMessages(Feed* feed, QList StandardServiceRoot::getContextMenuForFeed(StandardFeed* feed) { if (m_feedContextMenu.isEmpty()) { // Initialize. - auto* action_metadata = new QAction(qApp->icons()->fromTheme(QSL("emblem-downloads")), + auto* action_metadata = new QAction(qApp->icons()->fromTheme(QSL("download"), QSL("emblem-downloads")), tr("Fetch metadata"), this);