示例#1
0
	def set_progress(self, typ, sid, transfered_size, iter = None):
		''' change the progress of a transfer with new transfered size'''
		if not self.files_props[typ].has_key(sid):
			return
		file_props = self.files_props[typ][sid]
		full_size = int(file_props['size'])
		if full_size == 0:
			percent = 0
		else:
			percent = round(float(transfered_size) / full_size * 100)
		if iter is None:
			iter = self.get_iter_by_sid(typ, sid)
		if iter is not None:
			text = self._format_percent(percent)
			if transfered_size == 0:
				text += '0'
			else:
				text += helpers.convert_bytes(transfered_size)
			text += '/' + helpers.convert_bytes(full_size)
			# Kb/s
			
			# remaining time
			eta, speed = self._get_eta_and_speed(full_size, transfered_size, 
				file_props['elapsed-time'])
			
			self.model.set(iter, C_PROGRESS, text)
			self.model.set(iter, C_PERCENT, int(percent))
			text = self._format_time(eta)
			text += '\n'
			#This should make the string Kb/s, 
			#where 'Kb' part is taken from %s.
			#Only the 's' after / (which means second) should be translated.
			text += _('(%(filesize_unit)s/s)') % {'filesize_unit':
				helpers.convert_bytes(speed)}
			self.model.set(iter, C_TIME, text)
			
			# try to guess what should be the status image
			if file_props['type'] == 'r':
				status = 'download'
			else:
				status = 'upload'
			if file_props.has_key('paused') and file_props['paused'] == True:
				status = 'pause'
			elif file_props.has_key('stalled') and file_props['stalled'] == True:
				status = 'waiting'
			if file_props.has_key('connected') and file_props['connected'] == False:
				status = 'stop'
			self.model.set(iter, 0, self.images[status])
			if percent == 100:
				self.set_status(typ, sid, 'ok')
示例#2
0
    def show_file_request(self, account, contact, file_props):
        """
        Show dialog asking for comfirmation and store location of new file
        requested by a contact
        """
        if not file_props or not file_props.name:
            return
        sec_text = '\t' + _('File: %s') % GLib.markup_escape_text(
            file_props.name)
        if file_props.size:
            sec_text += '\n\t' + _('Size: %s') % \
                    helpers.convert_bytes(file_props.size)
        if file_props.mime_type:
            sec_text += '\n\t' + _('Type: %s') % file_props.mime_type
        if  file_props.desc:
            sec_text += '\n\t' + _('Description: %s') % file_props.desc
        prim_text = _('%s wants to send you a file:') % contact.jid
        dialog = None

        def on_response_ok(account, contact, file_props):
            self.on_file_request_accepted(account, contact, file_props)

        def on_response_cancel(account, file_props):
            gajim.connections[account].send_file_rejection(file_props)

        dialog = dialogs.NonModalConfirmationDialog(prim_text, sec_text,
                on_response_ok=(on_response_ok, account, contact, file_props),
                on_response_cancel=(on_response_cancel, account, file_props))
        dialog.connect('delete-event', lambda widget, event:
            on_response_cancel(account, file_props))
        dialog.popup()
示例#3
0
    def show_file_request(self, account, contact, file_props):
        """
        Show dialog asking for comfirmation and store location of new file
        requested by a contact
        """
        if not file_props or not file_props.name:
            return
        sec_text = '\t' + _('File: %s') % GLib.markup_escape_text(
            file_props.name)
        if file_props.size:
            sec_text += '\n\t' + _('Size: %s') % \
                    helpers.convert_bytes(file_props.size)
        if file_props.mime_type:
            sec_text += '\n\t' + _('Type: %s') % file_props.mime_type
        if  file_props.desc:
            sec_text += '\n\t' + _('Description: %s') % file_props.desc
        prim_text = _('%s wants to send you a file:') % contact.jid
        dialog = None

        def on_response_ok(account, contact, file_props):
            self.on_file_request_accepted(account, contact, file_props)

        def on_response_cancel(account, file_props):
            gajim.connections[account].send_file_rejection(file_props)

        dialog = dialogs.NonModalConfirmationDialog(prim_text, sec_text,
                on_response_ok=(on_response_ok, account, contact, file_props),
                on_response_cancel=(on_response_cancel, account, file_props))
        dialog.connect('delete-event', lambda widget, event:
            on_response_cancel(account, file_props))
        dialog.popup()
