Пример #1
0
    def __model_exception_process(self, job, exception, level, trace=None):
        msg, msg_ext, icon = self.__get_model_exception_description(job, exception)

        if exception.__class__ == JobAuthorizationError:
            name_of_conn = NgwPluginSettings.get_selected_ngw_connection_name()
            conn_sett = NgwPluginSettings.get_ngw_connection(name_of_conn)
            dlg = NGWConnectionEditDialog(ngw_connection_settings=conn_sett, only_password_change=True)
            dlg.setWindowTitle(
                self.tr("Access denied. Enter your login.")
            )
            res = dlg.exec_()
            if res:
                conn_sett = dlg.ngw_connection_settings
                NgwPluginSettings.save_ngw_connection(conn_sett)
                self.reinit_tree()
            del dlg
        else:
            if msg is not None:
                self.__msg_in_qgis_mes_bar(
                    msg,
                    msg_ext is not None,
                    level=level
                )

            if msg_ext is not None:
                qgisLog(msg + "\n" + msg_ext)
Пример #2
0
    def __init__(self, parent=None):
        super(SettingsDialog, self).__init__(parent)
        self.setupUi(self)
        # self.setFixedSize(self.size())

        self.btnNew.clicked.connect(self.new_connection)
        self.btnEdit.clicked.connect(self.edit_connection)
        self.btnDelete.clicked.connect(self.delete_connection)

        self.populate_connection_list()

        self.chSanitizeRenameFields.setCheckState(
            QtCore.Qt.Checked if NgwApiSettings.get_sanitize_rename_fields() else QtCore.Qt.Unchecked
        )
        self.chSanitizeRenameFields.stateChanged.connect(self.sanitizeOptionsChanged)

        self.chSanitizeFixGeometry.setCheckState(
            QtCore.Qt.Checked if NgwApiSettings.get_sanitize_fix_geometry() else QtCore.Qt.Unchecked
        )
        self.chSanitizeFixGeometry.stateChanged.connect(self.sanitizeOptionsChanged)

        self.cbForceImport.setCheckState(
            QtCore.Qt.Unchecked if NgwApiSettings.get_force_qgis_project_import() else QtCore.Qt.Checked
        )
        self.cbForceImport.stateChanged.connect(self.forceImportChanged)

        self.cbAutoOpenWebMap.setCheckState(
            QtCore.Qt.Checked if PluginSettings.auto_open_web_map_option() else QtCore.Qt.Unchecked
        )
        self.cbAutoOpenWebMap.stateChanged.connect(self.autoOpenWebMapChanged)

        self.cbAutoAddWFS.setCheckState(
            QtCore.Qt.Checked if PluginSettings.auto_add_wfs_option() else QtCore.Qt.Unchecked
        )
        self.cbAutoAddWFS.stateChanged.connect(self.autoAddWFSChanged)
Пример #3
0
 def new_connection(self):
     dlg = NGWConnectionEditDialog()
     if dlg.exec_():
         conn_sett = dlg.ngw_connection_settings
         PluginSettings.save_ngw_connection(conn_sett)
         PluginSettings.set_selected_ngw_connection_name(conn_sett.connection_name)
         self.populate_connection_list()
     del dlg
Пример #4
0
 def new_connection(self):
     dlg = NGWConnectionEditDialog()
     if dlg.exec_():
         conn_sett = dlg.ngw_connection_settings
         NgwApiSettings.save_ngw_connection(conn_sett)
         NgwApiSettings.set_selected_ngw_connection_name(conn_sett.connection_name)
         self.populate_connection_list()
     del dlg
Пример #5
0
    def sanitizeOptionsChanged(self, state):
        optionWidget = self.sender()

        option = (state == QtCore.Qt.Checked)

        if optionWidget is self.chSanitizeRenameFields:
            NgwApiSettings.set_sanitize_rename_fields(option)

        if optionWidget is self.chSanitizeFixGeometry:
            NgwApiSettings.set_sanitize_fix_geometry(option)
