Commits

Peer Sommerlund committed bfd3478 Merge

merge of show_startup_progress

Comments (0)

Files changed (3)

.hgpatchinfo/thread-repoview-load.dep

+5bd0e9cccee072da675ecd31006c1a78689f32fe

.hgpatchinfo/thread-repoview-load.desc

+repoview: move initialization of RepoTreeModel into a thread

tortoisehg/hgqt/repotreemodel.py

         self.showNetworkSubrepos = showNetworkSubrepos
         self.showShortPaths = showShortPaths
 
-        root = None
-        all = None
+        self.loader = None
+        self.rootItem = RepoTreeItem(self)
+        self.allrepos = AllRepoGroupItem(self)
+        self.rootItem.appendChild(self.allrepos)
 
         if filename:
-            f = QFile(filename)
-            if f.open(QIODevice.ReadOnly):
-                root = readXml(f, reporegistryXmlElementName)
-                f.close()
-                if root:
-                    for c in root.childs:
-                        if isinstance(c, AllRepoGroupItem):
-                            all = c
-                            break
+            self.loader = RepoTreeModelLoader(filename, self)
+            self.loader.loadProgress.connect(self.emitUpdateProgress)
+            self.loader.treeModelLoaded.connect(self.loadCompleted)
+            self.loader.start()
 
-                    if self.showSubrepos:
-                        self.loadSubrepos(root)
-
-        if not root:
-            root = RepoTreeItem(self)
-            all = AllRepoGroupItem(self)
-            root.appendChild(all)
-
+    def loadCompleted(self, root, all):
+        n = getRepoItemList(root)
+        self.beginResetModel()
         self.rootItem = root
         self.allrepos = all
+        self.loader = None
+        self.endResetModel()
         self.updateCommonPaths()
 
     # see http://doc.qt.nokia.com/4.6/model-view-model-subclassing.html
             if index.row() < 0:
                 return count
             count += 1
+            
+    def emitUpdateProgress(self, i, n, path):
+        if i < n:
+            self.updateProgress.emit(i, n,
+                    _('Updating repository registry'),
+                    _('Loading repository %s') 
+                    % hglib.tounicode(path))
+        else:
+            self.updateProgress.emit(i, n,
+                    _('Updating repository registry'),
+                    _('Repository Registry updated'))
 
     def loadSubrepos(self, root, filterFunc=(lambda r: True)):
         repoList = getRepoItemList(root)
             if filterFunc(c.rootpath()):
                 if self.showNetworkSubrepos \
                         or not paths.netdrive_status(c.rootpath()):
-                    self.updateProgress.emit(n, len(repoList),
-                        _('Updating repository registry'),
-                        _('Loading repository %s')
-                        % hglib.tounicode(c.rootpath()))
+                    self.emitUpdateProgress(n, len(repoList), c.rootpath())
                     QCoreApplication.processEvents()
                     self.removeRows(0, c.childCount(),
                         self.createIndex(c.row(), 0, c))
                     c.appendSubrepos()
-        self.updateProgress.emit(len(repoList), len(repoList),
-            _('Updating repository registry'),
-            _('Repository Registry updated'))
+        self.emitUpdateProgress(len(repoList), len(repoList), "")
 
     def updateCommonPaths(self, showShortPaths=None):
         if not showShortPaths is None:
         self.layoutAboutToBeChanged.emit()
         childs.sort(key=keyfunc)
         self.layoutChanged.emit()
+
+
+
+class RepoTreeModelLoader(QThread):
+    "A one-shot thread that loads the model from a file"
+
+    treeModelLoaded = pyqtSignal(object, object)
+    loadProgress = pyqtSignal(int, int, QString)
+
+    def __init__(self, filename, parent):
+        super(RepoTreeModelLoader, self).__init__(parent)
+
+        self.filename = filename
+        self.model = parent
+        self.root = None
+        self.all = None
+        self.finished.connect(self.thread_finished)
+
+    def thread_finished(self):
+        self.treeModelLoaded.emit(self.root, self.all)
+
+    def run(self):
+        root = self.root
+        all = self.all
+        if False:
+            self.root = RepoTreeItem()
+            self.all = AllRepoGroupItem()
+            self.root.appendChild(self.all)
+            self.all.name = 'THREAD WORKS'
+            return
+        f = QFile(self.filename)
+        if f.open(QIODevice.ReadOnly):
+            root = readXml(f, reporegistryXmlElementName)
+            f.close()
+            if root:
+                for c in root.childs:
+                    if isinstance(c, AllRepoGroupItem):
+                        all = c
+                        break
+
+                if self.model.showSubrepos:
+                    self.loadSubrepos(root)
+
+        self.root = root
+        self.all = all
+
+    def loadSubrepos(self, root):
+        # Note that the sub-repo-relation is transient since it 
+        # depends on the workdir cset of the parent repo
+        repoList = getRepoItemList(root)
+        for n, c in enumerate(repoList):
+            if (self.model.showNetworkSubrepos 
+                or not paths.netdrive_status(c.rootpath()) 
+            ):
+                self.loadProgress.emit(n, len(repoList), c.rootpath())
+                # Remove listed subrepos, append current subrepos 
+                c.removeRows(0,c.childCount())
+                c.appendSubrepos()
+        self.loadProgress.emit(len(repoList), len(repoList), "")