示例#4
0
	def show_file_request(self, account, contact, file_props):
		''' show dialog asking for comfirmation and store location of new
		file requested by a contact'''
		if file_props is None or not file_props.has_key('name'):
			return
		last_save_dir = gajim.config.get('last_save_dir')
		sec_text = '\t' + _('File: %s') % file_props['name']
		if file_props.has_key('size'):
			sec_text += '\n\t' + _('Size: %s') % \
				helpers.convert_bytes(file_props['size'])
		if file_props.has_key('mime-type'):
			sec_text += '\n\t' + _('Type: %s') % file_props['mime-type']
		if file_props.has_key('desc'):
			sec_text += '\n\t' + _('Description: %s') % file_props['desc']
		prim_text = _('%s wants to send you a file:') % contact.jid
		dialog = dialogs.ConfirmationDialog(prim_text, sec_text)
		if dialog.get_response() == gtk.RESPONSE_OK:
			dialog = gtk.FileChooserDialog(title=_('Save File as...'), 
				action=gtk.FILE_CHOOSER_ACTION_SAVE, 
				buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, 
				gtk.STOCK_SAVE, gtk.RESPONSE_OK))
			dialog.set_current_name(file_props['name'])
			dialog.set_default_response(gtk.RESPONSE_OK)
			gtk28 = False
			if gtk.gtk_version >= (2, 8, 0) and gtk.pygtk_version >= (2, 8, 0):
				dialog.props.do_overwrite_confirmation = True
				gtk28 = True
			if last_save_dir and os.path.isdir(last_save_dir):
				dialog.set_current_folder(last_save_dir)
			else:
				home_dir = os.path.expanduser('~')
				dialog.set_current_folder(home_dir)
			while True:
				response = dialog.run()
				if response == gtk.RESPONSE_OK:
					file_path = dialog.get_filename()
					file_path = file_path.decode('utf-8')
					if not gtk28 and os.path.exists(file_path):
						primtext = _('This file already exists')
						sectext = _('Would you like to overwrite it?')
						dialog2 = dialogs.ConfirmationDialog(primtext, sectext)
						if dialog2.get_response() != gtk.RESPONSE_OK:
							continue
					file_dir = os.path.dirname(file_path)
					if file_dir:
						gajim.config.set('last_save_dir', file_dir)
					file_props['file-name'] = file_path
					self.add_transfer(account, contact, file_props)
					gajim.connections[account].send_file_approval(file_props)
				else:
					gajim.connections[account].send_file_rejection(file_props)
				dialog.destroy()
				break
		else:
			gajim.connections[account].send_file_rejection(file_props)
示例#5
0
    def show_completed(self, jid, file_props):
        """
        Show a dialog saying that file (file_props) has been transferred
        """
        def on_open(widget, file_props):
            dialog.destroy()
            if not file_props.file_name:
                return
            path = os.path.split(file_props.file_name)[0]
            if os.path.exists(path) and os.path.isdir(path):
                helpers.launch_file_manager(path)
            self.tree.get_selection().unselect_all()

        if file_props.type_ == 'r':
            # file path is used below in 'Save in'
            (file_path, file_name) = os.path.split(file_props.file_name)
        else:
            file_name = file_props.name
        sectext = '\t' + _('Filename: %s') % gobject.markup_escape_text(
            file_name)
        sectext += '\n\t' + _('Size: %s') % \
        helpers.convert_bytes(file_props.size)
        if file_props.type_ == 'r':
            jid = unicode(file_props.sender).split('/')[0]
            sender_name = gajim.contacts.get_first_contact_from_jid(
                    file_props.tt_account, jid).get_shown_name()
            sender = sender_name
        else:
            #You is a reply of who sent a file
            sender = _('You')
        sectext += '\n\t' + _('Sender: %s') % sender
        sectext += '\n\t' + _('Recipient: ')
        if file_props.type_ == 's':
            jid = unicode(file_props.receiver).split('/')[0]
            receiver_name = gajim.contacts.get_first_contact_from_jid(
                    file_props.tt_account, jid).get_shown_name()
            recipient = receiver_name
        else:
            #You is a reply of who received a file
            recipient = _('You')
        sectext += recipient
        if file_props.type_ == 'r':
            sectext += '\n\t' + _('Saved in: %s') % file_path
        dialog = dialogs.HigDialog(None, gtk.MESSAGE_INFO, gtk.BUTTONS_NONE,
                        _('File transfer completed'), sectext)
        if file_props.type_ == 'r':
            button = gtk.Button(_('_Open Containing Folder'))
            button.connect('clicked', on_open, file_props)
            dialog.action_area.pack_start(button)
        ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
        def on_ok(widget):
            dialog.destroy()
        ok_button.connect('clicked', on_ok)
        dialog.show_all()
示例#6
0
    def show_completed(self, jid, file_props):
        """
        Show a dialog saying that file (file_props) has been transferred
        """
        def on_open(widget, file_props):
            dialog.destroy()
            if not file_props.file_name:
                return
            path = os.path.split(file_props.file_name)[0]
            if os.path.exists(path) and os.path.isdir(path):
                helpers.launch_file_manager(path)
            self.tree.get_selection().unselect_all()

        if file_props.type_ == 'r':
            # file path is used below in 'Save in'
            (file_path, file_name) = os.path.split(file_props.file_name)
        else:
            file_name = file_props.name
        sectext = '\t' + _('Filename: %s') % GLib.markup_escape_text(file_name)
        sectext += '\n\t' + _('Size: %s') % \
        helpers.convert_bytes(file_props.size)
        if file_props.type_ == 'r':
            jid = file_props.sender.split('/')[0]
            sender_name = gajim.contacts.get_first_contact_from_jid(
                    file_props.tt_account, jid).get_shown_name()
            sender = sender_name
        else:
            #You is a reply of who sent a file
            sender = _('You')
        sectext += '\n\t' + _('Sender: %s') % sender
        sectext += '\n\t' + _('Recipient: ')
        if file_props.type_ == 's':
            jid = file_props.receiver.split('/')[0]
            receiver_name = gajim.contacts.get_first_contact_from_jid(
                    file_props.tt_account, jid).get_shown_name()
            recipient = receiver_name
        else:
            #You is a reply of who received a file
            recipient = _('You')
        sectext += recipient
        if file_props.type_ == 'r':
            sectext += '\n\t' + _('Saved in: %s') % file_path
        dialog = dialogs.HigDialog(None, Gtk.MessageType.INFO, Gtk.ButtonsType.NONE,
                        _('File transfer completed'), sectext)
        if file_props.type_ == 'r':
            button = Gtk.Button(_('_Open Containing Folder'))
            button.connect('clicked', on_open, file_props)
            dialog.action_area.pack_start(button, True, True, 0)
        ok_button = dialog.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK)
        def on_ok(widget):
            dialog.destroy()
        ok_button.connect('clicked', on_ok)
        dialog.show_all()
