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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #include <iostream> | 18 #include <iostream> |
19 #include <sstream> | 19 #include <sstream> |
20 | 20 |
21 #include "FiltersCommand.h" | 21 #include "FiltersCommand.h" |
22 | 22 |
23 namespace | 23 namespace |
24 { | 24 { |
25 typedef std::vector<AdblockPlus::FilterPtr> FilterList; | 25 typedef std::vector<AdblockPlus::Filter> FilterList; |
26 | 26 |
27 void ShowFilterList(const FilterList& filters) | 27 void ShowFilterList(const FilterList& filters) |
28 { | 28 { |
29 for (FilterList::const_iterator it = filters.begin(); | 29 for (FilterList::const_iterator it = filters.begin(); |
30 it != filters.end(); it++) | 30 it != filters.end(); it++) |
31 { | 31 { |
32 std::string type; | 32 std::string type; |
33 switch ((*it)->GetType()) | 33 switch (it->GetType()) |
34 { | 34 { |
35 case AdblockPlus::Filter::TYPE_BLOCKING: | 35 case AdblockPlus::Filter::TYPE_BLOCKING: |
36 type = "blocking"; | 36 type = "blocking"; |
37 break; | 37 break; |
38 case AdblockPlus::Filter::TYPE_EXCEPTION: | 38 case AdblockPlus::Filter::TYPE_EXCEPTION: |
39 type = "exception"; | 39 type = "exception"; |
40 break; | 40 break; |
41 case AdblockPlus::Filter::TYPE_ELEMHIDE: | 41 case AdblockPlus::Filter::TYPE_ELEMHIDE: |
42 type = "elemhide"; | 42 type = "elemhide"; |
43 break; | 43 break; |
44 case AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION: | 44 case AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION: |
45 type = "elemhideexception"; | 45 type = "elemhideexception"; |
46 break; | 46 break; |
47 case AdblockPlus::Filter::TYPE_COMMENT: | 47 case AdblockPlus::Filter::TYPE_COMMENT: |
48 type = "comment"; | 48 type = "comment"; |
49 break; | 49 break; |
50 case AdblockPlus::Filter::TYPE_INVALID: | 50 case AdblockPlus::Filter::TYPE_INVALID: |
51 type = "invalid"; | 51 type = "invalid"; |
52 break; | 52 break; |
53 default: | 53 default: |
54 type = "(unknown type)"; | 54 type = "(unknown type)"; |
55 break; | 55 break; |
56 } | 56 } |
57 std::cout << (*it)->GetProperty("text").AsString() << " - " << | 57 std::cout << it->GetProperty("text").AsString() << " - " << |
58 type << std::endl; | 58 type << std::endl; |
59 } | 59 } |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 FiltersCommand::FiltersCommand(AdblockPlus::FilterEngine& filterEngine) | 63 FiltersCommand::FiltersCommand(AdblockPlus::FilterEngine& filterEngine) |
64 : Command("filters"), filterEngine(filterEngine) | 64 : Command("filters"), filterEngine(filterEngine) |
65 { | 65 { |
66 } | 66 } |
67 | 67 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 return name + " [add FILTER|remove FILTER]"; | 108 return name + " [add FILTER|remove FILTER]"; |
109 } | 109 } |
110 | 110 |
111 void FiltersCommand::ShowFilters() | 111 void FiltersCommand::ShowFilters() |
112 { | 112 { |
113 ShowFilterList(filterEngine.GetListedFilters()); | 113 ShowFilterList(filterEngine.GetListedFilters()); |
114 } | 114 } |
115 | 115 |
116 void FiltersCommand::AddFilter(const std::string& text) | 116 void FiltersCommand::AddFilter(const std::string& text) |
117 { | 117 { |
118 AdblockPlus::FilterPtr filter = filterEngine.GetFilter(text); | 118 AdblockPlus::Filter filter = filterEngine.GetFilter(text); |
119 filter->AddToList(); | 119 filter.AddToList(); |
120 } | 120 } |
121 | 121 |
122 void FiltersCommand::RemoveFilter(const std::string& text) | 122 void FiltersCommand::RemoveFilter(const std::string& text) |
123 { | 123 { |
124 AdblockPlus::FilterPtr filter = filterEngine.GetFilter(text); | 124 AdblockPlus::Filter filter = filterEngine.GetFilter(text); |
125 if (!filter->IsListed()) | 125 if (!filter.IsListed()) |
126 { | 126 { |
127 std::cout << "No such filter '" << text << "'" << std::endl; | 127 std::cout << "No such filter '" << text << "'" << std::endl; |
128 return; | 128 return; |
129 } | 129 } |
130 filter->RemoveFromList(); | 130 filter.RemoveFromList(); |
131 } | 131 } |
OLD | NEW |