Hide QVariant from the ui implementation, and make a refactoring of the validation...
authorduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Fri, 9 Jan 2009 15:49:48 +0000 (15:49 +0000)
committerduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Fri, 9 Jan 2009 15:49:48 +0000 (15:49 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2152 38d2e660-2303-0410-9eaa-f027e97ec537

wizard/BToolchainPage.py
wizard/BToolchainSearch.py
wizard/BWizardPage.py
wizard/bertos_utils.py
wizard/qvariant_converter.py

index d9ea7687da2f0b27c9918ff00558b468c1db6824..2383c3933a5c8c40a4927a65ef0223fff39ebd89 100644 (file)
@@ -22,7 +22,7 @@ class BToolchainPage(BWizardPage):
         BWizardPage.__init__(self, "toolchain_select.ui")
         self.setTitle(self.tr("Select toolchain"))
         self._validationProcess = None
-        self._populateToolchainList()
+        #self._populateToolchainList()
         self._connectSignals()
     
     def _updateUi(self):
@@ -37,11 +37,13 @@ class BToolchainPage(BWizardPage):
     
     def _populateToolchainList(self):
         toolchains = self.toolchains()
-        for element in toolchains:
-            item = QListWidgetItem(element)
-            item.setData(Qt.UserRole, qvariant_converter.convertString(element))
+        for key, value in toolchains.items():
+            item = QListWidgetItem(key)
+            item.setData(Qt.UserRole, qvariant_converter.convertString(key))
             self.pageContent.toolchainList.addItem(item)
-            
+            if value:
+                self.validateToolchain(self.pageContent.toolchainList.row(item))
+
     def _clearList(self):
         self.pageContent.toolchainList.clear()
     
@@ -53,20 +55,21 @@ class BToolchainPage(BWizardPage):
         if(self.pathSearch()):
             dirList += [element for element in bertos_utils.getSystemPath()]
         toolchainList = bertos_utils.findToolchains(dirList)
-        storedToolchainList = self.toolchains()
-        toolchainList = set(toolchainList) - set(storedToolchainList)
+        storedToolchains = self.toolchains()
         for element in toolchainList:
-            item = QListWidgetItem(element)
-            item.setData(Qt.UserRole, qvariant_converter.convertString(element))
-            self.pageContent.toolchainList.addItem(item)
-        self.setToolchains(list(toolchainList.union(storedToolchainList)))
+            if not element in storedToolchains.keys():
+                item = QListWidgetItem(element)
+                item.setData(Qt.UserRole, qvariant_converter.convertString(element))
+                self.pageContent.toolchainList.addItem(item)
+                storedToolchains[element] = False
+        self.setToolchains(storedToolchains)
         
     def _connectSignals(self):
         self.connect(self.pageContent.toolchainList, SIGNAL("itemSelectionChanged()"), self._selectionChanged)
         self.connect(self.pageContent.addButton, SIGNAL("clicked()"), self.addToolchain)
         self.connect(self.pageContent.removeButton, SIGNAL("clicked()"), self.removeToolchain)
         self.connect(self.pageContent.searchButton, SIGNAL("clicked()"), self.searchToolchain)
-        self.connect(self.pageContent.checkButton, SIGNAL("clicked()"), self.validateToolchains)
+        self.connect(self.pageContent.checkButton, SIGNAL("clicked()"), self.validateAllToolchains)
     
     def _validItem(self, index, infos):
         item = self.pageContent.toolchainList.item(index)
@@ -75,7 +78,7 @@ class BToolchainPage(BWizardPage):
             item.setIcon(QIcon(":/images/ok.png"))
         else:
             item.setIcon(QIcon(":/images/warning.png"))
-        item.setText("GCC " + infos["version"] + " " + infos["target"])
+        item.setText("GCC " + infos["version"] + " " + infos["target"])
     
     def _invalidItem(self, index):
         item = self.pageContent.toolchainList.item(index)
@@ -88,15 +91,15 @@ class BToolchainPage(BWizardPage):
             item.setData(Qt.UserRole, qvariant_converter.convertString(sel_toolchain))
             self.pageContent.toolchainList.addItem(item)
             toolchains = self.toolchains()
-            toolchains = set(toolchains + [sel_toolchain])
-            self.setToolchains(list(toolchains))
+            toolchains[sel_toolchain] = False
+            self.setToolchains(toolchains)
     
     def removeToolchain(self):
         if self.pageContent.toolchainList.currentRow() != -1:
             item = self.pageContent.toolchainList.takeItem(self.pageContent.toolchainList.currentRow())
             toolchain = qvariant_converter.getString(item.data(Qt.UserRole))
             toolchains = self.toolchains()
-            toolchains.remove(toolchain)
+            del toolchains[toolchain]
             self.setToolchains(toolchains)
     
     def searchToolchain(self):
@@ -104,22 +107,28 @@ class BToolchainPage(BWizardPage):
         self.connect(search, SIGNAL("accepted()"), self._search)
         search.exec_()
     
-    def validateToolchains(self):
+    def validateAllToolchains(self):
         for i in range(self.pageContent.toolchainList.count()):
-            filename = qvariant_converter.getString(self.pageContent.toolchainList.item(i).data(Qt.UserRole))
-            self._validationProcess = QProcess()
-            self._validationProcess.start(filename, ["-v"])
-            self._validationProcess.waitForStarted(1000)
-            if self._validationProcess.waitForFinished(200):
-                description = str(self._validationProcess.readAllStandardError())
-                infos = bertos_utils.getToolchainInfo(description)
-                if len(infos.keys()) >= 4:
-                    self._validItem(i, infos)
-                else:
-                    self._invalidItem(i)
+            self.validateToolchain(i)
+    
+    def validateToolchain(self, i):
+        filename = qvariant_converter.getString(self.pageContent.toolchainList.item(i).data(Qt.UserRole))
+        self._validationProcess = QProcess()
+        self._validationProcess.start(filename, ["-v"])
+        self._validationProcess.waitForStarted(1000)
+        if self._validationProcess.waitForFinished(200):
+            description = str(self._validationProcess.readAllStandardError())
+            infos = bertos_utils.getToolchainInfo(description)
+            if len(infos.keys()) >= 4:
+                self._validItem(i, infos)
             else:
-                self._validationProcess.kill()
                 self._invalidItem(i)
+        else:
+            self._validationProcess.kill()
+            self._invalidItem(i)
+        toolchains = self.toolchains()
+        toolchains[filename] = True
+        self.setToolchains(toolchains)
     
     def isComplete(self):
         if self.pageContent.toolchainList.currentRow() != -1:
@@ -127,4 +136,8 @@ class BToolchainPage(BWizardPage):
                 qvariant_converter.getString(self.pageContent.toolchainList.item(self.pageContent.toolchainList.currentRow()).data(Qt.UserRole)))
             return True
         else:
