Ticket #1235: sugar-1235.2.patch

File sugar-1235.2.patch, 7.5 KB (added by alsroot, 12 years ago)
  • src/jarabe/journal/listmodel.py

    From 654d5269b7204be2171c5610e7432dd5eb3e7e41 Mon Sep 17 00:00:00 2001
    From: Aleksey Lim <alsroot@member.fsf.org>
    Date: Sun, 6 Sep 2009 06:58:49 +0000
    Subject: Journal list view: jumping back to first page when popping up a palette #1235
    
    ---
     src/jarabe/journal/listmodel.py |   57 +++++++++++++++++++++++++++++++++-----
     src/jarabe/journal/listview.py  |   39 ++++++++------------------
     src/jarabe/journal/model.py     |    3 ++
     3 files changed, 64 insertions(+), 35 deletions(-)
    
    diff --git a/src/jarabe/journal/listmodel.py b/src/jarabe/journal/listmodel.py
    index 917fbb1..0e1a3c8 100644
    a b class ListModel(gtk.GenericTreeModel, gtk.TreeDragSource): 
    3535    __gtype_name__ = 'JournalListModel'
    3636
    3737    __gsignals__ = {
     38        'setup':    (gobject.SIGNAL_RUN_FIRST,
     39                     gobject.TYPE_NONE,
     40                     ([])),
    3841        'ready':    (gobject.SIGNAL_RUN_FIRST,
    3942                     gobject.TYPE_NONE,
    4043                     ([])),
    4144        'progress': (gobject.SIGNAL_RUN_FIRST,
    4245                     gobject.TYPE_NONE,
    4346                     ([])),
     47        'invalidated': (gobject.SIGNAL_RUN_FIRST,
     48                        gobject.TYPE_NONE,
     49                        ([])),
    4450    }
    4551
    4652    COLUMN_UID = 0
    class ListModel(gtk.GenericTreeModel, gtk.TreeDragSource): 
    6773
    6874    _PAGE_SIZE = 10
    6975
    70     def __init__(self, query):
     76    def __init__(self):
    7177        gobject.GObject.__init__(self)
    7278
     79        self._query = None
    7380        self._last_requested_index = None
    7481        self._cached_row = None
    75         self._result_set = model.find(query, ListModel._PAGE_SIZE)
     82        self._result_set = None
    7683        self._temp_drag_file_path = None
    7784
    7885        # HACK: The view will tell us that it is resizing so the model can
    7986        # avoid hitting D-Bus and disk.
    8087        self.view_is_resizing = False
    8188
    82         self._result_set.ready.connect(self.__result_set_ready_cb)
     89        model.updated.connect(self.__model_updated_cb)
     90        model.created.connect(self.__model_created_cb)
     91        model.deleted.connect(self.__model_deleted_cb)
     92
     93    def refresh(self, query):
     94        self._query = query
     95
     96        old_len = None
     97        if self._result_set is not None:
     98            old_len = self._result_set.length
     99            self._result_set.stop()
     100
     101        self._last_requested_index = None
     102        self._cached_row = None
     103
     104        self.emit('setup')
     105
     106        def result_set_ready_cb(**kwargs):
     107            if old_len is not None:
     108                new_len = self._result_set.length
     109                for i in range(old_len, new_len):
     110                    self.emit('row-inserted', (i, ), self.get_iter((i, )))
     111                for i in reversed(range(new_len, old_len)):
     112                    self.emit('row-deleted', (i, ))
     113            self.emit('ready')
     114
     115        self._result_set = model.find(self._query, ListModel._PAGE_SIZE)
     116        self._result_set.ready.connect(result_set_ready_cb, weak=False)
    83117        self._result_set.progress.connect(self.__result_set_progress_cb)
     118        self._result_set.setup()
     119
     120    def __model_updated_cb(self, sender, **kwargs):
     121        self._result_set.invalidate()
     122        self._last_requested_index = None
     123        self._cached_row = None
     124        self.emit('invalidated')
     125
     126    def __model_created_cb(self, sender, **kwargs):
     127        self.refresh(self._query)
    84128
    85     def __result_set_ready_cb(self, **kwargs):
    86         self.emit('ready')
     129    def __model_deleted_cb(self, sender, **kwargs):
     130        self.refresh(self._query)
    87131
    88132    def __result_set_progress_cb(self, **kwargs):
    89133        self.emit('progress')
    90134
    91     def setup(self):
    92         self._result_set.setup()
    93 
    94135    def stop(self):
    95136        self._result_set.stop()
    96137
  • src/jarabe/journal/listview.py

    diff --git a/src/jarabe/journal/listview.py b/src/jarabe/journal/listview.py
    index 057b7c4..6d21fc7 100644
    a b class BaseListView(gtk.Bin): 
    101101
    102102        # Auto-update stuff
    103103        self._fully_obscured = True
    104         self._dirty = False
    105104        self._refresh_idle_handler = None
    106105        self._update_dates_timer = None
    107106
    108         model.created.connect(self.__model_created_cb)
    109         model.updated.connect(self.__model_updated_cb)
    110         model.deleted.connect(self.__model_deleted_cb)
    111 
    112     def __model_created_cb(self, sender, **kwargs):
    113         self._set_dirty()
    114 
    115     def __model_updated_cb(self, sender, **kwargs):
    116         self._set_dirty()
    117 
    118     def __model_deleted_cb(self, sender, **kwargs):
    119         self._set_dirty()
    120 
    121107    def _add_columns(self):
    122108        cell_favorite = CellRendererFavorite(self.tree_view)
    123109        cell_favorite.connect('clicked', self.__favorite_clicked_cb)
    class BaseListView(gtk.Bin): 
    261247    def __favorite_clicked_cb(self, cell, path):
    262248        row = self._model[path]
    263249        metadata = model.get(row[ListModel.COLUMN_UID])
    264         if metadata['keep'] == '1':
     250        if 'keep' in metadata and metadata['keep'] == '1':
    265251            metadata['keep'] = '0'
    266252        else:
    267253            metadata['keep'] = '1'
    class BaseListView(gtk.Bin): 
    278264
    279265    def refresh(self):
    280266        logging.debug('ListView.refresh query %r', self._query)
    281         self._stop_progress_bar()
    282         self._start_progress_bar()
    283267
    284268        if self._model is not None:
    285269            self._model.stop()
    286270
    287         self._model = ListModel(self._query)
     271        self._model = ListModel()
     272        self._model.connect('setup', self.__model_setup_cb)
    288273        self._model.connect('ready', self.__model_ready_cb)
    289274        self._model.connect('progress', self.__model_progress_cb)
    290         self._model.setup()
     275        self._model.connect('invalidated', self.__model_invalidated_cb)
     276        self._model.refresh(self._query)
     277
     278    def __model_setup_cb(self, tree_model):
     279        self._stop_progress_bar()
     280        self._start_progress_bar()
    291281
    292282    def __model_ready_cb(self, tree_model):
    293283        self._stop_progress_bar()
    class BaseListView(gtk.Bin): 
    320310                self._progress_bar.pulse()
    321311                self._last_progress_bar_pulse = time.time()
    322312
     313    def __model_invalidated_cb(self, tree_model):
     314        self.tree_view.queue_draw()
     315
    323316    def _start_progress_bar(self):
    324317        alignment = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.5)
    325318        self.remove(self.child)
    class BaseListView(gtk.Bin): 
    408401                next_iter = self._model.iter_next(self._model.get_iter(path))
    409402                path = self._model.get_path(next_iter)
    410403
    411     def _set_dirty(self):
    412         if self._fully_obscured:
    413             self._dirty = True
    414         else:
    415             self.refresh()
    416 
    417404    def set_is_visible(self, visible):
    418405        logging.debug('canvas_visibility_notify_event_cb %r', visible)
    419406        if visible:
    420407            self._fully_obscured = False
    421             if self._dirty:
    422                 self.refresh()
    423408            if self._update_dates_timer is None:
    424409                logging.debug('Adding date updating timer')
    425410                self._update_dates_timer = \
  • src/jarabe/journal/model.py

    diff --git a/src/jarabe/journal/model.py b/src/jarabe/journal/model.py
    index 8ae78d8..76ac791 100644
    a b class BaseResultSet(object): 
    199199
    200200        return self._cache[self._position - self._offset]
    201201
     202    def invalidate(self):
     203        self._cache = _Cache()
     204
    202205class DatastoreResultSet(BaseResultSet):
    203206    """Encapsulates the result of a query on the datastore
    204207    """