Index: compiled/subscription/Subscription.cpp |
=================================================================== |
--- a/compiled/subscription/Subscription.cpp |
+++ b/compiled/subscription/Subscription.cpp |
@@ -17,16 +17,33 @@ Subscription::Subscription(Type type, co |
annotate_address(this, "Subscription"); |
} |
Subscription::~Subscription() |
{ |
knownSubscriptions.erase(mID); |
} |
+Filter* Subscription::FilterAt(unsigned index) |
+{ |
+ if (index >= mFilters.size()) |
+ return nullptr; |
+ |
+ FilterPtr result(mFilters[index]); |
+ return result.release(); |
+} |
+ |
+int Subscription::IndexOfFilter(Filter* filter) |
+{ |
+ for (unsigned i = 0; i < mFilters.size(); i++) |
+ if (mFilters[i] == filter) |
+ return i; |
+ return -1; |
+} |
+ |
OwnedString Subscription::Serialize() const |
{ |
OwnedString result(u"[Subscription]\nurl="_str); |
result.append(mID); |
result.append(u'\n'); |
if (!mTitle.empty()) |
{ |
result.append(u"title="_str); |
@@ -36,18 +53,27 @@ OwnedString Subscription::Serialize() co |
if (mDisabled) |
result.append(u"disabled=true\n"_str); |
return result; |
} |
OwnedString Subscription::SerializeFilters() const |
{ |
- // TODO |
- return OwnedString(); |
+ if (!mFilters.size()) |
+ return OwnedString(); |
+ |
+ OwnedString result(u"[Subscription filters]\n"_str); |
+ for (unsigned i = 0; i < mFilters.size(); i++) |
+ { |
+ // TODO: Escape [ characters |
Wladimir Palant
2017/03/16 18:31:23
Not fixing this at this point because the serializ
|
+ result.append(mFilters[i]->GetText()); |
+ result.append(u'\n'); |
+ } |
+ return result; |
} |
Subscription* Subscription::FromID(const String& id) |
{ |
if (id.empty()) |
{ |
// Generate a new random ID |
unsigned seed = knownSubscriptions.size(); |
@@ -68,19 +94,19 @@ Subscription* Subscription::FromID(const |
if (knownSubscription) |
{ |
knownSubscription->second->AddRef(); |
return knownSubscription->second; |
} |
SubscriptionPtr subscription; |
if (!id.empty() && id[0] == '~') |
- subscription = new UserDefinedSubscription(id); |
+ subscription = SubscriptionPtr(new UserDefinedSubscription(id), false); |
else |
- subscription = new DownloadableSubscription(id); |
+ subscription = SubscriptionPtr(new DownloadableSubscription(id), false); |
// This is a hack: we looked up the entry using id but create it using |
// subscription->mID. This works because both are equal at this point. |
// However, id refers to a temporary buffer which will go away. |
enter_context("Adding to known subscriptions"); |
knownSubscription.assign(subscription->mID, subscription.get()); |
exit_context(); |