home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / chrome / messenger.jar / content / messenger / importDialog.js < prev    next >
Text File  |  2001-02-14  |  23KB  |  796 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * The contents of this file are subject to the Mozilla Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/MPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is mozilla.org code.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation.  Portions created by Netscape are
  17.  * Copyright (C) 1999 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  */
  22.  
  23. var importType = null;
  24. var bundle = 0;
  25. var importService = 0;
  26. var successStr = null;
  27. var errorStr = null;
  28. var progressInfo = null;
  29. var selectedModuleName = null;
  30.  
  31.  
  32.  
  33. function GetBundleString( strId)
  34. {
  35.     try {
  36.         return( top.bundle.GetStringFromName( strId));
  37.     } catch( ex) {
  38.     }
  39.     
  40.     return( "String Bundle Bad");
  41. }
  42.  
  43. function GetFormattedBundleString( strId, formatStr)
  44. {
  45.     try {
  46.         return( top.bundle.formatStringFromName( strId, [ formatStr ], 1));
  47.     } catch( ex) {
  48.     }
  49.     return( "String Bundle Bad");
  50. }
  51.  
  52. function OnLoadImportDialog()
  53. {
  54.     bundle = srGetStrBundle("chrome://messenger/locale/importMsgs.properties");
  55.     importService = Components.classes["@mozilla.org/import/import-service;1"].getService();
  56.     importService = top.importService.QueryInterface(Components.interfaces.nsIImportService);
  57.     
  58.     progressInfo = { };
  59.     progressInfo.progressWindow = null;
  60.     progressInfo.importInterface = null;
  61.     progressInfo.mainWindow = window;
  62.     progressInfo.intervalState = 0;
  63.     progressInfo.importSuccess = false;
  64.     progressInfo.importType = null;
  65.  
  66.     // look in arguments[0] for parameters
  67.     if (window.arguments && window.arguments[0] && window.arguments.importType)
  68.     {
  69.         // keep parameters in global for later
  70.         importType = window.arguments[0].importType;
  71.         progressInfo.importType = top.importType;
  72.     }
  73.     else
  74.     {
  75.         importType = "addressbook";
  76.         progressInfo.importType = "addressbook";
  77.     }
  78.     
  79.     SetUpImportType();    
  80. }
  81.  
  82.  
  83. function SetUpImportType()
  84. {
  85.     // set dialog title
  86.   var typeRadioGroup = document.getElementById("importFields");
  87.   switch (importType)
  88.     {
  89.  
  90.         case "mail":
  91.       typeRadioGroup.selectedItem = document.getElementById("mailRadio");
  92.             break;
  93.         case "addressbook":
  94.       typeRadioGroup.selectedItem = document.getElementById("addressbookRadio");
  95.             break;
  96.         case "settings":
  97.       typeRadioGroup.selectedItem = document.getElementById("settingsRadio");
  98.             break;
  99.     }
  100.     
  101.     ListModules();
  102. }
  103.  
  104.  
  105. function SetDivText(id, text)
  106. {
  107.     var div = document.getElementById(id);
  108.         
  109.     if (div) {
  110.         if (!div.childNodes.length) {            
  111.             var textNode = document.createTextNode(text);
  112.             div.appendChild(textNode);                               
  113.         }
  114.         else if ( div.childNodes.length == 1 ) {            
  115.             div.childNodes[0].nodeValue = text;
  116.         }
  117.     }
  118. }
  119.  
  120.  
  121. function ImportDialogOKButton()
  122. {
  123.     var tree = document.getElementById('moduleList');
  124.   var deck = document.getElementById("stateDeck");
  125.   var header = document.getElementById("header");
  126.   var progressMeterEl = document.getElementById("progressMeter");
  127.   var progressStatusEl = document.getElementById("progressStatus");
  128.   var progressTitleEl = document.getElementById("progressTitle");
  129.  
  130.   // better not mess around with navigation at this point
  131.   var nextButton = document.getElementById("forward");
  132.   nextButton.setAttribute("disabled", "true");
  133.   var backButton = document.getElementById("back");
  134.   backButton.setAttribute("disabled", "true");
  135.   
  136.     if ( tree && tree.selectedItems && (tree.selectedItems.length == 1) )
  137.     {
  138.     var importTypeRadioGroup = document.getElementById("importFields");
  139.     importType = importTypeRadioGroup.selectedItem.getAttribute("data");
  140.         var index = tree.selectedItems[0].getAttribute('list-index');
  141.         var module = importService.GetModule(importType, index);
  142.         var name = importService.GetModuleName(importType, index);
  143.         selectedModuleName = name;
  144.         if (module) 
  145.         {
  146.             switch(importType)
  147.             {
  148.                 case "mail":
  149.                     top.successStr = Components.classes["@mozilla.org/supports-wstring;1"].createInstance();
  150.                     if (top.successStr) {
  151.                         top.successStr = top.successStr.QueryInterface( Components.interfaces.nsISupportsWString);
  152.                     }
  153.                     top.errorStr = Components.classes["@mozilla.org/supports-wstring;1"].createInstance();
  154.                     if (top.errorStr)
  155.                         top.errorStr = top.errorStr.QueryInterface( Components.interfaces.nsISupportsWString);
  156.                     
  157.                     if (ImportMail( module, top.successStr, top.errorStr) == true) 
  158.                     {
  159.                         // We think it was a success, either, we need to 
  160.                         // wait for the import to finish
  161.                         // or we are done!
  162.                         if (top.progressInfo.importInterface == null) {
  163.                             ShowImportResults(true, 'Mail');
  164.                             return( true);
  165.                         }
  166.                         else {
  167.                             var meterText = GetFormattedBundleString('MailProgressMeterText', name);
  168.               header.setAttribute("description", meterText);
  169.               
  170.               progressStatusEl.setAttribute("value", "");
  171.               progressTitleEl.setAttribute("value", meterText);
  172.               
  173.               deck.setAttribute("index", "2");
  174.               progressInfo.progressWindow = top.window;
  175.               progressInfo.intervalState = setInterval("ContinueImportCallback()", 100);
  176.  
  177.                             return( true);
  178.                         }
  179.                     }
  180.                     else 
  181.                     {
  182.                         ShowImportResults(false, 'Mail');
  183.                         return( false);
  184.                     }
  185.                     break;
  186.                     
  187.                 case "addressbook":
  188.                     top.successStr = Components.classes["@mozilla.org/supports-wstring;1"].createInstance();
  189.                     if (top.successStr)
  190.                         top.successStr = top.successStr.QueryInterface( Components.interfaces.nsISupportsWString);
  191.                     top.errorStr = Components.classes["@mozilla.org/supports-wstring;1"].createInstance();
  192.                     if (top.errorStr)
  193.                         top.errorStr = top.errorStr.QueryInterface( Components.interfaces.nsISupportsWString);
  194.                     
  195.                     if (ImportAddress( module, top.successStr, top.errorStr) == true) {
  196.                         // We think it was a success, either, we need to 
  197.                         // wait for the import to finish
  198.                         // or we are done!
  199.                         if (top.progressInfo.importInterface == null) {
  200.                             ShowImportResults(true, 'Address');
  201.                             return( true);
  202.                         }
  203.                         else {
  204.                             var meterText = GetFormattedBundleString('MailProgressMeterText', name);
  205.               header.setAttribute("description", meterText);
  206.               
  207.               progressStatusEl.setAttribute("value", "");
  208.               progressTitleEl.setAttribute("value", meterText);
  209.               
  210.               deck.setAttribute("index", "2");
  211.               progressInfo.progressWindow = top.window;
  212.               progressInfo.intervalState = setInterval("ContinueImportCallback()", 100);
  213.             
  214.                             return( true);
  215.                         }
  216.                     }
  217.                     else 
  218.                     {
  219.                         ShowImportResults(false, 'Address');
  220.                         return( false);
  221.                     }
  222.                     break;
  223.  
  224.                 case "settings":
  225.                     var error = new Object();
  226.                     error.value = null;
  227.                     var newAccount = new Object();
  228.                     if (!ImportSettings( module, newAccount, error)) 
  229.                     {
  230.                         if (error.value)
  231.               ShowImportResultsRaw(GetBundleString( 'ImportSettingsFailed'), null);
  232.                         // the user canceled the operation, shoud we dismiss
  233.                         // this dialog or not?
  234.                         return false;
  235.                     }
  236.                     else
  237.             ShowImportResultsRaw(GetFormattedBundleString( 'ImportSettingsSuccess', name), null);
  238.                     break;
  239.             }
  240.         }
  241.     }
  242.     
  243.     return true;
  244. }
  245.  
  246. function SetStatusText( val)
  247. {
  248.   var progressStatus = document.getElementById("progressStatus");
  249.     progressStatus.setAttribute( "value", val);
  250. }
  251.  
  252. function SetProgress( val)
  253. {
  254.   var progressMeter = document.getElementById("progressMeter");
  255.     progressMeter.setAttribute( "value", val);
  256. }
  257.  
  258. function ContinueImportCallback()
  259. {
  260.     progressInfo.mainWindow.ContinueImport( top.progressInfo);
  261. }
  262.  
  263. function ImportSelectionChanged()
  264. {
  265.     var tree = document.getElementById('moduleList');
  266.     if ( tree && tree.selectedItems && (tree.selectedItems.length == 1) )
  267.     {
  268.         var index = tree.selectedItems[0].getAttribute('list-index');
  269.         SetDivText('description', top.importService.GetModuleDescription(top.importType, index));
  270.     }
  271. }
  272.  
  273. function ListModules() {
  274.     if (top.importService == null)
  275.         return;
  276.     
  277.     var body = document.getElementById( "bucketBody");
  278.     var max = body.childNodes.length - 1;
  279.     while (max >= 0) {
  280.         body.removeChild( body.childNodes[max]);
  281.         max--;
  282.     }
  283.         
  284.     var count = top.importService.GetModuleCount( top.importType);    
  285.     for (var i = 0; i < count; i++) {
  286.         AddModuleToList( top.importService.GetModuleName( top.importType, i), i);
  287.     }
  288. }
  289.  
  290. function AddModuleToList(moduleName, index)
  291. {
  292.     var body = document.getElementById("bucketBody");
  293.     
  294.     var item = document.createElement('treeitem');
  295.     var row = document.createElement('treerow');
  296.     var cell = document.createElement('treecell');
  297.     cell.setAttribute('value', moduleName);
  298.     item.setAttribute('list-index', index);
  299.     
  300.     row.appendChild(cell);
  301.     item.appendChild(row);
  302.     body.appendChild(item);
  303. }
  304.  
  305.  
  306. function ContinueImport( info) {
  307.   var isMail = info.importType == 'mail' ? true : false;
  308.     var clear = true;
  309.  
  310.     if (info.importInterface) {
  311.         if (!info.importInterface.ContinueImport()) {
  312.             info.importSuccess = false;
  313.             clearInterval( info.intervalState);
  314.             if (info.progressWindow != null) {
  315.                 var deck = document.getElementById("stateDeck");
  316.         deck.setAttribute("index", "3");
  317.                 info.progressWindow = null;
  318.             }
  319.  
  320.       ShowImportResults(false, isMail ? 'Mail' : 'Address');
  321.         }
  322.         else if ((pcnt = info.importInterface.GetProgress()) < 100) {
  323.             clear = false;
  324.             if (info.progressWindow != null) {
  325.                 if (pcnt < 5)
  326.                     pcnt = 5;
  327.                 SetProgress( pcnt);
  328.                 if (isMail) {
  329.                     var mailName = info.importInterface.GetData( "currentMailbox");
  330.                     if (mailName) {
  331.                         mailName = mailName.QueryInterface( Components.interfaces.nsISupportsWString);
  332.                         if (mailName)
  333.                             SetStatusText( mailName.data);
  334.                     }
  335.                 }
  336.             }
  337.         }
  338.         else {
  339.       dump("*** WARNING! sometimes this shows results too early. \n");
  340.       dump("    something screwy here. this used to work fine.\n");
  341.             clearInterval( info.intervalState);
  342.             info.importSuccess = true;
  343.             if (info.progressWindow) {
  344.                 var deck = document.getElementById("stateDeck");
  345.         deck.setAttribute("index", "3");
  346.                 info.progressWindow = null;
  347.             }
  348.       
  349.       ShowImportResults(true, isMail ? 'Mail' : 'Address');
  350.         }
  351.     }
  352.     if (clear) {
  353.         info.intervalState = null;
  354.         info.importInterface = null;
  355.     }
  356. }
  357.  
  358. function ShowImportResults(good, module)
  359. {
  360.   var modSuccess = 'Import' + module + 'Success';
  361.   var modFailed = 'Import' + module + 'Failed';
  362.   var results, title;
  363.     if (good) {
  364.     title = GetFormattedBundleString(modSuccess, selectedModuleName ? selectedModuleName : '');
  365.     results = successStr.data;    
  366.     }
  367.     else if (errorStr.data) { 
  368.     title = GetFormattedBundleString(modFailed, selectedModuleName ? selectedModuleName : '');
  369.     results = errorStr.data;
  370.     }
  371.     
  372.     if (results && title) 
  373.     ShowImportResultsRaw(title, results)
  374. }
  375.  
  376. function ShowImportResultsRaw(title, results)
  377. {
  378.   SetDivText("status", title);
  379.   var header = document.getElementById("header");
  380.   header.setAttribute("description", title);
  381.   dump("*** results = " + results + "\n");
  382.   attachStrings("results", results);
  383.   var deck = document.getElementById("stateDeck");
  384.   deck.setAttribute("index", "3");
  385.   var nextButton = document.getElementById("forward");
  386.   nextButton.value = nextButton.getAttribute("finishedval");    
  387.   nextButton.removeAttribute("disabled");
  388.   var cancelButton = document.getElementById("cancel");
  389.   cancelButton.setAttribute("disabled", "true");
  390. }
  391.  
  392. function attachStrings(aNode, aString)
  393. {
  394.   var attachNode = document.getElementById(aNode);
  395.   if (!aString) {
  396.     attachNode.parentNode.setAttribute("hidden", "true");
  397.     return;
  398.   }
  399.   var strings = aString.split("\n");
  400.   for (var i = 0; i < strings.length; i++) {
  401.     if (strings[i]) {
  402.       var currNode = document.createTextNode(strings[i]);
  403.       attachNode.appendChild(currNode);
  404.       var br = document.createElementNS("http://www.w3.org/1999/xhtml", 'br');
  405.       attachNode.appendChild( br);
  406.     }
  407.   }
  408. }
  409.  
  410. function ShowAddressComplete( good)
  411. {
  412.     var str = null;
  413.     if (good == true) {
  414.         if ((top.selectedModuleName != null) && (top.selectedModuleName.length > 0))
  415.             str = GetFormattedBundleString( 'ImportAddressSuccess', top.selectedModuleName);
  416.         else
  417.             str = GetFormattedBundleString( 'ImportAddressSuccess', "");
  418.         str += "\n";
  419.         str += "\n" + top.successStr.data;
  420.     }
  421.     else {
  422.         if ((top.errorStr.data != null) && (top.errorStr.data.length > 0)) {
  423.             if ((top.selectedModuleName != null) && (top.selectedModuleName.length > 0))
  424.                 str = GetFormattedBundleString( 'ImportAddressFailed', top.selectedModuleName);
  425.             else
  426.                 str = GetFormattedBundleString( 'ImportAddressFailed', "");
  427.             str += "\n" + top.errorStr.data;
  428.         }
  429.     }
  430.     
  431.     if (str != null)
  432.         alert( str);
  433. }
  434.  
  435. function CreateNewFileSpecFromPath( inPath)
  436. {
  437.     var file = Components.classes["@mozilla.org/filespec;1"].createInstance();
  438.     if (file != null) {
  439.         file = file.QueryInterface( Components.interfaces.nsIFileSpec);
  440.         if (file != null) {
  441.             file.nativePath = inPath;
  442.         }
  443.     }
  444.  
  445.     return( file);
  446. }
  447.  
  448. /*
  449.     Import Settings from a specific module, returns false if it failed
  450.     and true if successful.  A "local mail" account is returned in newAccount.
  451.     This is only useful in upgrading - import the settings first, then
  452.     import mail into the account returned from ImportSettings, then
  453.     import address books.
  454.     An error string is returned as error.value
  455. */
  456. function ImportSettings( module, newAccount, error) {
  457.     var setIntf = module.GetImportInterface( "settings");
  458.     if (setIntf != null)
  459.         setIntf = setIntf.QueryInterface( Components.interfaces.nsIImportSettings);
  460.     if (setIntf == null) {
  461.         error.value = GetBundleString( 'ImportSettingsBadModule');
  462.         return( false);
  463.     }
  464.     
  465.     // determine if we can auto find the settings or if we need to ask the user
  466.     var location = new Object();
  467.     var description = new Object();
  468.     var result = setIntf.AutoLocate( description, location);
  469.     if (result == false) {
  470.         // In this case, we couldn't not find the settings
  471.         if (location.value != null) {
  472.             // Settings were not found, however, they are specified
  473.             // in a file, so ask the user for the settings file.
  474.             var filePicker = Components.classes["@mozilla.org/filepicker;1"].createInstance();
  475.             if (filePicker != null) {
  476.                 filePicker = filePicker.QueryInterface( Components.interfaces.nsIFilePicker);
  477.                 if (filePicker != null) {
  478.                     var file = null;
  479.                     try {
  480.                         filePicker.init( top.window, GetBundleString( 'ImportSelectSettings'), Components.interfaces.nsIFilePicker.modeOpen);
  481.                         filePicker.appendFilters( Components.interfaces.nsIFilePicker.filterAll);
  482.                         filePicker.show();
  483.                         if (filePicker.file && (filePicker.file.path.length > 0))
  484.                             file = CreateNewFileSpecFromPath( filePicker.file.path);
  485.                         else
  486.                             file = null;
  487.                     }
  488.                     catch(ex) {
  489.                         file = null;
  490.                         error.value = null;
  491.                         return( false);
  492.                     }                    
  493.                     if (file != null) {
  494.                         setIntf.SetLocation( file);
  495.                     } 
  496.                     else {
  497.                         error.value = null;
  498.                         return( false);
  499.                     }                    
  500.                 }
  501.                 else {
  502.                     error.value = GetBundleString( 'ImportSettingsNotFound');
  503.                     return( false);
  504.                 }
  505.             }
  506.             else {
  507.                 error.value = GetBundleString( 'ImportSettingsNotFound');
  508.                 return( false);
  509.             }
  510.         }
  511.         else {
  512.             error.value = GetBundleString( 'ImportSettingsNotFound');
  513.             return( false);
  514.         }
  515.     }
  516.  
  517.     // interesting, we need to return the account that new
  518.     // mail should be imported into?
  519.     // that's really only useful for "Upgrade"
  520.     var result = setIntf.Import( newAccount);
  521.     if (result == false) {
  522.         error.value = GetBundleString( 'ImportSettingsFailed');
  523.     }
  524.     return( result);
  525. }
  526.  
  527. function CreateNewFileSpec( inFile)
  528. {
  529.     var file = Components.classes["@mozilla.org/filespec;1"].createInstance();
  530.     if (file != null) {
  531.         file = file.QueryInterface( Components.interfaces.nsIFileSpec);
  532.         if (file != null) {
  533.             file.fromFileSpec( inFile);
  534.         }
  535.     }
  536.  
  537.     return( file);
  538. }
  539.  
  540. function ImportMail( module, success, error) {
  541.     if (top.progressInfo.importInterface || top.progressInfo.intervalState) {
  542.         error.data = GetBundleString( 'ImportAlreadyInProgress');
  543.         return( false);
  544.     }
  545.     
  546.     top.progressInfo.importSuccess = false;
  547.  
  548.     var mailInterface = module.GetImportInterface( "mail");
  549.     if (mailInterface != null)
  550.         mailInterface = mailInterface.QueryInterface( Components.interfaces.nsIImportGeneric);
  551.     if (mailInterface == null) {
  552.         error.data = GetBundleString( 'ImportMailBadModule');
  553.         return( false);
  554.     }
  555.     
  556.     var loc = mailInterface.GetData( "mailLocation");
  557.     
  558.     if (loc == null) {
  559.         // No location found, check to see if we can ask the user.
  560.         if (mailInterface.GetStatus( "canUserSetLocation") != 0) {
  561.             var filePicker = Components.classes["@mozilla.org/filepicker;1"].createInstance();
  562.             if (filePicker != null) {
  563.                 filePicker = filePicker.QueryInterface( Components.interfaces.nsIFilePicker);
  564.                 if (filePicker != null) {
  565.                     try {
  566.                         filePicker.init( top.window, GetBundleString( 'ImportSelectMailDir'), Components.interfaces.nsIFilePicker.modeGetFolder);
  567.                         filePicker.appendFilters( Components.interfaces.nsIFilePicker.filterAll);
  568.                         filePicker.show();
  569.                         if (filePicker.file && (filePicker.file.path.length > 0))
  570.                             mailInterface.SetData( "mailLocation", CreateNewFileSpecFromPath( filePicker.file.path));
  571.                         else
  572.                             return( false);
  573.                     } catch( ex) {
  574.                         // don't show an error when we return!
  575.                         return( false);
  576.                     }                    
  577.                 }
  578.                 else {
  579.                     error.data = GetBundleString( 'ImportMailNotFound');
  580.                     return( false);
  581.                 }
  582.             }
  583.             else {
  584.                 error.data = GetBundleString( 'ImportMailNotFound');
  585.                 return( false);
  586.             }
  587.         }
  588.         else {
  589.             error.data = GetBundleString( 'ImportMailNotFound');
  590.             return( false);
  591.         }
  592.     }
  593.  
  594.     if (mailInterface.WantsProgress()) {
  595.         if (mailInterface.BeginImport( success, error)) {
  596.             top.progressInfo.importInterface = mailInterface;
  597.             // top.intervalState = setInterval( "ContinueImport()", 100);
  598.             return true;
  599.         }
  600.         else
  601.             return false;
  602.     }
  603.     else
  604.     return mailInterface.BeginImport( success, error) ? true : false;
  605. }
  606.  
  607.  
  608. // The address import!  A little more complicated than the mail import
  609. // due to field maps...
  610. function ImportAddress( module, success, error) {
  611.     if (top.progressInfo.importInterface || top.progressInfo.intervalState) {
  612.         error.data = GetBundleString( 'ImportAlreadyInProgress');
  613.         return( false);
  614.     }
  615.  
  616.     top.progressInfo.importSuccess = false;
  617.  
  618.     var addInterface = module.GetImportInterface( "addressbook");
  619.     if (addInterface != null)
  620.         addInterface = addInterface.QueryInterface( Components.interfaces.nsIImportGeneric);
  621.     if (addInterface == null) {
  622.         error.data = GetBundleString( 'ImportAddressBadModule');
  623.         return( false);
  624.     }
  625.     
  626.     
  627.     var loc = addInterface.GetStatus( "autoFind");
  628.     if (loc == false) {
  629.         loc = addInterface.GetData( "addressLocation");
  630.         if (loc != null) {
  631.             loc = loc.QueryInterface( Components.interfaces.nsIFileSpec);
  632.             if (loc != null) {
  633.                 if (!loc.exists)
  634.                     loc = null;
  635.             }
  636.         }
  637.     }
  638.     
  639.     if (loc == null) {
  640.         // Couldn't find the address book, see if we can
  641.         // as the user for the location or not?
  642.         if (addInterface.GetStatus( "canUserSetLocation") == 0) {
  643.             // an autofind address book that could not be found!
  644.             error.data = GetBundleString( 'ImportAddressNotFound');
  645.             return( false);
  646.         }
  647.  
  648.         var filePicker = Components.classes["@mozilla.org/filepicker;1"].createInstance();
  649.         if (filePicker != null) {
  650.             filePicker = filePicker.QueryInterface( Components.interfaces.nsIFilePicker);
  651.             if (filePicker == null) {
  652.                 error.data = GetBundleString( 'ImportAddressNotFound');
  653.                 return( false);
  654.             }
  655.         }
  656.         else {
  657.             error.data = GetBundleString( 'ImportAddressNotFound');
  658.             return( false);
  659.         }
  660.  
  661.         // The address book location was not found.
  662.         // Determine if we need to ask for a directory
  663.         // or a single file.
  664.         var file = null;
  665.         if (addInterface.GetStatus( "supportsMultiple") != 0) {
  666.             // ask for dir
  667.             try {
  668.                 filePicker.init( top.window, GetBundleString( 'ImportSelectAddrDir'), Components.interfaces.nsIFilePicker.modeGetFolder);
  669.                 filePicker.appendFilters( Components.interfaces.nsIFilePicker.filterAll);
  670.                 filePicker.show();
  671.                 if (filePicker.file && (filePicker.file.path.length > 0))
  672.                     file = filePicker.file.path;
  673.                 else
  674.                     file = null;
  675.             } catch( ex) {
  676.                 file = null;
  677.             }
  678.         }
  679.         else {
  680.             // ask for file
  681.             try {
  682.                 filePicker.init( top.window, GetBundleString( 'ImportSelectAddrFile'), Components.interfaces.nsIFilePicker.modeOpen);
  683.                 filePicker.appendFilters( Components.interfaces.nsIFilePicker.filterAll);
  684.                 filePicker.show();
  685.                 if (filePicker.file && (filePicker.file.path.length > 0))
  686.                     file = filePicker.file.path;
  687.                 else
  688.                     file = null;
  689.             } catch( ex) {
  690.                 file = null;
  691.             }
  692.         }
  693.  
  694.         if (file == null) {
  695.             return( false);
  696.         }
  697.         
  698.         file = CreateNewFileSpecFromPath( file);
  699.  
  700.         addInterface.SetData( "addressLocation", file);
  701.     }
  702.     
  703.     var map = addInterface.GetData( "fieldMap");
  704.     if (map != null) {
  705.         map = map.QueryInterface( Components.interfaces.nsIImportFieldMap);
  706.         if (map != null) {
  707.             var result = new Object();
  708.             result.ok = false;
  709.             top.window.openDialog(
  710.                 "chrome://messenger/content/fieldMapImport.xul",
  711.                 "",
  712.                 "chrome,modal,titlebar",
  713.                 {fieldMap: map,
  714.                  addInterface: addInterface,
  715.                  result: result});
  716.         }
  717.         if (result.ok == false)
  718.             return( false);
  719.     }
  720.  
  721.     if (addInterface.WantsProgress()) {
  722.         if (addInterface.BeginImport( success, error)) {
  723.             top.progressInfo.importInterface = addInterface;
  724.             // top.intervalState = setInterval( "ContinueImport()", 100);
  725.             return( true);
  726.         }
  727.         else {
  728.             return( false);
  729.         }
  730.     }
  731.     else {
  732.         if (addInterface.BeginImport( success, error)) {
  733.             return( true);
  734.         }
  735.         else {
  736.             return( false);
  737.         }
  738.     }
  739. }
  740.  
  741. function SwitchType( newType)
  742. {
  743.     top.importType = newType;
  744.     top.progressInfo.importType = newType;
  745.     
  746.     SetUpImportType();    
  747.     
  748.     SetDivText('description', "");
  749. }
  750.  
  751.  
  752. function next()
  753. {
  754.   var deck = document.getElementById("stateDeck");
  755.   var index = deck.getAttribute("index");
  756.   switch (index) {
  757.   case "0":
  758.     var backButton = document.getElementById("back");
  759.     backButton.removeAttribute("disabled");
  760.     var radioGroup = document.getElementById("importFields");
  761.     SwitchType(radioGroup.data);
  762.     deck.setAttribute("index", "1");
  763.     enableAdvance();
  764.     break;
  765.   case "1":
  766.     ImportDialogOKButton();
  767.     break;
  768.   case "3":
  769.     close();
  770.     break;
  771.   }      
  772. }
  773.  
  774. function enableAdvance()
  775. {
  776.   var tree = document.getElementById("moduleList");
  777.   var nextButton = document.getElementById("forward");
  778.   if (tree.selectedItems.length)
  779.     nextButton.removeAttribute("disabled");
  780.   else
  781.     nextButton.setAttribute("disabled", "true");
  782. }
  783.  
  784. function back()
  785. {
  786.   var deck = document.getElementById("stateDeck");
  787.   if (deck.getAttribute("index") == "1") {
  788.     var backButton = document.getElementById("back");
  789.     backButton.setAttribute("disabled", "true");
  790.     var nextButton = document.getElementById("forward");
  791.     nextButton.value = nextButton.getAttribute("nextval");
  792.     nextButton.removeAttribute("disabled");
  793.     deck.setAttribute("index", "0");
  794.   }
  795. }
  796.