diff --git a/qfieldsync/gui/package_dialog.py b/qfieldsync/gui/package_dialog.py
index 7664be8b..bad18f7f 100644
--- a/qfieldsync/gui/package_dialog.py
+++ b/qfieldsync/gui/package_dialog.py
@@ -21,6 +21,7 @@
***************************************************************************/
"""
import os
+from pathlib import Path
from libqfieldsync.layer import LayerSource
from libqfieldsync.offline_converter import ExportType, OfflineConverter
@@ -73,12 +74,9 @@ def __init__(self, iface, project, offline_editing, parent=None):
self.qfield_preferences = Preferences()
self.dirsToCopyWidget = DirsToCopyWidget()
self.__project_configuration = ProjectConfiguration(self.project)
- self.packaged_project_filename.setText(self.project.baseName())
- self.packaged_project_title.setText(get_project_title(self.project))
-
self.button_box.button(QDialogButtonBox.Save).setText(self.tr("Create"))
self.button_box.button(QDialogButtonBox.Save).clicked.connect(
- self.package_project
+ self.run_package_project
)
self.button_box.button(QDialogButtonBox.Reset).setText(
self.tr("Configure current project...")
@@ -115,7 +113,11 @@ def setup_gui(self):
)
self.manualDir.setText(QDir.toNativeSeparators(str(export_dirname)))
+ self.manualDir.textChanged.connect(self.set_export_filename_suggested)
self.manualDir_btn.clicked.connect(make_folder_selector(self.manualDir))
+ self.packaged_project_filename.setText(self.get_export_filename_suggestion())
+ self.packaged_project_title.setText(get_project_title(self.project))
+
self.update_info_visibility()
self.nextButton.clicked.connect(lambda: self.show_package_page())
@@ -147,15 +149,43 @@ def get_export_folder_from_dialog(self):
# manual
return self.manualDir.text()
+ def get_export_filename_suggestion(self):
+ export_folder = Path(self.get_export_folder_from_dialog())
+ full_project_name_suggestion = export_folder.joinpath(
+ f"{self.project.baseName()}_qfield.qgs"
+ )
+ return str(full_project_name_suggestion)
+
+ def set_export_filename_suggested(self):
+ self.packaged_project_filename.setText(self.get_export_filename_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):
+ export_packaged_project = Path(self.packaged_project_filename.text())
+
+ if export_packaged_project.exists():
+ reply = QMessageBox.question(
+ self,
+ "File Already Exists",
+ f"'{export_packaged_project.name}' already exists. Do you want to overwrite it?",
+ QMessageBox.Yes | QMessageBox.No,
+ QMessageBox.No,
+ )
+ if reply == QMessageBox.Yes:
+ self.package_project()
+ else:
+ self.show_package_page()
+ else:
+ self.package_project()
+
def package_project(self):
self.button_box.button(QDialogButtonBox.Save).setEnabled(False)
- export_folder = self.get_export_folder_from_dialog()
+ export_packaged_project = Path(self.packaged_project_filename.text())
area_of_interest = (
self.__project_configuration.area_of_interest
if self.__project_configuration.area_of_interest
@@ -167,20 +197,21 @@ def package_project(self):
else QgsProject.instance().crs().authid()
)
- self.qfield_preferences.set_value("exportDirectoryProject", export_folder)
+ self.qfield_preferences.set_value(
+ "exportDirectoryProject", export_packaged_project.parent
+ )
self.dirsToCopyWidget.save_settings()
offline_convertor = OfflineConverter(
self.project,
- export_folder,
- self.packaged_project_filename.text(),
- self.packaged_project_title.text(),
+ export_packaged_project,
area_of_interest,
area_of_interest_crs,
self.qfield_preferences.value("attachmentDirs"),
self.offliner,
ExportType.Cable,
dirs_to_copy=self.dirsToCopyWidget.dirs_to_copy(),
+ export_title=self.packaged_project_title.text(),
)
# progress connections
@@ -210,7 +241,7 @@ def do_post_offline_convert_action(self, is_success):
with a nice link to open the result folder.
"""
if is_success:
- export_folder = self.get_export_folder_from_dialog()
+ export_folder = str(Path(self.packaged_project_filename.text()).parent)
result_message = self.tr(
"Finished creating the project at {result_folder}. Please copy this folder to "
"your QField device."
diff --git a/qfieldsync/ui/package_dialog.ui b/qfieldsync/ui/package_dialog.ui
index 8458b867..6012cb25 100644
--- a/qfieldsync/ui/package_dialog.ui
+++ b/qfieldsync/ui/package_dialog.ui
@@ -14,55 +14,6 @@
Package Project for QField
- -
-
-
- bold
-
-
- <p><span style=" font-weight:600;">Packaged Project Name</span></p>
-
-
- Qt::RichText
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
-
-
-
- -
-
-
- <p><span style=" font-weight:600;">Packaged Project Title</span></p>
-
-
- Qt::RichText
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
-
-
-
-
@@ -130,11 +81,33 @@
-
- Export Directory
+ Packaged Project Title
-
-
+
+
+
+
+
+ -
+
+
+ Packaged Project Filename
+
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+ -
+
-