~timo-jyrinki/ubuntu/trusty/pitivi/backport_utopic_fixes

« back to all changes in this revision

Viewing changes to pitivi/undo/medialibrary.py

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2014-04-05 15:28:16 UTC
  • mfrom: (6.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20140405152816-6lijoax4cngiz5j5
Tags: 0.93-3
* debian/control:
  + Depend on python-gi (>= 3.10), older versions do not work
    with pitivi (Closes: #732813).
  + Add missing dependency on gir1.2-clutter-gst-2.0 (Closes: #743692).
  + Add suggests on gir1.2-notify-0.7 and gir1.2-gnomedesktop-3.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Pitivi video editor
 
2
#
 
3
#       pitivi/undo/medialibrary.py
 
4
#
 
5
# Copyright (c) 2009, Alessandro Decina <alessandro.d@gmail.com>
 
6
#
 
7
# This program is free software; you can redistribute it and/or
 
8
# modify it under the terms of the GNU Lesser General Public
 
9
# License as published by the Free Software Foundation; either
 
10
# version 2.1 of the License, or (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
# Lesser General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU Lesser General Public
 
18
# License along with this program; if not, write to the
 
19
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 
20
# Boston, MA 02110-1301, USA.
 
21
 
 
22
from pitivi.undo.undo import UndoableAction
 
23
 
 
24
 
 
25
class MediaLibrarySourceAddedAction(UndoableAction):
 
26
    def __init__(self, medialibrary, source):
 
27
        self.medialibrary = medialibrary
 
28
        self.source = source
 
29
 
 
30
    def undo(self):
 
31
        self.medialibrary.removeUri(self.source.get_uri())
 
32
        self._undone()
 
33
 
 
34
    def do(self):
 
35
        self.medialibrary.addUris(self.source.get_uri())
 
36
        self._done()
 
37
 
 
38
 
 
39
class MediaLibrarySourceRemovedAction(UndoableAction):
 
40
    def __init__(self, medialibrary, uri, source):
 
41
        self.medialibrary = medialibrary
 
42
        self.uri = uri
 
43
        self.source = source
 
44
 
 
45
    def undo(self):
 
46
        self.medialibrary.addUris(self.source.get_uri())
 
47
        self._undone()
 
48
 
 
49
    def do(self):
 
50
        self.medialibrary.removeUri(self.source.get_uri())
 
51
        self._done()
 
52
 
 
53
 
 
54
class MediaLibraryLogObserver(object):
 
55
    def __init__(self, log):
 
56
        self.log = log
 
57
 
 
58
    def startObserving(self, medialibrary):
 
59
        self._connectToSourcelist(medialibrary)
 
60
 
 
61
    def stopObserving(self, medialibrary):
 
62
        self._disconnectFromSourcelist(medialibrary)
 
63
 
 
64
    def _connectToSourcelist(self, medialibrary):
 
65
        medialibrary.connect("source-added", self._sourceAddedCb)
 
66
        medialibrary.connect("source-removed", self._sourceRemovedCb)
 
67
 
 
68
    def _disconnectFromSourcelist(self, medialibrary):
 
69
        medialibrary.disconnect_by_func(self._sourceAddedCb)
 
70
        medialibrary.disconnect_by_func(self._sourceRemovedCb)
 
71
 
 
72
    def _sourceAddedCb(self, medialibrary, factory):
 
73
        self.log.begin("add source")
 
74
        action = MediaLibrarySourceAddedAction(medialibrary, factory)
 
75
        self.log.push(action)
 
76
        self.log.commit()
 
77
 
 
78
    def _sourceRemovedCb(self, medialibrary, uri, factory):
 
79
        self.log.begin("remove source")
 
80
        action = MediaLibrarySourceRemovedAction(medialibrary, uri, factory)
 
81
        self.log.push(action)
 
82
        self.log.commit()