gtkgui don't send messages to the connection but call the correct functions

This commit is contained in:
Yann Leboulanger 2005-04-14 09:38:08 +00:00
parent d6a76e58c4
commit eb7cf5ba4d
9 changed files with 89 additions and 92 deletions

View File

@ -33,7 +33,7 @@ class Config:
__options = {
# name: [ type, value ]
'log': [ opt_bool, 'False' ],
'log': [ opt_bool, 'True' ],
'delauth': [ opt_bool, 'True' ],
'delroster': [ opt_bool, 'True' ],
'alwaysauth': [ opt_bool, 'False' ],

View File

@ -85,7 +85,7 @@ def get_os_info():
class connection:
"""connection"""
def __init__(self, name = None):
def __init__(self, name):
# dict of function to be calledfor each event
self.handlers = {'ROSTER': [], 'WARNING': [], 'ERROR': [], 'STATUS': [], \
'NOTIFY': [], 'MSG': [], 'MSGERROR': [], 'MSGSENT': [] , \
@ -99,13 +99,12 @@ class connection:
self.connection = None # Jabber.py instance
self.gpg = None
self.myVCardID = []
if name:
self.password = gajim.config.get_per('accounts', name, 'hostname')
if USE_GPG:
self.gpg = GnuPG.GnuPG()
gajim.config.set('usegpg', True)
else:
gajim.config.set('usegpg', False)
self.password = gajim.config.get_per('accounts', name, 'hostname')
if USE_GPG:
self.gpg = GnuPG.GnuPG()
gajim.config.set('usegpg', True)
else:
gajim.config.set('usegpg', False)
# END __init__
def dispatch(self, event, data):

View File

@ -1110,7 +1110,7 @@ class Account_modification_window:
gajim.config.set_per('accounts', name, 'no_log_for', \
self.infos['no_log_for'])
if save_password:
self.plugin.send('PASSPHRASE', name, password)
gajim.connections[name].password = password
#refresh accounts window
if self.plugin.windows.has_key('accounts'):
self.plugin.windows['accounts'].init_accounts()
@ -1126,8 +1126,8 @@ class Account_modification_window:
self.plugin.register_handlers(gajim.connections[name])
#if we neeed to register a new account
if new_account_checkbutton.get_active():
self.plugin.send('NEW_ACC', None, (hostname, login, password, name, \
resource, priority, use_proxy, proxyhost, proxyport))
gajim.connections[name].new_account(hostname, login, password, name, \
resource, priority, use_proxy, proxyhost, proxyport)
return
gajim.config.set_per('accounts', name, 'name', login)
gajim.config.set_per('accounts', name, 'hostname', hostname)
@ -1148,7 +1148,7 @@ class Account_modification_window:
gajim.config.set_per('accounts', name, 'no_log_for', \
self.infos['no_log_for'])
if save_password:
self.plugin.send('PASSPHRASE', name, password)
gajim.connections[name].password = password
#update variables
self.plugin.windows[name] = {'infos': {}, 'chats': {}, 'gc': {}}
self.plugin.queues[name] = {}
@ -1170,8 +1170,8 @@ class Account_modification_window:
dialog = Change_password_dialog(self.plugin, self.account)
new_password = dialog.run()
if new_password != -1:
self.plugin.send('CHANGE_PASSWORD', self.account,\
(new_password, self.plugin.nicks[self.account]))
gajim.connections[self.account].change_password(new_password, \
self.plugin.nicks[self.account])
if self.xml.get_widget('save_password_checkbutton').get_active():
self.xml.get_widget('password_entry').set_text(new_password)
@ -1239,7 +1239,7 @@ class Account_modification_window:
if not self.plugin.windows[self.account]['infos'].has_key('vcard'):
self.plugin.windows[self.account]['infos'][jid] = \
vcard_information_window(jid, self.plugin, self.account, True)
self.plugin.send('ASK_VCARD', self.account, jid)
gajim.connections[self.account].request_vcard(jid)
def on_gpg_choose_button_clicked(self, widget, data=None):
secret_keys = gajim.connections[self.account].ask_gpg_secrete_keys()
@ -1359,7 +1359,7 @@ class Accounts_window:
dialog = Confirmation_dialog(_('Are you sure you want to remove account (%s) ?') % account)
if dialog.get_response() == gtk.RESPONSE_YES:
if gajim.connections[account].connected:
self.plugin.send('STATUS', account, ('offline', 'offline'))
gajim.connections[account].change_status('offline', 'offline')
del gajim.connections[account]
del self.plugin.windows[account]
del self.plugin.queues[account]
@ -1449,7 +1449,7 @@ class Service_registration_window:
'offline', 'from', '', '', 0, '')
self.plugin.roster.contacts[self.account][self.service] = [user1]
self.plugin.roster.add_user_to_roster(self.service, self.account)
self.plugin.send('REG_AGENT', self.account, self.service)
gajim.connections[self.account].register_agent(self.service)
self.window.destroy()
def __init__(self, service, infos, plugin, account):
@ -1669,7 +1669,7 @@ class Service_discovery_window:
# we begin to fill the treevier with the first line
iter = model.append(None, (jid, jid))
self.agent_infos[jid] = {'features' : []}
self.plugin.send('REQ_AGENTS', self.account, jid)
gajim.connections[self.account].request_agents(jid)
def agents(self, agents):
"""When list of available agent arrive :

View File

@ -53,8 +53,8 @@ class Vcard_information_window:
self.user.name = new_name
for i in self.plugin.roster.get_user_iter(self.user.jid, self.account):
self.plugin.roster.tree.get_model().set_value(i, 1, new_name)
self.plugin.send('UPDUSER', self.account, (self.user.jid, \
self.user.name, self.user.groups))
gajim.connections[self.account].update_user(self.user.jid, \
self.user.name, self.user.groups)
#log history ?
oldlog = 1
no_log_for = gajim.config.get_per('accounts', self.account, 'no_log_for')\
@ -119,8 +119,9 @@ class Vcard_information_window:
stats += '\n' + u.show + ': ' + u.status
self.xml.get_widget('resource_label').set_text(resources)
self.xml.get_widget('status_label').set_text(stats)
self.plugin.send('ASK_VCARD', self.account, self.user.jid)
self.plugin.send('ASK_OS_INFO', self.account, (self.user.jid, self.user.resource))
gajim.connections[self.account].request_vcard(self.user.jid)
gajim.connections[self.account].request_os_info(self.user.jid, \
self.user.resource)
def add_to_vcard(self, vcard, entry, txt):
"""Add an information to the vCard dictionary"""
@ -163,7 +164,7 @@ class Vcard_information_window:
if nick == '':
nick = gajim.config.get_per('accounts', self.account, 'name')
self.plugin.nicks[self.account] = nick
self.plugin.send('VCARD', self.account, vcard)
gajim.connections[self.account].send_vcard(vcard)
def on_retrieve_button_clicked(self, widget):
entries = ['FN', 'NICKNAME', 'BDAY', 'EMAIL_USERID', 'URL', 'TEL_NUMBER',\
@ -174,7 +175,7 @@ class Vcard_information_window:
for e in entries:
self.xml.get_widget(e + '_entry').set_text('')
self.xml.get_widget('DESC_textview').get_buffer().set_text('')
self.plugin.send('ASK_VCARD', self.account, self.jid)
gajim.connections[self.account].request_vcard(self.jid)
else:
Error_dialog(_('You must be connected to get your informations'))
@ -251,8 +252,8 @@ class Edit_groups_dialog:
self.dialog.run()
self.dialog.destroy()
#TODO: do not send if unnecesary
self.plugin.send('UPDUSER', self.account, (self.user.jid, \
self.user.name, self.user.groups))
gajim.connections[self.account].update_user(self.user.jid, \
self.user.name, self.user.groups)
def update_user(self):
self.plugin.roster.remove_user(self.user, self.account)
@ -505,7 +506,7 @@ class Add_new_contact_window:
self.plugin.roster.req_sub(self, jid, message, self.account, group,\
nickname)
if self.xml.get_widget('auto_authorize_checkbutton').get_active():
self.plugin.send('AUTH', self.account, jid)
gajim.connections[self.account].send_authorization(jid)
self.window.destroy()
def fill_jid(self):
@ -647,14 +648,14 @@ class subscription_request_window:
def on_authorize_button_clicked(self, widget):
"""Accept the request"""
self.plugin.send('AUTH', self.account, self.jid)
gajim.connections[self.account].send_authorization(self.jid)
self.window.destroy()
if not self.plugin.roster.contacts[self.account].has_key(self.jid):
Add_new_contact_window(self.plugin, self.account, self.jid)
def on_deny_button_clicked(self, widget):
"""refuse the request"""
self.plugin.send('DENY', self.account, self.jid)
gajim.connections[self.account].refuse_authorization(self.jid)
self.window.destroy()
class Join_groupchat_window:
@ -718,8 +719,7 @@ class Join_groupchat_window:
self.recently_groupchat = self.recently_groupchat[0:10]
gajim.config.set('recently_groupchat', ' '.join(self.recently_groupchat))
self.plugin.roster.new_group(jid, nickname, self.account)
self.plugin.send('GC_JOIN', self.account, (nickname, room, server, \
password))
gajim.connections[self.account].join_gc(nickname, room, server, password)
self.window.destroy()

View File

@ -72,8 +72,8 @@ class Groupchat_window(Chat):
def on_groupchat_window_destroy(self, widget):
for room_jid in self.xmls:
self.plugin.send('GC_STATUS', self.account, (self.nicks[room_jid], \
room_jid, 'offline', 'offline'))
gajim.connections[self.account].send_gc_status(self.nicks[room_jid], \
room_jid, 'offline', 'offline')
Chat.on_window_destroy(self, widget, 'gc')
def on_groupchat_window_focus_in_event(self, widget, event):
@ -233,7 +233,7 @@ class Groupchat_window(Chat):
def on_set_button_clicked(self, widget):
room_jid = self.get_active_jid()
subject = self.xml.get_widget('subject_entry').get_text()
self.plugin.send('GC_SUBJECT', self.account, (room_jid, subject))
gajim.connections[self.account].send_gc_subject(room_jid, subject)
def on_message_textview_key_press_event(self, widget, event):
"""When a key is pressed:
@ -267,7 +267,7 @@ class Groupchat_window(Chat):
txt = message_buffer.get_text(start_iter, end_iter, 0)
if txt != '':
room_jid = self.get_active_jid()
self.plugin.send('GC_MSG', self.account, (room_jid, txt))
gajim.connections[self.account].send_gc_message(room_jid, txt)
message_buffer.set_text('', -1)
widget.grab_focus()
return True
@ -315,68 +315,62 @@ class Groupchat_window(Chat):
def kick(self, widget, room_jid, nick):
"""kick a user"""
self.plugin.send('GC_SET_ROLE', self.account, (room_jid, nick, 'none'))
gajim.connections[self.account].gc_set_role(room_jid, nick, 'none')
def grant_voice(self, widget, room_jid, nick):
"""grant voice privilege to a user"""
self.plugin.send('GC_SET_ROLE', self.account, (room_jid, nick, \
'participant'))
gajim.connections[self.account].gc_set_role(room_jid, nick, 'participant')
def revoke_voice(self, widget, room_jid, nick):
"""revoke voice privilege to a user"""
self.plugin.send('GC_SET_ROLE', self.account, (room_jid, nick, 'visitor'))
gajim.connections[self.account].gc_set_role(room_jid, nick, 'visitor')
def grant_moderator(self, widget, room_jid, nick):
"""grant moderator privilege to a user"""
self.plugin.send('GC_SET_ROLE', self.account, (room_jid, nick,\
'moderator'))
gajim.connections[self.account].gc_set_role(room_jid, nick, 'moderator')
def revoke_moderator(self, widget, room_jid, nick):
"""revoke moderator privilege to a user"""
self.plugin.send('GC_SET_ROLE', self.account, (room_jid, nick, \
'participant'))
gajim.connections[self.account].gc_set_role(room_jid, nick, 'participant')
def ban(self, widget, room_jid, jid):
"""ban a user"""
self.plugin.send('GC_SET_AFFILIATION', self.account, (room_jid, jid, \
'outcast'))
gajim.connections[self.account].gc_set_affiliation(room_jid, jid, \
'outcast')
def grant_membership(self, widget, room_jid, jid):
"""grant membership privilege to a user"""
self.plugin.send('GC_SET_AFFILIATION', self.account, (room_jid, jid, \
'member'))
gajim.connections[self.account].gc_set_affiliation(room_jid, jid, \
'member')
def revoke_membership(self, widget, room_jid, jid):
"""revoke membership privilege to a user"""
self.plugin.send('GC_SET_AFFILIATION', self.account, (room_jid, jid, \
'none'))
gajim.connections[self.account].gc_set_affiliation(room_jid, jid, \
'none')
def grant_admin(self, widget, room_jid, jid):
"""grant administrative privilege to a user"""
self.plugin.send('GC_SET_AFFILIATION', self.account, (room_jid, jid, \
'admin'))
gajim.connections[self.account].gc_set_affiliation(room_jid, jid, 'admin')
def revoke_admin(self, widget, room_jid, jid):
"""revoke administrative privilege to a user"""
self.plugin.send('GC_SET_AFFILIATION', self.account, (room_jid, jid, \
'member'))
gajim.connections[self.account].gc_set_affiliation(room_jid, jid, \
'member')
def grant_owner(self, widget, room_jid, jid):
"""grant owner privilege to a user"""
self.plugin.send('GC_SET_AFFILIATION', self.account, (room_jid, jid, \
'owner'))
gajim.connections[self.account].gc_set_affiliation(room_jid, jid, 'owner')
def revoke_owner(self, widget, room_jid, jid):
"""revoke owner privilege to a user"""
self.plugin.send('GC_SET_AFFILIATION', self.account, (room_jid, jid, \
'admin'))
gajim.connections[self.account].gc_set_affiliation(room_jid, jid, 'admin')
def on_info(self, widget, jid):
"""Call vcard_information_window class to display user's information"""
if not self.plugin.windows[self.account]['infos'].has_key(jid):
self.plugin.windows[self.account]['infos'][jid] = \
Vcard_information_window(jid, self.plugin, self.account, True)
self.plugin.send('ASK_VCARD', self.account, jid)
gajim.connections[self.account].request_vcard(jid)
#FIXME: maybe use roster.on_info above?
#FIXME: we need the resource but it's not saved
@ -455,8 +449,8 @@ class Groupchat_window(Chat):
Chat.remove_tab(self, room_jid, 'gc')
if len(self.xmls) > 0:
self.plugin.send('GC_STATUS', self.account, (self.nicks[room_jid], \
room_jid, 'offline', 'offline'))
gajim.connections[self.account].send_gc_status(self.nicks[room_jid], \
room_jid, 'offline', 'offline')
del self.nicks[room_jid]
del self.list_treeview[room_jid]
del self.subjects[room_jid]

View File

@ -372,7 +372,7 @@ class interface:
jid = array[0].split('/')[0]
if jid.find("@") <= 0:
jid = jid.replace('@', '')
self.roster.on_message(jid, _("error while sending") + \
self.roster.on_message(jid, _('error while sending') + \
' \"%s\" ( %s )' % (array[3], array[2]), array[4], account)
def handle_event_msgsent(self, account, array):
@ -396,7 +396,7 @@ class interface:
if len(u.groups) == 0:
u.groups = ['General']
self.roster.add_user_to_roster(u.jid, account)
self.send('UPDUSER', account, (u.jid, u.name, u.groups))
gajim.connections[account].update_user(u.jid, u.name, u.groups)
else:
user1 = User(jid, jid, ['General'], 'online', \
'online', 'to', '', array[1], 0, '')
@ -532,20 +532,20 @@ class interface:
if state == common.sleepy.STATE_AWAKE and \
self.sleeper_state[account] > 1:
#we go online
self.send('STATUS', account, ('online', 'Online'))
gajim.connections[account].change_status('online', 'Online')
self.sleeper_state[account] = 1
elif state == common.sleepy.STATE_AWAY and \
self.sleeper_state[account] == 1 and \
gajim.config.get('autoaway'):
#we go away
self.send('STATUS', account, ('away', 'auto away (idle)'))
gajim.connections[account].change_status('away', 'auto away (idle)')
self.sleeper_state[account] = 2
elif state == common.sleepy.STATE_XAWAY and (\
self.sleeper_state[account] == 2 or \
self.sleeper_state[account] == 1) and \
gajim.config.get('autoxa'):
#we go extended away
self.send('STATUS', account, ('xa', 'auto away (idle)'))
gajim.connections[account].change_status('xa', 'auto away (idle)')
self.sleeper_state[account] = 3
return 1

View File

@ -52,7 +52,8 @@ class history_window:
end = 50
if end > self.nb_line:
end = self.nb_line
self.plugin.send('LOG_GET_RANGE', None, (self.jid, 0, end))
#FIXME:
# self.plugin.send('LOG_GET_RANGE', None, (self.jid, 0, end))
self.num_begin = self.nb_line
def on_previous_button_clicked(self, widget):
@ -68,7 +69,8 @@ class history_window:
end = begin + 50
if end > self.nb_line:
end = self.nb_line
self.plugin.send('LOG_GET_RANGE', None, (self.jid, begin, end))
#FIXME:
# self.plugin.send('LOG_GET_RANGE', None, (self.jid, begin, end))
self.num_begin = self.nb_line
def on_forward_button_clicked(self, widget):
@ -84,7 +86,8 @@ class history_window:
end = begin + 50
if end > self.nb_line:
end = self.nb_line
self.plugin.send('LOG_GET_RANGE', None, (self.jid, begin, end))
#FIXME:
# self.plugin.send('LOG_GET_RANGE', None, (self.jid, begin, end))
self.num_begin = self.nb_line
def on_latest_button_clicked(self, widget):
@ -97,7 +100,8 @@ class history_window:
begin = self.nb_line - 50
if begin < 0:
begin = 0
self.plugin.send('LOG_GET_RANGE', None, (self.jid, begin, self.nb_line))
#FIXME:
# self.plugin.send('LOG_GET_RANGE', None, (self.jid, begin, self.nb_line))
self.num_begin = self.nb_line
def new_line(self, infos):
@ -158,4 +162,5 @@ class history_window:
color = gajim.config.get('statusmsgcolor')
tagStatus.set_property('foreground', color)
self.window.show_all()
self.plugin.send('LOG_NB_LINE', None, jid)
#FIXME:
# self.plugin.send('LOG_NB_LINE', None, jid)

View File

@ -30,7 +30,7 @@ from tabbed_chat_window import *
from groupchat_window import *
from history_window import *
from gtkgui import CellRendererImage, User
from dialogs import *
import dialogs
from config import *
from common import i18n
@ -408,13 +408,13 @@ class Roster_window:
def on_agent_logging(self, widget, jid, state, account):
"""When an agent is requested to log in or off"""
self.plugin.send('AGENT_LOGGING', account, (jid, state))
gajim.connections[account].send_agent_status(jid, state)
def on_remove_agent(self, widget, jid, account):
"""When an agent is requested to log in or off"""
window = Confirmation_dialog(_('Are you sure you want to remove the agent %s from your roster?') % jid)
if window.get_response() == gtk.RESPONSE_YES:
self.plugin.send('UNSUB_AGENT', account, jid)
gajim.connections[account].unsubscribe_agent(jid)
for u in self.contacts[account][jid]:
self.remove_user(u, account)
del self.contacts[account][u.jid]
@ -596,13 +596,13 @@ class Roster_window:
def authorize(self, widget, jid, account):
"""Authorize a user"""
self.plugin.send('AUTH', account, jid)
gajim.connections[account].send_authorization(jid)
def req_sub(self, widget, jid, txt, account, group=None, pseudo=None):
"""Request subscription to a user"""
if not pseudo:
pseudo = jid
self.plugin.send('SUB', account, (jid, txt))
gajim.connections[account].request_subscription(jid, txt)
if not self.contacts[account].has_key(jid):
if not group:
group = 'General'
@ -685,7 +685,7 @@ class Roster_window:
"""Remove a user"""
window = Confirmation_dialog(_("Are you sure you want to remove %s (%s) from your roster?") % (user.name, user.jid))
if window.get_response() == gtk.RESPONSE_YES:
self.plugin.send('UNSUB', account, user.jid)
gajim.connections[account].unsubscribe(user.jid)
for u in self.contacts[account][user.jid]:
self.remove_user(u, account)
del self.contacts[account][u.jid]
@ -705,7 +705,7 @@ class Roster_window:
save_pass = gajim.config.get_per('accounts', account, 'savepass')
if not save_pass and gajim.connections[account].connected < 2:
passphrase = ''
w = Passphrase_dialog(_('Enter your password for account %s') \
w = dialogs.Passphrase_dialog(_('Enter your password for account %s') \
% account, 'Save password', autoconnect)
passphrase, save = w.run()
if passphrase == -1:
@ -715,7 +715,7 @@ class Roster_window:
self.plugin.systray.set_status('offline')
self.update_status_comboxbox()
return
self.plugin.send('PASSPHRASE', account, passphrase)
gajim.connections[account].password = passphrase
if save:
gajim.config.set_per('accounts', account, 'savepass', True)
gajim.config.set_per('accounts', account, 'password', passphrase)
@ -732,7 +732,7 @@ class Roster_window:
'gpgpassword')
else:
passphrase = ''
w = Passphrase_dialog(\
w = dialogs.Passphrase_dialog(\
_('Enter GPG key passphrase for account %s') % account, \
'Save passphrase', autoconnect)
passphrase, save = w.run()
@ -742,14 +742,13 @@ class Roster_window:
gajim.config.set_per('accounts', account, 'savegpgpass', True)
gajim.config.set_per('accounts', account, 'gpgpassword', \
passphrase)
#FIXME:
self.plugin.send('GPGPASSPHRASE', account, passphrase)
self.plugin.send('STATUS', account, (status, txt))
gajim.connections[account].gpg_passphrase(passphrase)
gajim.connections[account].change_status(status, txt)
for room_jid in self.plugin.windows[account]['gc']:
if room_jid != 'tabbed':
nick = self.plugin.windows[account]['gc'][room_jid].nicks[room_jid]
self.plugin.send('GC_STATUS', account, (nick, room_jid, status, \
txt))
gajim.connections[account].send_gc_status(nick, room_jid, status, \
txt)
if status == 'online' and self.plugin.sleeper.getState() != \
common.sleepy.STATE_UNKNOWN:
self.plugin.sleeper_state[account] = 1
@ -982,7 +981,8 @@ class Roster_window:
gajim.config.set('height', height)
self.plugin.save_config()
self.plugin.send('QUIT', None, ('gtkgui', 1))
for account in gajim.connections:
gajim.connections[account].quit(True)
self.close_all(self.plugin.windows)
if self.plugin.systray_enabled:
self.plugin.hide_systray()
@ -1083,8 +1083,7 @@ class Roster_window:
if old_text != new_text:
for u in self.contacts[account][jid]:
u.name = new_text
self.plugin.send('UPDUSER', account, (jid, new_text, \
self.contacts[account][jid][0].groups))
gajim.connections[account].update_user(jid, new_text, u.groups)
self.redraw_jid(jid, account)
elif type == 'group':
old_name = model.get_value(iter, 1)
@ -1097,8 +1096,8 @@ class Roster_window:
user.groups.remove(old_name)
user.groups.append(new_text)
self.add_user_to_roster(user.jid, account)
self.plugin.send('UPDUSER', account, (user.jid, user.name, \
user.groups))
gajim.connections[account].update_user(user.jid, user.name, \
user.groups)
model.set_value(iter, 5, False)
def on_service_disco_menuitem_activate(self, widget, account):
@ -1298,7 +1297,7 @@ class Roster_window:
u = self.contacts[account][data][0]
u.groups.remove(grp_source)
u.groups.append(grp_dest)
self.plugin.send('UPDUSER', account, (u.jid, u.name, u.groups))
gajim.connections[account].update_user(u.jid, u.name, u.groups)
if model.iter_n_children(iter_group_source) == 1: #this was the only child
model.remove(iter_group_source)
#delete the group if it is empty (need to look for offline users too)

View File

@ -187,7 +187,7 @@ class Tabbed_chat_window(Chat):
keyID = ''
if self.xmls[jid].get_widget('gpg_togglebutton').get_active():
keyID = self.users[jid].keyID
self.plugin.send('MSG', self.account, (jid, message, keyID))
gajim.connections[self.account].send_message(jid, message, keyID)
message_buffer.set_text('', -1)
self.print_conversation(message, jid, jid)
return True