Example #1
0
    def add_separator(self, timestamp):
        """Add whitespace and timestamp between chat sessions."""
        time_with_current_year = (time.localtime(time.time())[0],) +\
                time.strptime(timestamp, "%b %d %H:%M:%S")[1:]

        timestamp_seconds = time.mktime(time_with_current_year)
        if timestamp_seconds > time.time():
            time_with_previous_year = (time.localtime(time.time())[0] - 1,) +\
                    time.strptime(timestamp, "%b %d %H:%M:%S")[1:]
            timestamp_seconds = time.mktime(time_with_previous_year)

        message = ColorLabel(
            text=timestamp_to_elapsed_string(timestamp_seconds),
            color=style.COLOR_BUTTON_GREY)

        box = gtk.HBox()
        box.show()
        align = gtk.Alignment(xalign=0.5, yalign=0.0, xscale=0.0, yscale=0.0)
        box.pack_start(align, True, True)
        align.add(message)
        box.show_all()
        self._conversation.pack_start(box, False, False)
        self.add_log_timestamp(timestamp)

        self._last_msg_sender = None
Example #2
0
    def _add_activity(self, activity_info):
        if activity_info.get_bundle_id() == 'org.laptop.JournalActivity':
            return

        timestamp = activity_info.get_installation_time()
        version = activity_info.get_activity_version()

        registry = bundleregistry.get_registry()
        favorite = registry.is_bundle_favorite(activity_info.get_bundle_id(),
                                               version)

        tag_list = activity_info.get_tags()
        if tag_list is None or not tag_list:
            title = '<b>%s</b>' % activity_info.get_name()
        else:
            tags = ', '.join(tag_list)
            title = '<b>%s</b>\n' \
                    '<span style="italic" weight="light">%s</span>' % \
                            (activity_info.get_name(), tags)

        self._model.append([
            activity_info.get_bundle_id(), favorite,
            activity_info.get_icon(), title, version,
            _('Version %s') % version, timestamp,
            util.timestamp_to_elapsed_string(timestamp)
        ])
    def _add_activity(self, activity_info):
        if activity_info.get_bundle_id() == 'org.laptop.JournalActivity':
            return

        timestamp = activity_info.get_installation_time()
        version = activity_info.get_activity_version()

        registry = bundleregistry.get_registry()
        favorite = registry.is_bundle_favorite(activity_info.get_bundle_id(),
                                               version)

        tag_list = activity_info.get_tags()
        if tag_list is None or not tag_list:
            title = '<b>%s</b>' % activity_info.get_name()
        else:
            tags = ', '.join(tag_list)
            title = '<b>%s</b>\n' \
                    '<span style="italic" weight="light">%s</span>' % \
                            (activity_info.get_name(), tags)

        self._model.append([activity_info.get_bundle_id(),
                            favorite,
                            activity_info.get_icon(),
                            title,
                            version,
                            _('Version %s') % version,
                            timestamp,
                            util.timestamp_to_elapsed_string(timestamp)])
Example #4
0
    def add_separator(self, timestamp):
        """Add whitespace and timestamp between chat sessions."""
        time_with_current_year = (time.localtime(time.time())[0],) +\
                time.strptime(timestamp, "%b %d %H:%M:%S")[1:]

        timestamp_seconds = time.mktime(time_with_current_year)
        if timestamp_seconds > time.time():
            time_with_previous_year = (time.localtime(time.time())[0] - 1,) +\
                    time.strptime(timestamp, "%b %d %H:%M:%S")[1:]
            timestamp_seconds = time.mktime(time_with_previous_year)

        message = ColorLabel(
            text=timestamp_to_elapsed_string(timestamp_seconds),
            color=style.COLOR_BUTTON_GREY)

        box = gtk.HBox()
        box.show()
        align = gtk.Alignment(xalign=0.5, yalign=0.0, xscale=0.0, yscale=0.0)
        box.pack_start(align, True, True)
        align.add(message)
        box.show_all()
        self._conversation.pack_start(box, False, False)
        self.add_log_timestamp(timestamp)

        self._last_msg_sender = None
