diff --git a/qfieldsync/gui/package_dialog.py b/qfieldsync/gui/package_dialog.py
index b2bcca22..f00955e7 100644
--- a/qfieldsync/gui/package_dialog.py
+++ b/qfieldsync/gui/package_dialog.py
@@ -61,6 +61,8 @@
class PackageDialog(QDialog, DialogUi):
+ MAX_LENGTH_CHARS_FILEPATH = 200
+
def __init__(self, iface, project, offline_editing, parent=None):
"""Constructor."""
super(PackageDialog, self).__init__(parent=parent)
@@ -74,7 +76,7 @@ def __init__(self, iface, project, offline_editing, parent=None):
self.__project_configuration = ProjectConfiguration(self.project)
self.button_box.button(QDialogButtonBox.Save).setText(self.tr("Create"))
self.button_box.button(QDialogButtonBox.Save).clicked.connect(
- self.run_package_project
+ self.package_project
)
self.button_box.button(QDialogButtonBox.Reset).setText(
self.tr("Configure current project...")
@@ -110,6 +112,13 @@ def setup_gui(self):
self.get_export_filename_suggestion()
)
+ self.packagedProjectFileWidget.lineEdit().textChanged.connect(
+ self.check_path_length_and_extension
+ )
+ self.packagedProjectFileFeedbackLabel.setStyleSheet("color: red;")
+ self.packagedProjectFileFeedbackLabel.setWordWrap(True)
+ self.packagedProjectFileFeedbackLabel.hide()
+
self.update_info_visibility()
self.nextButton.clicked.connect(lambda: self.show_package_page())
@@ -150,24 +159,44 @@ def get_export_filename_suggestion(self) -> str:
)
return str(full_project_name_suggestion)
- def show_package_page(self):
- self.nextButton.setVisible(False)
- self.button_box.setVisible(True)
- self.stackedWidget.setCurrentWidget(self.packagePage)
-
- def run_package_project(self) -> None:
+ def check_path_length_and_extension(self):
+ """Check if the file path exceeds 200 characters and the extension is .qgs."""
export_packaged_project = Path(self.packagedProjectFileWidget.filePath())
- if export_packaged_project.suffix != ".qgs":
- QMessageBox.critical(
- self,
- self.tr("Invalid Filename"),
- self.tr('The filename must have a ".qgs" extension.'),
+ if not export_packaged_project:
+ self._set_feedback("Please select a file.", disable_save=True)
+ return
+
+ if export_packaged_project.suffix.lower() != ".qgs":
+ self._set_feedback(
+ self.tr('The filename must have a ".qgs" extension'), disable_save=True
)
return
- else:
- self.package_project()
+ if len(export_packaged_project.as_posix()) > 200:
+ self._set_feedback(
+ self.tr(
+ "Warning: File path exceeds 200 characters. "
+ "Longer paths may not be handled properly by your file system."
+ ),
+ disable_save=True,
+ )
+ return
+
+ self._set_feedback("", disable_save=False)
+
+ def _set_feedback(self, message, disable_save=True):
+ """Set feedback message and enable/disable the Save button."""
+ self.packagedProjectFileFeedbackLabel.setText(message)
+ self.packagedProjectFileFeedbackLabel.setVisible(bool(message))
+ self.button_box.button(QDialogButtonBox.StandardButton.Save).setEnabled(
+ not disable_save
+ )
+
+ def show_package_page(self):
+ self.nextButton.setVisible(False)
+ self.button_box.setVisible(True)
+ self.stackedWidget.setCurrentWidget(self.packagePage)
def package_project(self):
self.button_box.button(QDialogButtonBox.Save).setEnabled(False)
diff --git a/qfieldsync/ui/package_dialog.ui b/qfieldsync/ui/package_dialog.ui
index d3df43d8..de8aa935 100644
--- a/qfieldsync/ui/package_dialog.ui
+++ b/qfieldsync/ui/package_dialog.ui
@@ -17,7 +17,7 @@
-
- 0
+ 1
@@ -103,6 +103,13 @@
+ -
+
+
+
+
+
+