Ticket #3888: 0001-Change-Journal-model-to-make-the-buddy-icons-work.patch

File 0001-Change-Journal-model-to-make-the-buddy-icons-work.patch, 5.7 KB (added by manuq, 8 years ago)

Change the model to fix the icon in the Jounal list view

  • src/jarabe/journal/listmodel.py

    From af8e9a556a0f035b231977964e6471cac233985c Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
    Date: Thu, 22 Nov 2012 16:16:06 -0300
    Subject: [PATCH shell] Change Journal model to make the buddy icons work
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
    
    Signed-off-by: Manuel Quiñones <manuq@laptop.org>
    ---
     src/jarabe/journal/listmodel.py | 22 ++++++++++++++-------
     src/jarabe/journal/listview.py  | 42 ++++++++++++++++++++++-------------------
     2 files changed, 38 insertions(+), 26 deletions(-)
    
    diff --git a/src/jarabe/journal/listmodel.py b/src/jarabe/journal/listmodel.py
    index b98d01c..f0fd369 100644
    a b class ListModel(GObject.GObject, Gtk.TreeModel, Gtk.TreeDragSource): 
    5151    COLUMN_CREATION_TIME = 6
    5252    COLUMN_FILESIZE = 7
    5353    COLUMN_PROGRESS = 8
    54     COLUMN_BUDDY_1 = 9
    55     COLUMN_BUDDY_2 = 10
    56     COLUMN_BUDDY_3 = 11
     54    COLUMN_BUDDY_1_NAME = 9
     55    COLUMN_BUDDY_1_COLOR = 10
     56    COLUMN_BUDDY_2_NAME = 11
     57    COLUMN_BUDDY_2_COLOR = 12
     58    COLUMN_BUDDY_3_NAME = 13
     59    COLUMN_BUDDY_3_COLOR = 14
    5760
    5861    _COLUMN_TYPES = {
    5962        COLUMN_UID: str,
    class ListModel(GObject.GObject, Gtk.TreeModel, Gtk.TreeDragSource): 
    6568        COLUMN_CREATION_TIME: str,
    6669        COLUMN_FILESIZE: str,
    6770        COLUMN_PROGRESS: int,
    68         COLUMN_BUDDY_1: object,
    69         COLUMN_BUDDY_3: object,
    70         COLUMN_BUDDY_2: object,
     71        COLUMN_BUDDY_1_NAME: str,
     72        COLUMN_BUDDY_1_COLOR: object,
     73        COLUMN_BUDDY_2_NAME: str,
     74        COLUMN_BUDDY_2_COLOR: object,
     75        COLUMN_BUDDY_3_NAME: str,
     76        COLUMN_BUDDY_3_COLOR: object,
    7177    }
    7278
    7379    _PAGE_SIZE = 10
    class ListModel(GObject.GObject, Gtk.TreeModel, Gtk.TreeDragSource): 
    194200                    logging.warning('Malformed buddies for %r: %s',
    195201                                    metadata['uid'], exception)
    196202                else:
    197                     self._cached_row.append((nick, XoColor(color)))
     203                    self._cached_row.append(nick)
     204                    self._cached_row.append(XoColor(color))
    198205                    continue
    199206
    200207            self._cached_row.append(None)
     208            self._cached_row.append(None)
    201209
    202210        return self._cached_row[column]
    203211
  • src/jarabe/journal/listview.py

    diff --git a/src/jarabe/journal/listview.py b/src/jarabe/journal/listview.py
    index 4af6e3c..787f4c1 100644
    a b class BaseListView(Gtk.Bin): 
    176176        buddies_column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
    177177        self.tree_view.append_column(buddies_column)
    178178
    179         for column_index in [ListModel.COLUMN_BUDDY_1,
    180                              ListModel.COLUMN_BUDDY_2,
    181                              ListModel.COLUMN_BUDDY_3]:
    182             cell_icon = CellRendererBuddy(self.tree_view,
    183                                           column_index=column_index)
     179        for n_ in xrange(0, 3):
     180            index_name = getattr(ListModel, 'COLUMN_BUDDY_' \
     181                                     + str(n_ + 1) + '_NAME')
     182            index_color = getattr(ListModel, 'COLUMN_BUDDY_' \
     183                                      + str(n_ + 1) + '_COLOR')
     184            cell_icon = CellRendererBuddy(self.tree_view)
    184185            buddies_column.pack_start(cell_icon, True)
    185186            buddies_column.props.fixed_width += cell_icon.props.width
    186             buddies_column.add_attribute(cell_icon, 'buddy', column_index)
     187            buddies_column.add_attribute(cell_icon, 'buddy-name',
     188                                         index_name)
     189            buddies_column.add_attribute(cell_icon, 'xo-color',
     190                                         index_color)
    187191            buddies_column.set_cell_data_func(cell_icon,
    188192                                              self.__buddies_set_data_cb)
    189193
    class CellRendererActivityIcon(CellRendererIcon): 
    663667class CellRendererBuddy(CellRendererIcon):
    664668    __gtype_name__ = 'JournalCellRendererBuddy'
    665669
    666     def __init__(self, tree_view, column_index):
     670    def __init__(self, tree_view):
    667671        CellRendererIcon.__init__(self, tree_view)
    668672
    669673        self.props.width = style.STANDARD_ICON_SIZE
    class CellRendererBuddy(CellRendererIcon): 
    671675        self.props.size = style.STANDARD_ICON_SIZE
    672676        self.props.mode = Gtk.CellRendererMode.ACTIVATABLE
    673677
     678        self._buddy_name = None
    674679        self.tree_view = tree_view
    675         self._model_column_index = column_index
    676680
    677681    def create_palette(self):
    678         tree_model = self.tree_view.get_model()
    679         row = tree_model[self.props.palette_invoker.path]
    680 
    681         if row[self._model_column_index] is not None:
    682             nick, xo_color = row[self._model_column_index]
    683             return BuddyPalette((nick, xo_color.to_string()))
     682        if self.props.buddy_name is not None:
     683            return BuddyPalette((self.props.buddy_name,
     684                                 self.props.xo_color.to_string()))
    684685        else:
    685686            return None
    686687
    687     def set_buddy(self, buddy):
    688         if buddy is None:
     688    def set_buddy_name(self, buddy_name):
     689        self._buddy_name = buddy_name
     690        if buddy_name is None:
    689691            self.props.icon_name = None
    690692        else:
    691             nick_, xo_color = buddy
    692693            self.props.icon_name = 'computer-xo'
    693             self.props.xo_color = xo_color
    694694
    695     buddy = GObject.property(type=object, setter=set_buddy)
     695    def get_buddy_name(self):
     696        return self._buddy_name
     697
     698    buddy_name = GObject.property(type=str, getter=get_buddy_name,
     699                                  setter=set_buddy_name)