Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucian Branescu Mihaila <lucian.branescu@gmail.com>2009-08-07 15:22:03 (GMT)
committer Lucian Branescu Mihaila <lucian.branescu@gmail.com>2009-08-07 15:22:03 (GMT)
commit25450e1f18701402eb3bdba3a7c3297f61ac752a (patch)
tree5822b460bbeea177a3d7f663905e01685188c369
parentbb4c863dc8a711f0fa4dc1f8a4bca8b662443474 (diff)
Proof of concept 'save complete page'
-rw-r--r--usercode.py40
-rw-r--r--webtoolbar.py10
2 files changed, 31 insertions, 19 deletions
diff --git a/usercode.py b/usercode.py
index 80cf7f7..1abecc4 100644
--- a/usercode.py
+++ b/usercode.py
@@ -201,27 +201,26 @@ def add_script(location):
cls = components.classes[ \
'@mozilla.org/embedding/browser/nsWebBrowserPersist;1']
- browser_persist = cls.createInstance(interfaces.nsIWebBrowserPersist)
- browser_persist.persistFlags = interfaces.nsIWebBrowserPersist \
+ persist = cls.createInstance(interfaces.nsIWebBrowserPersist)
+ persist.persistFlags = interfaces.nsIWebBrowserPersist \
.PERSIST_FLAGS_REPLACE_EXISTING_FILES
cls = components.classes["@mozilla.org/network/io-service;1"]
- io_service = cls.getService(interfaces.nsIIOService)
- location_uri = io_service.newURI(location, None, None)
+ uri = cls.getService(interfaces.nsIIOService).newURI(location, None, None)
cls = components.classes["@mozilla.org/file/local;1"]
local_file = cls.createInstance(interfaces.nsILocalFile)
- file_name = os.path.basename(location_uri.path)
+ file_name = os.path.basename(uri.path)
file_path = os.path.join(SCRIPTS_PATH, file_name)
local_file.initWithPath(file_path)
if not local_file.exists():
local_file.create(0x00, 0644)
logging.debug('Saving userscript %s -> %s' % \
- (location_uri.spec, file_path))
+ (uri.spec, file_path))
- browser_persist.saveURI(location_uri, None, None, None, None, local_file)
+ persist.saveURI(uri, None, None, None, None, local_file)
def script_exists(location):
script_name = os.path.basename(urlparse(location).path)
@@ -229,22 +228,25 @@ def script_exists(location):
return os.path.isfile(os.path.join(SCRIPTS_PATH, script_name))
def save_document(browser):
- cls = components.classes["@mozilla.org/network/io-service;1"]
- io_service = cls.getService(interfaces.nsIIOService)
-
cls = components.classes[ \
- '@mozilla.org/embedding/browser/nsWebBrowserPersist;1']
- browser_persist = cls.getService(interfaces.nsIWebBrowserPersist)
+ '@mozilla.org/embedding/browser/nsWebBrowserPersist;1']
+ persist = cls.createInstance(interfaces.nsIWebBrowserPersist)
+ persist.persistFlags = interfaces.nsIWebBrowserPersist \
+ .PERSIST_FLAGS_REPLACE_EXISTING_FILES
+
+ local = components.classes["@mozilla.org/file/local;1"]
+ local_file = local.createInstance(interfaces.nsILocalFile)
+ local_data = local.createInstance(interfaces.nsILocalFile)
+ file_path = '/media/desktop/saved/x.html'
+ local_file.initWithPath(file_path)
- file_path = os.path.join(activity.get_activity_root(),
- 'data/saved/x.html')
- file_uri = io_service.newURI('file://'+file_path, None, None)
- data_path = os.path.join(activity.get_activity_root(), 'data/saved/x')
- data_uri = io_service.newURI('file://'+data_path, None, None)
+ data_path = '/media/desktop/saved/x'
+ local_data.initWithPath(data_path)
- browser_persist.saveDocument(browser.dom_window.document,
- file_uri, data_uri, None, 0, 0)
+
+ persist.saveDocument(browser.dom_window.document,
+ local_file, local_data, None, 0, 0)
class Injector():
_com_interfaces_ = interfaces.nsIDOMEventListener
diff --git a/webtoolbar.py b/webtoolbar.py
index c71ce1a..8c6393b 100644
--- a/webtoolbar.py
+++ b/webtoolbar.py
@@ -288,6 +288,12 @@ class WebToolbar(gtk.Toolbar):
self._create_ssb.connect('clicked', self._create_ssb_clicked_cb)
self.insert(self._create_ssb, -1)
self._create_ssb.show()
+
+ self._save_document = ToolButton('save')
+ self._save_document.set_tooltip(_('Save Document'))
+ self._save_document.connect('clicked', self._save_document_clicked_cb)
+ self.insert(self._save_document, -1)
+ self._save_document.show()
def _session_history_changed_cb(self, session_history, current_page_index):
# We have to wait until the history info is updated.
@@ -468,3 +474,7 @@ class WebToolbar(gtk.Toolbar):
self._ssb.show_in_journal()
else:
self._ssb.install()
+
+ def _save_document_clicked_cb(self, button):
+ import usercode
+ usercode.save_document(self._activity._browser)