Beispiel #1
0
	def send_file(self, *args):
		'''send_file(file_path, jid, account=None) 
		send file, located at 'file_path' to 'jid', using account 
		(optional) 'account' '''
		file_path, jid, account = self._get_real_arguments(args, 3)
		accounts = gajim.contacts.keys()
		
		# if there is only one account in roster, take it as default
		# if user did not ask for account
		if not account and len(accounts) == 1:
			account = accounts[0]
		if account:
			if gajim.connections[account].connected > 1: # account is  online
				connected_account = gajim.connections[account]
		else:
			for account in accounts:
				if gajim.contacts[account].has_key(jid) and \
					gajim.connections[account].connected > 1: # account is  online
					connected_account = gajim.connections[account]
					break
		if gajim.contacts.has_key(account) and \
			gajim.contacts[account].has_key(jid):
			contact = gajim.get_highest_prio_contact_from_contacts(
				gajim.contacts[account][jid])
		else:
			contact = jid
		
		if connected_account:
			if os.path.isfile(file_path): # is it file?
				gajim.interface.instances['file_transfers'].send_file(account, 
					contact, file_path)
				return True
		return False
Beispiel #2
0
	def make_groups_submenus_for_chat_with(self, account):
		iconset = gajim.config.get('iconset')
		if not iconset:
			iconset = 'dcraven'
		path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
		state_images = gajim.interface.roster.load_iconset(path)
		
		groups_menu = gtk.Menu()
		
		for group in gajim.groups[account].keys():
			if group == _('Transports'):
				continue
			# at least one 'not offline' or 'without errors' in this group
			at_least_one = False
			item = gtk.MenuItem(group)
			groups_menu.append(item)
			contacts_menu = gtk.Menu()
			item.set_submenu(contacts_menu)
			for contacts in gajim.contacts[account].values():
				contact = gajim.get_highest_prio_contact_from_contacts(contacts)
				if group in contact.groups and contact.show != 'offline' and \
						contact.show != 'error':
					at_least_one = True
					s = contact.name.replace('_', '__') # two _ show one _ and no underline happens
					item = gtk.ImageMenuItem(s)
					# any given gtk widget can only be used in one place
					# (here we use it in status menu too)
					# gtk.Image is a widget, it's better we refactor to use gdk.gdk.Pixbuf allover
					img = state_images[contact.show]
					img_copy = gobject.new(gtk.Image, pixbuf=img.get_pixbuf())
					item.set_image(img_copy)
					item.connect('activate', self.start_chat, account,
							contact.jid)
					contacts_menu.append(item)
			
			if not at_least_one:
				message = _('All contacts in this group are offline or have errors')
				item = gtk.MenuItem(message)
				item.set_sensitive(False)
				contacts_menu.append(item)

		return groups_menu
Beispiel #3
0
    def populate(self, contacts):
        self.create_window()
        self.hbox = gtk.HBox()
        self.hbox.set_homogeneous(False)
        self.hbox.set_spacing(0)
        self.create_table()
        if not contacts or len(contacts) == 0:
            # Tooltip for merged accounts row
            accounts = self.get_accounts_info()
            self.current_row = 0
            self.table.resize(2, 1)
            self.spacer_label = ""
            self.fill_table_with_accounts(accounts)
            self.hbox.add(self.table)
            self.win.add(self.hbox)
            return
            # primary contact
        prim_contact = gajim.get_highest_prio_contact_from_contacts(contacts)

        # try to find the image for the contact status
        icon_name = helpers.get_icon_name_to_show(prim_contact)
        state_file = icon_name.replace(" ", "_")
        transport = gajim.get_transport_name_from_jid(prim_contact.jid)
        if transport:
            file_path = os.path.join(gajim.DATA_DIR, "iconsets", "transports", transport, "16x16")
        else:
            iconset = gajim.config.get("iconset")
            if not iconset:
                iconset = "dcraven"
            file_path = os.path.join(gajim.DATA_DIR, "iconsets", iconset, "16x16")

        files = []
        file_full_path = os.path.join(file_path, state_file)
        files.append(file_full_path + ".png")
        files.append(file_full_path + ".gif")
        self.image.set_from_pixbuf(None)
        for file in files:
            if os.path.exists(file):
                self.image.set_from_file(file)
                break

        info = '<span size="large" weight="bold">' + prim_contact.jid + "</span>"
        info += (
            '\n<span weight="bold">'
            + _("Name: ")
            + "</span>"
            + gtkgui_helpers.escape_for_pango_markup(prim_contact.name)
        )
        if prim_contact.sub:
            info += (
                '\n<span weight="bold">'
                + _("Subscription: ")
                + "</span>"
                + gtkgui_helpers.escape_for_pango_markup(prim_contact.sub)
            )

        if prim_contact.keyID:
            keyID = None
            if len(prim_contact.keyID) == 8:
                keyID = prim_contact.keyID
            elif len(prim_contact.keyID) == 16:
                keyID = prim_contact.keyID[8:]
            if keyID:
                info += (
                    '\n<span weight="bold">'
                    + _("OpenPGP: ")
                    + "</span>"
                    + gtkgui_helpers.escape_for_pango_markup(keyID)
                )

        num_resources = 0
        for contact in contacts:
            if contact.resource:
                num_resources += 1
        if num_resources > 1:
            self.current_row = 1
            self.table.resize(2, 1)
            info += '\n<span weight="bold">' + _("Status: ") + "</span>"
            for contact in contacts:
                if contact.resource:
                    status_line = self.get_status_info(contact.resource, contact.priority, contact.show, contact.status)
                    icon_name = helpers.get_icon_name_to_show(contact)
                    self.add_status_row(file_path, icon_name, status_line)

        else:  # only one resource
            if contact.resource:
                info += (
                    '\n<span weight="bold">'
                    + _("Resource: ")
                    + "</span>"
                    + gtkgui_helpers.escape_for_pango_markup(contact.resource)
                    + " ("
                    + unicode(contact.priority)
                    + ")"
                )
            if contact.show:
                info += '\n<span weight="bold">' + _("Status: ") + "</span>" + helpers.get_uf_show(contact.show)
                if contact.status:
                    status = contact.status.strip()
                    if status != "":
                        # reduce long status
                        # (no more than 130 chars on line and no more than 5 lines)
                        status = gtkgui_helpers.reduce_chars_newlines(status, 130, 5)
                        # escape markup entities.
                        info += " - " + gtkgui_helpers.escape_for_pango_markup(status)

        self.text_label.set_markup(info)
        self.hbox.pack_start(self.image, False, False)
        self.hbox.pack_start(self.table, True, True)
        self.win.add(self.hbox)