Ejemplo n.º 1
0
	def show_avatar(self, jid, resource):
		# Get the XML instance
		jid_with_resource = jid
		if resource:
			jid_with_resource += '/' + resource

		xml = None
		if self.xmls.has_key(jid):
			xml = self.xmls[jid]
		else:
			# it can be xmls[jid/resource] if it's a vcard from pm
			if self.xmls.has_key(jid_with_resource):
				xml = self.xmls[jid_with_resource]
		if not xml:
			return
		
		# we assume contact has no avatar
		scaled_pixbuf = None

		real_jid = gajim.get_real_jid_from_fjid(self.account, jid)
		pixbuf = None
		if real_jid:
			pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(real_jid)
		if not real_jid or pixbuf == 'ask':
			# we don't have the vcard or it's pm and we don't have the real jid
			gajim.connections[self.account].request_vcard(jid_with_resource)
			return
		if pixbuf is not None:
			scaled_pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'chat')
			

		image = xml.get_widget('avatar_image')
		image.set_from_pixbuf(scaled_pixbuf)
		image.show_all()
Ejemplo n.º 2
0
	def show_bigger_avatar(self, small_avatar):
		'''resizes the avatar, if needed, so it has at max half the screen size
		and shows it'''
		jid = self.get_active_jid()
		real_jid = gajim.get_real_jid_from_fjid(self.account, jid)
		if not real_jid: # this can happend if we're in a moderate room
			return
		avatar_pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(real_jid)
		screen_w = gtk.gdk.screen_width()
		screen_h = gtk.gdk.screen_height()
		avatar_w = avatar_pixbuf.get_width()
		avatar_h = avatar_pixbuf.get_height()
		half_scr_w = screen_w / 2
		half_scr_h = screen_h / 2
		if avatar_w > half_scr_w:
			avatar_w = half_scr_w
		if avatar_h > half_scr_h:
			avatar_h = half_scr_h
		window = gtk.Window(gtk.WINDOW_POPUP)
		self.bigger_avatar_window = window
		pixmap, mask = avatar_pixbuf.render_pixmap_and_mask()
		window.set_size_request(avatar_w, avatar_h)
		# we should make the cursor visible
		# gtk+ doesn't make use of the motion notify on gtkwindow by default
		# so this line adds that
		window.set_events(gtk.gdk.POINTER_MOTION_MASK)
		window.set_app_paintable(True)
		
		window.realize()
		window.window.set_back_pixmap(pixmap, False) # make it transparent
		window.window.shape_combine_mask(mask, 0, 0)

		# make the bigger avatar window show up centered 
		x0, y0 = small_avatar.window.get_origin()
		x0 += small_avatar.allocation.x
		y0 += small_avatar.allocation.y
		center_x= x0 + (small_avatar.allocation.width / 2)
		center_y = y0 + (small_avatar.allocation.height / 2)
		pos_x, pos_y = center_x - (avatar_w / 2), center_y - (avatar_h / 2) 
		window.move(pos_x, pos_y)
		# make the cursor invisible so we can see the image
		invisible_cursor = gtkgui_helpers.get_invisible_cursor()
		window.window.set_cursor(invisible_cursor)

		# we should hide the window
		window.connect('leave_notify_event',
			self.on_window_avatar_leave_notify_event)
		window.connect('motion-notify-event',
			self.on_window_motion_notify_event)

		window.show_all()
Ejemplo n.º 3
0
	def on_avatar_eventbox_enter_notify_event(self, widget, event):
		'''we enter the eventbox area so we under conditions add a timeout
		to show a bigger avatar after 0.5 sec'''
		jid = self.get_active_jid()
		real_jid = gajim.get_real_jid_from_fjid(self.account, jid)
		if not real_jid: # this can happend if we're in a moderate room
			return
		avatar_pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(real_jid)
		if avatar_pixbuf in ('ask', None):
			return
		avatar_w = avatar_pixbuf.get_width()
		avatar_h = avatar_pixbuf.get_height()
		
		scaled_buf = self.xmls[jid].get_widget('avatar_image').get_pixbuf()
		scaled_buf_w = scaled_buf.get_width()
		scaled_buf_h = scaled_buf.get_height()
		
		# do we have something bigger to show?
		if avatar_w > scaled_buf_w or avatar_h > scaled_buf_h:
			# wait for 0.5 sec in case we leave earlier
			self.show_bigger_avatar_timeout_id = gobject.timeout_add(500,
				self.show_bigger_avatar, widget)