Skip to content

Commit

Permalink
Merge pull request #290 from GeoNode/ISSUE_286
Browse files Browse the repository at this point in the history
UI improvements in the connection dialog
  • Loading branch information
giohappy authored Nov 13, 2024
2 parents 6eed6e3 + c21dbd2 commit 7075bd5
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 18 deletions.
15 changes: 15 additions & 0 deletions src/qgis_geonode/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import json
import typing
import uuid
from configparser import ConfigParser
from pathlib import Path

from qgis.PyQt import (
QtCore,
Expand Down Expand Up @@ -94,6 +96,18 @@ def to_json(self):
)


class PluginMetadata:
def prepare(self, plugin_dir):
self.plugin_dir = plugin_dir
_plugin_metadata = ConfigParser()
_plugin_metadata.read(Path(self.plugin_dir) / "metadata.txt")

self.plugin_metadata = _plugin_metadata["general"]

def get(self, attr):
return self.plugin_metadata.get(attr)


class SettingsManager(QtCore.QObject):
"""Manage saving/loading settings for the plugin in QgsSettings"""

Expand Down Expand Up @@ -303,3 +317,4 @@ def clear_current_search_filters(self):


settings_manager = SettingsManager()
plugin_metadata = PluginMetadata()
56 changes: 40 additions & 16 deletions src/qgis_geonode/gui/connection_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import typing
import uuid