示例#7
0
	def show_completed(self, jid, file_props):
		''' show a dialog saying that file (file_props) has been transferred'''
		def on_open(widget, file_props):
			dialog.destroy()
			if 'file-name' not in file_props:
				return
			(path, file) = os.path.split(file_props['file-name'])
			if os.path.exists(path) and os.path.isdir(path):
				helpers.launch_file_manager(path)
			self.tree.get_selection().unselect_all()

		if file_props['type'] == 'r':
			# file path is used below in 'Save in'
			(file_path, file_name) = os.path.split(file_props['file-name'])
		else:
			file_name = file_props['name']
		sectext = '\t' + _('Filename: %s') % file_name
		sectext += '\n\t' + _('Size: %s') % \
		helpers.convert_bytes(file_props['size'])
		if file_props['type'] == 'r':
			jid = unicode(file_props['sender']).split('/')[0]
			sender_name = gajim.contacts.get_first_contact_from_jid( 
				file_props['tt_account'], jid).get_shown_name()
			sender = sender_name
		else:
			#You is a reply of who sent a file
			sender = _('You')
		sectext += '\n\t' +_('Sender: %s') % sender
		sectext += '\n\t' +_('Recipient: ')
		if file_props['type'] == 's':
			jid = unicode(file_props['receiver']).split('/')[0]
			receiver_name = gajim.contacts.get_first_contact_from_jid( 
				file_props['tt_account'], jid).get_shown_name()
			recipient = receiver_name
		else:
			#You is a reply of who received a file
			recipient = _('You')
		sectext += recipient
		if file_props['type'] == 'r':
			sectext += '\n\t' +_('Saved in: %s') % file_path
		dialog = dialogs.HigDialog(None, gtk.MESSAGE_INFO, gtk.BUTTONS_NONE, 
				_('File transfer completed'), sectext)
		if file_props['type'] == 'r':
			button = gtk.Button(_('_Open Containing Folder'))
			button.connect('clicked', on_open, file_props)
			dialog.action_area.pack_start(button)
		ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
		def on_ok(widget):
			dialog.destroy()
		ok_button.connect('clicked', on_ok)
		dialog.show_all()
示例#8
0
	def show_completed(self, jid, file_props):
		''' show a dialog saying that file (file_props) has been transferred'''
		self.window.present()
		self.window.window.focus()
		if file_props['type'] == 'r':
			# file path is used below in 'Save in'
			(file_path, file_name) = os.path.split(file_props['file-name'])
		else:
			file_name = file_props['name']
		sectext = '\t' + _('Filename: %s') % \
			gtkgui_helpers.escape_for_pango_markup(file_name)
		sectext += '\n\t' + _('Size: %s') % \
		helpers.convert_bytes(file_props['size'])
		if file_props['type'] == 'r':
			jid = unicode(file_props['sender']).split('/')[0]
			sender_name = gajim.get_first_contact_instance_from_jid( 
				file_props['tt_account'], jid).name
			sender = gtkgui_helpers.escape_for_pango_markup(sender_name)
		else:
			#You is a reply of who sent a file
			sender = _('You')
		sectext += '\n\t' +_('Sender: %s') % sender
		sectext += '\n\t' +_('Recipient: ')
		if file_props['type'] == 's':
			jid = unicode(file_props['receiver']).split('/')[0]
			receiver_name = gajim.get_first_contact_instance_from_jid( 
				file_props['tt_account'], jid).name
			recipient = gtkgui_helpers.escape_for_pango_markup(receiver_name)
		else:
			#You is a reply of who received a file
			recipient = _('You')
		sectext += recipient
		if file_props['type'] == 'r':
			sectext += '\n\t' +_('Saved in: %s') % \
				gtkgui_helpers.escape_for_pango_markup(file_path)
		dialog = dialogs.HigDialog(None, gtk.MESSAGE_INFO, gtk.BUTTONS_NONE, 
				_('File transfer completed'), sectext)
		if file_props['type'] == 'r':
			dialog.add_buttons(_('_Open Containing Folder'), gtk.RESPONSE_ACCEPT)
		dialog.add_buttons(gtk.STOCK_OK, gtk.RESPONSE_OK)
		dialog.show_all()
		response = dialog.run()
		dialog.destroy()
		if response == gtk.RESPONSE_ACCEPT:
			if not file_props.has_key('file-name'):
				return
			(path, file) = os.path.split(file_props['file-name'])
			if os.path.exists(path) and os.path.isdir(path):
				helpers.launch_file_manager(path)
			self.tree.get_selection().unselect_all()
