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 / incomingFile.js < prev    next >
Text File  |  2006-01-06  |  5KB  |  138 lines

  1. // globals
  2. // window arguments defined here, but may not be used.
  3. // mainly to test & explain valid arguments.
  4.  
  5. inviteArgsObj = window.arguments[0];
  6.  
  7. var inviteMode                = inviteArgsObj.inviteMode;
  8. var inviteProposalObj         = inviteArgsObj.inviteProposalObj;
  9. var inviteMsg                 = inviteProposalObj.GetInvitation();
  10. var fileProposalScreenName    = inviteArgsObj.inviteProposalScreenName;
  11.  
  12. var nsIFilePicker = Components.interfaces.nsIFilePicker;
  13. var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
  14. var fileXferSession;
  15. var fileName;
  16. var fileXferSessionCallback = new Object();
  17. var remoteError = false;
  18.  
  19. fileXferSessionCallback.OnStateChange = function (state, msg)
  20. {
  21.   var stateEnum = Components.interfaces.nsAimFileXferStates;
  22.   if (stateEnum.Complete == state)
  23.   {
  24.       window.close();
  25.   }
  26.   if (stateEnum.Progress == state)
  27.   {
  28.       if (document.getElementById("imfileprogress").getAttribute("mode") !="determined"){
  29.         document.getElementById("imfileprogress").setAttribute("mode", "determined");
  30.       }
  31.       document.getElementById("filestate").setAttribute("value", fileXferSession.GetTotalBytes() + " / " + fileXferSession.GetTotalSize() * 100);
  32.     document.getElementById("imfileprogress").setAttribute("value", fileXferSession.GetTotalBytes() / fileXferSession.GetTotalSize() * 100);
  33.   }
  34.         if (stateEnum.Error == state)
  35.         {
  36.                 aimErrorBox(msg);
  37.                 remoteError = true;
  38.                 window.close();
  39.         }
  40. }
  41.  
  42. function incomingFileOnWinLoad(){
  43.    dump("incomingFileOnWinLoad\n");
  44.  
  45.    if(inviteMode && inviteMode=="incomingfile"){
  46.      //setButtons(aimString('chat.YesButton'), aimString('chat.NoButton'), aimString('accept.tooltip'), aimString('decline.tooltip'));
  47.     
  48.       dump("incoming file\n");
  49.  
  50.       doSetOKCancel(incomingFileCmdAcceptRendezvous, incomingfileCmdDeclineRendezvous);
  51.  
  52.       if(inviteProposalObj)
  53.       {
  54.          incomingChatRoomInviteMsg = inviteProposalObj.GetInvitation();
  55.  
  56.          document.getElementById("IncomingFile").setAttribute("title", aimString('file.receive').replace(/%ScreenName%/, fileProposalScreenName));
  57.  
  58.          var descriptionNode = top.document.getElementById("description").contentWindow;
  59.          
  60.          var myRange = descriptionNode.document.createRange();
  61.          var descriptionBody = descriptionNode.document.body;
  62.          myRange.setStartAfter(descriptionBody);
  63.  
  64.          var docFrag = myRange.createContextualFragment(inviteMsg);
  65.          descriptionBody.appendChild(docFrag)
  66.  
  67.          inviteProposalObj.Accept();
  68.          fileXferSession = fileXfer().Receive(inviteProposalObj);
  69.          inviteArgsObj.fileXferSession = fileXferSession;
  70.          document.getElementById("size").setAttribute("label", aimString('file.buddy') + "    (" + aimString('file.size') + " " + fileXferSession.GetTotalSize() + " " + aimString('file.bytes') + ")");
  71.          fileName = fileXferSession.GetFileName();
  72.          var fileDirectory = aimPrefsManager().GetCharPref( "aim.filexfer.location", null, false );
  73.          if (fileDirectory && fileDirectory != "")
  74.            document.getElementById("filelocation").setAttribute("value", fileDirectory + fileName);
  75.          document.getElementById("filename").setAttribute("value",fileName);
  76.          fileXferSession.SetScreenName(fileProposalScreenName);
  77.          fileXferSession.SetInviteMode(0);
  78.        } 
  79.       fileXferSession.SetFileXferSessionCallback(fileXferSessionCallback);
  80.    }
  81. }
  82.  
  83. function incomingFileOnWinUnLoad(){
  84.    //window.close();
  85. }
  86.  
  87. function cmdIncomingFileWarn()
  88. {
  89. }
  90.  
  91. function incomingfileCmdDeclineRendezvous()
  92. {
  93.    inviteProposalObj.Reject();
  94.    window.close();
  95. }
  96.  
  97. function incomingFileCmdAcceptRendezvous(){
  98.    var fileLocation = document.getElementById("filelocation").value;
  99.    if (fileLocation && fileLocation.length > 0)
  100.        inviteArgsObj.filepath = document.getElementById("filelocation").value;
  101.    else
  102.    {
  103.        alert(aimString('file.pickdirectory'));
  104.        return;
  105.    }
  106.  
  107.    window.openDialog('chrome://aim/content/transfer.xul','_blank','chrome,all,dialog=no',inviteArgsObj); 
  108.    window.close();
  109. }
  110.  
  111. function openfilepicker()
  112. {
  113.       fp.init(window, aimString('file.choose'), nsIFilePicker.modeSave);
  114.       if (fileName && fileName != "")
  115.       {
  116.         dump ("fileName is : " + fileName + " \n");
  117.         fp.defaultString = fileName;
  118.       }
  119.       else
  120.       {
  121.         fp.defaultString = aimPrefsManager().GetCharPref( "aim.filexfer.location", null, false );
  122.         dump ("fileName is : " + aimPrefsManager().GetCharPref( "aim.filexfer.location", null, false ) + " \n");
  123.       }
  124.  
  125.       fp.appendFilters(nsIFilePicker.filterAll);
  126.  
  127.       try {
  128.          fp.show();
  129.       }
  130.       catch (ex) {
  131.          dump ("filePicker.chooseInputFile threw an exception\n");
  132.          return false;
  133.       }
  134.       if (fp.file && fp.file.path.length > 0)
  135.           document.getElementById("filelocation").setAttribute("value", fp.file.path);
  136. }
  137.  
  138.