From 3a01502d7ecd9b028b01a1472adcb31359292e02 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Wed, 1 Nov 2023 18:47:03 +0700 Subject: [PATCH 1/2] Fix #85 handle missing thumbnail. --- qgis_hub_plugin/utilities/common.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/qgis_hub_plugin/utilities/common.py b/qgis_hub_plugin/utilities/common.py index 13fd174..e4335ad 100644 --- a/qgis_hub_plugin/utilities/common.py +++ b/qgis_hub_plugin/utilities/common.py @@ -5,14 +5,19 @@ from qgis.PyQt.QtGui import QIcon from qgis_hub_plugin.__about__ import DIR_PLUGIN_ROOT +from qgis_hub_plugin.toolbelt import PlgLogger from qgis_hub_plugin.utilities.file_downloader import FileDownloader -def get_icon(icon_name: str): - full_path = os.path.join(DIR_PLUGIN_ROOT, "resources", "images", icon_name) +def get_icon(icon_name: str) -> QIcon: + full_path = get_icon_path(icon_name) return QIcon(full_path) +def get_icon_path(icon_name: str) -> str: + return os.path.join(DIR_PLUGIN_ROOT, "resources", "images", icon_name) + + def download_file(url: str, file_path: Path, force: bool = False): if not force and file_path.exists(): return @@ -25,14 +30,19 @@ def download_file(url: str, file_path: Path, force: bool = False): return file_path.exists() -def download_resource_thumbnail(url: str, uuid: str): +# If not able to download or not found, set the thumbnail to the default one +def download_resource_thumbnail(url: str, uuid: str) -> Path: + if not url: + PlgLogger.log(f"UUID: {uuid} has URL == None: {url}") + return Path(get_icon_path("QGIS_Hub_icon.svg")) + qgis_user_dir = QgsApplication.qgisSettingsDirPath() # Assume it as jpg extension = ".jpg" try: extension = url.split(".")[-1] - except IndexError(): - pass + except IndexError as e: + PlgLogger.log(f"UUID: {uuid} on URL: {url} get index error: {e}") thumbnail_dir = Path(qgis_user_dir, "qgis_hub", "thumbnails") thumbnail_path = Path(thumbnail_dir, f"{uuid}.{extension}") @@ -42,3 +52,5 @@ def download_resource_thumbnail(url: str, uuid: str): download_file(url, thumbnail_path) if thumbnail_path.exists(): return thumbnail_path + else: + return Path(get_icon_path("QGIS_Hub_icon.svg")) From dac4475783e036fcba206113b60e9af812339b51 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Wed, 1 Nov 2023 18:48:39 +0700 Subject: [PATCH 2/2] Update changelog and bump to 0.1.2 --- CHANGELOG.md | 4 ++++ qgis_hub_plugin/metadata.txt | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a94497..172ad8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ Unreleased --> +## 0.1.2 - 2023-11-01 + +- Fix bug #85: failed to handle null thumbnail + ## 0.1.1 - 2023-08-23 - Fix UI issue on HiDPI screen diff --git a/qgis_hub_plugin/metadata.txt b/qgis_hub_plugin/metadata.txt index 3ef3f79..d3d594b 100644 --- a/qgis_hub_plugin/metadata.txt +++ b/qgis_hub_plugin/metadata.txt @@ -21,5 +21,5 @@ qgisMinimumVersion=3.28 qgisMaximumVersion=3.99 # versioning -version=0.1.1 +version=0.1.2 changelog=