Skip to content

Commit

Permalink
Merge pull request #86 from qgis/fix-85-attribute-error-split
Browse files Browse the repository at this point in the history
Fix #85 attribute error split
  • Loading branch information
ismailsunni authored Nov 1, 2023
2 parents 8273ed2 + dac4475 commit 51ea8bd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion qgis_hub_plugin/metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ qgisMinimumVersion=3.28
qgisMaximumVersion=3.99

# versioning
version=0.1.1
version=0.1.2
changelog=
22 changes: 17 additions & 5 deletions qgis_hub_plugin/utilities/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}")
Expand All @@ -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"))

0 comments on commit 51ea8bd

Please sign in to comment.