src/eric7/PluginManager/PluginRepositoryDialog.py

branch
eric7
changeset 11094
0cbc2ec68d2a
parent 11090
f5f5f5803935
equal deleted inserted replaced
11093:e8932a99beb4 11094:0cbc2ec68d2a
119 self.__external = False 119 self.__external = False
120 120
121 self.__integratedWidget = integrated 121 self.__integratedWidget = integrated
122 122
123 self.__statusTranslations = { 123 self.__statusTranslations = {
124 "obsolete": self.tr("Obsolete"),
124 "stable": self.tr("Stable"), 125 "stable": self.tr("Stable"),
126 "unknown": self.tr("Unknown"),
125 "unstable": self.tr("Unstable"), 127 "unstable": self.tr("Unstable"),
126 "obsolete": self.tr("Obsolete"), 128 "upgrade": self.tr("Upgrade Available"),
127 "unknown": self.tr("Unknown"),
128 } 129 }
130 self.__statusOrder = ("upgrade", "stable", "unstable", "obsolete", "unknown")
131
129 self.__initHeaderItemsCache() 132 self.__initHeaderItemsCache()
130 133
131 if self.__integratedWidget: 134 if self.__integratedWidget:
132 self.layout().setContentsMargins(0, 3, 0, 0) 135 self.layout().setContentsMargins(0, 3, 0, 0)
133 136
196 199
197 self.__closeButton.setEnabled(True) 200 self.__closeButton.setEnabled(True)
198 201
199 self.repositoryList.headerItem().setText( 202 self.repositoryList.headerItem().setText(
200 self.repositoryList.columnCount(), "" 203 self.repositoryList.columnCount(), ""
201 )
202 self.repositoryList.header().setSortIndicator(
203 0, Qt.SortOrder.AscendingOrder
204 ) 204 )
205 205
206 self.__downloadButton.setEnabled(False) 206 self.__downloadButton.setEnabled(False)
207 self.__downloadInstallButton.setEnabled(False) 207 self.__downloadInstallButton.setEnabled(False)
208 self.__downloadCancelButton.setEnabled(False) 208 self.__downloadCancelButton.setEnabled(False)
548 self.downloadProgress.setValue(0) 548 self.downloadProgress.setValue(0)
549 549
550 # repopulate the list to update the refresh icons 550 # repopulate the list to update the refresh icons
551 self.__populateList() 551 self.__populateList()
552 552
553 def __resortRepositoryList(self):
554 """
555 Private method to resort the tree.
556 """
557 if self.__integratedWidget:
558 self.repositoryList.sortItems(
559 self.repositoryList.sortColumn(),
560 Qt.SortOrder.AscendingOrder,
561 )
562 else:
563 self.repositoryList.sortItems(
564 self.repositoryList.sortColumn(),
565 self.repositoryList.header().sortIndicatorOrder(),
566 )
567
568 def __initHeaderItemsCache(self): 553 def __initHeaderItemsCache(self):
569 """ 554 """
570 Private method to initialize the cache variables for the header items. 555 Private method to initialize the cache variables for the header items.
571 """ 556 """
572 self.__statusItems = defaultdict(lambda: None) 557 self.__statusItems = defaultdict(lambda: None)
589 self.__repositoryMissing = False 574 self.__repositoryMissing = False
590 f = QFile(self.pluginRepositoryFile) 575 f = QFile(self.pluginRepositoryFile)
591 if f.open(QIODevice.OpenModeFlag.ReadOnly): 576 if f.open(QIODevice.OpenModeFlag.ReadOnly):
592 reader = PluginRepositoryReader(f, self.addEntry) 577 reader = PluginRepositoryReader(f, self.addEntry)
593 reader.readXML() 578 reader.readXML()
579 self.__updateStatusItemTexts()
580
594 self.repositoryList.resizeColumnToContents(0) 581 self.repositoryList.resizeColumnToContents(0)
595 self.repositoryList.resizeColumnToContents(1) 582 self.repositoryList.resizeColumnToContents(1)
596 self.repositoryList.resizeColumnToContents(2) 583 self.repositoryList.resizeColumnToContents(2)
597 self.__resortRepositoryList() 584 self.repositoryList.sortItems(0, Qt.SortOrder.AscendingOrder)
585
598 url = Preferences.getUI("PluginRepositoryUrl7") 586 url = Preferences.getUI("PluginRepositoryUrl7")
599 if url != self.repositoryUrlEdit.text(): 587 if url != self.repositoryUrlEdit.text():
600 self.repositoryUrlEdit.setText(url) 588 self.repositoryUrlEdit.setText(url)
601 EricMessageBox.warning( 589 EricMessageBox.warning(
602 self, 590 self,
762 """ 750 """
763 if total: 751 if total:
764 self.downloadProgress.setMaximum(total) 752 self.downloadProgress.setMaximum(total)
765 self.downloadProgress.setValue(done) 753 self.downloadProgress.setValue(done)
766 754
755 def __addPluginItem(
756 self,
757 parentItem,
758 name,
759 short,
760 description,
761 url,
762 author,
763 version,
764 filename,
765 updateStatus,
766 countIt=True,
767 ):
768 """
769 Private method to add an item for the given plugin parameters.
770
771 @param parentItem reference to the parent item
772 @type QTreeWidgetItem
773 @param name data for the name field
774 @type str
775 @param short data for the short field
776 @type str
777 @param description data for the description field
778 @type list of str
779 @param url data for the url field
780 @type str
781 @param author data for the author field
782 @type str
783 @param version data for the version field
784 @type str
785 @param filename data for the filename field
786 @type str
787 @param updateStatus update status
788 @type PluginStatus
789 @param countIt flag indicating to count the item for status labels
790 (defaults to True)
791 @type bool (optional)
792 """
793 if self.__integratedWidget:
794 entryFormat = "<b>{0}</b> - Version: <i>{1}</i><br/>{2}"
795 itm = QTreeWidgetItem(parentItem)
796 itm.setFirstColumnSpanned(True)
797 label = QLabel(entryFormat.format(name, version, short))
798 self.repositoryList.setItemWidget(itm, 0, label)
799 else:
800 itm = QTreeWidgetItem(parentItem, [name, version, short])
801
802 itm.setData(0, PluginRepositoryWidget.UrlRole, url)
803 itm.setData(0, PluginRepositoryWidget.FilenameRole, filename)
804 itm.setData(0, PluginRepositoryWidget.AuthorRole, author)
805 itm.setData(0, PluginRepositoryWidget.DescrRole, description)
806
807 iconColumn = 0 if self.__integratedWidget else 1
808 if updateStatus == PluginStatus.UpToDate:
809 itm.setIcon(iconColumn, EricPixmapCache.getIcon("empty"))
810 itm.setToolTip(iconColumn, self.tr("up-to-date"))
811 elif updateStatus == PluginStatus.New:
812 itm.setIcon(iconColumn, EricPixmapCache.getIcon("download"))
813 itm.setToolTip(iconColumn, self.tr("new download available"))
814 if countIt:
815 self.__newItems += 1
816 elif updateStatus == PluginStatus.LocalUpdate:
817 itm.setIcon(iconColumn, EricPixmapCache.getIcon("updateLocal"))
818 itm.setToolTip(iconColumn, self.tr("update installable"))
819 if countIt:
820 self.__updateLocalItems += 1
821 elif updateStatus == PluginStatus.RemoteUpdate:
822 itm.setIcon(iconColumn, EricPixmapCache.getIcon("updateRemote"))
823 itm.setToolTip(iconColumn, self.tr("updated download available"))
824 if countIt:
825 self.__updateRemoteItems += 1
826 elif updateStatus == PluginStatus.Error:
827 itm.setIcon(iconColumn, EricPixmapCache.getIcon("warning"))
828 itm.setToolTip(iconColumn, self.tr("error determining status"))
829
767 def addEntry( 830 def addEntry(
768 self, 831 self,
769 name, 832 name,
770 short, 833 short,
771 description, 834 description,
803 return 866 return
804 867
805 # 1. determine and create the status item 868 # 1. determine and create the status item
806 statusItem = self.__statusItems[status] 869 statusItem = self.__statusItems[status]
807 if statusItem is None: 870 if statusItem is None:
808 statusItem = QTreeWidgetItem( 871 if status not in self.__statusTranslations:
809 self.repositoryList, 872 status = "unknown"
810 [ 873 statusItem = QTreeWidgetItem(self.repositoryList, [""])
811 self.__statusTranslations.get(
812 status, self.__statusTranslations["unknown"]
813 )
814 ],
815 )
816 statusItem.setExpanded(True) 874 statusItem.setExpanded(True)
817 statusItem.setFirstColumnSpanned(True) 875 statusItem.setFirstColumnSpanned(True)
818 self.__statusItems[status] = statusItem 876 self.__statusItems[status] = statusItem
819 877
820 # 2. determine and create the category item 878 # 2. determine and create the category item
826 categoryItem.setExpanded(True) 884 categoryItem.setExpanded(True)
827 categoryItem.setFirstColumnSpanned(True) 885 categoryItem.setFirstColumnSpanned(True)
828 self.__categoryItems[status][category] = categoryItem 886 self.__categoryItems[status][category] = categoryItem
829 887
830 # 3. create the plugin item 888 # 3. create the plugin item
831 if self.__integratedWidget:
832 entryFormat = "<b>{0}</b> - Version: <i>{1}</i><br/>{2}"
833 itm = QTreeWidgetItem(categoryItem)
834 itm.setFirstColumnSpanned(True)
835 label = QLabel(entryFormat.format(name, version, short))
836 self.repositoryList.setItemWidget(itm, 0, label)
837 else:
838 itm = QTreeWidgetItem(categoryItem, [name, version, short])
839
840 itm.setData(0, PluginRepositoryWidget.UrlRole, url)
841 itm.setData(0, PluginRepositoryWidget.FilenameRole, filename)
842 itm.setData(0, PluginRepositoryWidget.AuthorRole, author)
843 itm.setData(0, PluginRepositoryWidget.DescrRole, description)
844
845 iconColumn = 0 if self.__integratedWidget else 1
846 updateStatus = self.__updateStatus(filename, version) 889 updateStatus = self.__updateStatus(filename, version)
847 if updateStatus == PluginStatus.UpToDate: 890 self.__addPluginItem(
848 itm.setIcon(iconColumn, EricPixmapCache.getIcon("empty")) 891 categoryItem,
849 itm.setToolTip(iconColumn, self.tr("up-to-date")) 892 name,
850 elif updateStatus == PluginStatus.New: 893 short,
851 itm.setIcon(iconColumn, EricPixmapCache.getIcon("download")) 894 description,
852 itm.setToolTip(iconColumn, self.tr("new download available")) 895 url,
853 self.__newItems += 1 896 author,
854 elif updateStatus == PluginStatus.LocalUpdate: 897 version,
855 itm.setIcon(iconColumn, EricPixmapCache.getIcon("updateLocal")) 898 filename,
856 itm.setToolTip(iconColumn, self.tr("update installable")) 899 updateStatus,
857 self.__updateLocalItems += 1 900 )
858 elif updateStatus == PluginStatus.RemoteUpdate: 901
859 itm.setIcon(iconColumn, EricPixmapCache.getIcon("updateRemote")) 902 # 4. create the upgradable plugin item
860 itm.setToolTip(iconColumn, self.tr("updated download available")) 903 if updateStatus in (PluginStatus.LocalUpdate, PluginStatus.RemoteUpdate):
861 self.__updateRemoteItems += 1 904 status = "upgrade"
862 elif updateStatus == PluginStatus.Error: 905
863 itm.setIcon(iconColumn, EricPixmapCache.getIcon("warning")) 906 statusItem = self.__statusItems[status]
864 itm.setToolTip(iconColumn, self.tr("error determining status")) 907 if statusItem is None:
908 statusItem = QTreeWidgetItem(self.repositoryList, [""])
909 statusItem.setExpanded(True)
910 statusItem.setFirstColumnSpanned(True)
911 self.__statusItems[status] = statusItem
912
913 self.__addPluginItem(
914 statusItem,
915 name,
916 short,
917 description,
918 url,
919 author,
920 version,
921 filename,
922 updateStatus,
923 countIt=False,
924 )
865 925
866 def __updateStatus(self, filename, version): 926 def __updateStatus(self, filename, version):
867 """ 927 """
868 Private method to check the given archive update status. 928 Private method to check the given archive update status.
869 929
925 return PluginStatus.LocalUpdate 985 return PluginStatus.LocalUpdate
926 else: 986 else:
927 return PluginStatus.UpToDate 987 return PluginStatus.UpToDate
928 else: 988 else:
929 return PluginStatus.RemoteUpdate 989 return PluginStatus.RemoteUpdate
990
991 def __updateStatusItemTexts(self):
992 """
993 Private method to update the status item texts to include a number determined
994 by a given status order.
995 """
996 index = 1
997 for status in self.__statusOrder:
998 statusItem = self.__statusItems[status]
999 if statusItem is not None:
1000 statusItem.setText(
1001 0,
1002 self.tr("{0}. {1}").format(
1003 index, self.__statusTranslations[status]
1004 ),
1005 )
1006 index += 1
930 1007
931 def __sslErrors(self, reply, errors): 1008 def __sslErrors(self, reply, errors):
932 """ 1009 """
933 Private slot to handle SSL errors. 1010 Private slot to handle SSL errors.
934 1011

eric ide

mercurial