@@ -61,39 +61,9 @@ void RssDownloadRuleList::saveRulesToStorage()
6161void RssDownloadRuleList::loadRulesFromStorage ()
6262{
6363 QIniSettings qBTRSS (" qBittorrent" , " qBittorrent-rss" );
64- if (qBTRSS.contains (" feed_filters" )) {
65- importFeedsInOldFormat (qBTRSS.value (" feed_filters" ).toHash ());
66- // Remove outdated rules
67- qBTRSS.remove (" feed_filters" );
68- // Save to new format
69- saveRulesToStorage ();
70- return ;
71- }
72- // Load from new format
7364 loadRulesFromVariantHash (qBTRSS.value (" download_rules" ).toHash ());
7465}
7566
76- void RssDownloadRuleList::importFeedsInOldFormat (const QHash<QString, QVariant> &rules)
77- {
78- foreach (const QString &feed_url, rules.keys ()) {
79- importFeedRulesInOldFormat (feed_url, rules.value (feed_url).toHash ());
80- }
81- }
82-
83- void RssDownloadRuleList::importFeedRulesInOldFormat (const QString &feed_url, const QHash<QString, QVariant> &rules)
84- {
85- foreach (const QString &rule_name, rules.keys ()) {
86- RssDownloadRulePtr rule = RssDownloadRule::fromOldFormat (rules.value (rule_name).toHash (), feed_url, rule_name);
87- if (!rule) continue ;
88- // Check for rule name clash
89- while (m_rules.contains (rule->name ())) {
90- rule->setName (rule->name ()+" _" );
91- }
92- // Add the rule to the list
93- saveRule (rule);
94- }
95- }
96-
9767QVariantHash RssDownloadRuleList::toVariantHash () const
9868{
9969 QVariantHash ret;
@@ -105,11 +75,10 @@ QVariantHash RssDownloadRuleList::toVariantHash() const
10575
10676void RssDownloadRuleList::loadRulesFromVariantHash (const QVariantHash &h)
10777{
108- foreach ( const QVariant& v, h.values () ) {
109- RssDownloadRulePtr rule = RssDownloadRule::fromNewFormat (v .toHash ());
110- if (rule && !rule->name ().isEmpty ()) {
78+ for (QVariantHash::ConstIterator it = h.begin (); it != h. end (); it++ ) {
79+ RssDownloadRulePtr rule = RssDownloadRule::fromVariantHash (it. value () .toHash ());
80+ if (rule && !rule->name ().isEmpty ())
11181 saveRule (rule);
112- }
11382 }
11483}
11584
@@ -182,30 +151,18 @@ bool RssDownloadRuleList::unserialize(const QString &path)
182151 QFile f (path);
183152 if (f.open (QIODevice::ReadOnly)) {
184153 QDataStream in (&f);
185- if (path.endsWith (" .filters" , Qt::CaseInsensitive)) {
186- // Old format (< 2.5.0)
187- qDebug (" Old serialization format detected, processing..." );
188- in.setVersion (QDataStream::Qt_4_3);
189- QVariantHash tmp;
190- in >> tmp;
191- f.close ();
192- if (tmp.isEmpty ()) return false ;
193- qDebug (" Processing was successful!" );
194- // Unfortunately the feed_url is lost
195- importFeedRulesInOldFormat (" " , tmp);
196- } else {
197- qDebug (" New serialization format detected, processing..." );
198- in.setVersion (QDataStream::Qt_4_5);
199- QVariantHash tmp;
200- in >> tmp;
201- f.close ();
202- if (tmp.isEmpty ()) return false ;
203- qDebug (" Processing was successful!" );
204- loadRulesFromVariantHash (tmp);
205- }
154+ in.setVersion (QDataStream::Qt_4_5);
155+ QVariantHash tmp;
156+ in >> tmp;
157+ f.close ();
158+ if (tmp.isEmpty ())
159+ return false ;
160+ qDebug (" Processing was successful!" );
161+ loadRulesFromVariantHash (tmp);
206162 return true ;
163+ } else {
164+ qDebug (" Error: could not open file at %s" , qPrintable (path));
165+ return false ;
207166 }
208- qDebug (" Error: could not open file at %s" , qPrintable (path));
209- return false ;
210167}
211168
0 commit comments