示例#9
0
 def set_status(self,file_props, status):
     """
     Change the status of a transfer to state 'status'
     """
     iter_ = self.get_iter_by_sid(file_props.type_, file_props.sid)
     if iter_ is None:
         return
     self.model[iter_][C_SID]
     if status == 'stop':
         file_props.stopped = True
     elif status == 'ok':
         file_props.completed = True
         text = self._format_percent(100)
         received_size = int(file_props.received_len)
         full_size = file_props.size
         text += helpers.convert_bytes(received_size) + '/' + \
             helpers.convert_bytes(full_size)
         self.model.set(iter_, C_PROGRESS, text)
         self.model.set(iter_, C_PULSE, GLib.MAXINT32)
     elif status == 'computing':
         self.model.set(iter_, C_PULSE, 1)
         text = _('Checking file...') + '\n'
         received_size = int(file_props.received_len)
         full_size = file_props.size
         text += helpers.convert_bytes(received_size) + '/' + \
             helpers.convert_bytes(full_size)
         self.model.set(iter_, C_PROGRESS, text)
         def pulse():
             p = self.model.get(iter_, C_PULSE)[0]
             if p == GLib.MAXINT32:
                 return False
             self.model.set(iter_, C_PULSE, p + 1)
             return True
         GLib.timeout_add(100, pulse)
     elif status == 'hash_error':
         text = _('File error') + '\n'
         received_size = int(file_props.received_len)
         full_size = file_props.size
         text += helpers.convert_bytes(received_size) + '/' + \
             helpers.convert_bytes(full_size)
         self.model.set(iter_, C_PROGRESS, text)
         self.model.set(iter_, C_PULSE, GLib.MAXINT32)
     self.model.set(iter_, C_IMAGE, self.get_icon(status))
     path = self.model.get_path(iter_)
     self.select_func(path)
示例#10
0
 def set_status(self,file_props, status):
     """
     Change the status of a transfer to state 'status'
     """
     iter_ = self.get_iter_by_sid(file_props.type_, file_props.sid)
     if iter_ is None:
         return
     self.model[iter_][Column.SID]
     if status == 'stop':
         file_props.stopped = True
     elif status == 'ok':
         file_props.completed = True
         text = self._format_percent(100)
         received_size = int(file_props.received_len)
         full_size = file_props.size
         text += helpers.convert_bytes(received_size) + '/' + \
             helpers.convert_bytes(full_size)
         self.model.set(iter_, Column.PROGRESS, text)
         self.model.set(iter_, Column.PULSE, GLib.MAXINT32)
     elif status == 'computing':
         self.model.set(iter_, Column.PULSE, 1)
         text = _('Checking file…') + '\n'
         received_size = int(file_props.received_len)
         full_size = file_props.size
         text += helpers.convert_bytes(received_size) + '/' + \
             helpers.convert_bytes(full_size)
         self.model.set(iter_, Column.PROGRESS, text)
         def pulse():
             p = self.model.get(iter_, Column.PULSE)[0]
             if p == GLib.MAXINT32:
                 return False
             self.model.set(iter_, Column.PULSE, p + 1)
             return True
         GLib.timeout_add(100, pulse)
     elif status == 'hash_error':
         text = _('File error') + '\n'
         received_size = int(file_props.received_len)
         full_size = file_props.size
         text += helpers.convert_bytes(received_size) + '/' + \
             helpers.convert_bytes(full_size)
         self.model.set(iter_, Column.PROGRESS, text)
         self.model.set(iter_, Column.PULSE, GLib.MAXINT32)
     self.model.set(iter_, Column.IMAGE, self.get_icon(status))
     path = self.model.get_path(iter_)
     self.select_func(path)
示例#11
0
	def populate(self, file_props):
		ft_table = gtk.Table(2, 1)
		ft_table.set_property('column-spacing', 2)
		current_row = 1
		self.create_window()
		properties = []
		name = file_props['name']
		if file_props['type'] == 'r':
			(file_path, file_name) = os.path.split(file_props['file-name'])
		else:
			file_name = file_props['name']
		properties.append((_('Name: '), 
			gobject.markup_escape_text(file_name)))
		if file_props['type'] == 'r':
			type = _('Download')
			actor = _('Sender: ') 
			sender = unicode(file_props['sender']).split('/')[0]
			name = gajim.contacts.get_first_contact_from_jid( 
				file_props['tt_account'], sender).get_shown_name()
		else:
			type = _('Upload')
			actor = _('Recipient: ')
			receiver = file_props['receiver']
			if hasattr(receiver, 'name'):
				name = receiver.get_shown_name()
			else:
				name = receiver.split('/')[0]
		properties.append((_('Type: '), type))
		properties.append((actor, gobject.markup_escape_text(name)))
		
		transfered_len = file_props.get('received-len', 0)
		properties.append((_('Transferred: '), helpers.convert_bytes(transfered_len)))
		status = '' 
		if 'started' not in file_props or not file_props['started']:
			status = _('Not started')
		elif 'connected' in file_props:
			if 'stopped' in file_props and \
			file_props['stopped'] == True:
				status = _('Stopped')
			elif file_props['completed']:
				status = _('Completed')
			elif file_props['connected'] == False:
				if file_props['completed']:
					status = _('Completed')
			else:
				if 'paused' in file_props and \
				file_props['paused'] == True:
					status = _('?transfer status:Paused')
				elif 'stalled' in file_props and \
				file_props['stalled'] == True:
					#stalled is not paused. it is like 'frozen' it stopped alone
					status = _('Stalled')
				else:
					status = _('Transferring')
		else:
			status = _('Not started')
		properties.append((_('Status: '), status))
		if 'desc' in file_props:
			file_desc = file_props['desc']
			properties.append((_('Description: '), gobject.markup_escape_text(
				file_desc)))
		while properties:
			property = properties.pop(0)
			current_row += 1
			label = gtk.Label()
			label.set_alignment(0, 0)
			label.set_markup(property[0])
			ft_table.attach(label, 1, 2, current_row, current_row + 1, 
				gtk.FILL, gtk.FILL, 0, 0)
			label = gtk.Label()
			label.set_alignment(0, 0)
			label.set_line_wrap(True)
			label.set_markup(property[1])
			ft_table.attach(label, 2, 3, current_row, current_row + 1, 
				gtk.EXPAND | gtk.FILL, gtk.FILL, 0, 0)
		
		self.win.add(ft_table)
