[pitivi] project_: Start an undo transaction when switching proxies



commit 1ce34a2dd223df9ecdf4ba5304dbe361d256f285
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Tue Jun 7 15:52:49 2016 +0000

    project_: Start an undo transaction when switching proxies
    
    Otherwise an error is raised when the transcoding is done and
    __updateAssetLoadingProgress tries to commit the nonstarted transaction.
    
    Fixes https://phabricator.freedesktop.org/T7464
    
    Reviewed-by: Thibault Saunier <tsaunier gnome org>
    Differential Revision: https://phabricator.freedesktop.org/D1063

 pitivi/project.py           |    9 ++++++-
 tests/test_media_library.py |    2 +-
 tests/test_undo_project.py  |   45 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 3 deletions(-)
---
diff --git a/pitivi/project.py b/pitivi/project.py
index d116c41..0a0f99a 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -989,8 +989,7 @@ class Project(Loggable, GES.Project):
         self.__setProxy(asset, None)
         self.__updateAssetLoadingProgress()
 
-    def __proxyErrorCb(self, unused_proxy_manager, asset, proxy,
-                       error):
+    def __proxyErrorCb(self, unused_proxy_manager, asset, proxy, error):
         if asset is None:
             asset_id = self.app.proxy_manager.getTargetUri(proxy)
             if asset_id:
@@ -1178,9 +1177,15 @@ class Project(Loggable, GES.Project):
         self.app.proxy_manager.disconnect_by_func(self.__proxyReadyCb)
 
     def useProxiesForAssets(self, assets):
+        originals = []
         for asset in assets:
             proxy_target = asset.get_proxy_target()
             if not proxy_target:
+                # The asset is not a proxy.
+                originals.append(asset)
+        if originals:
+            self.app.action_log.begin("Adding assets")
+            for asset in originals:
                 # Add and remove the asset to
                 # trigger the proxy creation code path
                 self.remove_asset(asset)
diff --git a/tests/test_media_library.py b/tests/test_media_library.py
index 5134a2b..45ff2e3 100644
--- a/tests/test_media_library.py
+++ b/tests/test_media_library.py
@@ -96,7 +96,7 @@ class BaseTestMediaLibrary(common.TestCase):
         self.samples = samples
         for sample_name in samples:
             self.app.project_manager.current_project.create_asset(
-                common.get_sample_uri(sample_name), GES.UriClip,)
+                common.get_sample_uri(sample_name), GES.UriClip)
 
     def runCheckImport(self, assets, proxying_strategy=ProxyingStrategy.ALL,
                        check_no_transcoding=False, clean_proxies=True):
diff --git a/tests/test_undo_project.py b/tests/test_undo_project.py
index 480d5db..23cbc85 100644
--- a/tests/test_undo_project.py
+++ b/tests/test_undo_project.py
@@ -70,6 +70,51 @@ class TestProjectUndo(TestCase):
         self.action_log.redo()
         self.assertEqual(len(self.project.list_assets(GES.Extractable)), 1)
 
+    def test_use_proxy(self):
+        # Import an asset.
+        uris = [common.get_sample_uri("tears_of_steel.webm")]
+        mainloop = common.create_main_loop()
+
+        def commit_cb(unused_action_log, stack):
+            self.assertEqual(stack.action_group_name, "Adding assets")
+            mainloop.quit()
+        self.action_log.connect("commit", commit_cb)
+
+        def loaded_cb(unused_project, unused_timeline):
+            self.project.addUris(uris)
+        self.project.connect_after("loaded", loaded_cb)
+
+        mainloop.run()
+        self.action_log.disconnect_by_func(commit_cb)
+        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 1)
+
+        # Make sure the asset is not a proxy.
+        assets = [GES.UriClipAsset.request_sync(uri) for uri in uris]
+        for asset in assets:
+            self.assertIsNone(asset.get_proxy_target(), "Asset is proxy")
+
+        # Use proxy instead of the asset.
+        mainloop = common.create_main_loop()
+
+        def error_cb(proxy_manager, asset, proxy, error):
+            self.fail("Failed to create proxy: %s" % error)
+        self.app.proxy_manager.connect("error-preparing-asset", error_cb)
+
+        def proxy_ready_cb(proxy_manager, asset, proxy):
+            uris.remove(asset.props.id)
+            if not uris:
+                mainloop.quit()
+        self.app.proxy_manager.connect("proxy-ready", proxy_ready_cb)
+
+        self.project.useProxiesForAssets(assets)
+        mainloop.run()
+
+        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 2)
+        self.action_log.undo()
+        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 1)
+        self.action_log.redo()
+        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 2)
+
     def test_project_settings(self):
         window = Gtk.Window()
         dialog = ProjectSettingsDialog(parent_window=window,


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