Index: shell/src/SubscriptionsCommand.cpp |
=================================================================== |
--- a/shell/src/SubscriptionsCommand.cpp |
+++ b/shell/src/SubscriptionsCommand.cpp |
@@ -1,22 +1,22 @@ |
#include <iostream> |
#include <sstream> |
#include "SubscriptionsCommand.h" |
namespace |
{ |
- typedef std::vector<AdblockPlus::Subscription> SubscriptionList; |
+ typedef std::vector<AdblockPlus::Subscription*> SubscriptionList; |
void ShowSubscriptionList(const SubscriptionList& subscriptions) |
{ |
for (SubscriptionList::const_iterator it = subscriptions.begin(); |
it != subscriptions.end(); it++) |
- std::cout << it->title << " - " << it->url << std::endl; |
+ std::cout << (*it)->GetProperty("title") << " - " << (*it)->GetProperty("url") << std::endl; |
} |
} |
SubscriptionsCommand::SubscriptionsCommand( |
AdblockPlus::FilterEngine& filterEngine) |
: Command("subscriptions"), filterEngine(filterEngine) |
{ |
} |
@@ -33,17 +33,17 @@ void SubscriptionsCommand::operator()(co |
} |
if (action == "add") |
{ |
std::string url; |
argumentStream >> url; |
std::string title; |
std::getline(argumentStream, title); |
- if (url.size() || title.size()) |
+ if (url.size()) |
AddSubscription(url, title); |
else |
ShowUsage(); |
} |
else if (action == "remove") |
{ |
std::string url; |
argumentStream >> url; |
@@ -62,46 +62,48 @@ void SubscriptionsCommand::operator()(co |
std::string SubscriptionsCommand::GetDescription() const |
{ |
return "List and manage subscriptions"; |
} |
std::string SubscriptionsCommand::GetUsage() const |
{ |
- return name + " [add URL TITLE|remove URL|update|fetch]"; |
+ return name + " [add URL [TITLE]|remove URL|update|fetch]"; |
} |
void SubscriptionsCommand::ShowSubscriptions() |
{ |
- ShowSubscriptionList(filterEngine.GetSubscriptions()); |
+ ShowSubscriptionList(filterEngine.GetListedSubscriptions()); |
} |
void SubscriptionsCommand::AddSubscription(const std::string& url, |
const std::string& title) |
{ |
- filterEngine.AddSubscription(AdblockPlus::Subscription(url, title)); |
+ AdblockPlus::Subscription& subscription = filterEngine.GetSubscription(url); |
+ if (title.size()) |
+ subscription.SetProperty("title", title); |
+ subscription.AddToList(); |
} |
void SubscriptionsCommand::RemoveSubscription(const std::string& url) |
{ |
- const AdblockPlus::Subscription* const subscription = |
- filterEngine.FindSubscription(url); |
- if (!subscription) |
+ AdblockPlus::Subscription& subscription = filterEngine.GetSubscription(url); |
+ if (!subscription.IsListed()) |
{ |
std::cout << "No subscription with URL '" << url << "'" << std::endl; |
return; |
} |
- filterEngine.RemoveSubscription(*subscription); |
+ subscription.RemoveFromList(); |
} |
void SubscriptionsCommand::UpdateSubscriptions() |
{ |
- const SubscriptionList& subscriptions = filterEngine.GetSubscriptions(); |
+ const SubscriptionList& subscriptions = filterEngine.GetListedSubscriptions(); |
for (SubscriptionList::const_iterator it = subscriptions.begin(); |
it != subscriptions.end(); it++) |
- filterEngine.UpdateSubscriptionFilters(*it); |
+ (*it)->UpdateFilters(); |
} |
void SubscriptionsCommand::FetchSubscriptions() |
{ |
- ShowSubscriptionList(filterEngine.FetchAvailableSubscriptions()); |
+ filterEngine.FetchAvailableSubscriptions(&ShowSubscriptionList); |
} |