|
7 | 7 | from urllib.error import URLError, HTTPError
|
8 | 8 | import configparser
|
9 | 9 | import os
|
| 10 | +import webbrowser |
10 | 11 | from osgeo import gdal
|
11 | 12 | import pathlib
|
12 | 13 | import platform
|
|
18 | 19 | import re
|
19 | 20 |
|
20 | 21 | from qgis.PyQt.QtCore import QSettings, QVariant
|
21 |
| -from qgis.PyQt.QtWidgets import QMessageBox, QFileDialog |
| 22 | +from qgis.PyQt.QtWidgets import QMessageBox, QFileDialog, QCheckBox |
22 | 23 | from qgis.PyQt.QtGui import QPalette, QColor, QIcon
|
23 | 24 | from qgis.PyQt.QtXml import QDomDocument
|
24 | 25 | from qgis.core import (
|
@@ -861,30 +862,48 @@ def login_error_message(e):
|
861 | 862 | QMessageBox.critical(None, "Login failed", msg, QMessageBox.StandardButton.Close)
|
862 | 863 |
|
863 | 864 |
|
864 |
| -def unhandled_exception_message(error_details, dialog_title, error_text, log_file=None, username=None): |
865 |
| - msg = ( |
866 |
| - error_text + "<p>This should not happen, " |
867 |
| - '<a href="https://github.com/MerginMaps/qgis-mergin-plugin/issues">' |
868 |
| - "please report the problem</a>." |
869 |
| - ) |
| 865 | +def unhandled_exception_message(error_details, dialog_title, error_text, mm_client, log_file=None): |
870 | 866 | box = QMessageBox()
|
871 | 867 | box.setIcon(QMessageBox.Icon.Critical)
|
872 | 868 | box.setWindowTitle(dialog_title)
|
873 |
| - box.setText(msg) |
874 |
| - if log_file is None: |
875 |
| - box.setDetailedText(error_details) |
876 |
| - else: |
877 |
| - error_details = ( |
878 |
| - "An error occured during project synchronisation. The log was saved to " |
879 |
| - f"{log_file}. Click 'Send logs' to send a diagnostic log to the developers " |
880 |
| - "to help them determine the exact cause of the problem.\n\n" |
881 |
| - "The log does not contain any of your data, only file names. " |
882 |
| - "It would be useful if you also send a mail to support@merginmaps.com " |
883 |
| - "and briefly describe the problem to add more context to the diagnostic log." |
| 869 | + box.setText(error_text) |
| 870 | + box.setInformativeText( |
| 871 | + "An unexpected error occurred. " |
| 872 | + "You can help us fix it by reporting the problem. " |
| 873 | + "Click the button below to create a report we can review." |
| 874 | + ) |
| 875 | + |
| 876 | + if log_file: |
| 877 | + check = QCheckBox("Include diagnostic log (what is this?)") |
| 878 | + check.setChecked(True) |
| 879 | + check.setToolTip( |
| 880 | + "The diagnostic log contains only file names and activity steps that " |
| 881 | + "help us understand what went wrong. It does not include your data." |
| 882 | + ) |
| 883 | + |
| 884 | + box.setCheckBox(check) |
| 885 | + |
| 886 | + error_details = f"The diagnostic log is saved here: {log_file}.\n\n" f"Error details:\n{error_details}" |
| 887 | + |
| 888 | + box.setDetailedText(error_details) |
| 889 | + username = mm_client.username() if mm_client else "Unknown" |
| 890 | + |
| 891 | + email_subject = "Problem with sync from QGIS" |
| 892 | + email_body = ( |
| 893 | + "Hi,\n" |
| 894 | + "I encountered an issue during synchronisation. (Please add more details here).\n\n" |
| 895 | + f"Problem: {error_text}\n" |
| 896 | + f"Username: {username}\n" |
| 897 | + f"{error_details}" |
| 898 | + ) |
| 899 | + |
| 900 | + btn = box.addButton("Report problem", QMessageBox.ButtonRole.HelpRole) |
| 901 | + btn.clicked.connect( |
| 902 | + lambda: ( |
| 903 | + send_logs(mm_client, log_file) if box.checkBox() and box.checkBox().isChecked() else None, |
| 904 | + webbrowser.open(f"mailto:support@merginmaps.com?subject={email_subject}&body={email_body}"), |
884 | 905 | )
|
885 |
| - box.setDetailedText(error_details) |
886 |
| - btn = box.addButton("Send logs", QMessageBox.ButtonRole.ActionRole) |
887 |
| - btn.clicked.connect(lambda: send_logs(username, log_file)) |
| 906 | + ) |
888 | 907 | box.exec()
|
889 | 908 |
|
890 | 909 |
|
|
0 commit comments