All outstanding updates
[webos-internals:skurriers-modifications.git] / messaging / messaging-sms-tone-per-contact.patch
1 diff --git a/usr/palm/applications/com.palm.app.contacts/app/controllers/edit-assistant.js b/usr/palm/applications/com.palm.app.contacts/app/controllers/edit-assistant.js
2 index 8599a50..b9bba87 100644
3 --- a/usr/palm/applications/com.palm.app.contacts/app/controllers/edit-assistant.js
4 +++ b/usr/palm/applications/com.palm.app.contacts/app/controllers/edit-assistant.js
5 @@ -64,6 +64,17 @@ EditAssistant = Class.create({
6                         template: "edit/ringtones"
7                 }));
8                 
9 +               if(this.person.messagingRingtoneName){
10 +                       this.person.MsgtoneDisplay = this.person.messagingRingtoneName;
11 +                       this.person.MsgtoneSet = "msgtone-set";
12 +               } else {
13 +                       this.person.MsgtoneDisplay = $L("Set a message tone");
14 +                       this.person.MsgtoneSet = "";
15 +               }
16 +               this.controller.get("MsgtoneBox").update(Mojo.View.render({
17 +                       object: this.person,
18 +                       template: "edit/msgtones"
19 +               }));            
20                 
21                 var that = this;
22                 
23 @@ -278,6 +289,11 @@ EditAssistant = Class.create({
24                                         object: {ringtoneDisplay:ringtoneName},
25                                         template: "edit/ringtones"
26                                 }));
27 +                               var messagingRingtoneName = this.person.messagingRingtoneName || $L("Set a message tone");
28 +                               this.controller.get("MsgtoneBox").update(Mojo.View.render({
29 +                                       object: {MsgtoneDisplay:messagingRingtoneName},
30 +                                       template: "edit/msgtones"
31 +                               }));
32                                 
33                         }
34                 }
35 @@ -543,6 +559,7 @@ EditAssistant = Class.create({
36                 this.controller.listen("NameSyncPickerWrapper", Mojo.Event.tap, this.popupContactChooser.bind(this));
37                 this.controller.get("edit-photo").observe(Mojo.Event.tap, this.attachFilePicker.bind(this));
38                 this.controller.get("RingtoneBox").observe(Mojo.Event.tap, this.attachRingtonePicker.bind(this));
39 +               this.controller.get("MsgtoneBox").observe(Mojo.Event.tap, this.attachMsgtonePicker.bind(this));
40                 this.renderLabels();
41                 this.setupContact();
42                 if (this.contact.readOnly) {
43 diff --git a/usr/palm/applications/com.palm.app.contacts/app/controllers/filepicker-behaviors.js b/usr/palm/applications/com.palm.app.contacts/app/controllers/filepicker-behaviors.js
44 index 276995f..695a2c1 100644
45 --- a/usr/palm/applications/com.palm.app.contacts/app/controllers/filepicker-behaviors.js
46 +++ b/usr/palm/applications/com.palm.app.contacts/app/controllers/filepicker-behaviors.js
47 @@ -56,6 +56,55 @@ var FilepickerBehaviors = {
48                         Mojo.FilePicker.pickFile(params, this.controller.stageController);
49  
50         },
51 +
52 +       attachMsgtonePicker: function(event){
53 +               if(this.person.messagingRingtoneLoc){
54 +                       this.controller.popupSubmenu( {
55 +                               onChoose:function(c){
56 +                                       if(c == "CHANGE"){
57 +                                               this.pushMsgtonePicker();
58 +                                       } else if(c == "DELETE"){
59 +                                               this.clearMsgtone();
60 +                                       }
61 +                               }.bind(this),
62 +                               placeNear:event.target,
63 +                               items:[
64 +                                       {label:$L("Change Msgtone"), command:'CHANGE'},
65 +                                       {label:$L("Delete Msgtone"), command:'DELETE'}
66 +                               ]
67 +                       })                      
68 +               } else {
69 +                       this.pushMsgtonePicker();
70 +               }
71 +               
72 +       },
73 +       
74 +       clearMsgtone:function(){
75 +               this.person.messagingRingtoneLoc = "";
76 +               this.person.messagingRingtoneName = "";
77 +               this.person.MsgtoneDisplay = $L("Set a message tone");
78 +               this.person.MsgtoneSet = "";
79 +               this.person.dirty = true;
80 +               this.controller.get("MsgtoneBox").update(Mojo.View.render({
81 +                       object:this.person,
82 +                       template:"edit/msgtones"
83 +               }));
84 +       },
85 +       
86 +       pushMsgtonePicker:function(){
87 +                       var params = {
88 +                               actionType: 'attach',
89 +                               kinds: ['ringtone'],
90 +                               defaultKind: 'ringtone',
91 +                               filePath:this.person.messagingRingtoneLoc,
92 +                               onSelect: function(file){
93 +                                       this.attachMsgtone(this.sanitizeSystemPath(file.fullPath), file.name);
94 +                               }.bind(this)
95 +                       };
96 +                       //Mojo.Log.info("ContactMulti Picking a msgtone for " + this.contact.firstName + " " + this.contact.lastName);
97 +                       Mojo.FilePicker.pickFile(params, this.controller.stageController);
98 +
99 +       },
100         
101         attachFilePicker: function(event){
102                 if(this.contact.readOnly){
103 @@ -153,6 +202,20 @@ var FilepickerBehaviors = {
104                         template:"edit/ringtones"
105                       }));
106                 }
107 +       },
108 +       
109 +       attachMsgtone: function(msgtonePath, name){
110 +               if (msgtonePath) {
111 +                       this.person.dirty = true;
112 +                       this.person.messagingRingtoneName = name;
113 +                       this.person.MsgtoneDisplay = name;
114 +                       this.person.MsgtoneSet = "msgtone-set";
115 +                       this.person.messagingRingtoneLoc = msgtonePath;
116 +                       this.controller.get("MsgtoneBox").update(Mojo.View.render({
117 +                       object:this.person,
118 +                       template:"edit/msgtones"
119 +                     }));
120 +               }
121         }
122  }
123  
124 diff --git a/usr/palm/applications/com.palm.app.contacts/app/views/edit/lists-fake.html b/usr/palm/applications/com.palm.app.contacts/app/views/edit/lists-fake.html
125 index 306b79a..505ddb2 100644
126 --- a/usr/palm/applications/com.palm.app.contacts/app/views/edit/lists-fake.html
127 +++ b/usr/palm/applications/com.palm.app.contacts/app/views/edit/lists-fake.html
128 @@ -32,6 +32,20 @@
129          </div>
130      </div>
131  </div>
132 +<div>
133 +<div id="MsgtoneBox" class="">
134 +    <div class="palm-group unlabeled">
135 +        <div class="palm-list">
136 +            <div class="palm-row single" id="MsgtoneButton" x-mojo-tap-highlight="momentary">
137 +                <div class="palm-row-wrapper">
138 +                    <div class="title"  x-mojo-loc="">
139 +                        Set a message tone
140 +                    </div>
141 +                </div>
142 +            </div>
143 +        </div>
144 +    </div>
145 +</div>
146  </div>
147  <div>
148  <div id="emailList" name="emailList" class="contactPointList" >
149 diff --git a/usr/palm/applications/com.palm.app.contacts/app/views/edit/msgtones.html b/usr/palm/applications/com.palm.app.contacts/app/views/edit/msgtones.html
150 new file mode 100644
151 index 0000000..809d707
152 --- /dev/null
153 +++ b/usr/palm/applications/com.palm.app.contacts/app/views/edit/msgtones.html
154 @@ -0,0 +1,16 @@
155 +<div class="palm-group unlabeled">
156 +  <div class="palm-list">
157 +    <div class="palm-row single #{MsgtoneSet} msgtone-button" id="MsgtoneButton" x-mojo-tap-highlight="momentary">
158 +      <div class="palm-row-wrapper">
159 +        <div class="label right truncating-text" x-mojo-loc=''>
160 +          Msgtone
161 +        </div>
162 +        <div class="title">
163 +          <div class="truncating-text">
164 +            #{MsgtoneDisplay}
165 +          </div>
166 +        </div>
167 +      </div>
168 +    </div>
169 +  </div>
170 +</div>
171 diff --git a/usr/palm/applications/com.palm.app.messaging/app/controllers/chatview-assistant.js b/usr/palm/applications/com.palm.app.messaging/app/controllers/chatview-assistant.js
172 index 98ab9b2..cd36463 100644
173 --- a/usr/palm/applications/com.palm.app.messaging/app/controllers/chatview-assistant.js
174 +++ b/usr/palm/applications/com.palm.app.messaging/app/controllers/chatview-assistant.js
175 @@ -354,7 +354,7 @@ var ChatviewAssistant = Class.create({
176                 if (this.isScreenOn && data.chatThreadId == this.chatThreadId) {
177                         Mojo.Log.info("[CV] ****** chatview considerForNotification --- screen is on!");
178                         if (data.notificationType == this.Messaging.notificationTypes.newMessage) {
179 -                               data = {playSoundOnly:true};
180 +                               Object.extend(data, {playSoundOnly:true});
181                         } else if (data.notificationType == this.Messaging.notificationTypes.sendFailure) {
182                                 data = {}; // wipe out the notification because we are in the chat
183                         }
184 diff --git a/usr/palm/applications/com.palm.app.messaging/app/controllers/listview-assistant.js b/usr/palm/applications/com.palm.app.messaging/app/controllers/listview-assistant.js
185 index 5058e58..248d5e7 100644
186 --- a/usr/palm/applications/com.palm.app.messaging/app/controllers/listview-assistant.js
187 +++ b/usr/palm/applications/com.palm.app.messaging/app/controllers/listview-assistant.js
188 @@ -436,7 +436,7 @@ var ListviewAssistant = Class.create(App.Scene, {
189                 // if we are in the history view and the screen is on, do not display a banner + dashboard, just play a notification sound
190                 if (this.isScreenOn) {
191                         if (data.notificationType == this.Messaging.notificationTypes.newMessage && this.currentListView == this.Messaging.Views.HISTORY) {
192 -                               data = {playSoundOnly:true};
193 +                               Object.extend(data, {playSoundOnly:true});
194                         }
195                 }
196                 return data;
197 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
198 index 3d7c4b2..4622c57 100644
199 --- a/usr/palm/applications/com.palm.app.messaging/app/controllers/notification-assistant.js
200 +++ b/usr/palm/applications/com.palm.app.messaging/app/controllers/notification-assistant.js
201 @@ -27,6 +27,8 @@ function NotificationAssistant(controller){
202         };
203  }
204  
205 +var contact = {};
206 +
207  NotificationAssistant.prototype.subscribeToNotifications = function(){
208         this.messageNotificationRequest = MessagingMojoService.registerForIncomingMessages({onSuccess: this.sendNotification.bind(this, this.Messaging.notificationTypes.newMessage)});
209         this.sendErrorNotificationRequest = MessagingMojoService.registerForSendFailures(this.sendNotification.bind(this, this.Messaging.notificationTypes.sendFailure));
210 @@ -35,6 +37,37 @@ NotificationAssistant.prototype.subscribeToNotifications = function(){
211         this.airplaneModeNotificationRequest = MessagingMojoService.registerForAirplaneModeNotifications(this.sendAirplaneModeNotification.bind(this));
212  };
213  
214 +NotificationAssistant.prototype.doBanner = function(bannerParams,bannerLaunchParams,bannerType,payload) {
215 +       if (payload.messagetone.fullPath)
216 +               bannerParams.soundFile = payload.messagetone.fullPath;
217 +       this.controller.showBanner(bannerParams,bannerLaunchParams,bannerType);
218 +};
219 +
220 +NotificationAssistant.prototype.playMessagetone = function(payload){
221 +       if (payload.messagetone.fullPath)
222 +               this.controller.playSoundNotification('alerts',payload.messagetone.fullPath);
223 +       else
224 +               this.controller.playSoundNotification('alerts','');
225 +};
226 +
227 +NotificationAssistant.prototype.doB = function(bannerParams,bannerLaunchParams,bannerType,contact) {
228 +        Mojo.Log.error("Banner Ringtone: %j",contact.ringtoneLoc);                                                                                                                          
229 +       if (contact.ringtoneLoc) {
230 +               bannerParams.soundFile = contact.ringtoneLoc;
231 +               this.controller.showBanner(bannerParams,bannerLaunchParams,bannerType);
232 +       } else {
233 +               MessagingMojoService.getMessagetone(this.doBanner.bind(this,bannerParams,bannerLaunchParams,'chat'));
234 +       }
235 +};
236 +
237 +NotificationAssistant.prototype.playmsgtone = function(contact){
238 +       Mojo.Log.error("Playmsgtone Ringtone: %j",contact.ringtoneLoc);
239 +       if (contact.ringtoneLoc)
240 +               this.controller.playSoundNotification('alerts',contact.ringtoneLoc);
241 +       else
242 +               MessagingMojoService.getMessagetone(this.playMessagetone.bind(this));
243 +};
244 +
245  NotificationAssistant.prototype.sendNotification = function(notificationType, resp){
246         if (window.PalmSystem && !resp.returnValue) {
247                 try {
248 @@ -149,9 +182,8 @@ NotificationAssistant.prototype.considerForNotification = function(notificationD
249         
250         // check if we should only play a sound (when you are already in a chat & a new message comes in)
251         if(notificationData.playSoundOnly && this.Messaging.messagingPrefs.enableNotificationSound) {
252 -               var notifParams = {};
253 -               this.setNotificationSound(notifParams);
254 -               this.controller.playSoundNotification(notifParams.soundClass, notifParams.soundFile);
255 +               var smsid = notificationData.address;
256 +               MessagingMojoService.rLookup(smsid,contact,this.playmsgtone.bind(this),this.playmsgtone.bind(this));
257                 return; // don't display any visual notification
258         }       
259         
260 @@ -186,21 +218,25 @@ NotificationAssistant.prototype.sendClass0PopupAlert = function(notificationData
261  
262         notificationData.carrierName = carrierName;
263         this.class0AlertData.list.push(notificationData);
264 -       this.renderClass0PopupAlert(true);
265 +       var smsid = notificationData.address;
266 +       MessagingMojoService.getMessagetone(this.renderClass0PopupAlert.bind(this,true));
267  };
268  
269 -NotificationAssistant.prototype.renderClass0PopupAlert = function(playSound) {
270 +NotificationAssistant.prototype.renderClass0PopupAlert = function(playSound,messageTone) {
271         var class0Stage = this.controller.getStageController(Class0AlertStageName);
272  
273         if(class0Stage) {
274                 class0Stage.swapScene('class0Alert', this.class0AlertData);
275                 if (playSound){
276 -                       this.controller.playSoundNotification('alerts','');
277 +                       this.controller.playSoundNotification('alerts',contact.ringtoneLoc);
278                 }
279         } else {
280                 var soundClass = 'none';
281                 if(playSound) {
282                         soundClass = 'alerts';
283 +                       if(messageTone) {
284 +                               soundFile = messageTone;
285 +                       }
286                 }               
287                 
288                 var pushClass0AlertScene = function(stageController) {
289 @@ -211,7 +247,8 @@ NotificationAssistant.prototype.renderClass0PopupAlert = function(playSound) {
290                         name: Class0AlertStageName,
291                         lightweight: true,
292                         height: Math.floor(Mojo.Environment.DeviceInfo.screenHeight * 0.50),
293 -                       soundclass: soundClass
294 +                       soundclass: soundClass,
295 +                       soundfile: soundFile
296                 }, pushClass0AlertScene, 'popupalert');         
297         }
298  
299 @@ -279,14 +316,19 @@ NotificationAssistant.prototype.sendNewMessageNotificationAndUpdateDashboard = f
300         var bannerParams = {
301                 messageText: notificationText
302         };
303 -       this.setNotificationSound(bannerParams);
304 +       //this.setNotificationSound(bannerParams);
305         var bannerLaunchParams =  {
306                 chatThreadId: chatThreadId,
307                 clearBanner: true               
308         };
309 -       
310 -       this.controller.showBanner(bannerParams, bannerLaunchParams, 'chat');
311 -       
312 +       if (this.Messaging.messagingPrefs.enableNotificationSound) {
313 +                       var smsid = notificationData.address;                                                  
314 +               bannerParams.soundClass = "alerts";
315 +               MessagingMojoService.rLookup(smsid,contact,this.doB.bind(this,bannerParams,bannerLaunchParams,'chat'),this.doB.bind(this,bannerParams,bannerLaunchParams,'chat'));
316 +       } else {
317 +               Mojo.Log.error("Setting banner params");        
318 +               this.controller.showBanner(bannerParams, bannerLaunchParams, 'chat');
319 +       }       
320         // Store the data so it can be used in the dashboard
321         var data = {
322                 chatThreadId: chatThreadId,
323 @@ -343,13 +385,9 @@ NotificationAssistant.prototype.sendNewMessageNotificationAndUpdateDashboard = f
324                 // delay creating the dashboard window for the case where the banner is clicked on
325                 // to take you to the chat view.  This will likely result in the dashboard data
326                 // being cleared.  If the dashboard data is empty, we do not need to create the dashboard.              
327 -               if (this.Messaging.DisplayState.isDisplayOn()) {
328 -                       if (!this.isNewMessageDashboardPending) {
329 -                               this.isNewMessageDashboardPending = true; 
330 -                               createDashboard.delay(5);
331 -                       }
332 -               } else {
333 -                       createDashboard(); // if the screen is off, create the dashboard right away
334 +               if (!this.isNewMessageDashboardPending) {
335 +                       this.isNewMessageDashboardPending = true;
336 +                       createDashboard.delay(5); 
337                 }
338         }
339  };
340 diff --git a/usr/palm/applications/com.palm.app.messaging/app/models/messaging-luna-service.js b/usr/palm/applications/com.palm.app.messaging/app/models/messaging-luna-service.js
341 index 119950a..e011557 100644
342 --- a/usr/palm/applications/com.palm.app.messaging/app/models/messaging-luna-service.js
343 +++ b/usr/palm/applications/com.palm.app.messaging/app/models/messaging-luna-service.js
344 @@ -1009,5 +1009,167 @@ var MessagingMojoService = {
345                   method: 'setSMSCAddressAndEmailGateway',
346                   parameters: {smscAddr:address, emailGateway: gateway}
347           });
348 +       },
349 +       
350 +               isNumberValid: function(number) {
351 +               return !(number === undefined
352 +                       || number == null
353 +                       || number == "" 
354 +                       || number == "unknown" 
355 +                       || number == "unknown caller"
356 +                       || number == "blocked caller") 
357 +       },
358 +       
359 +       // use contacts service and carrier book to perform reverse lookup on number.  stores results in passed contact object.
360 +       // runs callback when done.
361 +       // if the number isn't valid, marks contact lookup complete 
362 +       // if there's already one happening, or one already completed, just fires callback
363 +       // if there's a lateCallback provided, calls that if the result comes much later
364 +       rLookup: function(number, contact, callback, lateCallback){
365 +               
366 +               //Reset contact to always get the tone
367 +               contact = {};   
368 +               Mojo.Log.error("Current contact value: %j",contact);
369 +               Mojo.Log.error("SMS ID: %j",number);
370 +               
371 +               // bail if the number is invalid
372 +               if (!(this.isNumberValid(number))) {
373 +                               this.finishLookup(contact, callback);
374 +                               return;
375 +               }
376 +               
377 +               if (contact.lookupComplete) {
378 +                       callback(contact);      
379 +                       return;
380 +               }
381 +               
382 +               if (contact.lookupPending) {
383 +                       callback(contact);      
384 +                       return;
385 +               }
386 +               
387 +               
388 +               // use contacts service to perform lookup.
389 +               // if contact already has an id in it, use person lookup
390 +               // instead of doing reverse lookup on number
391 +               contact.lookupPending = true;
392 +               var method, params;
393 +               if (contact.initialId) {
394 +                       method = 'basicDetails'
395 +                       params =  {'id' : contact.initialId}
396 +                       delete contact.initialId;
397 +               } else {
398 +                       method = 'reverseLookup'
399 +                       params = {
400 +                'value': number,
401 +            }
402 +               }
403 +               this.lastRequest = new Mojo.Service.Request('palm://com.palm.contacts', {
404 +                       'method': method,
405 +            parameters: params,
406 +            onSuccess: this.onLookup.bind(this, number, contact, callback, lateCallback),
407 +                       onFailure: function() {
408 +                               // cancel previous lookup, so this doesn't fire on a service crash
409 +                               if (this.lastRequest) {
410 +                                       this.lastRequest.cancel();
411 +                                       this.lastRequest = undefined;
412 +                               }
413 +                               
414 +                               this.carrierBookLookup(number,contact);
415 +                               this.finishLookup(contact, callback);
416 +                       }.bind(this)
417 +        });
418 +               
419 +               // timeout if lookup hasn't completed in 4 seconds
420 +               this.lookupTimeout = setTimeout(this.onLookupTimeout.bind(this, contact, callback, lateCallback), 4000);
421 +    },
422 +       
423 +       // when contact lookup returns, check for valid result
424 +       // if valid result, grab name, ringtone; if there's a picture, start loading and set callback to measure it
425 +       // if no valid result, look in carrier book
426 +       // fire callback when done
427 +    onLookup: function(number, contact, callback, lateCallback, result){
428 +        Mojo.Log.info( "PhoneApp: Contact::onLookup CALLER ID LOOKUP %s RETURNED %j" , number , result);
429 +               var statusChange = "";
430 +               
431 +               // cancel previous lookup, so this doesn't fire on a service crash
432 +               if (this.lastRequest) {
433 +                       this.lastRequest.cancel();
434 +                       this.lastRequest = undefined;
435 +               }
436 +               
437 +               if (result.record) {
438 +                       /*              
439 +                       // don't match if the number we get back is different than the number
440 +                       // we passed in (provided the lengths are the same)
441 +                       if (!(result.record.number)
442 +                               || ( (result.record.number) && ( (result.record.number.length !== number.length) 
443 +                                       || (result.record.number.length === number.length 
444 +                                                && result.record.number === number)))) {
445 +                       */
446 +                       contact.id = result.record.id;
447 +                       
448 +       
449 +                       contact.ringtoneLoc = result.record.messagingRingtoneLoc;
450 +                       Mojo.Log.error("MSGTone: %j",contact.ringtoneLoc);                      
451 +
452 +               }
453 +               
454 +               this.finishLookup(contact, callback, lateCallback);
455 +    },
456 +       
457 +       
458 +
459 +       // mark complete; cancel timeout; fire callback if it hasn't fired yet
460 +       finishLookup: function(contact, callback, lateCallback) {
461 +               contact.lookupPending = false;
462 +               
463 +               // cancel lookup timeout
464 +               clearTimeout(this.lookupTimeout); 
465 +               this.lookupTimeout = undefined;
466 +               
467 +               if (!(contact.lookupComplete)) {
468 +                       contact.lookupComplete = true;
469 +                       callback(contact);
470 +               // if we have a late return, and we got a contact result, call
471 +               // the late return update 
472 +               } else if (lateCallback && contact.doLateCallback && contact.id) {
473 +                       contact.doLateCallback = false;
474 +                       lateCallback.delay(5, contact);
475 +               } else {
476 +               }
477 +               
478 +       },
479 +       
480 +       // flag lookup as done; proceed with callback
481 +       onLookupTimeout: function(contact, callback, lateCallback) {
482 +               
483 +               if (lateCallback) {
484 +                       contact.doLateCallback = true;
485 +               } else if (this.lastRequest && !lateCallback) {
486 +                       // cancel previous lookup, so this doesn't fire on a service crash
487 +                       this.lastRequest.cancel();
488 +                       this.lastRequest = undefined;
489 +               }
490 +               
491 +               // clear timeout
492 +               this.lookupTimeout = undefined;
493 +               
494 +               // flag done; fire callback if it hasn't yet
495 +               contact.lookupComplete = true;
496 +               var lookupWasPending = contact.lookupPending;
497 +               contact.lookupPending = false;
498 +               if (lookupWasPending) 
499 +                       callback(contact);
500 +       },
501 +       
502 +       getMessagetone:  function(callback) {
503 +               var request = new Mojo.Service.Request('palm://com.palm.systemservice', {
504 +                       method: 'getPreferences',
505 +                       parameters: {"keys":["messagetone"]},
506 +                       onSuccess: callback,
507 +                       onFailure: callback
508 +               });
509 +               return request;
510         }
511  };
512 \ No newline at end of file
513 diff --git a/usr/palm/applications/com.palm.app.soundsandalerts/app/controllers/soundsalertsconfig-assistant.js b/usr/palm/applications/com.palm.app.soundsandalerts/app/controllers/soundsalertsconfig-assistant.js
514 index 638958f..0f53d58 100644
515 --- a/usr/palm/applications/com.palm.app.soundsandalerts/app/controllers/soundsalertsconfig-assistant.js
516 +++ b/usr/palm/applications/com.palm.app.soundsandalerts/app/controllers/soundsalertsconfig-assistant.js
517 @@ -96,9 +96,15 @@ var SoundsalertsconfigAssistant = Class.create({
518                 $('system_ui_sounds').observe('mojo-property-change', this.toggleSystemUISounds.bindAsEventListener(this));
519                 
520                 $('currentringtonerow').observe(Mojo.Event.tap, this.showAudioFilePicker.bindAsEventListener(this));
521 +               $('currentalertrow').observe(Mojo.Event.tap, this.showAlertFilePicker.bindAsEventListener(this));
522 +               $('currentnotificationrow').observe(Mojo.Event.tap, this.showNotificationFilePicker.bindAsEventListener(this));
523 +               $('currentmessagerow').observe(Mojo.Event.tap, this.showMessageFilePicker.bindAsEventListener(this));
524                                 
525                 this.getCurrentVolumes();
526                 this.getCurrentRingtone();
527 +               this.getCurrentAlert();
528 +               this.getCurrentNotification();
529 +               this.getCurrentMessage();
530                 this.getVibrateSettings();      
531                 this.getOtherSettings();
532                 
533 @@ -272,6 +278,84 @@ var SoundsalertsconfigAssistant = Class.create({
534                 $('currentringtone').innerHTML = file.name;
535         },
536         
537 +       // Alert Picking
538 +       getCurrentAlert: function() {
539 +       this.getCurrentAlertReq = SystemService.getAlerts(this.getCurrentAlertQuery.bind(this));
540 +       },
541 +       
542 +       getCurrentAlertQuery: function(payload) {
543 +       if (payload.alerttone) {
544 +       $('currentalert').innerHTML = payload.alerttone.name;
545 +       this.currAlertPath = payload.alerttone.fullPath;
546 +       }
547 +       else 
548 +       $('currentalert').innerHTML = $L("Pick an alert");
549 +       
550 +       },
551 +       
552 +       showAlertFilePicker: function(event) {
553 +       var params = {"kinds": ["ringtone"],"filePath":this.currAlertPath,"onSelect":this.selectedAlertFile.bind(this),actionType:"attach",actionName: $L("Done")};
554 +       Mojo.FilePicker.pickFile(params,Mojo.Controller.stageController);
555 +       },
556 +       
557 +       selectedAlertFile: function(file) {
558 +       //var params = {"fullPath": encodeURIComponent(file.fullPath), "name":file.name};
559 +       this.setAlertReq = SystemService.setAlerts(file);
560 +       $('currentalert').innerHTML = file.name;
561 +       },
562 +       
563 +       // Notification Picking
564 +       getCurrentNotification: function() {
565 +       this.getCurrentNotificationReq = SystemService.getNotifications(this.getCurrentNotificationQuery.bind(this));
566 +       },
567 +       
568 +       getCurrentNotificationQuery: function(payload) {
569 +       if (payload.notificationtone) {
570 +       $('currentnotification').innerHTML = payload.notificationtone.name;
571 +       this.currNotificationPath = payload.notificationtone.fullPath;
572 +       }
573 +       else 
574 +       $('currentnotification').innerHTML = $L("Pick a notification");
575 +       
576 +       },
577 +       
578 +       showNotificationFilePicker: function(event) {
579 +       var params = {"kinds": ["ringtone"],"filePath":this.currNotificationPath,"onSelect":this.selectedNotificationFile.bind(this),actionType:"attach",actionName: $L("Done")};
580 +       Mojo.FilePicker.pickFile(params,Mojo.Controller.stageController);
581 +       },
582 +       
583 +       selectedNotificationFile: function(file) {
584 +       //var params = {"fullPath": encodeURIComponent(file.fullPath), "name":file.name};
585 +       this.setNotificationReq = SystemService.setNotifications(file);
586 +       $('currentnotification').innerHTML = file.name;
587 +       },
588 +       
589 +       // Message Picking
590 +       getCurrentMessage: function() {
591 +               this.getCurrentMessageReq = SystemService.getMessages(this.getCurrentMessageQuery.bind(this));
592 +       },
593 +       
594 +       getCurrentMessageQuery: function(payload) {
595 +               if (payload.messagetone) {
596 +                       $('currentmessage').innerHTML = payload.messagetone.name;
597 +                       this.currMessagePath = payload.messagetone.fullPath;
598 +               }
599 +               else 
600 +               $('currentmessage').innerHTML = $L("Pick an message");
601 +       
602 +       },
603 +       
604 +       showMessageFilePicker: function(event) {
605 +               var params = {"kinds": ["ringtone"],"filePath":this.currMessagePath,"onSelect":this.selectedMessageFile.bind(this),actionType:"attach",actionName: $L("Done")};
606 +               Mojo.FilePicker.pickFile(params,Mojo.Controller.stageController);
607 +       },
608 +       
609 +       selectedMessageFile: function(file) {
610 +               //var params = {"fullPath": encodeURIComponent(file.fullPath), "name":file.name};
611 +               this.setMessageReq = SystemService.setMessages(file);
612 +               $('currentmessage').innerHTML = file.name;
613 +       },
614 +       
615         getVibrateSettings: function() {
616                 this.getVibrateSettingsReq = AudioService.getVibrateSettings(this.vibrateSettingsCB.bind(this),this);
617         },
618 diff --git a/usr/palm/applications/com.palm.app.soundsandalerts/app/models/SystemService.js b/usr/palm/applications/com.palm.app.soundsandalerts/app/models/SystemService.js
619 index c5babe5..11a7d0a 100644
620 --- a/usr/palm/applications/com.palm.app.soundsandalerts/app/models/SystemService.js
621 +++ b/usr/palm/applications/com.palm.app.soundsandalerts/app/models/SystemService.js
622 @@ -28,6 +28,60 @@ SystemService.getRingtone = function(callback) {
623         return request;
624  }
625  
626 +SystemService.getAlerts = function(callback) {
627 +       var request = new Mojo.Service.Request(SystemService.identifier, {
628 +               method: 'getPreferences',
629 +               parameters: {"keys":["alerttone"]}, 
630 +               onSuccess: callback,
631 +               onFailure: callback
632 +       });
633 +       return request;
634 +}
635 +
636 +SystemService.setAlerts = function(value){
637 +       var request = new Mojo.Service.Request(SystemService.identifier, {
638 +               method: 'setPreferences',
639 +               parameters: {"alerttone":value}, 
640 +       });
641 +       return request;
642 +}
643 +
644 +SystemService.getNotifications = function(callback) {
645 +       var request = new Mojo.Service.Request(SystemService.identifier, {
646 +               method: 'getPreferences',
647 +               parameters: {"keys":["notificationtone"]}, 
648 +               onSuccess: callback,
649 +               onFailure: callback
650 +       });
651 +       return request;
652 +}
653 +
654 +SystemService.setNotifications = function(value){
655 +       var request = new Mojo.Service.Request(SystemService.identifier, {
656 +               method: 'setPreferences',
657 +               parameters: {"notificationtone":value}, 
658 +       });
659 +       return request;
660 +}
661 +
662 +SystemService.getMessages = function(callback) {
663 +       var request = new Mojo.Service.Request(SystemService.identifier, {
664 +               method: 'getPreferences',
665 +               parameters: {"keys":["messagetone"]}, 
666 +               onSuccess: callback,
667 +               onFailure: callback
668 +       });
669 +       return request;
670 +}
671 +
672 +SystemService.setMessages = function(value){
673 +       var request = new Mojo.Service.Request(SystemService.identifier, {
674 +               method: 'setPreferences',
675 +               parameters: {"messagetone":value}, 
676 +       });
677 +       return request;
678 +}
679 +
680  SystemService.getSystemUISounds = function(callback) {
681         var request = new Mojo.Service.Request(SystemService.identifier, {
682                         method: 'getPreferences',
683 diff --git a/usr/palm/applications/com.palm.app.soundsandalerts/app/views/soundsalertsconfig/soundsalertsconfig-scene.html b/usr/palm/applications/com.palm.app.soundsandalerts/app/views/soundsalertsconfig/soundsalertsconfig-scene.html
684 index f59d208..8bd809e 100644
685 --- a/usr/palm/applications/com.palm.app.soundsandalerts/app/views/soundsalertsconfig/soundsalertsconfig-scene.html
686 +++ b/usr/palm/applications/com.palm.app.soundsandalerts/app/views/soundsalertsconfig/soundsalertsconfig-scene.html
687 @@ -52,9 +52,27 @@
688                         </div>
689                     </div>
690              </div>
691 +           <div id='currentalertrow' class="palm-row" x-mojo-tap-highlight="momentary">
692 +               <div class="palm-row-wrapper">
693 +                               <div class="label" x-mojo-loc=''>Alert</div>
694 +                       <div id='currentalert' class="title"></div> 
695 +               </div>
696 +           </div>
697 +           <div id='currentnotificationrow' class="palm-row" x-mojo-tap-highlight="momentary">
698 +                       <div class="palm-row-wrapper">
699 +                               <div class="label" x-mojo-loc=''>Notification</div>
700 +                       <div id='currentnotification' class="title"></div>  
701 +               </div>
702 +           </div>
703 +           <div id='currentmessagerow' class="palm-row" x-mojo-tap-highlight="momentary">
704 +                       <div class="palm-row-wrapper">
705 +                               <div class="label" x-mojo-loc=''>Messages</div>
706 +                       <div id='currentmessage' class="title"></div>     
707 +               </div>
708 +           </div>            
709                         <div class="palm-row last">
710                                 <div class="palm-row-wrapper">
711 -                                       <div class="title" x-mojo-loc=''>Volume</div>
712 +                                       <div class="title" x-mojo-loc=''>System Volume</div>
713                                         <div x-mojo-element="Slider" id='systemvolume' class="palm-slider"></div>
714                     </div>
715              </div>