~gary-lasker/software-center/restore-listview-progress-feedback

« back to all changes in this revision

Viewing changes to softwarecenter/models/appstore.py

  • Committer: Gary Lasker
  • Date: 2011-01-12 21:37:13 UTC
  • Revision ID: gary.lasker@canonical.com-20110112213713-053pzmttp0okplkw
use a dict so that we are able to handle multiple transactions in the index map, also don't block the UI when looking up an index

Show diffs side-by-side

added added

removed removed

Lines of Context:
152
152
        self.active_app = None
153
153
        self._prev_active_app = 0
154
154
        self.limit = limit
155
 
        # keep track of the index for a transaction in progress
156
 
        self.transaction_index = None
 
155
        # keep track of indicies for transactions in progress
 
156
        self.transaction_index_map = {}
157
157
        # no search query means "all"
158
158
        if not search_query:
159
159
            self.search_query = SearchQuery(xapian.Query(""))
341
341
        return 0
342
342
 
343
343
    def _on_transaction_progress_changed(self, backend, pkgname, progress):
344
 
        if self.transaction_index is not None:
345
 
            row = self[self.transaction_index]
 
344
        if pkgname in self.transaction_index_map:
 
345
            row = self[self.transaction_index_map[pkgname]]
346
346
            self.row_changed(row.path, row.iter)
347
347
            
348
348
    # the following methods ensure that the contents data is refreshed
351
351
    def _on_transaction_started(self, backend, pkgname):
352
352
        self._existing_apps = None
353
353
        self._installable_apps = None
354
 
        from softwarecenter.utils import ExecutionTime
355
 
        with ExecutionTime("TIME get_index_for_pkgname"):
356
 
            self.transaction_index = self._get_index_for_pkgname(pkgname)
 
354
        gobject.idle_add(self._register_transaction_index_for_pkgname, pkgname)
357
355
 
358
 
    def _get_index_for_pkgname(self, pkgname_to_match):
 
356
    def _register_transaction_index_for_pkgname(self, pkgname_to_match):
359
357
        for index in range(len(self.matches)):
360
358
            doc = self.matches[index].document
361
359
            pkgname = self.db.get_pkgname(doc)
362
360
            if pkgname == pkgname_to_match:
363
 
                return index
 
361
                self.transaction_index_map[pkgname] = index
 
362
                return
364
363
                
365
 
    def _on_transaction_finished(self, *args, **kwargs):
 
364
    def _on_transaction_finished(self, backend, result):
366
365
        self._existing_apps = None
367
366
        self._installable_apps = None
368
 
        self.transaction_index = None
 
367
        if result.pkgname in self.transaction_index_map:
 
368
            del self.transaction_index_map[result.pkgname]
369
369
 
370
370
    def _download_icon_and_show_when_ready(self, cache, pkgname, icon_file_name):
371
371
        self._logger.debug("did not find the icon locally, must download %s" % icon_file_name)