-            return False
\ No newline at end of file
+            return False
+    
+    def reloadData(self):
+        self._clearList()
+        self._populateToolchainList()
\ No newline at end of file
index b568dea235766e8be89fab9d2a4e89ff0381bd29..c2f57e346cbbcfef9d4fff9ea2390c1a21cda64d 100644 (file)
@@ -63,9 +63,9 @@ class BToolchainSearch(QDialog):
             directory = unicode(directory)
             item = QListWidgetItem(directory)
             self.content.customDirList.addItem(item)
-            search_dir_list = qvariant_conveter.getStringList(QApplication.instance().settings.value("search_dir_list"))
+            search_dir_list = qvariant_converter.getStringList(QApplication.instance().settings.value("search_dir_list"))
             search_dir_list = set(search_dir_list + [directory])
-            QApplication.instance().settings.setValue(QString("search_dir_list"), QVariant(list(search_dir_list)))
+            QApplication.instance().settings.setValue(QString("search_dir_list"), convertStringList(list(search_dir_list)))
             self._setSearchButton()
     
     def _removeDir(self):
@@ -73,7 +73,7 @@ class BToolchainSearch(QDialog):
             item = self.content.customDirList.takeItem(self.content.customDirList.currentRow())
             search_dir_list = qvariant_converter.getStringList(QApplication.instance().settings.value(QString("search_dir_list")))
             search_dir_list = set(search_dir_list)
-            search_dir_list.remove(item.text())
-            QApplication.instance().settings.setValue(QString("search_dir_list"), QVariant(list(search_dir_list)))
+            search_dir_list.remove(unicode(item.text()))
+            QApplication.instance().settings.setValue(QString("search_dir_list"), qvariant_converter.convertStringList(list(search_dir_list)))
             self._setSearchButton()
     
\ No newline at end of file
index 5e5569ab8362a5ce8e32df2ab4ae55e51ea4e9c7..b4fc6217025419c244c07c57af0743e68ca89319 100644 (file)
@@ -55,10 +55,10 @@ class BWizardPage(QWizardPage):
         self._settingsStore("path_search", qvariant_converter.convertBool(path_search))
     
     def toolchains(self):
-        return qvariant_converter.getStringList(self._settingsRetrieve("toolchains"))
+        return qvariant_converter.getBoolDict(self._settingsRetrieve("toolchains"))
 
     def setToolchains(self, toolchains):
-        self._settingsStore("toolchains", qvariant_converter.convertStringList(toolchains))
+        self._settingsStore("toolchains", qvariant_converter.convertBoolDict(toolchains))
     
     def reloadData(self):
         pass
\ No newline at end of file
index 3af061ef2a69e828e52ffca7757259efcc711720..89998949b1952aa7adfaeeccc63dd573a174f8e3 100644 (file)
@@ -38,7 +38,9 @@ def getSystemPath():
 def findToolchains(pathList):
     toolchains = []
     for element in pathList:
-        toolchains += glob.glob(element+ "/" + const.GCC_NAME)
+        for toolchain in glob.glob(element+ "/" + const.GCC_NAME):
+            if not os.path.islink(toolchain):
+                toolchains.append(toolchain)
     return toolchains
 
 def getToolchainInfo(output):
index c0c5431e6063a6d2c40a9586dac93dca47083431..9e3b3ed83e098276618ef61b073505202d98143c 100644 (file)
@@ -43,6 +43,18 @@ def getBool(qvariant):
 def convertBool(boolean):
     return QVariant(boolean)
 
+def getBoolDict(qvariant):
+    dict_str_bool = {}
+    for key, value in qvariant.toMap().items():
+        dict_str_bool[unicode(key)] = value.toBool()
+    return dict_str_bool
+
+def convertBoolDict(dict_str_bool):
+    result_dict = {}
+    for key, value in dict_str_bool.items():
+        result_dict[QString(key)] = value
+    return QVariant(result_dict)
+
 def getDict(qvariant):
     dict_str_variant = {}
     for key, value in qvariant.toMap().items():