New system menus patches
[webos-internals:jeffrotulls-modifications.git] / advanced / advanced-system-menus-power-menu.patch
1 --- .orig/usr/lib/luna/system/luna-systemui/app/controllers/bar-assistant.js
2 +++ /usr/lib/luna/system/luna-systemui/app/controllers/bar-assistant.js
3 @@ -460,12 +460,12 @@
4                 }
5         }       
6         
7 -       if(!this.deviceLocked) {
8 +/*     if(!this.deviceLocked) {
9                 var appController = Mojo.Controller.getAppController();
10                 var stageController = appController.getStageController("PowerOffAlert");
11                 if(stageController)
12                         stageController.delegateToSceneAssistant("cancelTimer");
13 -       }
14 +       } */
15  },
16  
17  isDeviceLocked: function() {
18 @@ -2612,9 +2612,9 @@
19      if (payload["mode-avail"]) {
20                 this.isUSBConnected = true;
21                 if (!this.onActiveCall) {
22 -                       if (this.canUSBAlertDisplayed()) 
23 -                               this.showStorageModeAlert();
24 -                       else 
25 +//                     if (this.canUSBAlertDisplayed()) 
26 +//                             this.showStorageModeAlert();
27 +//                     else 
28                                 this.createUSBDashboard();
29                 }
30         }
31 @@ -2730,10 +2730,10 @@
32                                 Mojo.Log.info("SystemUI - USB Is connected(During Init)" + Object.toJSON(payload));
33                                 this.isUSBConnected = true;
34                                 if (!this.onActiveCall) {
35 -                                       if (this.updateAvailable) 
36 +//                                     if (this.updateAvailable) 
37                                                 this.createUSBDashboard();
38 -                                       else 
39 -                                               this.showStorageModeAlert();
40 +//                                     else 
41 +//                                             this.showStorageModeAlert();
42                                 }                                                       
43                         }
44                 }.bind(this),
45 @@ -2807,6 +2807,16 @@
46   * Register to receive power off notifications
47   */
48  powerOffInit: function() {
49 +       this.powerMenuCfg = {items: ["shutdownDevice", "restartDevice"], allowSleep: true};
50 +
51 +       var cookieContainer = new Mojo.Model.Cookie("powerMenu");
52 +               
53 +       var cookie = cookieContainer.get();
54 +
55 +       if(cookie) {
56 +               this.powerMenuCfg.items = cookie.menuItems;
57 +       }
58 +
59      this.powerOffNotificationSession = new Mojo.Service.Request('palm://com.palm.bus/signal/', {
60                 method: 'addmatch',
61                 parameters: {
62 @@ -2844,21 +2854,39 @@
63         
64         var appController = Mojo.Controller.getAppController();
65         var stageController = appController.getStageController("PowerOffAlert");
66 +       
67 +               if (stageController) {
68 +                       appController.closeStage("PowerOffAlert");
69 +
70 +                       var f = function(stageController){
71 +                     stageController.pushScene('poweroffalert',this, this.powerMenuCfg, true);
72 +                   }.bind(this);
73 +                   var params = {name: 'PowerOffAlertEdit', height: 240,lightweight:true};
74 +               
75 +                   appController.createStageWithCallback(params,f,'popupalert');
76 +               }
77 +               else {
78 +                       appController.closeStage("PowerOffAlertEdit");
79 +               
80          // if the window already exists, don't do anything
81          if (!stageController) {
82                 // Create a popuo alert
83                     var f = function(stageController){
84 -                     stageController.pushScene('poweroffalert',this);
85 +                     stageController.pushScene('poweroffalert',this, this.powerMenuCfg, false);
86                     }.bind(this);
87 -                   var params = {name: 'PowerOffAlert', height: 175,lightweight:true};                     
88 +                   
89 +                        var popupHeight = (this.powerMenuCfg.items.length + 1) * 55 + 10;
90 +                   
91 +                   var params = {name: 'PowerOffAlert', height: popupHeight,lightweight:true};
92                     appController.createStageWithCallback(params,f,'popupalert');
93          }
94 +       }
95         //Close the Storage Alert and create a USB dashboard.
96 -       var storageAlertStageController = appController.getStageController('StorageModeAlert');
97 +/*     var storageAlertStageController = appController.getStageController('StorageModeAlert');
98         if(storageAlertStageController) {
99                 storageAlertStageController.delegateToSceneAssistant("closeAndCreateDashboard");
100                 this.createUSBDashboard.bind(this).delay(0.5,false);
101 -       }
102 +       } */
103                         
104  },
105      
106 --- .orig/usr/lib/luna/system/luna-systemui/app/controllers/poweroffalert-assistant.js
107 +++ /usr/lib/luna/system/luna-systemui/app/controllers/poweroffalert-assistant.js
108 @@ -1,21 +1,43 @@
109  /* Copyright 2009 Palm, Inc.  All rights reserved. */
110  
111  var PoweroffalertAssistant = Foundations.Class.create({
112 -    initialize: function(barAssistant) {       
113 +    initialize: function(barAssistant, menuCfg, editMenu) {    
114                 this.barAssistant = barAssistant;       
115 +               this.menuCfg = menuCfg;
116 +               this.editMenu = editMenu;
117      },
118      
119      setup: function() {                
120 +       if(this.editMenu) {
121 +                       this.controller.get('powermenu').hide();
122 +                       this.controller.get('editmenu').show();
123 +
124 +                       for(var i = 0; i < this.menuCfg.items.length; i++)
125 +                               this.controller.get(this.menuCfg.items[i] + "State").update("SHOW");
126 +               }
127 +               else {
128 +                       for(var i = 0; i < this.menuCfg.items.length; i++)
129 +                               this.controller.get(this.menuCfg.items[i] + "Button").show();
130 +               }
131 +               
132 +               var luna = this.luna.bindAsEventListener(this);
133 +               var sleep = this.sleep.bindAsEventListener(this);
134 +               var restart = this.restart.bindAsEventListener(this);
135                 var flightMode = this.flightMode.bindAsEventListener(this);
136 -               var powerOff = this.powerOff.bindAsEventListener(this);
137 +               var powerOff = this.shutdown.bindAsEventListener(this);
138                 var cancel = this.cancel.bindAsEventListener(this);
139                 var launchAirplaneModeHelp = this.launchAirplaneModeHelp.bindAsEventListener(this);
140                 this.flightMode = this.barAssistant.getAirplaneMode();
141                 if(this.flightMode)
142                         this.controller.get('flightmode').innerHTML = $L('Turn off Airplane Mode');
143 -               else
144 -                       this.controller.get('flightmode').innerHTML = "<div class='info-icon' id='airplaneInfo' x-mojo-touch-feedback='immediate'></div>" + $L('Airplane Mode');
145 +//             else
146 +//                     this.controller.get('flightmode').innerHTML = "<div class='info-icon' id='airplaneInfo' x-mojo-touch-feedback='immediate'></div>" + $L('Airplane Mode');
147 +               if(!this.menuCfg.allowSleep)
148 +                       this.controller.get('sleep').innerHTML = $L('Enable Device Sleep');
149                         
150 +               this.controller.get('luna').addEventListener(Mojo.Event.tap, luna);
151 +               this.controller.get('sleep').addEventListener(Mojo.Event.tap, sleep);
152 +               this.controller.get('restart').addEventListener(Mojo.Event.tap, restart);
153                 this.controller.get('poweroff').addEventListener(Mojo.Event.tap, powerOff);
154                 this.controller.get('flightmode').addEventListener(Mojo.Event.tap, flightMode);
155                 this.controller.get('cancel').addEventListener(Mojo.Event.tap, cancel);
156 @@ -26,6 +48,35 @@
157                         this.powerOffAlertCancel = this.cancel.bind(this);
158                         this.powerOffAlertTimer = this.controller.window.setTimeout(this.powerOffAlertCancel, 30000);
159                 }
160 +
161 +               this.controller.get('airplaneModeEdit').addEventListener(Mojo.Event.tap, this.editToggle.bind(this, "airplaneMode"));
162 +               this.controller.get('deviceSleepEdit').addEventListener(Mojo.Event.tap, this.editToggle.bind(this, "deviceSleep"));
163 +               this.controller.get('shutdownDeviceEdit').addEventListener(Mojo.Event.tap, this.editToggle.bind(this, "shutdownDevice"));
164 +               this.controller.get('restartDeviceEdit').addEventListener(Mojo.Event.tap, this.editToggle.bind(this, "restartDevice"));
165 +               this.controller.get('restartLunaEdit').addEventListener(Mojo.Event.tap, this.editToggle.bind(this, "restartLuna"));
166 +       },
167 +       
168 +       editToggle: function(item) {
169 +               var index = this.menuCfg.items.indexOf(item);
170 +               
171 +               if(index == -1) {
172 +                       this.controller.get(item + "State").update("SHOW");
173 +                       
174 +                       this.menuCfg.items.push(item);
175 +               }
176 +               else {
177 +                       this.controller.get(item + "State").update("HIDE");
178 +                       
179 +                       this.menuCfg.items.splice(index, 1);
180 +               }
181 +               
182 +               var cookieContainer = new Mojo.Model.Cookie("powerMenu");
183 +               
184 +               var cookie = {
185 +                       menuItems: this.menuCfg.items
186 +               }
187 +               
188 +               cookieContainer.put(cookie);
189         },
190         
191         cleanup: function() {
192 @@ -33,6 +84,44 @@
193              this.controller.window.clearTimeout(this.powerOffAlertTimer);
194          } catch(e) {}
195         },
196 +
197 +       luna: function() {
198 +               var request = new Mojo.Service.Request('palm://org.webosinternals.ipkgservice/', {
199 +                       method: 'restartLuna'});
200 +       },
201 +               
202 +       sleep: function() {
203 +               if(this.menuCfg.allowSleep) {
204 +                       this.menuCfg.allowSleep = false;
205 +                       
206 +                       this.request = this.controller.serviceRequest("palm://com.palm.display/control", {
207 +                               method: "setProperty", parameters: {requestBlock: true, client: "powerMenu"}});
208 +
209 +                       this.request = this.controller.serviceRequest("palm://com.palm.power/com/palm/power", {
210 +                               method: "activityStart", parameters: {id: "com.palm.systemui", duration_ms: '86400000'}});
211 +               }
212 +               else {
213 +                       this.menuCfg.allowSleep = true;
214 +
215 +                       this.request = this.controller.serviceRequest("palm://com.palm.display/control", {
216 +                               method: "setProperty", parameters: {requestBlock: false, client: "powerMenu"}});
217 +
218 +                       this.request = this.controller.serviceRequest("palm://com.palm.power/com/palm/power", {
219 +                               method: "activityEnd", parameters: {id: "com.palm.systemui"}});
220 +               }       
221 +
222 +               this.controller.window.close();
223 +       },
224 +       
225 +       restart: function() {
226 +               this.barAssistant.machineReboot("Restart request by User");
227 +               this.controller.window.close();
228 +       },
229 +       
230 +       shutdown:function() {
231 +               this.barAssistant.machineOffNow("Shutdown request by User");
232 +               this.controller.window.close();
233 +       },
234         
235         powerOff:function() {   
236                 var appController = Mojo.Controller.getAppController();
237 --- .orig/usr/lib/luna/system/luna-systemui/app/views/poweroffalert/poweroffalert-scene.html
238 +++ /usr/lib/luna/system/luna-systemui/app/views/poweroffalert/poweroffalert-scene.html
239 @@ -1,5 +1,47 @@
240  <div class="system-notification power-off">
241 -               <div class="palm-notification-button affirmative" x-mojo-tap-highlight="immediate" id='flightmode' x-mojo-loc=''></div>
242 -               <div class="palm-notification-button negative" x-mojo-tap-highlight="immediate" id='poweroff' x-mojo-loc=''>Power</div>
243 -               <div class="palm-notification-button" x-mojo-tap-highlight="immediate" id='cancel' x-mojo-loc=''>Cancel</div>
244 -</div>
245 \ No newline at end of file
246 +       <div id="powermenu">
247 +               <div id="airplaneModeButton" style="display:none;">
248 +                       <div class="palm-notification-button affirmative" x-mojo-tap-highlight="immediate" id='flightmode' x-mojo-loc=''>Turn on Airplane Mode</div>
249 +               </div>
250 +               <div id="deviceSleepButton" style="display:none;">
251 +                       <div class="palm-notification-button affirmative" x-mojo-tap-highlight="immediate" id='sleep' x-mojo-loc=''>Disable Device Sleep</div>
252 +               </div>
253 +               <div id="shutdownDeviceButton" style="display:none;">
254 +                       <div class="palm-notification-button negative" x-mojo-tap-highlight="immediate" id='poweroff' x-mojo-loc=''>Shut Down Device</div>
255 +               </div>
256 +               <div id="restartDeviceButton" style="display:none;">
257 +                       <div class="palm-notification-button alternate" x-mojo-tap-highlight="immediate" id='restart' x-mojo-loc=''>Restart Device</div>
258 +               </div>
259 +               <div id="restartLunaButton" style="display:none;">
260 +                       <div class="palm-notification-button alternate" x-mojo-tap-highlight="immediate" id='luna' x-mojo-loc=''>Restart Luna</div>
261 +               </div>
262 +               <div id="cancelButton" style="display:block;">
263 +                       <div class="palm-notification-button" x-mojo-tap-highlight="immediate" id='cancel' x-mojo-loc=''>Cancel</div>
264 +               </div>
265 +       </div>
266 +       <div id="editmenu" style="display: none;">
267 +               <div style="font-size: 20px;text-align:center;padding:6px;">Menu Content Settings</div>
268 +               <div style="padding:5px;padding-left:15px;padding-right:15px;"><div style="background:gray;min-height:1px;"></div></div>
269 +               
270 +               <div id="airplaneModeEdit">
271 +                       <div id="airplaneModeState" style="font-size:12px;float:right;color:gray;padding:8px;padding-top:11px;padding-right:25px;">HIDE</div>
272 +                       <div style="font-size:16px;padding:8px;padding-left:25px;">Airplane Mode Toggle</div>
273 +               </div>
274 +               <div id="deviceSleepEdit">
275 +                       <div id="deviceSleepState" style="font-size:12px;float:right;color:gray;padding:8px;padding-top:11px;padding-right:25px;">HIDE</div>
276 +                       <div style="font-size:16px;padding:8px;padding-left:25px;">Device Sleep Toggle</div>
277 +               </div>
278 +               <div id="shutdownDeviceEdit">
279 +                       <div id="shutdownDeviceState" style="font-size:12px;float:right;color:gray;padding:8px;padding-top:11px;padding-right:25px;">HIDE</div>
280 +                       <div style="font-size:16px;padding:8px;padding-left:25px;">Shut Down Device Action</div>
281 +               </div>
282 +               <div id="restartDeviceEdit">
283 +                       <div id="restartDeviceState" style="font-size:12px;float:right;color:gray;padding:8px;padding-top:11px;padding-right:25px;">HIDE</div>
284 +                       <div style="font-size:16px;padding:8px;padding-left:25px;">Restart Device Action</div>
285 +               </div>
286 +               <div id="restartLunaEdit">
287 +                       <div id="restartLunaState" style="font-size:12px;float:right;color:gray;padding:8px;padding-top:11px;padding-right:25px;">HIDE</div>
288 +                       <div style="font-size:16px;padding:8px;padding-left:25px;">Restart Luna Action</div>
289 +               </div>
290 +       </div>
291 +</div>