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
/
filBF7F26F5B896BD8B655E131FC8B77D36
< prev
next >
Wrap
Text File
|
2010-07-12
|
15KB
|
493 lines
var gYaUServices = {
_servicesFileName: "services.mybar.xml",
_servicesFileURL: "http://export.yandex.ru/xml/services.mybar.xml",
_countersServicesURL: "http://export.yandex.ru/for/counters.xml",
_servicesFileWrapper: null,
_timedHTTPRequester: null,
_timedHTTPRequesterCallback: function(aResponseData) {
var data = gYaSearchService.safeE4Xml(aResponseData, null, ["services"]);
return (data && data..service.length() > 5) ? aResponseData : null;
},
_init: function() {
OBSERVER_SERVICE.addObserver(this, "quit-application-granted", false);
OBSERVER_SERVICE.addObserver(this, "profile-after-change", false);
OBSERVER_SERVICE.addObserver(this, "profile-before-change", false);
},
_uninit: function() {
OBSERVER_SERVICE.removeObserver(this, "profile-before-change");
OBSERVER_SERVICE.removeObserver(this, "profile-after-change");
OBSERVER_SERVICE.removeObserver(this, "quit-application-granted");
},
_profileInit: function() {
this._timedHTTPRequester = new G_TimedHTTPRequester(
"servicesmybar", this._servicesFileURL, this._servicesFileName,
this._timedHTTPRequesterCallback.bind(this)// default: 2 weeks, 1 hour
);
this._servicesFileWrapper = new G_HTTPFileWrapper(this._servicesFileName, ["services"]);
this.servicesXMLData;
},
_profileUninit: function() {
this._servicesFileWrapper = null;
},
observe: function(aSubject, aTopic, aData) {
switch (aTopic) {
case "quit-application-granted":
this._uninit();
break;
case "profile-after-change":
this._profileInit();
break;
case "profile-before-change":
this._profileUninit();
break;
}
},
_data: {},
_SERVICES_DATA: {
mail: { sid: 43, isCounter: true },
lenta: { sid: 44, isCounter: true, notifyUser: true },
money: { sid: 45, isCounter: true },
fotki: { sid: 46, isCounter: true },
yaru: { sid: 47, isCounter: true, alias: "blogs"},
moikrug: { sid: 48, isCounter: true}
},
get SERVICES_DATA() {
return this._SERVICES_DATA;
},
_getServiceAlias: function(aServiceName) {
let alias = aServiceName;
if (aServiceName in this.SERVICES_DATA)
alias = this.SERVICES_DATA[aServiceName].alias || aServiceName;
return alias;
},
getSID: function(aType) {
return this.SERVICES_DATA[aType].sid;
},
getURLForSID: function(aTypes) {
let params = [];
if (aTypes === "allCounters") {
const servicesData = this.SERVICES_DATA;
let buttonsInfo = gYaSearchService.buttonsInfo;
if (buttonsInfo) {
for (let service in servicesData) {
let sData = servicesData[service];
if (sData.isCounter && sData.sid && buttonsInfo[service]) {
params.push("services=" + sData.sid);
}
}
}
} else if (aTypes === "allServices") {
params.push("services=all");
} else {
for each (let type in aTypes)
params.push("services=" + this.getSID(type));
}
if (!params.length)
return false;
return this._countersServicesURL + "?" + params.join("&").replace(/'/g, "\\'");
},
_errorTimeout: 0,
get errorTimeout() {
var timeout = (this._errorTimeout || 1) * Math.max(5, gYaSearchService.getIntPref("yasearch.http.update.interval"));
return Math.min(15, timeout) * MIN_SEC;
},
set errorTimeout(val) {
this._errorTimeout = (val === null) ? 0 : Math.min(3, Math.max(1, val));
return this._errorTimeout;
},
_error: false,
get error() {
return this._error;
},
set error(val) {
this._error = val;
return this._error;
},
get login() {
return gYaSearchService.username;
},
_usersData: {},
_getUserData: function(aLogin) {
if (!aLogin)
return null;
if (!this._usersData[aLogin])
this._usersData[aLogin] = <s><c/></s>;
return this._usersData[aLogin];
},
_getUserCounters: function(aLogin) {
let userData = this._getUserData(aLogin);
if (!userData)
return null;
return userData.c[0];
},
get currentUserData() {
return this._getUserData(this.login);
},
get currentUserCounters() {
return this._getUserCounters(this.login);
},
setAllServicesError: function(aNotifyObservers) {
if (aNotifyObservers)
OBSERVER_SERVICE.notifyObservers(null, "Ya-Refresh-Data", "allServices");
},
setDataFromInboxString: function(aCounterTypes, aInboxXMLString) {
let currentUserCounters = this.currentUserCounters;
if (!currentUserCounters)
return;
let xmlData = gYaSearchService.safeE4Xml(aInboxXMLString, null, "s");
let xmlCountersData = xmlData ? xmlData.c[0] : null;
if (!xmlCountersData)
return;
if (aCounterTypes.allServices || aCounterTypes.mailAndFeeds)
aCounterTypes = this.SERVICES_DATA;
for (let counterType in aCounterTypes) {
let counterName = this._getServiceAlias(counterType);
let counterData = xmlCountersData[counterName][0];
if (!currentUserCounters[counterName].length())
currentUserCounters[counterName] = new XML("<" + counterName + "/>");
let serviceData = currentUserCounters[counterName];
if (counterData) {
let counterError = counterData.@e.toString() || "0";
if (counterError == "0") {
let counterValue = parseInt(counterData.@v, 10) || 0;
if (counterType in this.SERVICES_DATA && this.SERVICES_DATA[counterType].notifyUser) {
let cDiff = counterValue - parseInt(serviceData.@permCounter, 10);
if (cDiff != 0 && counterValue > 0)
gYaSearchService.notifyAboutNewItems(counterType, cDiff > 0 ? cDiff : counterValue);
}
serviceData.@permCounter = counterValue;
serviceData.@lastVisited = Date.now();
}
for each (let propNode in counterData.@*)
serviceData["@" + propNode.name()] = propNode.toString();
serviceData.@error = counterError;
} else {
serviceData.@v = 0;
}
}
},
_getXMLDataForService: function(aServiceName) {
let xmlCountersData = this.currentUserCounters;
if (!xmlCountersData)
return null;
let counterName = this._getServiceAlias(aServiceName);
let counterData = xmlCountersData[counterName][0];
return counterData || null;
},
getCount: function(aServiceName, aCounterProp) {
let counterData = this._getXMLDataForService(aServiceName);
if (!counterData || counterData.@error != "0")
return null;
let counterProp = aCounterProp || "v";
switch (counterProp) {
case "comments":
counterProp = "c";
case "v":
case "c":
break;
default:
return null;
}
return parseInt(counterData["@" + counterProp].toString(), 10) || null;
},
getXULNode: function(aServiceName) {
let result = <counter><data/></counter>;
let login = this.login;
if (login) {
let xmlData = this._getXMLDataForService(aServiceName);
if (xmlData) {
result.@login = login;
for each (let propNode in xmlData.@*)
result.data["@" + propNode.name()] = propNode.toString();
}
}
return gYaSearchService.getDOMDocContent("counter-" + aServiceName,
gYaSearchService.domParser.parseFromString(result.toSource(), "text/xml"));
},
_handleNoAuth: function() {
gYaSearchService.mailCounter = 0;
gYaSearchService.mailDOMMenuDoc = false;
},
getErrorFromInboxString: function(aInboxXMLString) {
let error = false;
let xmlData = gYaSearchService.safeE4Xml(aInboxXMLString, null, "s");
if (!xmlData || (xmlData.@error.toString() > "")) {
error = { type: "error" };
} else {
if (xmlData.toXMLString() === "<s/>") {
error = { type: "noauth" };
this._handleNoAuth();
}
}
return (this.error = error);
},
appendUserSessionData: function(aLogin, aServiceXMLData, aYaruXMLData) {
let userCounters = this._getUserCounters(aLogin);
for each (let serviceNode in aServiceXMLData.*) {
let serviceName = serviceNode.name();
if (!userCounters[serviceName].length())
userCounters[serviceName] = <{serviceName}/>;
userCounters[serviceName].@permCounter = gYaSearchService.parseIntFromStr(serviceNode.@pcounter.toString());
userCounters[serviceName].@error = serviceNode.@perror.toString() === "0" ? 0 : 10;
}
this.setYaruUserData(aYaruXMLData, aLogin);
},
getUserSessionDataForFlush: function(aLogin) {
let counters = <counters/>;
let userCounters = this._getUserCounters(aLogin);
for each (let counter in userCounters) {
let permCounter = gYaSearchService.parseIntFromStr(counter.@permCounter.toString());
let permError = gYaSearchService.parseIntFromStr(counter.@error.toString());
if (permCounter || permError === 0) {
let counterName = counter.name();
counters[counterName].@pcounter = permCounter;
counters[counterName].@perror = permError;
}
}
return [counters, this.getYaruUserData(aLogin)];
},
getServicesXML: function(aLogin) {
let servicesXML = this._servicesFileWrapper.mergedContent;
if (!servicesXML)
return null;
let oldFeeds = servicesXML.service.(function::attribute("name") == "lenta")[0];
let newFeeds = servicesXML.service.(function::attribute("name") == "subscriptions")[0];
if (oldFeeds && newFeeds) {
delete oldFeeds.parent().service[oldFeeds.childIndex()];
newFeeds.@name = "lenta";
}
for each (let node in servicesXML.service..*.(!function::hasComplexContent() && /\{user\}/.test(function::text())))
node.setChildren(node.text().toString().replace(/\{user\}/g, this.login));
return servicesXML;
},
getServicesLocalizedXML: function() {
let servicesXML = this.getServicesXML();
if (!servicesXML)
return null;
let currentLang = gYaSearchService.localeLang;
let currentLangFix = gYaSearchService.localeTld;
let defaultLang = "ru";
for each (let service in servicesXML.service) {
for each (let serviceNode in service.*) {
let serviceName = serviceNode.name();
let nodes = service[serviceName];
if (nodes.length() > 1) {
let node = nodes.(function::attribute("lang") == currentLang)[0] ||
nodes.(function::attribute("lang") == currentLangFix)[0] ||
nodes.(function::attribute("lang").length() == 0)[0] ||
nodes.(function::attribute("lang") == defaultLang)[0];
if (node) {
delete service[serviceName];
delete node.@lang;
service.appendChild(node);
}
}
}
}
return servicesXML;
},
getServiceLocalizedXML: function(aServiceName) {
let servicesXML = this.getServicesLocalizedXML();
if (!servicesXML)
return null;
let serviceXML = servicesXML.service.(function::attribute("name") == aServiceName)[0];
return serviceXML || null;
},
getUserServicesXUL: function() {
let servicesXML = this.getServicesLocalizedXML();
if (!servicesXML)
return null;
let i = 0,
sortArr = [];
for each (let service in servicesXML.service) {
let counterData = this._getXMLDataForService(service.@name.toString());
service.@sorthelper = i++;
service.@error = 30;
if (counterData) {
service.@error = counterData.@error.toString() == "40" ? 0 : counterData.@error.toString();
if (counterData.@v.length() == 1)
service.@v = counterData.@v;
}
sortArr.push(service);
}
delete servicesXML.service;
sortArr.sort(function(a,b) {
let aE = a.@error.toString(), bE = b.@error.toString();
let aS = parseInt(a.@sorthelper,10), bS = parseInt(b.@sorthelper,10);
return (aE > bE) ? 1 : (aE < bE) ? -1 : (aS > bS ? 1 : (aS < bS ? -1 : 0));
})
.forEach(function(a) servicesXML.appendChild(a));
return gYaSearchService.getDOMDocContent2("services/mybar/uservices.xsl", servicesXML, {});
},
getUserServicesXULForMFDUser: function(aBoxname) {
let servicesXML = this.getServicesLocalizedXML();
if (!servicesXML)
return null;
delete servicesXML.service.url;
delete servicesXML.service.counterurl;
let mfdUserData = gYaSearchService.yaMFD.getDataForUser(aBoxname);
if (mfdUserData) {
let mailURL = "http://mail.yandex.ru/for/" + mfdUserData.list.@domain;
let mailService = servicesXML.service.(@name = "pdd")[0];
if (mailService) {
mailService.@v = mfdUserData.counter;
mailService.@error = 0;
mailService.appendChild(<url action="1005">{mailURL}</url>);
mailService.appendChild(<counterurl action="1005">{mailURL}/messages</counterurl>);
}
}
return gYaSearchService.getDOMDocContent2("services/mybar/uservices.xsl", servicesXML, {});
},
getYaruUserData: function(aLogin) {
let login = arguments.length == 1 ? aLogin : this.login;
let userData = this._getUserData(login);
if (!userData)
return null;
let yaruData = userData.yaru[0];
if (!yaruData) {
yaruData = <yaru/>;
userData.appendChild(yaruData);
}
return yaruData;
},
setYaruUserData: function(aXMLData, aLogin) {
let userData = this._getUserData(aLogin);
if (userData)
userData.yaru = aXMLData;
},
refreshYaRuUserData: function() {
gYaSearchService.xmlHttpRequest("http://export.yandex.ru/yaru-info.xml?" + getNCRndStr(),
{ callbackFunc: this.refreshYaRuUserDataCallback.bind(this) });
},
refreshYaRuUserDataCallback: function(aReq) {
let error = null;
if (gYaSearchService.isReqError(aReq)) {
error = "lost_connection";
} else if (!this.login) {
error = "auth_required";
}
if (!error) {
let responseText = aReq.target.responseText;
if (responseText)
this.setYaruUserData(gYaSearchService.safeE4Xml(responseText.replace(/[\r\n]/g, ""), null, "yaru"), this.login);
}
OBSERVER_SERVICE.notifyObservers(null, "Ya-Refresh-Data", "yaru-user-data");
}
}
gYaUServices._init();