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

Delta Between Two Patch Sets: src/plugin/PluginUserSettings.cpp

Issue 5979857238360064: Issues #1163, #1173 - refactor CPluginUserSettings (Closed)
Left Patch Set: rebased to current tip Created Feb. 2, 2015, 2:28 p.m.
Right Patch Set: rebase + add one final space character Created Feb. 23, 2015, 1:37 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/plugin/PluginUserSettings.h ('k') | test/plugin/UserSettingsTest.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 // ENTRY POINT 82 // ENTRY POINT
83 STDMETHODIMP CPluginUserSettings::QueryInterface(REFIID riid, void **ppvObj) 83 STDMETHODIMP CPluginUserSettings::QueryInterface(REFIID riid, void **ppvObj)
84 { 84 {
85 if (!ppvObj) 85 if (!ppvObj)
86 { 86 {
87 return E_POINTER; 87 return E_POINTER;
88 } 88 }
89 if (riid == IID_IUnknown || riid == IID_IDispatch) // GUID comparison does not throw 89 if (riid == IID_IUnknown || riid == IID_IDispatch) // GUID comparison does not throw
90 { 90 {
91 *ppvObj = static_cast<void *>(this); 91 *ppvObj = static_cast<void*>(this);
92 return S_OK; 92 return S_OK;
93 } 93 }
94 return E_NOINTERFACE; 94 return E_NOINTERFACE;
95 } 95 }
96 96
97 /** 97 /**
98 * \par Limitation 98 * \par Limitation
99 * CPluginUserSettings is not allocated on the heap. 99 * CPluginUserSettings is not allocated on the heap.
100 * It appears only as a member variable in CPluginTabBase. 100 * It appears only as a member variable in CPluginTabBase.
101 * 'AddRef' and 'Release' don't need reference counting because they don't pre sent COM factories. 101 * 'AddRef' and 'Release' don't need reference counting because they don't pre sent COM factories.
(...skipping 29 matching lines...) Expand all
131 { 131 {
132 if (!name || !id) 132 if (!name || !id)
133 { 133 {
134 return E_POINTER; 134 return E_POINTER;
135 } 135 }
136 if (count != 1) 136 if (count != 1)
137 { 137 {
138 return E_FAIL; 138 return E_FAIL;
139 } 139 }
140 auto item = methodIndex.find(*name); // unordered_map::find is not declared noexcept 140 auto item = methodIndex.find(*name); // unordered_map::find is not declared noexcept
141 if (item==methodIndex.end()) 141 if (item == methodIndex.end())
142 { 142 {
143 return DISP_E_UNKNOWNNAME; 143 return DISP_E_UNKNOWNNAME;
144 } 144 }
145 *id = item->second; 145 *id = item->second;
146 } 146 }
147 catch (...) 147 catch (...)
148 { 148 {
149 return E_FAIL; 149 return E_FAIL;
150 } 150 }
151 return S_OK; 151 return S_OK;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 if (pDispparams->cArgs != 1) 214 if (pDispparams->cArgs != 1)
215 { 215 {
216 return DISP_E_BADPARAMCOUNT; 216 return DISP_E_BADPARAMCOUNT;
217 } 217 }
218 if (pDispparams->rgvarg[0].vt != VT_I4) 218 if (pDispparams->rgvarg[0].vt != VT_I4)
219 { 219 {
220 return DISP_E_TYPEMISMATCH; 220 return DISP_E_TYPEMISMATCH;
221 } 221 }
222 if (pVarResult) 222 if (pVarResult)
223 { 223 {
224 int indx = pDispparams->rgvarg[0].lVal; 224 int index = pDispparams->rgvarg[0].lVal;
225 225
226 std::map<CString, CString> languageTitleList = settings->GetFilterLang uageTitleList(); 226 std::map<CString, CString> languageTitleList = settings->GetFilterLang uageTitleList();
227 227
228 if (indx < 0 || indx >= (int)languageTitleList.size()) 228 if (index < 0 || index >= static_cast<int>(languageTitleList.size()) )
229 return DISP_E_EXCEPTION; 229 return DISP_E_EXCEPTION;
230 230
231 CString language; 231 CString language;
232 232
233 int curIndx = 0; 233 int loopIndex = 0;
234 for(std::map<CString, CString>::const_iterator it = languageTitleList. begin(); it != languageTitleList.end(); ++it) 234 for (std::map<CString, CString>::const_iterator it = languageTitleList .begin(); it != languageTitleList.end(); ++it)
235 { 235 {
236 if (curIndx == indx) 236 if (loopIndex == index)
237 { 237 {
238 language = it->first; 238 language = it->first;
239 break; 239 break;
240 } 240 }
241 curIndx++; 241 ++loopIndex;
242 } 242 }
243 243
244 pVarResult->vt = VT_BSTR; 244 pVarResult->vt = VT_BSTR;
245 pVarResult->bstrVal = SysAllocString(language); 245 pVarResult->bstrVal = SysAllocString(language);
246 } 246 }
247 } 247 }
248 break; 248 break;
249 case dispatchID_GetLanguageTitleByIndex: 249 case dispatchID_GetLanguageTitleByIndex:
250 { 250 {
251 if (pDispparams->cArgs != 1) 251 if (pDispparams->cArgs != 1)
252 { 252 {
253 return DISP_E_BADPARAMCOUNT; 253 return DISP_E_BADPARAMCOUNT;
254 } 254 }
255 if (pDispparams->rgvarg[0].vt != VT_I4) 255 if (pDispparams->rgvarg[0].vt != VT_I4)
256 { 256 {
257 return DISP_E_TYPEMISMATCH; 257 return DISP_E_TYPEMISMATCH;
258 } 258 }
259 if (pVarResult) 259 if (pVarResult)
260 { 260 {
261 int indx = pDispparams->rgvarg[0].lVal; 261 int index = pDispparams->rgvarg[0].lVal;
262 262
263 std::map<CString, CString> languageTitleList = settings->GetFilterLang uageTitleList(); 263 std::map<CString, CString> languageTitleList = settings->GetFilterLang uageTitleList();
264 264
265 if (indx < 0 || indx >= (int)languageTitleList.size()) 265 if (index < 0 || index >= static_cast<int>(languageTitleList.size()) )
266 return DISP_E_EXCEPTION; 266 return DISP_E_EXCEPTION;
267 267
268 CString languageTitle; 268 CString languageTitle;
269 269
270 int curIndx = 0; 270 int loopIndex = 0;
271 for(std::map<CString, CString>::const_iterator it = languageTitleList. begin(); it != languageTitleList.end(); ++it) 271 for (std::map<CString, CString>::const_iterator it = languageTitleList .begin(); it != languageTitleList.end(); ++it)
272 { 272 {
273 if (curIndx == indx) 273 if (loopIndex == index)
274 { 274 {
275 languageTitle = it->second; 275 languageTitle = it->second;
276 break; 276 break;
277 } 277 }
278 curIndx++; 278 loopIndex++;
279 } 279 }
280 280
281 pVarResult->vt = VT_BSTR; 281 pVarResult->vt = VT_BSTR;
282 pVarResult->bstrVal = SysAllocString(languageTitle); 282 pVarResult->bstrVal = SysAllocString(languageTitle);
283 } 283 }
284 } 284 }
285 break; 285 break;
286 case dispatchID_SetLanguage: 286 case dispatchID_SetLanguage:
287 { 287 {
288 if (pDispparams->cArgs != 1) 288 if (pDispparams->cArgs != 1)
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 settings->RemoveWhiteListedDomain((BSTR)domain); 367 settings->RemoveWhiteListedDomain((BSTR)domain);
368 } 368 }
369 } 369 }
370 break; 370 break;
371 case dispatchID_GetAppLocale: 371 case dispatchID_GetAppLocale:
372 { 372 {
373 if (pDispparams->cArgs != 0) 373 if (pDispparams->cArgs != 0)
374 { 374 {
375 return DISP_E_BADPARAMCOUNT; 375 return DISP_E_BADPARAMCOUNT;
376 } 376 }
377 pVarResult->vt = VT_BSTR; 377 if (pVarResult)
378 pVarResult->bstrVal = SysAllocString(settings->GetAppLocale()); 378 {
379 pVarResult->vt = VT_BSTR;
380 pVarResult->bstrVal = SysAllocString(settings->GetAppLocale());
381 }
379 } 382 }
380 break; 383 break;
381 case dispatchID_GetDocumentationLink: 384 case dispatchID_GetDocumentationLink:
382 { 385 {
383 if (pDispparams->cArgs != 0) 386 if (pDispparams->cArgs != 0)
384 { 387 {
385 return DISP_E_BADPARAMCOUNT; 388 return DISP_E_BADPARAMCOUNT;
386 } 389 }
387 pVarResult->vt = VT_BSTR; 390 if (pVarResult)
388 pVarResult->bstrVal = SysAllocString(settings->GetDocumentationLink()); 391 {
392 pVarResult->vt = VT_BSTR;
393 pVarResult->bstrVal = SysAllocString(settings->GetDocumentationLink()) ;
394 }
389 } 395 }
390 break; 396 break;
391 case dispatchID_IsAcceptableAdsEnabled: 397 case dispatchID_IsAcceptableAdsEnabled:
392 { 398 {
393 if (pDispparams->cArgs != 0) 399 if (pDispparams->cArgs != 0)
394 { 400 {
395 return DISP_E_BADPARAMCOUNT; 401 return DISP_E_BADPARAMCOUNT;
396 } 402 }
397 pVarResult->vt = VT_BOOL; 403 if (pVarResult)
398 pVarResult->boolVal = CPluginClient::GetInstance()->IsAcceptableAdsEnabl ed() ? VARIANT_TRUE : VARIANT_FALSE; 404 {
405 pVarResult->vt = VT_BOOL;
406 pVarResult->boolVal = CPluginClient::GetInstance()->IsAcceptableAdsEna bled() ? VARIANT_TRUE : VARIANT_FALSE;
407 }
399 } 408 }
400 break; 409 break;
401 case dispatchID_SetAcceptableAdsEnabled: 410 case dispatchID_SetAcceptableAdsEnabled:
402 { 411 {
403 if (pDispparams->cArgs != 1) 412 if (pDispparams->cArgs != 1)
404 { 413 {
405 return DISP_E_BADPARAMCOUNT; 414 return DISP_E_BADPARAMCOUNT;
406 } 415 }
407 if (pDispparams->rgvarg[0].vt != VT_BOOL) 416 if (pDispparams->rgvarg[0].vt != VT_BOOL)
408 { 417 {
(...skipping 10 matching lines...) Expand all
419 client->RemoveSubscription(client->GetPref(L"subscriptions_exceptionsu rl", L"")); 428 client->RemoveSubscription(client->GetPref(L"subscriptions_exceptionsu rl", L""));
420 } 429 }
421 } 430 }
422 break; 431 break;
423 case dispatchID_IsUpdate: 432 case dispatchID_IsUpdate:
424 { 433 {
425 if (pDispparams->cArgs != 0) 434 if (pDispparams->cArgs != 0)
426 { 435 {
427 return DISP_E_BADPARAMCOUNT; 436 return DISP_E_BADPARAMCOUNT;
428 } 437 }
429 pVarResult->vt = VT_BOOL; 438 if (pVarResult)
430 pVarResult->boolVal = CPluginClient::GetInstance()->GetPref(L"displayUpd atePage", false) ? VARIANT_TRUE : VARIANT_FALSE; 439 {
440 pVarResult->vt = VT_BOOL;
441 pVarResult->boolVal = CPluginClient::GetInstance()->GetPref(L"displayU pdatePage", false) ? VARIANT_TRUE : VARIANT_FALSE;
442 }
431 } 443 }
432 break; 444 break;
433 default: 445 default:
434 return DISP_E_MEMBERNOTFOUND; 446 return DISP_E_MEMBERNOTFOUND;
435 break; 447 break;
436 } 448 }
437 } 449 }
438 catch(...) 450 catch (...)
439 { 451 {
440 return E_FAIL; 452 return E_FAIL;
441 } 453 }
442 return S_OK; 454 return S_OK;
443 } 455 }
444
LEFTRIGHT

Powered by Google App Engine
This is Rietveld