Example #5
0
    def add_separator(self, timestamp):
        '''Add whitespace and timestamp between chat sessions.'''
        time_with_current_year = \
            (time.localtime(time.time())[0], ) + \
            time.strptime(timestamp, '%b %d %H:%M:%S')[1:]

        timestamp_seconds = time.mktime(time_with_current_year)
        if timestamp_seconds > time.time():
            time_with_previous_year = \
                (time.localtime(time.time())[0] - 1, ) + \
                time.strptime(timestamp, '%b %d %H:%M:%S')[1:]
            timestamp_seconds = time.mktime(time_with_previous_year)

        message = TextBox(self,
                          style.COLOR_BUTTON_GREY, style.COLOR_BUTTON_GREY,
                          style.COLOR_WHITE, style.COLOR_BUTTON_GREY, False,
                          None, timestamp_to_elapsed_string(timestamp_seconds))
        self._message_list.append(message)
        box = gtk.HBox()
        align = gtk.Alignment(0.5, 0.0, 0.0, 0.0)
        box.pack_start(align, True, True, 0)
        align.show()
        align.add(message)
        message.show()
        self._conversation.pack_start(box)
        box.show()
        self._row_counter += 1
        self.add_log_timestamp(timestamp)
        self._last_msg_sender = None
Example #6
0
    def on_calc_value(self, row, column):
        if column == FIELD_ICON:
            return port.pixbuf.sugar_icon(
                file_name=port.shell.get_icon_filename(
                    activity=row[FIELD_ACTIVITY] or row[FIELD_BUNDLE_ID],
                    mime_type=row[FIELD_MIME_TYPE]),
                width=model.ICON_SIZE,
                height=model.ICON_SIZE,
                color=XoColor(row[FIELD_ICON_COLOR]))

        elif column == FIELD_MODIFY_TIME:
            if row[FIELD_TIMESTAMP]:
                timestamp = float(row[FIELD_TIMESTAMP])
                return util.timestamp_to_elapsed_string(timestamp)
            elif row[FIELD_MTIME]:
                ti = time.strptime(row[FIELD_MTIME], '%Y-%m-%dT%H:%M:%S')
                return util.timestamp_to_elapsed_string(time.mktime(ti))
            else:
                return _('No date')

        elif column >= FIELD_BUDDY_FIRST \
                and column < FIELD_BUDDY_FIRST + VISIBLE_BUDDIES_COUNT:
            buddies = row[FIELD_BUDDIES] or []
            if not buddies:
                return None
            buddy_num = column - FIELD_BUDDY_FIRST
            if buddy_num >= len(buddies):
                return None
            return port.pixbuf.sugar_icon(icon_name='computer-xo',
                                          width=model.ICON_SIZE,
                                          height=model.ICON_SIZE,
                                          color=XoColor(buddies[buddy_num][2]))

        elif column == FIELD_THUMB:
            self.fetch_metadata(row)
            return model.THUMB_STUB

        elif column == FIELD_PREVIEW:
            self.fetch_metadata(row)
            return model.PREVIEW_STUB

        elif column == FIELD_BUDDY_MENU:
            return ObjectMenu(row, row[FIELD_ICON])

        return None
Example #7
0
def get_date(metadata):
    """ Convert from a string in iso format to a more human-like format. """
    if 'timestamp' in metadata:
        try:
            timestamp = float(metadata['timestamp'])
        except (TypeError, ValueError):
            logging.warning('Invalid timestamp: %r', metadata['timestamp'])
        else:
            return util.timestamp_to_elapsed_string(timestamp)

    if 'mtime' in metadata:
        try:
            ti = time.strptime(metadata['mtime'], '%Y-%m-%dT%H:%M:%S')
        except (TypeError, ValueError):
            logging.warning('Invalid mtime: %r', metadata['mtime'])
        else:
            return util.timestamp_to_elapsed_string(time.mktime(ti))

    return _('No date')
