Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 17 matching lines...) Expand all Loading... | |
28 typedef std::vector<NotificationTypeString> NotificationTypes; | 28 typedef std::vector<NotificationTypeString> NotificationTypes; |
29 NotificationTypes InitNotificationTypes() | 29 NotificationTypes InitNotificationTypes() |
30 { | 30 { |
31 NotificationTypes retValue; | 31 NotificationTypes retValue; |
32 retValue.push_back(std::make_pair(NotificationType::NOTIFICATION_TYPE_QUESTI ON, "question")); | 32 retValue.push_back(std::make_pair(NotificationType::NOTIFICATION_TYPE_QUESTI ON, "question")); |
33 retValue.push_back(std::make_pair(NotificationType::NOTIFICATION_TYPE_CRITIC AL, "critical")); | 33 retValue.push_back(std::make_pair(NotificationType::NOTIFICATION_TYPE_CRITIC AL, "critical")); |
34 retValue.push_back(std::make_pair(NotificationType::NOTIFICATION_TYPE_INFORM ATION, "information")); | 34 retValue.push_back(std::make_pair(NotificationType::NOTIFICATION_TYPE_INFORM ATION, "information")); |
35 return retValue; | 35 return retValue; |
36 } | 36 } |
37 | 37 |
38 const NotificationTypes g_notificationTypes = InitNotificationTypes(); | 38 const NotificationTypes notificationTypes = InitNotificationTypes(); |
Felix Dahlke
2015/01/23 13:25:55
No hungarian notation please :) https://adblockplu
sergei
2015/01/23 14:48:19
fixed, although it's not hungarian notation
| |
39 | 39 |
40 NotificationType StringToNotificationType(const std::string& value) | 40 NotificationType StringToNotificationType(const std::string& value) |
41 { | 41 { |
42 struct IsSecondEqualToPredicate | 42 struct IsSecondEqualToPredicate |
43 { | 43 { |
44 std::string value; | 44 std::string value; |
45 bool operator()(const NotificationTypeString& pair) const | 45 bool operator()(const NotificationTypeString& pair) const |
46 { | 46 { |
47 return value == pair.second; | 47 return value == pair.second; |
48 } | 48 } |
49 } findBySecond = {value}; | 49 } findBySecond = {value}; |
50 NotificationTypes::const_iterator ci_notificationType = std::find_if( | 50 NotificationTypes::const_iterator notificationTypeIterator = std::find_if( |
Felix Dahlke
2015/01/23 13:25:55
Hungarian again :)
sergei
2015/01/23 14:48:19
fixed
| |
51 g_notificationTypes.begin(), g_notificationTypes.end(), findBySecond); | 51 notificationTypes.begin(), notificationTypes.end(), findBySecond); |
52 if (ci_notificationType == g_notificationTypes.end()) | 52 if (notificationTypeIterator == notificationTypes.end()) |
53 { | 53 { |
54 return NotificationType::NOTIFICATION_TYPE_INFORMATION; | 54 return NotificationType::NOTIFICATION_TYPE_INFORMATION; |
55 } | 55 } |
56 return ci_notificationType->first; | 56 return notificationTypeIterator->first; |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 Notification::Notification(const JsValuePtr& jsValue, PrivateCtrArg) | 60 Notification::Notification(const JsValuePtr& jsValue) |
61 : JsValue(jsValue) | 61 : JsValue(jsValue) |
62 { | 62 { |
63 } | 63 } |
64 | 64 |
65 NotificationType Notification::GetType() const | 65 NotificationType Notification::GetType() const |
66 { | 66 { |
67 return type; | 67 return type; |
68 } | 68 } |
69 | 69 |
70 const std::string& Notification::GetTitle() const | 70 const std::string& Notification::GetTitle() const |
71 { | 71 { |
72 return title; | 72 return title; |
73 } | 73 } |
74 | 74 |
75 const std::string& Notification::GetMessageString() const | 75 const std::string& Notification::GetMessageString() const |
76 { | 76 { |
77 return message; | 77 return message; |
78 } | 78 } |
79 | 79 |
80 void Notification::MarkAsShown() | 80 void Notification::MarkAsShown() |
81 { | 81 { |
82 JsValueList params; | 82 JsValueList params; |
83 params.push_back(GetProperty("id")); | 83 params.push_back(GetProperty("id")); |
84 jsEngine->Evaluate("API.markNotificationAsShown")->Call(params); | 84 jsEngine->Evaluate("API.markNotificationAsShown")->Call(params); |
85 } | 85 } |
86 | 86 |
87 NotificationPtr Notification::JsValueToNotification(const JsValuePtr& jsValue) | 87 NotificationPtr Notification::JsValueToNotification(const JsValuePtr& jsValue) |
Felix Dahlke
2015/01/23 13:25:55
Why not simply do this in the constructor, as Filt
| |
88 { | 88 { |
89 if(!jsValue || !jsValue->IsObject()) | 89 if (!jsValue || !jsValue->IsObject()) |
Felix Dahlke
2015/01/23 13:25:55
Single space before ( please.
sergei
2015/01/23 14:48:19
fixed
| |
90 { | 90 { |
91 return NotificationPtr(); | 91 return NotificationPtr(); |
92 } | 92 } |
93 | 93 |
94 NotificationPtr notification = std::tr1::make_shared<Notification>(jsValue, Pr ivateCtrArg()); | 94 NotificationPtr notification(new Notification(jsValue)); |
95 JsValuePtr jsType = notification->GetProperty("type"); | 95 JsValuePtr jsType = notification->GetProperty("type"); |
96 notification->type = StringToNotificationType(jsType ? jsType->AsString() : "" ); | 96 notification->type = StringToNotificationType(jsType ? jsType->AsString() : "" ); |
97 | 97 |
98 JsValueList params; | 98 JsValueList params; |
99 params.push_back(notification); | 99 params.push_back(notification); |
100 JsValuePtr func = notification->jsEngine->Evaluate("API.getNotificationTexts") ; | 100 JsValuePtr func = notification->jsEngine->Evaluate("API.getNotificationTexts") ; |
101 JsValuePtr jsTexts = func->Call(params); | 101 JsValuePtr jsTexts = func->Call(params); |
102 JsValuePtr jsTitle = jsTexts->GetProperty("title"); | 102 JsValuePtr jsTitle = jsTexts->GetProperty("title"); |
103 if (jsTitle->IsString()) | 103 if (jsTitle->IsString()) |
104 { | 104 { |
105 notification->title = jsTitle->AsString(); | 105 notification->title = jsTitle->AsString(); |
106 } | 106 } |
107 JsValuePtr jsMessage = jsTexts->GetProperty("message"); | 107 JsValuePtr jsMessage = jsTexts->GetProperty("message"); |
108 if (jsMessage->IsString()) | 108 if (jsMessage->IsString()) |
109 { | 109 { |
110 notification->message = jsMessage->AsString(); | 110 notification->message = jsMessage->AsString(); |
111 } | 111 } |
112 return notification; | 112 return notification; |
113 } | 113 } |
LEFT | RIGHT |