#! /usr/bin/python3 from __future__ import print_function from __future__ import division from __future__ import absolute_import from __future__ import unicode_literals import os, sys #support running uninstalled _dirname = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) if os.path.exists(os.path.join(_dirname, "CHANGELOG.md")): sys.path.insert(0, _dirname) from optparse import OptionParser import gettext import time from blueman.Constants import * import gi gi.require_version("Gtk", "3.0") from blueman.bluez.Manager import Manager from blueman.gui.DeviceSelectorDialog import DeviceSelectorDialog from blueman.Functions import * from blueman.main.Config import Config from gi.repository import Gtk, Gdk class Browse: def __init__(self): setup_icon_path() usage = "Usage: %prog [options]" parser = OptionParser(usage) parser.add_option("-d", "--device", dest="device", action="store", help=_("Browse this device"), metavar="ADDRESS") (options, args) = parser.parse_args() self.options = options self.args = args if options.device == None: dev = self.select_device() if not dev: exit() addr = dev.Address else: addr = options.device addr = addr.strip(" ") conf = Config("org.blueman.transfer") try: if conf["browse-command"]: launch(conf["browse-command"].replace("%d", addr), system=True, name="blueman") else: Gtk.show_uri(None, ('obex://[%s]' % addr), Gdk.CURRENT_TIME) except Exception as e: dprint(e) d = Gtk.MessageDialog(None, buttons=Gtk.ButtonsType.OK, type=Gtk.MessageType.ERROR) if conf["browse-command"]: d.props.text = _("Failed to launch \"%s\"") % conf["browse-command"].split(' ')[0] else: d.props.text = _("Failed to launch default file browser") d.props.secondary_text = "%s\n\n" % e.message + \ _("You can enter an alternate browser in service settings") d.run() d.destroy() def select_device(self): d = DeviceSelectorDialog() resp = d.run() d.destroy() if resp == Gtk.ResponseType.ACCEPT: sel = d.GetSelection() if sel: return sel[1] else: return None else: return None set_proc_title() Browse()