Skip to content

Commit

Permalink
Merge pull request #622 from opengisch/QF-2101-adding_warning_for_lon…
Browse files Browse the repository at this point in the history
…g_path_names_for_export_folder

Adding critical message when path exceed 200 characters
  • Loading branch information
suricactus authored Nov 15, 2024
2 parents e51f5c7 + 1df7643 commit 4ce2bb3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
41 changes: 31 additions & 10 deletions qfieldsync/gui/package_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
from qfieldsync.gui.dirs_to_copy_widget import DirsToCopyWidget
from qfieldsync.gui.project_configuration_dialog import ProjectConfigurationDialog

MAX_LENGTH_CHARS_FILEPATH = 200

DialogUi, _ = loadUiType(
os.path.join(os.path.dirname(__file__), "../ui/package_dialog.ui")
)
Expand All @@ -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...")
Expand Down Expand Up @@ -110,6 +112,13 @@ def setup_gui(self):
self.get_export_filename_suggestion()
)

self.packagedProjectFileWidget.lineEdit().textChanged.connect(
self._validate_packaged_project_filename
)
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())
Expand Down Expand Up @@ -155,19 +164,31 @@ def show_package_page(self):
self.button_box.setVisible(True)
self.stackedWidget.setCurrentWidget(self.packagePage)

def run_package_project(self) -> None:
def _validate_packaged_project_filename(self) -> None:
"""Check multiple conditions for the packaged project file and show feedback."""
export_packaged_project = Path(self.packagedProjectFileWidget.filePath())
feedback_messages = []

if export_packaged_project.suffix != ".qgs":
QMessageBox.critical(
self,
self.tr("Invalid Filename"),
self.tr('The filename must have a ".qgs" extension.'),
if export_packaged_project.suffix.lower() != ".qgs":
feedback_messages.append(
self.tr('The filename must have a ".qgs" extension')
)
return

else:
self.package_project()
if len(export_packaged_project.as_posix()) > MAX_LENGTH_CHARS_FILEPATH:
feedback_messages.append(
self.tr(
"Warning: File path exceeds 200 characters. "
"Longer paths may not be handled properly by your file system."
)
)

feedback_text = "\n".join(feedback_messages)
self.packagedProjectFileFeedbackLabel.setText(feedback_text)
self.packagedProjectFileFeedbackLabel.setVisible(bool(feedback_text))

self.button_box.button(QDialogButtonBox.StandardButton.Save).setEnabled(
not feedback_messages
)

def package_project(self):
self.button_box.button(QDialogButtonBox.Save).setEnabled(False)
Expand Down
7 changes: 7 additions & 0 deletions qfieldsync/ui/package_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="packagedProjectFileFeedbackLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 4ce2bb3

Please sign in to comment.