OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 /** | 18 /** |
19 * @fileOverview Handles notifications. | 19 * @fileOverview Handles notifications. |
20 */ | 20 */ |
21 | 21 |
22 Cu.import("resource://gre/modules/Services.jsm"); | 22 Cu.import("resource://gre/modules/Services.jsm"); |
23 | 23 |
24 let {TimeLine} = require("timeline"); | 24 let {TimeLine} = require("timeline"); |
25 let {Prefs} = require("prefs"); | 25 let {Prefs} = require("prefs"); |
26 let {Downloader, Downloadable, MILLIS_IN_MINUTE, MILLIS_IN_HOUR, MILLIS_IN_DAY}
= require("downloader"); | 26 let {Downloader, Downloadable, MILLIS_IN_MINUTE, MILLIS_IN_HOUR, MILLIS_IN_DAY}
= require("downloader"); |
| 27 let {Utils} = require("utils"); |
27 | 28 |
28 let INITIAL_DELAY = 12 * MILLIS_IN_MINUTE; | 29 let INITIAL_DELAY = 12 * MILLIS_IN_MINUTE; |
29 let CHECK_INTERVAL = 1 * MILLIS_IN_HOUR; | 30 let CHECK_INTERVAL = 1 * MILLIS_IN_HOUR; |
30 let EXPIRATION_INTERVAL = 1 * MILLIS_IN_DAY; | 31 let EXPIRATION_INTERVAL = 1 * MILLIS_IN_DAY; |
31 | 32 |
32 function getNumericalSeverity(notification) | 33 function getNumericalSeverity(notification) |
33 { | 34 { |
34 let levels = {information: 0, critical: 1}; | 35 let levels = {information: 0, critical: 1}; |
35 return (notification.severity in levels ? levels[notification.severity] : leve
ls.information); | 36 return (notification.severity in levels ? levels[notification.severity] : leve
ls.information); |
36 } | 37 } |
37 | 38 |
38 function saveNotificationData() | 39 function saveNotificationData() |
39 { | 40 { |
40 // HACK: JSON values aren't saved unless they are assigned a different object. | 41 // HACK: JSON values aren't saved unless they are assigned a different object. |
41 Prefs.notificationdata = JSON.parse(JSON.stringify(Prefs.notificationdata)); | 42 Prefs.notificationdata = JSON.parse(JSON.stringify(Prefs.notificationdata)); |
42 } | 43 } |
43 | 44 |
| 45 function localize(translations, locale) |
| 46 { |
| 47 if (locale in translations) |
| 48 return translations[locale]; |
| 49 |
| 50 let languagePart = locale.substring(0, locale.indexOf("-")); |
| 51 if (languagePart && languagePart in translations) |
| 52 return translations[languagePart]; |
| 53 |
| 54 let defaultLocale = "en-US"; |
| 55 return translations[defaultLocale]; |
| 56 } |
| 57 |
44 /** | 58 /** |
45 * The object providing actual downloading functionality. | 59 * The object providing actual downloading functionality. |
46 * @type Downloader | 60 * @type Downloader |
47 */ | 61 */ |
48 let downloader = null; | 62 let downloader = null; |
49 | 63 |
50 /** | 64 /** |
51 * Regularly fetches notifications and decides which to show. | 65 * Regularly fetches notifications and decides which to show. |
52 * @class | 66 * @class |
53 */ | 67 */ |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 notificationToShow = notification; | 182 notificationToShow = notification; |
169 } | 183 } |
170 | 184 |
171 if (notificationToShow && "id" in notificationToShow) | 185 if (notificationToShow && "id" in notificationToShow) |
172 { | 186 { |
173 Prefs.notificationdata.shown.push(notificationToShow.id); | 187 Prefs.notificationdata.shown.push(notificationToShow.id); |
174 saveNotificationData(); | 188 saveNotificationData(); |
175 } | 189 } |
176 | 190 |
177 return notificationToShow; | 191 return notificationToShow; |
| 192 }, |
| 193 |
| 194 /** |
| 195 * Localizes the texts of the supplied notification. |
| 196 * @param {Object} notification notification to translate |
| 197 * @param {String} locale the target locale (optional, defaults to the |
| 198 * application locale) |
| 199 * @return {Object} the translated texts |
| 200 */ |
| 201 getLocalizedTexts: function(notification, locale) |
| 202 { |
| 203 locale = locale || Utils.appLocale; |
| 204 let textKeys = ["title", "message"]; |
| 205 let localizedTexts = []; |
| 206 for each (let key in textKeys) |
| 207 { |
| 208 if (key in notification) |
| 209 localizedTexts[key] = localize(notification[key], locale); |
| 210 } |
| 211 return localizedTexts; |
178 } | 212 } |
179 }; | 213 }; |
180 Notification.init(); | 214 Notification.init(); |
OLD | NEW |