Add an autofill for /name in the roster when 'n' is pressed

This commit is contained in:
mathieui 2012-04-19 17:37:53 +02:00
parent 5a1a7a567d
commit 2f78a5f2dd

View file

@ -1712,6 +1712,7 @@ class RosterInfoTab(Tab):
self.key_func["o"] = self.toggle_offline_show self.key_func["o"] = self.toggle_offline_show
self.key_func["v"] = self.get_contact_version self.key_func["v"] = self.get_contact_version
self.key_func["i"] = self.show_contact_info self.key_func["i"] = self.show_contact_info
self.key_func["n"] = self.change_contact_name
self.key_func["s"] = self.start_search self.key_func["s"] = self.start_search
self.key_func["S"] = self.start_search_slow self.key_func["S"] = self.start_search_slow
self.commands['deny'] = (self.command_deny, _("Usage: /deny [jid]\nDeny: Deny your presence to the provided JID (or the selected contact in your roster), who is asking you to be in his/here roster."), self.completion_deny) self.commands['deny'] = (self.command_deny, _("Usage: /deny [jid]\nDeny: Deny your presence to the provided JID (or the selected contact in your roster), who is asking you to be in his/here roster."), self.completion_deny)
@ -2250,6 +2251,9 @@ class RosterInfoTab(Tab):
return True return True
def get_contact_version(self): def get_contact_version(self):
"""
Show the versions of the resource(s) currently selected
"""
selected_row = self.roster_win.get_selected_row() selected_row = self.roster_win.get_selected_row()
if isinstance(selected_row, Contact): if isinstance(selected_row, Contact):
for resource in selected_row.resources: for resource in selected_row.resources:
@ -2260,6 +2264,10 @@ class RosterInfoTab(Tab):
self.core.information('Nothing to get versions from', 'Info') self.core.information('Nothing to get versions from', 'Info')
def show_contact_info(self): def show_contact_info(self):
"""
Show the contact info (resource number, status, presence, etc)
when 'i' is pressed.
"""
selected_row = self.roster_win.get_selected_row() selected_row = self.roster_win.get_selected_row()
if isinstance(selected_row, Contact): if isinstance(selected_row, Contact):
cont = selected_row cont = selected_row
@ -2287,6 +2295,22 @@ class RosterInfoTab(Tab):
if msg: if msg:
self.core.information(msg, 'Info') self.core.information(msg, 'Info')
def change_contact_name(self):
"""
Auto-fill a /name command when 'n' is pressed
"""
selected_row = self.roster_win.get_selected_row()
if isinstance(selected_row, Contact):
jid = selected_row.bare_jid
elif isinstance(selected_row, Resource):
jid = JID(selected_row.jid).bare
else:
return
self.on_slash()
self.input.text = '/name "%s" ' % jid
self.input.key_end()
self.input.refresh()
def start_search(self): def start_search(self):
""" """
Start the search. The input should appear with a short instruction Start the search. The input should appear with a short instruction