Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move old RSS items to separate config file. Closes #6167. #6175

Merged
merged 1 commit into from
Jan 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Application> app(new Application(appId, argc, argv));
Expand Down
18 changes: 17 additions & 1 deletion src/app/upgrade.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ bool upgrade(bool ask = true)
return true;
}


#ifdef Q_OS_MAC
void migratePlistToIni(const QString &application)
{
Expand Down Expand Up @@ -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<QString, QVariant> allOldItems = qBTRSSLegacy.value("old_items", QHash<QString, QVariant>()).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
16 changes: 9 additions & 7 deletions src/base/rss/rssfeed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,24 @@ 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();
ArticleHash::ConstIterator itend = m_articles.end();
for (; it != itend; ++it)
oldItems << it.value()->toHash();
qDebug("Saving %d old items for feed %s", oldItems.size(), qPrintable(displayName()));
QHash<QString, QVariant> allOldItems = qBTRSS.value("old_items", QHash<QString, QVariant>()).toHash();
QHash<QString, QVariant> allOldItems = qBTRSSFeeds.value("old_items", QHash<QString, QVariant>()).toHash();
allOldItems[m_url] = oldItems;
qBTRSS.setValue("old_items", allOldItems);
qBTRSSFeeds.setValue("old_items", allOldItems);
}

void Feed::loadItemsFromDisk()
{
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
QHash<QString, QVariant> allOldItems = qBTRSS.value("old_items", QHash<QString, QVariant>()).toHash();
QIniSettings qBTRSSFeeds("qBittorrent", "qBittorrent-rss-feeds");
QHash<QString, QVariant> allOldItems = qBTRSSFeeds.value("old_items", QHash<QString, QVariant>()).toHash();

const QVariantList oldItems = allOldItems.value(m_url, QVariantList()).toList();
qDebug("Loading %d old items for feed %s", oldItems.size(), qPrintable(displayName()));

Expand Down Expand Up @@ -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);
}
}

Expand Down