Refactor WiFi module 94/12494/1
authorJimmy Huang <jimmy.huang@intel.com>
Wed, 13 Nov 2013 19:56:46 +0000 (11:56 -0800)
committerJimmy Huang <jimmy.huang@intel.com>
Fri, 15 Nov 2013 22:29:10 +0000 (14:29 -0800)
- Renamed WiFi settings to Connman settings to support different connman technologies
- Fixed event handling for connman property changes
- Added support for adding unknown/hidden networks
- Added support to connect to protected networks

Change-Id: I15557ff56582b7202d20a0e55d78ce0af432b266
Signed-off-by: Jimmy Huang <jimmy.huang@intel.com>
css/style.css
index.html
js/api-connman.js [new file with mode: 0644]
js/api-wifi.js [deleted file]
js/main.js
js/panel-bluetooth.js
js/panel-connman.js [new file with mode: 0644]
js/panel-wifi.js [deleted file]
js/utils.js
js/websocket.js
packaging/Settings.changes

index b19f5a0..b8f6d66 100644 (file)
     margin: auto;
     right: 10px;
 }
-/* WiFi */
-#wifi_networks {
-    display: none;
-}
-.network-connected .network-status {
+/* Connman */
+.service-connected .service-status {
     color: green;
 }
-.network-ssid {
+.service-ssid {
     font-size: 15px;
 }
-.network-encryption {
+.service-encryption {
     font-size: 10px;
 }
-.network-strength {
+.service-strength {
     font-size: 10px;
 }
-.network-address {
+.service-address {
     font-size: 10px;
 }
-.network-status {
+.service-status {
     font-size: 10px;
 }
-.network-action-button {
+.service-action-button {
     max-width: 150px;
     text-align: center;
 }
 /* make the button text so that it doesn't add the ellipsis */
-.network-action-button .ui-btn-inner {
+.service-action-button .ui-btn-inner {
     text-overflow: initial;
 }
 /* make room for bottom for bottom of the screen due to weston compositor */
-#button_wifi_add {
+#button_connman_wifi_add {
     margin-bottom: 100px;
 }
 /* Bluetooth */
index 22b4f69..530cd5a 100644 (file)
 *
 -->
 <html>
+
 <head>
     <meta charset="utf-8" />
     <!-- <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"> -->
 
     <title>Settings</title>
 
-    <link rel="stylesheet" href="./css/jquery.mobile-1.3.1.css"/>
+    <link rel="stylesheet" href="./css/jquery.mobile-1.3.1.css" />
     <script type="text/javascript" src="./js/jquery-1.10.1.js"></script>
     <script type="text/javascript" src="./js/jquery.mobile-1.3.1.js"></script>
     <script type="text/javascript" src="./js/main.js"></script>
     <script type="text/javascript" src="./js/utils.js"></script>
     <script type="text/javascript" src="./js/websocket.js"></script>
-    <script type="text/javascript" src="./js/api-wifi.js"></script>
+    <script type="text/javascript" src="./js/api-connman.js"></script>
     <script type="text/javascript" src="./js/api-bluetooth.js"></script>
     <script type="text/javascript" src="./js/api-datetime.js"></script>
-    <script type="text/javascript" src="./js/panel-wifi.js"></script>
+    <script type="text/javascript" src="./js/panel-connman.js"></script>
     <script type="text/javascript" src="./js/panel-bluetooth.js"></script>
     <script type="text/javascript" src="./js/panel-datetime.js"></script>
     <link rel="stylesheet" href="./css/style.css" />
 </head>
 
 <body>
-       <!-- Settings -->
+    <!-- Settings -->
     <div data-role="page" id="main">
         <div data-role="header" data-position="fixed">
-               <a href="" id="quit" data-icon="back">Quit</a>
+            <a href="" id="quit" data-icon="back">Quit</a>
             <h1>Settings</h1>
-        </div><!-- /header -->
+        </div>
+        <!-- /header -->
 
-               <div data-role="collapsible-set">
-                   <div data-role="collapsible" id="col_connectivity" data-collapsed="false">
-                       <h3>Connectivity</h3>
-                               <div data-role="content">
-                                   <ul data-role="listview">
-                               <li>
-                                   <a href="#page_wifi" id="button_wifi_settings">Wi-Fi</a>
-                               </li>
-                               <li>
-                                   <a href="#page_bluetooth" id="button_bluetooth_settings">Bluetooth</a>
-                               </li>
-                                   </ul>
-                               </div>
-                   </div>
-               </div>
+        <div data-role="collapsible-set">
+            <div data-role="collapsible" id="col_connectivity" data-collapsed="false">
+                <h3>Connectivity</h3>
+                <div data-role="content">
+                    <ul data-role="listview">
+                        <li>
+                            <a href="#page_connman" id="button_connman_settings">Connman</a>
+                        </li>
+                        <li>
+                            <a href="#page_bluetooth" id="button_bluetooth_settings">Bluetooth</a>
+                        </li>
+                    </ul>
+                </div>
+            </div>
+        </div>
 
-               <div data-role="collapsible-set">
-                   <div data-role="collapsible" id="col_system" data-collapsed="false">
-                       <h3>System</h3>
-                               <div data-role="content">
-                                   <ul data-role="listview">
-                               <li>
-                                   <a href="#page_datetime" id="button_datetime_settings">Date and Time</a>
-                               </li>
-                                   </ul>
-                               </div>
-                   </div>
-               </div>
-       </div>
+        <div data-role="collapsible-set">
+            <div data-role="collapsible" id="col_system" data-collapsed="false">
+                <h3>System</h3>
+                <div data-role="content">
+                    <ul data-role="listview">
+                        <li>
+                            <a href="#page_datetime" id="button_datetime_settings">Date and Time</a>
+                        </li>
+                    </ul>
+                </div>
+            </div>
+        </div>
+    </div>
 
-       <!-- Wi-Fi Settings -->
-       <div data-role="page" id="page_wifi">
-               <div data-role="header" data-position="fixed">
-                       <a href="#main" data-icon="back">Back</a>
-                       <h1>Wi-Fi</h1>
-               </div>
+    <!-- Connman Settings -->
+    <div data-role="page" id="page_connman">
+        <div data-role="header" data-position="fixed">
+            <a href="#main" data-icon="back">Back</a>
+            <h1>Connman</h1>
+        </div>
 
-               <div data-role="content">
-            <div class="adapter-info">
-                <div class="adapter-name">
-                    <div id="label_wifi_adapter"></div>
-                </div>
+        <div data-role="content">
+            <div>
+                <p>Technologies</p>
             </div>
-            <ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">
-                <li data-role="fieldcontain">
-                    <label for="toggle_wifi" class="ui-slider">WiFi</label>
-                    <select data-role="slider" name="toggle_wifi" id="toggle_wifi" class="ui-slider-switch">
-                        <option value="off">Off</option>
-                        <option value="on">On</option>
-                    </select>
-                </li>
-            </ul>
-            <div id="wifi_networks">
-                <div><p>Available Networks</p></div>
-                <ul data-role="listview" id="listview_network_known" data-inset="true" class="device-list ui-listview"></ul>
-                <ul data-role="listview" id="listview_network_available" data-inset="true" class="device-list ui-listview"></ul>
-                <div data-role="button" id="button_wifi_refresh">Refresh</div>
-                <div data-role="button" id="button_wifi_add">Add</div>
+            <div id="connman_technologies">
+                <ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">
+                    <li data-role="fieldcontain">
+                        <label for="toggle_connman_wifi" class="ui-slider">WiFi</label>
+                        <select data-role="slider" name="toggle_connman_wifi" id="toggle_connman_wifi" class="ui-slider-switch">
+                            <option value="off">Off</option>
+                            <option value="on">On</option>
+                        </select>
+                    </li>
+                </ul>
+            </div>
+            <div id="connman_services">
+                <div>
+                    <p>Available Services</p>
+                </div>
+                <ul data-role="listview" id="listview_services_connected" data-inset="true" class="device-list ui-listview"></ul>
+                <ul data-role="listview" id="listview_services_available" data-inset="true" class="device-list ui-listview"></ul>
+                <div data-role="button" id="button_connman_refresh">Refresh</div>
+                <div data-role="button" id="button_connman_wifi_add">Add</div>
             </div>
-               </div>
-       </div>
+        </div>
+    </div>
 
-    <!-- WiFi Network Info -->
-    <div data-role="page" id="page_wifi_detail">
+    <!-- Connman Service Info -->
+    <div data-role="page" id="page_connman_service">
         <div data-role="header" data-position="fixed">
-            <a href="#page_wifi" data-icon="back">Back</a>
-            <h1>Network Info</h1>
+            <a href="#page_connman" data-icon="back">Back</a>
+            <h1>Service Info</h1>
         </div>
 
-        <div data-role="content" id="page_wifi_detail_content">
+        <div data-role="content" id="page_connman_service_content">
         </div>
     </div>
 
     <!-- WiFi Add New Network -->
     <div data-role="page" id="page_wifi_add">
         <div data-role="header" data-position="fixed">
-            <a href="#page_wifi" id="page_wifi_button_back" data-icon="back">Back</a>
+            <a href="#page_connman" data-icon="back">Back</a>
             <h1>Add Network</h1>
-            <a href="#" id="page_wifi_button_add" data-icon="plus">Add</a>
+            <a href="#" id="button_wifi_add" data-icon="plus">Add</a>
         </div>
 
         <div data-role="content" id="page_wifi_add_content">
-            <label for="input_wifi_ssid">SSID:</label>
-            <input type="text" name="name" id="input_wifi_ssid" value="" />
+            <label for="input_wifi_add_ssid">SSID:</label>
+            <input type="text" name="name" id="input_wifi_add_ssid" value="" />
+
+            <label for="select_wifi_add_security" class="select">Security:</label>
+            <fieldset data-role="controlgroup" data-type="horizontal">
+                <input type="radio" name="radio_wifi_security" id="radio_wifi_none" value="none" checked="checked" />
+                <label for="radio_wifi_none">None</label>
+
+                <input type="radio" name="radio_wifi_security" id="radio_wifi_wep" value="wep" />
+                <label for="radio_wifi_wep">WEP</label>
 
-            <label for="select_wifi_security" class="select">Security:</label>
+                <input type="radio" name="radio_wifi_security" id="radio_wifi_wpa" value="tkip" />
+                <label for="radio_wifi_wpa">WPA</label>
+
+                <input type="radio" name="radio_wifi_security" id="radio_wifi_wpa2" value="aes" />
+                <label for="radio_wifi_wpa2">WPA2</label>
+            </fieldset>
             <ul data-role="listview" data-inset="true" class="device-list ui-listview">
-                <li>
-                    <select name="select_wifi_security" id="select_wifi_security">
-                        <option value="None">None</option>
-                        <option value="WEP">WEP</option>
-                        <option value="WPA">WPA</option>
-                        <option value="WPA2">WPA2</option>
-                        <option value="WPA_Enterprise">WPA Enterprise</option>
-                        <option value="WPA2_Enterprise">WPA2 Enterprise</option>
-                    </select>
+                <li id="page_wifi_add_password">
+                    <label for="input_wifi_add_password">Password:</label>
+                    <input type="password" name="name" id="input_wifi_add_password" value="" />
                 </li>
-                <li id="page_wifi_password">
-                    <label for="input_wifi_password">Password:</label>
-                    <input type="password" name="name" id="input_wifi_password" value="" />
+            </ul>
+        </div>
+    </div>
+
+    <!-- WiFi Connect Encryppted Network -->
+    <div data-role="page" id="page_wifi_connect">
+        <div data-role="header" data-position="fixed">
+            <a href="#page_connman" data-icon="back">Back</a>
+            <h1>Enter passphrase</h1>
+        </div>
+
+        <div data-role="content" id="page_wifi_connect_content">
+            <ul data-role="listview" data-inset="true" class="device-list ui-listview">
+                <li id="page_wifi_connect_passphrase">
+                    <label for="input_wifi_connect_passphrase">Password:</label>
+                    <input type="password" name="name" id="input_wifi_connect_passphrase" value="" />
                 </li>
             </ul>
+            <div data-role="button" id="button_wifi_connect">Connect</div>
         </div>
     </div>
-       
-       <!-- Bluetooth Settings -->
-       <div data-role="page" id="page_bluetooth">
-               <div data-role="header" data-position="fixed">
-                       <a href="#main" data-icon="back">Back</a>
-                       <h1>Bluetooth</h1>
-               </div>
 
-               <div data-role="content">
-               <div class="adapter-info">  
-                   <div class="adapter-name">
-                       <div id="label_bluetooth_adapter"></div>
-                   </div>
-               </div>
-                       <ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">
-                               <li data-role="fieldcontain">
-                                       <label for="toggle_bluetooth" class="ui-slider">Bluetooth</label>
-                                       <select data-role="slider" name="toggle_bluetooth" id="toggle_bluetooth" class="ui-slider-switch">
-                                               <option value="off">Off</option>
-                                               <option value="on">On</option>
-                                       </select>
-                               </li>
-                       </ul>
-                       <div id="bluetooth_devices">
-                           <div><p>Available Devices</p></div>
+    <!-- Bluetooth Settings -->
+    <div data-role="page" id="page_bluetooth">
+        <div data-role="header" data-position="fixed">
+            <a href="#main" data-icon="back">Back</a>
+            <h1>Bluetooth</h1>
+        </div>
+
+        <div data-role="content">
+            <div class="adapter-info">
+                <div class="adapter-name">
+                    <div id="label_bluetooth_adapter"></div>
+                </div>
+            </div>
+            <ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">
+                <li data-role="fieldcontain">
+                    <label for="toggle_bluetooth" class="ui-slider">Bluetooth</label>
+                    <select data-role="slider" name="toggle_bluetooth" id="toggle_bluetooth" class="ui-slider-switch">
+                        <option value="off">Off</option>
+                        <option value="on">On</option>
+                    </select>
+                </li>
+            </ul>
+            <div id="bluetooth_devices">
+                <div>
+                    <p>Available Devices</p>
+                </div>
                 <ul data-role="listview" id="listview_device_paired" data-inset="true" class="device-list ui-listview"></ul>
-                   <ul data-role="listview" id="listview_device_available" data-inset="true" class="device-list ui-listview"></ul>
-                           <div data-role="button" id="button_bluetooth_scan">Scan</div>
-                       </div>
-               </div>
-       </div>
+                <ul data-role="listview" id="listview_device_available" data-inset="true" class="device-list ui-listview"></ul>
+                <div data-role="button" id="button_bluetooth_scan">Scan</div>
+            </div>
+        </div>
+    </div>
 
     <!-- Bluetooth Device Info -->
     <div data-role="page" id="page_bluetooth_detail">
         </div>
     </div>
 
-       <!--  Date and Time Settings -->
-       <div data-role="page" id="page_datetime">
-               <div data-role="header" data-position="fixed">
-                       <a href="#main" id="page_datetime_button_back" data-icon="back">Back</a>
-                       <h1>Date and Time</h1>
-               </div>
+    <!--  Date and Time Settings -->
+    <div data-role="page" id="page_datetime">
+        <div data-role="header" data-position="fixed">
+            <a href="#main" id="page_datetime_button_back" data-icon="back">Back</a>
+            <h1>Date and Time</h1>
+        </div>
 
-               <div data-role="content">
-                   <ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">
-                       <li data-role="fieldcontain">
-                <label for="toggle_timeupdates" class="ui-slider">Automatic time</label>
-                <select data-role="slider" name="toggle_timeupdates" id="toggle_timeupdates" class="ui-slider-switch">
-                    <option value="manual">Off</option>
-                    <option value="auto">On</option>
+        <div data-role="content">
+            <ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">
+                <li data-role="fieldcontain">
+                    <label for="toggle_timeupdates" class="ui-slider">Automatic time</label>
+                    <select data-role="slider" name="toggle_timeupdates" id="toggle_timeupdates" class="ui-slider-switch">
+                        <option value="manual">Off</option>
+                        <option value="auto">On</option>
                     </select>
                 </li>
             </ul>
-                       <ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">
-                               <li data-role="fieldcontain">
-                                       <label for="input_time">Time (hh:mm:ss):</label>
-                                       <input type="text" data-clear-btn="false" name="input_time" id="input_time" value="">
-                               </li>
-                       </ul>
+            <ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">
+                <li data-role="fieldcontain">
+                    <label for="input_time">Time (hh:mm:ss):</label>
+                    <input type="text" data-clear-btn="false" name="input_time" id="input_time" value="">
+                </li>
+            </ul>
             <ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">
                 <li data-role="fieldcontain">
                     <label for="input_date">Date (yyyy-mm-dd):</label>
             </ul>
             <ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">
                 <li data-role="fieldcontain">
-                <label for="toggle_timezoneupdates" class="ui-slider">Automatic time zone</label>
-                <select data-role="slider" name="toggle_timezoneupdates" id="toggle_timezoneupdates" class="ui-slider-switch">
-                    <option value="manual">Off</option>
-                    <option value="auto">On</option>
+                    <label for="toggle_timezoneupdates" class="ui-slider">Automatic time zone</label>
+                    <select data-role="slider" name="toggle_timezoneupdates" id="toggle_timezoneupdates" class="ui-slider-switch">
+                        <option value="manual">Off</option>
+                        <option value="auto">On</option>
+                    </select>
+                </li>
+            </ul>
+            <ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">
+                <li data-role="fieldcontain">
+                    <label for="select_timezone" class="select">Time zone:</label>
+                    <select name="select_timezone" id="select_timezone" data-native-menu="false">
+                        <option value="Pacific/Midway">(GMT-11:00) Midway Island, Samoa</option>
+                        <option value="America/Adak">(GMT-10:00) Hawaii-Aleutian</option>
+                        <option value="Etc/GMT+10">(GMT-10:00) Hawaii</option>
+                        <option value="Pacific/Marquesas">(GMT-09:30) Marquesas Islands</option>
+                        <option value="Pacific/Gambier">(GMT-09:00) Gambier Islands</option>
+                        <option value="America/Anchorage">(GMT-09:00) Alaska</option>
+                        <option value="America/Ensenada">(GMT-08:00) Tijuana, Baja California</option>
+                        <option value="Etc/GMT+8">(GMT-08:00) Pitcairn Islands</option>
+                        <option value="America/Los_Angeles">(GMT-08:00) Pacific Time (US & Canada)</option>
+                        <option value="America/Denver">(GMT-07:00) Mountain Time (US & Canada)</option>
+                        <option value="America/Chihuahua">(GMT-07:00) Chihuahua, La Paz, Mazatlan</option>
+                        <option value="America/Dawson_Creek">(GMT-07:00) Arizona</option>
+                        <option value="America/Belize">(GMT-06:00) Saskatchewan, Central America</option>
+                        <option value="America/Cancun">(GMT-06:00) Guadalajara, Mexico City, Monterrey</option>
+                        <option value="Chile/EasterIsland">(GMT-06:00) Easter Island</option>
+                        <option value="America/Chicago">(GMT-06:00) Central Time (US & Canada)</option>
+                        <option value="America/New_York">(GMT-05:00) Eastern Time (US & Canada)</option>
+                        <option value="America/Havana">(GMT-05:00) Cuba</option>
+                        <option value="America/Bogota">(GMT-05:00) Bogota, Lima, Quito, Rio Branco</option>
+                        <option value="America/Caracas">(GMT-04:30) Caracas</option>
+                        <option value="America/Santiago">(GMT-04:00) Santiago</option>
+                        <option value="America/La_Paz">(GMT-04:00) La Paz</option>
+                        <option value="Atlantic/Stanley">(GMT-04:00) Faukland Islands</option>
+                        <option value="America/Campo_Grande">(GMT-04:00) Brazil</option>
+                        <option value="America/Goose_Bay">(GMT-04:00) Atlantic Time (Goose Bay)</option>
+                        <option value="America/Glace_Bay">(GMT-04:00) Atlantic Time (Canada)</option>
+                        <option value="America/St_Johns">(GMT-03:30) Newfoundland</option>
+                        <option value="America/Araguaina">(GMT-03:00) UTC-3</option>
+                        <option value="America/Montevideo">(GMT-03:00) Montevideo</option>
+                        <option value="America/Miquelon">(GMT-03:00) Miquelon, St. Pierre</option>
+                        <option value="America/Godthab">(GMT-03:00) Greenland</option>
+                        <option value="America/Argentina/Buenos_Aires">(GMT-03:00) Buenos Aires</option>
+                        <option value="America/Sao_Paulo">(GMT-03:00) Brasilia</option>
+                        <option value="America/Noronha">(GMT-02:00) Mid-Atlantic</option>
+                        <option value="Atlantic/Cape_Verde">(GMT-01:00) Cape Verde Is.</option>
+                        <option value="Atlantic/Azores">(GMT-01:00) Azores</option>
+                        <option value="Europe/Belfast">(GMT) Greenwich Mean Time : Belfast</option>
+                        <option value="Europe/Dublin">(GMT) Greenwich Mean Time : Dublin</option>
+                        <option value="Europe/Lisbon">(GMT) Greenwich Mean Time : Lisbon</option>
+                        <option value="Europe/London">(GMT) Greenwich Mean Time : London</option>
+                        <option value="Africa/Abidjan">(GMT) Monrovia, Reykjavik</option>
+                        <option value="Europe/Amsterdam">(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna</option>
+                        <option value="Europe/Belgrade">(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague</option>
+                        <option value="Europe/Brussels">(GMT+01:00) Brussels, Copenhagen, Madrid, Paris</option>
+                        <option value="Africa/Algiers">(GMT+01:00) West Central Africa</option>
+                        <option value="Africa/Windhoek">(GMT+01:00) Windhoek</option>
+                        <option value="Asia/Beirut">(GMT+02:00) Beirut</option>
+                        <option value="Africa/Cairo">(GMT+02:00) Cairo</option>
+                        <option value="Asia/Gaza">(GMT+02:00) Gaza</option>
+                        <option value="Africa/Blantyre">(GMT+02:00) Harare, Pretoria</option>
+                        <option value="Asia/Jerusalem">(GMT+02:00) Jerusalem</option>
+                        <option value="Europe/Minsk">(GMT+02:00) Minsk</option>
+                        <option value="Asia/Damascus">(GMT+02:00) Syria</option>
+                        <option value="Europe/Moscow">(GMT+03:00) Moscow, St. Petersburg, Volgograd</option>
+                        <option value="Africa/Addis_Ababa">(GMT+03:00) Nairobi</option>
+                        <option value="Asia/Tehran">(GMT+03:30) Tehran</option>
+                        <option value="Asia/Dubai">(GMT+04:00) Abu Dhabi, Muscat</option>
+                        <option value="Asia/Yerevan">(GMT+04:00) Yerevan</option>
+                        <option value="Asia/Kabul">(GMT+04:30) Kabul</option>
+                        <option value="Asia/Yekaterinburg">(GMT+05:00) Ekaterinburg</option>
+                        <option value="Asia/Tashkent">(GMT+05:00) Tashkent</option>
+                        <option value="Asia/Kolkata">(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi</option>
+                        <option value="Asia/Katmandu">(GMT+05:45) Kathmandu</option>
+                        <option value="Asia/Dhaka">(GMT+06:00) Astana, Dhaka</option>
+                        <option value="Asia/Novosibirsk">(GMT+06:00) Novosibirsk</option>
+                        <option value="Asia/Rangoon">(GMT+06:30) Yangon (Rangoon)</option>
+                        <option value="Asia/Bangkok">(GMT+07:00) Bangkok, Hanoi, Jakarta</option>
+                        <option value="Asia/Krasnoyarsk">(GMT+07:00) Krasnoyarsk</option>
+                        <option value="Asia/Hong_Kong">(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi</option>
+                        <option value="Asia/Irkutsk">(GMT+08:00) Irkutsk, Ulaan Bataar</option>
+                        <option value="Australia/Perth">(GMT+08:00) Perth</option>
+                        <option value="Australia/Eucla">(GMT+08:45) Eucla</option>
+                        <option value="Asia/Tokyo">(GMT+09:00) Osaka, Sapporo, Tokyo</option>
+                        <option value="Asia/Seoul">(GMT+09:00) Seoul</option>
+                        <option value="Asia/Yakutsk">(GMT+09:00) Yakutsk</option>
+                        <option value="Australia/Adelaide">(GMT+09:30) Adelaide</option>
+                        <option value="Australia/Darwin">(GMT+09:30) Darwin</option>
+                        <option value="Australia/Brisbane">(GMT+10:00) Brisbane</option>
+                        <option value="Australia/Hobart">(GMT+10:00) Hobart</option>
+                        <option value="Asia/Vladivostok">(GMT+10:00) Vladivostok</option>
+                        <option value="Australia/Lord_Howe">(GMT+10:30) Lord Howe Island</option>
+                        <option value="Etc/GMT-11">(GMT+11:00) Solomon Is., New Caledonia</option>
+                        <option value="Asia/Magadan">(GMT+11:00) Magadan</option>
+                        <option value="Pacific/Norfolk">(GMT+11:30) Norfolk Island</option>
+                        <option value="Asia/Anadyr">(GMT+12:00) Anadyr, Kamchatka</option>
+                        <option value="Pacific/Auckland">(GMT+12:00) Auckland, Wellington</option>
+                        <option value="Etc/GMT-12">(GMT+12:00) Fiji, Kamchatka, Marshall Is.</option>
+                        <option value="Pacific/Chatham">(GMT+12:45) Chatham Islands</option>
+                        <option value="Pacific/Tongatapu">(GMT+13:00) Nuku\'alofa</option>
+                        <option value="Pacific/Kiritimati">(GMT+14:00) Kiritimati</option>
                     </select>
                 </li>
             </ul>
-                       <ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">
-                               <li data-role="fieldcontain">
-                                       <label for="select_timezone" class="select">Time zone:</label>
-                                       <select name="select_timezone" id="select_timezone">
-                                               <option value="Pacific/Midway">(GMT-11:00) Midway Island, Samoa</option>
-                                               <option value="America/Adak">(GMT-10:00) Hawaii-Aleutian</option>
-                                               <option value="Etc/GMT+10">(GMT-10:00) Hawaii</option>
-                                               <option value="Pacific/Marquesas">(GMT-09:30) Marquesas Islands</option>
-                                               <option value="Pacific/Gambier">(GMT-09:00) Gambier Islands</option>
-                                               <option value="America/Anchorage">(GMT-09:00) Alaska</option>
-                                               <option value="America/Ensenada">(GMT-08:00) Tijuana, Baja California</option>
-                                               <option value="Etc/GMT+8">(GMT-08:00) Pitcairn Islands</option>
-                                               <option value="America/Los_Angeles">(GMT-08:00) Pacific Time (US & Canada)</option>
-                                               <option value="America/Denver">(GMT-07:00) Mountain Time (US & Canada)</option>
-                                               <option value="America/Chihuahua">(GMT-07:00) Chihuahua, La Paz, Mazatlan</option>
-                                               <option value="America/Dawson_Creek">(GMT-07:00) Arizona</option>
-                                               <option value="America/Belize">(GMT-06:00) Saskatchewan, Central America</option>
-                                               <option value="America/Cancun">(GMT-06:00) Guadalajara, Mexico City, Monterrey</option>
-                                               <option value="Chile/EasterIsland">(GMT-06:00) Easter Island</option>
-                                               <option value="America/Chicago">(GMT-06:00) Central Time (US & Canada)</option>
-                                               <option value="America/New_York">(GMT-05:00) Eastern Time (US & Canada)</option>
-                                               <option value="America/Havana">(GMT-05:00) Cuba</option>
-                                               <option value="America/Bogota">(GMT-05:00) Bogota, Lima, Quito, Rio Branco</option>
-                                               <option value="America/Caracas">(GMT-04:30) Caracas</option>
-                                               <option value="America/Santiago">(GMT-04:00) Santiago</option>
-                                               <option value="America/La_Paz">(GMT-04:00) La Paz</option>
-                                               <option value="Atlantic/Stanley">(GMT-04:00) Faukland Islands</option>
-                                               <option value="America/Campo_Grande">(GMT-04:00) Brazil</option>
-                                               <option value="America/Goose_Bay">(GMT-04:00) Atlantic Time (Goose Bay)</option>
-                                               <option value="America/Glace_Bay">(GMT-04:00) Atlantic Time (Canada)</option>
-                                               <option value="America/St_Johns">(GMT-03:30) Newfoundland</option>
-                                               <option value="America/Araguaina">(GMT-03:00) UTC-3</option>
-                                               <option value="America/Montevideo">(GMT-03:00) Montevideo</option>
-                                               <option value="America/Miquelon">(GMT-03:00) Miquelon, St. Pierre</option>
-                                               <option value="America/Godthab">(GMT-03:00) Greenland</option>
-                                               <option value="America/Argentina/Buenos_Aires">(GMT-03:00) Buenos Aires</option>
-                                               <option value="America/Sao_Paulo">(GMT-03:00) Brasilia</option>
-                                               <option value="America/Noronha">(GMT-02:00) Mid-Atlantic</option>
-                                               <option value="Atlantic/Cape_Verde">(GMT-01:00) Cape Verde Is.</option>
-                                               <option value="Atlantic/Azores">(GMT-01:00) Azores</option>
-                                               <option value="Europe/Belfast">(GMT) Greenwich Mean Time : Belfast</option>
-                                               <option value="Europe/Dublin">(GMT) Greenwich Mean Time : Dublin</option>
-                                               <option value="Europe/Lisbon">(GMT) Greenwich Mean Time : Lisbon</option>
-                                               <option value="Europe/London">(GMT) Greenwich Mean Time : London</option>
-                                               <option value="Africa/Abidjan">(GMT) Monrovia, Reykjavik</option>
-                                               <option value="Europe/Amsterdam">(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna</option>
-                                               <option value="Europe/Belgrade">(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague</option>
-                                               <option value="Europe/Brussels">(GMT+01:00) Brussels, Copenhagen, Madrid, Paris</option>
-                                               <option value="Africa/Algiers">(GMT+01:00) West Central Africa</option>
-                                               <option value="Africa/Windhoek">(GMT+01:00) Windhoek</option>
-                                               <option value="Asia/Beirut">(GMT+02:00) Beirut</option>
-                                               <option value="Africa/Cairo">(GMT+02:00) Cairo</option>
-                                               <option value="Asia/Gaza">(GMT+02:00) Gaza</option>
-                                               <option value="Africa/Blantyre">(GMT+02:00) Harare, Pretoria</option>
-                                               <option value="Asia/Jerusalem">(GMT+02:00) Jerusalem</option>
-                                               <option value="Europe/Minsk">(GMT+02:00) Minsk</option>
-                                               <option value="Asia/Damascus">(GMT+02:00) Syria</option>
-                                               <option value="Europe/Moscow">(GMT+03:00) Moscow, St. Petersburg, Volgograd</option>
-                                               <option value="Africa/Addis_Ababa">(GMT+03:00) Nairobi</option>
-                                               <option value="Asia/Tehran">(GMT+03:30) Tehran</option>
-                                               <option value="Asia/Dubai">(GMT+04:00) Abu Dhabi, Muscat</option>
-                                               <option value="Asia/Yerevan">(GMT+04:00) Yerevan</option>
-                                               <option value="Asia/Kabul">(GMT+04:30) Kabul</option>
-                                               <option value="Asia/Yekaterinburg">(GMT+05:00) Ekaterinburg</option>
-                                               <option value="Asia/Tashkent">(GMT+05:00) Tashkent</option>
-                                               <option value="Asia/Kolkata">(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi</option>
-                                               <option value="Asia/Katmandu">(GMT+05:45) Kathmandu</option>
-                                               <option value="Asia/Dhaka">(GMT+06:00) Astana, Dhaka</option>
-                                               <option value="Asia/Novosibirsk">(GMT+06:00) Novosibirsk</option>
-                                               <option value="Asia/Rangoon">(GMT+06:30) Yangon (Rangoon)</option>
-                                               <option value="Asia/Bangkok">(GMT+07:00) Bangkok, Hanoi, Jakarta</option>
-                                               <option value="Asia/Krasnoyarsk">(GMT+07:00) Krasnoyarsk</option>
-                                               <option value="Asia/Hong_Kong">(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi</option>
-                                               <option value="Asia/Irkutsk">(GMT+08:00) Irkutsk, Ulaan Bataar</option>
-                                               <option value="Australia/Perth">(GMT+08:00) Perth</option>
-                                               <option value="Australia/Eucla">(GMT+08:45) Eucla</option>
-                                               <option value="Asia/Tokyo">(GMT+09:00) Osaka, Sapporo, Tokyo</option>
-                                               <option value="Asia/Seoul">(GMT+09:00) Seoul</option>
-                                               <option value="Asia/Yakutsk">(GMT+09:00) Yakutsk</option>
-                                               <option value="Australia/Adelaide">(GMT+09:30) Adelaide</option>
-                                               <option value="Australia/Darwin">(GMT+09:30) Darwin</option>
-                                               <option value="Australia/Brisbane">(GMT+10:00) Brisbane</option>
-                                               <option value="Australia/Hobart">(GMT+10:00) Hobart</option>
-                                               <option value="Asia/Vladivostok">(GMT+10:00) Vladivostok</option>
-                                               <option value="Australia/Lord_Howe">(GMT+10:30) Lord Howe Island</option>
-                                               <option value="Etc/GMT-11">(GMT+11:00) Solomon Is., New Caledonia</option>
-                                               <option value="Asia/Magadan">(GMT+11:00) Magadan</option>
-                                               <option value="Pacific/Norfolk">(GMT+11:30) Norfolk Island</option>
-                                               <option value="Asia/Anadyr">(GMT+12:00) Anadyr, Kamchatka</option>
-                                               <option value="Pacific/Auckland">(GMT+12:00) Auckland, Wellington</option>
-                                               <option value="Etc/GMT-12">(GMT+12:00) Fiji, Kamchatka, Marshall Is.</option>
-                                               <option value="Pacific/Chatham">(GMT+12:45) Chatham Islands</option>
-                                               <option value="Pacific/Tongatapu">(GMT+13:00) Nuku\'alofa</option>
-                                               <option value="Pacific/Kiritimati">(GMT+14:00) Kiritimati</option>
-                                       </select>
-                               </li>
-                       </ul>
-                       <div data-role="button" id="button_datetime_apply">Apply</div>
-                       <div data-role="button" id="button_datetime_cancel">Cancel</div>
-               </div>
-       </div>
-       
+            <div data-role="button" id="button_datetime_apply">Apply</div>
+            <div data-role="button" id="button_datetime_cancel">Cancel</div>
+        </div>
+    </div>
 </body>
 </html>
diff --git a/js/api-connman.js b/js/api-connman.js
new file mode 100644 (file)
index 0000000..08b8660
--- /dev/null
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) 2013, Intel Corporation.
+ *
+ * This program is licensed under the terms and conditions of the
+ * Apache License, version 2.0.  The full text of the Apache License is at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ */
+
+/* Namespace */
+var settings = settings || {};
+settings.connman = settings.connman || {};
+
+/* Module */
+settings.connman = (function() {
+
+    var default_adapter = null;
+
+    /* Technology class */
+    var ConnmanTechnology = function(technology_path, technology_properties) {
+            this.id = technology_path;
+            this.prop = technology_properties;
+        };
+
+    ConnmanTechnology.prototype.setPowered = function(powered, success_cb, error_cb) {
+        if (wsAPI === undefined) return;
+        if (this.setPowerInProgress) {
+            console.log('Enabling/disabling technology in progress');
+            return;
+        }
+
+        var me = this;
+        this.setPowerInProgress = true;
+        setTimeout(function() {
+            wsAPI.sendRequest(me.prop.Type, 'enable', powered, function() {
+                me.setPowerInProgress = false;
+                success_cb();
+            }, function(e) {
+                if (e.indexOf('Already enabled') >= 0) {
+                    console.log('connman ' + me.prop.Type + ' already enabled');
+                    me.setPowerInProgress = false;
+                    success_cb();
+                } else if (e.indexOf('Already disabled') >= 0) {
+                    console.log('connman ' + me.prop.Type + ' already disabled');
+                    me.setPowerInProgress = false;
+                    success_cb();
+                } else {
+                    me.setPowerInProgress = false;
+                    error_cb(e);
+                }
+            })
+        }, 2000);
+    };
+
+    ConnmanTechnology.prototype.getPowered = function(success_cb, error_cb) {
+        if (wsAPI === undefined) return;
+        var me = this;
+        wsAPI.sendRequest(this.prop.Type, 'is_enabled', null, function(isEnabled) {
+            if (isEnabled === undefined) {
+                console.log('Badly formed json message: ' + json_msg);
+            }
+            me.powered = isEnabled;
+            success_cb(me.powered);
+        }, error_cb);
+    };
+
+    /* Service class */
+    ConnmanService = function(service_path, service_properties) {
+        this.id = service_path;
+        this.prop = service_properties;
+    };
+
+    ConnmanService.prototype.connect = function(passphrase, success_cb, error_cb) {
+        if (wsAPI === undefined) return;
+
+        var info = [this.id,
+        {
+            'Name': this.prop.Name,
+            'Type': this.prop.EncryptionMode,
+            'Passphrase': passphrase
+        }]
+        wsAPI.sendRequest(WS_REQUEST_TYPE.WIFI, 'connect', info, success_cb, error_cb);
+    };
+
+    ConnmanService.prototype.disconnect = function(success_cb, error_cb) {
+        if (wsAPI === undefined) return;
+        wsAPI.sendRequest(WS_REQUEST_TYPE.WIFI, 'disconnect', this.id, success_cb, error_cb);
+    };
+
+    /* global functions */
+    function subscribeEvents(callback) {
+        wsAPI.subscribeEvents(callback);
+    }
+
+    function unsubscribeEvents(callback) {
+        wsAPI.unsubscribeEvents(callback);
+    }
+
+    function getTechnologies(success_cb, error_cb) {
+        wsAPI.sendRequest('connman', 'getTechnologies', null, function(results) {
+            success_cb(results);
+        }, function(error) {
+            console.log('getTechnologies not implemented in settingsd, using pre-defined values');
+            var results = [
+                ['/net/connman/technology/ethernet',
+                {
+                    'Name': 'Wired',
+                    'Type': 'ethernet',
+                }],
+                ['/net/connman/technology/wifi',
+                {
+                    'Name': 'WiFi',
+                    'Type': 'wifi',
+                }],
+                ['/net/connman/technology/bluetooth',
+                {
+                    'Name': 'Bluetooth',
+                    'Type': 'bluetooth',
+                }]
+            ];
+
+            var technologies = [];
+            for (var i = 0; i < results.length; i++) {
+                var technology = new settings.connman.ConnmanTechnology(results[i][0], results[i][1]);
+                technologies.push(technology);
+            }
+
+            success_cb(technologies);
+        });
+    }
+
+    function getServices(success_cb, error_cb) {
+        return this.scan(success_cb, error_cb);
+
+        wsAPI.sendRequest(WS_REQUEST_TYPE.CONNMAN, 'getServices', null, function(results) {
+            if (results.length >= 0 && results[0].length >= 0 && results[0][0][0] === undefined) {
+                error_cb('Cannot parse getServices results');
+                return;
+            }
+
+            var services_list = results[0];
+
+            try {
+                var results = [];
+                for (var i = 0; i < services_list.length; i++) {
+                    if (services_list[i][0] === undefined || services_list[i][1] === undefined) {
+                        console.log('Badly form json message: ' + json_msg);
+                    }
+
+                    var service = new settings.connman.ConnmanService(services_list[i][0], services_list[i][1]);
+                    results.push(service);
+                }
+            } catch (e) {
+                error_cb(e);
+            }
+            success_cb(results);
+        }, error_cb);
+    }
+
+    function scan(success_cb, error_cb) {
+        if (wsAPI === undefined) return;
+        wsAPI.sendRequest(WS_REQUEST_TYPE.WIFI, 'scan', null, function(results) {
+            if (results.length >= 0 && results[0].length >= 0 && results[0][0][0] === undefined) {
+                error_cb('Cannot parse scan results');
+                return;
+            }
+
+            var services_list = results[0];
+
+            try {
+                var results = [];
+                for (var i = 0; i < services_list.length; i++) {
+                    if (services_list[i][0] === undefined || services_list[i][1] === undefined) {
+                        console.log('Badly form json message: ' + json_msg);
+                    }
+
+                    var service = new settings.connman.ConnmanService(services_list[i][0], services_list[i][1]);
+                    results.push(service);
+                }
+            } catch (e) {
+                error_cb(e);
+            }
+            success_cb(results);
+        }, error_cb);
+    };
+
+    return {
+        ConnmanTechnology: ConnmanTechnology,
+        ConnmanService: ConnmanService,
+        subscribeEvents: subscribeEvents,
+        unsubscribeEvents: unsubscribeEvents,
+        getTechnologies: getTechnologies,
+        getServices: getServices,
+        scan: scan
+    };
+})();
\ No newline at end of file
diff --git a/js/api-wifi.js b/js/api-wifi.js
deleted file mode 100644 (file)
index c8be691..0000000
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * Copyright (c) 2013, Intel Corporation.
- *
- * This program is licensed under the terms and conditions of the
- * Apache License, version 2.0.  The full text of the Apache License is at
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- */
-
-/* Namespace */
-var settings = settings || {};
-settings.wifi = settings.wifi || {};
-
-var WIFI_SECURITY_TYPE = {
-    NONE: 0,
-    WEP: 1,
-    WPA: 2,
-    WPA2: 3,
-    WPA_ENTERPRISE: 4,
-    WPA2_ENTERPRISE: 5
-};
-
-/* Module */
-settings.wifi = (function() {
-
-    var default_adapter = null;
-
-    /* Adapter class */
-    var WiFiAdapter = function(adapter) {
-            this.wifi_adapter = adapter;
-            this.name = 'Connman-WiFi';
-            this.powered = false;
-        };
-
-    WiFiAdapter.prototype.setPowered = function(powered, success_cb, error_cb) {
-        if (wsAPI === undefined) return;
-        wsAPI.sendRequest(WS_REQUEST_TYPE.WIFI, 'enable', powered, success_cb, function(e) {
-            if (e.indexOf('Already enabled') >= 0) {
-                console.log('wifi subsystem already enabled');
-                success_cb();
-            } else if (e.indexOf('Already disabled') >= 0) {
-                console.log('wifi subsystem already disabled');
-                success_cb();
-            } else {
-                error_cb(e);
-            }
-        });
-    };
-
-    WiFiAdapter.prototype.getPowered = function(success_cb, error_cb) {
-        if (wsAPI === undefined) return;
-        var me = this;
-        wsAPI.sendRequest(WS_REQUEST_TYPE.WIFI, 'is_enabled', null, function(isEnabled) {
-            if (isEnabled === undefined) {
-                console.log('Badly formed json message: ' + json_msg);
-            }
-            me.powered = isEnabled;
-            success_cb(me.powered);
-        }, error_cb);
-    };
-
-    WiFiAdapter.prototype.scan = function(success_cb, error_cb) {
-        if (wsAPI === undefined) return;
-        wsAPI.sendRequest(WS_REQUEST_TYPE.WIFI, 'scan', null, function(results) {
-            if (results.length >= 0 && results[0].length >= 0 && results[0][0][0] === undefined) {
-                error_cb('Cannot parse scan results');
-                return;
-            }
-
-            var network_list = results[0];
-
-            try {
-                var results = [];
-                for (var i = 0; i < network_list.length; i++) {
-                    if (network_list[i][1] === undefined) {
-                        console.log('Badly form json message: ' + json_msg);
-                    }
-                    if (network_list[i][1].Type === 'wifi') {
-                        var network = new settings.wifi.WiFiNetwork(network_list[i][0]);
-                        if (network_list[i][1].Name !== undefined) {
-                            network.ssid = network_list[i][1].Name;
-                        }
-                        if (network_list[i][1].State === 'ready') {
-                            network.connected = true;
-                        } else if (network_list[i][1].State === 'idle') {
-                            network.connected = false;
-                        }
-                        if (network_list[i][1].EncryptionMode !== undefined) {
-                            network.encryption = network_list[i][1].EncryptionMode;
-                        }
-                        if (network_list[i][1].Strength !== undefined) {
-                            network.strength = network_list[i][1].Strength;
-                        }
-                        if (network_list[i][1].IPv4.Address !== undefined) {
-                            network.ipAddress = network_list[i][1].IPv4.Address;
-                        }
-                        if (network_list[i][1].IPv4.Gateway !== undefined) {
-                            network.gateway = network_list[i][1].IPv4.Gateway;
-                        }
-                        if (network_list[i][1].IPv4.Netmask !== undefined) {
-                            network.netmask = network_list[i][1].IPv4.Netmask;
-                        }
-                        results.push(network);
-                    }
-                }
-            } catch (e) {
-                error_cb(e);
-            }
-            success_cb(results);
-        }, error_cb);
-    };
-
-    WiFiAdapter.prototype.connectNetwork = function(network_id, security, passcode, success_cb, error_cb) {
-        if (wsAPI === undefined) return;
-
-        wsAPI.sendRequest(WS_REQUEST_TYPE.WIFI, 'connect', network_id, success_cb, error_cb);
-    };
-
-    WiFiAdapter.prototype.disconnectNetwork = function(network_id, success_cb, error_cb) {
-        if (wsAPI === undefined) return;
-        wsAPI.sendRequest(WS_REQUEST_TYPE.WIFI, 'disconnect', network_id, success_cb, error_cb);
-    };
-
-    /* Network class */
-    WiFiNetwork = function(object_path) {
-        this.id = object_path;
-        this.ssid = '';
-        this.connected = false;
-        this.security = WIFI_SECURITY_TYPE.NONE;
-        this.encryption = 'Unknown';
-        this.ipAddress = 'Unknown';
-        this.gateway = 'Unknown';
-        this.netmask = 'Unknown';
-        this.strength = -1;
-    };
-
-    WiFiNetwork.prototype.getSecurity = function() {
-        return this.security;
-    }
-
-    function subscribeEvents(callback) {
-        wsAPI.subscribeEvents(callback);
-    }
-
-    function unsubscribeEvents(callback) {
-        wsAPI.unsubscribeEvents(callback);
-    }
-
-    function getDefaultAdapter() {
-        if (default_adapter === null) {
-            default_adapter = new WiFiAdapter(wsAPI);
-        }
-
-        return default_adapter;
-    };
-
-    return {
-        WiFiAdapter: WiFiAdapter,
-        WiFiNetwork: WiFiNetwork,
-        subscribeEvents: subscribeEvents,
-        unsubscribeEvents: unsubscribeEvents,
-        getDefaultAdapter: getDefaultAdapter
-    };
-})();
\ No newline at end of file
index 8b6595c..3c16653 100644 (file)
             /* Settings Panel */
             $('#main').on('pageshow', function(event, data) {
                 /* TODO: unsubscribe events if neccessary */
-                if (data.prevPage.attr('id') === 'page_wifi') {
-                    console.log('Wi-Fi settings exited');
-                    settings.wifi.unsubscribeEvents(wifiEventReceived);
+                if (data.prevPage.attr('id') === 'page_connman') {
+                    console.log('Connman settings exited');
+                    settings.connman.unsubscribeEvents(connmanEventReceived);
                 } else if (data.prevPage.attr('id') === 'page_bluetooth') {
                     console.log('Bluetooth settings exited');
-                    settings.wifi.unsubscribeEvents(bluetoothEventReceived);
+                    settings.bluetooth.unsubscribeEvents(bluetoothEventReceived);
                 } else if (data.prevPage.attr('id') === 'page_datetime') {
                     console.log('Date and Time settings exited');
                 }
             });
 
             /* Different sub panels */
-            wifiPanelInit();
+            connmanPanelInit();
             bluetoothPanelInit();
             datetimePanelInit();
         } catch (e) {
index 769abab..c2aeb84 100644 (file)
@@ -102,12 +102,12 @@ function bluetoothPanelInit() {
 }
 
 function bluetoothEventReceived(event) {
-    if (event.type !== WS_EVENT_TYPE.BLUETOOTH) return;
+    if (event.type !== WS_EVENT_TYPE.BLUETOOTH && event.type !== WS_EVENT_TYPE.CONNMAN) return;
     if ($.mobile.activePage.attr('id') !== 'page_bluetooth' || $.mobile.activePage.attr('id') !== 'page_bluetooth_detail') {
         return;
     }
 
-    if (event.name === 'PropertyChanged') {
+    if (event.id === '/net/connman/technology/bluetooth' && event.name === 'PropertyChanged') {
         bluetoothHandlePropertyChanged(event.value);
     } else {
         console.log('Unsupported bluetooth event received: ' + event.name);
diff --git a/js/panel-connman.js b/js/panel-connman.js
new file mode 100644 (file)
index 0000000..bf6fa80
--- /dev/null
@@ -0,0 +1,654 @@
+/*
+ * Copyright (c) 2013, Intel Corporation.
+ *
+ * This program is licensed under the terms and conditions of the
+ * Apache License, version 2.0.  The full text of the Apache License is at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ */
+var connmanScanInProgress = false;
+
+function connmanPanelInit() {
+
+    /* Connman Settings Panel */
+    $('#page_connman').on('pageshow', function(event, data) {
+        if (data.prevPage.attr('id') === 'page_connman_service') return;
+
+        settings.connman.subscribeEvents(connmanEventReceived);
+
+        console.log('Get all the available technologies');
+        $('#connman_technologies').html('');
+        settings.connman.getTechnologies(function(technologies) {
+            for (var i = 0; i < technologies.length; i++) {
+                var technology = technologies[i];
+                console.log('Connman technology found: ' + technology.prop.Type);
+                if (technology.prop.Type === 'bluetooth') {
+                    /* Do not show bluetooth */
+                    continue;
+                }
+                if (technology.prop.Powered === undefined) {
+                    (function(t) {
+                        t.getPowered(function(is_powered) {
+                            t.prop.Powered = is_powered;
+                            connmanConstructTechnologyElement(t);
+                        }, function(e) {
+                            t.prop.Powered = false;
+                            connmanConstructTechnologyElement(t);
+                        });
+                    })(technology);
+                } else {
+                    connmanConstructTechnologyElement(technology);
+                }
+            }
+        });
+    });
+
+    $('#button_connman_refresh').on('click', function() {
+        /* connman only supports wifi scan */
+        connmanScan('wifi');
+    });
+
+    $('#button_connman_wifi_add').on('click', function() {
+        if (connmanScanInProgress) return;
+
+        console.log('Enter add WiFi page');
+        $.mobile.changePage('#page_wifi_add');
+    });
+
+    /* Connman service detail page */
+    $('#page_connman_service').on('pageshow', function(event, data) {
+        var service_id = localStorage.getItem('connman_service_id');
+        if (service_id == undefined) return;
+        var service = $(jqId(service_id)).data('service-object');
+        connmanConstructServicePanel(service);
+    });
+
+    /* WiFi add new network page */
+    $('#page_wifi_add').on('pagebeforeshow', function(event, data) {
+        $('#input_wifi_add_ssid').val('');
+        $('#input_wifi_add_password').val('');
+        $('#radio_wifi_none').prop('checked', true);
+        $('input[name=radio_wifi_security]').checkboxradio('refresh');
+        $('#input_wifi_add_password').textinput('disable');
+    });
+
+    $('#button_wifi_add').on('click', function() {
+        var name = $('#input_wifi_add_ssid').val();
+        var security = $('input[name=radio_wifi_security]:checked').val();
+        var passcode = $('#input_wifi_add_password').val();
+
+        if (name === '') {
+            showMsg('Error', 'Enter SSID');
+            return;
+        }
+
+        if (security !== 'None' && passcode === '') {
+            showMsg('Error', 'Enter passphrase');
+            return;
+        }
+
+        showSpinner(false, 'Adding...');
+        connmanGetHiddenServicePath(security, function(service_path) {
+            var service = new settings.connman.ConnmanService('', {
+                'Name': name,
+                'EncryptionMode': security
+            });
+            service.connect(passcode, function() {
+                /* success */
+                connmanSync(function() {
+                    hideSpinner();
+                    console.log('Go back to Connman page');
+                    $.mobile.changePage('#page_connman');
+                }, null);
+            }, function(e) {
+                /* error */
+                hideSpinner();
+                showMsg('Error', 'Failed to add network: ' + e);
+            });
+        }, function(e) {
+            hideSpinner();
+               showMsg('Error', e);
+        });
+    });
+
+    $('[name="radio_wifi_security"]').on('change', function(event, data) {
+        var security = $('input[name=radio_wifi_security]:checked').val();
+
+        if (security === 'none') {
+            $('#input_wifi_add_password').textinput('disable');
+            $('#input_wifi_add_password').val('');
+        } else {
+            $('#input_wifi_add_password').textinput('enable');
+        }
+    });
+
+    $('#button_wifi_connect').on('click', function() {
+        var service_id = localStorage.getItem('connman_service_id');
+        if (service_id == undefined) return;
+        var service = $(jqId(service_id)).data('service-object');
+        var passcode = $('#input_wifi_connect_passphrase').val();
+        connmanConnectToService(service, passcode, function() {
+            console.log('Successfully connected to service: ' + service.prop.Name);
+            if ($.mobile.activePage.attr('id') !== 'page_connman') {
+                console.log('Go back to Connman page');
+                $.mobile.changePage('#page_connman');
+            }
+        }, function(e) {
+            showMsg('Error', 'Connect service failed: ' + e);
+        });
+    });
+}
+
+function connmanEventReceived(event) {
+    if (event.type !== WS_EVENT_TYPE.CONNMAN) return;
+    if ($.mobile.activePage.attr('id') !== 'page_connman' && $.mobile.activePage.attr('id') !== 'page_connman_service') {
+        return;
+    }
+
+    if (event.name === 'ServicesChanged') {
+        connmanHandleServicesChanged(event.id, event.value);
+    } else if (event.name === 'PropertyChanged') {
+        connmanHandlePropertyChanged(event.id, event.value);
+    } else {
+        console.log('Unsupported event received: ' + event.name);
+    }
+}
+
+function connmanHandleServicesChanged(object_path, services) {
+    var servicesChanged = services[0];
+    var servicesRemoved = services[1];
+
+    console.log(servicesChanged.length + ' services changed');
+    for (var i = 0; i < servicesChanged.length; i++) {
+        if (servicesChanged[i][0] === undefined) {
+            console.log('Invalid parameters, missing object path');
+            continue;
+        }
+
+        var service = $(jqId(servicesChanged[i][0])).data('service-object');
+
+        if (service == null) {
+            console.log('could not find service object ' + servicesChanged[i][0]);
+            continue;
+        }
+
+        for (var prop in servicesChanged[i][1]) {
+            if (servicesChanged[i][1].hasOwnProperty(prop)) {
+                service.prop.prop = servicesChanged[i][1].prop;
+                connmanUpdateService(service);
+                console.log('Service ' + service.prop.Name + ' updated: ' + prop);
+            }
+        }
+    }
+
+    console.log(servicesRemoved.length + ' services removed');
+    for (var i = 0; i < servicesRemoved.length; i++) {
+        if (servicesRemoved[i] === undefined) {
+            console.log('Invalid parameters, missing object path');
+            continue;
+        }
+
+        connmanRemoveFromAvailableList(servicesRemoved[i]);
+    }
+}
+
+function connmanHandlePropertyChanged(id, property) {
+    if (property[0] === 'Powered') {
+        var index = id.lastIndexOf('/');
+        var technology = id.substring(index + 1);
+        if (property[1] === true) {
+            connmanToggleOn(technology);
+            if (technology === 'wifi') {
+                setTimeout(function() {
+                    /* add a 1 sec delay */
+                    connmanScan(technology);
+                }, 1000);
+            }
+        } else {
+            connmanToggleOff(technology);
+        }
+    }
+
+    if (property[0] === 'State') {
+        /* specific service has changed */
+        var service = $(jqId(id)).data('service-object');
+        if (service == null) {
+            console.error('Connman service not found ' + id);
+            return;
+        }
+
+        service.prop.State = property[1];
+        connmanUpdateService(service);
+    } else if (property[0] === 'Connected') {
+        /* unknown service has changed, sync Connman */
+        console.log('Unknown service connected property changed');
+        connmanSync(null, null);
+    }
+}
+
+function connmanClearAvailableList() {
+    $('#listview_services_available').html('');
+}
+
+function connmanScan(technology) {
+    if (technology !== 'wifi') {
+        /* Connman only supports wifi scan */
+        return;
+    }
+
+    if (connmanScanInProgress) {
+        console.log('Connman scan in progress...');
+        return;
+    }
+
+    console.log('Start connman scan');
+    connmanScanInProgress = true;
+
+    /* clear the services list with new scan */
+    connmanClearAvailableList();
+
+    showSpinner(false, 'Scanning...');
+    $('#toggle_connman_wifi').slider('disable');
+    $('#toggle_connman_wifi').slider('refresh');
+    settings.connman.scan(function(services) {
+        hideSpinner();
+        connmanScanInProgress = false;
+        $('#toggle_connman_wifi').slider('enable');
+        $('#toggle_connman_wifi').slider('refresh');
+        console.log('found ' + services.length + ' connman services');
+        for (var i = 0; i < services.length; i++) {
+            var service = services[i];
+            if (service.prop.Type === undefined || service.prop.Type === 'bluetooth') {
+                console.log('Ignore bluetooth or unknown services');
+                continue;
+            }
+            if (service.prop.Name === undefined) {
+                console.log('Ignore hidden service - ' + service.id);
+                continue;
+            }
+
+            connmanUpdateService(service);
+        }
+    }, function(e) {
+        hideSpinner();
+        connmanScanInProgress = false;
+        $('#toggle_connman_wifi').slider('enable');
+        $('#toggle_connman_wifi').slider('refresh');
+        showMsg('Error', 'Cannot scan: ' + e);
+    });
+}
+
+function connmanSync(success_cb, error_cb) {
+    if (connmanScanInProgress) {
+        console.log('Connman scan in progress...');
+        return;
+    }
+
+    console.log('Start connman sync');
+    /* clear the services list with new scan */
+    connmanClearAvailableList();
+
+    wifiScanInProgress = true;
+    $('#toggle_connman_wifi').slider('disable');
+    $('#toggle_connman_wifi').slider('refresh');
+    settings.connman.getServices(function(services) {
+        connmanScanInProgress = false;
+        $('#toggle_connman_wifi').slider('enable');
+        $('#toggle_connman_wifi').slider('refresh');
+        console.log('found ' + services.length + ' connman services');
+        for (var i = 0; i < services.length; i++) {
+            var service = services[i];
+            if (service.prop.Type === undefined || service.prop.Type === 'bluetooth') {
+                console.log('Ignore bluetooth or unknown services');
+                continue;
+            }
+            if (service.prop.Name === undefined) {
+                console.log('Ignore hidden service - ' + service.id);
+                continue;
+            }
+
+            connmanUpdateService(service);
+        }
+        if (success_cb) {
+            success_cb();
+        }
+    }, function(e) {
+        connmanScanInProgress = false;
+        $('#toggle_connman_wifi').slider('enable');
+        $('#toggle_connman_wifi').slider('refresh');
+        if (error_cb) {
+            error_cb(e);
+        }
+    });
+}
+
+function connmanRefreshServicesList() {
+    $('#listview_services_available').listview('refresh');
+}
+
+function connmanAppendToAvailableList(service) {
+    if ($('#listview_services_available').find(jqId(service.id)).length != 0) return;
+
+    var parent = '#listview_services_available';
+    connmanConstructServiceElement(parent, service);
+    connmanUpdateServiceButton(service);
+    connmanRefreshServicesList();
+}
+
+function connmanRemoveFromAvailableList(service_id) {
+    var removeThis = $('#listview_services_available li').filter(function() {
+        return $(this).find(jqId(service_id)).length === 1;
+    });
+
+    if (removeThis.length !== 0) {
+        removeThis.remove();
+        connmanRefreshServicesList();
+    }
+}
+
+function getSignalStrengthStr(strength) {
+    var signal_strength = 'unknown';
+    if (strength > 0 && strength <= 20) {
+        strength = 'very poor';
+    } else if (strength > 20 && strength <= 40) {
+        signal_strength = 'poor';
+    } else if (strength > 40 && strength <= 70) {
+        signal_strength = 'average';
+    } else if (strength > 70 && strength <= 90) {
+        signal_strength = 'good';
+    } else if (strength > 90 && strength <= 100) {
+        signal_strength = 'excellent';
+    }
+    return signal_strength;
+}
+
+function connmanConstructTechnologyElement(technology) {
+    if (technology.prop.Type === undefined || technology.prop.Name == undefined) {
+        console.error('technology type or name missing ' + technology);
+        return;
+    }
+
+    var html = '<ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">';
+    html += '<li data-role="fieldcontain">';
+    html += '<label for="toggle_connman_' + technology.prop.Type + '" class="ui-slider">' + technology.prop.Name + '</label>';
+    html += '<select data-role="slider" name="toggle_connman_' + technology.prop.Type + '" ';
+    html += 'id="toggle_connman_' + technology.prop.Type + '" class="ui-slider-switch">';
+    html += '<option value="off">Off</option>';
+    html += '<option value="on">On</option>';
+    html += '</select></li></ul>';
+    $('#connman_technologies').append(html).trigger('create');
+
+    console.log('Connman technology ' + technology.prop.Type + ' is powered: ' + technology.prop.Powered);
+    if (technology.prop.Powered) {
+        connmanToggleOn(technology.prop.Type);
+        if ($('ul#listview_services_available li').length === 0) {
+            connmanScan(technology.prop.Type);
+        }
+    } else {
+        connmanToggleOff(technology.prop.Type);
+    }
+
+    $('#toggle_connman_' + technology.prop.Type).change(function() {
+        console.log('toggle ' + technology.prop.Type + ' changed');
+
+        if (connmanScanInProgress) {
+            console.log('Connman scan in progress...');
+            return;
+        }
+
+        $('#toggle_connman_' + technology.prop.Type).slider('disable');
+        $('#toggle_connman_' + technology.prop.Type).slider('refresh');
+        if ($('#toggle_connman_' + technology.prop.Type).val() === 'off') {
+            technology.setPowered(false, function() {
+                /* success */
+                $('#toggle_connman_' + technology.prop.Type).slider('enable');
+                $('#toggle_connman_' + technology.prop.Type).slider('refresh');
+                console.log('Successfully disabled connman technology ' + technology.prop.Type);
+            }, function(e) {
+                /* error */
+                hideSpinner();
+                $('#toggle_connman_' + technology.prop.Type).slider('enable');
+                $('#toggle_connman_' + technology.prop.Type).val('on').slider('refresh');
+                showMsg('Error', 'Cannot disable ' + technology.prop.Type);
+            });
+        } else {
+            technology.setPowered(true, function() {
+                /* success */
+                $('#toggle_connman_' + technology.prop.Type).slider('enable');
+                $('#toggle_connman_' + technology.prop.Type).slider('refresh');
+                if (technology.prop.Type === 'wifi') {
+                    setTimeout(function() {
+                        /* add a 1 sec delay */
+                        connmanScan(technology.prop.Type);
+                    }, 1000);
+                }
+                console.log('Successfully enabled connman technology ' + technology.prop.Type);
+            }, function(e) {
+                /* error */
+                hideSpinner();
+                $('#toggle_connman_' + technology.prop.Type).slider('enable');
+                $('#toggle_connman_' + technology.prop.Type).val('off').slider('refresh');
+                showMsg('Error', 'Cannot enable ' + technology.prop.Type);
+            });
+        }
+    });
+}
+
+function connmanConstructServiceElement(parent, service) {
+    if (service.id === undefined || service.prop.Type === undefined) {
+        console.error('service id or type missing ' + service);
+        return;
+    }
+
+    var html = '<li data-icon="false"><a href="#" id="' + jqId(service.id).replace('#', '') + '">';
+    html += '<div class="service-ssid">' + service.prop.Name + '</div>';
+
+    if (service.prop.Type === 'wifi') {
+        html += '<div class="service-encryption">Encryption: ' + service.prop.EncryptionMode + '</div>';
+        html += '<div class="service-strength">Signal: ' + getSignalStrengthStr(service.prop.Strength) + '</div>';
+    }
+    html += '<div class="service-status"></div>';
+    html += '<div data-role="button" class="service-action-button ui-li-aside" data-inline="true"></div>';
+    html += '</a></li>';
+    $(parent).append(html).trigger('create');
+
+    /* store service object in the element so we can reference it later */
+    $(jqId(service.id)).data('service-object', service);
+
+    $(jqId(service.id)).on('click', function() {
+        /* BUG in webruntime that cause click event when another page is rendered */
+        if ($.mobile.activePage.attr('id') === 'page_connman') {
+            localStorage.setItem('connman_service_id', service.id);
+            console.log('Enter Connman service page');
+            $.mobile.changePage('#page_connman_service');
+        }
+    });
+
+    $(jqId(service.id)).find('div.service-action-button').on('click', function(e) {
+        var parent = $(this).parent().attr('id');
+
+        /*
+         * prevent the click event to propagate up
+         */
+        e.stopImmediatePropagation();
+        e.preventDefault();
+
+        /* retrieve the service object from element */
+        var service = $(jqId(parent)).data('service-object');
+        if (service == null) {
+            console.error('Connman service object not found');
+            return;
+        }
+
+        if (service.prop.State === 'idle') {
+            if (service.prop.EncryptionMode === 'none') {
+                connmanConnectToService(service, null);
+            } else {
+                connmanConnectToService(service, null, null, function(e) {
+                    console.log('Connect failed, will ask for passphrase');
+                    localStorage.setItem('connman_service_id', service.id);
+                    console.log('Enter connect WiFi page');
+                    $.mobile.changePage('#page_wifi_connect');
+                });
+            }
+        } else if (service.prop.State === 'ready') {
+            console.log('Disconnecting from service: ' + service.prop.Name);
+            showSpinner(false, 'Disconnecting...');
+            service.disconnect(function() {
+                /* success */
+                connmanSync(function() {
+                    hideSpinner();
+                }, null)
+            }, function(e) {
+                /* error */
+                hideSpinner();
+                showMsg('Error', 'Disconnect service failed: ' + e);
+            });
+        }
+    });
+}
+
+function connmanUpdateService(service) {
+    connmanAppendToAvailableList(service);
+
+    /* update service button for allowed action */
+    connmanUpdateServiceButton(service);
+
+    /* update service connection status */
+    connmanUpdateConnectionStatus(service);
+
+    /* update service detail panel */
+    if ($.mobile.activePage.attr('id') === 'page_connman_service') {
+        var service_id = localStorage.getItem('connman_service_id');
+        if (service_id == undefined) return;
+        var service_object = $(jqId(service_id)).data('service-object');
+        if (service.id === service_object.id) {
+            connmanConstructServicePanel(service);
+        }
+    }
+}
+
+function connmanUpdateServiceButton(service) {
+    if (service.prop.State === 'ready') {
+        $(jqId(service.id)).find('div.service-action-button').find('span').text('Disconnect');
+    } else if (service.prop.State === 'idle' || service.prop.State === 'online') {
+        $(jqId(service.id)).find('div.service-action-button').find('span').text('Connect');
+    }
+}
+
+function connmanUpdateConnectionStatus(service) {
+    var status = 'disconnected';
+    if (service.prop.State === 'ready') {
+        $(jqId(service.id)).addClass('service-connected');
+        status = 'connected';
+    } else if (service.prop.State === 'idle' || service.prop.State === 'online') {
+        status = 'disconnected';
+        $(jqId(service.id)).removeClass('service-connected');
+    }
+
+    connmanUpdateConnectionStatusText(service, status);
+}
+
+function connmanUpdateConnectionStatusText(service, status) {
+    $(jqId(service.id)).find('div.service-status').text(status);
+}
+
+function connmanConstructServicePanel(service) {
+    var status_connected = 'No';
+
+    if (service == null) return;
+    if (service.prop.State === 'ready') status_connected = 'Yes';
+
+    $('#page_connman_service_content').html('');
+    var html = '<ul data-role="listview" id="listview_connman_service" data-inset="true" ' + 'class="service-list ui-listview">';
+    html += '<li id="connman_service_name"><h2>Name: ' + service.prop.Name + '</h2></li>';
+    html += '<li id="connman_service_type"><h2>Type: ' + service.prop.Type + '</h2></li>';
+    html += '<li id="connman_service_type"><h2>State: ' + service.prop.State + '</h2></li>';
+    if (service.prop.Type === 'ethernet' || service.prop.Type === 'wifi') {
+        if (service.prop.Type === 'wifi') {
+            html += '<li id="connman_service_bssid"><h2>SSID: ' + service.prop.BSSID + '</h2></li>';
+            html += '<li id="connman_service_encryption"><h2>Encryption: ' + service.prop.EncryptionMode + '</h2></li>';
+            html += '<li id="connman_service_strength"><h2>Signal Strength: ' + service.prop.Strength + '</h2></li>';
+        }
+        if (service.prop.State === 'ready') {
+            html += '<li id="connman_service_ip_address"><h2>IP Address: ' + service.prop.IPv4.Address + '</h2></li>';
+            html += '<li id="connman_servicel_gateway"><h2>Gateway: ' + service.prop.IPv4.Gateway + '</h2></li>';
+            html += '<li id="connman_service_netmask"><h2>Netmask: ' + service.prop.IPv4.Netmask + '</h2></li>';
+        }
+    }
+    html += '<li id="connman_service_connected"><h2>Connected: ' + status_connected + '</h2></li>';
+    html += '<li id="connman_service_autoconnect"><h2>AutoConnect: ' + service.prop.AutoConnect + '</h2></li>';
+    html += '</ul>';
+    $('#page_connman_service_content').append(html).trigger('create');
+    $('#listview_connman_services').listview('refresh');
+}
+
+function connmanUpdateServicePanel(service) {
+    var status_connected = 'No';
+
+    if (service == null) return;
+    if (service.prop.State === 'ready') status_connected = 'Yes';
+    $('#connman_service_connected').text(status_connected);
+    $('#listview_connman_service').listview('refresh');
+}
+
+function connmanToggleOn(technology_type) {
+    setTimeout(function() {
+        $('#toggle_connman_' + technology_type).val('on').slider('refresh');
+        console.log('Turn on toggle #toggle_connman_' + technology_type);
+    }, 1000);
+}
+
+function connmanToggleOff(technology_type) {
+    setTimeout(function() {
+        $('#toggle_connman_' + technology_type).val('off').slider('refresh');
+        console.log('Turn off toggle #toggle_connman_' + technology_type);
+    }, 1000);
+}
+
+function connmanConnectToService(service, passphrase, success_cb, error_cb) {
+    console.log('Connect to service: ' + service.prop.Name);
+    showSpinner(false, 'Connecting...');
+    service.connect(passphrase, function() {
+        /* success */
+        connmanSync(function() {
+            hideSpinner();
+            if (success_cb) {
+                success_cb();
+            }
+        }, function(e) {
+            hideSpinner();
+            if (error_cb) {
+                error_cb(e);
+            }
+        });
+    }, function(e) {
+        /* error */
+        hideSpinner();
+        if (error_cb) {
+            error_cb(e);
+        }
+    });
+}
+
+function connmanGetHiddenServicePath(security_type, success_cb, error_cb) {
+    if (security_type === undefined || success_cb === undefined || error_cb === undefined) return;
+    settings.connman.scan(function(services) {
+        connmanScanInProgress = false;
+        console.log('found ' + services.length + ' connman services');
+        for (var i = 0; i < services.length; i++) {
+            var service = services[i];
+            if (service.prop.Name === undefined && service.prop.Type === 'wifi') {
+                console.log('Hidden network matched - ' + service.id);
+                success_cb(service.id);
+                return;
+            }
+        }
+        error_cb('No hidden network with security: ' + security_type);
+    }, function(e) {
+        connmanScanInProgress = false;
+        if (error_cb) {
+            error_cb(e);
+        }
+    });
+}
\ No newline at end of file
diff --git a/js/panel-wifi.js b/js/panel-wifi.js
deleted file mode 100644 (file)
index 2ba9683..0000000
+++ /dev/null
@@ -1,607 +0,0 @@
-/*
- * Copyright (c) 2013, Intel Corporation.
- *
- * This program is licensed under the terms and conditions of the
- * Apache License, version 2.0.  The full text of the Apache License is at
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- */
-var wifiScanInProgress = false;
-
-function wifiPanelInit() {
-
-    /* WiFi Settings Panel */
-    $('#page_wifi').on('pageshow', function(event, data) {
-        if (data.prevPage.attr('id') === 'page_wifi_detail') return;
-
-        settings.wifi.subscribeEvents(wifiEventReceived);
-        var adapter = settings.wifi.getDefaultAdapter();
-        if (adapter === null) {
-            showMsg('Error', 'WiFi adapter not found');
-            return;
-        }
-
-        if (adapter.name != undefined) {
-            $('#label_wifi_adapter').html(adapter.name);
-        } else {
-            $('#label_wifi_adapter').html('WiFi adapter not found');
-        }
-
-        adapter.getPowered(function(is_powered) {
-            if (is_powered) {
-                wifiToggleOn();
-                if ($('ul#listview_network_known li').length === 0 && $('ul#listview_network_available li').length === 0) {
-                    wifiClearKnownList();
-                    wifiClearAvailableList();
-                    setTimeout(function() {
-                        wifiScan(adapter);
-                    }, 1000);
-                }
-            } else {
-                wifiToggleOff();
-            }
-        }, function(e) {
-            showMsg('Error', 'Cannot get WiFi state: ' + e);
-        });
-    });
-
-    $('#toggle_wifi').change(function() {
-        if (wifiScanInProgress) return;
-
-        var adapter = settings.wifi.getDefaultAdapter();
-        if (adapter === null) {
-            showMsg('Error', 'WiFi adapter not found');
-            wifiToggleOff();
-            return;
-        }
-
-        if ($('#toggle_wifi').val() === 'off') {
-            adapter.setPowered(false, function() {
-                /* success */
-                console.log('Successfully disable wifi subsystem');
-                wifiToggleOff();
-            }, function(e) {
-                /* error */
-                wifiToggleOn();
-                showMsg('Error', 'Cannot disable WiFi subsystem: ' + e);
-            });
-        } else {
-            adapter.setPowered(true, function() {
-                /* success */
-                console.log('Successfully enable WiFi subsystem');
-                wifiClearKnownList();
-                wifiClearAvailableList();
-                wifiToggleOn();
-                setTimeout(function() {
-                    wifiScan(adapter);
-                }, 1000);
-            }, function(e) {
-                /* error */
-                wifiToggleOff();
-                showMsg('Error', 'Cannot enable WiFi subsystem: ' + e);
-            });
-        }
-    });
-
-    $('#button_wifi_refresh').on('click', function() {
-        var adapter = settings.wifi.getDefaultAdapter();
-        if (adapter === null) {
-            showErr('Error', 'WiFi adapter not found');
-        }
-
-        wifiScan(adapter);
-    });
-
-    $('#button_wifi_add').on('click', function() {
-        if (wifiScanInProgress) return;
-
-        /* Not fully implemented, disable for now */
-        showMsg('Error', 'Not supported');
-        return;
-
-        var adapter = settings.wifi.getDefaultAdapter();
-        if (adapter === null) {
-            showMsg('Error', 'WiFi adapter not found');
-        }
-
-        $.mobile.changePage('#page_wifi_add');
-    });
-
-    /* WiFi network detail page */
-    $('#page_wifi_detail').on('pageshow', function(event, data) {
-        var network_id = localStorage.getItem('wifi_network_id');
-        if (network_id == undefined) return;
-        var network = $(jqId(network_id)).data('network-object');
-        wifiConstructDetailPanel(network);
-    });
-
-    /* WiFi add new network page */
-    $('#page_wifi_add').on('pagebeforeshow', function(event, data) {
-        $('#input_wifi_ssid').val('');
-        $('#input_wifi_password').val('');
-        $('#select_wifi_security').val('None').change();
-        $('#input_wifi_password').textinput('disable');
-    });
-
-    $('#page_wifi_button_add').on('click', function() {
-        var adapter = settings.wifi.getDefaultAdapter();
-        var ssid = $('#input_wifi_ssid').val();
-        var security_option = $('#select_wifi_security').val();
-        var passcode = $('#input_wifi_password').val();
-
-        if (ssid === '') {
-            showMsg('Error', 'Enter SSID');
-            return;
-        }
-        if (security_option !== 'None') {
-            showMsg('Error', 'Not supported');
-            return;
-        }
-
-        showSpinner(false, 'Connecting...');
-        adapter.connectNetwork(ssid, security_option, passcode, function() {
-            /* success */
-            hideSpinner();
-            $.mobile.changePage('#page_wifi');
-
-        }, function(e) {
-            /* error */
-            hideSpinner();
-            showMsg('Error', 'WiFi connect failed: ' + e);
-        });
-    });
-
-    $('#select_wifi_security').on('change', function(event, data) {
-        var security = this.value;
-
-        if (security === 'None') {
-            $('#input_wifi_password').textinput('disable');
-            $('#input_wifi_password').val('');
-        } else {
-            $('#input_wifi_password').textinput('enable');
-        }
-    });
-}
-
-function wifiEventReceived(event) {
-    if (event.type !== WS_EVENT_TYPE.WIFI) return;
-    if ($.mobile.activePage.attr('id') !== 'page_wifi' && $.mobile.activePage.attr('id') !== 'page_wifi_detail') {
-        return;
-    }
-
-    if (event.name === 'ServicesChanged') {
-        wifiHandleServicesChanged(event.id, event.value);
-    } else if (event.name === 'PropertyChanged') {
-        wifiHandlePropertyChanged(event.id, event.value);
-    } else {
-        console.log('Unsupported WiFi event received: ' + event.name);
-    }
-}
-
-function wifiHandleServicesChanged(object_path, services) {
-    var servicesChanged = services[0];
-    var servicesRemoved = services[1];
-
-    if ($('#toggle_wifi').val() === 'off') return;
-
-    console.log(servicesChanged.length + ' networks changed');
-    for (var i = 0; i < servicesChanged.length; i++) {
-        if (servicesChanged[i][0] === undefined) {
-            console.log('Invalid parameters, missing object path');
-            continue;
-        }
-
-        if (servicesChanged[i][1].Type === 'wifi') {
-            var network = $(jqId(servicesChanged[i][0])).data('network-object');
-
-            if (network == null) {
-                console.log('could not find network object ' + servicesChanged[i][0]);
-                continue;
-            }
-
-            var network = new settings.wifi.WiFiNetwork(servicesChanged[i][0]);
-            if (servicesChanged[i][1].Name !== undefined) {
-                network.ssid = servicesChanged[i][1].Name;
-            }
-            if (servicesChanged[i][1].State === 'ready') {
-                network.connected = true;
-            } else if (servicesChanged[i][1].State === 'idle') {
-                network.connected = false;
-            }
-            if (servicesChanged[i][1].EncryptionMode !== undefined) {
-                network.encryption = servicesChanged[i][1].EncryptionMode;
-            }
-            if (servicesChanged[i][1].Strength !== undefined) {
-                network.strength = servicesChanged[i][1].Strength;
-            }
-            if (servicesChanged[i][1].IPv4.Address !== undefined) {
-                network.ipAddress = servicesChanged[i][1].IPv4.Address;
-            }
-            if (servicesChanged[i][1].IPv4.Gateway !== undefined) {
-                network.gateway = servicesChanged[i][1].IPv4.Gateway;
-            }
-            if (servicesChanged[i][1].IPv4.Netmask !== undefined) {
-                network.netmask = servicesChanged[i][1].IPv4.Netmask;
-            }
-
-            if ($.mobile.activePage.attr('id') === 'page_wifi') {
-                console.log('Network updated');
-                wifiUpdateNetwork(network);
-            }
-        }
-    }
-
-    console.log(servicesRemoved.length + ' networks removed');
-    for (var i = 0; i < servicesRemoved.length; i++) {
-        if (servicesRemoved[i] === undefined) {
-            console.log('Invalid parameters, missing object path');
-            continue;
-        }
-
-        wifiRemoveFromKnownList(servicesRemoved[i]);
-        wifiRemoveFromAvailableList(servicesRemoved[i]);
-    }
-}
-
-function wifiHandlePropertyChanged(id, property) {
-    if (property[0] === 'Powered') {
-        if (property[1] === true) {
-            wifiClearKnownList();
-            wifiClearAvailableList();
-            wifiToggleOn();
-            setTimeout(function() {
-                var adapter = settings.wifi.getDefaultAdapter();
-                wifiScan(adapter);
-            }, 1000);
-        } else {
-            wifiToggleOff();
-        }
-    }
-
-    /* if wifi is off, ignore all the propertyChanged events */
-    if ($('#toggle_wifi').val() === 'off') return;
-
-    if (property[0] === 'State') {
-        /* specific network has changed */
-        var network = $(jqId(parent)).data('network-object');
-        if (network == null) {
-            console.error('Wifi network not found');
-            return;
-        }
-
-        if (property[1] === 'ready') {
-            network.connected = true;
-        } else if (property[1] === 'idle') {
-            network.connected = false;
-        }
-
-        wifiUpdateNetwork(network);
-    } else if (property[0] === 'Connected') {
-        /* unknown network has changed, sync WiFi network */
-        console.log('Unknown network connected property changed');
-        var adapter = settings.wifi.getDefaultAdapter();
-        wifiSync(adapter, null, null);
-    }
-}
-
-function wifiClearKnownList() {
-    $('#listview_network_known').html('');
-}
-
-function wifiClearAvailableList() {
-    $('#listview_network_available').html('');
-}
-
-function wifiScan(adapter) {
-    if (wifiScanInProgress) return;
-
-    console.log('Start wifi scan');
-    /* clear the network list with new scan */
-    wifiClearKnownList();
-    wifiClearAvailableList();
-
-    showSpinner(false, 'Scanning...');
-    wifiScanInProgress = true;
-    $('#toggle_wifi').slider('disable');
-    $('#toggle_wifi').slider('refresh');
-    adapter.scan(function(networks) {
-        hideSpinner();
-        wifiScanInProgress = false;
-        $('#toggle_wifi').slider('enable');
-        $('#toggle_wifi').slider('refresh');
-        console.log('found ' + networks.length + ' wifi networks');
-        for (var i = 0; i < networks.length; i++) {
-            var network = networks[i];
-            if (network.ssid && network.ssid !== '') {
-                wifiUpdateNetwork(network);
-            } else {
-                console.log('Skipping hidden network - ' + network.ipAddress);
-            }
-        }
-    }, function(e) {
-        hideSpinner();
-        wifiScanInProgress = false;
-        $('#toggle_wifi').slider('enable');
-        $('#toggle_wifi').slider('refresh');
-        showMsg('Error', 'Cannot scan: ' + e);
-    });
-}
-
-function wifiSync(adapter, success_cb, error_cb) {
-    if (wifiScanInProgress) return;
-
-    console.log('Start wifi sync');
-    /* clear the network list with new scan */
-    wifiClearKnownList();
-    wifiClearAvailableList();
-
-    wifiScanInProgress = true;
-    $('#toggle_wifi').slider('disable');
-    $('#toggle_wifi').slider('refresh');
-    adapter.scan(function(networks) {
-        hideSpinner();
-        wifiScanInProgress = false;
-        $('#toggle_wifi').slider('enable');
-        $('#toggle_wifi').slider('refresh');
-        console.log('found ' + networks.length + ' wifi networks');
-        for (var i = 0; i < networks.length; i++) {
-            var network = networks[i];
-            if (network.ssid && network.ssid !== '') {
-                wifiUpdateNetwork(network);
-            }
-        }
-        if (success_cb) {
-            success_cb();
-        }
-    }, function(e) {
-        wifiScanInProgress = false;
-        $('#toggle_wifi').slider('enable');
-        $('#toggle_wifi').slider('refresh');
-        if (error_cb) {
-            error_cb(e);
-        }
-    });
-}
-
-function wifiRefreshList() {
-    $('#listview_network_known').listview('refresh');
-    $('#listview_network_available').listview('refresh');
-}
-
-function wifiAppendToKnownList(network) {
-    if ($('#listview_network_known').find(jqId(network.id)).length != 0) return;
-
-    var parent = '#listview_network_known';
-    wifiConstructNetworkElement(parent, network);
-    wifiUpdateNetworkButton(network);
-    wifiRefreshList();
-}
-
-function wifiRemoveFromKnownList(network_id) {
-    var removeThis = $('#listview_network_known li').filter(function() {
-        return $(this).find(jqId(network_id)).length === 1;
-    });
-
-    if (removeThis.length !== 0) {
-        removeThis.remove();
-        wifiRefreshList();
-    }
-}
-
-function wifiAppendToAvailableList(network) {
-    if ($('#listview_network_available').find(jqId(network.id)).length != 0) return;
-
-    var parent = '#listview_network_available';
-    wifiConstructNetworkElement(parent, network);
-    wifiUpdateNetworkButton(network);
-    wifiRefreshList();
-}
-
-function wifiRemoveFromAvailableList(network_id) {
-    var removeThis = $('#listview_network_available li').filter(function() {
-        return $(this).find(jqId(network_id)).length === 1;
-    });
-
-    if (removeThis.length !== 0) {
-        removeThis.remove();
-        wifiRefreshList();
-    }
-}
-
-function getSignalStrengthStr(strength) {
-    var signal_strength = 'unknown';
-    if (strength > 0 && strength <= 20) {
-        strength = 'very poor';
-    } else if (strength > 20 && strength <= 40) {
-        signal_strength = 'poor';
-    } else if (strength > 40 && strength <= 70) {
-        signal_strength = 'average';
-    } else if (strength > 70 && strength <= 90) {
-        signal_strength = 'good';
-    } else if (strength > 90 && strength <= 100) {
-        signal_strength = 'excellent';
-    }
-    return signal_strength;
-}
-
-function wifiConstructNetworkElement(parent, network) {
-    var html = '<li data-icon="false"><a href="#" id="' + jqId(network.id).replace('#', '') + '">';
-    html += '<div class="network-ssid">' + network.ssid + '</div>';
-    html += '<div class="network-encryption">Encryption: ' + network.encryption + '</div>';
-    html += '<div class="network-strength">Signal: ' + getSignalStrengthStr(network.strength) + '</div>';
-    html += '<div class="network-status"></div>';
-    html += '<div data-role="button" class="network-action-button ui-li-aside" data-inline="true"></div>';
-    html += '</a></li>';
-    $(parent).append(html).trigger('create');
-
-    /* store network object in the element so we can reference it later */
-    $(jqId(network.id)).data('network-object', network);
-
-    $(jqId(network.id)).on('click', function() {
-        localStorage.setItem('wifi_network_id', network.id);
-        $.mobile.changePage('#page_wifi_detail');
-    });
-
-    $(jqId(network.id)).find('div.network-action-button').on('click', function(e) {
-        var parent = $(this).parent().attr('id');
-
-        /*
-         * prevent the click event to propagate up
-         */
-        e.stopImmediatePropagation();
-        e.preventDefault();
-
-        var adapter = settings.wifi.getDefaultAdapter();
-        if (adapter === null) return;
-
-        /* retrieve the network object from element */
-        var network = $(jqId(parent)).data('network-object');
-        if (network == null) {
-            console.error('Wifi network not found');
-            return;
-        }
-
-        if (!network.connected && network.encryption !== 'none') {
-            /* Encryption based connection not supported now */
-            showMsg('Error', 'Only open networks are supported');
-            return;
-        }
-
-        if (!network.connected) {
-            createPopupDialog(false, false, 'Connect to network', network.ssid, 'Connect', 'Cancel', function() {
-                console.log('WiFi connect to network: ' + network.ssid);
-                showSpinner(false, 'Connecting...');
-                adapter.connectNetwork(network.id, null, null, function() {
-                    /* success */
-                    wifiSync(adapter, function() {
-                        hideSpinner();
-                    }, function(e) {
-                        /* changing from disconnected to connected */
-                        hideSpinner();
-                        network.connected = true;
-                        wifiUpdateNetwork(network);
-                    })
-                }, function(e) {
-                    /* error */
-                    hideSpinner();
-                    showMsg('Error', 'WiFi connect failed: ' + e);
-                });
-            });
-        } else {
-            console.log('Wifi disconnect from network: ' + network.ssid);
-            showSpinner(false, 'Disconnecting...');
-            adapter.disconnectNetwork(network.id, function() {
-                /* success */
-                wifiSync(adapter, function() {
-                    hideSpinner();
-                }, function(e) {
-                    /* changing from connected to disconnected */
-                    hideSpinner();
-                    network.connected = false;
-                    wifiUpdateNetwork(network);
-                })
-            }, function(e) {
-                /* error */
-                hideSpinner();
-                showMsg('Error', 'Network disconnect failed: ' + e);
-            });
-        }
-    });
-}
-
-function wifiUpdateNetwork(network) {
-    /* reposition device if it's connected or disconnected */
-    if (network.connected) {
-        wifiRemoveFromAvailableList(network.id);
-        wifiAppendToKnownList(network);
-    } else {
-        wifiRemoveFromKnownList(network.id);
-        wifiAppendToAvailableList(network);
-    }
-
-    /* update network button for allowed action */
-    wifiUpdateNetworkButton(network);
-
-    /* update network connection status */
-    wifiUpdateConnectionStatus(network);
-
-    /* update network detail panel */
-    if ($.mobile.activePage.attr('id') === 'page_wifi_detail') {
-        var network_id = localStorage.getItem('wifi_network_id');
-        if (network_id == undefined) return;
-        var network_object = $(jqId(network_id)).data('network-object');
-        if (network.id === network_object.id) {
-            wifiConstructDetailPanel(network);
-        }
-    }
-}
-
-function wifiUpdateNetworkButton(network) {
-    if (network.connected) {
-        $(jqId(network.id)).find('div.network-action-button').find('span').text('Disconnect');
-    } else {
-        $(jqId(network.id)).find('div.network-action-button').find('span').text('Connect');
-    }
-}
-
-function wifiUpdateConnectionStatus(network) {
-    var status = 'disconnected';
-    if (network.connected) {
-        $(jqId(network.id)).addClass('network-connected');
-        status = 'connected';
-    } else {
-        status = 'disconnected';
-        $(jqId(network.id)).removeClass('network-connected');
-    }
-
-    wifiUpdateConnectionStatusText(network, status);
-}
-
-function wifiUpdateConnectionStatusText(network, status) {
-    $(jqId(network.id)).find('div.network-status').text(status);
-}
-
-function wifiConstructDetailPanel(network) {
-    var status_connected = 'No';
-
-    if (network == null) return;
-    if (network.connected) status_connected = 'Yes';
-
-    $('#page_wifi_detail_content').html('');
-    var html = '<ul data-role="listview" id="listview_network_detail" data-inset="true" ' + 'class="network-list ui-listview">';
-    html += '<li id="network_detail_ssid"><h2>SSID: ' + network.ssid + '</h2></li>';
-    html += '<li id="network_detail_encryption"><h2>Encryption: ' + network.encryption + '</h2></li>';
-    html += '<li id="network_detail_strength"><h2>Signal Strength: ' + network.strength + '</h2></li>';
-    html += '<li id="network_detail_connected"><h2>Connected: ' + status_connected + '</h2></li>';
-    if (network.connected) {
-        html += '<li id="network_detail_ip_address"><h2>IP Address: ' + network.ipAddress + '</h2></li>';
-        html += '<li id="network_detail_gateway"><h2>Gateway: ' + network.gateway + '</h2></li>';
-        html += '<li id="network_detail_netmask"><h2>Netmask: ' + network.netmask + '</h2></li>';
-    }
-    html += '</ul>';
-    $('#page_wifi_detail_content').append(html).trigger('create');
-    $('#listview_wifi_detail').listview('refresh');
-}
-
-function wifiUpdateDetailPanel(network) {
-    var status_connected = 'No';
-
-    if (network == null) return;
-    if (network.connected) status_connected = 'Yes';
-    $('#wifi_detail_connected').text(status_connected);
-    $('#listview_wifi_detail').listview('refresh');
-}
-
-function wifiToggleOn() {
-    setTimeout(function() {
-        $('#wifi_networks').show();
-        $('#toggle_wifi').val('on').slider('refresh');
-    }, 100);
-}
-
-function wifiToggleOff() {
-    setTimeout(function() {
-        $('#wifi_networks').hide();
-        $('#toggle_wifi').val('off').slider('refresh');
-    }, 100);
-}
\ No newline at end of file
index cbf0067..9345063 100644 (file)
@@ -15,7 +15,7 @@ function jqId(id) {
 }
 
 function showMsg(title, message) {
-    if (title == 'Error') {
+    if (title === 'Error') {
         console.error(message);
         if (message.indexOf(ERROR_SETTINGSD_DISCONNECTED) >= 0) {
             createPopupDialog(false, false, ERROR_SETTINGSD_DISCONNECTED, 'Reconnect?', 'OK', 'Cancel', function() {
index c4c962d..901c1c2 100644 (file)
@@ -13,6 +13,7 @@ var dummyBackend = false;
 var ERROR_SETTINGSD_DISCONNECTED = 'Settings daemon is not connected';
 
 var WS_REQUEST_TYPE = {
+    CONNMAN: "connman::manager",
     WIFI: "wifi",
     BLUETOOTH: "bluetooth",
     DISPLAY: "display",
@@ -22,6 +23,7 @@ var WS_REQUEST_TYPE = {
 };
 
 var WS_EVENT_TYPE = {
+    CONNMAN: "connman::manager",
     WIFI: "wifi",
     BLUETOOTH: "bluetooth",
     DISPLAY: "display",
@@ -155,6 +157,7 @@ var wsAPI = (function() {
         this.methodCalls[i].start();
 
         var jsonMsg = JSON.stringify(msg);
+        console.log('Sending json msg: ' + jsonMsg);
         if (dummyBackend) {
             /* fake with dummy data */
             dummyBackendSend(msg);
@@ -172,6 +175,7 @@ var wsAPI = (function() {
         var self = this;
         var response;
         try {
+            console.log("Received json msg: " + msg);
             response = JSON.parse(msg);
         } catch (e) {
             console.error('Garbage message: ' + msg);
@@ -191,10 +195,8 @@ var wsAPI = (function() {
                     return;
                 }
 
-                if (response.value.object_path === '/' || response.value.object_path.indexOf('/net/connman/technology/wifi') >= 0) {
-                    fireEvent(WS_REQUEST_TYPE.WIFI, response.value.object_path, response.value.signal_name, response.value.parameters);
-                } else if (response.value.object_path.indexOf('/net/connman/technology/bluetooth') >= 0) {
-                    fireEvent(WS_REQUEST_TYPE.BLUETOOTH, response.value.object_path, response.value.signal_name, response.value.parameters);
+                if (response.value.object_path === '/' || response.value.object_path.indexOf('/net/connman/technology/') >= 0) {
+                    fireEvent(WS_REQUEST_TYPE.CONNMAN, response.value.object_path, response.value.signal_name, response.value.parameters);
                 } else {
                     console.error('Unrecognized event object_path, skipping');
                 }
@@ -210,7 +212,6 @@ var wsAPI = (function() {
                 if (call && (!call.done) && (call.transactionid === response.transactionid)) {
                     call.finish();
                     if (response.result !== 'succeeded' && response.reason !== undefined && call.errorCB !== undefined) {
-                        console.log('error - ' + response.reason);
                         call.errorCB(response.reason);
                     } else if (call.successCB !== undefined) {
                         if (response.value !== undefined) {
index 3ce5dac..7142887 100644 (file)
@@ -1,3 +1,6 @@
+* Fri Nov 15 2013 Jimmy Huang <jimmy.huang@intel.com> submit/tizen_ivi_milestone/20131113.054020@1cf567d
+- Refactor WiFi module
+
 * Thu Oct 17 2013 Jimmy Huang <jimmy.huang@intel.com> accepted/tizen/20131007.221312@7a2360b
 - Improve page load time by not doing a scan everytime user enters page