add and remove contacts

This commit is contained in:
Yann Leboulanger 2003-10-27 16:30:37 +00:00
parent 4593339efb
commit d8b7e22828
3 changed files with 343 additions and 25 deletions

View File

@ -48,10 +48,10 @@ class GajimCore:
# END messageCB # END messageCB
def presenceCB(self, con, prs): def presenceCB(self, con, prs):
log.debug("PresenceCB")
who = str(prs.getFrom()) who = str(prs.getFrom())
type = prs.getType() type = prs.getType()
if type == None: type = 'available' if type == None: type = 'available'
log.debug("PresenceCB : %s" % type)
if type == 'available': if type == 'available':
if prs.getShow(): if prs.getShow():
show = prs.getShow() show = prs.getShow()
@ -59,9 +59,17 @@ class GajimCore:
show = 'online' show = 'online'
self.hub.sendPlugin('NOTIFY', \ self.hub.sendPlugin('NOTIFY', \
(prs.getFrom().getBasic(), show, prs.getStatus())) (prs.getFrom().getBasic(), show, prs.getStatus()))
if type == 'unavailable': elif type == 'unavailable':
self.hub.sendPlugin('NOTIFY', \ self.hub.sendPlugin('NOTIFY', \
(prs.getFrom().getBasic(), 'offline', prs.getStatus())) (prs.getFrom().getBasic(), 'offline', prs.getStatus()))
elif type == 'subscribe':
log.debug("subscribe request from %s" % who)
elif type == 'subscribed':
log.debug("we are now subscribed to %s" % who)
elif type == 'unsubscribe':
log.debug("unsubscribe request from %s" % who)
elif type == 'unsubscribed':
log.debug("we are now unsubscribed to %s" % who)
# END presenceCB # END presenceCB
@ -113,6 +121,7 @@ class GajimCore:
if self.connected == 1: if self.connected == 1:
self.con.disconnect() self.con.disconnect()
return return
#('STATUS', status)
elif ev[0] == 'STATUS': elif ev[0] == 'STATUS':
if (ev[1] != 'offline') and (self.connected == 0): if (ev[1] != 'offline') and (self.connected == 0):
self.connect() self.connect()
@ -124,10 +133,20 @@ class GajimCore:
p = common.jabber.Presence() p = common.jabber.Presence()
p.setShow(ev[1]) p.setShow(ev[1])
self.con.send(p) self.con.send(p)
#('MSG', (jid, msg))
elif ev[0] == 'MSG': elif ev[0] == 'MSG':
msg = common.jabber.Message(ev[1][0], ev[1][1]) msg = common.jabber.Message(ev[1][0], ev[1][1])
msg.setType('chat') msg.setType('chat')
self.con.send(msg) self.con.send(msg)
#('SUB', (jid, txt))
elif ev[0] == 'SUB':
log.debug('subscription request for %s' % ev[1][0])
self.con.send(common.jabber.Presence(ev[1][0], 'subscribe'))
#('UNSUB', jid)
elif ev[0] == 'UNSUB':
self.con.send(common.jabber.Presence(ev[1], 'unsubscribe'))
else:
log.debug("Unknown Command")
elif self.connected == 1: elif self.connected == 1:
self.con.process(1) self.con.process(1)
time.sleep(0.1) time.sleep(0.1)

View File

