| Index: src/plugin/AdblockPlusClient.cpp |
| =================================================================== |
| --- a/src/plugin/AdblockPlusClient.cpp |
| +++ b/src/plugin/AdblockPlusClient.cpp |
| @@ -4,13 +4,11 @@ |
| #include "PluginSystem.h" |
| #include "PluginFilter.h" |
| #include "PluginClientFactory.h" |
| -#include "PluginHttpRequest.h" |
| #include "PluginMutex.h" |
| #include "PluginClass.h" |
| #include "AdblockPlusClient.h" |
| -#include "../shared/Communication.h" |
| #include "../shared/Utils.h" |
| namespace |
| @@ -356,11 +354,9 @@ |
| } |
| } |
| -void CAdblockPlusClient::AddFilter(const std::wstring& text) |
| +// A helper method to reuse the code |
|
Felix Dahlke
2013/07/25 13:52:33
Ignoring this, since I commented on it in patch se
|
| +void CAdblockPlusClient::PostRequest(Communication::OutputBuffer request) |
| { |
| - Communication::OutputBuffer request; |
| - request << Communication::PROC_ADD_FILTER << ToUtf8String(text); |
| - |
| try |
| { |
| CallAdblockPlusEngineProcedure(request); |
| @@ -371,17 +367,118 @@ |
| } |
| } |
| +void CAdblockPlusClient::AddFilter(const std::wstring& text) |
| +{ |
| + Communication::OutputBuffer request; |
| + request << Communication::PROC_ADD_FILTER << ToUtf8String(text); |
| + PostRequest(request); |
| +} |
| + |
| void CAdblockPlusClient::RemoveFilter(const std::wstring& text) |
| { |
| Communication::OutputBuffer request; |
| request << Communication::PROC_REMOVE_FILTER << ToUtf8String(text); |
| + PostRequest(request); |
| +} |
| + |
| +void CAdblockPlusClient::SetPref(const std::wstring& name, const std::wstring& value) |
| +{ |
| + Communication::OutputBuffer request; |
| + request << Communication::PROC_SET_PREF << ToUtf8String(name) << ToUtf8String(value); |
| + PostRequest(request); |
| +} |
| + |
| +void CAdblockPlusClient::SetPref(const std::wstring& name, const int64_t & value) |
| +{ |
| + Communication::OutputBuffer request; |
| + request << Communication::PROC_SET_PREF << ToUtf8String(name) << value; |
| + PostRequest(request); |
| +} |
| + |
| +void CAdblockPlusClient::SetPref(const std::wstring& name, bool value) |
| +{ |
| + Communication::OutputBuffer request; |
| + request << Communication::PROC_SET_PREF << ToUtf8String(name) << value; |
| + PostRequest(request); |
| +} |
| + |
| +std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const wchar_t* defaultValue) |
| +{ |
| + return GetPref(name, std::wstring(defaultValue)); |
| +} |
| +std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const std::wstring& defaultValue) |
| +{ |
| + Communication::OutputBuffer request; |
| + request << Communication::PROC_GET_PREF << ToUtf8String(name); |
| try |
| { |
| - CallAdblockPlusEngineProcedure(request); |
| + Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request); |
| + bool success; |
| + response >> success; |
| + if (success) |
| + { |
| + std::string value; |
| + response >> value; |
| + return ToUtf16String(value); |
| + } |
| + else |
| + return defaultValue; |
| } |
| catch (const std::exception& e) |
| { |
| DEBUG_GENERAL(e.what()); |
| + return defaultValue; |
| } |
| } |
| + |
| +bool CAdblockPlusClient::GetPref(const std::wstring& name, bool defaultValue) |
| +{ |
| + Communication::OutputBuffer request; |
| + request << Communication::PROC_GET_PREF << ToUtf8String(name); |
| + |
| + try |
| + { |
| + Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request); |
| + bool success; |
| + response >> success; |
| + if (success) |
| + { |
| + bool value; |
| + response >> value; |
| + return value; |
| + } |
| + else |
| + return defaultValue; |
| + } |
| + catch (const std::exception& e) |
| + { |
| + DEBUG_GENERAL(e.what()); |
| + return defaultValue; |
| + } |
| +} |
| +int64_t CAdblockPlusClient::GetPref(const std::wstring& name, int64_t defaultValue) |
| +{ |
| + Communication::OutputBuffer request; |
| + request << Communication::PROC_GET_PREF << ToUtf8String(name); |
| + |
| + try |
| + { |
| + Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request); |
| + bool success; |
| + response >> success; |
| + if (success) |
| + { |
| + int64_t value; |
| + response >> value; |
| + return value; |
| + } |
| + else |
| + return defaultValue; |
| + } |
| + catch (const std::exception& e) |
| + { |
| + DEBUG_GENERAL(e.what()); |
| + return defaultValue; |
| + } |
| +} |