Esempio n. 1
0
    def got_metadata(self, path, data):
        """Activate the information elements and hide the spinner."""
        # stop and hide the spinner
        self.spinner.stop()
        self.spinner.hide()

        # title with crude path
        self.dialog.set_title("Metadata for %s" % (path,))

        # the icon is taken from crude path, no matter if synched or not
        if os.path.isdir(path):
            icon = Gtk.STOCK_DIRECTORY
        else:
            icon = Gtk.STOCK_FILE
        self.filetype_image.set_from_stock(icon, Gtk.IconSize.MENU)

        # set the data in the elements
        if data == NOT_SYNCHED_PATH:
            # metadata path doesn't exist for syncdaemon, show crude path,
            # error message, and quit
            self.path_label.set_text(path)
            self.filepath_hbox.show()
            self.basic_info_label.set_text(NOT_SYNCHED_PATH)
            self.basic_info_label.show()
            return

        # show the nice path
        self.path_label.set_text(data['path'])
        self.filepath_hbox.show()

        # prepare simple text
        simple = []
        stat = data['stat']
        if stat is not None:
            size = stat['st_size']
            try:
                size = humanize_bytes(size)
            except (ValueError, TypeError):
                logger.exception('Error while humanizing bytes')
            simple.append("Size: %s" % (size,))
            tstamp = stat['st_mtime']
            simple.append("Modified on %s" % (time.ctime(tstamp),))

        # set state message and image
        state, stock = self.changed_message.get(data['changed'],
                                                ('Unknown state', None))
        simple.append(state)
        simple_text = "\n".join(simple)
        if stock is None:
            self.state_image.hide()
        else:
            self.state_image.set_from_stock(stock, Gtk.IconSize.LARGE_TOOLBAR)
        self.state_hbox.show()

        # prepare detailed text
        raw = data['raw_result']
        detailed_text = '\n'.join('%s: %s' % i for i in raw.iteritems())

        # fill and show
        self.basic_info_label.set_text(simple_text)
        self.basic_info_label.show()
        self.detailed_info_textview.get_buffer().set_text(detailed_text)
        self.details_expander.show()