Serialize Path objects to QML
- media_cache.get_(thumbnail/media) now return a Path instead of str - When converted to strings in the serialization, the "file://" prefix is prepended. This fixes problems when the app is built in release mode with QRC resources.
This commit is contained in:
parent
a8f4a00e5e
commit
eee2162575
1
TODO.md
1
TODO.md
|
@ -1,6 +1,5 @@
|
||||||
- Media
|
- Media
|
||||||
- Verify things work with chat.privacytools.io (subdomain weirdness)
|
- Verify things work with chat.privacytools.io (subdomain weirdness)
|
||||||
- Allow multiple file selection
|
|
||||||
- Confirmation box after picking file to upload
|
- Confirmation box after picking file to upload
|
||||||
- Handle upload errors: non existent path, path is a dir, file too big, etc
|
- Handle upload errors: non existent path, path is a dir, file too big, etc
|
||||||
- Show real progression for mxc thumbnail loadings, uploads and downloads
|
- Show real progression for mxc thumbnail loadings, uploads and downloads
|
||||||
|
|
|
@ -223,8 +223,8 @@ class MediaCache:
|
||||||
await Media(self, mxc, data, {}).create()
|
await Media(self, mxc, data, {}).create()
|
||||||
|
|
||||||
|
|
||||||
async def get_media(self, mxc: str, crypt_dict: CryptDict = None) -> str:
|
async def get_media(self, mxc: str, crypt_dict: CryptDict = None) -> Path:
|
||||||
return str(await Media(self, mxc, None, crypt_dict).get())
|
return await Media(self, mxc, None, crypt_dict).get()
|
||||||
|
|
||||||
|
|
||||||
async def create_thumbnail(
|
async def create_thumbnail(
|
||||||
|
@ -236,10 +236,10 @@ class MediaCache:
|
||||||
|
|
||||||
async def get_thumbnail(
|
async def get_thumbnail(
|
||||||
self, mxc: str, width: int, height: int, crypt_dict: CryptDict = None,
|
self, mxc: str, width: int, height: int, crypt_dict: CryptDict = None,
|
||||||
) -> str:
|
) -> Path:
|
||||||
|
|
||||||
thumb = Thumbnail(
|
thumb = Thumbnail(
|
||||||
# QML sometimes pass float sizes, which matrix API doesn't like.
|
# QML sometimes pass float sizes, which matrix API doesn't like.
|
||||||
self, mxc, None, crypt_dict, (round(width), round(height)),
|
self, mxc, None, crypt_dict, (round(width), round(height)),
|
||||||
)
|
)
|
||||||
return str(await thumb.get())
|
return await thumb.get()
|
||||||
|
|
|
@ -3,6 +3,7 @@ import html
|
||||||
import xml.etree.cElementTree as xml_etree # FIXME: bandit warning
|
import xml.etree.cElementTree as xml_etree # FIXME: bandit warning
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from enum import auto as autostr
|
from enum import auto as autostr
|
||||||
|
from pathlib import Path
|
||||||
from typing import IO, Any, Tuple, Union
|
from typing import IO, Any, Tuple, Union
|
||||||
|
|
||||||
import filetype
|
import filetype
|
||||||
|
@ -68,4 +69,7 @@ def serialize_value_for_qml(value: Any) -> Any:
|
||||||
if hasattr(value, "__class__") and issubclass(value.__class__, Enum):
|
if hasattr(value, "__class__") and issubclass(value.__class__, Enum):
|
||||||
return value.value
|
return value.value
|
||||||
|
|
||||||
|
if isinstance(value, Path):
|
||||||
|
return f"file://{value!s}"
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
Loading…
Reference in New Issue
Block a user