def importClicked(self):
        if self.repo is None:
            connector = PyQtConnectorDecorator()
            connector.checkIsAlive()
            self.repo = Repository(self.repos[self.repoCombo.currentText()], connector)
        if self.layer is None:
            text = self.layerCombo.currentText()
            self.layer = resolveLayer(text)

        source = self.layer.source()
        hasIdField = self.layer.dataProvider().fieldNameIndex("geogigid") != -1

        if not hasIdField:
            autoAddId = config.getConfigValue(config.GENERAL, config.AUTO_ADD_ID)
            if not autoAddId:
                dlg = AddGeogigIdDialog(self)
                ok, check = dlg.exec_()
                if ok == QtGui.QMessageBox.No:
                    self.close()
                    return
                if check:
                    config.setConfigValue(config.GENERAL, config.AUTO_ADD_ID, True)

            QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
            addIdField(self.layer)
            QtGui.QApplication.restoreOverrideCursor()
            hasIdField = self.layer.dataProvider().fieldNameIndex("geogigid") != -1
            if not hasIdField:
                QtGui.QMessageBox.warning(self, "Error",
                            "Could not add 'geogigid' field to layer.\n"
                            "Possible causes for this are:\n"
                            "- No permission to edit the layer.\n",
                            QtGui.QMessageBox.Ok, QtGui.QMessageBox.Ok)
                return

        # determine encoding
        # first look in .cpg file
        cpgPath = source.replace('.shp', '.cpg')
        if os.path.exists(cpgPath):
            with open(cpgPath) as f:
                charset = f.readline().strip('\r\n')
        else:
            # try to get encoding from provider
            charset = self.layer.dataProvider().encoding()
            if charset.lower() == 'system':
                # get encoding from system
                charset = locale.getpreferredencoding()

        self.repo.importshp(source, False, self.layer.name(), "geogigid", True, charset)
        message = self.messageBox.toPlainText()
        self.repo.add()
        try:
            self.repo.commit(message)
        except UnconfiguredUserException, e:
            configureUser()
            self.repo.commit(message)
    def importClicked(self):
        if self.repo is None:
            connector = PyQtConnectorDecorator()
            connector.checkIsAlive()
            self.repo = Repository(self.repos[self.repoCombo.currentText()], connector)
        if self.layer is None:
            text = self.layerCombo.currentText()
            self.layer = resolveLayer(text)

        source = self.layer.source()
        hasIdField = self.layer.dataProvider().fieldNameIndex("geogigid") != -1

        if not hasIdField:
            autoAddId = config.getConfigValue(config.GENERAL, config.AUTO_ADD_ID)
            if not autoAddId:
                dlg = AddGeogigIdDialog(self)
                ok, check = dlg.exec_()
                if ok == QtGui.QMessageBox.No:
                    self.close()
                    return
                if check:
                    config.setConfigValue(config.GENERAL, config.AUTO_ADD_ID, True)

            QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
            addIdField(self.layer)
            QtGui.QApplication.restoreOverrideCursor()
            hasIdField = self.layer.dataProvider().fieldNameIndex("geogigid") != -1
            if not hasIdField:
                QtGui.QMessageBox.warning(self, "Error",
                            "Could not add 'geogigid' field to layer.\n"
                            "Possible causes for this are:\n"
                            "- No permission to edit the layer.\n",
                            QtGui.QMessageBox.Ok, QtGui.QMessageBox.Ok)
                return

        self.repo.importshp(source, False, self.layer.name(), "geogigid", True)
        message = self.messageBox.toPlainText()
        self.repo.add()
        try:
            self.repo.commit(message)
        except UnconfiguredUserException, e:
            configdlg = UserConfigDialog(config.iface.mainWindow())
            configdlg.exec_()
            if configdlg.user is not None:
                self.repo.config(geogig.USER_NAME, configdlg.user)
                self.repo.config(geogig.USER_EMAIL, configdlg.email)
                self.repo.commit(message)
            else:
                return
    def importClicked(self):
        if self.repo is None:
            connector = PyQtConnectorDecorator()
            connector.checkIsAlive()
            self.repo = Repository(self.repos[self.repoCombo.currentText()],
                                   connector)
        if self.layer is None:
            text = self.layerCombo.currentText()
            self.layer = resolveLayer(text)

        source = self.layer.source()
        hasIdField = self.layer.dataProvider().fieldNameIndex("geogigid") != -1

        if not hasIdField:
            autoAddId = config.getConfigValue(config.GENERAL,
                                              config.AUTO_ADD_ID)
            if not autoAddId:
                dlg = AddGeogigIdDialog(self)
                ok, check = dlg.exec_()
                if ok == QtGui.QMessageBox.No:
                    self.close()
                    return
                if check:
                    config.setConfigValue(config.GENERAL, config.AUTO_ADD_ID,
                                          True)

            QtGui.QApplication.setOverrideCursor(
                QtGui.QCursor(QtCore.Qt.WaitCursor))
            addIdField(self.layer)
            QtGui.QApplication.restoreOverrideCursor()
            hasIdField = self.layer.dataProvider().fieldNameIndex(
                "geogigid") != -1
            if not hasIdField:
                QtGui.QMessageBox.warning(
                    self, "Error", "Could not add 'geogigid' field to layer.\n"
                    "Possible causes for this are:\n"
                    "- No permission to edit the layer.\n",
                    QtGui.QMessageBox.Ok, QtGui.QMessageBox.Ok)
                return

        # determine encoding
        # first look in .cpg file
        cpgPath = source.replace('.shp', '.cpg')
        if os.path.exists(cpgPath):
            with open(cpgPath) as f:
                charset = f.readline().strip('\r\n')
        else:
            # try to get encoding from provider
            charset = self.layer.dataProvider().encoding()
            if charset.lower() == 'system':
                # get encoding from system
                charset = locale.getpreferredencoding()

        self.repo.importshp(source, False, self.layer.name(), "geogigid", True,
                            charset)
        message = self.messageBox.toPlainText()
        self.repo.add()
        try:
            self.repo.commit(message)
        except UnconfiguredUserException, e:
            configureUser()
            self.repo.commit(message)