Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSAMdroid <sam.parkinson3@gmail.com>2013-11-29 09:28:04 (GMT)
committer SAMdroid <sam.parkinson3@gmail.com>2013-11-29 09:28:04 (GMT)
commit71c469e59635893524bceb686518705e1c78925a (patch)
tree6ded3e7f7d0fed06541b7feeed0f4c1b96bfa694
parent826af38e6ab3373c997c46a1f6a4099f134691c7 (diff)
Working on adding save to external device support
-rwxr-xr-x[-rw-r--r--]instance.py11
-rwxr-xr-x[-rw-r--r--]model.py18
-rwxr-xr-x[-rw-r--r--]record.py73
-rwxr-xr-x[-rw-r--r--]recorded.py19
4 files changed, 99 insertions, 22 deletions
diff --git a/instance.py b/instance.py
index bcee466..afe69c7 100644..100755
--- a/instance.py
+++ b/instance.py
@@ -6,15 +6,20 @@ from sugar import util
class Instance:
key = profile.get_pubkey()
keyHash = util.sha_data(key)
-
+
keyHashPrintable = util.printable_hash(keyHash)
-
+
instancePath = None
+ savePath = None
def __init__(self, ca):
self.__class__.instancePath = os.path.join(ca.get_activity_root(), "instance")
recreateTmp()
-
+
+ def get_path(self):
+ if self.savePath:
+ return self.savePath
+ return self.instancePath
def recreateTmp():
if (not os.path.exists(Instance.instancePath)):
diff --git a/model.py b/model.py
index 1af2487..78a3366 100644..100755
--- a/model.py
+++ b/model.py
@@ -277,7 +277,7 @@ class Model:
def save_photo(self, pixbuf):
recd = self.createNewRecorded(constants.TYPE_PHOTO)
- imgpath = os.path.join(Instance.instancePath, recd.mediaFilename)
+ imgpath = os.path.join(self.activity.Instance.get_path(), recd.mediaFilename)
pixbuf.save(imgpath, "jpeg")
pixbuf = utils.generate_thumbnail(pixbuf)
@@ -292,7 +292,7 @@ class Model:
# called from gstreamer thread
def save_video(self, path, still):
recd = self.createNewRecorded(constants.TYPE_VIDEO)
- os.rename(path, os.path.join(Instance.instancePath, recd.mediaFilename))
+ os.rename(path, os.path.join(self.activity.Instance.get_path(), recd.mediaFilename))
still = utils.generate_thumbnail(still)
still.save(recd.make_thumb_path(), "png")
@@ -304,10 +304,10 @@ class Model:
def save_audio(self, path, still):
recd = self.createNewRecorded(constants.TYPE_AUDIO)
- os.rename(path, os.path.join(Instance.instancePath, recd.mediaFilename))
+ os.rename(path, os.path.join(self.activity.Instance.get_path(), recd.mediaFilename))
if still:
- image_path = os.path.join(Instance.instancePath, "audioPicture.png")
+ image_path = os.path.join(self.activity.Instance.get_path(), "audioPicture.png")
image_path = utils.getUniqueFilepath(image_path, 0)
still.save(image_path, "png")
recd.audioImageFilename = os.path.basename(image_path)
@@ -363,10 +363,10 @@ class Model:
return None
def createNewRecorded(self, type):
- recd = Recorded()
+ recd = Recorded(self.activity)
recd.recorderName = self.get_nickname()
- recd.recorderHash = Instance.keyHashPrintable
+ recd.recorderHash = self.activity.Instance.keyHashPrintable
#to create a file, use the hardware_id+time *and* check if available or not
nowtime = int(time.time())
@@ -376,7 +376,7 @@ class Model:
mediaThumbFilename = str(recd.recorderHash) + "_" + str(recd.time)
mediaFilename = mediaThumbFilename
mediaFilename = mediaFilename + "." + constants.MEDIA_INFO[type]['ext']
- mediaFilepath = os.path.join( Instance.instancePath, mediaFilename )
+ mediaFilepath = os.path.join( self.activity.Instance.get_path(), mediaFilename )
mediaFilepath = utils.getUniqueFilepath( mediaFilepath, 0 )
recd.mediaFilename = os.path.basename( mediaFilepath )
@@ -398,13 +398,13 @@ class Model:
#load the thumbfile
if recd.thumbFilename:
- thumbFile = os.path.join(Instance.instancePath, recd.thumbFilename)
+ thumbFile = os.path.join(self.activity.Instance.get_path(), recd.thumbFilename)
recd.thumbBytes = os.stat(thumbFile)[6]
recd.tags = ""
#load the mediafile
- mediaFile = os.path.join(Instance.instancePath, recd.mediaFilename)
+ mediaFile = os.path.join(self.activity.Instance.get_path(), recd.mediaFilename)
mBytes = os.stat(mediaFile)[6]
recd.mediaBytes = mBytes
diff --git a/record.py b/record.py
index e25010e..6926b6f 100644..100755
--- a/record.py
+++ b/record.py
@@ -72,10 +72,66 @@ else:
class Record(activity.Activity):
+
+ DIALOG_OK = 13
+
+ def _getDirs(self, path, parent_item, tree_data_store, path_to_file):
+ """Gets all of the folders and adds them to
+ tree_data_store"""
+ logging.debug(path)
+ if os.path.exists(path):
+ for File in os.listdir(path):
+ filepath = os.path.join(path, File)
+ if os.path.isdir(filepath):
+ item = tree_data_store.append(parent_item, [File])
+ item_path = tree_data_store.get_path(item)
+ path_to_file[str(item_path)] = filepath
+ self._getDirs(filepath, item, tree_data_store, path_to_file)
+
+ def _getDirsWithoutRootFolder(self, path, tree_data_store, path_to_file):
+ """Like getDirs except omits the first folder in the tree"""
+ logging.debug(path)
+ if os.path.exists(path):
+ logging.debug(path)
+ for File in os.listdir(path):
+ filepath = os.path.join(path, File)
+ if os.path.isdir(filepath):
+ tree_data_store = self._getDirs(filepath, None, tree_data_store, path_to_file)
+
+ def _genFileTree(self, path_to_file):
+ """Generates the file tree of the external devices directory
+ and returns a tree data store"""
+ tree_data_store = gtk.TreeStore(str)
+
+ self._getDirsWithoutRootFolder("/run/media", tree_data_store, path_to_file)
+ self._getDirsWithoutRootFolder("/media", tree_data_store, path_to_file)
+
+ internal_item = tree_data_store.append(None, ["Internal Storage"])
+ path = tree_data_store.get_path(internal_item)
+ path_to_file[str(path)] = None
+ return tree_data_store
+
+ def _init_dialog(self):
+ """Returns a dialog with a folder picker
+ picks between /media folders or just 'internal'
+ also returns a tree view used"""
+ path_to_file = {}
+ tree_data_store = self._genFileTree(path_to_file)
+ tree_view = gtk.TreeView(tree_data_store)
+ renderer = gtk.CellRendererText()
+ column = gtk.TreeViewColumn("Media Folders", renderer, text=0)
+ tree_view.append_column(column)
+
+ folder_dialog = gtk.Dialog("Chose a folder")
+ folder_dialog.add_button("Use selected folder", self.DIALOG_OK)
+ folder_dialog.get_content_area().add(tree_view)
+ folder_dialog.get_content_area().show_all()
+ return folder_dialog, tree_view, path_to_file
+
def __init__(self, handle):
super(Record, self).__init__(handle)
self.props.enable_fullscreen_mode = False
- Instance(self)
+ self.Instance = Instance(self)
self.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK)
self.connect("visibility-notify-event", self._visibility_changed)
@@ -171,6 +227,11 @@ class Record(activity.Activity):
self._toolbar.insert(self._audio_button, -1)
self._toolbar.insert(gtk.SeparatorToolItem(), -1)
+
+ self._set_path_button = ToolButton()
+ self._set_path_button.props.label = _('Set Output File')
+ self._set_path_button.connect('clicked', self._set_path_button_clicked)
+ self._toolbar.insert(self._set_path_button, -1)
self._toolbar_controls = RecordControl(self._toolbar)
@@ -367,6 +428,16 @@ class Record(activity.Activity):
def _mode_button_clicked(self, button):
self.model.change_mode(button.mode)
+
+ def _set_path_button_clicked(self, button):
+ folder_dialog, tree_view, path_to_file = self._init_dialog()
+ dialog_responce = folder_dialog.run()
+ if dialog_responce == self.DIALOG_OK:
+ tree_sel = tree_view.get_selection()
+ (tree_store, ti) = tree_sel.get_selected()
+ ids = tree_store.get_path(ti)
+ self.Instance.savePath = path_to_file[str(ids)]
+ folder_dialog.destroy()
def _shutter_clicked(self, arg):
self.model.do_shutter()
diff --git a/recorded.py b/recorded.py
index 9296742..8ee8e3d 100644..100755
--- a/recorded.py
+++ b/recorded.py
@@ -27,7 +27,8 @@ import utils
import serialize
class Recorded:
- def __init__( self ):
+ def __init__( self, activity ):
+ self.activity = activity
self.type = -1
self.time = None
self.recorderName = None
@@ -115,11 +116,11 @@ class Recorded:
def getThumbFilepath( self ):
if not self.thumbFilename:
return None
- return os.path.join(Instance.instancePath, self.thumbFilename)
+ return os.path.join(self.activity.Instance.get_path(), self.thumbFilename)
def make_thumb_path(self):
thumbFilename = self.mediaFilename + "_thumb.jpg"
- thumbFilepath = os.path.join(Instance.instancePath, thumbFilename)
+ thumbFilepath = os.path.join(self.activity.Instance.get_path(), thumbFilename)
thumbFilepath = utils.getUniqueFilepath(thumbFilepath, 0)
self.thumbFilename = os.path.basename(thumbFilepath)
return self.getThumbFilepath()
@@ -139,7 +140,7 @@ class Recorded:
def getAudioImageFilepath( self ):
if (self.audioImageFilename != None):
- audioFilepath = os.path.join(Instance.instancePath, self.audioImageFilename)
+ audioFilepath = os.path.join(self.activity.Instance.get_path(), self.audioImageFilename)
return os.path.abspath(audioFilepath)
else:
return self.getThumbFilepath()
@@ -149,24 +150,24 @@ class Recorded:
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)
+ mediaFilepath = os.path.join(self.activity.Instance.get_path(), 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)
+ mediaFilepath = os.path.join(self.activity.Instance.get_path(), 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 = os.path.join(self.activity.Instance.get_path(), "recdFile_"+self.mediaMd5+"."+ext)
recdPath = utils.getUniqueFilepath(recdPath, 0)
self.mediaFilename = os.path.basename(recdPath)
- mediaFilepath = os.path.join(Instance.instancePath, self.mediaFilename)
+ mediaFilepath = os.path.join(self.activity.Instance.get_path(), self.mediaFilename)
return os.path.abspath(mediaFilepath)
else:
- mediaFilepath = os.path.join(Instance.instancePath, self.mediaFilename)
+ mediaFilepath = os.path.join(self.activity.Instance.get_path(), self.mediaFilename)
return os.path.abspath(mediaFilepath)
else: #pulling from the datastore, regardless of who took it, cause we got it