Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/recorded.py
blob: 3fac646ea7d46a33221c9e5a9b4d1ab7ecd6aa93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#Copyright (c) 2007, Media Modifications Ltd.

#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:

#The above copyright notice and this permission notice shall be included in
#all copies or substantial portions of the Software.

#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.

import os
import gtk
from gtk import gdk

class Recorded:

	def __init__( self, pca ):
		self.ca = pca

		self.type = -1
		self.time = None
		self.photographer = None
		self.title = None
		self.colorStroke = None
		self.colorFill = None
		self.hashKey = None
		self.mediaMd5 = None
		self.thumbMd5 = None

		#flag to alert need to re-datastore the title
		self.titleChange = False

		#when you are datastore-serialized, you get one of these ids...
		self.datastoreId = None
		self.datastoreOb = None

		#if not from the datastore, then your media is here...
		self.mediaFilename = None
		self.thumbFilename = None
		self.audioImageFilename = None

		#assume you took the picture
		self.buddy = False
		self.downloadedFromBuddy = False

		#for flagging when you are being saved to the datastore for the first time...
		#and just because you have an id, doesn't mean you're
		self.saved = False



	def setTitle( self, newTitle ):
		self.title = newTitle
		self.titleChange = True


	def isClipboardCopyable( self ):
		copyme = True
		if (self.buddy):
			if (not self.downloadedFromBuddy):
				return False
		return copyme


	#scenarios:
	#launch, your new thumb    -- Journal/session
	#launch, your new media    -- Journal/session
	#launch, their new thumb   -- Journal/session/buddy
	#launch, their new media   -- ([request->]) Journal/session/buddy
	#relaunch, your old thumb  -- metadataPixbuf on request (or save to Journal/session..?)
	#relaunch, your old media  -- datastoreObject->file (hold onto the datastore object, delete if deleted)
	#relaunch, their old thumb -- metadataPixbuf on request (or save to Journal/session..?)
	#relaunch, their old media -- datastoreObject->file (hold onto the datastore object, delete if deleted) | ([request->]) Journal/session/buddy

	def getThumbPixbuf( self ):
		if (self.datastoreId == None):
			#just taken, so it is in the tempSessionDir
			#so load file, convert to pixbuf, and return it here...
			thumbPixbuf = None
			thumbFilepath = os.path.join(self.ca.journalPath, self.thumbFilename)
			if ( os.path.isfile(thumbFilepath) ):
				thumbPixbuf = gtk.gdk.pixbuf_new_from_file(thumbFilepath)
			return thumbPixbuf
		else:
			if (self.datastoreOb == None):
				self.ca.m.loadMediaFromDatastore( self )
			if (self.datastoreOb == None):
				print("RecordActivity error -- unable to get datastore object in getThumbPixbuf")
				return None
			pbl = gtk.gdk.PixbufLoader()
			import base64
			data = base64.b64decode(self.datastoreOb.metadata['preview'])
			pbl.write(data)
			return pbl.get_pixbuf()


	def getThumbFilepath( self, meshReq ):
		#todo: make sure this is used everywhere
		if (self.datastoreId == None):
			#just taken, so it is in the tempSessionDir
			#so load file, convert to pixbuf, and return it here...
			thumbPixbuf = None
			thumbFilepath = os.path.join(self.ca.journalPath, self.thumbFilename)
			if ( os.path.isfile(thumbFilepath) ):
				return thumbFilepath
		else:
			if (self.datastoreOb == None):
				self.ca.m.loadMediaFromDatastore( self )
			if (self.datastoreOb == None):
				print("RecordActivity error -- unable to get datastore object in getThumbPixbuf")
				return None
			pbl = gtk.gdk.PixbufLoader()
			import base64
			data = base64.b64decode(self.datastoreOb.metadata['preview'])
			pbl.write(data)

			#todo: write to tmp (rainbow?) and random unused filename...
			thumbFilepath = os.path.join(self.ca.journalPath, "thumb.png")
			pbl.get_pixbuf().save(thumbFilepath, "png", {} )

			return thumbFilepath

		return None


	def getAudioImagePixbuf( self ):
		if (self.datastoreId == None):
			#just taken, so it is in the tempSessionDir
			#so load file, convert to pixbuf, and return it here...
			audioPixbuf = None
			audioFilepath = os.path.join(self.ca.journalPath, self.audioImageFilename)
			if ( os.path.isfile(audioFilepath) ):
				return audioFilepath
		else:
			if (self.datastoreOb == None):
				self.ca.m.loadMediaFromDatastore( self )
			if (self.datastoreOb == None):
				print("RecordActivity error -- unable to get datastore object in getAudioImage")
				return None
			pbl = gtk.gdk.PixbufLoader()
			import base64
			data = base64.b64decode(self.datastoreOb.metadata['audioImage'])
			pbl.write(data)
			audioImageFilepath = os.path.join(self.ca.journalPath, "audioImage.png")
			thumbImg.save(audioImageFilepath, "png", {} )
			return audioImageFilepath

		return None


	def getMediaFilepath( self, meshReq ):
		print("getMediaFilepath 1")
		if (self.datastoreId == None):
			if (not self.buddy):
				#just taken by you, so it is in the tempSessionDir
				print("getMediaFilepath 3")
				mediaFilepath = os.path.join(self.ca.journalPath, self.mediaFilename)
				return os.path.abspath(mediaFilepath)
			else:
				if (self.downloadedFromBuddy):
					print("getMediaFilepath 4")
					#the user has requested the high-res version, and it has downloaded
					mediaFilepath = os.path.join(self.ca.journalPath, self.mediaFilename)
					return os.path.abspath(mediaFilepath)
				else:
					print("getMediaFilepath 5")
					#you should request it from someone and return None for the request to handle...
					#e.g., thumbs for pics, or "coming attractions" for videos ;-)
					#todo: always re-request?
					#todo: notify to the user that the request is underway or not possible...
					if ( (self.ca.meshClient != None) and meshReq):
						print("getMediaFilepath 6")
						self.ca.meshClient.requestMediaBits( self )
						print("getMediaFilepath 7")
					return None

		else:
			#pulling from the datastore, regardless of who took it
			print("getMediaFilepath 8")

			#first, get the datastoreObject and hold the reference in this Recorded instance
			if (self.datastoreOb == None):
				self.ca.m.loadMediaFromDatastore( self )
			if (self.datastoreOb == None):
				print("RecordActivity error -- unable to get datastore object in getMediaFilepath")
				return None

			#if this is a buddy's media and you only ever got a thumbnail, then return null and query for the real deal...

			print("getMediaFilepath 9")
			return self.datastoreOb.file_path