src/eric7/PluginManager/PluginRepositoryDialog.py

branch
eric7
changeset 11094
0cbc2ec68d2a
parent 11090
f5f5f5803935
--- a/src/eric7/PluginManager/PluginRepositoryDialog.py	Sat Dec 14 13:03:11 2024 +0100
+++ b/src/eric7/PluginManager/PluginRepositoryDialog.py	Sat Dec 14 17:25:19 2024 +0100
@@ -121,11 +121,14 @@
         self.__integratedWidget = integrated
 
         self.__statusTranslations = {
+            "obsolete": self.tr("Obsolete"),
             "stable": self.tr("Stable"),
+            "unknown": self.tr("Unknown"),
             "unstable": self.tr("Unstable"),
-            "obsolete": self.tr("Obsolete"),
-            "unknown": self.tr("Unknown"),
+            "upgrade": self.tr("Upgrade Available"),
         }
+        self.__statusOrder = ("upgrade", "stable", "unstable", "obsolete", "unknown")
+
         self.__initHeaderItemsCache()
 
         if self.__integratedWidget:
@@ -199,9 +202,6 @@
             self.repositoryList.headerItem().setText(
                 self.repositoryList.columnCount(), ""
             )
-            self.repositoryList.header().setSortIndicator(
-                0, Qt.SortOrder.AscendingOrder
-            )
 
         self.__downloadButton.setEnabled(False)
         self.__downloadInstallButton.setEnabled(False)
@@ -550,21 +550,6 @@
             # repopulate the list to update the refresh icons
             self.__populateList()
 
