format of l_contact and user's class in gtkgui
This commit is contained in:
parent
d8b7e22828
commit
c1035c159b
|
@ -65,6 +65,7 @@ class GajimCore:
|
||||||
elif type == 'subscribe':
|
elif type == 'subscribe':
|
||||||
log.debug("subscribe request from %s" % who)
|
log.debug("subscribe request from %s" % who)
|
||||||
elif type == 'subscribed':
|
elif type == 'subscribed':
|
||||||
|
#plein de trucs a faire
|
||||||
log.debug("we are now subscribed to %s" % who)
|
log.debug("we are now subscribed to %s" % who)
|
||||||
elif type == 'unsubscribe':
|
elif type == 'unsubscribe':
|
||||||
log.debug("unsubscribe request from %s" % who)
|
log.debug("unsubscribe request from %s" % who)
|
||||||
|
@ -105,7 +106,7 @@ class GajimCore:
|
||||||
else:
|
else:
|
||||||
show = roster.getOnline(jid)
|
show = roster.getOnline(jid)
|
||||||
tab_roster[jid.getBasic()] = \
|
tab_roster[jid.getBasic()] = \
|
||||||
{"Online":roster.getOnline(jid), "Status":roster.getStatus(jid), "Show":show}
|
{"Online":roster.getOnline(jid), "nom":jid.getNode(), "server":jid.getDomain(), "resource":jid.getResource(), "group":'general', "status":roster.getStatus(jid), "show":show}
|
||||||
self.hub.sendPlugin('ROSTER', tab_roster)
|
self.hub.sendPlugin('ROSTER', tab_roster)
|
||||||
self.con.sendInitPresence()
|
self.con.sendInitPresence()
|
||||||
self.connected = 1
|
self.connected = 1
|
||||||
|
|
|
@ -24,6 +24,8 @@ import gtk
|
||||||
import gtk.glade
|
import gtk.glade
|
||||||
import gobject
|
import gobject
|
||||||
import string
|
import string
|
||||||
|
import pickle
|
||||||
|
import marshal
|
||||||
import common.optparser
|
import common.optparser
|
||||||
CONFPATH = "~/.gajimrc"
|
CONFPATH = "~/.gajimrc"
|
||||||
|
|
||||||
|
@ -31,21 +33,29 @@ class user:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
if len(args) == 0:
|
if len(args) == 0:
|
||||||
self.name = ''
|
self.name = ''
|
||||||
|
self.server = ''
|
||||||
|
self.resource = ''
|
||||||
self.group = ''
|
self.group = ''
|
||||||
self.show = ''
|
self.show = ''
|
||||||
self.status = ''
|
self.status = ''
|
||||||
elif len(args) == 4:
|
elif len(args) == 6:
|
||||||
self.name = args[0]
|
self.name = args[0]
|
||||||
self.group = args[1]
|
self.server = args[1]
|
||||||
self.show = args[2]
|
self.resource = args[2]
|
||||||
self.status = args[3]
|
self.group = args[3]
|
||||||
|
self.show = args[4]
|
||||||
|
self.status = args[5]
|
||||||
elif ((len(args)) and (type (args[0]) == type (self)) and
|
elif ((len(args)) and (type (args[0]) == type (self)) and
|
||||||
(self.__class__ == args[0].__class__)):
|
(self.__class__ == args[0].__class__)):
|
||||||
self.name = args[0].name
|
self.name = args[0].name
|
||||||
|
self.server = args[0].server
|
||||||
|
self.resource = args[0].resource
|
||||||
self.group = args[0].group
|
self.group = args[0].group
|
||||||
self.show = args[0].show
|
self.show = args[0].show
|
||||||
self.status = args[0].status
|
self.status = args[0].status
|
||||||
else: raise TypeError, 'bad arguments'
|
else: raise TypeError, 'bad arguments'
|
||||||
|
# self.jid = self.name + '@' + self.server + '/' + self.resource
|
||||||
|
self.jid = self.name + '@' + self.server
|
||||||
|
|
||||||
class add:
|
class add:
|
||||||
def delete_event(self, widget):
|
def delete_event(self, widget):
|
||||||
|
@ -86,7 +96,7 @@ class accounts:
|
||||||
|
|
||||||
class message:
|
class message:
|
||||||
def delete_event(self, widget):
|
def delete_event(self, widget):
|
||||||
del self.roster.tab_messages[self.jid]
|
del self.roster.tab_messages[self.user.jid]
|
||||||
self.window.destroy()
|
self.window.destroy()
|
||||||
|
|
||||||
def print_conversation(self, txt, contact = None):
|
def print_conversation(self, txt, contact = None):
|
||||||
|
@ -94,7 +104,7 @@ class message:
|
||||||
if contact:
|
if contact:
|
||||||
self.convTxtBuffer.insert_with_tags_by_name(end_iter, '<moi> ', 'outgoing')
|
self.convTxtBuffer.insert_with_tags_by_name(end_iter, '<moi> ', 'outgoing')
|
||||||
else:
|
else:
|
||||||
self.convTxtBuffer.insert_with_tags_by_name(end_iter, '<lui> ', 'incomming')
|
self.convTxtBuffer.insert_with_tags_by_name(end_iter, '<' + self.user.name + '> ', 'incomming')
|
||||||
self.convTxtBuffer.insert(end_iter, txt+'\n')
|
self.convTxtBuffer.insert(end_iter, txt+'\n')
|
||||||
self.conversation.scroll_to_mark(\
|
self.conversation.scroll_to_mark(\
|
||||||
self.convTxtBuffer.get_mark('end'), 0.1, 0, 0, 0)
|
self.convTxtBuffer.get_mark('end'), 0.1, 0, 0, 0)
|
||||||
|
@ -107,21 +117,21 @@ class message:
|
||||||
start_iter = txt_buffer.get_start_iter()
|
start_iter = txt_buffer.get_start_iter()
|
||||||
end_iter = txt_buffer.get_end_iter()
|
end_iter = txt_buffer.get_end_iter()
|
||||||
txt = txt_buffer.get_text(start_iter, end_iter, 0)
|
txt = txt_buffer.get_text(start_iter, end_iter, 0)
|
||||||
self.roster.queueOUT.put(('MSG',(self.jid, txt)))
|
self.roster.queueOUT.put(('MSG',(self.user.jid, txt)))
|
||||||
txt_buffer.set_text('', -1)
|
txt_buffer.set_text('', -1)
|
||||||
self.print_conversation(txt, self.jid)
|
self.print_conversation(txt, self.user.jid)
|
||||||
widget.grab_focus()
|
widget.grab_focus()
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def __init__(self, jid, roster):
|
def __init__(self, user, roster):
|
||||||
self.cfgParser = common.optparser.OptionsParser(CONFPATH)
|
self.cfgParser = common.optparser.OptionsParser(CONFPATH)
|
||||||
self.cfgParser.parseCfgFile()
|
self.cfgParser.parseCfgFile()
|
||||||
self.jid = jid
|
self.user = user
|
||||||
self.roster = roster
|
self.roster = roster
|
||||||
self.xml = gtk.glade.XML('plugins/gtkgui.glade', 'Chat')
|
self.xml = gtk.glade.XML('plugins/gtkgui.glade', 'Chat')
|
||||||
self.window = self.xml.get_widget('Chat')
|
self.window = self.xml.get_widget('Chat')
|
||||||
self.window.set_title('Chat with ' + jid)
|
self.window.set_title('Chat with ' + user.name)
|
||||||
self.message = self.xml.get_widget('message')
|
self.message = self.xml.get_widget('message')
|
||||||
self.conversation = self.xml.get_widget('conversation')
|
self.conversation = self.xml.get_widget('conversation')
|
||||||
self.convTxtBuffer = self.conversation.get_buffer()
|
self.convTxtBuffer = self.conversation.get_buffer()
|
||||||
|
@ -144,29 +154,29 @@ class roster:
|
||||||
return self.tree.render_icon(stock, size = gtk.ICON_SIZE_MENU, detail = None)
|
return self.tree.render_icon(stock, size = gtk.ICON_SIZE_MENU, detail = None)
|
||||||
|
|
||||||
def mkl_group(self):
|
def mkl_group(self):
|
||||||
""" {name:iter} """
|
""" l_group = {name:iter} """
|
||||||
self.l_group = {}
|
self.l_group = {}
|
||||||
for u in self.l_contact:
|
for u in self.l_contact.values():
|
||||||
if not self.l_group.has_key(u.group):
|
if not self.l_group.has_key(u.group):
|
||||||
iterG = self.treestore.append(None, (self.pixbufs['online'], u.group, 'group'))
|
iterG = self.treestore.append(None, (self.pixbufs['online'], u.group, 'group'))
|
||||||
self.l_group[u.group]=iterG
|
self.l_group[u.group]=iterG
|
||||||
|
|
||||||
def mkroster(self, tab):
|
def mkroster(self, tab):
|
||||||
self.l_contact = []
|
self.l_contact = {}
|
||||||
for jid in tab.keys():
|
for jid in tab.keys():
|
||||||
user1 = user(jid, 'general', tab[jid]["Show"], tab[jid]["Status"])
|
user1 = user(tab[jid]['nom'], tab[jid]['server'], tab[jid]['resource'], tab[jid]['group'], tab[jid]["show"], tab[jid]["status"])
|
||||||
self.l_contact.append(user1)
|
self.l_contact[user1.jid] = user1
|
||||||
self.treestore.clear()
|
self.treestore.clear()
|
||||||
self.mkl_group()
|
self.mkl_group()
|
||||||
for g in self.l_group.keys():
|
for g in self.l_group.keys():
|
||||||
for c in self.l_contact:
|
for c in self.l_contact.values():
|
||||||
if c.group == g:
|
if c.group == g:
|
||||||
if c.show != 'offline' or self.showOffline:
|
if c.show != 'offline' or self.showOffline:
|
||||||
self.treestore.append(self.l_group[g], (self.pixbufs[c.show], c.name, c.show))
|
self.treestore.append(self.l_group[g], (self.pixbufs[c.show], c.name, c.jid))
|
||||||
|
|
||||||
def update_iter(self, widget, path, iter, data):
|
def update_iter(self, widget, path, iter, data):
|
||||||
val = self.treestore.get_value(iter, 1)
|
jid = self.treestore.get_value(iter, 2)
|
||||||
if val == data[0]:
|
if jid == data[0]:
|
||||||
if data[1] == 'offline':
|
if data[1] == 'offline':
|
||||||
self.treestore.remove(iter)
|
self.treestore.remove(iter)
|
||||||
if not self.showOffline:
|
if not self.showOffline:
|
||||||
|
@ -178,18 +188,17 @@ class roster:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def chg_status(self, jid, show, status):
|
def chg_status(self, jid, show, status):
|
||||||
for u in self.l_contact:
|
u = self.l_contact[jid]
|
||||||
if u.name == jid:
|
self.found = 0
|
||||||
self.found = 0
|
self.treestore.foreach(self.update_iter, (jid, show))
|
||||||
self.treestore.foreach(self.update_iter, (jid, show))
|
if self.found == 0:
|
||||||
if self.found == 0:
|
if not self.l_group.has_key(u.group):
|
||||||
if not self.l_group.has_key(u.group):
|
iterG = self.treestore.append(None, (self.pixbufs['online'], u.group, 'group'))
|
||||||
iterG = self.treestore.append(None, (self.pixbufs['online'], u.group, 'group'))
|
self.l_group[u.group] = iterG
|
||||||
self.l_group[u.group] = iterG
|
self.treestore.append(self.l_group[u.group], (self.pixbufs[show], u.name, u.jid))
|
||||||
self.treestore.append(self.l_group[u.group], (self.pixbufs[show], u.name, show))
|
u.show = show
|
||||||
u.show = show
|
u.status = status
|
||||||
u.status = status
|
return 1
|
||||||
return 1
|
|
||||||
|
|
||||||
def mk_menu_c(self, event, iter):
|
def mk_menu_c(self, event, iter):
|
||||||
self.menu_c = gtk.Menu()
|
self.menu_c = gtk.Menu()
|
||||||
|
@ -228,25 +237,18 @@ class roster:
|
||||||
return gtk.FALSE
|
return gtk.FALSE
|
||||||
|
|
||||||
def on_req_usub(self, widget, iter):
|
def on_req_usub(self, widget, iter):
|
||||||
who = self.treestore.get_value(iter, 1)
|
jid = self.treestore.get_value(iter, 2)
|
||||||
print "on vire %s" % who
|
self.queueOUT.put(('UNSUB', jid))
|
||||||
self.queueOUT.put(('UNSUB', who))
|
del self.l_contact[jid]
|
||||||
for u in self.l_contact:
|
|
||||||
if u.name == who:
|
|
||||||
self.l_contact.remove(u)
|
|
||||||
self.treestore.remove(iter)
|
self.treestore.remove(iter)
|
||||||
|
|
||||||
def req_sub(self, who, txt):
|
def req_sub(self, jid, txt):
|
||||||
self.queueOUT.put(('SUB', (who, txt)))
|
self.queueOUT.put(('SUB', (jid, txt)))
|
||||||
found=0
|
if not self.l_contact.has_key(jid):
|
||||||
for u in self.l_contact:
|
user1 = user(jid, jid, jid, 'general', 'requested', 'requested')
|
||||||
if u.name == who:
|
self.l_contact[jid] = user1
|
||||||
found=1
|
|
||||||
if found == 0:
|
|
||||||
user1 = user(who, 'general', 'requested', 'requested')
|
|
||||||
self.l_contact.append(user1)
|
|
||||||
#TODO: ajouter un grp si necessaire
|
#TODO: ajouter un grp si necessaire
|
||||||
self.treestore.append(self.l_group['general'], (self.pixbufs['requested'], who, 'requested'))
|
self.treestore.append(self.l_group['general'], (self.pixbufs['requested'], jid, jid))
|
||||||
|
|
||||||
def on_status_changed(self, widget):
|
def on_status_changed(self, widget):
|
||||||
self.queueOUT.put(('STATUS',widget.name))
|
self.queueOUT.put(('STATUS',widget.name))
|
||||||
|
@ -266,12 +268,12 @@ class roster:
|
||||||
|
|
||||||
def on_row_activated(self, widget, path, col):
|
def on_row_activated(self, widget, path, col):
|
||||||
iter = self.treestore.get_iter(path)
|
iter = self.treestore.get_iter(path)
|
||||||
jid = self.treestore.get_value(iter, 1)
|
jid = self.treestore.get_value(iter, 2)
|
||||||
if self.tab_messages.has_key(jid):
|
if self.tab_messages.has_key(jid):
|
||||||
#NE FONCTIONNE PAS !
|
#NE FONCTIONNE PAS !
|
||||||
self.tab_messages[jid].window.grab_focus()
|
self.tab_messages[jid].window.grab_focus()
|
||||||
else:
|
else:
|
||||||
self.tab_messages[jid] = message(jid, self)
|
self.tab_messages[jid] = message(self.l_contact[jid], self)
|
||||||
|
|
||||||
def __init__(self, queueOUT):
|
def __init__(self, queueOUT):
|
||||||
#initialisation des variables
|
#initialisation des variables
|
||||||
|
@ -331,7 +333,7 @@ class plugin:
|
||||||
self.r.chg_status(ev[1][0], ev[1][1], ev[1][2])
|
self.r.chg_status(ev[1][0], ev[1][1], ev[1][2])
|
||||||
elif ev[0] == 'MSG':
|
elif ev[0] == 'MSG':
|
||||||
if not self.r.tab_messages.has_key(ev[1][0]):
|
if not self.r.tab_messages.has_key(ev[1][0]):
|
||||||
self.r.tab_messages[ev[1][0]] = message(ev[1][0], self.r)
|
self.r.tab_messages[ev[1][0]] = message(self.r.l_contact[ev[1][0]], self.r)
|
||||||
self.r.tab_messages[ev[1][0]].print_conversation(ev[1][1])
|
self.r.tab_messages[ev[1][0]].print_conversation(ev[1][1])
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue