diff --git a/qfieldsync/gui/package_dialog.py b/qfieldsync/gui/package_dialog.py
index 39c95e07..b2bcca22 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
@@ -54,8 +55,6 @@
from qfieldsync.gui.dirs_to_copy_widget import DirsToCopyWidget
from qfieldsync.gui.project_configuration_dialog import ProjectConfigurationDialog
-from ..utils.qt_utils import make_folder_selector
-
DialogUi, _ = loadUiType(
os.path.join(os.path.dirname(__file__), "../ui/package_dialog.ui")
)
@@ -73,10 +72,9 @@ def __init__(self, iface, project, offline_editing, parent=None):
self.qfield_preferences = Preferences()
self.dirsToCopyWidget = DirsToCopyWidget()
self.__project_configuration = ProjectConfiguration(self.project)
- self.project_lbl.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...")
@@ -105,15 +103,13 @@ def update_progress(self, sent, total):
def setup_gui(self):
"""Populate gui and connect signals of the push dialog"""
- export_dirname = self.qfield_preferences.value("exportDirectoryProject")
- if not export_dirname:
- export_dirname = os.path.join(
- self.qfield_preferences.value("exportDirectory"),
- fileparts(QgsProject.instance().fileName())[1],
- )
+ self.packagedProjectTitleLineEdit.setText(get_project_title(self.project))
+ self.packagedProjectFileWidget.setFilter("QGIS Project Files (*.qgs)")
+ self.packagedProjectFileWidget.setConfirmOverwrite(True)
+ self.packagedProjectFileWidget.setFilePath(
+ self.get_export_filename_suggestion()
+ )
- self.manualDir.setText(QDir.toNativeSeparators(str(export_dirname)))
- self.manualDir_btn.clicked.connect(make_folder_selector(self.manualDir))
self.update_info_visibility()
self.nextButton.clicked.connect(lambda: self.show_package_page())
@@ -140,20 +136,43 @@ def setup_gui(self):
else:
self.show_package_page()
- def get_export_folder_from_dialog(self):
- """Get the export folder according to the inputs in the selected"""
- # manual
- return self.manualDir.text()
+ def get_export_filename_suggestion(self) -> str:
+ """Get the suggested export filename"""
+ export_dirname = self.qfield_preferences.value("exportDirectoryProject")
+ if not export_dirname:
+ export_dirname = os.path.join(
+ self.qfield_preferences.value("exportDirectory"),
+ fileparts(QgsProject.instance().fileName())[1],
+ )
+ export_folder = Path(QDir.toNativeSeparators(str(export_dirname)))
+ full_project_name_suggestion = export_folder.joinpath(
+ f"{self.project.baseName()}_qfield.qgs"
+ )
+ 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:
+ 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.'),
+ )
+ return
+
+ else:
+ self.package_project()
+
def package_project(self):
self.button_box.button(QDialogButtonBox.Save).setEnabled(False)
- export_folder = self.get_export_folder_from_dialog()
+ packaged_project_file = Path(self.packagedProjectFileWidget.filePath())
area_of_interest = (
self.__project_configuration.area_of_interest
if self.__project_configuration.area_of_interest
@@ -165,18 +184,21 @@ def package_project(self):
else QgsProject.instance().crs().authid()
)
- self.qfield_preferences.set_value("exportDirectoryProject", export_folder)
+ self.qfield_preferences.set_value(
+ "exportDirectoryProject", packaged_project_file.parent
+ )
self.dirsToCopyWidget.save_settings()
offline_convertor = OfflineConverter(
self.project,
- export_folder,
+ packaged_project_file,
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.packagedProjectTitleLineEdit.text(),
)
# progress connections
@@ -206,7 +228,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.packagedProjectFileWidget.filePath()).parent)
result_message = self.tr(
"Finished creating the project at {result_folder}. Please copy this folder to "
"your QField device."
diff --git a/qfieldsync/tests/test_export.py b/qfieldsync/tests/test_export.py
index d3d687e4..703fff56 100644
--- a/qfieldsync/tests/test_export.py
+++ b/qfieldsync/tests/test_export.py
@@ -70,7 +70,7 @@ def test_copy(self):
offline_editing = QgsOfflineEditing()
offline_converter = OfflineConverter(
project,
- str(self.target_dir),
+ self.target_dir.joinpath("project_qfield.qgs"),
"POLYGON((1 1, 5 0, 5 5, 0 5, 1 1))",
QgsProject.instance().crs().authid(),
["DCIM"],
@@ -110,7 +110,7 @@ def test_primary_keys_custom_property(self):
offline_editing = QgsOfflineEditing()
offline_converter = OfflineConverter(
project,
- str(self.target_dir),
+ self.target_dir.joinpath("project_qfield.qgs"),
"POLYGON((1 1, 5 0, 5 5, 0 5, 1 1))",
QgsProject.instance().crs().authid(),
["DCIM"],
diff --git a/qfieldsync/ui/package_dialog.ui b/qfieldsync/ui/package_dialog.ui
index 4f423b7d..d3df43d8 100644
--- a/qfieldsync/ui/package_dialog.ui
+++ b/qfieldsync/ui/package_dialog.ui
@@ -7,43 +7,13 @@
0
0
599
- 570
+ 700
Package Project for QField
- -
-
-
- 0
-
-
-
-
-
- <html><head/><body><p><span style=" font-weight:600;">Project:</span></p></body></html>
-
-
- Qt::RichText
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
-
-
-
-
-
-
@@ -111,16 +81,25 @@
-
- Export Directory
+ Packaged Project Title
-
-
+
- -
-
-
- ...
+
+
+
+ -
+
+
+ Packaged Project Filename
+
+
+
-
+
+
+ QgsFileWidget::SaveFile
@@ -279,6 +258,11 @@
1
+
+ QgsFileWidget
+ QWidget
+
+
diff --git a/requirements.txt b/requirements.txt
index 6ebc2a81..4878552d 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -7,4 +7,4 @@ future
transifex-client
# NOTE `libqfielsync` version should be defined in the `*.tar.gz` format, not `git+https://` to make `wheel` happy
-libqfieldsync @ https://github.com/opengisch/libqfieldsync/archive/5ba992c1f91ae74418a07c372a7ae11db557b10e.tar.gz
+libqfieldsync @ https://github.com/opengisch/libqfieldsync/archive/1b923ba27ecfc8def5adcd255e94a226ae92b3eb.tar.gz