5 new, 10 updated patches.
[webos-internals:djcin7s-modifications.git] / messaging / messaging-notification-repeat.patch
1 diff --git a/usr/palm/applications/com.palm.app.messaging/app/controllers/app-assistant.js b/usr/palm/applications/com.palm.app.messaging/app/controllers/app-assistant.js
2 index 5867d78..a39955f 100644
3 --- a/usr/palm/applications/com.palm.app.messaging/app/controllers/app-assistant.js
4 +++ b/usr/palm/applications/com.palm.app.messaging/app/controllers/app-assistant.js
5 @@ -69,8 +69,10 @@ var AppAssistant = Class.create({
6                         this.launchChatWithPerson(stageController,launchParams.personId, launchParams.contactPointId, launchParams.address, launchParams.type, launchParams.serviceName);
7                 // Launching composeview with message/attachment/composeAddress
8                 } else if (launchParams.messageText || launchParams.attachment || launchParams.composeAddress || (launchParams.composeRecipients && launchParams.composeRecipients.length)) {
9 -                       
10                         this.launchCompose(stageController,launchParams);
11 +               // play alarm nag                       
12 +               } else if(launchParams.playalarmsound){
13 +                       this.playAlarmSound();
14                 // Launch listview - make sure the listview is the current scene, don't just focus the window
15                 } else if (launchParams.launchListView) {
16                         this.launchListView(stageController,launchParams.forceListView);
17 @@ -88,7 +90,14 @@ var AppAssistant = Class.create({
18                         this.launchMessaging(stageController);
19                 }               
20         },
21 -       
22 +
23 +       playAlarmSound: function() {
24 +               var dashboard = this.appController.notificationAssistant.controller.getStageProxy(DashboardMessageStageName);
25 +               if (dashboard) {
26 +                       dashboard.delegateToSceneAssistant("playAlarmSound");
27 +               }
28 +       },
29 +                       
30         launchChatWithId: function(stageController, chatThreadId) {
31                 if (stageController) {                  
32                         // Don't pop/push if the chat we want is already open
33 diff --git a/usr/palm/applications/com.palm.app.messaging/app/controllers/dashboardMessage-assistant.js b/usr/palm/applications/com.palm.app.messaging/app/controllers/dashboardMessage-assistant.js
34 index fe431e5..a2f0b6e 100644
35 --- a/usr/palm/applications/com.palm.app.messaging/app/controllers/dashboardMessage-assistant.js
36 +++ b/usr/palm/applications/com.palm.app.messaging/app/controllers/dashboardMessage-assistant.js
37 @@ -1,5 +1,7 @@
38  /* Copyright 2009 Palm, Inc.  All rights reserved. */
39  
40 +g_notificationRepeatCount = 0;
41 +
42  function DashboardMessageAssistant(dashboardData) {
43         this.dashboardData = dashboardData; // hold onto a reference to the dashboardData
44         this.appController = Mojo.Controller.getAppController();
45 @@ -9,6 +11,39 @@ function DashboardMessageAssistant(dashboardData) {
46  }
47  
48  DashboardMessageAssistant.prototype.setup = function() {
49 +
50 +       //load the notification repeat preferences.
51 +       //get notification repeat interval and max repeat values from cookie
52 +       this.notificationCookie = new Mojo.Model.Cookie("com.palm.app.messaging.notificationrepeat");
53 +       
54 +       if (this.notificationCookie) 
55 +       {
56 +               var notificationCookie = this.notificationCookie.get();
57 +
58 +               if (notificationCookie) 
59 +               {                       
60 +                       if(notificationCookie.notificationRepeatInterval)
61 +                       {
62 +                               this.notificationRepeatInterval = notificationCookie.notificationRepeatInterval;
63 +                       }
64 +                       else
65 +                       {
66 +                               //set default value to 2 minutes
67 +                               this.notificationRepeatInterval = '2';
68 +                       }
69 +                       
70 +                       if(notificationCookie.notificationMaxRepeat)
71 +                       {
72 +                               this.notificationMaxRepeat = notificationCookie.notificationMaxRepeat;
73 +                       }
74 +                       else
75 +                       {
76 +                               //set default value to unlimited
77 +                               this.notificationMaxRepeat = '99999';
78 +                       }
79 +               }
80 +       }
81 +       
82         this.update(true);
83         this.messageInfoElement = this.controller.get('message_info');
84         this.messageInfoElement.addEventListener(Mojo.Event.tap, this.tapHandler);
85 @@ -18,9 +53,16 @@ DashboardMessageAssistant.prototype.cleanup = function() {
86         // If the dashboard is unloaded then wipe out our data
87         this.appController.notificationAssistant.resetNewMessages();
88         this.messageInfoElement.removeEventListener(Mojo.Event.tap, this.tapHandler);
89 +       
90 +       //remove the Notification repeat task
91 +       this.removePlayAlarmSoundTask();
92  };
93  
94  DashboardMessageAssistant.prototype.update = function(isNewContent) {
95 +
96 +       //remove the nag reminder
97 +       this.removePlayAlarmSoundTask();
98 +
99         // TODO close the dashboard if dashboardData is empty?
100         if (!this.dashboardData || this.dashboardData.newest == undefined) {
101                 Mojo.Log.error("DashboardMessageAssistant.update called with empty data.");
102 @@ -28,6 +70,9 @@ DashboardMessageAssistant.prototype.update = function(isNewContent) {
103                 this.closeDashboard();
104                 return;
105         }
106 +
107 +       //reschedule the nag reminder
108 +       this.schedulePlayAlarmSoundTask();
109         
110         var data = this.dashboardData[this.dashboardData.newest].list;
111         var numConversations = Object.keys(this.dashboardData).length - 1; // subtract one because of the 'newest' property
112 @@ -142,6 +187,69 @@ DashboardMessageAssistant.prototype.tapHandler = function(event) {
113         }
114  };
115  
116 +DashboardMessageAssistant.prototype.playAlarmSound =  function() {
117 +       //play nag sound and reschedule
118 +       if (this.appController.notificationAssistant.Messaging.messagingPrefs.enableNotificationSound) {
119 +               //first try to use the SMS Tone Per Contact method if that fails use the default method
120 +               try
121 +               {
122 +                       var data = this.dashboardData[this.dashboardData.newest].list;
123 +                       this.appController.notificationAssistant.playMsgToneForSMSId(data[0].address);
124 +               }
125 +               catch(e)
126 +               {
127 +                       var notifParams = {};
128 +                       this.appController.notificationAssistant.setNotificationSound(notifParams);
129 +                       this.appController.notificationAssistant.controller.playSoundNotification(notifParams.soundClass, notifParams.soundFile);
130 +               }
131 +               
132 +               this.schedulePlayAlarmSoundTask();
133 +       }
134 +};
135 +
136 +DashboardMessageAssistant.prototype.schedulePlayAlarmSoundTask = function() {
137 +       try {
138 +               //retrigger reminder every X minutes until we acknowledge it.
139 +               //notificationRepeatInterval disables the notification repeat
140 +               //also check to make sure we have not exceeded the max repeat value
141 +               if( parseFloat(this.notificationRepeatInterval) != 0 && g_notificationRepeatCount < parseInt(this.notificationMaxRepeat))
142 +               {
143 +                       g_notificationRepeatCount++;
144 +
145 +                       var playSoundTime = new Date();
146 +                       playSoundTime = new Date(playSoundTime.getTime() + parseFloat(this.notificationRepeatInterval)*60*1000);
147 +
148 +                       this.controller.serviceRequest('palm://com.palm.taskScheduler', {
149 +                               method: 'updateTask',
150 +                               parameters: {uri: 'palm://com.palm.applicationManager/open',
151 +                                       arguments: {'id': 'com.palm.app.messaging',
152 +                                               'params': {'playalarmsound': true}},
153 +                               key: 'msg-playalarmsound',
154 +                               start: {date: playSoundTime.toUTCString()}}
155 +                               });
156 +               }
157 +       }
158 +       catch (e) {
159 +               Mojo.Log.logException(e, "dashboardMessage-assistant.schedulePlayAlarmSoundTask");
160 +       }
161 +};
162 +
163 +DashboardMessageAssistant.prototype.removePlayAlarmSoundTask =  function() {
164 +       try 
165 +       {
166 +               //reset the notification repeat counter
167 +               g_notificationRepeatCount = 0;
168 +                       
169 +               this.controller.serviceRequest('palm://com.palm.taskScheduler', {
170 +                       method: 'removeTask',
171 +                       parameters: {key: 'msg-playalarmsound'}
172 +                       });
173 +       }
174 +       catch (e) {
175 +               Mojo.Log.logException(e, "dashboardMessage-assistant.removePlayAlarmSoundTask");
176 +       }
177 +};
178 +
179  DashboardMessageAssistant.prototype.closeDashboard = function(){
180         this.controller.window.close(); 
181  };
182 \ No newline at end of file
183 diff --git a/usr/palm/applications/com.palm.app.messaging/app/controllers/notification-assistant.js b/usr/palm/applications/com.palm.app.messaging/app/controllers/notification-assistant.js
184 index 8238c68..b732bce 100644
185 --- a/usr/palm/applications/com.palm.app.messaging/app/controllers/notification-assistant.js
186 +++ b/usr/palm/applications/com.palm.app.messaging/app/controllers/notification-assistant.js
187 @@ -52,6 +52,12 @@ NotificationAssistant.prototype.sendNotification = function(notificationType, re
188         }
189  };
190  
191 +//Support for using SMS Tone Per Contact from the Notification Repeat Patch
192 +//placing it here to avoid patch conflicts.
193 +NotificationAssistant.prototype.playMsgToneForSMSId = function(SMSId){
194 +       MessagingMojoService.rLookup(SMSId,contact,this.playmsgtone.bind(this),this.playmsgtone.bind(this));
195 +};
196 +
197  /*
198   * <ReminderCode>
199   */
200 diff --git a/usr/palm/applications/com.palm.app.messaging/app/controllers/prefsAccountSummary-assistant.js b/usr/palm/applications/com.palm.app.messaging/app/controllers/prefsAccountSummary-assistant.js
201 index 50c8e26..039d784 100644
202 --- a/usr/palm/applications/com.palm.app.messaging/app/controllers/prefsAccountSummary-assistant.js
203 +++ b/usr/palm/applications/com.palm.app.messaging/app/controllers/prefsAccountSummary-assistant.js
204 @@ -16,6 +16,39 @@ var PrefsAccountSummaryAssistant = Class.create({
205      },
206   
207      setup: function(){
208 +               //get notification repeat interval and max repeat values from cookie
209 +               this.notificationCookie = new Mojo.Model.Cookie("com.palm.app.messaging.notificationrepeat");
210 +
211 +               if (this.notificationCookie) 
212 +               {
213 +                       var notificationCookie = this.notificationCookie.get();
214 +
215 +                       if (notificationCookie) 
216 +                       {                       
217 +                               if(notificationCookie.notificationRepeatInterval)
218 +                               {
219 +                                       this.notificationRepeatInterval = notificationCookie.notificationRepeatInterval;
220 +                               }
221 +                               else
222 +                               {
223 +                                       //set default value to 2 minutes
224 +                                       this.notificationRepeatInterval = '2';
225 +                               }
226 +                               
227 +                               if(notificationCookie.notificationMaxRepeat)
228 +                               {
229 +                                       this.notificationMaxRepeat = notificationCookie.notificationMaxRepeat;
230 +                               }
231 +                               else
232 +                               {
233 +                                       //set default value to unlimited
234 +                                       this.notificationMaxRepeat = '99999';
235 +                               }
236 +                       }
237 +               }
238 +               
239 +               this.renderNotificationRepeatValues(this.getCurrentNotificationRepeatIntervalString(), this.getCurrentNotificationMaxRepeatString());
240 +               
241        this.preferencesAccountsModel = {items: []};
242           this.controller.setupWidget('preferences-accounts', {itemTemplate:'prefsAccountSummary/accountsRow'}, this.preferencesAccountsModel);
243  
244 @@ -35,9 +68,25 @@ var PrefsAccountSummaryAssistant = Class.create({
245        this.controller.listen('addAccountButton',Mojo.Event.tap, this.handleAddAccountTap);   
246     
247        this.controller.listen('currentringtonerow',Mojo.Event.tap, this.chooseNotificationRingtone);
248 +         
249 +               //repeat notification handlers
250 +               this.notificationRepeatIntervalClickHandler = this.handleNotificationRepeatIntervalClick.bindAsEventListener(this);
251 +               this.controller.get('pv_notification_repeat_interval').observe('mojo-tap', this.notificationRepeatIntervalClickHandler);
252 +               this.notificationMaxRepeatClickHandler = this.handleNotificationMaxRepeatClick.bindAsEventListener(this);
253 +               this.controller.get('pv_notification_max_repeat').observe('mojo-tap', this.notificationMaxRepeatClickHandler);
254      },
255         
256         cleanup: function() {
257 +               
258 +               //save notification repeat preferences
259 +               if (this.notificationCookie)
260 +               {
261 +                       this.notificationCookie.put({
262 +                                                                               notificationRepeatInterval: this.notificationRepeatInterval,
263 +                                                                               notificationMaxRepeat: this.notificationMaxRepeat
264 +                                                                               });
265 +               }
266 +               
267                 this.controller.stopListening('preferences-accounts',Mojo.Event.listTap, this.handleAccountListTap);
268                 this.controller.stopListening('addAccountButton',Mojo.Event.tap, this.handleAddAccountTap);
269                 if (this.saveSMSPrefs) {
270 @@ -46,6 +95,12 @@ var PrefsAccountSummaryAssistant = Class.create({
271        this.controller.stopListening('notificationToggle',Mojo.Event.propertyChange,this.notificationToggleChanged);
272        this.controller.stopListening('notificationSoundSelector',Mojo.Event.propertyChange,this.notificationSoundToggleChanged);                
273        this.controller.stopListening('autoDownloadToggle',Mojo.Event.propertyChange,this.autoDownloadToggleChanged);
274 +         
275 +               //stop observing notification repeat controls
276 +               this.controller.get('pv_notification_repeat_interval').stopObserving('mojo-tap', this.notificationRepeatIntervalClickHandler);
277 +               this.notificationRepeatIntervalClickHandler = undefined;
278 +               this.controller.get('pv_notification_max_repeat').stopObserving('mojo-tap', this.notificationMaxRepeatClickHandler);
279 +               this.notificationMaxRepeatClickHandler = undefined;
280         },
281  
282         handleAccountListTap: function(e) {
283 @@ -342,5 +397,120 @@ var PrefsAccountSummaryAssistant = Class.create({
284           Object.extend(newParams,this.params);
285        Object.extend(newParams,inputHash);
286        this.controller.stageController.pushScene('prefsSetupAccount',newParams);
287 -    }
288 +    },
289 +       
290 +       //notification repat settings section
291 +       renderNotificationRepeatValues: function(notificationRepeatIntervalStr, notificationMaxRepeatStr) {
292 +               //Mojo.Log.info('prefs-assistant: renderNotificationRepeatValues');
293 +               var obj = {};
294 +               
295 +               // Notification Repeat Interval
296 +               this.controller.get('pv_notification_repeat_interval_value').update(notificationRepeatIntervalStr);
297 +               
298 +               // Notification Max Repeat
299 +               this.controller.get('pv_notification_max_repeat_value').update(notificationMaxRepeatStr);
300 +       },
301 +       
302 +       getCurrentNotificationRepeatIntervalString: function() {
303 +               var index = 0;
304 +               for (index = 0; index < this.notificationRepeatIntervals.size(); index++) {
305 +                       if (this.notificationRepeatIntervals[index].command == this.notificationRepeatInterval)
306 +                               return this.notificationRepeatIntervals[index].label;
307 +               }
308 +       },
309 +       
310 +       getCurrentNotificationMaxRepeatString: function() {
311 +               var index = 0;
312 +               for (index = 0; index < this.notificationMaxRepeats.size(); index++) {
313 +                       if (this.notificationMaxRepeats[index].command == this.notificationMaxRepeat)
314 +                               return this.notificationMaxRepeats[index].label;
315 +               }
316 +       },
317 +       
318 +       notificationRepeatIntervalChoose: function(value) {
319 +               //Mojo.Log.info('prefs-assistant: defaultNotificationRepeatIntervalChoose');
320 +               
321 +               if (value != undefined && value != this.notificationRepeatInterval) {
322 +                       this.notificationRepeatInterval = value;
323 +                       this.renderNotificationRepeatValues(this.getCurrentNotificationRepeatIntervalString(), this.getCurrentNotificationMaxRepeatString());
324 +                       this.dirty = true;
325 +               }
326 +       },
327 +       
328 +       handleNotificationRepeatIntervalClick: function(event) {
329 +               //Mojo.Log.info('prefs-assistant: handleNotificationRepeatIntervalClick');
330 +
331 +               Event.stop(event);
332 +               this.controller.popupSubmenu({
333 +                               onChoose: this.notificationRepeatIntervalChoose.bind(this),
334 +                               toggleCmd: this.notificationRepeatInterval,
335 +                               items: this.notificationRepeatIntervals
336 +                       });
337 +       },
338 +       
339 +       notificationMaxRepeatChoose: function(value) {
340 +               //Mojo.Log.info('prefs-assistant: notificationMaxRepeatChoose');
341 +               
342 +               if (value != undefined && value != this.notificationMaxRepeat) {
343 +                       this.notificationMaxRepeat = value;
344 +                       this.renderNotificationRepeatValues(this.getCurrentNotificationRepeatIntervalString(), this.getCurrentNotificationMaxRepeatString());
345 +                       this.dirty = true;
346 +               }
347 +       },
348 +       
349 +       handleNotificationMaxRepeatClick: function(event) {
350 +               //Mojo.Log.info('prefs-assistant: handleNotificationMaxRepeatClick');
351 +
352 +               Event.stop(event);
353 +               this.controller.popupSubmenu({
354 +                               onChoose: this.notificationMaxRepeatChoose.bind(this),
355 +                               toggleCmd: this.notificationMaxRepeat,
356 +                               items: this.notificationMaxRepeats
357 +                       });
358 +       },
359 +       
360 +       notificationRepeatIntervals: [
361 +               {label:$L('Disabled'), command:'0'},
362 +               {label:$L('5 Seconds'), command:'.083'},
363 +               {label:$L('10 Seconds'), command:'.167'},
364 +               {label:$L('15 Seconds'), command:'.25'},
365 +               {label:$L('20 Seconds'), command:'.333'},
366 +               {label:$L('25 Seconds'), command:'.417'},
367 +               {label:$L('30 Seconds'), command:'.5'},
368 +               {label:$L('1 Minutes'), command:'1'},
369 +               {label:$L('2 Minutes'), command:'2'},
370 +               {label:$L('3 Minutes'), command:'3'},
371 +               {label:$L('4 Minutes'), command:'4'},
372 +               {label:$L('5 Minutes'), command:'5'},
373 +               {label:$L('10 Minutes'), command:'10'},
374 +               {label:$L('15 Minutes'), command:'15'}
375 +       ],
376 +       
377 +       notificationMaxRepeats: [
378 +               {label:$L('Unlimited'), command:'99999'}, //this should be a large enough value to be conisdered unlimited for our purpose.
379 +               {label:$L('1'), command:'1'},
380 +               {label:$L('2'), command:'2'},
381 +               {label:$L('3'), command:'3'},
382 +               {label:$L('4'), command:'4'},
383 +               {label:$L('5'), command:'5'},
384 +               {label:$L('10'), command:'10'},
385 +               {label:$L('15'), command:'15'},
386 +               {label:$L('20'), command:'20'},
387 +               {label:$L('25'), command:'25'},
388 +               {label:$L('30'), command:'30'},
389 +               {label:$L('35'), command:'35'},
390 +               {label:$L('40'), command:'40'},
391 +               {label:$L('45'), command:'45'},
392 +               {label:$L('50'), command:'50'},
393 +               {label:$L('55'), command:'55'},
394 +               {label:$L('60'), command:'60'},
395 +               {label:$L('65'), command:'65'},
396 +               {label:$L('70'), command:'70'},
397 +               {label:$L('75'), command:'75'},
398 +               {label:$L('80'), command:'80'},
399 +               {label:$L('85'), command:'85'},
400 +               {label:$L('90'), command:'90'},
401 +               {label:$L('95'), command:'95'},
402 +               {label:$L('100'), command:'100'}
403 +       ]
404  });
405 \ No newline at end of file
406 diff --git a/usr/palm/applications/com.palm.app.messaging/app/views/prefsAccountSummary/prefsAccountSummary-scene.html b/usr/palm/applications/com.palm.app.messaging/app/views/prefsAccountSummary/prefsAccountSummary-scene.html
407 index 03d2b66..6b5a28a 100644
408 --- a/usr/palm/applications/com.palm.app.messaging/app/views/prefsAccountSummary/prefsAccountSummary-scene.html
409 +++ b/usr/palm/applications/com.palm.app.messaging/app/views/prefsAccountSummary/prefsAccountSummary-scene.html
410 @@ -44,6 +44,26 @@
411         
412                 </div>
413         </div>
414 +       
415 +       <div id='pv_notificationrepeat_div' class="palm-group">
416 +               <div class="palm-group-title" x-mojo-loc="">Notification Repeat</div>
417 +               <div class="palm-list">
418 +                       <div id="pv_notification_repeat_interval" class="palm-row">
419 +                               <div class="palm-row-wrapper">
420 +                                       <div class="label" x-mojo-loc="">Repeat Interval</div>
421 +                                       <div id="pv_notification_repeat_interval_value" class="title"></div>
422 +                               </div>
423 +                       </div>
424 +                       
425 +                       <div id="pv_notification_max_repeat" class="palm-row">
426 +                               <div class="palm-row-wrapper">
427 +                                       <div class="label" x-mojo-loc="">Max Repeats</div>
428 +                                       <div id="pv_notification_max_repeat_value" class="title"></div>
429 +                               </div>
430 +                       </div>
431 +               </div>
432 +       </div>
433 +       
434         <div class="palm-group">
435                 <div class="palm-group-title" x-mojo-loc=''>Accounts</div>      
436             <div class="palm-list">