</li>
</ul>
</div>
+ <div id="connman_tethering">
+ <ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">
+ <li data-role="fieldcontain">
+ <a href="#page_connman_tethering">Tethering</a>
+ </li>
+ </ul>
+ </div>
<div id="connman_services">
<div>
<p>Available Services</p>
</div>
</div>
+ <!-- Connman Tethering -->
+ <div data-role="page" id="page_connman_tethering">
+ <div data-role="header" data-position="fixed">
+ <a href="#page_connman" data-icon="back">Back</a>
+ <h1>Tethering</h1>
+ </div>
+
+ <div data-role="content">
+ <div id="connman_tethering_technologies"></div>
+
+ <label for="input_wifi_tethering_id">Tethering Identifier:</label>
+ <input type="text" name="name" id="input_wifi_tethering_id" value="" />
+
+ <label for="input_wifi_tethering_passphrase">Tethering Passphrase:</label>
+ <input type="password" name="name" id="input_wifi_tethering_passphrase" value="" />
+ </div>
+ </div>
+
<!-- Connman Service Info -->
<div data-role="page" id="page_connman_service">
<div data-role="header" data-position="fixed">
}, error_cb);
};
+ ConnmanTechnology.prototype.setTethering = function(tethered, identifier, passphrase, success_cb, error_cb) {
+ if (wsAPI === undefined) return;
+ if (this.setTetheringInProgress) {
+ console.log('Activating/Deactiviating tethering in progress');
+ return;
+ }
+
+ var me = this;
+ this.setTetheringInProgress = true;
+
+ var tethering_options = {
+ 'path': me.id,
+ 'ssid': identifier,
+ 'password': passphrase,
+ 'enabled': tethered
+ };
+
+ wsAPI.sendRequest(WS_REQUEST_TYPE.CONNMAN_TECHNOLOGY, 'tethering', tethering_options, function() {
+ me.setTetheringInProgress = false;
+ success_cb();
+ }, function(e) {
+ if (e.indexOf('Already enabled') >= 0) {
+ console.log('tethering ' + me.prop.Type + ' already enabled');
+ me.setTetheringInProgress = false;
+ success_cb();
+ } else if (e.indexOf('Already disabled') >= 0) {
+ console.log('tethering ' + me.prop.Type + ' already disabled');
+ me.setTetheringInProgress = false;
+ success_cb();
+ } else {
+ me.setTetheringInProgress = false;
+ error_cb(e);
+ }
+ })
+ };
+
/* Service class */
ConnmanService = function(service_path, service_properties) {
this.id = service_path;
$.mobile.changePage('#page_wifi_add');
});
+ /* Connman tethering page */
+ $('#page_connman_tethering').on('pageshow', function(event, data) {
+ connmanTetheringPageReload();
+ });
+
/* Connman service detail page */
$('#page_connman_service').on('pageshow', function(event, data) {
var service_id = localStorage.getItem('connman_service_id');
});
}
+function connmanTetheringPageReload() {
+ $('#connman_tethering_technologies').html('');
+ settings.connman.getTechnologies(function(technologies) {
+ for (var i = 0; i < technologies.length; i++) {
+ var technology = technologies[i];
+ console.log('Connman technology available for tethering: ' + technology.prop.Name);
+ connmanConstructTetheringElement(technology);
+ }
+ }, function(e) {
+ showMsg('Error', e);
+ });
+}
+
+function connmanConstructTetheringElement(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_tethering_' + technology.prop.Type + '" class="ui-slider">Tether ' + technology.prop.Name + '</label>';
+ html += '<select data-role="slider" name="toggle_tethering_' + technology.prop.Type + '" ';
+ html += 'id="toggle_tethering_' + technology.prop.Type + '" class="ui-slider-switch">';
+ html += '<option value="off">Off</option>';
+ html += '<option value="on">On</option>';
+ html += '</select></li></ul>';
+ $('#connman_tethering_technologies').append(html).trigger('create');
+
+ console.log('Connman technology ' + technology.prop.Type + ' is tethered: ' + technology.prop.Tethering);
+
+ if (technology.prop.Powered === true && technology.prop.Connected === true) {
+ if (technology.prop.Tethering === true) {
+ $('#toggle_tethering_' + technology.prop.Type).val('on').slider('refresh');
+ $('#input_wifi_tethering_id').textinput('disable');
+ $('#input_wifi_tethering_passphrase').textinput('disable');
+ /* WiFi-only options */
+ if (technology.prop.Type === 'wifi') {
+ $('#connman_wifi_tethering_options').show();
+ if (technology.prop.TetheringIdentifier) {
+ $('#input_wifi_tethering_id').val(technology.prop.TetheringIdentifier);
+ }
+ if (technology.prop.TetheringPassphrase) {
+ $('#input_wifi_tethering_passphrase').val(technology.prop.TetheringPassphrase);
+ }
+ }
+ } else {
+ $('#toggle_tethering_' + technology.prop.Type).val('off').slider('refresh');
+ }
+ } else {
+ if (technology.prop.Type === 'wifi') {
+ $('#input_wifi_tethering_id').textinput('disable');
+ $('#input_wifi_tethering_passphrase').textinput('disable');
+ }
+ $('#toggle_tethering_' + technology.prop.Type).slider('disable');
+ $('#toggle_tethering_' + technology.prop.Type).slider('refresh');
+ }
+
+ $('#toggle_tethering_' + technology.prop.Type).change(function() {
+ if ($('#toggle_tethering_' + technology.prop.Type).val() === 'on') {
+ if (technology.prop.Type === 'wifi') {
+ var tethering_id = $('#input_wifi_tethering_id').val();
+ var tethering_passphrase = $('#input_wifi_tethering_passphrase').val();
+ if (tethering_id === '' || tethering_passphrase === '') {
+ connmanTetheringPageReload();
+ showMsg('Error', 'Please provide identifier and passphrase');
+ return;
+ }
+
+ technology.setTethering(true, tethering_id, tethering_passphrase, function() {
+ /* success */
+ console.log('Successfully tethered connman technology ' + technology.prop.Type);
+ connmanTetheringPageReload();
+ }, function(e) {
+ /* error */
+ connmanTetheringPageReload();
+ showMsg('Error', 'Cannot tether ' + technology.prop.Type + ': ' + e);
+ });
+ } else {
+ technology.setTethering(true, '', '', function() {
+ /* success */
+ console.log('Successfully tethered connman technology ' + technology.prop.Type);
+ connmanTetheringPageReload();
+ }, function(e) {
+ /* error */
+ connmanTetheringPageReload();
+ showMsg('Error', 'Cannot tether ' + technology.prop.Type + ': ' + e);
+ });
+ }
+ } else {
+ technology.setTethering(false, '', '', function() {
+ /* success */
+ console.log('Successfully untethered connman technology ' + technology.prop.Type);
+ connmanTetheringPageReload();
+ }, function(e) {
+ /* error */
+ connmanTetheringPageReload();
+ showMsg('Error', 'Cannot untether ' + technology.prop.Type + ': ' + e);
+ });
+ }
+ });
+}
+
function connmanUpdateService(service) {
connmanAppendToAvailableList(service);