diff options
author | portix <none@none> | 2012-04-29 13:09:56 +0200 |
---|---|---|
committer | portix <none@none> | 2012-04-29 13:09:56 +0200 |
commit | 3b75a96b57033f35f2e2aa983319760f9ce01f79 (patch) | |
tree | 21c0c7791fceaadf96dbea4144e31b11e3e31fe0 /scripts | |
parent | 1ee05fad020a5af499d0283273af4cb4f9c13d2b (diff) | |
download | dwb-3b75a96b57033f35f2e2aa983319760f9ce01f79.zip |
Get gobject properties from scripts; started rewriting of documentation
--HG--
branch : scripts
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/data.js | 94 | ||||
-rw-r--r-- | scripts/lib/extensions.js | 68 | ||||
-rw-r--r-- | scripts/lib/globals.js | 3 | ||||
-rw-r--r-- | scripts/lib/signals.js | 125 |
4 files changed, 188 insertions, 102 deletions
diff --git a/scripts/lib/data.js b/scripts/lib/data.js index 8079a996..1cfa800d 100644 --- a/scripts/lib/data.js +++ b/scripts/lib/data.js @@ -1,60 +1,34 @@ -Object.defineProperty(data, "bookmarks", { - value : data.configDir + "/" + data.profile + "/bookmarks", - enumerable : true -}); -Object.defineProperty(data, "history", { - value : data.configDir + "/" + data.profile + "/history", - enumerable : true -}); -Object.defineProperty(data, "cookies", { - value : data.configDir + "/" + data.profile + "/cookies", - enumerable : true -}); -Object.defineProperty(data, "quickmarks", { - value : data.configDir + "/" + data.profile + "/cookies", - enumerable : true -}); -Object.defineProperty(data, "cookies", { - value : data.configDir + "/" + data.profile + "/cookies", - enumerable : true -}); -Object.defineProperty(data, "cookiesWhitelist", { - value : data.configDir + "/" + data.profile + "/cookies.allow", - enumerable : true -}); -Object.defineProperty(data, "sessionCookiesWhitelist", { - value : data.configDir + "/" + data.profile + "/cookies_session.allow", - enumerable : true -}); -Object.defineProperty(data, "sessionCookiesWhitelist", { - value : data.configDir + "/" + data.profile + "/cookies_session.allow", - enumerable : true -}); -Object.defineProperty(data, "pluginsWhitelist", { - value : data.configDir + "/" + data.profile + "/plugins.allow", - enumerable : true -}); -Object.defineProperty(data, "scriptWhitelist", { - value : data.configDir + "/" + data.profile + "/scripts.allow", - enumerable : true -}); -Object.defineProperty(data, "session", { - value : data.configDir + "/" + data.profile + "/session", - enumerable : true -}); -Object.defineProperty(data, "customKeys", { - value : data.configDir + "/" + data.profile + "/custom_keys", - enumerable : true -}); -Object.defineProperty(data, "keys", { - value : data.configDir + "/keys", - enumerable : true -}); -Object.defineProperty(data, "settings", { - value : data.configDir + "/settings", - enumerable : true -}); -Object.defineProperty(data, "searchEngines", { - value : data.configDir + "/searchengines", - enumerable : true -}); +(function () { + var configDir = data.configDir; + var profile = data.profile; + Object.defineProperties(data, { + "bookmarks" : { value : configDir + "/" + profile + "/bookmarks", enumerable : true }, + "history" : { value : configDir + "/" + profile + "/history", enumerable : true }, + "cookies" : { value : configDir + "/" + profile + "/cookies", enumerable : true }, + "quickmarks" : { value : configDir + "/" + profile + "/cookies", enumerable : true }, + "cookies" : { value : configDir + "/" + profile + "/cookies", enumerable : true }, + "cookiesWhitelist" : { value : configDir + "/" + profile + "/cookies.allow", enumerable : true }, + "sessionCookiesWhitelist" : { value : configDir + "/" + profile + "/cookies_session.allow", enumerable : true }, + "sessionCookiesWhitelist" : { value : configDir + "/" + profile + "/cookies_session.allow", enumerable : true }, + "pluginsWhitelist" : { value : configDir + "/" + profile + "/plugins.allow", enumerable : true }, + "scriptWhitelist" : { value : configDir + "/" + profile + "/scripts.allow", enumerable : true }, + "session" : { value : configDir + "/" + profile + "/session", enumerable : true }, + "customKeys" : { value : configDir + "/" + profile + "/custom_keys", enumerable : true }, + "keys" : { value : configDir + "/keys", enumerable : true }, + "settings" : { value : configDir + "/settings", enumerable : true }, + "searchEngines" : { value : configDir + "/searchengines", enumerable : true }, + "cookies" : { value : configDir + "/" + profile + "/cookies", enumerable : true }, + "quickmarks" : { value : configDir + "/" + profile + "/cookies", enumerable : true }, + "cookies" : { value : configDir + "/" + profile + "/cookies", enumerable : true }, + "cookiesWhitelist" : { value : configDir + "/" + profile + "/cookies.allow", enumerable : true }, + "sessionCookiesWhitelist" : { value : configDir + "/" + profile + "/cookies_session.allow", enumerable : true }, + "sessionCookiesWhitelist" : { value : configDir + "/" + profile + "/cookies_session.allow", enumerable : true }, + "pluginsWhitelist" : { value : configDir + "/" + profile + "/plugins.allow", enumerable : true }, + "scriptWhitelist" : { value : configDir + "/" + profile + "/scripts.allow", enumerable : true }, + "session" : { value : configDir + "/" + profile + "/session", enumerable : true }, + "customKeys" : { value : configDir + "/" + profile + "/custom_keys", enumerable : true }, + "keys" : { value : configDir + "/keys", enumerable : true }, + "settings" : { value : configDir + "/settings", enumerable : true }, + "searchEngines" : { value : configDir + "/searchengines", enumerable : true } + }); +})(); diff --git a/scripts/lib/extensions.js b/scripts/lib/extensions.js new file mode 100644 index 00000000..e96ab7bd --- /dev/null +++ b/scripts/lib/extensions.js @@ -0,0 +1,68 @@ +Object.defineProperties(extensions, { + "config" : { + value : undefined + }, + "warning" : { + value : function (name, message) { + io.print("\033[1mDWB EXTENSION WARNING: \033[0mextension \033[1m" + name + "\033[0m: " + message, "stderr"); + } + }, + "error" : { + value : function (name, message) { + io.print("\033[31mDWB EXTENSION ERROR: \033[0mextension \033[1m" + name + "\033[0m: " + message, "stderr"); + } + }, + "message" : { + value : function (name, message) { + io.print("\033[1mDWB EXTENSION: \033[0mextension \033[1m" + name + "\033[0m: " + message, "stderr"); + } + }, + "load" : { + value : function (name) { + var boldname = "\033[1m" + name + "\033[0m"; + + var config, dataBase, pluginPath, plugin; + var extConfig = null; + + /* Get default config if the config hasn't been read yet */ + if (extensions._config === undefined) { + try { + config = include(data.configDir + "/extensionrc"); + } + catch (e) { + extensions.error(name, "loading config failed : " + e); + } + if (config === null) { + extensions.warning(name, "Could not load config."); + } + else { + Object.defineProperty(extensions, "_config", { + value : config + }); + } + } + if (extensions._config) { + extConfig = extensions._config[name] || null; + } + + /* Load extension */ + plugin = include(data.userDataDir + "/extensions/" + name); + if (plugin === null) { + plugin = include(data.systemDataDir + "/extensions/" + name); + if (plugin === null) { + extensions.error(name, "Couldn't find extension."); + return false; + } + + } + if (plugin.init(extConfig)) { + extensions.message(name, "Successfully loaded and initialized."); + return true; + } + else { + extensions.error(name, "Initialization failed."); + return false; + } + } + } +}); diff --git a/scripts/lib/globals.js b/scripts/lib/globals.js new file mode 100644 index 00000000..123e9c4c --- /dev/null +++ b/scripts/lib/globals.js @@ -0,0 +1,3 @@ +//Object.defineProperty(this, "globals", { +// value : {} +//}); diff --git a/scripts/lib/signals.js b/scripts/lib/signals.js index fccf2674..303e823a 100644 --- a/scripts/lib/signals.js +++ b/scripts/lib/signals.js @@ -1,50 +1,91 @@ -Object.defineProperty(signals, "_registered", { - value : {} -}); -Object.defineProperty(signals, "_maxId", { - value : 0, - writable : true -}); -Object.defineProperty(signals, "emit", { - value : function(sig, wv, o) { - var sigs = signals._registered[sig]; - var ret = false; - var i; - for (i=0; i<sigs.length; i++) { - ret = sigs[i].callback(wv, o) || ret; +Object.defineProperties(signals, { + "_registered" : { + value : {} + }, + "emit" : { + value : function(sig, args) { + var sigs = signals._registered[sig]; + var ret = false; + var i = 0; + do { + if (sigs[i].connected) { + ret = sigs[i].callback.apply(this, args) || ret; + i++; + } + else { + sigs.splice(i, 1); + } + } while (i<sigs.length); + if (signals._registered[sig].length === 0) { + signals[sig] = null; + } + return ret; } - return ret; - } -}); -Object.defineProperty(signals, "connect", { - value : function(sig, func) { - if (signals._registered[sig] === undefined || signals._registered[sig] === null) { - signals._registered[sig] = []; - signals[sig] = function (wv, o) { - return signals.emit(sig, wv, o); + }, + "connect" : { + value : (function () { + var id = 0; + return function(sig, func) { + ++id; + if (signals._registered[sig] === undefined || signals._registered[sig] === null) { + signals._registered[sig] = []; + signals[sig] = function () { return signals.emit(sig, arguments); }; + } + if (func === null || typeof func !== "function") { + return -1; + } + signals._registered[sig].push({callback : func, id : id, connected : true }); + return id; }; + })() + }, + "disconnect" : { + value : function(id) { + var sig, i, sigs; + for (sig in signals._registered) { + sigs = signals._registered[sig]; + for (i = 0; i<sigs.length; i++) { + if (sigs[i].id == id) { + if (signals._registered[sig].length === 1) { + signals[sig] = null; + } + else { + sigs[i].connected = false; + } + return true; + } + } + } + return false; } - if (func !== null && typeof func === "function") { - signals._maxId++; - signals._registered[sig].push({callback : func, id : signals._maxId }); - return signals._maxId; - } - return -1; - } -}); -Object.defineProperty(signals, "disconnect", { - value : function(id) { - var name, i, sigs; - for (name in signals._registered) { - sigs = signals._registered[name]; - for (i = 0; i<sigs.length; i++) { - if (sigs[i].id == id) { - delete sigs.splice(i, 1); - if (signals._registered[name].length === 0) - signals[name] = null; - return; + }, + "disconnectByFunction" : { + value : function(func) { + var sig, i, sigs, ret = false; + for (sig in signals._registered) { + sigs = signals._registered[sig]; + for (i = 0; i<sigs.length; i++) { + if (sigs[i].callback == func) { + if (signals._registered[sig].length === 1) { + signals[sig] = null; + } + else { + sigs[i].connected = false; + } + ret = true; + } } } + return ret; + } + }, + "disconnectByName" : { + value : function (name) { + if (signals[name] !== null && signals[name] !== undefined) { + signals[name] = null; + return true; + } + return false; } } }); |