Compare with Previous | Blame | Download | View Log
#!/usr/bin/pythonimport osimport sys#support running uninstalled_dirname = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))if os.path.exists(os.path.join(_dirname,"ChangeLog")):sys.path.insert(0, _dirname)import gtkfrom blueman.gui.GenericList import GenericListfrom blueman.Functions import *from blueman.Constants import *import blueman.plugins.servicesfrom blueman.plugins.ServicePlugin import ServicePluginfrom blueman.main.Config import Configenable_rgba_colormap()setup_icon_path()class BluemanServices:def __init__(self):self.Builder = gtk.Builder()self.Builder.set_translation_domain("blueman")self.Builder.add_from_file(UI_PATH +"/services.ui")self.Config = Config()self.Dialog = self.Builder.get_object("dialog")self.Dialog.resize(520, 420)check_single_instance("blueman-services", lambda time: self.Dialog.present_with_time(time))self.Dialog.connect("delete-event", lambda x, y: gtk.main_quit())data = [["picture", 'GdkPixbuf', gtk.CellRendererPixbuf(), {"pixbuf":0}, None],["caption", str, gtk.CellRendererText(), {"markup":1}, None, {"expand": True}],["id", str],]ls = GenericList(data)ls.props.headers_visible = Falsels.selection.connect("changed", self.on_selection_changed)self.List = lsself.Builder.get_object("viewport1").add(ls)ls.show()self.container = self.Builder.get_object("hbox1")self.load_plugins()try:ls.selection.select_path(self.Config.props.services_last_item)except:ls.selection.select_path(0)self.Builder.get_object("b_apply").connect("clicked", self.on_apply_clicked)self.Builder.get_object("b_close").connect("clicked", lambda x: gtk.main_quit())self.Dialog.show()gtk.main()def option_changed(self):rets = self.plugin_exec("on_query_apply_state")show_apply = Falsefor ret in rets:if ret == -1:show_apply = Falsebreakshow_apply = show_apply or retb_apply = self.Builder.get_object("b_apply")b_apply.props.sensitive = show_applydef load_plugins(self):path = os.path.dirname(blueman.plugins.services.__file__)plugins = []for root, dirs, files in os.walk(path):for f in files:if f.endswith(".py") and not (f.endswith(".pyc") or f.endswith("_.py")):plugins.append(f[0:-3])plugins.sort()dprint(plugins)for plugin in plugins:try:__import__("blueman.plugins.services.%s" % plugin, None, None, [])except ImportError, e:dprint("Unable to load %s plugin\n%s" % (plugin, e))for cls in ServicePlugin.__subclasses__():try:inst = cls(self)except:continueif not cls.__plugin_info__:dprint("Invalid plugin info in %s" % (plugin))else:(name, icon) = cls.__plugin_info__self.setup_list_item(inst, name, icon)def setup_list_item(self, inst, name, icon):self.List.append(picture=get_icon(icon, 32), caption=name, id=inst.__class__.__name__)#executes a function on all plugin instancesdef plugin_exec(self, function, *args, **kwargs):rets = []for inst in ServicePlugin.instances:ret = getattr(inst, function)(*args, **kwargs)rets.append(ret)return retsdef on_apply_clicked(self, button):self.plugin_exec("on_apply")self.option_changed()def set_page(self, pageid):dprint("Set page", pageid)if len(ServicePlugin.instances) == 0:return#set the first itemif pageid == None:pageid = ServicePlugin.instances[0].__class__.__name__for inst in ServicePlugin.instances:if inst.__class__.__name__ == pageid:if not inst._is_loaded:inst.on_load(self.container)inst._is_loaded = Trueinst._on_enter()else:inst._on_leave()def on_selection_changed(self, selection):iter = self.List.selected()if self.List.get_cursor()[0]:self.Config.props.services_last_item = self.List.get_cursor()[0][0]row = self.List.get(iter, "id")id = row["id"]self.set_page(id)BluemanServices()