3
# pitivi/undo/medialibrary.py
5
# Copyright (c) 2009, Alessandro Decina <alessandro.d@gmail.com>
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.
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.
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.
22
from pitivi.undo.undo import UndoableAction
25
class MediaLibrarySourceAddedAction(UndoableAction):
26
def __init__(self, medialibrary, source):
27
self.medialibrary = medialibrary
31
self.medialibrary.removeUri(self.source.get_uri())
35
self.medialibrary.addUris(self.source.get_uri())
39
class MediaLibrarySourceRemovedAction(UndoableAction):
40
def __init__(self, medialibrary, uri, source):
41
self.medialibrary = medialibrary
46
self.medialibrary.addUris(self.source.get_uri())
50
self.medialibrary.removeUri(self.source.get_uri())
54
class MediaLibraryLogObserver(object):
55
def __init__(self, log):
58
def startObserving(self, medialibrary):
59
self._connectToSourcelist(medialibrary)
61
def stopObserving(self, medialibrary):
62
self._disconnectFromSourcelist(medialibrary)
64
def _connectToSourcelist(self, medialibrary):
65
medialibrary.connect("source-added", self._sourceAddedCb)
66
medialibrary.connect("source-removed", self._sourceRemovedCb)
68
def _disconnectFromSourcelist(self, medialibrary):
69
medialibrary.disconnect_by_func(self._sourceAddedCb)
70
medialibrary.disconnect_by_func(self._sourceRemovedCb)
72
def _sourceAddedCb(self, medialibrary, factory):
73
self.log.begin("add source")
74
action = MediaLibrarySourceAddedAction(medialibrary, factory)
78
def _sourceRemovedCb(self, medialibrary, uri, factory):
79
self.log.begin("remove source")
80
action = MediaLibrarySourceRemovedAction(medialibrary, uri, factory)