@ -2,6 +2,7 @@
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> <!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<glade-interface> <glade-interface>
<requires lib="gnome"/>
<widget class="GtkWindow" id="Gajim"> <widget class="GtkWindow" id="Gajim">
<property name="visible">True</property> <property name="visible">True</property>
@ -39,7 +40,7 @@
<property name="use_underline">True</property> <property name="use_underline">True</property>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image23"> <widget class="GtkImage" id="image51">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-convert</property> <property name="stock">gtk-convert</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -54,10 +55,10 @@
<widget class="GtkMenu" id="gajim_menu_menu"> <widget class="GtkMenu" id="gajim_menu_menu">
<child> <child>
<widget class="GtkImageMenuItem" id="preferences"> <widget class="GtkMenuItem" id="preferences">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label">gtk-preferences</property> <property name="label" translatable="yes">gtk-preferences</property>
<property name="use_stock">True</property> <property name="use_underline">True</property>
<signal name="activate" handler="on_preferences_activate" last_modification_time="Wed, 22 Oct 2003 21:18:29 GMT"/> <signal name="activate" handler="on_preferences_activate" last_modification_time="Wed, 22 Oct 2003 21:18:29 GMT"/>
</widget> </widget>
</child> </child>
@ -70,7 +71,7 @@
<signal name="activate" handler="on_accounts_activate" last_modification_time="Wed, 22 Oct 2003 21:18:21 GMT"/> <signal name="activate" handler="on_accounts_activate" last_modification_time="Wed, 22 Oct 2003 21:18:21 GMT"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image24"> <widget class="GtkImage" id="image52">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-select-color</property> <property name="stock">gtk-select-color</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -89,6 +90,33 @@
</widget> </widget>
</child> </child>
<child>
<widget class="GtkImageMenuItem" id="add">
<property name="visible">True</property>
<property name="label" translatable="yes">Add</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_add_activate" last_modification_time="Sun, 26 Oct 2003 17:26:34 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image53">
<property name="visible">True</property>
<property name="stock">gtk-add</property>
<property name="icon_size">1</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="separator1">
<property name="visible">True</property>
</widget>
</child>
<child> <child>
<widget class="GtkImageMenuItem" id="about"> <widget class="GtkImageMenuItem" id="about">
<property name="visible">True</property> <property name="visible">True</property>
@ -97,7 +125,7 @@
<signal name="activate" handler="on_about_activate" last_modification_time="Fri, 03 Oct 2003 12:49:50 GMT"/> <signal name="activate" handler="on_about_activate" last_modification_time="Fri, 03 Oct 2003 12:49:50 GMT"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image25"> <widget class="GtkImage" id="image54">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-help</property> <property name="stock">gtk-help</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -113,9 +141,22 @@
<child> <child>
<widget class="GtkImageMenuItem" id="quit"> <widget class="GtkImageMenuItem" id="quit">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label">gtk-quit</property> <property name="label" translatable="yes">_Quit</property>
<property name="use_stock">True</property> <property name="use_underline">True</property>
<signal name="activate" handler="on_quit_activate" last_modification_time="Fri, 03 Oct 2003 12:49:50 GMT"/> <signal name="activate" handler="on_quit_activate" last_modification_time="Fri, 03 Oct 2003 12:49:50 GMT"/>
<accelerator key="Q" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image55">
<property name="visible">True</property>
<property name="stock">gtk-quit</property>
<property name="icon_size">1</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget> </widget>
</child> </child>
</widget> </widget>
@ -816,6 +857,7 @@ David Ferlier (david@yazzy.org)</property>
<property name="label">gtk-close</property> <property name="label">gtk-close</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property> <property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="gtk_widget_destroy" last_modification_time="Sun, 26 Oct 2003 20:45:42 GMT"/>
</widget> </widget>
</child> </child>
</widget> </widget>
@ -1243,4 +1285,214 @@ David Ferlier (david@yazzy.org)</property>
</child> </child>
</widget> </widget>
<widget class="GtkWindow" id="Add">
<property name="visible">True</property>
<property name="title" translatable="yes">Add user</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<child>
<widget class="GtkVBox" id="vbox8">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkHBox" id="hbox11">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkLabel" id="label17">
<property name="width_request">145</property>
<property name="height_request">8</property>
<property name="visible">True</property>
<property name="label" translatable="yes">Send subscription to : </property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_RIGHT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="entry_who">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char" translatable="yes">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">10</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow6">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTextView" id="textview_sub">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="justification">GTK_JUSTIFY_LEFT</property>
<property name="wrap_mode">GTK_WRAP_NONE</property>
<property name="cursor_visible">True</property>
<property name="pixels_above_lines">0</property>
<property name="pixels_below_lines">0</property>
<property name="pixels_inside_wrap">0</property>
<property name="left_margin">0</property>
<property name="right_margin">0</property>
<property name="indent">0</property>
<property name="text" translatable="yes">I would like to add you to my contact list, please</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkHSeparator" id="hseparator4">
<property name="visible">True</property>
</widget>
<packing>
<property name="padding">10</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkHButtonBox" id="hbuttonbox1">
<property name="border_width">10</property>
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<property name="spacing">30</property>
<child>
<widget class="GtkButton" id="button_sub">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_button_sub_clicked" last_modification_time="Sun, 26 Oct 2003 21:38:59 GMT"/>
<child>
<widget class="GtkAlignment" id="alignment7">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<child>
<widget class="GtkHBox" id="hbox10">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image32">
<property name="visible">True</property>
<property name="stock">gtk-apply</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label16">
<property name="visible">True</property>
<property name="label" translatable="yes">Subscribe</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkButton" id="button11">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="gtk_widget_destroy" last_modification_time="Sun, 26 Oct 2003 20:52:16 GMT"/>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface> </glade-interface>

