From a0ceeef2b8220e8594d0f8833b9732ffbe0e084a Mon Sep 17 00:00:00 2001 From: Lucian Branescu Mihaila Date: Thu, 15 Jul 2010 00:04:29 +0000 Subject: Downloads start, but do not progress or complete. Mime type is hard-coded. --- diff --git a/browser.py b/browser.py index e8f690e..c05b678 100644 --- a/browser.py +++ b/browser.py @@ -34,6 +34,7 @@ from sugar.activity import activity from sugar.graphics import style from palettes import ContentInvoker +import downloadmanager _ZOOM_AMOUNT = 0.1 @@ -46,16 +47,17 @@ class TabbedView(gtk.Notebook): USER_SHEET = os.path.join(env.get_profile_path(), 'webkit', 'user-stylesheet.css') - def __init__(self): + def __init__(self, activity_p): gobject.GObject.__init__(self) self.props.show_border = False self.props.scrollable = True + self._activity_p = activity_p self.new_tab() def new_tab(self, uri=None): - browser = Browser() + browser = Browser(self._activity_p) self._append_tab(browser) if uri: @@ -120,7 +122,7 @@ class TabbedView(gtk.Notebook): self.remove_page(self.get_n_pages() - 1) for tab_session in tab_sessions: - browser = Browser() + browser = Browser(self._activity_p) self._append_tab(browser) browser.set_session(tab_session) @@ -183,8 +185,10 @@ class TabLabel(gtk.HBox): class Browser(webkit.WebView): __gtype_name__ = 'Browser' - def __init__(self): + def __init__(self, activity_p): webkit.WebView.__init__(self) + + self._activity_p = activity_p self._loaded = False # needed until webkitgtk 1.1.7+ @@ -202,10 +206,8 @@ class Browser(webkit.WebView): super(Browser, self).load_uri(uri) - def __download_requested_cb(self, download, user_data): - #TODO download ui - user_download = downloadmanager.UserDownload(download) - + def __download_requested_cb(self, browser, download): + user_download = downloadmanager.UserDownload(download, self._activity_p) return True def __loading_finished_cb(self, frame, user_data): diff --git a/downloadmanager.py b/downloadmanager.py index 56ad241..8167e5f 100644 --- a/downloadmanager.py +++ b/downloadmanager.py @@ -32,6 +32,8 @@ from sugar.graphics.alert import Alert, TimeoutAlert from sugar.graphics.icon import Icon from sugar.activity import activity +import webkit + # #3903 - this constant can be removed and assumed to be 1 when dbus-python # 0.82.3 is the only version used import dbus @@ -51,6 +53,13 @@ _active_downloads = [] _dest_to_window = {} +# HACK: pywebkitgtk is missing the WebKitDownloadStatus +webkit.WebKitDownloadStatus = type(webkit.Download().get_status()) + +webkit.DOWNLOAD_STATUS_STARTED = webkit.WebKitDownloadStatus(1) +webkit.DOWNLOAD_STATUS_FINISHED = webkit.WebKitDownloadStatus(3) +webkit.DOWNLOAD_STATUS_CANCELLED = webkit.WebKitDownloadStatus(2) + def can_quit(): return len(_active_downloads) == 0 @@ -64,13 +73,15 @@ def remove_all_downloads(): download.cleanup_datastore_write() class UserDownload(object): - def __init__(self, download): + def __init__(self, download, activity_p): self._download = download self._source = download.get_uri() self._download.connect('notify::progress', self.__progress_change_cb) self._download.connect('notify::status', self.__state_change_cb) - self._download.connect('error', self.__error_cb) + + # FIXME + #self._download.connect('error', self.__error_cb) self.datastore_deleted_handler = None @@ -82,21 +93,28 @@ class UserDownload(object): # figure out download URI self._dest_uri = os.path.join(activity.get_activity_root(), 'instance', - download.props.suggested_filename) + download.get_suggested_filename()) if not os.path.exists(self._dest_uri): os.makedirs(self._dest_uri) + # FIXME + self._mime_type = 'image/jpeg' + self._activity = activity_p + # start download self._download.set_destination_uri(self._dest_uri) self._download.start() - def __progress_change_cb(self, download, progress): - self.dl_jobject.metadata['progress'] = str(int(progress * 100)) + def __progress_change_cb(self, download, something): + progress = self._download.get_progress() + self.dl_jobject.metadata['progress'] = str(int(progress)) datastore.write(self.dl_jobject) - def __state_change_cb(self, download, state): + def __state_change_cb(self, download, gparamspec): + state = self._download.get_status() if state == webkit.DOWNLOAD_STATUS_STARTED: + print 'creating journal object' self._create_journal_object() self._object_id = self.dl_jobject.object_id diff --git a/webactivity.py b/webactivity.py index 715ce5b..420dd8b 100644 --- a/webactivity.py +++ b/webactivity.py @@ -173,7 +173,7 @@ class WebActivity(activity.Activity): _logger.debug('Starting the web activity') - self._tabbed_view = TabbedView() + self._tabbed_view = TabbedView(self) _set_accept_languages() _seed_xs_cookie() -- cgit v0.9.1