Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/filepicker.py
diff options
context:
space:
mode:
authorDaniel Drake <dsd@laptop.org>2012-06-05 00:54:50 (GMT)
committer Manuel Quiñones <manuq@laptop.org>2012-06-14 16:55:51 (GMT)
commit2cbc27e4b829df8a1af8087dde7cfaf50fc9aa86 (patch)
treef36b8721b79bd178e94603087291e1d9bb901e27 /filepicker.py
parent7b16255c7f71123d17eddb4d2e3e9ea5faff9164 (diff)
Restore journal file picker (#3411)
The run-file-chooser signal can be used to intercept a request for a file upload and display a custom file chooser. We want to do this to allow the user to upload files from the journal. By default, the standard GTK+ file chooser was being shown. run-file-chooser is present in WebKit2 and has been submitted for final review for inclusion in WebKit1. Signed-off-by: Daniel Drake <dsd@laptop.org> Acked-by: Manuel Quiñones <manuq@laptop.org>
Diffstat (limited to 'filepicker.py')
-rw-r--r--filepicker.py107
1 files changed, 11 insertions, 96 deletions
diff --git a/filepicker.py b/filepicker.py
index 489570a..65ac464 100644
--- a/filepicker.py
+++ b/filepicker.py
@@ -20,12 +20,6 @@ import tempfile
import shutil
from gi.repository import Gtk
-import hulahop
-
-import xpcom
-from xpcom import components
-from xpcom.components import interfaces
-from xpcom.server.factory import Factory
from sugar3.graphics.objectchooser import ObjectChooser
from sugar3.activity.activity import get_activity_root
@@ -44,114 +38,35 @@ def cleanup_temp_files():
temp_dir)
-class FilePicker:
- _com_interfaces_ = interfaces.nsIFilePicker
-
- cid = '{57901c41-06cb-4b9e-8258-37323327b583}'
- description = 'Sugar File Picker'
-
- def __init__(self):
- self._title = None
- self._parent = None
- self._file = None
-
- def appendFilter(self, title, filter):
- logging.warning('FilePicker.appendFilter: UNIMPLEMENTED')
-
- def appendFilters(self, filterMask):
- logging.warning('FilePicker.appendFilters: UNIMPLEMENTED')
-
- def init(self, parent, title, mode):
- self._title = title
- self._file = None
- self._parent = hulahop.get_view_for_window(parent).get_toplevel()
+class FilePicker(ObjectChooser):
+ def __init__(self, parent):
+ ObjectChooser.__init__(self, parent)
- if mode != interfaces.nsIFilePicker.modeOpen:
- raise xpcom.COMException(NS_ERROR_NOT_IMPLEMENTED)
-
- def show(self):
- chooser = ObjectChooser(parent=self._parent)
+ def run(self):
jobject = None
+ _file = None
try:
- result = chooser.run()
+ result = ObjectChooser.run(self)
if result == Gtk.ResponseType.ACCEPT:
- jobject = chooser.get_selected_object()
+ jobject = self.get_selected_object()
logging.debug('FilePicker.show: %r', jobject)
if jobject and jobject.file_path:
tmp_dir = tempfile.mkdtemp(prefix='', \
dir=os.path.join(get_activity_root(), 'tmp'))
- self._file = os.path.join(tmp_dir,
- _basename_strip(jobject))
+ _file = os.path.join(tmp_dir, _basename_strip(jobject))
- os.rename(jobject.file_path, self._file)
+ os.rename(jobject.file_path, _file)
global _temp_dirs_to_clean
_temp_dirs_to_clean.append(tmp_dir)
- logging.debug('FilePicker.show: file=%r', self._file)
+ logging.debug('FilePicker.show: file=%r', _file)
finally:
if jobject is not None:
jobject.destroy()
- chooser.destroy()
- del chooser
-
- if self._file:
- return interfaces.nsIFilePicker.returnOK
- else:
- return interfaces.nsIFilePicker.returnCancel
-
- def set_defaultExtension(self, default_extension):
- logging.warning('FilePicker.set_defaultExtension: UNIMPLEMENTED')
-
- def get_defaultExtension(self):
- logging.warning('FilePicker.get_defaultExtension: UNIMPLEMENTED')
- return None
-
- def set_defaultString(self, default_string):
- logging.warning('FilePicker.set_defaultString: UNIMPLEMENTED')
-
- def get_defaultString(self):
- logging.warning('FilePicker.get_defaultString: UNIMPLEMENTED')
- return None
-
- def set_displayDirectory(self, display_directory):
- logging.warning('FilePicker.set_displayDirectory: UNIMPLEMENTED')
-
- def get_displayDirectory(self):
- logging.warning('FilePicker.get_displayDirectory: UNIMPLEMENTED')
- return None
-
- def set_filterIndex(self, filter_index):
- logging.warning('FilePicker.set_filterIndex: UNIMPLEMENTED')
-
- def get_filterIndex(self):
- logging.warning('FilePicker.get_filterIndex: UNIMPLEMENTED')
- return None
-
- def get_file(self):
- logging.debug('FilePicker.get_file: %r', self._file)
- if self._file:
- cls = components.classes["@mozilla.org/file/local;1"]
- local_file = cls.createInstance(interfaces.nsILocalFile)
- local_file.initWithPath(self._file)
- return local_file
- else:
- return None
-
- def get_Files(self):
- logging.warning('FilePicker.get_Files: UNIMPLEMENTED')
- return None
-
- def get_FileURL(self):
- logging.warning('FilePicker.get_FileURL: UNIMPLEMENTED')
- return None
-
-components.registrar.registerFactory(FilePicker.cid,
- FilePicker.description,
- '@mozilla.org/filepicker;1',
- Factory(FilePicker))
+ return _file
def _basename_strip(jobject):