diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core.py | 22 | ||||
-rw-r--r-- | src/pubsub.py | 52 |
2 files changed, 57 insertions, 17 deletions
diff --git a/src/core.py b/src/core.py index df7f3cad..0d6bf6ea 100644 --- a/src/core.py +++ b/src/core.py @@ -40,6 +40,7 @@ import multiuserchat as muc import tabs import xhtml +import pubsub import windows import connection import timed_events @@ -130,6 +131,7 @@ class Core(object): 'connect': (self.command_reconnect, _('Usage: /connect\nConnect: disconnect from the remote server if you are currently connected and then connect to it again'), None), 'server_cycle': (self.command_server_cycle, _('Usage: /server_cycle [domain] [message]\nServer Cycle: disconnect and reconnects in all the rooms in domain.'), None), 'bind': (self.command_bind, _('Usage: /bind <key> <equ>\nBind: bind a key to an other key or to a “command”. For example "/bind ^H KEY_UP" makes Control + h do the same same than the Up key.')), + 'pubsub': (self.command_pubsub, _('Usage: /pubsub <domain>\nPubsub: Open a pubsub browser on the given domain'), None), } self.key_func = { @@ -149,6 +151,7 @@ class Core(object): 'M-z': self.go_to_previous_tab, '^L': self.full_screen_redraw, 'M-j': self.go_to_room_number, + 'M-c': self.coucou, } # Add handlers @@ -174,6 +177,9 @@ class Core(object): self.timed_events = set() + def coucou(self): + self.command_pubsub('psgxs.linkmauve.fr') + def start(self): """ Init curses, create the first tab, etc @@ -1388,6 +1394,22 @@ class Core(object): config.set_and_save(args[0], args[1], section='bindings') self.information('%s is now bound to %s' % (args[0], args[1]), 'Info') + def command_pubsub(self, args): + """ + Opens a pubsub browser on the given domain + """ + args = common.shell_split(args) + if len(args) != 1: + return self.command_help('pubsub') + domain = args[0] + tab = self.get_tab_by_name('%s@@pubsubbrowser' % (domain,), pubsub.PubsubBrowserTab) + if tab: + self.command_win('%s' % tab.nb) + else: + new_tab = pubsub.PubsubBrowserTab(domain) + self.add_tab(new_tab, True) + self.refresh_window() + def go_to_room_number(self): """ Read 2 more chars and go to the tab diff --git a/src/pubsub.py b/src/pubsub.py index af9ca001..3e463a3e 100644 --- a/src/pubsub.py +++ b/src/pubsub.py @@ -77,7 +77,7 @@ class PubsubBrowserTab(tabs.Tab): self.tab_win = windows.GlobalInfoBar() self.upper_message = windows.Topic() - self.upper_message.set_message('Pubsub server: %s/%s' % (self.server,self.current_node or '')) + self.set_info_message('Loading') # Node List View node_columns = ('node', 'name',) @@ -104,6 +104,12 @@ class PubsubBrowserTab(tabs.Tab): self.get_nodes() + def set_info_message(self, message): + """ + Set an informative message in the upper line, near the server name + """ + self.upper_message.set_message('Pubsub server: %s/%s [%s]' % (self.server, self.current_node or '', message)) + def resize(self): self.upper_message.resize(1, self.width, 0, 0) self.tab_win.resize(1, self.width, self.height-2, 0) @@ -137,6 +143,10 @@ class PubsubBrowserTab(tabs.Tab): self.tab_win.refresh() self.input.refresh() + def force_refresh(self): + if self.core.current_tab() is self: + self.core.refresh_window() + def get_name(self): return '%s@@pubsubbrowser' % (self.server,) @@ -195,16 +205,20 @@ class PubsubBrowserTab(tabs.Tab): """ Get all items in the given node """ - items = self.core.xmpp.plugin['xep_0060'].get_items(self.server, node.name) - item_list = [] - if items: - for it in items: - item_list.append(PubsubItem(it.attrib['id'], it)) - node.items = item_list - log.debug('get_selected_node_name: %s' % self.get_selected_node_name()) - if self.get_selected_node_name() == node.name: - self.display_items_from_node(node) - log.debug('Item on node %s: %s' % (node.name, item_list)) + def callback(items): + item_list = [] + if items: + for it in items: + item_list.append(PubsubItem(it.attrib['id'], it)) + node.items = item_list + log.debug('get_selected_node_name: %s' % self.get_selected_node_name()) + if self.get_selected_node_name() == node.name: + self.display_items_from_node(node) + log.debug('Item on node %s: %s' % (node.name, item_list)) + self.set_info_message('Items received') + self.force_refresh() + + self.core.xmpp.plugin['xep_0060'].get_items(self.server, node.name, callback=callback) def display_items_from_node(self, node): """ @@ -240,17 +254,21 @@ class PubsubBrowserTab(tabs.Tab): Get all subnodes of the given node. If no node is given, get the root nodes """ - nodes = self.core.xmpp.plugin['xep_0060'].get_nodes(self.server) - lines = [{'name': nodes[node] or '', + def callback(nodes): + lines = [{'name': nodes[node] or '', 'node': node} for node in nodes.keys()] - self.add_nodes(lines) + self.add_nodes(lines) + self.set_info_message('Nodes received') + self.force_refresh() + self.core.xmpp.plugin['xep_0060'].get_nodes(self.server, callback=callback) def create_node(self, node_name): - if node_name: - res = self.core.xmpp.plugin['xep_0060'].create_node(self.server, node_name) + def callback(res): if res: self.node_listview.add_lines([{'name': '', 'node': node_name}]) - self.reset_help_message() + self.reset_help_message() + if node_name: + self.core.xmpp.plugin['xep_0060'].create_node(self.server, node_name) return True def reset_help_message(self, txt=None): |