Пример #6
0
    def populate_connection_list(self):
        self.cmbConnections.clear()
        self.cmbConnections.addItems(PluginSettings.get_ngw_connection_names())

        last_connection = PluginSettings.get_selected_ngw_connection_name()
        idx = self.cmbConnections.findText(last_connection)
        if idx == -1 and self.cmbConnections.count() > 0:
            self.cmbConnections.setCurrentIndex(0)
        else:
            self.cmbConnections.setCurrentIndex(idx)

        if self.cmbConnections.count() == 0:
            self.btnEdit.setEnabled(False)
            self.btnDelete.setEnabled(False)
        else:
            self.btnEdit.setEnabled(True)
            self.btnDelete.setEnabled(True)
Пример #7
0
    def populate_connection_list(self):
        self.cmbConnections.clear()
        self.cmbConnections.addItems(NgwApiSettings.get_ngw_connection_names())

        last_connection = NgwApiSettings.get_selected_ngw_connection_name()

        idx = self.cmbConnections.findText(last_connection)
        if idx == -1 and self.cmbConnections.count() > 0:
            self.cmbConnections.setCurrentIndex(0)
        else:
            self.cmbConnections.setCurrentIndex(idx)

        if self.cmbConnections.count() == 0:
            self.btnEdit.setEnabled(False)
            self.btnDelete.setEnabled(False)
        else:
            self.btnEdit.setEnabled(True)
            self.btnDelete.setEnabled(True)
Пример #8
0
    def __ngw_error_process(self, exception, level, prefix=""):
        try:
            exeption_dict = json.loads(exception.message)
            exeption_type = exeption_dict.get("exception")

            name_of_conn = NgwPluginSettings.get_selected_ngw_connection_name()

            if exeption_type in ["HTTPForbidden", "ForbiddenError"]:

                self.__msg_in_qgis_mes_bar("WebGIS access denied", level=level)

                conn_sett = NgwPluginSettings.get_ngw_connection(name_of_conn)
                dlg = NGWConnectionEditDialog(
                    ngw_connection_settings=conn_sett,
                    only_password_change=True)
                dlg.setWindowTitle(self.tr("Access denied. Enter your login."))
                res = dlg.exec_()
                if res:
                    conn_sett = dlg.ngw_connection_settings
                    NgwPluginSettings.save_ngw_connection(conn_sett)
                    self.reinit_tree()
                del dlg

            elif exeption_type == "ConnectionError":
                self.__msg_in_qgis_mes_bar(
                    prefix + "Webgis connection failed. See logs for detail.",
                    level=level)
                qgisLog(
                    prefix + "Webgis connection failed: %s" %
                    exeption_dict.get("message", ""), )

            else:
                self.__msg_in_qgis_mes_bar(prefix + "WebGIS answered - " +
                                           exeption_dict.get("message", ""),
                                           level=level)

        except Exception:
            self.__msg_in_qgis_mes_bar(prefix +
                                       "Received unknown error. See logs.",
                                       level=level)
            qgisLog(prefix + "Received unknown error. See logs.", )
            qgisLog(exception.message, )
Пример #9
0
    def reinit_tree(self):
        # clear tree and states
        self.disable_tools()

        # ----------------------------------------------
        # Configurate new WebGIS InfoWidget
        # This widget may be useful in the future
        # Check show message for creation new web gis
        # if not PluginSettings.webgis_creation_message_closed_by_user():
        #     for conn_name in NgwPluginSettings.get_ngw_connection_names():
        #         conn_settings = NgwPluginSettings.get_ngw_connection(conn_name)
        #         o = urlparse(conn_settings.server_url)
        #         if o.hostname.find("nextgis.com") != -1:
        #             self.webGISCreationMessageWidget.setVisible(False)
        #             break
        # ----------------------------------------------

        name_of_conn = NgwPluginSettings.get_selected_ngw_connection_name()
        if not name_of_conn:
            self.trvResources.showWelcomeMessage()
            self._resource_model.cleanModel()
            return

        self.trvResources.hideWelcomeMessage()

        conn_sett = NgwPluginSettings.get_ngw_connection(name_of_conn)

        if not conn_sett:
            return

        self._resource_model.resetModel(conn_sett)

        # expand root item
        # self.trvResources.setExpanded(self._resource_model.index(0, 0, QModelIndex()), True)

        # reconnect signals
        self.trvResources.selectionModel().currentChanged.connect(self.active_item_chg)