Example #8
0
    def on_get_value(self, index, column):
        if self.view_is_resizing:
            return None

        if index == self._last_requested_index:
            return self._cached_row[column]

        if index >= self._result_set.length:
            return None

        self._result_set.seek(index)
        metadata = self._result_set.read()

        self._last_requested_index = index
        self._cached_row = []
        self._cached_row.append(metadata['uid'])
        self._cached_row.append(metadata.get('keep', '0') == '1')
        self._cached_row.append(misc.get_icon_name(metadata))

        if misc.is_activity_bundle(metadata):
            xo_color = XoColor('%s,%s' % (style.COLOR_BUTTON_GREY.get_svg(),
                                          style.COLOR_TRANSPARENT.get_svg()))
        else:
            xo_color = misc.get_icon_color(metadata)
        self._cached_row.append(xo_color)

        title = gobject.markup_escape_text(metadata.get('title',
                                           _('Untitled')))
        self._cached_row.append('<b>%s</b>' % (title, ))

        try:
            timestamp = float(metadata.get('timestamp', 0))
        except (TypeError, ValueError):
            timestamp_content = _('Unknown')
        else:
            timestamp_content = util.timestamp_to_elapsed_string(timestamp)
        self._cached_row.append(timestamp_content)

        try:
            creation_time = float(metadata.get('creation_time'))
        except (TypeError, ValueError):
            self._cached_row.append(_('Unknown'))
        else:
            self._cached_row.append(
                util.timestamp_to_elapsed_string(float(creation_time)))

        try:
            size = int(metadata.get('filesize'))
        except (TypeError, ValueError):
            size = None
        self._cached_row.append(util.format_size(size))

        try:
            progress = int(float(metadata.get('progress', 100)))
        except (TypeError, ValueError):
            progress = 100
        self._cached_row.append(progress)

        buddies = []
        if metadata.get('buddies'):
            try:
                buddies = simplejson.loads(metadata['buddies']).values()
            except simplejson.decoder.JSONDecodeError, exception:
                logging.warning('Cannot decode buddies for %r: %s',
                                metadata['uid'], exception)
