home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Narzedzia
/
AIMP2
/
aimp_2.61.583.exe
/
$TEMP
/
YandexPackSetup.msi
/
fil03B29CDBD7A70AE54F431427D6AF92A7
< prev
next >
Wrap
Text File
|
2010-07-12
|
13KB
|
421 lines
var gYaOverlay = {
_yaToolbarId: "yasearch-bar",
_yaIdPrefix: "yasearch",
_yaIdPrefixRE: /^yasearch\-/,
_inited: false,
init: function Overlay_init() {
if (!this._inited) {
this._inited = true;
Components.utils.import("resource://yasearch/bar.protocol.jsm", this);
this.ProtocolHandler.addHandler(this.barProtocolHandler);
}
},
shutdown: function Overlay_destroy() {
if (this._inited) {
this._inited = false;
this.ProtocolHandler.removeHandler(this.barProtocolHandler);
}
},
get _rdf() {
delete this._rdf;
return this._rdf = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
},
get _dataSource() {
delete this._dataSource;
return this._dataSource = this._rdf.GetDataSource("rdf:local-store");
},
getRDFLiteralValue: function Overlay_getRDFLiteralValue(aSource, aProperty) {
let target = this._dataSource.GetTarget(aSource, aProperty, true);
if (target instanceof Ci.nsIRDFLiteral)
return target.Value;
return null;
},
setRDFLiteralValue: function Overlay_setRDFLiteralValue(aSource, aProperty, aTarget) {
try {
var oldTarget = this._dataSource.GetTarget(aSource, aProperty, true);
if (oldTarget) {
if (aTarget)
this._dataSource.Change(aSource, aProperty, oldTarget, this._rdf.GetLiteral(aTarget));
else
this._dataSource.Unassert(aSource, aProperty, oldTarget);
} else {
this._dataSource.Assert(aSource, aProperty, this._rdf.GetLiteral(aTarget), true);
}
} catch(e) {}
},
_mirateHelpInfo: {
quote: {
newPrefsId: "yasearch.xbwidgets.http://bar.yandex.ru/packages/yandexbar#quote",
newInstId: "yasearch.cb-http://bar.yandex.ru/packages/yandexbar#quote-inst-",
oldPrefsId: "yasearch.xbwidgets.A78155FC-41D5-4304-BD60-A01D8C1FB9FA",
oldInstId: "yasearch.cb-A78155FC-41D5-4304-BD60-A01D8C1FB9FA-inst-"
},
town: {
newPrefsId: "yasearch.xbwidgets.http://bar.yandex.ru/packages/yandexbar#town",
newInstId: "yasearch.cb-http://bar.yandex.ru/packages/yandexbar#town-inst-"
}
},
_migrateInstCounter: 1,
_generateNewMigrateInstId: function() {
return (Date.now() + this._migrateInstCounter++);
},
_migrateQuoteItem: function(aOldQuoteId) {
let helpInfo = this._mirateHelpInfo.quote;
let [, instId] = aOldQuoteId.split(helpInfo.oldInstId);
gYaSearchService.log("instId " + instId);
let quoteInstIdPrefix = [helpInfo.newPrefsId, instId, "settings.quote-id"].join(".");
let oldQuotePrefName = [helpInfo.oldPrefsId, instId, "quote-id"].join(".");
let oldQuoteId = gYaSearchService.getIntPref(oldQuotePrefName) || gYaSearchService.getCharPref(oldQuotePrefName);;
if (oldQuoteId) {
gYaSearchService.setCharPref(quoteInstIdPrefix, oldQuoteId);
}
gYaSearchService.resetPref(oldQuotePrefName);
return helpInfo.newInstId + instId;
},
_migrateCityItem: function(aOldCityId) {
let helpInfo = this._mirateHelpInfo.town;
let instId = this._generateNewMigrateInstId();
let townInstIdPrefix = [helpInfo.newPrefsId, instId, "settings"].join(".");
let props = this._getCityProps(aOldCityId);
if (props.cityId)
gYaSearchService.setIntPref(townInstIdPrefix + ".id", props.cityId);
if (props.weatherEnabledValue)
gYaSearchService.setBoolPref(townInstIdPrefix + ".show-weather", props.weatherEnabled);
if (props.trafficEnabledValue)
gYaSearchService.setBoolPref(townInstIdPrefix + ".show-traffic", props.trafficEnabled);
return helpInfo.newInstId + instId;
},
_getCityProps: function(aOldCityId) {
var props = aOldCityId.split("-");
function unescapePureLabel(aString) {
return aString.replace(/\$1/g, "-").replace(/\$2/g, ",");
}
return {
cityId: props[3] || "",
labelPure: props[4] || "",
labelAliasPure: props[7] || "",
get labelAlias() { return unescapePureLabel(this.labelAliasPure) },
weatherEnabledValue: props[5] || "",
trafficEnabledValue: props[6] || "",
get weatherEnabled() {
return (this.weatherEnabledValue != "0");
},
get trafficEnabled() {
return (this.trafficEnabledValue == "1");
}
}
},
migrateWidgets: function(aLastVersion) {
if (aLastVersion >= "5.0")
return;
let migrateHelpInfo = this._mirateHelpInfo;
let oldTownUpdateInterval = gYaSearchService.getIntPref("yasearch.http.update.weathertraff.interval");
if (oldTownUpdateInterval !== null) {
gYaSearchService.setIntPref(migrateHelpInfo.town.newPrefsId + ".all.settings.update-interval", oldTownUpdateInterval);
gYaSearchService.resetPref("yasearch.http.update.weathertraff.interval");
}
let oldQuoteUpdateInterval = gYaSearchService.getIntPref(migrateHelpInfo.quote.oldPrefsId + ".all.update-interval");
if (oldQuoteUpdateInterval !== null) {
gYaSearchService.setIntPref(migrateHelpInfo.quote.newPrefsId + ".all.settings.update-interval", oldQuoteUpdateInterval);
gYaSearchService.resetPref(migrateHelpInfo.quote.oldPrefsId + ".all.update-interval");
}
let oldQuoteInstIdPrefix = migrateHelpInfo.quote.oldInstId;
let dirty = false;
let allResources = this._dataSource.GetAllResources();
let currentsetResource = this._rdf.GetResource("currentset");
while (allResources.hasMoreElements()) {
let res = allResources.getNext().QueryInterface(Ci.nsIRDFResource);
let tool = res.Value;
if (tool) {
let _dirty = false;
let currentsetIds;
let toolbar = this._rdf.GetResource(tool);
let currentSet = this.getRDFLiteralValue(toolbar, currentsetResource);
if (currentSet && currentSet != "__empty") {
[",yasearch-bloggers,separator,yasearch-spellchecker,",
",yasearch-bookmarks,separator,yasearch-preferences,"]
.forEach(function(aDefaultsetNewPart) {
let oldPart = aDefaultsetNewPart.split("separator,").join("");
if (currentSet.indexOf(oldPart) > 0) {
currentSet = currentSet.replace(oldPart, aDefaultsetNewPart);
_dirty = true;
}
});
currentsetIds = currentSet.split(",");
for (let i = 0, len = currentsetIds.length; i < len; i++) {
if (currentsetIds[i]) {
let id = currentsetIds[i];
if (id.indexOf("yasearch-city-") == 0) {
currentsetIds[i] = this._migrateCityItem(id);
_dirty = true;
} else if (id.indexOf(oldQuoteInstIdPrefix) == 0) {
currentsetIds[i] = this._migrateQuoteItem(id);
_dirty = true;
}
}
}
}
if (_dirty) {
this.setRDFLiteralValue(toolbar, currentsetResource, currentsetIds.join(","));
dirty = true;
}
}
}
if (dirty)
this._dataSource.QueryInterface(Ci.nsIRDFRemoteDataSource).Flush();
},
get defaultset() {
delete this.defaultset;
return this.defaultset = this.overlayDocument.getElementById(this._yaToolbarId).getAttribute("defaultset");
},
setToolbarCollapsedState: function Overlay_setCollapsedState(aCollapsedState) {
if (typeof aCollapsedState !== "boolean")
return;
let newCollapsedState = aCollapsedState.toString();
try {
let collapsedResource = this._rdf.GetResource("collapsed");
let toolbarResource = this._rdf.GetResource("chrome://browser/content/browser.xul#yasearch-bar");
let currentCollapsedState = this.getRDFLiteralValue(toolbarResource, collapsedResource);
if ((currentCollapsedState || "false").toString() != newCollapsedState) {
this.setRDFLiteralValue(toolbarResource, collapsedResource, newCollapsedState);
this._dataSource.QueryInterface(Ci.nsIRDFRemoteDataSource).Flush();
}
} catch(e) {}
},
get _CurrentsetIds() {
delete this._CurrentsetIds;
this._CurrentsetIds = new G_HashTable();
let allResources = this._dataSource.GetAllResources();
let currentsetResource = this._rdf.GetResource("currentset");
let re = this._yaIdPrefixRE;
while (allResources.hasMoreElements()) {
let res = allResources.getNext().QueryInterface(Ci.nsIRDFResource);
let tool = res.Value;
if (tool) {
let toolbar = this._rdf.GetResource(tool);
let currentSet = this.getRDFLiteralValue(toolbar, currentsetResource);
if (currentSet) {
for each (let elemId in currentSet.split(",")) {
if (re.test(elemId)) {
this._CurrentsetIds.put(elemId, true);
}
}
}
}
}
for each (let elemId in this.defaultset.split(",")) {
if (re.test(elemId)) {
this._CurrentsetIds.put(elemId, true);
}
}
return this._CurrentsetIds;
},
get CurrentsetIds() {
return this._CurrentsetIds;
},
get ClonesData() {
delete this.ClonesData;
this.ClonesData = new G_HashTable();
let re = this._yaIdPrefixRE;
this.ClonesData.getNodeForId = function(aId) {
if (!(typeof aId == "string" && re.test(aId)))
return null;
return this.get(aId.split(/\-\d/)[0]);
}
this.ClonesData.getCloneForId = function(aId) {
let cloned = null;
let node = this.getNodeForId(aId);
if (node) {
cloned = node.cloneNode(true);
cloned.setAttribute("yadouble", "child");
cloned.setAttribute("id", aId);
}
return cloned;
}
let elements =
Array.slice(this.overlayDocument.getElementsByTagName("toolbaritem"))
.filter(function(el) {
return el.getAttribute("yadouble") == "parent" && re.test(el.getAttribute("id"));
});
for each (var el in elements) {
this.ClonesData.put(el.getAttribute("id"), el);
}
return this.ClonesData;
},
get overlayDocument() {
delete this.overlayDocument;
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
let overlayFile = gYaSearchService.getContentDir();
overlayFile.append("yasearch.xul");
let overlayData = gYaSearchService.readFile(overlayFile);
let overlayDoc = gYaSearchService.domParser.parseFromString(overlayData, "text/xml");
return this.overlayDocument = overlayDoc;
},
insertToolbarItem: function(aId, aBeforeElement, aBrowser) {
if ((aBeforeElement instanceof Ci.nsIDOMElement) && !aBrowser)
return [];
let newItemId = aId + "-" + Date.now();
let clone = this.ClonesData.getCloneForId(newItemId);
if (!clone)
return [];
function getBeforeElement(aToolbar) {
let node;
if (aBeforeElement) {
if (aBeforeElement instanceof Ci.nsIDOMElement)
node = aBeforeElement;
else
node = aToolbar.getElementsByAttribute("id", aBeforeElement)[0];
}
return node;
}
let browsers = typeof aBrowser != "undefined" ? [aBrowser] : gYaSearchService.getWindows("navigator:browser");
let newItemNode = null;
for each (let browser in browsers) {
let toolbar = browser.document.getElementById(this._yaToolbarId);
if (toolbar) {
newItemNode = toolbar.ownerDocument.importNode(clone.cloneNode(true), true);
let beforeElt = getBeforeElement(toolbar);
if (beforeElt)
toolbar.insertBefore(newItemNode, beforeElt);
else
toolbar.appendChild(newItemNode);
}
}
return [newItemId, newItemNode];
},
barProtocolHandler: {
canHandleSpec: function(aSpec) {
return aSpec === "browser-overlay";
},
newURI: function(aSpec, aOriginalCharset, aBaseURI) {
if (aSpec === "browser-overlay") {
try {
let content = btoa(this._docontent());
let uri = Cc["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI);
uri.spec = "data:application/vnd.mozilla.xul+xml;base64," + content;
return uri;
} catch(e) {
gYaSearchService.log("gYaOverlay.newURI: can't create content URI\n" + e);
}
}
return null;
},
newChannel: function(aURI) {
return null;
},
_docontent: function() {
let clonedOverlayDoc = gYaSearchService.domParser.parseFromString(' \
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> \
<toolbarpalette id="BrowserToolbarPalette"/> \
</overlay>', "text/xml");
let toolbarPalette = clonedOverlayDoc.getElementById("BrowserToolbarPalette");
let clonesData = gYaOverlay.ClonesData;
for (let [id,] in gYaOverlay.CurrentsetIds) {
let clone = clonesData.getCloneForId(id);
if (clone)
toolbarPalette.appendChild(clone);
}
return UConverter.ConvertFromUnicode(gYaSearchService.xmlSerializer.serializeToString(clonedOverlayDoc));
}
}
};