示例#12
0
    def set_progress(self, typ, sid, transfered_size, iter_=None):
        """
        Change the progress of a transfer with new transfered size
        """
        file_props = FilesProp.getFilePropByType(typ, sid)
        full_size = file_props.size
        if full_size == 0:
            percent = 0
        else:
            percent = round(float(transfered_size) / full_size * 100, 1)
        if iter_ is None:
            iter_ = self.get_iter_by_sid(typ, sid)
        if iter_ is not None:
            just_began = False
            if self.model[iter_][Column.PERCENT] == 0 and int(percent > 0):
                just_began = True
            text = self._format_percent(percent)
            if transfered_size == 0:
                text += '0'
            else:
                text += helpers.convert_bytes(transfered_size)
            text += '/' + helpers.convert_bytes(full_size)
            # Kb/s

            # remaining time
            if file_props.offset:
                transfered_size -= file_props.offset
                full_size -= file_props.offset

            if file_props.elapsed_time > 0:
                file_props.transfered_size.append((file_props.last_time, transfered_size))
            if len(file_props.transfered_size) > 6:
                file_props.transfered_size.pop(0)
            eta, speed = self._get_eta_and_speed(full_size, transfered_size,
                    file_props)

            self.model.set(iter_, Column.PROGRESS, text)
            self.model.set(iter_, Column.PERCENT, int(percent))
            text = self._format_time(eta)
            text += '\n'
            #This should make the string Kb/s,
            #where 'Kb' part is taken from %s.
            #Only the 's' after / (which means second) should be translated.
            text += _('(%(filesize_unit)s/s)') % {'filesize_unit':
                    helpers.convert_bytes(speed)}
            self.model.set(iter_, Column.TIME, text)

            # try to guess what should be the status image
            if file_props.type_ == 'r':
                status = 'download'
            else:
                status = 'upload'
            if file_props.paused == True:
                status = 'pause'
            elif file_props.stalled == True:
                status = 'waiting'
            if file_props.connected == False:
                status = 'stop'
            self.model.set(iter_, 0, self.get_icon(status))
            if transfered_size == full_size:
                # If we are receiver and this is a jingle session
                if file_props.type_ == 'r' and  \
                      file_props.session_type == 'jingle' and file_props.hash_:
                    # Show that we are computing the hash
                    self.set_status(file_props, 'computing')
                else:
                    self.set_status(file_props, 'ok')
            elif just_began:
                path = self.model.get_path(iter_)
                self.select_func(path)
示例#13
0
文件: tooltips.py 项目: gajim/gajim
    def populate(self, file_props):
        ft_table = Gtk.Table(2, 1)
        ft_table.set_property('column-spacing', 2)
        current_row = 1
        self.create_window()
        properties = []
        name = file_props.name
        if file_props.type_ == 'r':
            file_name = os.path.split(file_props.file_name)[1]
        else:
            file_name = file_props.name
        properties.append((_('Name: '), GLib.markup_escape_text(file_name)))
        if file_props.type_ == 'r':
            type_ = _('Download')
            actor = _('Sender: ')
            sender = file_props.sender.split('/')[0]
            name = gajim.contacts.get_first_contact_from_jid(
                    file_props.tt_account, sender).get_shown_name()
        else:
            type_ = _('Upload')
            actor = _('Recipient: ')
            receiver = file_props.receiver
            if hasattr(receiver, 'name'):
                name = receiver.get_shown_name()
            else:
                name = receiver.split('/')[0]
        properties.append((_('Type: '), type_))
        properties.append((actor, GLib.markup_escape_text(name)))

        transfered_len = file_props.received_len
        if not transfered_len:
            transfered_len = 0
        properties.append((_('Transferred: '), helpers.convert_bytes(transfered_len)))
        status = ''
        if file_props.started:
            status = _('Not started')
        if file_props.stopped == True:
            status = _('Stopped')
        elif file_props.completed:
            status = _('Completed')
        elif file_props.connected == False:
            if file_props.completed:
                status = _('Completed')
            else:
                if file_props.paused == True:
                    status = _('?transfer status:Paused')
                elif file_props.stalled == True:
                    #stalled is not paused. it is like 'frozen' it stopped alone
                    status = _('Stalled')
                else:
                    status = _('Transferring')
        else:
            status = _('Not started')
        properties.append((_('Status: '), status))
        file_desc = file_props.desc or ''
        properties.append((_('Description: '), GLib.markup_escape_text(
            file_desc)))
        while properties:
            property_ = properties.pop(0)
            current_row += 1
            label = Gtk.Label()
            label.set_halign(Gtk.Align.START)
            label.set_valign(Gtk.Align.START)
            label.set_markup(property_[0])
            ft_table.attach(label, 1, 2, current_row, current_row + 1,
                    Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL, 0, 0)
            label = Gtk.Label()
            label.set_halign(Gtk.Align.START)
            label.set_valign(Gtk.Align.START)
            label.set_line_wrap(True)
            label.set_markup(property_[1])
            ft_table.attach(label, 2, 3, current_row, current_row + 1,
                    Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL, 0, 0)

        self.win.add(ft_table)