Пример #10
0
    def edit_connection(self):
        conn_name = self.cmbConnections.currentText()
        conn_sett = None

        if conn_name is not None:
            conn_sett = PluginSettings.get_ngw_connection(conn_name)

        dlg = NGWConnectionEditDialog(ngw_connection_settings=conn_sett)
        dlg.setWindowTitle(self.tr("Edit connection"))
        if dlg.exec_():
            new_conn_sett = dlg.ngw_connection_settings
            # if conn was renamed - remove old
            if conn_name is not None and conn_name != new_conn_sett.connection_name:
                PluginSettings.remove_ngw_connection(conn_name)
            # save new
            PluginSettings.save_ngw_connection(new_conn_sett)
            PluginSettings.set_selected_ngw_connection_name(new_conn_sett.connection_name)

            self.populate_connection_list()
        del dlg
Пример #11
0
    def edit_connection(self):
        conn_name = self.cmbConnections.currentText()
        conn_sett = None

        if conn_name is not None:
            conn_sett = NgwApiSettings.get_ngw_connection(conn_name)

        dlg = NGWConnectionEditDialog(ngw_connection_settings=conn_sett)
        dlg.setWindowTitle(self.tr("Edit connection"))
        if dlg.exec_():
            new_conn_sett = dlg.ngw_connection_settings
            # if conn was renamed - remove old
            if conn_name is not None and conn_name != new_conn_sett.connection_name:
                NgwApiSettings.remove_ngw_connection(conn_name)
            # save new
            NgwApiSettings.save_ngw_connection(new_conn_sett)
            NgwApiSettings.set_selected_ngw_connection_name(new_conn_sett.connection_name)

            self.populate_connection_list()
        del dlg
Пример #12
0
 def reject(self):
     PluginSettings.set_selected_ngw_connection_name(self.cmbConnections.currentText())
     QDialog.reject(self)
Пример #13
0
    def reinit_tree(self, force=False):
        # clear tree and states
        self.disable_tools()

        # ----------------------------------------------
        # Configurate new WebGIS InfoWidget
        # This widget may be useful in the future
        # Check show message for creation new web gis
        # if not PluginSettings.webgis_creation_message_closed_by_user():
        #     for conn_name in NgwPluginSettings.get_ngw_connection_names():
        #         conn_settings = NgwPluginSettings.get_ngw_connection(conn_name)
        #         o = urlparse(conn_settings.server_url)
        #         if o.hostname.find("nextgis.com") != -1:
        #             self.webGISCreationMessageWidget.setVisible(False)
        #             break
        # ----------------------------------------------

        name_of_conn = NgwPluginSettings.get_selected_ngw_connection_name()
        if not name_of_conn:
            self.trvResources.showWelcomeMessage()
            self._resource_model.cleanModel()
            return

        self.trvResources.hideWelcomeMessage()

        conn_sett = NgwPluginSettings.get_ngw_connection(name_of_conn)

        if not conn_sett:
            return

        s = QSettings()
        proxyEnabled = s.value("proxy/proxyEnabled", u"", type=unicode)
        proxy_type = s.value("proxy/proxyType", u"", type=unicode)
        proxy_host = s.value("proxy/proxyHost", u"", type=unicode)
        proxy_port = s.value("proxy/proxyPort", u"", type=unicode)
        proxy_user = s.value("proxy/proxyUser", u"", type=unicode)
        proxy_password = s.value("proxy/proxyPassword", u"", type=unicode)

        if proxyEnabled == "true":
            if proxy_type == "DefaultProxy":
                qgsNetMan = QgsNetworkAccessManager.instance()
                proxy = qgsNetMan.proxy().applicationProxy()
                proxy_host = proxy.hostName()
                proxy_port = str(proxy.port())
                proxy_user = proxy.user()
                proxy_password = proxy.password()

            if proxy_type in ["DefaultProxy", "Socks5Proxy", "HttpProxy", "HttpCachingProxy"]:
                # QgsMessageLog.logMessage("%s  %s  %s  %s" % (
                #     proxy_host,
                #     proxy_port,
                #     proxy_user,
                #     proxy_password,
                # ))
                conn_sett.set_proxy(
                    proxy_host,
                    proxy_port,
                    proxy_user,
                    proxy_password
                )

        if not self._resource_model.isCurrentConnectionSame(conn_sett) or force:
            self._resource_model.resetModel(conn_sett)
