home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / mail.xpi / bin / chrome / messenger.jar / content / messenger / addressbook / ABSynch.js < prev    next >
Text File  |  2001-04-28  |  5KB  |  208 lines

  1. var prefs = Components.classes["@mozilla.org/preferences;1"].getService();
  2. prefs = prefs.QueryInterface(Components.interfaces.nsIPref);
  3.  
  4. okCallback = null;
  5.  
  6. //Progress and Status variables
  7. var gSyncButton;
  8. var gStatusText;
  9. var statusFeedback;
  10. var gProgressWindow = null;
  11.  
  12. addEventListener("load",ABSynchDisable,false);
  13.  
  14. function ABSynchDisable()
  15. {
  16.     var IsFranklinEnabled;
  17.     try {
  18.             IsFranklinEnabled = prefs.GetBoolPref("mail.is_a_franklin_user");
  19.             return;
  20.     }
  21.     catch(e){
  22.             try {
  23.                     document.getElementById("ABSynch").setAttribute("disabled","true");
  24.                     document.getElementById("button-absynch").setAttribute("disabled","true");
  25.             }
  26.             catch(ex){}
  27.     }
  28. }
  29. function ABSynchOKCallback()
  30. {
  31.     prefs.SetBoolPref("mail.absync.firsttime",false);
  32. }
  33.  
  34. function ABSynchStart()
  35. {
  36.     dump("ABSynchStart()\n");
  37.  
  38.     var IsFranklinEnabled;
  39.     
  40.     try {
  41.             IsFranklinEnabled = prefs.GetBoolPref("mail.is_a_franklin_user");
  42.     }
  43.     catch(e){
  44.                 return;
  45.     }
  46.  
  47.  
  48.     if (prefs.GetBoolPref("mail.absync.firsttime")) {
  49.         var dialog = window.openDialog("chrome://messenger/content/addressbook/ABSynch.xul","","chrome,modal,titlebar,dialog",{okCallback:ABSynchOKCallback});
  50.     }
  51.     
  52.     // if this is false, this is not their first time, or it was
  53.     // and they hit ok
  54.     if (!prefs.GetBoolPref("mail.absync.firsttime")) {
  55.         AbSync();
  56.     }
  57. }
  58.  
  59. function ABSynchCancel()
  60. {
  61.     dump("ABSynchCancel()\n");
  62.     return true;
  63. }
  64.  
  65. function ABSynchOK()
  66. {
  67.     dump("ABSynchOK()\n");
  68.     if (top.okCallback) {
  69.         top.okCallback();
  70.     }
  71.     return true;
  72. }
  73.  
  74. function ABSynchOnLoad()
  75. {
  76.     dump("ABSynchOnLoad()\n");
  77.  
  78.     doSetOKCancel(ABSynchOK, ABSynchCancel);
  79.  
  80.     // look in arguments[0] for parameters
  81.     if (window.arguments && window.arguments[0]) {
  82.         if (window.arguments[0].okCallback) {
  83.             top.okCallback = window.arguments[0].okCallback;
  84.         }
  85.     }    
  86. }
  87.  
  88. //
  89. // Do the sync operation
  90. //
  91. function AbSync()
  92. {
  93.   dump("AbSync()\n");
  94.   var syncDriverContractID = "@mozilla.org/addressbook/services/syncdriver;1";
  95.  
  96.     // Create windows status feedback
  97.   // set the JS implementation of status feedback before creating the c++ one..
  98.   window.statusFeedback = new nsMsgStatusFeedback();
  99.  
  100.   // Kill the sync button!
  101.   window.statusFeedback.startMeteors();
  102.  
  103.      /* get the sync driver instance */
  104.     var    syncDriver = Components.classes[syncDriverContractID].getService();
  105.   if (syncDriver)
  106.   {
  107.     syncDriver = syncDriver.QueryInterface(Components.interfaces.nsIAbSyncDriver);    
  108.   }
  109.   
  110.   syncDriver.KickIt(window.statusFeedback, window);  
  111. }
  112.  
  113. function nsMsgStatusFeedback()
  114. {
  115. }
  116.  
  117. function getStringBundle(aURL) 
  118. {
  119.   var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"].getService();
  120.   stringBundleService = stringBundleService.QueryInterface(Components.interfaces.nsIStringBundleService);
  121.   var stringBundle = stringBundleService.createBundle(aURL);
  122.   if (stringBundle)
  123.     return stringBundle.QueryInterface(Components.interfaces.nsIStringBundle);
  124. }
  125.  
  126. var selectionArray;
  127.  
  128. nsMsgStatusFeedback.prototype = 
  129. {
  130.     QueryInterface : function(iid)
  131.         {
  132.         if(iid.equals(Components.interfaces.nsIMsgStatusFeedback))
  133.             return this;
  134.         throw Components.results.NS_NOINTERFACE;
  135.         },
  136.     showStatusString : function(statusText)
  137.         {
  138.        if (!gStatusText) 
  139.           gStatusText = document.getElementById('statusText');
  140.        
  141.        gStatusText.setAttribute('label', statusText);
  142.         },
  143.     startMeteors : function()
  144.         {
  145.           // Disable Sync button...
  146.           if (!gSyncButton)
  147.             gSyncButton = document.getElementById('button-absynch');
  148.  
  149.       if (gSyncButton)
  150.         gSyncButton.setAttribute('disabled', 'true');
  151.         
  152.         selectionArray = RememberResultsTreeSelection();
  153.         ClearResultsTreeSelection()    ;        
  154.         },
  155.     stopMeteors : function()
  156.         {
  157.           // Enable Sync button...
  158.           if (!gSyncButton)
  159.             gSyncButton = document.getElementById('button-absynch');
  160.  
  161.       if (gSyncButton)
  162.         gSyncButton.setAttribute('disabled', 'false');
  163.  
  164.       // Make sure we redraw the results window...
  165.         RedrawResultsTree();
  166.         
  167.         WaitUntilDocumentIsLoaded();
  168.         SortToPreviousSettings();
  169.         RestoreResultsTreeSelection(selectionArray);
  170.         },
  171.     showProgress : function(percent)
  172.         {
  173.           if (!gProgressWindow)
  174.             gProgressWindow = window.open(
  175.                                               "chrome://messenger/content/addressbook/ABSyncProgress.xul",
  176.                                               "",
  177.                                               "chrome,centerscreen,titlebar,dialog");
  178.       if (percent==50)
  179.       {
  180.         var stringBundle = getStringBundle("chrome://messenger/locale/addressbook/absync.properties");
  181.         if (stringBundle) 
  182.         {
  183.           var tMsgObj = gProgressWindow.document.getElementById('progressStatusMsg');
  184.           if (tMsgObj)
  185.           {
  186.               var tMsg = stringBundle.GetStringFromName("syncInProgress");          
  187.               tMsgObj.setAttribute('label', tMsg);
  188.           }
  189.         }
  190.       }              
  191.         },
  192.     closeWindow : function()
  193.         {
  194.         if (gProgressWindow)
  195.         {
  196.           try {
  197.                 gProgressWindow.close();
  198.           }
  199.           catch (ex) 
  200.           {
  201.                 dump("failed to find window: ex="+ ex + "\n");
  202.             }
  203.  
  204.               gProgressWindow = null;
  205.         }
  206.         }
  207. }
  208.