Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/browser.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 /browser.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 'browser.py')
-rw-r--r--browser.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/browser.py b/browser.py
index 6895667..7379d2b 100644
--- a/browser.py
+++ b/browser.py
@@ -34,6 +34,7 @@ from sugar3.graphics import style
from sugar3.graphics.icon import Icon
from widgets import BrowserNotebook
+from filepicker import FilePicker
import globalhistory
import downloadmanager
from pdfviewer import PDFTabPage
@@ -461,6 +462,12 @@ class Browser(WebKit.WebView):
self.connect('new-window-policy-decision-requested',
self.__new_window_policy_cb)
+ try:
+ self.connect('run-file-chooser', self.__run_file_chooser)
+ except TypeError:
+ # Only present in WebKit1 > 1.9.3 and WebKit2
+ pass
+
def get_history(self):
"""Return the browsing history of this browser."""
back_forward_list = self.get_back_forward_list()
@@ -534,6 +541,18 @@ class Browser(WebKit.WebView):
def open_new_tab(self, url):
self.emit('new-tab', url)
+ def __run_file_chooser(self, browser, request):
+ picker = FilePicker(self)
+ chosen = picker.run()
+ picker.destroy()
+
+ if chosen:
+ request.select_files([chosen])
+ elif hasattr(request, 'cancel'):
+ # WebKit2 only
+ request.cancel()
+ return True
+
def __load_status_changed_cb(self, widget, param):
"""Add the url to the global history or update it."""
status = widget.get_load_status()