Skip to content

Commit c02bc9f

Browse files
authored
Merge pull request #54 from geotribu/feature/display-confirmation-dialog-with-setting
feature: display a confirmation message based on a new setting
2 parents d8b8744 + 61f296f commit c02bc9f

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

qchat/gui/dck_qchat.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,22 @@ def on_send_screenshot_button_clicked(self) -> None:
974974
Action called when the Send QGIS screenshot button is clicked
975975
"""
976976

977+
if (
978+
self.settings.confirm_before_send
979+
and QMessageBox.warning(
980+
self,
981+
self.tr("Sure ?"),
982+
self.tr(
983+
"""Screenshot of current QGIS map will be sent to QChat.
984+
985+
Are you sure ?"""
986+
),
987+
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
988+
)
989+
!= QMessageBox.StandardButton.Yes
990+
):
991+
return
992+
977993
sc_fp = Path(tempfile.gettempdir()) / "qgis_screenshot.png"
978994
self.iface.mapCanvas().saveAsImage(str(sc_fp))
979995
with open(sc_fp, "rb") as file:
@@ -992,6 +1008,22 @@ def on_send_bbox_button_clicked(self) -> None:
9921008
"""
9931009
Action called when the Send extent button is clicked
9941010
"""
1011+
if (
1012+
self.settings.confirm_before_send
1013+
and QMessageBox.warning(
1014+
self,
1015+
self.tr("Sure ?"),
1016+
self.tr(
1017+
"""The current map extent will be sent to QChat.
1018+
1019+
Are you sure ?"""
1020+
),
1021+
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
1022+
)
1023+
!= QMessageBox.StandardButton.Yes
1024+
):
1025+
return
1026+
9951027
crs = QgsProject.instance().crs()
9961028
rect = self.iface.mapCanvas().extent()
9971029
message = QChatBboxMessage(
@@ -1013,6 +1045,22 @@ def on_send_crs_button_clicked(self) -> None:
10131045
"""
10141046
Action called when the Send CRS button is clicked
10151047
"""
1048+
if (
1049+
self.settings.confirm_before_send
1050+
and QMessageBox.warning(
1051+
self,
1052+
self.tr("Sure ?"),
1053+
self.tr(
1054+
"""The current CRS will be sent to QChat.
1055+
1056+
Are you sure ?"""
1057+
),
1058+
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
1059+
)
1060+
!= QMessageBox.StandardButton.Yes
1061+
):
1062+
return
1063+
10161064
crs = QgsProject.instance().crs()
10171065
message = QChatCrsMessage(
10181066
type=QCHAT_MESSAGE_TYPE_CRS,
@@ -1208,7 +1256,8 @@ def on_send_geojson_layer_to_qchat(self) -> None:
12081256
return
12091257

12101258
if (
1211-
not QMessageBox.warning(
1259+
self.settings.confirm_before_send
1260+
and QMessageBox.warning(
12121261
self,
12131262
self.tr("Sure ?"),
12141263
self.tr(
@@ -1218,7 +1267,7 @@ def on_send_geojson_layer_to_qchat(self) -> None:
12181267
).format(layer_name=layer.name()),
12191268
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
12201269
)
1221-
== QMessageBox.StandardButton.Yes
1270+
!= QMessageBox.StandardButton.Yes
12221271
):
12231272
return
12241273

qchat/gui/dlg_settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def apply(self):
129129
settings.display_admin_messages = self.ckb_display_admin_messages.isChecked()
130130
settings.show_avatars = self.ckb_show_avatars.isChecked()
131131
settings.incognito_mode = self.ckb_incognito_mode.isChecked()
132+
settings.confirm_before_send = self.ckb_confirm_before_send.isChecked()
132133
settings.play_sounds = self.ckb_play_sounds.isChecked()
133134
settings.sound_volume = self.hsl_sound_volume.value()
134135
settings.ring_tone = self.cbb_ring_tone.currentText()
@@ -182,6 +183,7 @@ def load_settings(self):
182183
self.ckb_display_admin_messages.setChecked(settings.display_admin_messages)
183184
self.ckb_show_avatars.setChecked(settings.show_avatars)
184185
self.ckb_incognito_mode.setChecked(settings.incognito_mode)
186+
self.ckb_confirm_before_send.setChecked(settings.confirm_before_send)
185187
self.ckb_play_sounds.setChecked(settings.play_sounds)
186188
self.hsl_sound_volume.setValue(settings.sound_volume)
187189
beep_index = self.cbb_ring_tone.findText(

qchat/gui/dlg_settings.ui

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,16 @@
220220
</property>
221221
</widget>
222222
</item>
223+
<item>
224+
<widget class="QCheckBox" name="ckb_confirm_before_send">
225+
<property name="toolTip">
226+
<string extracomment="When sending a specific message, if QChat should display a confirmation dialog"/>
227+
</property>
228+
<property name="text">
229+
<string>Confirm before send</string>
230+
</property>
231+
</widget>
232+
</item>
223233
<item>
224234
<widget class="QCheckBox" name="ckb_display_admin_messages">
225235
<property name="toolTip">

qchat/toolbelt/preferences.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class PlgSettingsStructure:
7777
display_admin_messages: bool = False
7878
show_avatars: bool = True
7979
incognito_mode: bool = False
80+
confirm_before_send: bool = True
8081
play_sounds: bool = True
8182
sound_volume: int = 33
8283
ring_tone: str = "beep_1"

0 commit comments

Comments
 (0)