2010-07-24 07:57:53 -04:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Gdk = imports.gi.Gdk;
|
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GnomeBluetoothApplet = imports.gi.GnomeBluetoothApplet;
|
|
|
|
const Gtk = imports.gi.Gtk;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Mainloop = imports.mainloop;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
const MessageTray = imports.ui.messageTray;
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
|
|
|
|
const ConnectionState = {
|
|
|
|
DISCONNECTED: 0,
|
|
|
|
CONNECTED: 1,
|
|
|
|
DISCONNECTING: 2,
|
|
|
|
CONNECTING: 3
|
|
|
|
}
|
|
|
|
|
|
|
|
function Indicator() {
|
|
|
|
this._init.apply(this, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
Indicator.prototype = {
|
|
|
|
__proto__: PanelMenu.SystemStatusButton.prototype,
|
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
PanelMenu.SystemStatusButton.prototype._init.call(this, 'bluetooth-disabled', null);
|
|
|
|
|
|
|
|
GLib.spawn_command_line_sync ('pkill -f "^bluetooth-applet$"');
|
|
|
|
this._applet = new GnomeBluetoothApplet.Applet();
|
|
|
|
|
|
|
|
this._killswitch = new PopupMenu.PopupSwitchMenuItem(_("Bluetooth"), false);
|
|
|
|
this._applet.connect('notify::killswitch-state', Lang.bind(this, this._updateKillswitch));
|
|
|
|
this._killswitch.connect('toggled', Lang.bind(this, function() {
|
|
|
|
let current_state = this._applet.killswitch_state;
|
|
|
|
if (current_state != GnomeBluetoothApplet.KillswitchState.HARD_BLOCKED &&
|
|
|
|
current_state != GnomeBluetoothApplet.KillswitchState.NO_ADAPTER) {
|
|
|
|
this._applet.killswitch_state = this._killswitch.state ?
|
|
|
|
GnomeBluetoothApplet.KillswitchState.UNBLOCKED:
|
|
|
|
GnomeBluetoothApplet.KillswitchState.SOFT_BLOCKED;
|
|
|
|
} else
|
|
|
|
this._killswitch.setToggleState(false);
|
|
|
|
}));
|
|
|
|
|
|
|
|
this._discoverable = new PopupMenu.PopupSwitchMenuItem(_("Visibility"), this._applet.discoverable);
|
|
|
|
this._applet.connect('notify::discoverable', Lang.bind(this, function() {
|
|
|
|
this._discoverable.setToggleState(this._applet.discoverable);
|
|
|
|
}));
|
|
|
|
this._discoverable.connect('toggled', Lang.bind(this, function() {
|
|
|
|
this._applet.discoverable = this._discoverable.state;
|
|
|
|
}));
|
|
|
|
|
|
|
|
this._updateKillswitch();
|
|
|
|
this.menu.addMenuItem(this._killswitch);
|
|
|
|
this.menu.addMenuItem(this._discoverable);
|
|
|
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
|
|
|
|
2010-12-21 09:59:55 -05:00
|
|
|
this._fullMenuItems = [new PopupMenu.PopupSeparatorMenuItem(),
|
|
|
|
new PopupMenu.PopupMenuItem(_("Send Files to Device...")),
|
2011-04-21 14:40:37 -04:00
|
|
|
new PopupMenu.PopupMenuItem(_("Set up a New Device...")),
|
2011-01-17 15:02:03 -05:00
|
|
|
new PopupMenu.PopupSeparatorMenuItem()];
|
2010-12-21 10:26:26 -05:00
|
|
|
this._hasDevices = false;
|
2010-12-21 09:59:55 -05:00
|
|
|
this._deviceSep = this._fullMenuItems[0]; // hidden if no device exists
|
2010-07-24 07:57:53 -04:00
|
|
|
|
2010-12-21 09:59:55 -05:00
|
|
|
this._fullMenuItems[1].connect('activate', function() {
|
2010-07-24 07:57:53 -04:00
|
|
|
GLib.spawn_command_line_async('bluetooth-sendto');
|
|
|
|
});
|
2010-12-21 09:59:55 -05:00
|
|
|
this._fullMenuItems[2].connect('activate', function() {
|
2010-07-24 07:57:53 -04:00
|
|
|
GLib.spawn_command_line_async('bluetooth-wizard');
|
|
|
|
});
|
|
|
|
|
|
|
|
for (let i = 0; i < this._fullMenuItems.length; i++) {
|
|
|
|
let item = this._fullMenuItems[i];
|
|
|
|
this.menu.addMenuItem(item);
|
|
|
|
}
|
|
|
|
|
2010-12-21 09:59:55 -05:00
|
|
|
this._deviceItemPosition = 3;
|
2010-07-24 07:57:53 -04:00
|
|
|
this._deviceItems = [];
|
|
|
|
this._applet.connect('devices-changed', Lang.bind(this, this._updateDevices));
|
|
|
|
this._updateDevices();
|
|
|
|
|
|
|
|
this._applet.connect('notify::show-full-menu', Lang.bind(this, this._updateFullMenu));
|
|
|
|
this._updateFullMenu();
|
|
|
|
|
|
|
|
this.menu.addAction(_("Bluetooth Settings"), function() {
|
2011-06-21 18:26:57 -04:00
|
|
|
Main.overview.hide()
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 13:35:01 -04:00
|
|
|
let app = Shell.AppSystem.get_default().lookup_setting('bluetooth-properties.desktop');
|
2011-08-11 05:35:23 -04:00
|
|
|
app.activate();
|
2010-07-24 07:57:53 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
this._applet.connect('pincode-request', Lang.bind(this, this._pinRequest));
|
|
|
|
this._applet.connect('confirm-request', Lang.bind(this, this._confirmRequest));
|
|
|
|
this._applet.connect('auth-request', Lang.bind(this, this._authRequest));
|
|
|
|
this._applet.connect('cancel-request', Lang.bind(this, this._cancelRequest));
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateKillswitch: function() {
|
|
|
|
let current_state = this._applet.killswitch_state;
|
|
|
|
let on = current_state == GnomeBluetoothApplet.KillswitchState.UNBLOCKED;
|
2010-12-30 09:34:42 -05:00
|
|
|
let has_adapter = current_state != GnomeBluetoothApplet.KillswitchState.NO_ADAPTER;
|
2010-07-24 07:57:53 -04:00
|
|
|
let can_toggle = current_state != GnomeBluetoothApplet.KillswitchState.NO_ADAPTER &&
|
|
|
|
current_state != GnomeBluetoothApplet.KillswitchState.HARD_BLOCKED;
|
|
|
|
|
|
|
|
this._killswitch.setToggleState(on);
|
2011-04-21 11:02:19 -04:00
|
|
|
if (can_toggle)
|
|
|
|
this._killswitch.setStatus(null);
|
|
|
|
else
|
|
|
|
/* TRANSLATORS: this means that bluetooth was disabled by hardware rfkill */
|
|
|
|
this._killswitch.setStatus(_("hardware disabled"));
|
2010-07-24 07:57:53 -04:00
|
|
|
|
2010-12-30 09:34:42 -05:00
|
|
|
if (has_adapter)
|
|
|
|
this.actor.show();
|
|
|
|
else
|
|
|
|
this.actor.hide();
|
|
|
|
|
2010-07-24 07:57:53 -04:00
|
|
|
if (on) {
|
|
|
|
this._discoverable.actor.show();
|
|
|
|
this.setIcon('bluetooth-active');
|
|
|
|
} else {
|
|
|
|
this._discoverable.actor.hide();
|
|
|
|
this.setIcon('bluetooth-disabled');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-12-21 10:26:26 -05:00
|
|
|
_updateDevices: function() {
|
2010-07-24 07:57:53 -04:00
|
|
|
let devices = this._applet.get_devices();
|
2010-12-21 10:26:26 -05:00
|
|
|
|
2011-03-15 16:22:57 -04:00
|
|
|
let newlist = [ ];
|
2010-12-21 10:26:26 -05:00
|
|
|
for (let i = 0; i < this._deviceItems.length; i++) {
|
2010-12-30 09:34:42 -05:00
|
|
|
let item = this._deviceItems[i];
|
2010-12-21 10:26:26 -05:00
|
|
|
let destroy = true;
|
|
|
|
for (let j = 0; j < devices.length; j++) {
|
2011-04-13 13:08:45 -04:00
|
|
|
if (item._device.device_path == devices[j].device_path) {
|
|
|
|
this._updateDeviceItem(item, devices[j]);
|
2010-12-21 10:26:26 -05:00
|
|
|
destroy = false;
|
2011-03-15 16:22:57 -04:00
|
|
|
break;
|
2010-12-21 10:26:26 -05:00
|
|
|
}
|
|
|
|
}
|
2011-03-15 16:22:57 -04:00
|
|
|
if (destroy)
|
2010-12-21 10:26:26 -05:00
|
|
|
item.destroy();
|
2011-03-15 16:22:57 -04:00
|
|
|
else
|
2010-12-21 10:26:26 -05:00
|
|
|
newlist.push(item);
|
|
|
|
}
|
|
|
|
|
2011-03-15 16:22:57 -04:00
|
|
|
this._deviceItems = newlist;
|
2010-12-21 10:26:26 -05:00
|
|
|
this._hasDevices = newlist.length > 0;
|
2010-07-24 07:57:53 -04:00
|
|
|
for (let i = 0; i < devices.length; i++) {
|
|
|
|
let d = devices[i];
|
2011-04-13 13:08:45 -04:00
|
|
|
if (d._item)
|
2010-12-21 10:26:26 -05:00
|
|
|
continue;
|
2010-07-24 07:57:53 -04:00
|
|
|
let item = this._createDeviceItem(d);
|
|
|
|
if (item) {
|
|
|
|
this.menu.addMenuItem(item, this._deviceItemPosition + this._deviceItems.length);
|
|
|
|
this._deviceItems.push(item);
|
2010-12-21 10:26:26 -05:00
|
|
|
this._hasDevices = true;
|
2010-07-24 07:57:53 -04:00
|
|
|
}
|
|
|
|
}
|
2010-12-21 10:26:26 -05:00
|
|
|
if (this._hasDevices)
|
2010-12-20 11:58:12 -05:00
|
|
|
this._deviceSep.actor.show();
|
|
|
|
else
|
|
|
|
this._deviceSep.actor.hide();
|
2010-07-24 07:57:53 -04:00
|
|
|
},
|
|
|
|
|
2011-04-13 13:08:45 -04:00
|
|
|
_updateDeviceItem: function(item, device) {
|
|
|
|
if (!device.can_connect && device.capabilities == GnomeBluetoothApplet.Capabilities.NONE) {
|
|
|
|
item.destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let prevDevice = item._device;
|
|
|
|
let prevCapabilities = prevDevice.capabilities;
|
|
|
|
let prevCanConnect = prevDevice.can_connect;
|
|
|
|
|
|
|
|
// adopt the new device object
|
|
|
|
item._device = device;
|
|
|
|
device._item = item;
|
|
|
|
|
|
|
|
// update properties
|
|
|
|
item.label.text = device.alias;
|
|
|
|
|
|
|
|
if (prevCapabilities != device.capabilities ||
|
|
|
|
prevCanConnect != device.can_connect) {
|
|
|
|
// need to rebuild the submenu
|
|
|
|
item.menu.removeAll();
|
|
|
|
this._buildDeviceSubMenu(item, device);
|
|
|
|
}
|
|
|
|
|
|
|
|
// update connected property
|
|
|
|
if (device.can_connect)
|
|
|
|
item._connectedMenuitem.setToggleState(device.connected);
|
|
|
|
},
|
|
|
|
|
2010-07-24 07:57:53 -04:00
|
|
|
_createDeviceItem: function(device) {
|
|
|
|
if (!device.can_connect && device.capabilities == GnomeBluetoothApplet.Capabilities.NONE)
|
|
|
|
return null;
|
|
|
|
let item = new PopupMenu.PopupSubMenuMenuItem(device.alias);
|
2011-04-13 13:08:45 -04:00
|
|
|
|
|
|
|
// adopt the device object, and add a back link
|
2010-07-24 07:57:53 -04:00
|
|
|
item._device = device;
|
2011-04-13 13:08:45 -04:00
|
|
|
device._item = item;
|
2010-07-24 07:57:53 -04:00
|
|
|
|
2011-04-13 13:08:45 -04:00
|
|
|
this._buildDeviceSubMenu(item, device);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
},
|
|
|
|
|
|
|
|
_buildDeviceSubMenu: function(item, device) {
|
2010-07-24 07:57:53 -04:00
|
|
|
if (device.can_connect) {
|
|
|
|
item._connected = device.connected;
|
2011-04-13 13:08:45 -04:00
|
|
|
item._connectedMenuitem = new PopupMenu.PopupSwitchMenuItem(_("Connection"), device.connected);
|
|
|
|
item._connectedMenuitem.connect('toggled', Lang.bind(this, function() {
|
2010-07-24 07:57:53 -04:00
|
|
|
if (item._connected > ConnectionState.CONNECTED) {
|
|
|
|
// operation already in progress, revert
|
2011-04-21 11:02:19 -04:00
|
|
|
// (should not happen anyway)
|
2010-07-24 07:57:53 -04:00
|
|
|
menuitem.setToggleState(menuitem.state);
|
|
|
|
}
|
|
|
|
if (item._connected) {
|
|
|
|
item._connected = ConnectionState.DISCONNECTING;
|
2011-04-21 11:02:19 -04:00
|
|
|
menuitem.setStatus(_("disconnecting..."));
|
2010-07-24 07:57:53 -04:00
|
|
|
this._applet.disconnect_device(item._device.device_path, function(applet, success) {
|
|
|
|
if (success) { // apply
|
|
|
|
item._connected = ConnectionState.DISCONNECTED;
|
|
|
|
menuitem.setToggleState(false);
|
|
|
|
} else { // revert
|
|
|
|
item._connected = ConnectionState.CONNECTED;
|
|
|
|
menuitem.setToggleState(true);
|
|
|
|
}
|
2011-04-21 11:02:19 -04:00
|
|
|
menuitem.setStatus(null);
|
2010-07-24 07:57:53 -04:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
item._connected = ConnectionState.CONNECTING;
|
2011-04-21 11:02:19 -04:00
|
|
|
menuitem.setStatus(_("connecting..."));
|
2010-07-24 07:57:53 -04:00
|
|
|
this._applet.connect_device(item._device.device_path, function(applet, success) {
|
|
|
|
if (success) { // apply
|
|
|
|
item._connected = ConnectionState.CONNECTED;
|
|
|
|
menuitem.setToggleState(true);
|
|
|
|
} else { // revert
|
|
|
|
item._connected = ConnectionState.DISCONNECTED;
|
|
|
|
menuitem.setToggleState(false);
|
|
|
|
}
|
2011-04-21 11:02:19 -04:00
|
|
|
menuitem.setStatus(null);
|
2010-07-24 07:57:53 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
2011-04-13 13:08:45 -04:00
|
|
|
item.menu.addMenuItem(item._connectedMenuitem);
|
2010-07-24 07:57:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (device.capabilities & GnomeBluetoothApplet.Capabilities.OBEX_PUSH) {
|
|
|
|
item.menu.addAction(_("Send Files..."), Lang.bind(this, function() {
|
|
|
|
this._applet.send_to_address(device.bdaddr, device.alias);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
if (device.capabilities & GnomeBluetoothApplet.Capabilities.OBEX_FILE_TRANSFER) {
|
|
|
|
item.menu.addAction(_("Browse Files..."), Lang.bind(this, function(event) {
|
|
|
|
this._applet.browse_address(device.bdaddr, event.get_time(),
|
|
|
|
Lang.bind(this, function(applet, result) {
|
|
|
|
try {
|
|
|
|
applet.browse_address_finish(result);
|
|
|
|
} catch (e) {
|
|
|
|
this._ensureSource();
|
|
|
|
this._source.notify(new MessageTray.Notification(this._source,
|
|
|
|
_("Bluetooth"),
|
|
|
|
_("Error browsing device"),
|
|
|
|
{ body: _("The requested device cannot be browsed, error is '%s'").format(e) }));
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (device.type) {
|
|
|
|
case GnomeBluetoothApplet.Type.KEYBOARD:
|
|
|
|
item.menu.addAction(_("Keyboard Settings"), function() {
|
|
|
|
GLib.spawn_command_line_async('gnome-control-center keyboard');
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case GnomeBluetoothApplet.Type.MOUSE:
|
|
|
|
item.menu.addAction(_("Mouse Settings"), function() {
|
|
|
|
GLib.spawn_command_line_async('gnome-control-center mouse');
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case GnomeBluetoothApplet.Type.HEADSET:
|
|
|
|
case GnomeBluetoothApplet.Type.HEADPHONES:
|
|
|
|
case GnomeBluetoothApplet.Type.OTHER_AUDIO:
|
|
|
|
item.menu.addAction(_("Sound Settings"), function() {
|
|
|
|
GLib.spawn_command_line_async('gnome-control-center sound');
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateFullMenu: function() {
|
|
|
|
if (this._applet.show_full_menu) {
|
|
|
|
this._showAll(this._fullMenuItems);
|
2010-12-21 09:53:28 -05:00
|
|
|
if (this._hasDevices)
|
|
|
|
this._showAll(this._deviceItems);
|
|
|
|
else
|
2011-01-06 14:35:21 -05:00
|
|
|
this._deviceSep.actor.hide();
|
2010-07-24 07:57:53 -04:00
|
|
|
} else {
|
|
|
|
this._hideAll(this._fullMenuItems);
|
|
|
|
this._hideAll(this._deviceItems);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_showAll: function(items) {
|
|
|
|
for (let i = 0; i < items.length; i++)
|
|
|
|
items[i].actor.show();
|
|
|
|
},
|
|
|
|
|
|
|
|
_hideAll: function(items) {
|
|
|
|
for (let i = 0; i < items.length; i++)
|
|
|
|
items[i].actor.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
_destroyAll: function(items) {
|
|
|
|
for (let i = 0; i < items.length; i++)
|
|
|
|
items[i].destroy();
|
|
|
|
},
|
|
|
|
|
|
|
|
_ensureSource: function() {
|
|
|
|
if (!this._source) {
|
|
|
|
this._source = new Source();
|
|
|
|
Main.messageTray.add(this._source);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_authRequest: function(applet, device_path, name, long_name, uuid) {
|
|
|
|
this._ensureSource();
|
|
|
|
this._source.notify(new AuthNotification(this._source, this._applet, device_path, name, long_name, uuid));
|
|
|
|
},
|
|
|
|
|
|
|
|
_confirmRequest: function(applet, device_path, name, long_name, pin) {
|
|
|
|
this._ensureSource();
|
|
|
|
this._source.notify(new ConfirmNotification(this._source, this._applet, device_path, name, long_name, pin));
|
|
|
|
},
|
|
|
|
|
|
|
|
_pinRequest: function(applet, device_path, name, long_name, numeric) {
|
|
|
|
this._ensureSource();
|
|
|
|
this._source.notify(new PinNotification(this._source, this._applet, device_path, name, long_name, numeric));
|
|
|
|
},
|
|
|
|
|
|
|
|
_cancelRequest: function() {
|
|
|
|
this._source.destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function Source() {
|
|
|
|
this._init.apply(this, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
Source.prototype = {
|
|
|
|
__proto__: MessageTray.Source.prototype,
|
|
|
|
|
|
|
|
_init: function() {
|
2011-02-09 17:08:02 -05:00
|
|
|
MessageTray.Source.prototype._init.call(this, _("Bluetooth"));
|
2010-07-24 07:57:53 -04:00
|
|
|
|
|
|
|
this._setSummaryIcon(this.createNotificationIcon());
|
|
|
|
},
|
|
|
|
|
|
|
|
notify: function(notification) {
|
|
|
|
this._private_destroyId = notification.connect('destroy', Lang.bind(this, function(notification) {
|
|
|
|
if (this.notification == notification) {
|
|
|
|
// the destroyed notification is the last for this source
|
|
|
|
this.notification.disconnect(this._private_destroyId);
|
|
|
|
this.destroy();
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
MessageTray.Source.prototype.notify.call(this, notification);
|
|
|
|
},
|
|
|
|
|
|
|
|
createNotificationIcon: function() {
|
|
|
|
return new St.Icon({ icon_name: 'bluetooth-active',
|
|
|
|
icon_type: St.IconType.SYMBOLIC,
|
|
|
|
icon_size: this.ICON_SIZE });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function AuthNotification() {
|
|
|
|
this._init.apply(this, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
AuthNotification.prototype = {
|
|
|
|
__proto__: MessageTray.Notification.prototype,
|
|
|
|
|
|
|
|
_init: function(source, applet, device_path, name, long_name, uuid) {
|
|
|
|
MessageTray.Notification.prototype._init.call(this,
|
|
|
|
source,
|
2011-02-09 17:08:02 -05:00
|
|
|
_("Bluetooth"),
|
2010-07-24 07:57:53 -04:00
|
|
|
_("Authorization request from %s").format(name),
|
|
|
|
{ customContent: true });
|
|
|
|
this.setResident(true);
|
|
|
|
|
|
|
|
this._applet = applet;
|
|
|
|
this._devicePath = device_path;
|
|
|
|
this.addBody(_("Device %s wants access to the service '%s'").format(long_name, uuid));
|
|
|
|
|
|
|
|
this.addButton('always-grant', _("Always grant access"));
|
|
|
|
this.addButton('grant', _("Grant this time only"));
|
|
|
|
this.addButton('reject', _("Reject"));
|
|
|
|
|
|
|
|
this.connect('action-invoked', Lang.bind(this, function(self, action) {
|
|
|
|
switch (action) {
|
|
|
|
case 'always-grant':
|
|
|
|
this._applet.agent_reply_auth(this._devicePath, true, true);
|
|
|
|
break;
|
|
|
|
case 'grant':
|
|
|
|
this._applet.agent_reply_auth(this._devicePath, true, false);
|
|
|
|
break;
|
|
|
|
case 'reject':
|
|
|
|
default:
|
|
|
|
this._applet.agent_reply_auth(this._devicePath, false, false);
|
|
|
|
}
|
|
|
|
this.destroy();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function ConfirmNotification() {
|
|
|
|
this._init.apply(this, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmNotification.prototype = {
|
|
|
|
__proto__: MessageTray.Notification.prototype,
|
|
|
|
|
|
|
|
_init: function(source, applet, device_path, name, long_name, pin) {
|
|
|
|
MessageTray.Notification.prototype._init.call(this,
|
|
|
|
source,
|
2011-02-09 17:08:02 -05:00
|
|
|
_("Bluetooth"),
|
2010-07-24 07:57:53 -04:00
|
|
|
_("Pairing confirmation for %s").format(name),
|
|
|
|
{ customContent: true });
|
|
|
|
this.setResident(true);
|
|
|
|
|
|
|
|
this._applet = applet;
|
|
|
|
this._devicePath = device_path;
|
|
|
|
this.addBody(_("Device %s wants to pair with this computer").format(long_name));
|
|
|
|
this.addBody(_("Please confirm whether the PIN '%s' matches the one on the device.").format(pin));
|
|
|
|
|
|
|
|
this.addButton('matches', _("Matches"));
|
|
|
|
this.addButton('does-not-match', _("Does not match"));
|
|
|
|
|
|
|
|
this.connect('action-invoked', Lang.bind(this, function(self, action) {
|
|
|
|
if (action == 'matches')
|
|
|
|
this._applet.agent_reply_confirm(this._devicePath, true);
|
|
|
|
else
|
|
|
|
this._applet.agent_reply_confirm(this._devicePath, false);
|
|
|
|
this.destroy();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function PinNotification() {
|
|
|
|
this._init.apply(this, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
PinNotification.prototype = {
|
|
|
|
__proto__: MessageTray.Notification.prototype,
|
|
|
|
|
|
|
|
_init: function(source, applet, device_path, name, long_name, numeric) {
|
|
|
|
MessageTray.Notification.prototype._init.call(this,
|
|
|
|
source,
|
2011-02-09 17:08:02 -05:00
|
|
|
_("Bluetooth"),
|
2010-07-24 07:57:53 -04:00
|
|
|
_("Pairing request for %s").format(name),
|
|
|
|
{ customContent: true });
|
|
|
|
this.setResident(true);
|
|
|
|
|
|
|
|
this._applet = applet;
|
|
|
|
this._devicePath = device_path;
|
|
|
|
this._numeric = numeric;
|
|
|
|
this.addBody(_("Device %s wants to pair with this computer").format(long_name));
|
|
|
|
this.addBody(_("Please enter the PIN mentioned on the device."));
|
|
|
|
|
|
|
|
this._entry = new St.Entry();
|
|
|
|
this._entry.connect('key-release-event', Lang.bind(this, function(entry, event) {
|
|
|
|
let key = event.get_key_symbol();
|
|
|
|
if (key == Clutter.KEY_Return) {
|
|
|
|
this.emit('action-invoked', 'ok');
|
|
|
|
return true;
|
|
|
|
} else if (key == Clutter.KEY_Escape) {
|
|
|
|
this.emit('action-invoked', 'cancel');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
this.addActor(this._entry);
|
|
|
|
|
2010-12-20 16:07:28 -05:00
|
|
|
this.addButton('ok', _("OK"));
|
2010-07-24 07:57:53 -04:00
|
|
|
this.addButton('cancel', _("Cancel"));
|
|
|
|
|
|
|
|
this.connect('action-invoked', Lang.bind(this, function(self, action) {
|
|
|
|
if (action == 'ok') {
|
2011-03-02 11:27:24 -05:00
|
|
|
if (this._numeric) {
|
|
|
|
let num = parseInt(this._entry.text);
|
|
|
|
if (isNaN(num)) {
|
|
|
|
// user reply was empty, or was invalid
|
|
|
|
// cancel the operation
|
|
|
|
num = -1;
|
|
|
|
}
|
|
|
|
this._applet.agent_reply_passkey(this._devicePath, num);
|
|
|
|
} else
|
2010-07-24 07:57:53 -04:00
|
|
|
this._applet.agent_reply_pincode(this._devicePath, this._entry.text);
|
|
|
|
} else {
|
|
|
|
if (this._numeric)
|
|
|
|
this._applet.agent_reply_passkey(this._devicePath, -1);
|
|
|
|
else
|
|
|
|
this._applet.agent_reply_pincode(this._devicePath, null);
|
|
|
|
}
|
|
|
|
this.destroy();
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
grabFocus: function(lockTray) {
|
|
|
|
MessageTray.Notification.prototype.grabFocus.call(this, lockTray);
|
|
|
|
global.stage.set_key_focus(this._entry);
|
|
|
|
}
|
|
|
|
}
|