From 4cbd953f7c6860587632e890355b0b15c48f688e Mon Sep 17 00:00:00 2001 From: HarishFulara07 Date: Fri, 20 Jul 2018 16:50:56 +0530 Subject: [PATCH 1/2] project: Use assets thumbs if no thumbs are present in XDG cache --- pitivi/project.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/pitivi/project.py b/pitivi/project.py index 3fa290243..00a0484d2 100644 --- a/pitivi/project.py +++ b/pitivi/project.py @@ -44,6 +44,7 @@ from pitivi.preset import VideoPresetManager from pitivi.render import Encoders from pitivi.settings import get_dir from pitivi.settings import xdg_cache_home +from pitivi.timeline.previewers import ThumbnailCache from pitivi.undo.project import AssetAddedIntention from pitivi.undo.project import AssetProxiedIntention from pitivi.utils.loggable import Loggable @@ -836,6 +837,16 @@ class Project(Loggable, GES.Project): except FileNotFoundError: pass + @staticmethod + def __pick_thumb_from_assets_thumbs(assets): + """Picks project thumbnail from assets thumbnails.""" + for asset in assets: + thumb_cache = ThumbnailCache.get(asset) + thumb = thumb_cache.get_preview_thumbnail() + if thumb: + # First asset that has a preview thumbnail. + return thumb + def create_thumb(self): """Creates project thumbnails.""" thumb_path = self.get_thumb_path(self.uri, ORIGINAL_THUMB_DIR) @@ -848,7 +859,15 @@ class Project(Loggable, GES.Project): # the assets in the current project, the one with maximum file size # will be our project thumbnail - http://bit.ly/thumbnail-generation - assets_uri = [asset.props.id for asset in self.listSources()] + assets = self.listSources() + assets_uri = [asset.props.id for asset in assets] + + if not assets_uri: + # There are no assets in the project, + # so make sure there are no project thumbs. + self.__remove_thumbs() + return + normal_thumb_path = None large_thumb_path = None normal_thumb_size = 0 @@ -887,11 +906,14 @@ class Project(Loggable, GES.Project): shutil.copyfile(normal_thumb_path, thumb_path) else: shutil.copyfile(large_thumb_path, thumb_path) - self.__create_scaled_thumb() else: - # No asset thumbs available, so remove the existing - # project thumbnails, if any. - self.__remove_thumbs() + # No thumbnails available in the XDG cache. + thumb = self.__pick_thumb_from_assets_thumbs(assets) + if not thumb: + return + thumb.savev(thumb_path, "png", [], []) + + self.__create_scaled_thumb() def set_rendering(self, rendering): """Sets the a/v restrictions for rendering or for editing.""" -- GitLab From c17fa563bea16e8ec96e8e770a21ef009986e669 Mon Sep 17 00:00:00 2001 From: HarishFulara07 Date: Fri, 20 Jul 2018 17:45:20 +0530 Subject: [PATCH 2/2] greeter: Defer loading of project thumbnails --- pitivi/greeterperspective.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pitivi/greeterperspective.py b/pitivi/greeterperspective.py index 77d260fb9..38aeabc8f 100644 --- a/pitivi/greeterperspective.py +++ b/pitivi/greeterperspective.py @@ -24,6 +24,7 @@ from gettext import gettext as _ from gi.repository import Gdk from gi.repository import GES from gi.repository import Gio +from gi.repository import GLib from gi.repository import Gtk from pitivi.configure import get_ui_dir @@ -58,13 +59,20 @@ class ProjectInfoRow(Gtk.ListBoxRow): # show it during projects removal screen. self.select_button.hide() - builder.get_object("project_thumbnail").set_from_pixbuf(Project.get_thumb(self.uri)) + self.__thumb = builder.get_object("project_thumbnail") + # Defer loading of thumbnail. + GLib.idle_add(self.__load_thumb_cb) + builder.get_object("project_name_label").set_text(self.name) builder.get_object("project_uri_label").set_text( beautify_project_path(recent_project_item.get_uri_display())) builder.get_object("project_last_updated_label").set_text( beautify_last_updated_timestamp(recent_project_item.get_modified())) + def __load_thumb_cb(self): + self.__thumb.set_from_pixbuf(Project.get_thumb(self.uri)) + return False + # pylint: disable=too-many-instance-attributes class GreeterPerspective(Perspective): -- GitLab