Example #9
0
    def _add_columns(self):
        cell_favorite = CellRendererFavorite(self.tree_view)
        cell_favorite.connect('clicked', self.__favorite_clicked_cb)

        column = gtk.TreeViewColumn()
        column.props.sizing = gtk.TREE_VIEW_COLUMN_FIXED
        column.props.fixed_width = cell_favorite.props.width
        column.pack_start(cell_favorite)
        column.set_cell_data_func(cell_favorite, self.__favorite_set_data_cb)
        self.tree_view.append_column(column)

        self.cell_icon = CellRendererActivityIcon(self.tree_view)

        column = gtk.TreeViewColumn()
        column.props.sizing = gtk.TREE_VIEW_COLUMN_FIXED
        column.props.fixed_width = self.cell_icon.props.width
        column.pack_start(self.cell_icon)
        column.add_attribute(self.cell_icon, 'file-name',
                             ListModel.COLUMN_ICON)
        column.add_attribute(self.cell_icon, 'xo-color',
                             ListModel.COLUMN_ICON_COLOR)
        self.tree_view.append_column(column)

        self.cell_title = gtk.CellRendererText()
        self.cell_title.props.ellipsize = pango.ELLIPSIZE_MIDDLE
        self.cell_title.props.ellipsize_set = True

        self._title_column = gtk.TreeViewColumn()
        self._title_column.props.sizing = gtk.TREE_VIEW_COLUMN_FIXED
        self._title_column.props.expand = True
        self._title_column.props.clickable = True
        self._title_column.pack_start(self.cell_title)
        self._title_column.add_attribute(self.cell_title, 'markup',
                                         ListModel.COLUMN_TITLE)
        self.tree_view.append_column(self._title_column)

        buddies_column = gtk.TreeViewColumn()
        buddies_column.props.sizing = gtk.TREE_VIEW_COLUMN_FIXED
        self.tree_view.append_column(buddies_column)

        for column_index in [ListModel.COLUMN_BUDDY_1,
                             ListModel.COLUMN_BUDDY_2,
                             ListModel.COLUMN_BUDDY_3]:
            cell_icon = CellRendererBuddy(self.tree_view,
                                          column_index=column_index)
            buddies_column.pack_start(cell_icon)
            buddies_column.props.fixed_width += cell_icon.props.width
            buddies_column.add_attribute(cell_icon, 'buddy', column_index)
            buddies_column.set_cell_data_func(cell_icon,
                    self.__buddies_set_data_cb)

        cell_progress = gtk.CellRendererProgress()
        cell_progress.props.ypad = style.GRID_CELL_SIZE / 4
        buddies_column.pack_start(cell_progress)
        buddies_column.add_attribute(cell_progress, 'value',
                ListModel.COLUMN_PROGRESS)
        buddies_column.set_cell_data_func(cell_progress,
                self.__progress_data_cb)

        cell_text = gtk.CellRendererText()
        cell_text.props.xalign = 1

        # Measure the required width for a date in the form of "10 hours, 10
        # minutes ago"
        timestamp = time.time() - 10 * 60 - 10 * 60 * 60
        date = util.timestamp_to_elapsed_string(timestamp)
        date_width = self._get_width_for_string(date)

        self.sort_column = gtk.TreeViewColumn()
        self.sort_column.props.sizing = gtk.TREE_VIEW_COLUMN_FIXED
        self.sort_column.props.fixed_width = date_width
        self.sort_column.set_alignment(1)
        self.sort_column.props.resizable = True
        self.sort_column.props.clickable = True
        self.sort_column.pack_start(cell_text)
        self.sort_column.add_attribute(cell_text, 'text',
                                       ListModel.COLUMN_TIMESTAMP)
        self.tree_view.append_column(self.sort_column)
Example #10
0
    def on_get_value(self, index, column):
        if self.view_is_resizing:
            return None

        if index == self._last_requested_index:
            return self._cached_row[column]

        if index >= self._result_set.length:
            return None

        self._result_set.seek(index)
        metadata = self._result_set.read()

        self._last_requested_index = index
        self._cached_row = []
        self._cached_row.append(metadata['uid'])
        self._cached_row.append(metadata.get('keep', '0') == '1')
        self._cached_row.append(misc.get_icon_name(metadata))

        if misc.is_activity_bundle(metadata):
            xo_color = XoColor('%s,%s' % (style.COLOR_BUTTON_GREY.get_svg(),
                                          style.COLOR_TRANSPARENT.get_svg()))
        else:
            xo_color = misc.get_icon_color(metadata)
        self._cached_row.append(xo_color)

        title = gobject.markup_escape_text(metadata.get(
            'title', _('Untitled')))
        self._cached_row.append('<b>%s</b>' % (title, ))

        try:
            timestamp = float(metadata.get('timestamp', 0))
        except (TypeError, ValueError):
            timestamp_content = _('Unknown')
        else:
            timestamp_content = util.timestamp_to_elapsed_string(timestamp)
        self._cached_row.append(timestamp_content)

        try:
            creation_time = float(metadata.get('creation_time'))
        except (TypeError, ValueError):
            self._cached_row.append(_('Unknown'))
        else:
            self._cached_row.append(
                util.timestamp_to_elapsed_string(float(creation_time)))

        try:
            size = int(metadata.get('filesize'))
        except (TypeError, ValueError):
            size = None
        self._cached_row.append(util.format_size(size))

        try:
            progress = int(float(metadata.get('progress', 100)))
        except (TypeError, ValueError):
            progress = 100
        self._cached_row.append(progress)

        buddies = []
        if metadata.get('buddies'):
            try:
                buddies = simplejson.loads(metadata['buddies']).values()
            except simplejson.decoder.JSONDecodeError, exception:
                logging.warning('Cannot decode buddies for %r: %s',
                                metadata['uid'], exception)
