Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding critical message when path exceed 200 characters #622

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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":
SeqLaz marked this conversation as resolved.
Show resolved Hide resolved
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
Loading