Permalink
Browse files

Better organization of the code and a new html configuration page.

  • Loading branch information...
1 parent 5276001 commit ac552721ccb12f357055af4c3709eed005585dcf @mikeal committed Feb 2, 2009
@@ -0,0 +1,49 @@
+<html>
+<head>
+ <title>PushMarks</title>
+ <script type="text/javascript" src="jquery-1.3.1.min.js"></script>
+</head>
+
+<body>
+
+<script language="javascript" type="text/javascript">
+
+var prefs = Components.classes["@mozilla.org/preferences-service;1"]
+ .getService(Components.interfaces.nsIPrefService);
+prefs = prefs.getBranch("extensions.pushmarks.");
+
+function save () {
+ var prefValues = {
+ "deliciousEnabled" : $('input[@name=deliciousEnabled]')[0].checked,
+ "deliciousUsername" : $('input[@name=deliciousUsername]')[0].value,
+ "deliciousPassword" : $('input[@name=deliciousPassword]')[0].value,
+ };
+
+ prefs.setBoolPref('delicious.enabled', prefValues.deliciousEnabled);
+ prefs.setCharPref('delicious.username', prefValues.deliciousUsername);
+ prefs.setCharPref('delicious.password', prefValues.deliciousPassword);
+ service = {};
+ Components.utils.import('resource://pushmarks/modules/service.js', service);
+ service.refreshFromPrefs();
+}
+
+function initialize () {
+ $('input[@name=deliciousEnabled]')[0].checked = prefs.getBoolPref('delicious.enabled');
+ $('input[@name=deliciousUsername]')[0].value = prefs.getCharPref('delicious.username');
+ $('input[@name=deliciousPassword]')[0].value = prefs.getCharPref('delicious.password');
+}
+
+$(document).ready(initialize);
+
+</script>
+
+ <div class="in">
+ Delicious
+ <input type="checkbox" name="deliciousEnabled"> enabled <br>
+ Username: <input type="text" name="deliciousUsername" /> <br>
+ Password <input type="text" name="deliciousPassword"/> <br>
+ <a href="javascript:save()">save</a>
+ </div>
+</div>
+</body>
+</html>

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,3 @@
+pref("extensions.pushmarks.delicious.enabled", false);
+pref("extensions.pushmarks.delicious.username", "");
+pref("extensions.pushmarks.delicious.password", "");
@@ -36,9 +36,6 @@
var EXPORTED_SYMBOLS = ['getDelicious', 'fullSync', 'addedByExtension', 'Service', 'Bookmark', 'getAllBookmarks'];
-var Base64 = {}; Components.utils.import('resource://pushmarks/modules/base64.js', Base64);
-var Base64 = Base64.Base64;
-
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
@@ -60,49 +57,15 @@ var uuidgen = Components.classes["@mozilla.org/uuid-generator;1"]
.getService(Components.interfaces.nsIUUIDGenerator);
Components.utils.import("resource://gre/modules/JSON.jsm");
+Components.utils.import("resource://pushmarks/modules/service.js")
var withs = {}; Components.utils.import('resource://pushmarks/modules/withs.js', withs);
var arrays = {}; Components.utils.import('resource://pushmarks/modules/arrays.js', arrays);
+var utils = {}; Components.utils.import('resource://pushmarks/modules/utils.js', utils);
backstage = this;
addedCallback = null;
-function tempfile(appention) {
- if (appention == undefined) {
- var appention = "mozmill.utils.tempfile"
- }
- var tempfile = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("TmpD", Components.interfaces.nsIFile);
- tempfile.append(uuidgen.generateUUID().toString().replace('-', '').replace('{', '').replace('}',''))
- tempfile.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);
- tempfile.append(appention);
- tempfile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
- // do whatever you need to the created file
- return tempfile.clone();
-}
-
-function getWindows(type) {
- if (type == undefined) {
- var type = "";
- }
- var windows = []
- var enumerator = Components.classes["@mozilla.org/appshell/window-mediator;1"]
- .getService(Components.interfaces.nsIWindowMediator)
- .getEnumerator(type);
- while(enumerator.hasMoreElements()) {
- windows.push(enumerator.getNext());
- }
- return windows;
-}
-
-function getMethodInWindows (methodName) {
- for each(w in getWindows()) {
- if (w[methodName] != undefined) {
- return w[methodName];
- }
- }
- throw "Method with name: '"+methodName+"' is not in any open window.";
-}
-
function makeBaseAuth(user, pass) {
var tok = user + ':' + pass;
var hash = Base64.encode(tok);
@@ -111,54 +74,6 @@ function makeBaseAuth(user, pass) {
var unfiledFolder = bmsvc.unfiledBookmarksFolder
-var Service = {};
-Service.add = function (bookmark) {
- if (Service.deliciousEnabled) {
-
- Service.deliciousAdd(bookmark);
- }
-}
-Service.getFromDelicious = function (bookmark) {
-
-}
-Service._deliciousAdd = function (bookmark) {
- var XMLHttpRequest = getMethodInWindows('XMLHttpRequest');
- var req = new XMLHttpRequest();
- var url = 'https://api.del.icio.us/v1/posts/add?';
- url += '&url='+bookmark.uri;
- url += '&description='+bookmark.title;
- url += '&extended='+bookmark.title;
- url += '&tags='+bookmark.tags.join(' ');
- req.open('GET', url, false, Service.deliciousUsername, Service.deliciousPassword);
- req.setRequestHeader('User-Agent', 'pushmarks-0.1');
- req.send(null);
- if (req.status != 200) {
- throw "Request to delicious failed, status code "+req.status+". Message: "+String(req.responseText);
- }
- return req
-}
-Service._deliciousAddQueue = [];
-Service.deliciousAdd = function (bookmark) {
- Service._deliciousAddQueue.push(bookmark);
- if (Service.timeoutSet == false) {
- Service.setTimeoutQueue();
- }
-}
-Service.timeoutSet = false;
-Service.queueDo = function () {
- if (Service._deliciousAddQueue.length == 0) {
- hwindow.clearInterval(Service.timeoutSet);
- Service.timeoutSet = false;
- } else {
- Service._deliciousAdd(Service._deliciousAddQueue.pop())
- }
-}
-Service.setTimeoutQueue = function () {
- hwindow.Service = Service;
- Service.timeoutSet = hwindow.setInterval("Service.queueDo()", 5000);
-}
-Service.deliciousUsername = null;
-Service.deliciousPassword = null;
var Bookmark = function (uri, title, tags) {
this.uri = uri;
@@ -207,7 +122,7 @@ Bookmark.prototype.push = function() {
}
// var getDelicious = function (username, password) {
-// var XMLHttpRequest = getMethodInWindows('XMLHttpRequest');
+// var XMLHttpRequest = utils.getMethodInWindows('XMLHttpRequest');
// var req = new XMLHttpRequest();
// req.open('GET', 'https://api.del.icio.us/v1/posts/all', false, username, password);
// req.setRequestHeader('User-Agent', 'pushmarks-0.1')
@@ -245,7 +160,7 @@ var getDelicious = function(username, password) {
file.initWithPath("/Users/mikeal/Documents/git/pushmarks/all.xml");
// |file| is nsIFile
data = readFile(file)
- var parser = new getMethodInWindows('DOMParser')();
+ var parser = new utils.getMethodInWindows('DOMParser')();
var dom = parser.parseFromString(data, "text/xml");
posts = dom.getElementsByTagName('post');
bookmarks = []
@@ -309,8 +224,8 @@ var ignoreBookmarks = [
]
var getAllBookmarks = function () {
- var f = tempfile()
- var PlacesUtils = getMethodInWindows('PlacesUtils');
+ var f = utils.tempfile()
+ var PlacesUtils = utils.getMethodInWindows('PlacesUtils');
PlacesUtils.backupBookmarksToFile(f);
var recursizeChildAdd = function(node, hash) {
@@ -345,7 +260,7 @@ var myExt_bookmarkListener = {
},
onItemVisited: function(aBookmarkId, aVisitID, time) {},
onItemMoved: function(aItemId, aOldParent, aOldIndex, aNewParent, aNewIndex) {},
- QueryInterface: getMethodInWindows('XPCOMUtils').generateQI([Components.interfaces.nsINavBookmarkObserver])
+ QueryInterface: utils.getMethodInWindows('XPCOMUtils').generateQI([Components.interfaces.nsINavBookmarkObserver])
};
// An extension
@@ -0,0 +1,98 @@
+// ***** BEGIN LICENSE BLOCK *****
+// Version: MPL 1.1/GPL 2.0/LGPL 2.1
+//
+// The contents of this file are subject to the Mozilla Public License Version
+// 1.1 (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+// http://www.mozilla.org/MPL/
+//
+// Software distributed under the License is distributed on an "AS IS" basis,
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+// for the specific language governing rights and limitations under the
+// License.
+//
+// The Original Code is Mozilla Corporation Code.
+//
+// The Initial Developer of the Original Code is
+// Mikeal Rogers.
+// Portions created by the Initial Developer are Copyright (C) 2009
+// the Initial Developer. All Rights Reserved.
+//
+// Contributor(s):
+// Mikeal Rogers <mikeal.rogers@gmail.com>
+//
+// Alternatively, the contents of this file may be used under the terms of
+// either the GNU General Public License Version 2 or later (the "GPL"), or
+// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+// in which case the provisions of the GPL or the LGPL are applicable instead
+// of those above. If you wish to allow use of your version of this file only
+// under the terms of either the GPL or the LGPL, and not to allow others to
+// use your version of this file under the terms of the MPL, indicate your
+// decision by deleting the provisions above and replace them with the notice
+// and other provisions required by the GPL or the LGPL. If you do not delete
+// the provisions above, a recipient may use your version of this file under
+// the terms of any one of the MPL, the GPL or the LGPL.
+
+var EXPORTED_SYMBOLS = ['Service', 'refreshFromPrefs']
+
+var utils = {}; Components.utils.import('resource://pushmarks/modules/utils.js', utils);
+
+var Service = {};
+Service.add = function (bookmark) {
+ if (Service.deliciousEnabled) {
+
+ Service.deliciousAdd(bookmark);
+ }
+}
+Service.getFromDelicious = function (bookmark) {
+
+}
+Service._deliciousAdd = function (bookmark) {
+ var XMLHttpRequest = utils.getMethodInWindows('XMLHttpRequest');
+ var req = new XMLHttpRequest();
+ var url = 'https://api.del.icio.us/v1/posts/add?';
+ url += '&url='+bookmark.uri;
+ url += '&description='+bookmark.title;
+ url += '&extended='+bookmark.title;
+ url += '&tags='+bookmark.tags.join(' ');
+ req.open('GET', url, false, Service.deliciousUsername, Service.deliciousPassword);
+ req.setRequestHeader('User-Agent', 'pushmarks-0.1');
+ req.send(null);
+ if (req.status != 200) {
+ throw "Request to delicious failed, status code "+req.status+". Message: "+String(req.responseText);
+ }
+ return req
+}
+Service._deliciousAddQueue = [];
+Service.deliciousAdd = function (bookmark) {
+ Service._deliciousAddQueue.push(bookmark);
+ if (Service.timeoutSet == false) {
+ Service.setTimeoutQueue();
+ }
+}
+Service.timeoutSet = false;
+Service.queueDo = function () {
+ if (Service._deliciousAddQueue.length == 0) {
+ hwindow.clearInterval(Service.timeoutSet);
+ Service.timeoutSet = false;
+ } else {
+ Service._deliciousAdd(Service._deliciousAddQueue.pop())
+ }
+}
+Service.setTimeoutQueue = function () {
+ hwindow.Service = Service;
+ Service.timeoutSet = hwindow.setInterval("Service.queueDo()", 5000);
+}
+Service.deliciousUsername = null;
+Service.deliciousPassword = null;
+
+
+var prefs = Components.classes["@mozilla.org/preferences-service;1"]
+ .getService(Components.interfaces.nsIPrefService);
+prefs = prefs.getBranch("extensions.pushmarks.");
+
+var refreshFromPrefs = function () {
+ Service.deliciousEnabled = prefs.getBoolPref('delicious.enabled');
+ Service.deliciousUsername = prefs.getBoolPref('delicious.username');
+ Service.deliciousPassword = prefs.getBoolPref('delicious.password');
+}
@@ -0,0 +1,80 @@
+// ***** BEGIN LICENSE BLOCK *****
+// Version: MPL 1.1/GPL 2.0/LGPL 2.1
+//
+// The contents of this file are subject to the Mozilla Public License Version
+// 1.1 (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+// http://www.mozilla.org/MPL/
+//
+// Software distributed under the License is distributed on an "AS IS" basis,
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+// for the specific language governing rights and limitations under the
+// License.
+//
+// The Original Code is Mozilla Corporation Code.
+//
+// The Initial Developer of the Original Code is
+// Mikeal Rogers.
+// Portions created by the Initial Developer are Copyright (C) 2009
+// the Initial Developer. All Rights Reserved.
+//
+// Contributor(s):
+// Mikeal Rogers <mikeal.rogers@gmail.com>
+//
+// Alternatively, the contents of this file may be used under the terms of
+// either the GNU General Public License Version 2 or later (the "GPL"), or
+// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+// in which case the provisions of the GPL or the LGPL are applicable instead
+// of those above. If you wish to allow use of your version of this file only
+// under the terms of either the GPL or the LGPL, and not to allow others to
+// use your version of this file under the terms of the MPL, indicate your
+// decision by deleting the provisions above and replace them with the notice
+// and other provisions required by the GPL or the LGPL. If you do not delete
+// the provisions above, a recipient may use your version of this file under
+// the terms of any one of the MPL, the GPL or the LGPL.
+
+var EXPORTED_SYMBOLS = ['tempfile', 'getWindows', 'getMethodInWindows'];
+
+var ios = Components.classes["@mozilla.org/network/io-service;1"]
+ .getService(Components.interfaces.nsIIOService);
+var hwindow = Components.classes["@mozilla.org/appshell/appShellService;1"]
+ .getService(Components.interfaces.nsIAppShellService)
+ .hiddenDOMWindow;
+var uuidgen = Components.classes["@mozilla.org/uuid-generator;1"]
+ .getService(Components.interfaces.nsIUUIDGenerator);
+
+function tempfile(appention) {
+ if (appention == undefined) {
+ var appention = "mozmill.utils.tempfile"
+ }
+ var tempfile = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("TmpD", Components.interfaces.nsIFile);
+ tempfile.append(uuidgen.generateUUID().toString().replace('-', '').replace('{', '').replace('}',''))
+ tempfile.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);
+ tempfile.append(appention);
+ tempfile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
+ // do whatever you need to the created file
+ return tempfile.clone();
+}
+
+function getWindows(type) {
+ if (type == undefined) {
+ var type = "";
+ }
+ var windows = []
+ var enumerator = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Components.interfaces.nsIWindowMediator)
+ .getEnumerator(type);
+ while(enumerator.hasMoreElements()) {
+ windows.push(enumerator.getNext());
+ }
+ return windows;
+}
+
+function getMethodInWindows (methodName) {
+ for each(w in getWindows()) {
+ if (w[methodName] != undefined) {
+ return w[methodName];
+ }
+ }
+ throw "Method with name: '"+methodName+"' is not in any open window.";
+}

0 comments on commit ac55272

Please sign in to comment.