Exemplo n.º 1
0
	def attach_to_interface(self):
		if self.interface is not None:
			return
		self.interface = dbus_support.get_notifications_interface()
		self.interface.connect_to_signal('ActionInvoked', self.on_action_invoked)
		self.interface.connect_to_signal('NotificationClosed', self.on_closed)
Exemplo n.º 2
0
	def __init__(self, event_type, jid, account, msg_type = '', file_props = None):
		self.account = account
		self.jid = jid
		self.msg_type = msg_type
		self.file_props = file_props

		if jid in gajim.contacts[account]:
			actor = gajim.get_first_contact_instance_from_jid(account, jid).name
		else:
			actor = jid

		txt = actor # default value of txt

		if event_type == _('Contact Signed In'):
			img = 'contact_online.png'
			ntype = 'presence.online'
		elif event_type == _('Contact Signed Out'):
			img = 'contact_offline.png'
			ntype = 'presence.offline'
		elif event_type in (_('New Message'), _('New Single Message'),
			_('New Private Message')):
			ntype = 'im.received'
			if event_type == _('New Private Message'):
				room_jid, nick = gajim.get_room_and_nick_from_fjid(jid)
				room_name,t = gajim.get_room_name_and_server_from_room_jid(room_jid)
				txt = _('%(nickname)s in room %(room_name)s has sent you a new message.')\
					% {'nickname': nick, 'room_name': room_name}
				img = 'priv_msg_recv.png'
			else:
				#we talk about a name here
				txt = _('%s has sent you a new message.') % actor
				if event_type == _('New Message'):
					img = 'chat_msg_recv.png'
				else: # New Single Message
					img = 'single_msg_recv.png'
		elif event_type == _('File Transfer Request'):
			img = 'ft_request.png'
			ntype = 'transfer'
			#we talk about a name here
			txt = _('%s wants to send you a file.') % actor
		elif event_type == _('File Transfer Error'):
			img = 'ft_stopped.png'
			ntype = 'transfer.error'
		elif event_type in (_('File Transfer Completed'), _('File Transfer Stopped')):
			ntype = 'transfer.complete'
			if file_props is not None:
				if file_props['type'] == 'r':
					# get the name of the sender, as it is in the roster
					sender = unicode(file_props['sender']).split('/')[0]
					name = gajim.get_first_contact_instance_from_jid(
						account, sender).name
					filename = os.path.basename(file_props['file-name'])
					if event_type == _('File Transfer Completed'):
						txt = _('You successfully received %(filename)s from %(name)s.')\
							% {'filename': filename, 'name': name}
						img = 'ft_done.png'
					else: # ft stopped
						txt = _('File transfer of %(filename)s from %(name)s stopped.')\
							% {'filename': filename, 'name': name}
						img = 'ft_stopped.png'
				else:
					receiver = file_props['receiver']
					if hasattr(receiver, 'jid'):
						receiver = receiver.jid
					receiver = receiver.split('/')[0]
					# get the name of the contact, as it is in the roster
					name = gajim.get_first_contact_instance_from_jid(
						account, receiver).name
					filename = os.path.basename(file_props['file-name'])
					if event_type == _('File Transfer Completed'):
						txt = _('You successfully sent %(filename)s to %(name)s.')\
							% {'filename': filename, 'name': name}
						img = 'ft_done.png'
					else: # ft stopped
						txt = _('File transfer of %(filename)s to %(name)s stopped.')\
							% {'filename': filename, 'name': name}
						img = 'ft_stopped.png'
			else:
				txt = ''
		else:
			# defaul failsafe values
			img = 'chat_msg_recv.png' # img to display
			ntype = 'im'	 # Notification Type

		path = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', img)
		path = os.path.abspath(path)

		self.notif = dbus_support.get_notifications_interface()
		if self.notif is None:
			raise dbus.dbus_bindings.DBusException()
		self.id = self.notif.Notify(dbus.String(_('Gajim')),
			dbus.String(path), dbus.UInt32(0), ntype, dbus.Byte(0),
			dbus.String(event_type), dbus.String(txt),
			[dbus.String(path)], {'default':0}, [''], True, dbus.UInt32(5))
		notification_response_manager.attach_to_interface()
		notification_response_manager.pending[self.id] = self