def __init__(self, iface):
        QtGui.QDialog.__init__(self, iface.mainWindow())
        # Set up the user interface from Designer.
        self.ui = Ui_TransformToPostgis()
        self.ui.setupUi(self)

        settings = QSettings()
        settings.beginGroup("PostgreSQL/connections")
        self.ui.DataCon.addItems(settings.childGroups())
        settings.endGroup()

        self.ui.cmprc.addItem("Create New Table")
        self.ui.cmprc.addItem("Delete Existing Table and Create New Table")
        self.ui.cmprc.addItem("Update Existing Table")

        self.ui.cmftyp.addItem("Esri Shapefile")
        self.ui.cmftyp.addItem("MapInfo File")
        self.ui.cmftyp.addItem("GML")
        self.ui.cmftyp.addItem("ArcGIS Personal GeoDatabase")

        QtCore.QObject.connect(self.ui.btnok, QtCore.SIGNAL( "clicked()" ), self.run )
        QtCore.QObject.connect(self.ui.btnbrowse, QtCore.SIGNAL( "clicked()" ), self.OpenFileDialog )
class TransformToPostgisDialog(QtGui.QDialog):
    def __init__(self, iface):
        QtGui.QDialog.__init__(self, iface.mainWindow())
        # Set up the user interface from Designer.
        self.ui = Ui_TransformToPostgis()
        self.ui.setupUi(self)

        settings = QSettings()
        settings.beginGroup("PostgreSQL/connections")
        self.ui.DataCon.addItems(settings.childGroups())
        settings.endGroup()

        self.ui.cmprc.addItem("Create New Table")
        self.ui.cmprc.addItem("Delete Existing Table and Create New Table")
        self.ui.cmprc.addItem("Update Existing Table")

        self.ui.cmftyp.addItem("Esri Shapefile")
        self.ui.cmftyp.addItem("MapInfo File")
        self.ui.cmftyp.addItem("GML")
        self.ui.cmftyp.addItem("ArcGIS Personal GeoDatabase")

        QtCore.QObject.connect(self.ui.btnok, QtCore.SIGNAL( "clicked()" ), self.run )
        QtCore.QObject.connect(self.ui.btnbrowse, QtCore.SIGNAL( "clicked()" ), self.OpenFileDialog )


    def run(self):

        settings = QSettings()
        mysetting = self.ui.DataCon.currentText()
        mySettings = "/PostgreSQL/connections/" + mysetting

        if self.ui.cmprc.currentText() == "Create New Table" :
            command = "ogr2ogr -progress -append -f \"PostgreSQL\" PG:\"dbname="+settings.value(mySettings+"/database").toString()+" user="******"/username").toString()+" password="******"/password").toString()+"\" \""+str(self.ui.txtout.text())+"\""
            os.system(str(command))
        elif self.ui.cmprc.currentText() =="Delete Existing Table and Create New Table":
            command = "ogr2ogr -progress -overwrite -f \"PostgreSQL\" PG:\"dbname="+settings.value(mySettings+"/database").toString()+" user="******"/username").toString()+" password="******"/password").toString()+"\" \""+str(self.ui.txtout.text())+"\""
            os.system(str(command))
        else:
            command = "ogr2ogr -progress -update -f \"PostgreSQL\" PG:\"dbname="+settings.value(mySettings+"/database").toString()+" user="******"/username").toString()+" password="******"/password").toString()+"\" \""+str(self.ui.txtout.text())+"\""
            os.system(str(command))


    def OpenFileDialog(self):

        file_type = ""
        if self.ui.cmftyp.currentText() == "Esri Shapefile":
            file_type = '*.shp'
        elif self.ui.cmftyp.currentText() == "MapInfo File":
            file_type = "*.tab"
        elif self.ui.cmftyp.currentText() == "GML":
            file_type = '*.gml'
        else:
            file_type = '*.mdb *.gdb'

        settings = QtCore.QSettings()
        key = '/UI/lastShapefileDir'
        outDir = settings.value(key).toString()
        filter = 'Files ('+str(file_type)+')'
        outFilePath = QtGui.QFileDialog.getOpenFileName(self, self.tr('Select a '+str(self.ui.cmftyp.currentText())), outDir, filter)
        outFilePath = unicode(outFilePath)
        
        if outFilePath:
            root, ext = splitext(outFilePath)
            outDir = dirname(outFilePath)
            settings.setValue(key, outDir)

        self.ui.txtout.setText(QString(outFilePath))