diff options
-rw-r--r-- | constants.py | 2 | ||||
-rw-r--r-- | recorded.py | 49 | ||||
-rw-r--r-- | serialize.py | 33 | ||||
-rw-r--r-- | ui.py | 4 |
4 files changed, 29 insertions, 59 deletions
diff --git a/constants.py b/constants.py index c251522..8d2b661 100644 --- a/constants.py +++ b/constants.py @@ -35,7 +35,7 @@ class Constants: recdThumbMd5 = "thumbMd5" recdMediaBytes = "mediaBytes" recdThumbBytes = "thumbBytes" - recdBuddyThumb = "buddyThumb" + recdBase64Thumb = "base64Thumb" recdDatastoreId = "datastoreId" recdAudioImage = "audioImage" recdAlbum = "album" diff --git a/recorded.py b/recorded.py index 441ca23..fcdc315 100644 --- a/recorded.py +++ b/recorded.py @@ -100,52 +100,15 @@ class Recorded: #relaunch, their old media -- datastoreObject->file (hold onto the datastore object, delete if deleted) | ([request->]) Journal/session/buddy def getThumbPixbuf( self ): - record.Record.log.debug("getThumbPixbuf: self.datastoreId="+str(self.datastoreId)) - if (self.datastoreId == None): - #just taken, so it is in the tempSessionDir - #so load file, convert to pixbuf, and return it here... - thumbPixbuf = None - record.Record.log.debug("getThumbPixbuf: thumbfilename:" + str(self.thumbFilename)) - thumbFilepath = os.path.join(Instance.tmpPath, self.thumbFilename) - if ( os.path.isfile(thumbFilepath) ): - thumbPixbuf = gtk.gdk.pixbuf_new_from_file(thumbFilepath) - record.Record.log.debug("getThumbPixbuf: returning thumbPixbuf->"+str(thumbPixbuf)) - return thumbPixbuf - else: - #todo: handle possible corruption of the preview into some other format - if (self.datastoreOb == None): - self.datastoreOb = serialize.getMediaFromDatastore( self ) - if (self.datastoreOb == None): - record.Record.log.debug("getThumbPixbuf: datastoreOb==None") - return None - - record.Record.log.debug("getThumbPixbuf: got datastore Ob!") - return utils.getPixbufFromString( self.datastoreOb.metadata['preview'] ) + thumbPixbuf = None + thumbFilepath = self.getThumbFilepath() + if ( os.path.isfile(thumbFilepath) ): + thumbPixbuf = gtk.gdk.pixbuf_new_from_file(thumbFilepath) + return thumbPixbuf def getThumbFilepath( 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 - record.Record.log.debug("getThumbFilepath: thumbfilename:" + str(self.thumbFilename)) - thumbFilepath = os.path.join(Instance.tmpPath, self.thumbFilename) - if ( os.path.isfile(thumbFilepath) ): - return thumbFilepath - else: - if (self.datastoreOb == None): - self.datastoreOb = serialize.getMediaFromDatastore( self ) - if (self.datastoreOb == None): - print("RecordActivity error -- unable to get datastore object in getThumbPixbuf") - return None - - img = utils.getPixbufFromString( self.datastoreOb.metadata['preview'] ) - thumbFilepath = os.path.join( Instance.tmpPath, "thumb.png") - thumbFilepath = utils.getUniqueFilepath(thumbFilepath, 0) - img.save(thumbFilepath, "png", {} ) - return thumbFilepath - - return None + return os.path.join(Instance.tmpPath, self.thumbFilename) def getAudioImagePixbuf( self ): diff --git a/serialize.py b/serialize.py index 78c767b..2df2d3e 100644 --- a/serialize.py +++ b/serialize.py @@ -147,7 +147,7 @@ def fillRecdFromNode( recd, el ): if (el.getAttributeNode(Constants.recdThumbBytes) != None): recd.thumbBytes = el.getAttribute(Constants.recdThumbBytes) - bt = el.getAttributeNode(Constants.recdBuddyThumb) + bt = el.getAttributeNode(Constants.recdBase64Thumb) if (bt != None): try: thumbPath = os.path.join(Instance.tmpPath, "datastoreThumb.jpg") @@ -157,7 +157,7 @@ def fillRecdFromNode( recd, el ): recd.thumbFilename = os.path.basename(thumbPath) record.Record.log.debug("saved thumbFilename") except: - record.Record.log.error("unable to getRecdBuddyThumb") + record.Record.log.error("unable to getRecdBase64Thumb") ai = el.getAttributeNode(Constants.recdAudioImage) if (not ai == None): @@ -184,10 +184,6 @@ def getRecdXmlMeshString( recd ): root = recdXml.documentElement _addRecdXmlAttrs( root, recd, True ) - pixbuf = recd.getThumbPixbuf( ) - thumb = str( utils.getStringFromPixbuf(pixbuf) ) - root.setAttribute(Constants.recdBuddyThumb, thumb ) - writer = cStringIO.StringIO() recdXml.writexml(writer) return writer.getvalue() @@ -217,6 +213,10 @@ def _addRecdXmlAttrs( el, recd, forMeshTransmit ): el.setAttribute(Constants.recdThumbBytes, str(recd.thumbBytes)) el.setAttribute(Constants.recdRecordVersion, str(Constants.VERSION)) + pixbuf = recd.getThumbPixbuf( ) + thumb64 = str( utils.getStringFromPixbuf(pixbuf) ) + el.setAttribute(Constants.recdBase64Thumb, thumb64) + def saveMediaHash( mediaHashs ): impl = getDOMImplementation() @@ -251,9 +251,6 @@ def saveMediaHash( mediaHashs ): def _saveMedia( el, recd ): if ( (recd.buddy == True) and (recd.datastoreId == None) and (not recd.downloadedFromBuddy) ): - pixbuf = recd.getThumbPixbuf( ) - buddyThumb = str( utils.getStringFromPixbuf(pixbuf) ) - el.setAttribute(Constants.recdBuddyThumb, buddyThumb ) recd.savedMedia = True _saveXml( el, recd ) else: @@ -294,10 +291,20 @@ def _saveMediaToDatastore( el, recd ): mediaObject = datastore.create() mediaObject.metadata['title'] = recd.title - pixbuf = recd.getThumbPixbuf() - record.Record.log.debug("serialize: pixbuf->" + str(pixbuf)) - thumbData = utils.getStringFromPixbuf(pixbuf) - mediaObject.metadata['preview'] = thumbData + datastorePreviewPixbuf = recd.getThumbPixbuf() + if (recd.type == Constants.TYPE_AUDIO): + datastorePreviewPixbuf = recd.getAudioImagePixbuf() + elif (recd.type == Constant.TYPE_PHOTO): + datastorePreviewFilepath = recd.getMediaFilepath() + datastorePreviewPixbuf = gtk.gdk.pixbuf_new_from_file(datastorePreviewFilepath) + + datastorePreviewWidth = 300 + datastorePreviewHeight = 225 + if (datastorePreviewPixbuf.get_width() != datastorePreviewWidth): + datastorePreviewPixbuf = datastorePreviewPixbuf.scale_simple(datastorePreviewWidth, datastorePreviewHeight, gtk.gdk.INTERP_NEAREST) + + datastorePreviewBase64 = utils.getStringFromPixbuf(datastorePreviewPixbuf) + mediaObject.metadata['preview'] = datastorePreviewBase64 colors = str(recd.colorStroke.hex) + "," + str(recd.colorFill.hex) mediaObject.metadata['icon-color'] = colors @@ -1607,8 +1607,8 @@ class UI: def setPostProcessPixBuf( self, pixbuf ):
- if (pixbuf.get_width()>160):
- pixbuf = pixbuf.scale_simple(160, 120, gtk.gdk.INTERP_NEAREST)
+ if (pixbuf.get_width()>dim_THUMB_WIDTH):
+ pixbuf = pixbuf.scale_simple(dim_THUMB_WIDTH, dim_THUMB_HEIGHT, gtk.gdk.INTERP_NEAREST)
pixbuf = utils.grayScalePixBuf(pixbuf, True)
img = _camera.cairo_surface_from_gdk_pixbuf(pixbuf)
|