Skip to content

Commit b36b739

Browse files
committed
Add check for projects that are not currently opened
1 parent d2070da commit b36b739

2 files changed

Lines changed: 48 additions & 3 deletions

File tree

qfieldsync/gui/cloud_transfer_dialog.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@
2828

2929
from libqfieldsync.layer import LayerSource, SyncAction
3030
from libqfieldsync.offline_converter import ExportType
31-
from libqfieldsync.project_checker import ProjectChecker
31+
from libqfieldsync.project_checker import (
32+
Feedback,
33+
FeedbackResult,
34+
ProjectChecker,
35+
ProjectCheckerFeedback,
36+
)
3237
from libqfieldsync.utils.file_utils import get_unique_empty_dirname
3338
from libqfieldsync.utils.qgis import get_qgis_files_within_dir
3439
from qgis.core import Qgis, QgsApplication, QgsProject, QgsProviderRegistry
@@ -56,7 +61,7 @@
5661
from qfieldsync.core.preferences import Preferences
5762
from qfieldsync.gui.checker_feedback_table import CheckerFeedbackTable
5863
from qfieldsync.gui.storage_widget import StorageWidget
59-
from qfieldsync.utils.file_utils import filesizeformat10
64+
from qfieldsync.utils.file_utils import filesizeformat10, open_qgis_file
6065
from qfieldsync.utils.qt_utils import make_folder_selector, make_icon, make_pixmap
6166

6267
CloudTransferDialogUi, _ = loadUiType(
@@ -267,6 +272,33 @@ def show_project_compatibility_page(self):
267272
if self.cloud_project and self.cloud_project.is_current_qgis_project:
268273
checker = ProjectChecker(QgsProject.instance())
269274
feedback = checker.check(ExportType.Cloud)
275+
elif (
276+
self.cloud_project
277+
and self.cloud_project.local_project_file
278+
and self.cloud_project.local_project_file.local_path
279+
):
280+
feedback = ProjectCheckerFeedback()
281+
is_qgis_version_4 = False
282+
with open_qgis_file(
283+
self.cloud_project.local_project_file.local_path
284+
) as f:
285+
for _i in range(2):
286+
if 'version="4.' in str(f.readline().strip()):
287+
is_qgis_version_4 = True
288+
break
289+
290+
if is_qgis_version_4:
291+
feedback.add(
292+
Feedback(
293+
Feedback.Level.ERROR,
294+
FeedbackResult(
295+
self.tr(
296+
"QFieldCloud does not yet support projects saved using QGIS >= 4.0. "
297+
"Please configure your projects using QGIS 3.44 until further notice."
298+
)
299+
),
300+
)
301+
)
270302

271303
if feedback and feedback.count > 0:
272304
# check whether the widget has already been added the guard from adding twice due to repeated showEvent signal

qfieldsync/utils/file_utils.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
import shutil
2525
import stat
2626
import time
27+
import zipfile
2728
from collections.abc import Callable
2829
from enum import Enum
2930
from pathlib import Path
30-
from typing import Optional, TypedDict, Union
31+
from typing import Optional, TextIO, TypedDict, Union
3132

3233
from qgis.PyQt.QtCore import QObject
3334

@@ -339,3 +340,15 @@ def filesizeformat10(bytes_: int) -> str:
339340
value = "-{}".format(value)
340341

341342
return value
343+
344+
345+
def open_qgis_file(filename: PathLike) -> TextIO:
346+
filename = Path(filename)
347+
348+
if filename.suffix.lower() == ".qgz":
349+
with zipfile.ZipFile(filename, "r") as qgz:
350+
return qgz.open(f"{filename.stem}.qgs")
351+
elif filename.suffix.lower() == ".qgs":
352+
return open(filename)
353+
354+
return None

0 commit comments

Comments
 (0)