diff --git a/qtribu/gui/dlg_settings.py b/qtribu/gui/dlg_settings.py index 3023c141..e4051720 100644 --- a/qtribu/gui/dlg_settings.py +++ b/qtribu/gui/dlg_settings.py @@ -65,6 +65,8 @@ def __init__(self, parent=None): # self.lne_qchat_instance_uri.setValidator(QVAL_URL) self.btn_rules.pressed.connect(self.show_instance_rules) self.btn_rules.setIcon(QIcon(QgsApplication.iconPath("processingResult.svg"))) + self.btn_discover.pressed.connect(self.discover_instances) + self.btn_discover.setIcon(QIcon(QgsApplication.iconPath("mIconListView.svg"))) # customization self.btn_help.setIcon(QIcon(QgsApplication.iconPath("mActionHelpContents.svg"))) @@ -178,6 +180,9 @@ def load_settings(self) -> None: self.lbl_version_saved_value.setText(settings.version) def show_instance_rules(self) -> None: + """ + Action called when clicking on the "Instance rules" button + """ instance_url = self.cbb_qchat_instance_uri.currentText() try: client = QChatApiClient(instance_url) @@ -206,6 +211,27 @@ def show_instance_rules(self) -> None: except Exception as e: self.log(message=str(e), log_level=Qgis.Critical) + def discover_instances(self) -> None: + """ + Action called when clicking on the "Discover instances" button + """ + try: + client = QChatApiClient(self.cbb_qchat_instance_uri.currentText()) + instances = client.get_registered_instances() + msg = "" + for lang, lang_instances in instances.items(): + msg += f"[{lang}]:\n" + for li in lang_instances: + msg += f"- {li}\n" + msg += "\n" + QMessageBox.information( + self, + self.tr("Registered instances"), + msg, + ) + except Exception as e: + self.log(message=str(e), log_level=Qgis.Critical) + def on_ring_tone_changed(self) -> None: """ Action called when ringtone value is changed diff --git a/qtribu/gui/dlg_settings.ui b/qtribu/gui/dlg_settings.ui index f9312144..2ec01b6d 100644 --- a/qtribu/gui/dlg_settings.ui +++ b/qtribu/gui/dlg_settings.ui @@ -315,9 +315,6 @@ - - - @@ -348,6 +345,13 @@ + + + + Discover instances + + + @@ -754,11 +758,6 @@ QToolButton
qgscolorbutton.h
- - QgsSymbolButton - QToolButton -
qgssymbolbutton.h
-
AuthoringWidget QWidget @@ -774,7 +773,6 @@ btn_reset_read_history chb_integration_news_feed chb_license_global_accept - mSymbolButton cbb_qchat_instance_uri btn_rules ckb_show_avatars diff --git a/qtribu/logic/qchat_client.py b/qtribu/logic/qchat_client.py index 0eab8dc0..d73b14a9 100644 --- a/qtribu/logic/qchat_client.py +++ b/qtribu/logic/qchat_client.py @@ -16,6 +16,8 @@ CONTENT_TYPE_JSON = "application/json" +INSTANCES_JSON_URL = "https://github.com/geotribu/gischat/raw/main/instances.json" + class QChatApiClient: """ @@ -29,6 +31,16 @@ def __init__( self.instance_uri = instance_uri self.qntwk = NetworkRequestsManager() + def get_registered_instances(self) -> dict[str, list[str]]: + response: QByteArray = self.qntwk.get_from_source( + headers=HEADERS, + url=INSTANCES_JSON_URL, + response_expected_content_type="text/plain; charset=utf-8", + use_cache=False, + ) + data = json.loads(str(response, "UTF8")) + return data + def get_status(self) -> dict[str, Any]: """ Get instance status with an API call