home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2006 December
/
PCWorld_2006-12_cd.bin
/
komunikace
/
netscape
/
nsb-install-8-1-2.exe
/
chrome
/
aim.jar
/
content
/
aim
/
IMBuddyIconKnockKnock.js
< prev
next >
Wrap
Text File
|
2006-01-06
|
5KB
|
153 lines
//globals
var IMServiceClass = Components.classes['@netscape.com/aim/IMManager;1'];
var pIIMManager = IMServiceClass.getService(Components.interfaces.nsIIMManager);
var nimSession = pIIMManager.QueryInterface(Components.interfaces.nsIAimSession);
var nimIM = pIIMManager.QueryInterface(Components.interfaces.nsIAimIM);
var nimBuddy = pIIMManager.QueryInterface(Components.interfaces.nsIAimBuddy);
inviteArgsObj = window.arguments[0];
var buddyName = inviteArgsObj.inviteProposalScreenName;
//this is used to check how we call the onunload handler. Either by butten clicks or by close.
var buttonClose = 0;
function fillImageFunction()
{
var biimage = document.getElementById("bIcon");
var sn = document.getElementById("ScreenName");
var desc2 = document.getElementById("desc2");
var pDir = nimSession.profileDir;
var pictureDir = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
pictureDir.initWithPath(pDir.path);
pictureDir.append("picture");
if (pictureDir.exists()) {
pictureDir.append("temp"+buddyName+".gif");
if (pictureDir.exists()) {
var fileHandler = GetFileHandler();
var tfileurl = fileHandler.getURLSpecFromFile(pictureDir);
//this is just to avoid from loading from the cache.
var currentTime = new Date().getTime();
biimage.setAttribute("src", tfileurl+"?foobar="+currentTime);
var desc = aimString("bi.kktext").replace(/%ScreenName%/, buddyName);
var textNode = document.createTextNode(desc);
sn.appendChild(textNode);
var desc2Value = aimString("bi.kktext2");
var textNode1 = document.createTextNode(desc2Value);
desc2.appendChild(textNode1);
}
}
document.getElementById("acceptButton").focus();
}
function buddyIconKKOnUnload()
{
// if this unload is called coz of the button close, just return.
if (buttonClose)
return;
//if the user clicks the x on right top, => reject BI. This is how AIM works.
cmdBIIncomingReject();
}
function cmdBIIncomingAccept()
{
buttonClose = 1;
var pDir = nimSession.profileDir;
var picturedir = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
picturedir.initWithPath(pDir.path);
picturedir.append("picture");
var temppicturefile = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
temppicturefile.initWithPath(pDir.path);
temppicturefile.append("picture");
var pictureDir = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
pictureDir.initWithPath(pDir.path);
pictureDir.append("picture");
if (pictureDir.exists()) {
pictureDir.append(buddyName+".gif");
if (pictureDir.exists()) {
//delete any existing <SN>.gif file from the dir.
pictureDir.remove(false);
}
if(picturedir.exists()) {
//these tests shd ideally pass all the time.
var newname = buddyName+".gif";
temppicturefile.append("temp"+buddyName+".gif");
if (temppicturefile.exists()) {
//copy the tempSN.gif to SN.gif and remove tempSN.gif
temppicturefile.copyTo(picturedir, newname);
temppicturefile.remove(false);
//IM window update
picturedir.append(newname);
var fileHandler = GetFileHandler();
picturedir = fileHandler.getURLSpecFromFile(picturedir);
var currentTime = new Date().getTime();
var pIAimIM = aimIM();
if(pIAimIM) {
var pWindow = pIAimIM.GetExistingIM(buddyName);
if(pWindow) {
var doc = pWindow.document;
var imageElement = doc.getElementById("BuddyIcon");
if (imageElement) {
imageElement.setAttribute("src", picturedir+"?foobar="+currentTime);
}
}
}
}
}
}
nimIM.SetHasBIBuddyIconFlag(buddyName, true);
var nimBuddy = aimBuddyManager();
nimBuddy.SetHasBuddyIconFlag(buddyName, true);
window.close();
}
function cmdBIIncomingReject()
{
buttonClose = 1;
var rdf = aimRDF();
var rejres = rdf.GetResource("http://home.netscape.com/NC-rdf#Reject");
var trueliteral = rdf.GetLiteral("true");
nimIM.SetBuddyIconFlag(buddyName, rejres, trueliteral);
nimBuddy.SetBuddyIconRejectFlag(buddyName, true);
window.close();
}
function cmdBIIncomingWarn()
{
buttonClose = 1;
var warnUserArgs = new Object();
warnUserArgs.screenName = buddyName;
//two modal dialogs are bad in mozilla (until the control completes here, another modal dialog will not pop up).
window.close();
window.openDialog("chrome://aim/content/WarnUser.xul","_blank", "chrome,dialog=no",warnUserArgs);
}
function GetFileHandler()
{
var IOService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
return IOService.getProtocolHandler("file")
.QueryInterface(Components.interfaces.nsIFileProtocolHandler);
}
function stopShowingKK()
{
if (document.getElementById("dontdisplay").checked)
aimPrefsManager().SetBoolPref("aim.buddyicon.showknockknock", false, null, false);
else
aimPrefsManager().SetBoolPref("aim.buddyicon.showknockknock", true, null, false);
}