Add the module qvariant_converter.py that abstracts the user from the qvariant_conver...
[bertos.git] / wizard / BToolchainPage.py
index bce7471f938a06c265f5e93c843e164764c11b8f..2236fcfe3bd463eace52f6670a28ba0390a4e725 100644 (file)
@@ -9,16 +9,20 @@
 # Author: Lorenzo Berni <duplo@develer.com>
 #
 
+import os
+
 from BWizardPage import *
 import BToolchainSearch
 import bertos_utils
+import qvariant_converter
 
 class BToolchainPage(BWizardPage):
     
     def __init__(self):
         BWizardPage.__init__(self, "toolchain_select.ui")
         self.setTitle(self.tr("Select toolchain"))
-        self._populateToolchainList()
+        self._validationProcess = None
+        #self._populateToolchainList()
         self._connectSignals()
     
     def _updateUi(self):
@@ -32,12 +36,14 @@ class BToolchainPage(BWizardPage):
             self.pageContent.doSearchButton.setEnabled(False)
     
     def _populateToolchainList(self):
-        toolchains = self._settingsRetrieve("toolchains").toList()
-        for element in toolchains:
-            item = QListWidgetItem(element.toString())
-            item.setData(Qt.UserRole, element)
+        toolchains = self.toolchains()
+        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()
     
@@ -45,42 +51,93 @@ class BToolchainPage(BWizardPage):
         self.emit(SIGNAL("completeChanged()"))
     
     def _search(self):
-        pass
+        dirList = self.searchDirList()
+        if(self.pathSearch()):
+            dirList += [element for element in bertos_utils.getSystemPath()]
+        toolchainList = bertos_utils.findToolchains(dirList)
+        storedToolchains = self.toolchains()
+        for element in toolchainList:
+            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.validateAllToolchains)
+    
+    def _validItem(self, index, infos):
+        item = self.pageContent.toolchainList.item(index)
+        needed = self._projectInfoRetrieve("CPU_INFOS")
+        if infos["target"].find(qvariant_converter.getString(needed["TOOLCHAIN"])) != -1:
+            item.setIcon(QIcon(":/images/ok.png"))
+        else:
+            item.setIcon(QIcon(":/images/warning.png"))
+        item.setText("GCC " + infos["version"] + " - " + infos["target"])
+    
+    def _invalidItem(self, index):
+        item = self.pageContent.toolchainList.item(index)
+        item.setIcon(QIcon(":/images/error.png"))
     
     def addToolchain(self):
         sel_toolchain = QFileDialog.getOpenFileName(self, self.tr("Choose the toolchain"), "")
         if not sel_toolchain.isEmpty():
             item = QListWidgetItem(sel_toolchain)
-            item.setData(Qt.UserRole, QVariant(sel_toolchain))
+            item.setData(Qt.UserRole, qvariant_converter.convertString(sel_toolchain))
             self.pageContent.toolchainList.addItem(item)
-            toolchains = self._settingsRetrieve("toolchains").toList()
-            toolchains = set([toolchain.toString() for toolchain in toolchains] + [sel_toolchain])
-            self._settingsStore("toolchains", list(toolchains))
+            toolchains = self.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())
-            item = item.data(Qt.UserRole).toString()
-            toolchains = self._settingsRetrieve("toolchains").toList()
-            toolchains = [toolchain.toString() for toolchain in toolchains]
-            toolchains.remove(unicode(item))
-            self._settingsStore("toolchains", toolchains)
+            toolchain = qvariant_converter.getString(item.data(Qt.UserRole))
+            toolchains = self.toolchains()
+            del toolchains[toolchain]
+            self.setToolchains(toolchains)
     
     def searchToolchain(self):
         search = BToolchainSearch.BToolchainSearch()
         self.connect(search, SIGNAL("accepted()"), self._search)
         search.exec_()
     
+    def validateAllToolchains(self):
+        for i in range(self.pageContent.toolchainList.count()):
+            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._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:
-            self._projectInfoStore("TOOLCHAIN", self.pageContent.toolchainList.item(self.pageContent.toolchainList.currentRow()).data(Qt.UserRole).toString())
+            self._projectInfoStore("TOOLCHAIN", 
+                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