示例#14
0
    def populate(self, file_props):
        ft_table = Gtk.Table(2, 1)
        ft_table.set_property('column-spacing', 2)
        current_row = 1
        self.create_window()
        properties = []
        name = file_props.name
        if file_props.type_ == 'r':
            file_name = os.path.split(file_props.file_name)[1]
        else:
            file_name = file_props.name
        properties.append((_('Name: '), GLib.markup_escape_text(file_name)))
        if file_props.type_ == 'r':
            type_ = _('Download')
            actor = _('Sender: ')
            sender = file_props.sender.split('/')[0]
            name = gajim.contacts.get_first_contact_from_jid(
                    file_props.tt_account, sender).get_shown_name()
        else:
            type_ = _('Upload')
            actor = _('Recipient: ')
            receiver = file_props.receiver
            if hasattr(receiver, 'name'):
                name = receiver.get_shown_name()
            else:
                name = receiver.split('/')[0]
        properties.append((_('Type: '), type_))
        properties.append((actor, GLib.markup_escape_text(name)))

        transfered_len = file_props.received_len
        if not transfered_len:
            transfered_len = 0
        properties.append((_('Transferred: '), helpers.convert_bytes(transfered_len)))
        status = ''
        if file_props.started:
            status = _('Not started')
        if file_props.stopped == True:
            status = _('Stopped')
        elif file_props.completed:
            status = _('Completed')
        elif file_props.connected == False:
            if file_props.completed:
                status = _('Completed')
            else:
                if file_props.paused == True:
                    status = _('?transfer status:Paused')
                elif file_props.stalled == True:
                    #stalled is not paused. it is like 'frozen' it stopped alone
                    status = _('Stalled')
                else:
                    status = _('Transferring')
        else:
            status = _('Not started')
        properties.append((_('Status: '), status))
        file_desc = file_props.desc or ''
        properties.append((_('Description: '), GLib.markup_escape_text(
            file_desc)))
        while properties:
            property_ = properties.pop(0)
            current_row += 1
            label = Gtk.Label()
            label.set_alignment(0, 0)
            label.set_markup(property_[0])
            ft_table.attach(label, 1, 2, current_row, current_row + 1,
                    Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL, 0, 0)
            label = Gtk.Label()
            label.set_alignment(0, 0)
            label.set_line_wrap(True)
            label.set_markup(property_[1])
            ft_table.attach(label, 2, 3, current_row, current_row + 1,
                    Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL, 0, 0)

        self.win.add(ft_table)
示例#15
0
	def show_file_request(self, account, contact, file_props):
		''' show dialog asking for comfirmation and store location of new
		file requested by a contact'''
		if file_props is None or 'name' not in file_props:
			return
		sec_text = '\t' + _('File: %s') % file_props['name']
		if 'size' in file_props:
			sec_text += '\n\t' + _('Size: %s') % \
				helpers.convert_bytes(file_props['size'])
		if 'mime-type' in file_props:
			sec_text += '\n\t' + _('Type: %s') % file_props['mime-type']
		if 'desc' in file_props:
			sec_text += '\n\t' + _('Description: %s') % file_props['desc']
		prim_text = _('%s wants to send you a file:') % contact.jid
		dialog, dialog2 = None, None

		def on_response_ok(account, contact, file_props):

			def on_ok(widget, account, contact, file_props):
				file_path = dialog2.get_filename()
				file_path = gtkgui_helpers.decode_filechooser_file_paths(
					(file_path,))[0]
				if os.path.exists(file_path):
					# check if we have write permissions
					if not os.access(file_path, os.W_OK):
						file_name = os.path.basename(file_path)
						dialogs.ErrorDialog(_('Cannot overwrite existing file "%s"' % file_name),
						_('A file with this name already exists and you do not have permission to overwrite it.'))
						return
					stat = os.stat(file_path)
					dl_size = stat.st_size
					file_size = file_props['size']
					dl_finished = dl_size >= file_size

					def on_response(response):
						if response < 0:
							return
						elif response == 100:
							file_props['offset'] = dl_size
						dialog2.destroy()
						self._start_receive(file_path, account, contact, file_props)

					dialog = dialogs.FTOverwriteConfirmationDialog(
						_('This file already exists'), _('What do you want to do?'),
						propose_resume=not dl_finished, on_response=on_response)
					dialog.set_transient_for(dialog2)
					dialog.set_destroy_with_parent(True)
					return
				else:
					dirname = os.path.dirname(file_path)
					if not os.access(dirname, os.W_OK) and os.name != 'nt':
						# read-only bit is used to mark special folder under windows,
						# not to mark that a folder is read-only. See ticket #3587
						dialogs.ErrorDialog(_('Directory "%s" is not writable') % dirname, _('You do not have permission to create files in this directory.'))
						return
				dialog2.destroy()
				self._start_receive(file_path, account, contact, file_props)

			def on_cancel(widget, account, contact, file_props):
				dialog2.destroy()
				gajim.connections[account].send_file_rejection(file_props)

			dialog2 = dialogs.FileChooserDialog(
				title_text = _('Save File as...'), 
				action = gtk.FILE_CHOOSER_ACTION_SAVE, 
				buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, 
				gtk.STOCK_SAVE, gtk.RESPONSE_OK),
				default_response = gtk.RESPONSE_OK,
				current_folder = gajim.config.get('last_save_dir'),
				on_response_ok = (on_ok, account, contact, file_props),
				on_response_cancel = (on_cancel, account, contact, file_props))

			dialog2.set_current_name(file_props['name'])
			dialog2.connect('delete-event', lambda widget, event:
				on_cancel(widget, account, contact, file_props))

		def on_response_cancel(account, file_props):
			gajim.connections[account].send_file_rejection(file_props)

		dialog = dialogs.NonModalConfirmationDialog(prim_text, sec_text,
			on_response_ok = (on_response_ok, account, contact, file_props),
			on_response_cancel = (on_response_cancel, account, file_props))
		dialog.connect('delete-event', lambda widget, event: 
			on_response_cancel(widget, account, file_props))
		dialog.popup()