import qgis.core
from qgis.gui import QgsMessageBar
from qgis.PyQt import (
Expand All @@ -16,11 +15,7 @@

from .. import apiclient, network, utils
from ..apiclient.base import BaseGeonodeClient
from ..conf import (
ConnectionSettings,
WfsVersion,
settings_manager,
)
from ..conf import ConnectionSettings, WfsVersion, settings_manager, plugin_metadata
from ..utils import tr
from packaging import version as packaging_version

Expand All @@ -38,7 +33,7 @@ class ConnectionDialog(QtWidgets.QDialog, DialogUi):
wfs_version_cb: QtWidgets.QComboBox
detect_wfs_version_pb: QtWidgets.QPushButton
network_timeout_sb: QtWidgets.QSpinBox
test_connection_pb: QtWidgets.QPushButton
connection_pb: QtWidgets.QPushButton
buttonBox: QtWidgets.QDialogButtonBox
options_gb: QtWidgets.QGroupBox
bar: qgis.gui.QgsMessageBar
Expand All @@ -57,7 +52,7 @@ def __init__(self, connection_settings: typing.Optional[ConnectionSettings] = No
super().__init__()
self.setupUi(self)
self._widgets_to_toggle_during_connection_test = [
self.test_connection_pb,
self.connection_pb,
self.buttonBox,
self.authcfg_acs,
self.options_gb,
Expand Down Expand Up @@ -92,22 +87,40 @@ def __init__(self, connection_settings: typing.Optional[ConnectionSettings] = No
self.connection_id = uuid.uuid4()
self.remote_geonode_version = None
self.update_connection_details()
self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(False)
# self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(False)
ok_signals = [
self.name_le.textChanged,
self.url_le.textChanged,
]
for signal in ok_signals:
signal.connect(self.update_ok_buttons)
self.detect_wfs_version_pb.clicked.connect(self.detect_wfs_version)
self.test_connection_pb.clicked.connect(self.test_connection)
self.connection_pb.clicked.connect(self.test_connection)
# disallow names that have a slash since that is not compatible with how we
# are storing plugin state in QgsSettings
self.name_le.setValidator(
QtGui.QRegExpValidator(QtCore.QRegExp("[^\\/]+"), self.name_le)
)

# Plugin's docs open through the help button
self.buttonBox.button(QtWidgets.QDialogButtonBox.Help).clicked.connect(
lambda: QtGui.QDesktopServices.openUrl(
QtCore.QUrl(plugin_metadata.get("homepage"))
)
)
self.update_ok_buttons()

def validate_geonode_url(self):

inserted_url = QtCore.QUrl(self.url_le.text().strip().rstrip("#/"))

if inserted_url.isValid() == False:
return False
elif inserted_url.path() != "":
return False
else:
return True

def _populate_wfs_version_combobox(self):
self.wfs_version_cb.clear()
for name, member in WfsVersion.__members__.items():
Expand Down Expand Up @@ -150,6 +163,7 @@ def get_connection_settings(self) -> ConnectionSettings:
def test_connection(self):
for widget in self._widgets_to_toggle_during_connection_test:
widget.setEnabled(False)

current_settings = self.get_connection_settings()
self.discovery_task = network.NetworkRequestTask(
[
Expand All @@ -159,12 +173,10 @@ def test_connection(self):
],
network_task_timeout=current_settings.network_requests_timeout,
authcfg=current_settings.auth_config,
description="Test GeoNode connection",
description="Connect to a GeoNode client",
)
self.discovery_task.task_done.connect(self.handle_discovery_test)
utils.show_message(
self.bar, tr("Testing connection..."), add_loading_widget=True
)
utils.show_message(self.bar, tr("Connecting..."), add_loading_widget=True)
qgis.core.QgsApplication.taskManager().addTask(self.discovery_task)

def handle_discovery_test(self, task_result: bool):
Expand Down Expand Up @@ -230,7 +242,10 @@ def update_connection_details(self):
self.detected_capabilities_lw.clear()
self.detected_version_le.clear()
if not invalid_version:
# Enable the detected_version_db and OK button
self.detected_version_gb.setEnabled(True)
self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(True)

current_settings = self.get_connection_settings()
client: BaseGeonodeClient = apiclient.get_geonode_client(current_settings)
self.detected_version_le.setText(str(current_settings.geonode_version))
Expand All @@ -239,6 +254,7 @@ def update_connection_details(self):
)
else:
self.detected_version_gb.setEnabled(False)
self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(False)

def enable_post_test_connection_buttons(self):
for widget in self._widgets_to_toggle_during_connection_test:
Expand Down Expand Up @@ -268,9 +284,17 @@ def accept(self):
super().accept()

def update_ok_buttons(self):

url_status = self.validate_geonode_url()

enabled_state = self.name_le.text() != "" and self.url_le.text() != ""
self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(enabled_state)
self.test_connection_pb.setEnabled(enabled_state)
self.connection_pb.setEnabled(enabled_state)
if url_status != True:
self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(False)
self.connection_pb.setEnabled(False)
message = "Please insert only the domain of a valid GeoNode URL"
level = qgis.core.Qgis.Info
utils.show_message(self.bar, message, level)


def _get_wfs_declared_versions(raw_response: QtCore.QByteArray) -> typing.List[str]:
Expand Down
10 changes: 10 additions & 0 deletions src/qgis_geonode/gui/geonode_data_source_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
log,
tr,
)
from ..conf import plugin_metadata

WidgetUi, _ = loadUiType(Path(__file__).parents[1] / "ui/geonode_datasource_widget.ui")

Expand Down Expand Up @@ -199,6 +200,13 @@ def __init__(self, parent, fl, widgetMode):
self.title_le.returnPressed.connect(self.search_geonode)
self._hide_core_geonode_provider()

# Plugin's docs open through the help button
self.buttonBox.button(QtWidgets.QDialogButtonBox.Help).clicked.connect(
lambda: QtGui.QDesktopServices.openUrl(
QtCore.QUrl(plugin_metadata.get("homepage"))
)
)

def _initialize_spatial_extent_box(self):
# ATTENTION: the order of initialization of the self.spatial_extent_box widget
# is crucial here. Only call self.spatial_extent_box.setMapCanvas() after
Expand Down Expand Up @@ -286,6 +294,8 @@ def update_connections_combobox(self):

def activate_connection_configuration(self, index: int):
self.toggle_connection_management_buttons()
# Clear error messages from other connections
self.message_bar.clearWidgets()
self.clear_search_results()
self.current_page = 1
self.total_pages = 1
Expand Down
2 changes: 2 additions & 0 deletions src/qgis_geonode/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
from .gui.geonode_maplayer_config_widget_factory import (
GeonodeMapLayerConfigWidgetFactory,
)
from .conf import plugin_metadata


class QgisGeoNode:
def __init__(self, iface):
self.iface = iface
self.plugin_dir = os.path.dirname(__file__)
plugin_metadata.prepare(self.plugin_dir)
locale = QSettings().value("locale/userLocale")[0:2]
locale_path = os.path.join(
self.plugin_dir, "i18n", "QgisGeoNode_{}.qm".format(locale)
Expand Down
4 changes: 2 additions & 2 deletions src/qgis_geonode/ui/connection_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="test_connection_pb">
<widget class="QPushButton" name="connection_pb">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Test Connection</string>
<string>Connect</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit 7075bd5

Please sign in to comment.