| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 : mType(type), mID(id), mDisabled(false) | 32 : mType(type), mID(id), mDisabled(false) |
| 33 { | 33 { |
| 34 annotate_address(this, "Subscription"); | 34 annotate_address(this, "Subscription"); |
| 35 } | 35 } |
| 36 | 36 |
| 37 Subscription::~Subscription() | 37 Subscription::~Subscription() |
| 38 { | 38 { |
| 39 knownSubscriptions.erase(mID); | 39 knownSubscriptions.erase(mID); |
| 40 } | 40 } |
| 41 | 41 |
| 42 Filter* Subscription::FilterAt(unsigned index) |
| 43 { |
| 44 if (index >= mFilters.size()) |
| 45 return nullptr; |
| 46 |
| 47 FilterPtr result(mFilters[index]); |
| 48 return result.release(); |
| 49 } |
| 50 |
| 51 int Subscription::IndexOfFilter(Filter* filter) |
| 52 { |
| 53 for (unsigned i = 0; i < mFilters.size(); i++) |
| 54 if (mFilters[i] == filter) |
| 55 return i; |
| 56 return -1; |
| 57 } |
| 58 |
| 42 OwnedString Subscription::Serialize() const | 59 OwnedString Subscription::Serialize() const |
| 43 { | 60 { |
| 44 OwnedString result(u"[Subscription]\nurl="_str); | 61 OwnedString result(u"[Subscription]\nurl="_str); |
| 45 result.append(mID); | 62 result.append(mID); |
| 46 result.append(u'\n'); | 63 result.append(u'\n'); |
| 47 if (!mTitle.empty()) | 64 if (!mTitle.empty()) |
| 48 { | 65 { |
| 49 result.append(u"title="_str); | 66 result.append(u"title="_str); |
| 50 result.append(mTitle); | 67 result.append(mTitle); |
| 51 result.append(u'\n'); | 68 result.append(u'\n'); |
| 52 } | 69 } |
| 53 if (mDisabled) | 70 if (mDisabled) |
| 54 result.append(u"disabled=true\n"_str); | 71 result.append(u"disabled=true\n"_str); |
| 55 | 72 |
| 56 return result; | 73 return result; |
| 57 } | 74 } |
| 58 | 75 |
| 59 OwnedString Subscription::SerializeFilters() const | 76 OwnedString Subscription::SerializeFilters() const |
| 60 { | 77 { |
| 61 // TODO | 78 if (!mFilters.size()) |
| 62 return OwnedString(); | 79 return OwnedString(); |
| 80 |
| 81 OwnedString result(u"[Subscription filters]\n"_str); |
| 82 for (const auto& filter : mFilters) |
| 83 { |
| 84 // TODO: Escape [ characters |
| 85 result.append(filter->GetText()); |
| 86 result.append(u'\n'); |
| 87 } |
| 88 return result; |
| 63 } | 89 } |
| 64 | 90 |
| 65 Subscription* Subscription::FromID(const String& id) | 91 Subscription* Subscription::FromID(const String& id) |
| 66 { | 92 { |
| 67 if (id.empty()) | 93 if (id.empty()) |
| 68 { | 94 { |
| 69 // Generate a new random ID | 95 // Generate a new random ID |
| 70 unsigned int seed = knownSubscriptions.size(); | 96 unsigned int seed = knownSubscriptions.size(); |
| 71 OwnedString randomID(u"~user~000000"_str); | 97 OwnedString randomID(u"~user~000000"_str); |
| 72 do | 98 do |
| (...skipping 10 matching lines...) Expand all Loading... |
| 83 | 109 |
| 84 auto knownSubscription = knownSubscriptions.find(id); | 110 auto knownSubscription = knownSubscriptions.find(id); |
| 85 if (knownSubscription) | 111 if (knownSubscription) |
| 86 { | 112 { |
| 87 knownSubscription->second->AddRef(); | 113 knownSubscription->second->AddRef(); |
| 88 return knownSubscription->second; | 114 return knownSubscription->second; |
| 89 } | 115 } |
| 90 | 116 |
| 91 SubscriptionPtr subscription; | 117 SubscriptionPtr subscription; |
| 92 if (!id.empty() && id[0] == '~') | 118 if (!id.empty() && id[0] == '~') |
| 93 subscription = new UserDefinedSubscription(id); | 119 subscription = SubscriptionPtr(new UserDefinedSubscription(id), false); |
| 94 else | 120 else |
| 95 subscription = new DownloadableSubscription(id); | 121 subscription = SubscriptionPtr(new DownloadableSubscription(id), false); |
| 96 | 122 |
| 97 // This is a hack: we looked up the entry using id but create it using | 123 // This is a hack: we looked up the entry using id but create it using |
| 98 // subscription->mID. This works because both are equal at this point. | 124 // subscription->mID. This works because both are equal at this point. |
| 99 // However, id refers to a temporary buffer which will go away. | 125 // However, id refers to a temporary buffer which will go away. |
| 100 enter_context("Adding to known subscriptions"); | 126 enter_context("Adding to known subscriptions"); |
| 101 knownSubscription.assign(subscription->mID, subscription.get()); | 127 knownSubscription.assign(subscription->mID, subscription.get()); |
| 102 exit_context(); | 128 exit_context(); |
| 103 | 129 |
| 104 return subscription.release(); | 130 return subscription.release(); |
| 105 } | 131 } |
| OLD | NEW |