Пример #14
0
 def forceImportChanged(self, state):
     option = (state != QtCore.Qt.Checked)
     NgwApiSettings.set_force_qgis_project_import(option)
Пример #15
0
 def reject(self):
     NgwApiSettings.set_selected_ngw_connection_name(self.cmbConnections.currentText())
     QtGui.QDialog.reject(self)
Пример #16
0
 def delete_connection(self):
     PluginSettings.remove_ngw_connection(self.cmbConnections.currentText())
     self.populate_connection_list()
Пример #17
0
    def __model_error_process(self, job, exception):
        qgisLog("model error process job: %d" % job)

        error_mes = "Error in unknown operation."
        if job == self._resource_model.JOB_LOAD_NGW_RESOURCE_CHILDREN:
            error_mes = self.tr("Loading resource error. Check your connection settings.")
        elif job == self._resource_model.JOB_CREATE_NGW_GROUP_RESOURCE:
            error_mes = self.tr("Creating group resource error.")
        elif job == self._resource_model.JOB_IMPORT_QGIS_RESOURCE:
            error_mes = self.tr("Creating layer resource error.")
        elif job == self._resource_model.JOB_CREATE_NGW_WFS_SERVICE:
            error_mes = self.tr("Creating WFS service error. See log for details.")

        error_mes += " " + self.tr("See log for details.")

        self.iface.messageBar().pushMessage(
            self.tr('Error'),
            error_mes,
            level=QgsMessageBar.CRITICAL
        )

        if isinstance(exception, NGWError):
            try:
                exeption_dict = json.loads(exception.message)
                exeption_type = exeption_dict.get("exception", "")

                name_of_conn = NgwPluginSettings.get_selected_ngw_connection_name()

                if exeption_type in ["HTTPForbidden", "ForbiddenError"]:
                    conn_sett = NgwPluginSettings.get_ngw_connection(name_of_conn)
                    print "conn_sett: ", conn_sett
                    dlg = NGWConnectionEditDialog(ngw_connection_settings=conn_sett, only_password_change=True)
                    dlg.setWindowTitle(
                        self.tr("Access denied. Enter your login.")
                    )
                    res = dlg.exec_()
                    QgsMessageLog.logMessage("res: %d" % res)
                    if res:
                        conn_sett = dlg.ngw_connection_settings
                        NgwPluginSettings.save_ngw_connection(conn_sett)
                        self.reinit_tree()
                    del dlg

                ngw_err_msg = exeption_dict.get("message", "")

                qgisLog(
                    "%s\n\t %s" % (error_mes, ngw_err_msg),
                    level=QgsMessageLog.CRITICAL
                )

            except Exception as e:
                qgisLog(
                    "Error when proccess NGW Error: %s" % (e),
                    level=QgsMessageLog.CRITICAL
                )
        else:
            qgisLog(
                "%s\n\t %s" % (
                    error_mes,
                    exception,
                ),
                level=QgsMessageLog.CRITICAL
            )
Пример #18
0
 def delete_connection(self):
     NgwApiSettings.remove_ngw_connection(self.cmbConnections.currentText())
     self.populate_connection_list()