home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 October / Gamestar_77_2005-10_dvd.iso / Programy / nsb-install-8-0.exe / chrome / messenger.jar / content / messenger / addressbook / replicationProgress.js < prev    next >
Text File  |  2005-07-29  |  5KB  |  147 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is mozilla.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Srilatha Moturi <srilatha@netscape.com>.
  18.  * Portions created by the Initial Developer are Copyright (C) 2002
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Rajiv Dayal <rdayal@netscape.com>
  23.  *   Seth Spitzer <sspitzer@netscape.com>
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the MPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the MPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. var gCurrentDirectoryPrefName;
  40. var gReplicationService = Components.classes["@mozilla.org/addressbook/ldap-replication-service;1"].getService(Components.interfaces.nsIAbLDAPReplicationService);
  41. var gProgressText;
  42. var gProgressMeter;
  43. var gReplicationBundle;
  44.  
  45. function onLoad() 
  46. {
  47.   var dirName;
  48.  
  49.   if (window.arguments[0]) {
  50.     dirName = window.arguments[0].dirName;
  51.     gCurrentDirectoryPrefName = window.arguments[0].prefName;
  52.   }
  53.  
  54.   gProgressText = document.getElementById("replication.status");
  55.   gProgressMeter = document.getElementById("replication.progress");
  56.   gReplicationBundle = document.getElementById("bundle_replication");
  57.  
  58.   window.title = gReplicationBundle.getFormattedString("replicatingTitle", [dirName])
  59.  
  60.   Replicate();
  61. }
  62.  
  63. function DoReplicationClose()
  64. {
  65.   // XXX todo, confirm the cancel
  66.   onCancelReplication(false);
  67.   return true;
  68. }
  69.  
  70. var progressListener = {
  71.   onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus)
  72.   {
  73.     if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_START) {
  74.       // start the spinning
  75.       gProgressMeter.setAttribute("mode","undetermined");
  76.       if (aStatus)
  77.         SetProgressText(gReplicationBundle.getString("replicationStarted"));
  78.       else
  79.         SetProgressText(gReplicationBundle.getString("changesStarted"));
  80.     }
  81.     
  82.     if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP) {
  83.       // stop the spinning
  84.       gProgressMeter.setAttribute("mode","normal");
  85.       gProgressMeter.setAttribute("value", "100");
  86.  
  87.       if (aStatus)
  88.         SetProgressText(gReplicationBundle.getString("replicationSucceeded"));
  89.       else
  90.         SetProgressText(gReplicationBundle.getString("replicationFailed"));
  91.       window.close();
  92.     }
  93.   },
  94.   onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress)
  95.   {
  96.     SetProgressText(gReplicationBundle.getFormattedString("currentCount", [aCurSelfProgress]));     
  97.   },
  98.   onLocationChange: function(aWebProgress, aRequest, aLocation)
  99.   {
  100.   },
  101.   onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage)
  102.   {
  103.   },
  104.   onSecurityChange: function(aWebProgress, aRequest, state)
  105.   {
  106.   },
  107.   QueryInterface : function(iid)
  108.   {
  109.     if (iid.equals(Components.interfaces.nsIWebProgressListener) || 
  110.         iid.equals(Components.interfaces.nsISupportsWeakReference) || 
  111.         iid.equals(Components.interfaces.nsISupports))
  112.       return this;
  113.     throw Components.results.NS_NOINTERFACE;
  114.   }
  115. };
  116.  
  117. function Replicate()
  118. {
  119.   try {
  120.     gReplicationService.startReplication(gCurrentDirectoryPrefName, progressListener);
  121.   }
  122.   catch (ex) {
  123.     // XXX todo
  124.     // are you offline?  If so, you need to go offline to use this
  125.     dump("replication failed.  ex=" + ex + "\n");
  126.   }
  127. }
  128.  
  129. function onCancelReplication(closeWindow)
  130. {
  131.   try {
  132.     gReplicationService.cancelReplication(gCurrentDirectoryPrefName);
  133.   }
  134.   catch (ex) {
  135.     // XXX todo
  136.     // perhaps replication hasn't started yet?  This can happen if you hit cancel after attempting to replication when offline 
  137.     dump("unexpected failure while cancelling.  ex=" + ex + "\n");
  138.     if (closeWindow)
  139.       window.close();
  140.   }
  141. }
  142.  
  143. function SetProgressText(textStr)
  144. {
  145.   gProgressText.value = textStr;
  146. }
  147.