Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/recorded.py
blob: 9296742f58de564e8235a7eb794c44a7d7a16d6f (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
#Copyright (c) 2008, 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

import constants
from instance import Instance
import utils
import serialize

class Recorded:
    def __init__( self ):
        self.type = -1
        self.time = None
        self.recorderName = None
        self.recorderHash = None
        self.title = None
        self.colorStroke = None
        self.colorFill = None
        self.mediaMd5 = None
        self.thumbMd5 = None
        self.mediaBytes = None
        self.thumbBytes = None
        self.tags = None

        #flag to alert need to re-datastore the title
        self.metaChange = 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

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

        #assume you took the picture
        self.buddy = False
        self.downloadedFromBuddy = False
        self.triedMeshBuddies = []
        self.meshDownloading = False
        self.meshDownloadingFrom = ""
        self.meshDownloadingFromNick = ""
        self.meshDownlodingPercent = 0.0
        self.meshDownloadingProgress = False
        #if someone is downloading this, then hold onto it
        self.meshUploading = False
        self.meshReqCallbackId = 0

        self.deleted = False


    def setTitle( self, newTitle ):
        if self.title == newTitle:
            return
        self.title = newTitle
        self.metaChange = True


    def setTags( self, newTags ):
        self.tags = newTags
        self.metaChange = 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 ):
        thumbFilepath = self.getThumbFilepath()
        if thumbFilepath and os.path.isfile(thumbFilepath):
            return gtk.gdk.pixbuf_new_from_file(thumbFilepath)
        else:
            return None


    def getThumbFilepath( self ):
        if not self.thumbFilename:
            return None
        return os.path.join(Instance.instancePath, self.thumbFilename)

    def make_thumb_path(self):
        thumbFilename = self.mediaFilename + "_thumb.jpg"
        thumbFilepath = os.path.join(Instance.instancePath, thumbFilename)
        thumbFilepath = utils.getUniqueFilepath(thumbFilepath, 0)
        self.thumbFilename = os.path.basename(thumbFilepath)
        return self.getThumbFilepath()

    def getAudioImagePixbuf( self ):
        audioPixbuf = None

        if self.audioImageFilename == None:
            audioPixbuf = self.getThumbPixbuf()
        else:
            audioFilepath = self.getAudioImageFilepath()
            if (audioFilepath != None):
                audioPixbuf = gtk.gdk.pixbuf_new_from_file(audioFilepath)

        return audioPixbuf


    def getAudioImageFilepath( self ):
        if (self.audioImageFilename != None):
            audioFilepath = os.path.join(Instance.instancePath, self.audioImageFilename)
            return os.path.abspath(audioFilepath)
        else:
            return self.getThumbFilepath()


    def getMediaFilepath(self):
        if (self.datastoreId == None):
            if (not self.buddy):
                #just taken by you, so it is in the tempSessionDir
                mediaFilepath = os.path.join(Instance.instancePath, self.mediaFilename)
                return os.path.abspath(mediaFilepath)
            else:
                if (self.downloadedFromBuddy):
                    #the user has requested the high-res version, and it has downloaded
                    mediaFilepath = os.path.join(Instance.instancePath, self.mediaFilename)
                    return os.path.abspath(mediaFilepath)
                else:
                    if self.mediaFilename == None:
                        #creating a new filepath, probably just got here from the mesh
                        ext = constants.MEDIA_INFO[self.type]['ext']
                        recdPath = os.path.join(Instance.instancePath, "recdFile_"+self.mediaMd5+"."+ext)
                        recdPath = utils.getUniqueFilepath(recdPath, 0)
                        self.mediaFilename = os.path.basename(recdPath)
                        mediaFilepath = os.path.join(Instance.instancePath, self.mediaFilename)
                        return os.path.abspath(mediaFilepath)
                    else:
                        mediaFilepath = os.path.join(Instance.instancePath, self.mediaFilename)
                        return os.path.abspath(mediaFilepath)

        else: #pulling from the datastore, regardless of who took it, cause we got it
            #first, get the datastoreObject and hold the reference in this Recorded instance
            if (self.datastoreOb == None):
                self.datastoreOb = serialize.getMediaFromDatastore( self )
            if (self.datastoreOb == None):
                print("RecordActivity error -- unable to get datastore object in getMediaFilepath")
                return None

            return self.datastoreOb.file_path