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-07-20 12:03:52 (GMT)
committer Lucian Branescu Mihaila <lucian.branescu@gmail.com>2009-07-20 12:03:52 (GMT)
commit7131bdbf0fddae1c50b0b4bc0f6762b5195480b3 (patch)
tree02fd6c840d5c85f49c71fde4b6dd25c93b92d4ba
parentceb80786cdfbe373d12a77f3a747793bba4d6002 (diff)
Add userscript overwrite checking.
-rw-r--r--usercode.py10
-rw-r--r--viewsource.py2
-rw-r--r--webactivity.py26
3 files changed, 32 insertions, 6 deletions
diff --git a/usercode.py b/usercode.py
index ba7f1ad..0b62177 100644
--- a/usercode.py
+++ b/usercode.py
@@ -205,8 +205,18 @@ def add_script(location):
logging.debug('##### %s -> %s' % (location_uri.spec, file_uri.spec))
+ os.remove(file_path)
browser_persist.saveURI(location_uri, None, None, None, None, file_uri)
+def script_exists(location):
+ cls = components.classes["@mozilla.org/network/io-service;1"]
+ io_service = cls.getService(interfaces.nsIIOService)
+ location_uri = io_service.newURI(location, None, None)
+
+ if os.path.isfile(os.path.join(SCRIPTS_PATH, location_uri.path)):
+ return True
+ else:
+ return False
class Injector():
_com_interfaces_ = interfaces.nsIDOMEventListener
diff --git a/viewsource.py b/viewsource.py
index 870b176..5d6a5b6 100644
--- a/viewsource.py
+++ b/viewsource.py
@@ -148,6 +148,8 @@ class ViewSource(gtk.Window):
if document_path is not None:
self._select_source(document_path)
+
+ logging.debug('@@@@@ %s' % document_path)
def _calculate_char_width(self, char_count):
widget = gtk.Label('')
diff --git a/webactivity.py b/webactivity.py
index c40106c..ca35d70 100644
--- a/webactivity.py
+++ b/webactivity.py
@@ -166,6 +166,7 @@ import globalhistory
import filepicker
import bookmarklets
import usercode
+import viewsource
_LIBRARY_PATH = '/usr/share/library-common/index.html'
@@ -262,7 +263,7 @@ class WebActivity(activity.Activity):
f = open(os.path.join(activity.get_bundle_path(),
'data/homepage'))
self.homepage = f.read()
- f.close()
+ f.close()
# enable userscript saving
self._browser.userscript.connect('userscript-found',
@@ -528,7 +529,7 @@ class WebActivity(activity.Activity):
alert.props.msg = _('"%s" already exists. Overwrite?') % name
alert.connect('response', self._overwrite_bookmarklet_response_cb)
- # send the arguments through the alert
+ # send the arguments through the alert object
alert._bm = (name, url)
self.add_alert(alert)
@@ -544,9 +545,13 @@ class WebActivity(activity.Activity):
def _userscript_found_cb(self, listener, location):
alert = ConfirmationAlert()
alert.props.title = _('Add userscript')
- alert.props.msg = _('Do you want to add this userscript?')
+ if usercode.script_exists(location):
+ alert.props.msg = _('Userscript already exists. Overwrite?')
+ else:
+ alert.props.msg = _('Do you want to add this userscript?')
alert.connect('response', self._userscript_found_response_cb)
-
+
+ # send the argument through the alert object
alert._location = location
self.add_alert(alert)
@@ -660,5 +665,14 @@ class WebActivity(activity.Activity):
downloadmanager.remove_all_downloads()
self.close(force=True)
- def get_document_path(self, async_cb, async_err_cb):
- self._browser.get_source(async_cb, async_err_cb)
+ def handle_view_source(self):
+ logging.debug('##### local view source')
+ logging.debug('@@@@@ %s' % usercode.STYLE_PATH)
+ view_source = viewsource.ViewSource(self.get_xid(),
+ self.get_bundle_path(),
+ usercode.STYLE_PATH,
+ self.get_title())
+ #view_source.show()
+
+ #def get_document_path(self, async_cb, async_err_cb):
+ # self._browser.get_source(async_cb, async_err_cb)