From 622eadc80c322dfe6edbd7705e214561d297604f Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Wed, 3 Jul 2019 10:52:43 -0300 Subject: [PATCH] StartPage: thumbnails for image formats, + use freedesktop thumbnails if available --- src/Mod/Start/StartPage/StartPage.py | 30 +++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Mod/Start/StartPage/StartPage.py b/src/Mod/Start/StartPage/StartPage.py index 58e0b8fb68..58a2f30d9d 100644 --- a/src/Mod/Start/StartPage/StartPage.py +++ b/src/Mod/Start/StartPage/StartPage.py @@ -100,6 +100,22 @@ def getInfo(filename): hsize = str(int(size)) + "b" return hsize + def getFreeDesktopThumbnail(filename): + "if we have gnome libs available, try to find a system-generated thumbnail" + try: + import gnome.ui + import gnomevfs + except: + return None + + path = os.path.abspath(filename) + uri = gnomevfs.get_uri_from_local_path(path) + thumb = gnome.ui.thumbnail_path_for_uri(uri, "normal") + if os.path.exists(thumb): + return thumb + return None + + if os.path.exists(filename): if os.path.isdir(filename): @@ -151,6 +167,17 @@ def getInfo(filename): thumb.close() iconbank[filename] = image + # use image itself as icon if it's an image file + if os.path.splitext(filename)[1].lower() in [".jpg",".jpeg",".png",".svg"]: + image = filename + iconbank[filename] = image + + # use freedesktop thumbnail if available + fdthumb = getFreeDesktopThumbnail(filename) + if fdthumb: + image = fdthumb + iconbank[filename] = fdthumb + # retrieve default mime icon if needed if not image: i = QtCore.QFileInfo(filename) @@ -356,7 +383,8 @@ def handle(): SECTION_CUSTOM += "" HTML = HTML.replace("SECTION_CUSTOM",SECTION_CUSTOM) - # build IMAGE_SRC paths + # build IMAGE_SRC paths + HTML = HTML.replace("IMAGE_SRC_USERHUB",'file:///'+os.path.join(resources_dir, 'images/userhub.png')) HTML = HTML.replace("IMAGE_SRC_POWERHUB",'file:///'+os.path.join(resources_dir, 'images/poweruserhub.png')) HTML = HTML.replace("IMAGE_SRC_DEVHUB",'file:///'+os.path.join(resources_dir, 'images/developerhub.png'))