diff --git a/pitivi/greeterperspective.py b/pitivi/greeterperspective.py index 77d260fb9c0490b38a9bf0aeb68acaf3b2cba47e..38aeabc8f38cd0849c66beaf405d1050ffd923d7 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): diff --git a/pitivi/project.py b/pitivi/project.py index 3fa290243cf35cb3365901fde8a784f3cd7ede0c..00a0484d24b0bd77fd8d2eb6a7c68bd0d4cbde7c 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."""