Skip to content
Open
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
36 changes: 34 additions & 2 deletions qfieldsync/gui/cloud_transfer_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion qfieldsync/utils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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