Example #11
0
    def _add_columns(self):
        cell_favorite = CellRendererFavorite(self.tree_view)
        cell_favorite.connect('clicked', self.__favorite_clicked_cb)

        column = gtk.TreeViewColumn()
        column.props.sizing = gtk.TREE_VIEW_COLUMN_FIXED
        column.props.fixed_width = cell_favorite.props.width
        column.pack_start(cell_favorite)
        column.set_cell_data_func(cell_favorite, self.__favorite_set_data_cb)
        self.tree_view.append_column(column)

        self.cell_icon = CellRendererActivityIcon(self.tree_view)

        column = gtk.TreeViewColumn()
        column.props.sizing = gtk.TREE_VIEW_COLUMN_FIXED
        column.props.fixed_width = self.cell_icon.props.width
        column.pack_start(self.cell_icon)
        column.add_attribute(self.cell_icon, 'file-name',
                             ListModel.COLUMN_ICON)
        column.add_attribute(self.cell_icon, 'xo-color',
                             ListModel.COLUMN_ICON_COLOR)
        self.tree_view.append_column(column)

        self.cell_title = gtk.CellRendererText()
        self.cell_title.props.ellipsize = pango.ELLIPSIZE_MIDDLE
        self.cell_title.props.ellipsize_set = True

        self._title_column = gtk.TreeViewColumn()
        self._title_column.props.sizing = gtk.TREE_VIEW_COLUMN_FIXED
        self._title_column.props.expand = True
        self._title_column.props.clickable = True
        self._title_column.pack_start(self.cell_title)
        self._title_column.add_attribute(self.cell_title, 'markup',
                                         ListModel.COLUMN_TITLE)
        self.tree_view.append_column(self._title_column)

        buddies_column = gtk.TreeViewColumn()
        buddies_column.props.sizing = gtk.TREE_VIEW_COLUMN_FIXED
        self.tree_view.append_column(buddies_column)

        for column_index in [
                ListModel.COLUMN_BUDDY_1, ListModel.COLUMN_BUDDY_2,
                ListModel.COLUMN_BUDDY_3
        ]:
            cell_icon = CellRendererBuddy(self.tree_view,
                                          column_index=column_index)
            buddies_column.pack_start(cell_icon)
            buddies_column.props.fixed_width += cell_icon.props.width
            buddies_column.add_attribute(cell_icon, 'buddy', column_index)
            buddies_column.set_cell_data_func(cell_icon,
                                              self.__buddies_set_data_cb)

        cell_progress = gtk.CellRendererProgress()
        cell_progress.props.ypad = style.GRID_CELL_SIZE / 4
        buddies_column.pack_start(cell_progress)
        buddies_column.add_attribute(cell_progress, 'value',
                                     ListModel.COLUMN_PROGRESS)
        buddies_column.set_cell_data_func(cell_progress,
                                          self.__progress_data_cb)

        cell_text = gtk.CellRendererText()
        cell_text.props.xalign = 1

        # Measure the required width for a date in the form of "10 hours, 10
        # minutes ago"
        timestamp = time.time() - 10 * 60 - 10 * 60 * 60
        date = util.timestamp_to_elapsed_string(timestamp)
        date_width = self._get_width_for_string(date)

        self.sort_column = gtk.TreeViewColumn()
        self.sort_column.props.sizing = gtk.TREE_VIEW_COLUMN_FIXED
        self.sort_column.props.fixed_width = date_width
        self.sort_column.set_alignment(1)
        self.sort_column.props.resizable = True
        self.sort_column.props.clickable = True
        self.sort_column.pack_start(cell_text)
        self.sort_column.add_attribute(cell_text, 'text',
                                       ListModel.COLUMN_TIMESTAMP)
        self.tree_view.append_column(self.sort_column)