示例#16
0
	def set_progress(self, typ, sid, transfered_size, iter_ = None):
		''' change the progress of a transfer with new transfered size'''
		if sid not in self.files_props[typ]:
			return
		file_props = self.files_props[typ][sid]
		full_size = int(file_props['size'])
		if full_size == 0:
			percent = 0
		else:
			percent = round(float(transfered_size) / full_size * 100, 1)
		if iter_ is None:
			iter_ = self.get_iter_by_sid(typ, sid)
		if iter_ is not None:
			just_began = False
			if self.model[iter_][C_PERCENT] == 0 and int(percent > 0):
				just_began = True
			text = self._format_percent(percent)
			if transfered_size == 0:
				text += '0'
			else:
				text += helpers.convert_bytes(transfered_size)
			text += '/' + helpers.convert_bytes(full_size)
			# Kb/s

			# remaining time
			if 'offset' in file_props and file_props['offset']:
				transfered_size -= file_props['offset'] 
				full_size -= file_props['offset']

			if file_props['elapsed-time'] > 0:
				file_props['transfered_size'].append((file_props['last-time'], transfered_size))
			if len(file_props['transfered_size']) > 6:
				file_props['transfered_size'].pop(0)
			eta, speed = self._get_eta_and_speed(full_size, transfered_size, 
				file_props)

			self.model.set(iter_, C_PROGRESS, text)
			self.model.set(iter_, C_PERCENT, int(percent))
			text = self._format_time(eta)
			text += '\n'
			#This should make the string Kb/s, 
			#where 'Kb' part is taken from %s.
			#Only the 's' after / (which means second) should be translated.
			text += _('(%(filesize_unit)s/s)') % {'filesize_unit':
				helpers.convert_bytes(speed)}
			self.model.set(iter_, C_TIME, text)

			# try to guess what should be the status image
			if file_props['type'] == 'r':
				status = 'download'
			else:
				status = 'upload'
			if 'paused' in file_props and file_props['paused'] == True:
				status = 'pause'
			elif 'stalled' in file_props and file_props['stalled'] == True:
				status = 'waiting'
			if 'connected' in file_props and file_props['connected'] == False:
				status = 'stop'
			self.model.set(iter_, 0, self.images[status])
			if transfered_size == full_size:
				self.set_status(typ, sid, 'ok')
			elif just_began:
				path = self.model.get_path(iter_)
				self.select_func(path)
示例#17
0
    def populate(self, file_props):
        ft_table = gtk.Table(2, 1)
        ft_table.set_property('column-spacing', 2)
        current_row = 1
        self.create_window()
        properties = []
        name = file_props['name']
        if file_props['type'] == 'r':
            (file_path, file_name) = os.path.split(file_props['file-name'])
        else:
            file_name = file_props['name']
        properties.append((_('Name: '), gobject.markup_escape_text(file_name)))
        if file_props['type'] == 'r':
            type = _('Download')
            actor = _('Sender: ')
            sender = unicode(file_props['sender']).split('/')[0]
            name = gajim.contacts.get_first_contact_from_jid(
                file_props['tt_account'], sender).get_shown_name()
        else:
            type = _('Upload')
            actor = _('Recipient: ')
            receiver = file_props['receiver']
            if hasattr(receiver, 'name'):
                name = receiver.get_shown_name()
            else:
                name = receiver.split('/')[0]
        properties.append((_('Type: '), type))
        properties.append((actor, gobject.markup_escape_text(name)))

        transfered_len = file_props.get('received-len', 0)
        properties.append(
            (_('Transferred: '), helpers.convert_bytes(transfered_len)))
        status = ''
        if 'started' not in file_props or not file_props['started']:
            status = _('Not started')
        elif 'connected' in file_props:
            if 'stopped' in file_props and \
            file_props['stopped'] == True:
                status = _('Stopped')
            elif file_props['completed']:
                status = _('Completed')
            elif file_props['connected'] == False:
                if file_props['completed']:
                    status = _('Completed')
            else:
                if 'paused' in file_props and \
                file_props['paused'] == True:
                    status = _('?transfer status:Paused')
                elif 'stalled' in file_props and \
                file_props['stalled'] == True:
                    #stalled is not paused. it is like 'frozen' it stopped alone
                    status = _('Stalled')
                else:
                    status = _('Transferring')
        else:
            status = _('Not started')
        properties.append((_('Status: '), status))
        if 'desc' in file_props:
            file_desc = file_props['desc']
            properties.append(
                (_('Description: '), gobject.markup_escape_text(file_desc)))
        while properties:
            property = properties.pop(0)
            current_row += 1
            label = gtk.Label()
            label.set_alignment(0, 0)
            label.set_markup(property[0])
            ft_table.attach(label, 1, 2, current_row, current_row + 1,
                            gtk.FILL, gtk.FILL, 0, 0)
            label = gtk.Label()
            label.set_alignment(0, 0)
            label.set_line_wrap(True)
            label.set_markup(property[1])
            ft_table.attach(label, 2, 3, current_row, current_row + 1,
                            gtk.EXPAND | gtk.FILL, gtk.FILL, 0, 0)

        self.win.add(ft_table)
