Commit bbdc14aa authored by mathieui's avatar mathieui

Remove Tab.get_name() and use Tab.name instead

(keep a get_name() fallback just in case for now)
parent d859ec2e
......@@ -291,7 +291,7 @@ class Plugin(BasePlugin):
jid = JID(args[1])
else:
if isinstance(self.core.current_tab(), ConversationTab):
jid = JID(self.core.current_tab().get_name())
jid = JID(self.core.current_tab().name)
else:
return
command = args[0]
......
......@@ -73,14 +73,14 @@ class Plugin(BasePlugin):
def command_private_ping(self, arg):
if arg:
return self.command_ping(arg)
self.command_ping(self.api.current_tab().get_name())
self.command_ping(self.api.current_tab().name)
def command_muc_ping(self, arg):
if not arg.strip():
return
user = self.api.current_tab().get_user_by_name(arg)
if user:
jid = safeJID(self.api.current_tab().get_name())
jid = safeJID(self.api.current_tab().name)
jid.resource = user.nick
else:
jid = safeJID(arg)
......
......@@ -65,8 +65,8 @@ class Plugin(BasePlugin):
res += "%s seconds, " % seconds
return res[:-2]
last_message_date = self.last_messages.get(tab.get_name())
self.last_messages[tab.get_name()] = datetime.now()
last_message_date = self.last_messages.get(tab.name)
self.last_messages[tab.name] = datetime.now()
if last_message_date:
delta = datetime.now() - last_message_date
if delta >= timedelta(0, self.config.get('delay', 900)):
......
......@@ -147,7 +147,7 @@ def command_presence(self, arg):
else:
return
if jid == '.' and isinstance(self.current_tab(), tabs.ChatTab):
jid = self.current_tab().get_name()
jid = self.current_tab().name
if type == 'available':
type = None
try:
......@@ -238,7 +238,7 @@ def command_move_tab(self, arg):
except ValueError:
old_tab = None
for tab in self.tabs:
if not old_tab and value == tab.get_name():
if not old_tab and value == tab.name:
old_tab = tab
if not old_tab:
self.information("Tab %s does not exist" % args[0], "Error")
......@@ -269,7 +269,7 @@ def command_list(self, arg):
else:
if not isinstance(self.current_tab(), tabs.MucTab):
return self.information('Please provide a server', 'Error')
server = safeJID(self.current_tab().get_name()).server
server = safeJID(self.current_tab().name).server
list_tab = tabs.MucListTab(server)
self.add_tab(list_tab, True)
cb = list_tab.on_muc_list_item_received
......@@ -316,7 +316,7 @@ def command_join(self, arg, histo_length=None):
tab = self.current_tab()
if not isinstance(tab, (tabs.MucTab, tabs.PrivateTab)):
return
room = safeJID(tab.get_name()).bare
room = safeJID(tab.name).bare
nick = tab.own_nick
else:
if args[0].startswith('@'): # we try to join a server directly
......@@ -335,7 +335,7 @@ def command_join(self, arg, histo_length=None):
tab = self.current_tab()
if not isinstance(tab, tabs.MucTab):
return
room = tab.get_name()
room = tab.name
if nick == '':
nick = tab.own_nick
else:
......@@ -345,8 +345,8 @@ def command_join(self, arg, histo_length=None):
# check if the current room's name has a server
if room.find('@') == -1 and not server_root:
if isinstance(self.current_tab(), tabs.MucTab) and\
self.current_tab().get_name().find('@') != -1:
domain = safeJID(self.current_tab().get_name()).domain
self.current_tab().name.find('@') != -1:
domain = safeJID(self.current_tab().name).domain
room += '@%s' % domain
else:
room = args[0]
......@@ -421,15 +421,15 @@ def command_bookmark_local(self, arg=''):
return
if not args:
tab = self.current_tab()
roomname = tab.get_name()
roomname = tab.name
if tab.joined and tab.own_nick != self.own_nick:
nick = tab.own_nick
elif args[0] == '*':
new_bookmarks = []
for tab in self.get_tabs(tabs.MucTab):
b = bookmark.get_by_jid(tab.get_name())
b = bookmark.get_by_jid(tab.name)
if not b:
b = bookmark.Bookmark(tab.get_name(),
b = bookmark.Bookmark(tab.name,
autojoin=True,
method="local")
new_bookmarks.append(b)
......@@ -451,7 +451,7 @@ def command_bookmark_local(self, arg=''):
if not roomname:
if not isinstance(self.current_tab(), tabs.MucTab):
return
roomname = self.current_tab().get_name()
roomname = self.current_tab().name
if len(args) > 1:
password = args[1]
......@@ -485,7 +485,7 @@ def command_bookmark(self, arg=''):
return
if not args:
tab = self.current_tab()
roomname = tab.get_name()
roomname = tab.name
if tab.joined:
nick = tab.own_nick
autojoin = True
......@@ -497,9 +497,9 @@ def command_bookmark(self, arg=''):
autojoin = True
new_bookmarks = []
for tab in self.get_tabs(tabs.MucTab):
b = bookmark.get_by_jid(tab.get_name())
b = bookmark.get_by_jid(tab.name)
if not b:
b = bookmark.Bookmark(tab.get_name(), autojoin=autojoin,
b = bookmark.Bookmark(tab.name, autojoin=autojoin,
method=bookmark.preferred)
new_bookmarks.append(b)
else:
......@@ -523,7 +523,7 @@ def command_bookmark(self, arg=''):
if roomname == '':
if not isinstance(self.current_tab(), tabs.MucTab):
return
roomname = self.current_tab().get_name()
roomname = self.current_tab().name
if len(args) > 1:
autojoin = False if args[1].lower() != 'true' else True
else:
......@@ -571,8 +571,8 @@ def command_remove_bookmark(self, arg=''):
args = common.shell_split(arg)
if not args:
tab = self.current_tab()
if isinstance(tab, tabs.MucTab) and bookmark.get_by_jid(tab.get_name()):
bookmark.remove(tab.get_name())
if isinstance(tab, tabs.MucTab) and bookmark.get_by_jid(tab.name):
bookmark.remove(tab.name)
bookmark.save(self.xmpp)
if bookmark.save(self.xmpp):
self.information('Bookmark deleted', 'Info')
......@@ -643,22 +643,22 @@ def command_server_cycle(self, arg=''):
message = args[1]
else:
if isinstance(tab, tabs.MucTab):
domain = safeJID(tab.get_name()).domain
domain = safeJID(tab.name).domain
else:
self.information(_("No server specified"), "Error")
return
for tab in self.get_tabs(tabs.MucTab):
if tab.get_name().endswith(domain):
if tab.name.endswith(domain):
if tab.joined:
muc.leave_groupchat(tab.core.xmpp,
tab.get_name(),
tab.name,
tab.own_nick,
message)
tab.joined = False
if tab.get_name() == domain:
self.command_join('"@%s/%s"' %(tab.get_name(), tab.own_nick))
if tab.name == domain:
self.command_join('"@%s/%s"' %(tab.name, tab.own_nick))
else:
self.command_join('"%s/%s"' %(tab.get_name(), tab.own_nick))
self.command_join('"%s/%s"' %(tab.name, tab.own_nick))
def command_last_activity(self, arg):
"""
......@@ -928,7 +928,7 @@ def command_message(self, arg):
if not tab:
tab = self.open_conversation_window(jid.full, focus=True)
else:
self.focus_tab_named(tab.get_name())
self.focus_tab_named(tab.name)
if len(args) > 1:
tab.command_say(args[1])
......
......@@ -98,7 +98,7 @@ def completion_join(self, the_input):
relevant_rooms.extend(sorted(self.pending_invites.keys()))
bookmarks = {str(elem.jid): False for elem in bookmark.bookmarks}
for tab in self.get_tabs(tabs.MucTab):
name = tab.get_name()
name = tab.name
if name in bookmarks and not tab.joined:
bookmarks[name] = True
relevant_rooms.extend(sorted(room[0] for room in bookmarks.items() if room[1]))
......@@ -126,7 +126,7 @@ def completion_join(self, the_input):
serv_list = []
for tab in self.get_tabs(tabs.MucTab):
if tab.joined:
serv_list.append('%s@%s'% (jid.user, safeJID(tab.get_name()).host))
serv_list.append('%s@%s'% (jid.user, safeJID(tab.name).host))
serv_list.extend(relevant_rooms)
return the_input.new_completion(serv_list, 1, quotify=True)
elif args[1].startswith('/'):
......@@ -147,8 +147,8 @@ def completion_list(self, the_input):
"""Completion for /list"""
muc_serv_list = []
for tab in self.get_tabs(tabs.MucTab): # TODO, also from an history
if tab.get_name() not in muc_serv_list:
muc_serv_list.append(safeJID(tab.get_name()).server)
if tab.name not in muc_serv_list:
muc_serv_list.append(safeJID(tab.name).server)
if muc_serv_list:
return the_input.new_completion(muc_serv_list, 1, quotify=False)
......@@ -157,7 +157,7 @@ def completion_move_tab(self, the_input):
"""Completion for /move_tab"""
n = the_input.get_argument_position(quoted=True)
if n == 1:
nodes = [tab.get_name() for tab in self.tabs if tab]
nodes = [tab.name for tab in self.tabs if tab]
nodes.remove('Roster')
return the_input.new_completion(nodes, 1, ' ', quotify=True)
......@@ -199,7 +199,7 @@ def completion_bookmark(self, the_input):
nicks.append(nick)
jids_list = ['%s/%s' % (jid.bare, nick) for nick in nicks]
return the_input.new_completion(jids_list, 1, quotify=True)
muc_list = [tab.get_name() for tab in self.get_tabs(tabs.MucTab)]
muc_list = [tab.name for tab in self.get_tabs(tabs.MucTab)]
muc_list.sort()
muc_list.append('*')
return the_input.new_completion(muc_list, 1, quotify=True)
......@@ -259,7 +259,7 @@ def completion_invite(self, the_input):
rooms = []
for tab in self.get_tabs(tabs.MucTab):
if tab.joined:
rooms.append(tab.get_name())
rooms.append(tab.name)
rooms.sort()
return the_input.new_completion(rooms, n, '', quotify=True)
......@@ -300,7 +300,7 @@ def completion_server_cycle(self, the_input):
"""Completion for /server_cycle"""
serv_list = set()
for tab in self.get_tabs(tabs.MucTab):
serv = safeJID(tab.get_name()).server
serv = safeJID(tab.name).server
serv_list.add(serv)
return the_input.new_completion(sorted(serv_list), 1, ' ')
......@@ -380,7 +380,7 @@ def completion_bookmark_local(self, the_input):
nicks.append(nick)
jids_list = ['%s/%s' % (jid.bare, nick) for nick in nicks]
return the_input.new_completion(jids_list, 1, quotify=True)
muc_list = [tab.get_name() for tab in self.get_tabs(tabs.MucTab)]
muc_list = [tab.name for tab in self.get_tabs(tabs.MucTab)]
muc_list.append('*')
return the_input.new_completion(muc_list, 1, quotify=True)
......@@ -902,7 +902,7 @@ class Core(object):
If typ is provided, return a tab of this type only
"""
for tab in self.tabs:
if tab.get_name() == name:
if tab.name == name:
if (typ and isinstance(tab, typ)) or\
not typ:
return tab
......@@ -1081,7 +1081,7 @@ class Core(object):
def focus_tab_named(self, tab_name, type_=None):
"""Returns True if it found a tab to focus on"""
for tab in self.tabs:
if tab.get_name() == tab_name:
if tab.name == tab_name:
if (type_ and (isinstance(tab, type_))) or not type_:
self.command_win('%s' % (tab.nb,))
return True
......@@ -1133,7 +1133,7 @@ class Core(object):
complete_jid = room_name+'/'+user_nick
# if the room exists, focus it and return
for tab in self.get_tabs(tabs.PrivateTab):
if tab.get_name() == complete_jid:
if tab.name == complete_jid:
self.command_win('%s' % tab.nb)
return tab
# create the new tab
......@@ -1206,7 +1206,7 @@ class Core(object):
if reason is None:
reason = _('\x195}You left the chatroom\x193}')
for tab in self.get_tabs(tabs.PrivateTab):
if tab.get_name().startswith(room_name):
if tab.name.startswith(room_name):
tab.deactivate(reason=reason)
def enable_private_tabs(self, room_name, reason=None):
......@@ -1216,7 +1216,7 @@ class Core(object):
if reason is None:
reason = _('\x195}You joined the chatroom\x193}')
for tab in self.get_tabs(tabs.PrivateTab):
if tab.get_name().startswith(room_name):
if tab.name.startswith(room_name):
tab.activate(reason=reason)
def on_user_changed_status_in_private(self, jid, msg):
......@@ -1246,10 +1246,10 @@ class Core(object):
self.tabs[nb] = tabs.GapTab()
else:
self.tabs.remove(tab)
if tab and tab.get_name() in logger.fds:
logger.fds[tab.get_name()].close()
log.debug("Log file for %s closed.", tab.get_name())
del logger.fds[tab.get_name()]
if tab and tab.name in logger.fds:
logger.fds[tab.name].close()
log.debug("Log file for %s closed.", tab.name)
del logger.fds[tab.name]
if self.current_tab_nb >= len(self.tabs):
self.current_tab_nb = len(self.tabs) - 1
while not self.tabs[self.current_tab_nb]:
......
......@@ -161,7 +161,7 @@ def on_message(self, message):
# Differentiate both type of messages, and call the appropriate handler.
jid_from = message['from']
for tab in self.get_tabs(tabs.MucTab):
if tab.get_name() == jid_from.bare:
if tab.name == jid_from.bare:
if message['type'] == 'error':
return self.room_error(message, jid_from)
else:
......@@ -1003,12 +1003,12 @@ def on_attention(self, message):
jid_from = message['from']
self.information('%s requests your attention!' % jid_from, 'Info')
for tab in self.tabs:
if tab.get_name() == jid_from:
if tab.name == jid_from:
tab.state = 'attention'
self.refresh_tab_win()
return
for tab in self.tabs:
if tab.get_name() == jid_from.bare:
if tab.name == jid_from.bare:
tab.state = 'attention'
self.refresh_tab_win()
return
......
......@@ -90,6 +90,7 @@ class Tab(object):
plugin_commands = {}
plugin_keys = {}
def __init__(self):
self.name = self.__class__.__name__
self.input = None
self._state = 'normal'
self._prev_state = None
......@@ -299,13 +300,13 @@ class Tab(object):
"""
get the name of the tab
"""
return self.__class__.__name__
return self.name
def get_nick(self):
"""
Get the nick of the tab (defaults to its name)
"""
return self.get_name()
return self.name
def get_text_window(self):
"""
......@@ -410,7 +411,8 @@ class GapTab(Tab):
def __len__(self):
return 0
def get_name(self):
@property
def name(self):
return ''
def refresh(self):
......@@ -476,7 +478,7 @@ class ChatTab(Tab):
return False
def load_logs(self, log_nb):
logs = logger.get_logs(safeJID(self.get_name()).bare, log_nb)
logs = logger.get_logs(safeJID(self.name).bare, log_nb)
return logs
def log_message(self, txt, nickname, time=None, typ=1):
......@@ -569,7 +571,7 @@ class ChatTab(Tab):
return msg
def get_dest_jid(self):
return self.get_name()
return self.name
@refresh_wrapper.always
def command_clear(self, args):
......
......@@ -73,7 +73,7 @@ class ConversationTab(ChatTab):
@property
def general_jid(self):
return safeJID(self.get_name()).bare
return safeJID(self.name).bare
@staticmethod
def add_information_element(plugin_name, callback):
......@@ -109,7 +109,7 @@ class ConversationTab(ChatTab):
replaced = False
if correct or msg['replace']['id']:
msg['replace']['id'] = self.last_sent_message['id']
if config.get_by_tabname('group_corrections', True, self.get_name()):
if config.get_by_tabname('group_corrections', True, self.name):
try:
self.modify_message(msg['body'], self.last_sent_message['id'], msg['id'], jid=self.core.xmpp.boundjid,
nickname=self.core.own_nick)
......@@ -306,9 +306,6 @@ class ConversationTab(ChatTab):
self.text_win, self.chatstate, ConversationTab.additional_informations)
self.input.refresh()
def get_name(self):
return self.name
def get_nick(self):
jid = safeJID(self.name)
contact = roster[jid.bare]
......@@ -382,10 +379,10 @@ class ConversationTab(ChatTab):
def matching_names(self):
res = []
jid = safeJID(self.get_name())
jid = safeJID(self.name)
res.append((2, jid.bare))
res.append((1, jid.user))
contact = roster[self.get_name()]
contact = roster[self.name]
if contact and contact.name:
res.append((0, contact.name))
return res
......@@ -450,8 +447,8 @@ class DynamicConversationTab(ConversationTab):
the conversation is not locked.
"""
if self.locked_resource:
return "%s/%s" % (self.get_name(), self.locked_resource)
return self.get_name()
return "%s/%s" % (self.name, self.locked_resource)
return self.name
def refresh(self):
"""
......@@ -464,12 +461,12 @@ class DynamicConversationTab(ConversationTab):
self.text_win.refresh()
if display_bar:
self.upper_bar.refresh(self.get_name(), roster[self.get_name()])
self.upper_bar.refresh(self.name, roster[self.name])
if self.locked_resource:
displayed_jid = "%s/%s" % (self.get_name(), self.locked_resource)
displayed_jid = "%s/%s" % (self.name, self.locked_resource)
else:
displayed_jid = self.get_name()
self.info_header.refresh(displayed_jid, roster[self.get_name()],
displayed_jid = self.name
self.info_header.refresh(displayed_jid, roster[self.name],
self.text_win, self.chatstate,
ConversationTab.additional_informations)
if display_info_win:
......@@ -483,10 +480,10 @@ class DynamicConversationTab(ConversationTab):
Different from the parent class only for the info_header object.
"""
if self.locked_resource:
displayed_jid = "%s/%s" % (self.get_name(), self.locked_resource)
displayed_jid = "%s/%s" % (self.name, self.locked_resource)
else:
displayed_jid = self.get_name()
self.info_header.refresh(displayed_jid, roster[self.get_name()],
displayed_jid = self.name
self.info_header.refresh(displayed_jid, roster[self.name],
self.text_win, self.chatstate, ConversationTab.additional_informations)
self.input.refresh()
......
......@@ -184,9 +184,6 @@ class MucListTab(Tab):
self.execute_command(txt)
return self.reset_help_message()
def get_name(self):
return self.name
def completion(self):
if isinstance(self.input, windows.Input):
self.complete_commands(self.input)
......
......@@ -196,7 +196,7 @@ class MucTab(ChatTab):
@property
def general_jid(self):
return self.get_name()
return self.name
@property
def is_muc(self):
......@@ -251,7 +251,7 @@ class MucTab(ChatTab):
"""Completion for /nick"""
nicks = [os.environ.get('USER'),
config.get('default_nick', ''),
self.core.get_bookmark_nickname(self.get_name())]
self.core.get_bookmark_nickname(self.name)]
nicks = [i for i in nicks if i]
return the_input.auto_completion(nicks, '', quotify=False)
......@@ -360,7 +360,7 @@ class MucTab(ChatTab):
"""
/configure
"""
form = fixes.get_room_form(self.core.xmpp, self.get_name())
form = fixes.get_room_form(self.core.xmpp, self.name)
if not form:
self.core.information(
_('Could not retrieve the configuration form'),
......@@ -372,14 +372,14 @@ class MucTab(ChatTab):
"""
The user do not want to send his/her config, send an iq cancel
"""
self.core.xmpp.plugin['xep_0045'].cancelConfig(self.get_name())
self.core.xmpp.plugin['xep_0045'].cancelConfig(self.name)
self.core.close_tab()
def send_config(self, form):
"""
The user sends his/her config to the server
"""
self.core.xmpp.plugin['xep_0045'].configureRoom(self.get_name(), form)
self.core.xmpp.plugin['xep_0045'].configureRoom(self.name, form)
self.core.close_tab()
def command_cycle(self, arg):
......@@ -450,7 +450,7 @@ class MucTab(ChatTab):
return self.core.information(_('/nick only works in joined rooms'),
_('Info'))
current_status = self.core.get_status()
if not safeJID(self.get_name() + '/' + nick):
if not safeJID(self.name + '/' + nick):
return self.core.information('Invalid nick', 'Info')
muc.change_nick(self.core, self.name, nick,
current_status.message,
......@@ -632,7 +632,7 @@ class MucTab(ChatTab):
"""
def callback(iq):
if iq['type'] == 'error':
self.core.room_error(iq, self.get_name())
self.core.room_error(iq, self.name)
args = common.shell_split(arg)
if not args:
return self.core.command_help('ban')
......@@ -643,11 +643,11 @@ class MucTab(ChatTab):
nick = args[0]
if nick in [user.nick for user in self.users]:
res = muc.set_user_affiliation(self.core.xmpp, self.get_name(),
res = muc.set_user_affiliation(self.core.xmpp, self.name,
'outcast', nick=nick,
callback=callback, reason=msg)
else:
res = muc.set_user_affiliation(self.core.xmpp, self.get_name(),
res = muc.set_user_affiliation(self.core.xmpp, self.name,
'outcast', jid=safeJID(nick),
callback=callback, reason=msg)
if not res:
......@@ -661,7 +661,7 @@ class MucTab(ChatTab):
"""
def callback(iq):
if iq['type'] == 'error':
self.core.room_error(iq, self.get_name())
self.core.room_error(iq, self.name)
args = common.shell_split(arg)
if len(args) < 2:
self.core.command_help('role')
......@@ -674,9 +674,9 @@ class MucTab(ChatTab):
if not self.joined or \
not role in ('none', 'visitor', 'participant', 'moderator'):
return
if not safeJID(self.get_name() + '/' + nick):
if not safeJID(self.name + '/' + nick):
return self.core('Invalid nick', 'Info')
muc.set_user_role(self.core.xmpp, self.get_name(), nick, reason, role,
muc.set_user_role(self.core.xmpp, self.name, nick, reason, role,
callback=callback)
def command_affiliation(self, arg):
......@@ -687,7 +687,7 @@ class MucTab(ChatTab):
"""
def callback(iq):
if iq['type'] == 'error':
self.core.room_error(iq, self.get_name())
self.core.room_error(iq, self.name)
args = common.shell_split(arg)
if len(args) < 2:
self.core.command_help('affiliation')
......@@ -699,11 +699,11 @@ class MucTab(ChatTab):
self.core.command_help('affiliation')
return
if nick in [user.nick for user in self.users]:
res = muc.set_user_affiliation(self.core.xmpp, self.get_name(),
res = muc.set_user_affiliation(self.core.xmpp, self.name,
affiliation, nick=nick,
callback=callback)
else:
res = muc.set_user_affiliation(self.core.xmpp, self.get_name(),
res = muc.set_user_affiliation(self.core.xmpp, self.name,
affiliation, jid=safeJID(nick),
callback=callback)
if not res:
......@@ -715,7 +715,7 @@ class MucTab(ChatTab):
Or normal input + enter
"""
needed = 'inactive' if self.inactive else 'active'
msg = self.core.xmpp.make_message(self.get_name())
msg = self.core.xmpp.make_message(self.name)
msg['type'] = 'groupchat'
msg['body'] = line
# trigger the event BEFORE looking for colors.
......@@ -900,9 +900,6 @@ class MucTab(ChatTab):
self.input.get_text().startswith('//'))
self.send_composing_chat_state(empty_after)
def get_name(self):
return self.name
def get_nick(self):
if not config.get('show_muc_jid', True):