Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: shell/src/SubscriptionsCommand.cpp

Issue 10100009: FilterEngine API improvements (Closed)
Patch Set: Replace GetElementHidingRules by a domain-specific GetElementHidingSelectors Created April 5, 2013, 12:22 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
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", "(no 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);
}

Powered by Google App Engine
This is Rietveld