[kupfer] urlactions: Use late result mechanism
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [kupfer] urlactions: Use late result mechanism
- Date: Mon, 29 Mar 2010 16:09:14 +0000 (UTC)
commit 973facc22e498b33a601855728a33823d77ad9e9
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Mon Mar 29 17:35:15 2010 +0200
urlactions: Use late result mechanism
kupfer/plugin/urlactions.py | 22 +++++++++++++++++-----
1 files changed, 17 insertions(+), 5 deletions(-)
---
diff --git a/kupfer/plugin/urlactions.py b/kupfer/plugin/urlactions.py
index 0d9f424..9dcf4e9 100644
--- a/kupfer/plugin/urlactions.py
+++ b/kupfer/plugin/urlactions.py
@@ -13,15 +13,16 @@ import os
import shutil
import urllib2
-from kupfer.objects import Action, Source, UrlLeaf, FileLeaf
+from kupfer.objects import Action, Source, UrlLeaf, FileLeaf, OperationError
from kupfer import utils, pretty, task
+from kupfer import commandexec
class DownloadTask (task.ThreadTask):
def __init__(self, uri, destdir=None, tempfile=False, finish_callback=None):
super(DownloadTask, self).__init__()
self.uri = uri
- self.finish_callback = finish_callback
+ self.download_finish_callback = finish_callback
self.destdir = destdir
self.use_tempfile = tempfile
@@ -55,8 +56,8 @@ class DownloadTask (task.ThreadTask):
self.response.close()
def thread_finish(self):
- if self.finish_callback:
- self.finish_callback(self.destpath)
+ if self.download_finish_callback:
+ self.download_finish_callback(self.destpath)
class DownloadAndOpen (Action):
"""Asynchronous action to download file and open it"""
@@ -66,11 +67,16 @@ class DownloadAndOpen (Action):
def is_async(self):
return True
def activate(self, leaf):
+ ctx = commandexec.DefaultActionExecutionContext()
+ self.async_token = ctx.get_async_token()
uri = leaf.object
return DownloadTask(uri, None, True, self._finish_action)
def _finish_action(self, filename):
utils.show_path(filename)
+ ctx = commandexec.DefaultActionExecutionContext()
+ ctx.register_late_result(self.async_token, FileLeaf(filename),
+ show=False)
def item_types(self):
yield UrlLeaf
@@ -85,7 +91,13 @@ class DownloadTo (Action):
return True
def activate(self, leaf, obj):
uri = leaf.object
- return DownloadTask(uri, obj.object)
+ ctx = commandexec.DefaultActionExecutionContext()
+ self.async_token = ctx.get_async_token()
+ return DownloadTask(uri, obj.object, False, self._finish_action)
+
+ def _finish_action(self, filename):
+ ctx = commandexec.DefaultActionExecutionContext()
+ ctx.register_late_result(self.async_token, FileLeaf(filename))
def item_types(self):
yield UrlLeaf
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]