-    def __resortRepositoryList(self):
-        """
-        Private method to resort the tree.
-        """
-        if self.__integratedWidget:
-            self.repositoryList.sortItems(
-                self.repositoryList.sortColumn(),
-                Qt.SortOrder.AscendingOrder,
-            )
-        else:
-            self.repositoryList.sortItems(
-                self.repositoryList.sortColumn(),
-                self.repositoryList.header().sortIndicatorOrder(),
-            )
-
     def __initHeaderItemsCache(self):
         """
         Private method to initialize the cache variables for the header items.
@@ -591,10 +576,13 @@
             if f.open(QIODevice.OpenModeFlag.ReadOnly):
                 reader = PluginRepositoryReader(f, self.addEntry)
                 reader.readXML()
+                self.__updateStatusItemTexts()
+
                 self.repositoryList.resizeColumnToContents(0)
                 self.repositoryList.resizeColumnToContents(1)
                 self.repositoryList.resizeColumnToContents(2)
-                self.__resortRepositoryList()
+                self.repositoryList.sortItems(0, Qt.SortOrder.AscendingOrder)
+
                 url = Preferences.getUI("PluginRepositoryUrl7")
                 if url != self.repositoryUrlEdit.text():
                     self.repositoryUrlEdit.setText(url)
@@ -764,6 +752,81 @@
             self.downloadProgress.setMaximum(total)
             self.downloadProgress.setValue(done)
 
+    def __addPluginItem(
+        self,
+        parentItem,
+        name,
+        short,
+        description,
+        url,
+        author,
+        version,
+        filename,
+        updateStatus,
+        countIt=True,
+    ):
+        """
+        Private method to add an item for the given plugin parameters.
+
+        @param parentItem reference to the parent item
+        @type QTreeWidgetItem
+        @param name data for the name field
+        @type str
+        @param short data for the short field
+        @type str
+        @param description data for the description field
+        @type list of str
+        @param url data for the url field
+        @type str
+        @param author data for the author field
+        @type str
+        @param version data for the version field
+        @type str
+        @param filename data for the filename field
+        @type str
+        @param updateStatus update status
+        @type PluginStatus
+        @param countIt flag indicating to count the item for status labels
+            (defaults to True)
+        @type bool (optional)
+        """
+        if self.__integratedWidget:
+            entryFormat = "<b>{0}</b> - Version: <i>{1}</i><br/>{2}"
+            itm = QTreeWidgetItem(parentItem)
+            itm.setFirstColumnSpanned(True)
+            label = QLabel(entryFormat.format(name, version, short))
+            self.repositoryList.setItemWidget(itm, 0, label)
+        else:
+            itm = QTreeWidgetItem(parentItem, [name, version, short])
+
+        itm.setData(0, PluginRepositoryWidget.UrlRole, url)
+        itm.setData(0, PluginRepositoryWidget.FilenameRole, filename)
+        itm.setData(0, PluginRepositoryWidget.AuthorRole, author)
+        itm.setData(0, PluginRepositoryWidget.DescrRole, description)
+
+        iconColumn = 0 if self.__integratedWidget else 1
+        if updateStatus == PluginStatus.UpToDate:
+            itm.setIcon(iconColumn, EricPixmapCache.getIcon("empty"))
+            itm.setToolTip(iconColumn, self.tr("up-to-date"))
+        elif updateStatus == PluginStatus.New:
+            itm.setIcon(iconColumn, EricPixmapCache.getIcon("download"))
+            itm.setToolTip(iconColumn, self.tr("new download available"))
+            if countIt:
+                self.__newItems += 1
+        elif updateStatus == PluginStatus.LocalUpdate:
+            itm.setIcon(iconColumn, EricPixmapCache.getIcon("updateLocal"))
+            itm.setToolTip(iconColumn, self.tr("update installable"))
+            if countIt:
+                self.__updateLocalItems += 1
+        elif updateStatus == PluginStatus.RemoteUpdate:
+            itm.setIcon(iconColumn, EricPixmapCache.getIcon("updateRemote"))
+            itm.setToolTip(iconColumn, self.tr("updated download available"))
+            if countIt:
+                self.__updateRemoteItems += 1
+        elif updateStatus == PluginStatus.Error:
+            itm.setIcon(iconColumn, EricPixmapCache.getIcon("warning"))
+            itm.setToolTip(iconColumn, self.tr("error determining status"))
+
     def addEntry(
         self,
         name,
@@ -805,14 +868,9 @@
         # 1. determine and create the status item
         statusItem = self.__statusItems[status]
         if statusItem is None:
-            statusItem = QTreeWidgetItem(
-                self.repositoryList,
-                [
-                    self.__statusTranslations.get(
-                        status, self.__statusTranslations["unknown"]
-                    )
-                ],
-            )
+            if status not in self.__statusTranslations:
+                status = "unknown"
+            statusItem = QTreeWidgetItem(self.repositoryList, [""])
             statusItem.setExpanded(True)
             statusItem.setFirstColumnSpanned(True)
             self.__statusItems[status] = statusItem
@@ -828,40 +886,42 @@
             self.__categoryItems[status][category] = categoryItem
 
         # 3. create the plugin item
-        if self.__integratedWidget:
-            entryFormat = "<b>{0}</b> - Version: <i>{1}</i><br/>{2}"
-            itm = QTreeWidgetItem(categoryItem)
-            itm.setFirstColumnSpanned(True)
-            label = QLabel(entryFormat.format(name, version, short))
-            self.repositoryList.setItemWidget(itm, 0, label)
-        else:
-            itm = QTreeWidgetItem(categoryItem, [name, version, short])
+        updateStatus = self.__updateStatus(filename, version)
+        self.__addPluginItem(
+            categoryItem,
+            name,
+            short,
+            description,
+            url,
+            author,
+            version,
+            filename,
+            updateStatus,
+        )
 
-        itm.setData(0, PluginRepositoryWidget.UrlRole, url)
-        itm.setData(0, PluginRepositoryWidget.FilenameRole, filename)
-        itm.setData(0, PluginRepositoryWidget.AuthorRole, author)
-        itm.setData(0, PluginRepositoryWidget.DescrRole, description)
+        # 4. create the upgradable plugin item
+        if updateStatus in (PluginStatus.LocalUpdate, PluginStatus.RemoteUpdate):
+            status = "upgrade"
 
-        iconColumn = 0 if self.__integratedWidget else 1
-        updateStatus = self.__updateStatus(filename, version)
-        if updateStatus == PluginStatus.UpToDate:
-            itm.setIcon(iconColumn, EricPixmapCache.getIcon("empty"))
-            itm.setToolTip(iconColumn, self.tr("up-to-date"))
-        elif updateStatus == PluginStatus.New:
-            itm.setIcon(iconColumn, EricPixmapCache.getIcon("download"))
-            itm.setToolTip(iconColumn, self.tr("new download available"))
-            self.__newItems += 1
-        elif updateStatus == PluginStatus.LocalUpdate:
-            itm.setIcon(iconColumn, EricPixmapCache.getIcon("updateLocal"))
-            itm.setToolTip(iconColumn, self.tr("update installable"))
-            self.__updateLocalItems += 1
-        elif updateStatus == PluginStatus.RemoteUpdate:
-            itm.setIcon(iconColumn, EricPixmapCache.getIcon("updateRemote"))
-            itm.setToolTip(iconColumn, self.tr("updated download available"))
-            self.__updateRemoteItems += 1
-        elif updateStatus == PluginStatus.Error:
-            itm.setIcon(iconColumn, EricPixmapCache.getIcon("warning"))
-            itm.setToolTip(iconColumn, self.tr("error determining status"))
+            statusItem = self.__statusItems[status]
+            if statusItem is None:
+                statusItem = QTreeWidgetItem(self.repositoryList, [""])
+                statusItem.setExpanded(True)
+                statusItem.setFirstColumnSpanned(True)
+                self.__statusItems[status] = statusItem
+
+            self.__addPluginItem(
+                statusItem,
+                name,
+                short,
+                description,
+                url,
+                author,
+                version,
+                filename,
+                updateStatus,
+                countIt=False,
+            )
 
     def __updateStatus(self, filename, version):
         """
@@ -928,6 +988,23 @@
         else:
             return PluginStatus.RemoteUpdate
 
+    def __updateStatusItemTexts(self):
+        """
+        Private method to update the status item texts to include a number determined
+        by a given status order.
+        """
+        index = 1
+        for status in self.__statusOrder:
+            statusItem = self.__statusItems[status]
+            if statusItem is not None:
+                statusItem.setText(
+                    0,
+                    self.tr("{0}. {1}").format(
+                        index, self.__statusTranslations[status]
+                    ),
+                )
+                index += 1
+
     def __sslErrors(self, reply, errors):
         """
         Private slot to handle SSL errors.

eric ide

mercurial