示例#18
0
    def set_progress(self, typ, sid, transfered_size, iter_=None):
        """
        Change the progress of a transfer with new transfered size
        """
        file_props = FilesProp.getFilePropByType(typ, sid)
        full_size = file_props.size
        if full_size == 0:
            percent = 0
        else:
            percent = round(float(transfered_size) / full_size * 100, 1)
        if iter_ is None:
            iter_ = self.get_iter_by_sid(typ, sid)
        if iter_ is not None:
            just_began = False
            if self.model[iter_][C_PERCENT] == 0 and int(percent > 0):
                just_began = True
            text = self._format_percent(percent)
            if transfered_size == 0:
                text += '0'
            else:
                text += helpers.convert_bytes(transfered_size)
            text += '/' + helpers.convert_bytes(full_size)
            # Kb/s

            # remaining time
            if file_props.offset:
                transfered_size -= file_props.offset
                full_size -= file_props.offset

            if file_props.elapsed_time > 0:
                file_props.transfered_size.append((file_props.last_time, transfered_size))
            if len(file_props.transfered_size) > 6:
                file_props.transfered_size.pop(0)
            eta, speed = self._get_eta_and_speed(full_size, transfered_size,
                    file_props)

            self.model.set(iter_, C_PROGRESS, text)
            self.model.set(iter_, C_PERCENT, int(percent))
            text = self._format_time(eta)
            text += '\n'
            #This should make the string Kb/s,
            #where 'Kb' part is taken from %s.
            #Only the 's' after / (which means second) should be translated.
            text += _('(%(filesize_unit)s/s)') % {'filesize_unit':
                    helpers.convert_bytes(speed)}
            self.model.set(iter_, C_TIME, text)

            # try to guess what should be the status image
            if file_props.type_ == 'r':
                status = 'download'
            else:
                status = 'upload'
            if file_props.paused == True:
                status = 'pause'
            elif file_props.stalled == True:
                status = 'waiting'
            if file_props.connected == False:
                status = 'stop'
            self.model.set(iter_, 0, self.get_icon(status))
            if transfered_size == full_size:
                # If we are receiver and this is a jingle session
                if file_props.type_ == 'r' and  \
                      file_props.session_type == 'jingle' and file_props.hash_:
                    # Show that we are computing the hash
                    self.set_status(file_props, 'computing')
                else:
                    self.set_status(file_props, 'ok')
            elif just_began:
                path = self.model.get_path(iter_)
                self.select_func(path)
示例#19
0
    def populate(self, file_props):
        self.create_window()
        self.hbox = gtk.HBox()
        text = "<b>" + _("Name: ") + "</b>"
        name = file_props["name"]
        if file_props["type"] == "r":
            (file_path, file_name) = os.path.split(file_props["file-name"])
        else:
            file_name = file_props["name"]
        text += gtkgui_helpers.escape_for_pango_markup(file_name)
        text += "\n<b>" + _("Type: ") + "</b>"
        if file_props["type"] == "r":
            text += _("Download")
        else:
            text += _("Upload")
        if file_props["type"] == "r":
            text += "\n<b>" + _("Sender: ") + "</b>"
            sender = unicode(file_props["sender"]).split("/")[0]
            name = gajim.get_first_contact_instance_from_jid(file_props["tt_account"], sender).name
        else:
            text += "\n<b>" + _("Recipient: ") + "</b>"
            receiver = file_props["receiver"]
            if hasattr(receiver, "name"):
                receiver = receiver.name
            receiver = receiver.split("/")[0]
            if receiver.find("@") == -1:
                name = receiver
            else:
                name = gajim.get_first_contact_instance_from_jid(file_props["tt_account"], receiver).name
        text += gtkgui_helpers.escape_for_pango_markup(name)
        text += "\n<b>" + _("Size: ") + "</b>"
        text += helpers.convert_bytes(file_props["size"])
        text += "\n<b>" + _("Transferred: ") + "</b>"
        transfered_len = 0
        if file_props.has_key("received-len"):
            transfered_len = file_props["received-len"]
        text += helpers.convert_bytes(transfered_len)
        text += "\n<b>" + _("Status: ") + "</b>"
        status = ""
        if not file_props.has_key("started") or not file_props["started"]:
            status = _("Not started")
        elif file_props.has_key("connected"):
            if file_props.has_key("stopped") and file_props["stopped"] == True:
                status = _("Stopped")
            elif file_props["completed"]:
                status = _("Completed")
            elif file_props["connected"] == False:
                if file_props["completed"]:
                    status = _("Completed")
            else:
                if file_props.has_key("paused") and file_props["paused"] == True:
                    status = _("Paused")
                elif file_props.has_key("stalled") and file_props["stalled"] == True:
                    # stalled is not paused. it is like 'frozen' it stopped alone
                    status = _("Stalled")
                else:
                    status = _("Transferring")
        else:
            status = _("Not started")

        text += status
        self.text_label.set_markup(text)
        self.hbox.add(self.text_label)
        self.win.add(self.hbox)