[pitivi] project: Make use of the new API to get total number of asset in a project



commit f593b863a5b90a31a8fd0b9388089e3730307bff
Author: Thibault Saunier <thibault saunier collabora com>
Date:   Fri Jan 11 11:52:27 2013 -0300

    project: Make use of the new API to get total number of asset in a project
    
        + medialibrary: Make sure to take into accound currently loading assets
          when conneting to a new project
        + Make sure not to introduce multithreads in GES

 pitivi/medialibrary.py |   16 ++++++++++++++--
 pitivi/project.py      |   45 ++++++++++++++++++++-------------------------
 pitivi/utils/misc.py   |    3 ++-
 3 files changed, 36 insertions(+), 28 deletions(-)
---
diff --git a/pitivi/medialibrary.py b/pitivi/medialibrary.py
index 7cac4dd..650c0c5 100644
--- a/pitivi/medialibrary.py
+++ b/pitivi/medialibrary.py
@@ -414,6 +414,11 @@ class MediaLibraryWidget(Gtk.VBox, Loggable):
         self.project_signals.connect(project, "start-importing", None,
                 self._sourcesStartedImportingCb)
 
+        # The start-importing signal would have already been emited at that
+        # time, make sure to catch if it is the case
+        if project.nb_remaining_file_to_import > 0:
+            self._sourcesStartedImportingCb(project)
+
     def _setClipView(self, view_type):
         """
         Set which clip view to use when medialibrary is showing clips.
@@ -494,7 +499,7 @@ class MediaLibraryWidget(Gtk.VBox, Loggable):
         Update the _progressbar with the ratio of clips imported vs the total
         """
         current_clip_iter = self.app.current.nb_imported_files
-        total_clips = self.app.current.nb_files_to_import
+        total_clips = self.app.current.nb_remaining_file_to_import + current_clip_iter
 
         progressbar_text = _("Importing clip %(current_clip)d of %(total)d" %
             {"current_clip": current_clip_iter,
@@ -942,6 +947,13 @@ class MediaLibraryWidget(Gtk.VBox, Loggable):
         self.project_signals.disconnectAll()
         self._project = None
 
+    def _addUris(self, uris):
+        if self.app.current:
+            self.app.current.addUris(uris)
+        else:
+            self.warning("Adding uris to project, but the project has changed in the meantime")
+        return False
+
     ## Drag and Drop
     def _dndDataReceivedCb(self, unused_widget, unused_context, unused_x,
                            unused_y, selection, targettype, unused_time):
@@ -968,7 +980,7 @@ class MediaLibraryWidget(Gtk.VBox, Loggable):
         if len(directories):
             # Recursively import from folders that were dragged into the library
             self.app.threads.addThread(PathWalker, directories,
-                                    self.app.current.addUris)
+                                    self._addUris)
         if len(remote_files):
             #TODO waiting for remote files downloader support to be implemented
             pass
diff --git a/pitivi/project.py b/pitivi/project.py
index 93bce25..79a1138 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -517,8 +517,7 @@ class Project(Loggable, GES.Project):
 
         # Follow imports
         self._dirty = False
-        self._to_import_uris = []
-        self.nb_files_to_import = 0
+        self.nb_remaining_file_to_import = 0
         self.nb_imported_files = 0
 
         # Project property default values
@@ -761,16 +760,12 @@ class Project(Loggable, GES.Project):
     # GES.Project virtual methods implementation #
     #--------------------------------------------#
     def _handle_asset_loaded(self, id):
-        try:
-            self._to_import_uris.remove(id)
-            self.nb_imported_files += 1
-            if not self._to_import_uris:
-                self.nb_imported_files = 0
-                self.nb_files_to_import = 0
-                self._emitChange("done-importing")
-        except ValueError:
-            # We care only about the assets we are tracking
-            pass
+        self.nb_imported_files += 1
+        self.nb_remaining_file_to_import = len([asset for asset in self.get_loading_assets() if
+                GObject.type_is_a(asset.get_extractable_type(), GES.TimelineFileSource)])
+        if self.nb_remaining_file_to_import == 0:
+            self.nb_imported_files = 0
+            self._emitChange("done-importing")
 
     def do_asset_added(self, asset):
         """
@@ -825,6 +820,7 @@ class Project(Loggable, GES.Project):
         unlike GES.Project
         """
         self.timeline = self.extract()
+        self._calculateNbLoadingAssets()
         if self.timeline is None:
             return False
 
@@ -841,19 +837,9 @@ class Project(Loggable, GES.Project):
         The uris will be analyzed before being added.
         """
         # Do not try to reload URIS that we already have loaded
-        uris = [quote_uri(uri) for uri in uris if self.get_asset(uri, GES.TimelineFileSource) is None]
-        if not uris:
-            return
-
-        self.nb_files_to_import += len(uris)
-        if self._to_import_uris:
-            self._to_import_uris = set(uris.extend(list(self._to_import_uris)))
-        else:
-            self._emitChange("start-importing")
-            self._to_import_uris = uris
-
-        for uri in self._to_import_uris:
-            self.create_asset(uri, GES.TimelineFileSource)
+        for uri in uris:
+            self.create_asset(quote_uri(uri), GES.TimelineFileSource)
+        self._calculateNbLoadingAssets()
 
     def listSources(self):
         return self.list_assets(GES.TimelineFileSource)
@@ -1013,6 +999,15 @@ class Project(Loggable, GES.Project):
             return factories[0].get_name()
         return None
 
+    def _calculateNbLoadingAssets(self):
+        nb_remaining_file_to_import = len([asset for asset in self.get_loading_assets() if
+                GObject.type_is_a(asset.get_extractable_type(), GES.TimelineFileSource)])
+        if self.nb_remaining_file_to_import == 0 and nb_remaining_file_to_import:
+            self.nb_remaining_file_to_import = nb_remaining_file_to_import
+            self._emitChange("start-importing")
+            return
+        self.nb_remaining_file_to_import = nb_remaining_file_to_import
+
 
 #----------------------- UI classes ------------------------------------------#
 class ProjectSettingsDialog():
diff --git a/pitivi/utils/misc.py b/pitivi/utils/misc.py
index af235e7..8d4170b 100644
--- a/pitivi/utils/misc.py
+++ b/pitivi/utils/misc.py
@@ -26,6 +26,7 @@ import sys
 from gi.repository import GObject
 from gi.repository import Gst
 from gi.repository import Gtk
+from gi.repository import GLib
 import hashlib
 import os
 import struct
@@ -214,7 +215,7 @@ class PathWalker(Thread):
                     uris.append(quote_uri("file://%s" %
                             os.path.join(path, afile)))
                 if uris:
-                    self.callback(uris)
+                    GLib.idle_add(self.callback, uris)
 
     def abort(self):
         self.stopme.set()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]