From cecff159a059d51283d99b4fc2aab45e79d9156a Mon Sep 17 00:00:00 2001 From: Tim Delaney Date: Sun, 6 Nov 2016 12:00:09 +1100 Subject: [PATCH] Move old RSS items to separate config file. Closes #6167. --HG-- branch : magao-dev --- src/app/main.cpp | 4 ++++ src/app/upgrade.h | 18 +++++++++++++++++- src/base/rss/rssfeed.cpp | 16 +++++++++------- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/app/main.cpp b/src/app/main.cpp index 0ace32ef3..d82c0e038 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -141,6 +141,10 @@ int main(int argc, char *argv[]) macMigratePlists(); #endif +#ifndef DISABLE_GUI + migrateRSS(); +#endif + // Create Application QString appId = QLatin1String("qBittorrent-") + Utils::Misc::getUserIDString(); QScopedPointer app(new Application(appId, argc, argv)); diff --git a/src/app/upgrade.h b/src/app/upgrade.h index 7b76ec241..376b63164 100644 --- a/src/app/upgrade.h +++ b/src/app/upgrade.h @@ -228,7 +228,6 @@ bool upgrade(bool ask = true) return true; } - #ifdef Q_OS_MAC void migratePlistToIni(const QString &application) { @@ -257,5 +256,22 @@ void macMigratePlists() } #endif // Q_OS_MAC +#ifndef DISABLE_GUI +void migrateRSS() +{ + // Copy old feed items to new file if needed + QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss-feeds"); + if (!qBTRSS.allKeys().isEmpty()) return; // We move the contents of RSS old_items only if inifile does not exist (is empty). + + QIniSettings qBTRSSLegacy("qBittorrent", "qBittorrent-rss"); + QHash allOldItems = qBTRSSLegacy.value("old_items", QHash()).toHash(); + + if (!allOldItems.empty()) { + qDebug("Moving %d old items for feeds to qBittorrent-rss-feeds", allOldItems.size()); + qBTRSS.setValue("old_items", allOldItems); + qBTRSSLegacy.remove("old_items"); + } +} +#endif #endif // UPGRADE_H diff --git a/src/base/rss/rssfeed.cpp b/src/base/rss/rssfeed.cpp index 91f9debe7..12437f308 100644 --- a/src/base/rss/rssfeed.cpp +++ b/src/base/rss/rssfeed.cpp @@ -99,7 +99,7 @@ void Feed::saveItemsToDisk() m_dirty = false; - QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); + QIniSettings qBTRSSFeeds("qBittorrent", "qBittorrent-rss-feeds"); QVariantList oldItems; ArticleHash::ConstIterator it = m_articles.begin(); @@ -107,15 +107,16 @@ void Feed::saveItemsToDisk() for (; it != itend; ++it) oldItems << it.value()->toHash(); qDebug("Saving %d old items for feed %s", oldItems.size(), qPrintable(displayName())); - QHash allOldItems = qBTRSS.value("old_items", QHash()).toHash(); + QHash allOldItems = qBTRSSFeeds.value("old_items", QHash()).toHash(); allOldItems[m_url] = oldItems; - qBTRSS.setValue("old_items", allOldItems); + qBTRSSFeeds.setValue("old_items", allOldItems); } void Feed::loadItemsFromDisk() { - QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); - QHash allOldItems = qBTRSS.value("old_items", QHash()).toHash(); + QIniSettings qBTRSSFeeds("qBittorrent", "qBittorrent-rss-feeds"); + QHash allOldItems = qBTRSSFeeds.value("old_items", QHash()).toHash(); + const QVariantList oldItems = allOldItems.value(m_url, QVariantList()).toList(); qDebug("Loading %d old items for feed %s", oldItems.size(), qPrintable(displayName())); @@ -203,10 +204,11 @@ void Feed::removeAllSettings() allFeedsFilters.remove(m_url); qBTRSS.setValue("feed_filters", allFeedsFilters); } - QVariantHash allOldItems = qBTRSS.value("old_items", QVariantHash()).toHash(); + QIniSettings qBTRSSFeeds("qBittorrent", "qBittorrent-rss-feeds"); + QVariantHash allOldItems = qBTRSSFeeds.value("old_items", QVariantHash()).toHash(); if (allOldItems.contains(m_url)) { allOldItems.remove(m_url); - qBTRSS.setValue("old_items", allOldItems); + qBTRSSFeeds.setValue("old_items", allOldItems); } }