Skip to content

Commit

Permalink
Adding critical message when path exceed 200 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
SeqLaz committed Nov 14, 2024
1 parent e51f5c7 commit b606de6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 15 deletions.
57 changes: 43 additions & 14 deletions qfieldsync/gui/package_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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.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())
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion qfieldsync/ui/package_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="projectCompatibilityPage">
<layout class="QVBoxLayout" name="verticalLayout_2">
Expand Down 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 b606de6

Please sign in to comment.