Add the bertos versions in the settings
authorduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 15 Dec 2008 14:34:11 +0000 (14:34 +0000)
committerduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 15 Dec 2008 14:34:11 +0000 (14:34 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2031 38d2e660-2303-0410-9eaa-f027e97ec537

wizard/BVersionPage.py

index 48bc75bbd5dc619eebfc981b2049b146f6109184..752ace0efd89ed7fd798a5c0b25d317f24e37f43 100644 (file)
@@ -18,6 +18,7 @@ class BVersionPage(BWizardPage):
     def __init__(self):
         BWizardPage.__init__(self, "bertos_versions.ui")
         self._connectSignals()
+        self._fillVersionList()
         self._setupUi()
         self.setTitle(self.tr("Select the beRTOS version needed"))
     
@@ -31,17 +32,42 @@ class BVersionPage(BWizardPage):
     def _setupUi(self):
         pass
     
-    def addVersion(self):
-        directory = QFileDialog.getExistingDirectory(self, self.tr("Choose a directory"), QString(), QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks)
+    def _storeVersion(self, directory):
+        versions = self._settingsRetrieve("versions").toList()
+        versions = set([x.toString() for x in versions] + [directory])
+        self._settingsStore("versions", list(versions))
+    
+    def _deleteVersion(self, directory):
+        versions = self._settingsRetrieve(QString("versions")).toList()
+        versions = [x.toString() for x in versions]
+        versions.remove(directory)
+        self._settingsStore("versions", versions)
+        
+    def _insertListElement(self, directory):
         if bertos_utils.isBertosDir(directory):
-            version = bertos_utils.bertosVersion(directory)
-            self.pageContent.versionList.addItem(QListWidgetItem(QIcon(":/images/ok.png"), version + " (\"" + directory + "\")"))
+            item = QListWidgetItem(QIcon(":/images/ok.png"), bertos_utils.bertosVersion(directory) + " (\"" + directory + "\")")
+            item.setData(Qt.UserRole, QVariant(directory))
+            self.pageContent.versionList.addItem(item)
         elif not directory.isEmpty():
-            version = "UNCHECKED"
-            self.pageContent.versionList.addItem(QListWidgetItem(QIcon(":/images/warning.png"), version + " (\"" + directory + "\")"))
+            item = QListWidgetItem(QIcon(":/images/warning.png"), "UNKNOWN" + " (\"" + directory + "\")")
+            item.setData(Qt.UserRole, QVariant(directory))
+            self.pageContent.versionList.addItem(item)
+    
+    def _fillVersionList(self):
+        versions = self._settingsRetrieve("versions").toList()
+        for directory in versions:
+            self._insertListElement(directory.toString())
+
+    def addVersion(self):
+        directory = QFileDialog.getExistingDirectory(self, self.tr("Choose a directory"), "", QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks)
+        if not directory.isEmpty():
+            self._storeVersion(directory)
+            self.pageContent.versionList.clear()
+            self._fillVersionList()
     
     def removeVersion(self):
-        self.pageContent.versionList.takeItem(self.pageContent.versionList.currentRow())
+        item = self.pageContent.versionList.takeItem(self.pageContent.versionList.currentRow())
+        self._deleteVersion(item.data(Qt.UserRole).toString())
     
     def updateClicked(self):
         print "fake update checking"