diff --git a/qtribu/gui/dck_qchat.py b/qtribu/gui/dck_qchat.py
index fd8b391c..9093f1a2 100644
--- a/qtribu/gui/dck_qchat.py
+++ b/qtribu/gui/dck_qchat.py
@@ -46,7 +46,12 @@ class QChatWidget(QgsDockWidget):
qchat_client = QChatApiClient
- def __init__(self, iface: QgisInterface, parent: QWidget = None):
+ def __init__(
+ self,
+ iface: QgisInterface,
+ parent: QWidget = None,
+ auto_reconnect_room: str = None,
+ ):
"""QWidget to see and post messages on chat
:param parent: parent widget or application
@@ -59,6 +64,9 @@ def __init__(self, iface: QgisInterface, parent: QWidget = None):
self.plg_settings = PlgOptionsManager()
uic.loadUi(Path(__file__).parent / f"{Path(__file__).stem}.ui", self)
+ # set room to autoreconnect to when widget will open
+ self.auto_reconnect_room = auto_reconnect_room
+
# rules and status signal listener
self.btn_rules.pressed.connect(self.on_rules_button_clicked)
self.btn_rules.setIcon(QIcon(QgsApplication.iconPath("processingResult.svg")))
@@ -161,6 +169,10 @@ def on_widget_opened(self) -> None:
self.cbb_room.currentIndexChanged.connect(self.on_room_changed)
+ # auto reconnect to room if needed
+ if self.auto_reconnect_room:
+ self.cbb_room.setCurrentText(self.auto_reconnect_room)
+
def on_rules_button_clicked(self) -> None:
"""
Action called when clicking on "Rules" button
@@ -257,6 +269,12 @@ def on_room_changed(self) -> None:
self.connect_to_room(new_room)
self.current_room = new_room
+ # write new room value to auto-reconnect room in settings if needed
+ settings = self.settings
+ if settings.qchat_auto_reconnect:
+ settings.qchat_auto_reconnect_room = new_room
+ self.plg_settings.save_from_object(settings)
+
def on_connect_button_clicked(self) -> None:
"""
Action called when clicking on "Connect" / "Disconnect" button
@@ -289,6 +307,13 @@ def on_ws_connected(self, room: str) -> None:
self.grb_room.setTitle(self.tr("Room: {room}").format(room=room))
self.grb_user.setEnabled(True)
self.current_room = room
+
+ # write new room value to auto-reconnect room in settings if needed
+ settings = self.settings
+ if settings.qchat_auto_reconnect:
+ settings.qchat_auto_reconnect_room = room
+ self.plg_settings.save_from_object(settings)
+
self.connected = True
self.log(message=f"Websocket connected to room {room}")
if self.settings.qchat_display_admin_messages:
diff --git a/qtribu/gui/dlg_settings.py b/qtribu/gui/dlg_settings.py
index e4051720..8fecbe92 100644
--- a/qtribu/gui/dlg_settings.py
+++ b/qtribu/gui/dlg_settings.py
@@ -112,6 +112,7 @@ def apply(self):
settings.qchat_instance_uri = instance[0:-1]
else:
settings.qchat_instance_uri = instance
+ settings.qchat_auto_reconnect = self.ckb_auto_reconnect.isChecked()
settings.qchat_activate_cheatcode = self.ckb_cheatcodes.isChecked()
settings.qchat_display_admin_messages = (
self.ckb_display_admin_messages.isChecked()
@@ -159,6 +160,7 @@ def load_settings(self) -> None:
self.cbb_qchat_instance_uri.setCurrentIndex(instance_index)
else:
self.cbb_qchat_instance_uri.setCurrentText(settings.qchat_instance_uri)
+ self.ckb_auto_reconnect.setChecked(settings.qchat_auto_reconnect)
self.ckb_cheatcodes.setChecked(settings.qchat_activate_cheatcode)
self.ckb_display_admin_messages.setChecked(
settings.qchat_display_admin_messages
diff --git a/qtribu/gui/dlg_settings.ui b/qtribu/gui/dlg_settings.ui
index ddd7c8ea..f03dac15 100644
--- a/qtribu/gui/dlg_settings.ui
+++ b/qtribu/gui/dlg_settings.ui
@@ -373,6 +373,16 @@
+ -
+
+
+
+
+
+ Automatically reconnect
+
+
+
-
diff --git a/qtribu/plugin_main.py b/qtribu/plugin_main.py
index 06756692..f6116a91 100644
--- a/qtribu/plugin_main.py
+++ b/qtribu/plugin_main.py
@@ -282,6 +282,18 @@ def post_ui_init(self):
)
return
+ # auto reconnect to room if needed
+ settings = PlgOptionsManager().get_plg_settings()
+ if settings.qchat_auto_reconnect and settings.qchat_auto_reconnect_room:
+ if not self.qchat_widget:
+ self.qchat_widget = QChatWidget(
+ iface=self.iface,
+ parent=self.iface.mainWindow(),
+ auto_reconnect_room=settings.qchat_auto_reconnect_room,
+ )
+ self.iface.addDockWidget(int(Qt.RightDockWidgetArea), self.qchat_widget)
+ self.qchat_widget.show()
+
def tr(self, message: str) -> str:
"""Get the translation for a string using Qt translation API.
diff --git a/qtribu/toolbelt/preferences.py b/qtribu/toolbelt/preferences.py
index 666228e0..f4ae4f05 100644
--- a/qtribu/toolbelt/preferences.py
+++ b/qtribu/toolbelt/preferences.py
@@ -38,6 +38,8 @@ class PlgSettingsStructure:
# QChat
qchat_instance_uri: str = "https://gischat.geotribu.net"
+ qchat_auto_reconnect: bool = True
+ qchat_auto_reconnect_room: str = None
qchat_activate_cheatcode: bool = True
qchat_display_admin_messages: bool = False
qchat_show_avatars: bool = True