diff --git a/qfieldsync/gui/cloud_transfer_dialog.py b/qfieldsync/gui/cloud_transfer_dialog.py index cb99d81e..4e023cac 100644 --- a/qfieldsync/gui/cloud_transfer_dialog.py +++ b/qfieldsync/gui/cloud_transfer_dialog.py @@ -28,7 +28,12 @@ from libqfieldsync.layer import LayerSource, SyncAction from libqfieldsync.offline_converter import ExportType -from libqfieldsync.project_checker import ProjectChecker +from libqfieldsync.project_checker import ( + Feedback, + FeedbackResult, + ProjectChecker, + ProjectCheckerFeedback, +) from libqfieldsync.utils.file_utils import get_unique_empty_dirname from libqfieldsync.utils.qgis import get_qgis_files_within_dir from qgis.core import Qgis, QgsApplication, QgsProject, QgsProviderRegistry @@ -56,7 +61,7 @@ from qfieldsync.core.preferences import Preferences from qfieldsync.gui.checker_feedback_table import CheckerFeedbackTable from qfieldsync.gui.storage_widget import StorageWidget -from qfieldsync.utils.file_utils import filesizeformat10 +from qfieldsync.utils.file_utils import filesizeformat10, open_qgis_file from qfieldsync.utils.qt_utils import make_folder_selector, make_icon, make_pixmap CloudTransferDialogUi, _ = loadUiType( @@ -267,6 +272,33 @@ def show_project_compatibility_page(self): if self.cloud_project and self.cloud_project.is_current_qgis_project: checker = ProjectChecker(QgsProject.instance()) feedback = checker.check(ExportType.Cloud) + elif ( + self.cloud_project + and self.cloud_project.local_project_file + and self.cloud_project.local_project_file.local_path + ): + feedback = ProjectCheckerFeedback() + is_qgis_version_4 = False + with open_qgis_file( + self.cloud_project.local_project_file.local_path + ) as f: + for _i in range(2): + if 'version="4.' in str(f.readline().strip()): + is_qgis_version_4 = True + break + + if is_qgis_version_4: + feedback.add( + Feedback( + Feedback.Level.ERROR, + FeedbackResult( + self.tr( + "QFieldCloud does not yet support projects saved using QGIS >= 4.0. " + "Please configure your projects using QGIS 3.44 until further notice." + ) + ), + ) + ) if feedback and feedback.count > 0: # check whether the widget has already been added the guard from adding twice due to repeated showEvent signal diff --git a/qfieldsync/utils/file_utils.py b/qfieldsync/utils/file_utils.py index 8e20cf8c..d1285f9c 100644 --- a/qfieldsync/utils/file_utils.py +++ b/qfieldsync/utils/file_utils.py @@ -24,10 +24,11 @@ import shutil import stat import time +import zipfile from collections.abc import Callable from enum import Enum from pathlib import Path -from typing import Optional, TypedDict, Union +from typing import Optional, TextIO, TypedDict, Union from qgis.PyQt.QtCore import QObject @@ -339,3 +340,15 @@ def filesizeformat10(bytes_: int) -> str: value = "-{}".format(value) return value + + +def open_qgis_file(filename: PathLike) -> TextIO: + filename = Path(filename) + + if filename.suffix.lower() == ".qgz": + with zipfile.ZipFile(filename, "r") as qgz: + return qgz.open(f"{filename.stem}.qgs") + elif filename.suffix.lower() == ".qgs": + return open(filename) + + return None diff --git a/requirements.txt b/requirements.txt index 131d1d8e..085bb8ab 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ # 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/b83bfa46646d218a95202b62e8431354ead3de48.tar.gz +libqfieldsync @ https://github.com/opengisch/libqfieldsync/archive/ee83e64a8026f80a96031a5d3b3c32d72633af2e.tar.gz