View File

@ -47,12 +47,33 @@ class user:
self.status = args[0].status self.status = args[0].status
else: raise TypeError, 'bad arguments' else: raise TypeError, 'bad arguments'
class add:
def delete_event(self, widget):
self.Wadd.destroy()
def on_subscribe(self, widget):
who=self.xml.get_widget("entry_who").get_text()
buf=self.xml.get_widget("textview_sub").get_buffer()
start_iter = buf.get_start_iter()
end_iter = buf.get_end_iter()
txt = buf.get_text(start_iter, end_iter, 0)
self.r.req_sub(who, txt)
self.delete_event(self)
def __init__(self, roster):
self.r=roster
self.xml = gtk.glade.XML('plugins/gtkgui.glade', 'Add')
self.Wadd=self.xml.get_widget("Add")
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
self.xml.signal_connect('on_button_sub_clicked', self.on_subscribe)
class about: class about:
def delete_event(self, widget): def delete_event(self, widget):
self.window.destroy() self.Wabout.destroy()
def __init__(self): def __init__(self):
self.xml = gtk.glade.XML('plugins/gtkgui.glade', 'About') self.xml = gtk.glade.XML('plugins/gtkgui.glade', 'About')
self.Wabout=self.xml.get_widget("About")
self.xml.signal_connect('gtk_widget_destroy', self.delete_event) self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
class accounts: class accounts:
@ -73,7 +94,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> ', 'incoming') self.convTxtBuffer.insert_with_tags_by_name(end_iter, '<lui> ', '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)
@ -109,7 +130,7 @@ class message:
self.window.show() self.window.show()
self.xml.signal_connect('gtk_widget_destroy', self.delete_event) self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
self.xml.signal_connect('on_msg_key_press_event', self.on_msg_key_press_event) self.xml.signal_connect('on_msg_key_press_event', self.on_msg_key_press_event)
self.tag = self.convTxtBuffer.create_tag("incoming") self.tag = self.convTxtBuffer.create_tag("incomming")
color = self.cfgParser.GtkGui_inmsgcolor color = self.cfgParser.GtkGui_inmsgcolor
if not color : color = red if not color : color = red
self.tag.set_property("foreground", color) self.tag.set_property("foreground", color)
@ -170,14 +191,13 @@ class roster:
u.status = status u.status = status
return 1 return 1
def mk_menu_c(self, event): def mk_menu_c(self, event, iter):
self.menu_c = gtk.Menu() self.menu_c = gtk.Menu()
item = gtk.MenuItem("user1") item = gtk.MenuItem("Remove")
self.menu_c.append(item)
item = gtk.MenuItem("user2")
self.menu_c.append(item)
item = gtk.MenuItem("user3")
self.menu_c.append(item) self.menu_c.append(item)
item.connect("activate", self.on_req_usub, iter)
# item = gtk.MenuItem("user2")
# self.menu_c.append(item)
self.menu_c.popup(None, None, None, event.button, event.time) self.menu_c.popup(None, None, None, event.button, event.time)
self.menu_c.show_all() self.menu_c.show_all()
@ -196,7 +216,6 @@ class roster:
if (event.button == 3) & (event.type == gtk.gdk.BUTTON_PRESS): if (event.button == 3) & (event.type == gtk.gdk.BUTTON_PRESS):
try: try:
path, column, x, y = self.tree.get_path_at_pos(int(event.x), int(event.y)) path, column, x, y = self.tree.get_path_at_pos(int(event.x), int(event.y))
except TypeError: except TypeError:
return return
iter = self.treestore.get_iter(path) iter = self.treestore.get_iter(path)
@ -204,13 +223,37 @@ class roster:
if data == 'group': if data == 'group':
self.mk_menu_g(event) self.mk_menu_g(event)
else: else:
self.mk_menu_c(event) self.mk_menu_c(event, iter)
return gtk.TRUE return gtk.TRUE
return gtk.FALSE return gtk.FALSE
def on_req_usub(self, widget, iter):
who = self.treestore.get_value(iter, 1)
print "on vire %s" % who
self.queueOUT.put(('UNSUB', who))
for u in self.l_contact:
if u.name == who:
self.l_contact.remove(u)
self.treestore.remove(iter)
def req_sub(self, who, txt):
self.queueOUT.put(('SUB', (who, txt)))
found=0
for u in self.l_contact:
if u.name == who:
found=1
if found == 0:
user1 = user(who, 'general', 'requested', 'requested')
self.l_contact.append(user1)
#TODO: ajouter un grp si necessaire
self.treestore.append(self.l_group['general'], (self.pixbufs['requested'], who, 'requested'))
def on_status_changed(self, widget): def on_status_changed(self, widget):
self.queueOUT.put(('STATUS',widget.name)) self.queueOUT.put(('STATUS',widget.name))
def on_add(self, widget):
window_add = add(self)
def on_about(self, widget): def on_about(self, widget):
window_about = about() window_about = about()
@ -240,7 +283,10 @@ class roster:
self.treestore = gtk.TreeStore(gtk.gdk.Pixbuf, str, str) self.treestore = gtk.TreeStore(gtk.gdk.Pixbuf, str, str)
add_pixbuf = self.get_icon_pixbuf(gtk.STOCK_ADD) add_pixbuf = self.get_icon_pixbuf(gtk.STOCK_ADD)
remove_pixbuf = self.get_icon_pixbuf(gtk.STOCK_REMOVE) remove_pixbuf = self.get_icon_pixbuf(gtk.STOCK_REMOVE)
self.pixbufs = {"online":add_pixbuf, "away":remove_pixbuf, "xa":remove_pixbuf, "dnd":remove_pixbuf, "offline":remove_pixbuf} requested_pixbuf = self.get_icon_pixbuf(gtk.STOCK_QUIT)
self.pixbufs = {"online":add_pixbuf, "away":remove_pixbuf, \
"xa":remove_pixbuf, "dnd":remove_pixbuf, "offline":remove_pixbuf, \
"requested":requested_pixbuf}
self.tree.set_model(self.treestore) self.tree.set_model(self.treestore)
self.queueOUT = queueOUT self.queueOUT = queueOUT
self.optionmenu = self.xml.get_widget('optionmenu') self.optionmenu = self.xml.get_widget('optionmenu')
@ -266,6 +312,7 @@ class roster:
#signals #signals
self.xml.signal_connect('gtk_main_quit', self.on_quit) self.xml.signal_connect('gtk_main_quit', self.on_quit)
self.xml.signal_connect('on_accounts_activate', self.on_accounts) self.xml.signal_connect('on_accounts_activate', self.on_accounts)
self.xml.signal_connect('on_add_activate', self.on_add)
self.xml.signal_connect('on_about_activate', self.on_about) self.xml.signal_connect('on_about_activate', self.on_about)
self.xml.signal_connect('on_quit_activate', self.on_quit) self.xml.signal_connect('on_quit_activate', self.on_quit)
self.xml.signal_connect('on_treeview_event', self.on_treeview_event) self.xml.signal_connect('on_treeview_event', self.on_treeview_event)
@ -277,7 +324,7 @@ class plugin:
def read_queue(self): def read_queue(self):
while self.queueIN.empty() == 0: while self.queueIN.empty() == 0:
ev = self.queueIN.get() ev = self.queueIN.get()
print ev # print ev
if ev[0] == 'ROSTER': if ev[0] == 'ROSTER':
self.r.mkroster(ev[1]) self.r.mkroster(ev[1])
elif ev[0] == 'NOTIFY': elif ev[0] == 'NOTIFY':