<?xml version="1.0"?>
<!--
 * ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public
 * License Version 1.1 (the "MPL"); you may not use this file
 * except in compliance with the MPL. You may obtain a copy of
 * the MPL at http://www.mozilla.org/MPL/
 *
 * Software distributed under the MPL is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the MPL for the specific language governing
 * rights and limitations under the MPL.
 *
 * The Original Code is Enigmail.
 *
 * The Initial Developer of the Original Code is Patrick Brunschwig.
 * Portions created by Patrick Brunschwig <patrick@enigmail.net> are
 * Copyright (C) 2004 Patrick Brunschwig. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 * ***** END LICENSE BLOCK ***** *
-->


<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://enigmail/skin/enigmail.css" type="text/css"?>

<!DOCTYPE window [
<!ENTITY % brandDTD SYSTEM "chrome://global/locale/brand.dtd" >
%brandDTD;
<!ENTITY % enigMailDTD SYSTEM "chrome://enigmail/locale/enigmail.dtd" >
%enigMailDTD;
]>

<dialog id="enigmailEditKeyTrustDlg"
        title="&enigmail.keyTrust.title;"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        onload="onLoad();"
        ondialogaccept="return onAccept();"
        >


  <script type="application/x-javascript">
  <![CDATA[

    Components.utils.import("resource://enigmail/enigmailCommon.jsm");
    Components.utils.import("resource://enigmail/keyManagement.jsm");
    const Ec = EnigmailCommon;

    function onLoad() {
      // set current key trust if only one key is changed
      var enigmailSvc = Ec.getService(window);
      if (!enigmailSvc)
        return;

      var errorMsgObj = new Object();
      var exitCodeObj = new Object();
      try {
        window.arguments[1].refresh = false;
        var currTrust = -1;
        var lastTrust = -1;
        var sigListStr = enigmailSvc.getKeySig("0x"+window.arguments[0].keyId.join(" 0x"), exitCodeObj, errorMsgObj);
        if (exitCodeObj.value == 0) {
          var sigList = sigListStr.split(/[\n\r]+/);
          for (var i=0; i < sigList.length; i++) {
            var aLine=sigList[i].split(/:/);
            if (aLine[0] == "pub") {
              currTrust=(("-nmfuq").indexOf(aLine[8]) % 5)+1;
              if (lastTrust==-1) lastTrust=currTrust;
              if (currTrust != lastTrust) {
                currTrust = -1;
                break;
              }
            }
          }
          if (currTrust > 0) {
            var t=document.getElementById("trustLevel"+currTrust.toString());
            document.getElementById("trustLevelGroup").selectedItem=t;
          }
        }
      } catch (ex) {}

      var keyIdList = document.getElementById("keyIdList");
      for (i=0; i<window.arguments[0].userId.length; i++) {
        var keyId = window.arguments[0].userId[i]+" - 0x"+ window.arguments[0].keyId[i].substr(-8,8);
        keyIdList.appendItem(keyId);
      }
    }

    function processNextKey(index) {
      Ec.DEBUG_LOG("enigmailEditKeyTrust: processNextKey("+index+")\n");

      var t=document.getElementById("trustLevelGroup");
      EnigmailKeyMgmt.setKeyTrust(window,
        window.arguments[0].keyId[index],
        Number(t.selectedItem.value),
        function(exitCode, errorMsg) {
          if (exitCode != 0) {
            Ec.alert(window, Ec.getString("setKeyTrustFailed")+"\n\n"+errorMsg);
            window.close();
            return;
          }
          else {
            window.arguments[1].refresh = true;
          }

          ++index;
          if (index == window.arguments[0].keyId.length)
            window.close();
          else {
            processNextKey(index);
          }
        });
    }

    function onAccept() {
      processNextKey(0);

      return false;
    }
  ]]>
  </script>

  <vbox orient="vertical">
    <hbox>
      <label value="&enigmail.keyTrust.trustKey.label;" control="keyIdList"/>
      <listbox flex="1" id="keyIdList" style="height:60px"/>
    </hbox>
    <separator/>
    <vbox>
      <groupbox>
        <caption label="&enigmail.keyTrust.trustLevel.label;"/>
          <radiogroup id="trustLevelGroup">
            <radio value="1" id="trustLevel1"
                   label="&enigmail.keyTrust.dontKnow.label;"/>
            <radio value="2" id="trustLevel2"
                   label="&enigmail.keyTrust.noTrust.label;"/>
            <radio value="3" id="trustLevel3"
                   label="&enigmail.keyTrust.marginalTrust.label;"/>
            <radio value="4" id="trustLevel4"
                   label="&enigmail.keyTrust.fullTrust.label;"/>
            <radio value="5" id="trustLevel5"
                   label="&enigmail.keyTrust.ultimateTrust.label;"/>
          </radiogroup>
       </groupbox>
    </vbox>
  </vbox>
</dialog>

