import subprocess from time import sleep import prof last_window_jid = None unfocused_jid = {} def led_notify(state_on=True): if state_on: command = prof.settings_string_get("lednotification", "command_on", "xset led 3") else: command = prof.settings_string_get("lednotification", "command_off", "xset -led 3") subprocess.call(command, shell=True) def prof_on_chat_win_focus(barejid): on_focus(barejid) return None def prof_on_room_win_focus(barejid): rooms = prof.settings_string_get("lednotification", "rooms", "off") if rooms == "on": on_focus(barejid) return None def on_focus(jid): global last_window_jid global unfocused_jid last_window_jid = jid unfocused_jid.pop(jid, None) if not unfocused_jid: led_notify(False) def prof_post_chat_message_display(barejid, resource, message): if check_chat_notify(barejid): led_notify() return message def prof_post_room_message_display(barejid, nick, message): if check_chat_notify(barejid) and check_room_notify(barejid, nick): led_notify() return message def prof_post_priv_message_display(barejid, nick, message): if check_chat_notify(barejid): led_notify() return message def check_chat_notify(barejid): global unfocused_jid is_console = prof.current_win_is_console() if last_window_jid != barejid or is_console: unfocused_jid[barejid] = True enabled = prof.settings_string_get("lednotification", "enabled", "on") return enabled == "on" and is_console def check_room_notify(barejid, nick): rooms = prof.settings_string_get("lednotification", "rooms", "off") user = prof.get_room_nick(barejid) return rooms == "on" and user != nick def _cmd_say(arg1=None, arg2=None): if arg1 == "on": prof.settings_string_set("lednotification", "enabled", "on") prof.cons_show("LED notifications enabled") elif arg1 == "off": prof.settings_string_set("lednotification", "enabled", "off") prof.cons_show("LED notifications disabled") elif arg1 == "command": split = arg2.split() mode = split[0] arg3 = arg2.replace(mode, '', 1)[1:] arg2 = mode if arg2 == None or arg3 == None: prof.cons_bad_cmd_usage("/lednotification") elif arg2 == "on": prof.settings_string_set("lednotification", "command_on", arg3) prof.cons_show("LED notification enable command set to: " + arg3) elif arg2 == "off": prof.settings_string_set("lednotification", "command_off", arg3) prof.cons_show("LED notification disable command set to: " + arg3) elif arg1 == "rooms": if arg2 == None: prof.cons_bad_cmd_usage("/lednotification") else: prof.settings_string_set("lednotification", "rooms", arg2) prof.cons_show("LED notifications notifications for rooms set to: " + arg2) elif arg1 == "test": barejid = "TestJidUser" test_message_on = "Testing Receiving (LED should be on)" test_message_off = "Testing Focus (LED should be off)" test_message_fin = "Done testing LED notifications" prof.cons_show(test_message_on) prof_post_chat_message_display(barejid, barejid, test_message_on) sleep(0.5) prof.cons_show(test_message_off) prof_on_chat_win_focus(barejid) prof.cons_show(test_message_fin) else: print_settings() def print_settings(): enabled = prof.settings_string_get("lednotification", "enabled", "on") command_on = prof.settings_string_get("lednotification", "command_on", "xset led 3") command_off = prof.settings_string_get("lednotification", "command_off", "xset -led 3") rooms = prof.settings_string_get("lednotification", "rooms", "off") prof.cons_show("") prof.cons_show("LED notification plugin settings:") prof.cons_show("enabled: " + enabled) prof.cons_show("command on: " + command_on) prof.cons_show("command off: " + command_off) prof.cons_show("rooms: " + rooms) def prof_init(version, status, account_name, fulljid): synopsis = [ "/lednotification on|off", "/lednotification command on command", "/lednotification command off command", "/lednotification rooms on|off", "/lednotification test"] description = "Show new notifications with LEDs" args = [ ["on|off", "Enable/disable lednotification for all windows"], ["command on ", "Command for turning the LED on"], ["command off ", "Command for turning the LED off"], ["rooms ", "Turn notifications for rooms on or off"], ["test", "Tests LED notification calls"]] examples = [ "/lednotification on", "/lednotification command on xset led 3", "/lednotification rooms off"] prof.register_command("/lednotification", 0, 2, synopsis, description, args, examples, _cmd_say) prof.completer_add("/lednotification", ["on", "off", "rooms", "test"]) prof.completer_add("/lednotification rooms", ["on", "off"])