Add Rating to PEPIdentity.
authorDean
Fri, 14 Oct 2016 15:58:36 +0200
changeset 1362d29258bb3fb7
parent 1361 d1288e7d215a
child 1363 08ce4198bffd
Add Rating to PEPIdentity.
PEPIdentity.cs
UI/FormRegionPrivacyStatus.cs
     1.1 --- a/PEPIdentity.cs	Thu Oct 13 17:44:58 2016 +0200
     1.2 +++ b/PEPIdentity.cs	Fri Oct 14 15:58:36 2016 +0200
     1.3 @@ -24,6 +24,7 @@
     1.4          private bool?             _IsForceUnencrypted;
     1.5          private bool              _IsSmartAddressEnabled;
     1.6          private List<PEPIdentity> _Members;
     1.7 +        private pEpRating         _Rating;
     1.8  
     1.9          private pEpIdentity internalIdentity;
    1.10  
    1.11 @@ -42,6 +43,7 @@
    1.12              this._IsForceUnencrypted = null;
    1.13              this._IsSmartAddressEnabled = true;
    1.14              this._Members = new List<PEPIdentity>();
    1.15 +            this._Rating = pEpRating.pEpRatingUndefined;
    1.16          }
    1.17  
    1.18          /// <summary>
    1.19 @@ -55,6 +57,7 @@
    1.20              this._IsForceUnencrypted = null;
    1.21              this._IsSmartAddressEnabled = true;
    1.22              this._Members = new List<PEPIdentity>();
    1.23 +            this._Rating = pEpRating.pEpRatingUndefined;
    1.24          }
    1.25  
    1.26          /// <summary>
    1.27 @@ -67,6 +70,7 @@
    1.28              this._IsForceUnencrypted = null;
    1.29              this._IsSmartAddressEnabled = true;
    1.30              this._Members = new List<PEPIdentity>();
    1.31 +            this._Rating = pEpRating.pEpRatingUndefined;
    1.32          }
    1.33  
    1.34          /**************************************************************
    1.35 @@ -206,6 +210,20 @@
    1.36              get { return (this._Members); }
    1.37          }
    1.38  
    1.39 +        /// <summary>
    1.40 +        /// Gets or sets the associated rating of the identity.
    1.41 +        /// This will not be automatically calculated and must be managed externally.
    1.42 +        /// </summary>
    1.43 +        public pEpRating Rating
    1.44 +        {
    1.45 +            get { return (this._Rating); }
    1.46 +            set
    1.47 +            {
    1.48 +                this._Rating = value;
    1.49 +                this.RaisePropertyChangedEvent(nameof(this.Rating));
    1.50 +            }
    1.51 +        }
    1.52 +
    1.53          ///////////////////////////////////////////////////////////
    1.54          // Calculated
    1.55          ///////////////////////////////////////////////////////////
    1.56 @@ -424,7 +442,8 @@
    1.57                  Comparisons.Equals(this.UserName, obj.UserName) &&
    1.58                  Comparisons.Equals(this.IsForceUnencrypted, obj.IsForceUnencrypted) &&
    1.59                  Comparisons.Equals(this.IsSmartAddressEnabled, obj.IsSmartAddressEnabled) &&
    1.60 -                Comparisons.Equals(this.Members, obj.Members))
    1.61 +                Comparisons.Equals(this.Members, obj.Members) &&
    1.62 +                Comparisons.Equals(this.Rating, obj.Rating))
    1.63              {
    1.64                  return (true);
    1.65              }
    1.66 @@ -466,6 +485,8 @@
    1.67                  copy.Members.Add(this._Members[i].Copy());
    1.68              }
    1.69  
    1.70 +            copy.Rating = this._Rating;
    1.71 +
    1.72              return (copy);
    1.73          }
    1.74  
     2.1 --- a/UI/FormRegionPrivacyStatus.cs	Thu Oct 13 17:44:58 2016 +0200
     2.2 +++ b/UI/FormRegionPrivacyStatus.cs	Fri Oct 14 15:58:36 2016 +0200
     2.3 @@ -365,8 +365,6 @@
     2.4              List<PEPIdentity> identities;
     2.5              PEPIdentity identity;
     2.6              PEPIdentity myIdentity;
     2.7 -            pEpRating partnerIdentityRating;
     2.8 -            pEpColor partnerIdentityColor;
     2.9              SelectionItem item;
    2.10              FormControlManagePrivacyStatus.State managerState = new FormControlManagePrivacyStatus.State();
    2.11  
    2.12 @@ -436,14 +434,13 @@
    2.13  
    2.14                          try
    2.15                          {
    2.16 -                            partnerIdentityRating = ThisAddIn.PEPEngine.IdentityRating(partnerIdentity_s);
    2.17 +                            partnerIdentity.Rating = ThisAddIn.PEPEngine.IdentityRating(partnerIdentity_s);
    2.18                          }
    2.19                          catch (COMException ex)
    2.20                          {
    2.21 -                            partnerIdentityRating = pEpRating.pEpRatingUndefined;
    2.22 +                            partnerIdentity.Rating = pEpRating.pEpRatingUndefined;
    2.23                              Log.Warning("GetManagerState: Failed to get identity rating, " + ex.ToString());
    2.24                          }
    2.25 -                        partnerIdentityColor = partnerIdentityRating.ToColor();
    2.26  
    2.27                          isMyself = PEPIdentity.GetIsOwnIdentity(partnerIdentity.Address);
    2.28  
    2.29 @@ -475,7 +472,7 @@
    2.30                          }
    2.31                          else
    2.32                          {
    2.33 -                            switch (partnerIdentityColor)
    2.34 +                            switch (partnerIdentity.Rating.ToColor())
    2.35                              {
    2.36                                  case pEpColor.pEpColorGreen:
    2.37                                      item.ItemImage = imageGreen;
    2.38 @@ -505,69 +502,79 @@
    2.39                          }
    2.40                          else
    2.41                          {
    2.42 -                            if (partnerIdentityColor == pEpColor.pEpColorGreen)
    2.43 +                            switch (partnerIdentity.Rating.ToColor())
    2.44                              {
    2.45 -                                // Undo handshake
    2.46 -                                item.TextButton = pEp.Properties.Resources.PrivacyStatus_StopTrusting;
    2.47 -                                item.IsButtonVisible = true;
    2.48 -                                item.ButtonOnClick = (x, y) => { this.UndoHandshake(partnerIdentity.Copy()); };
    2.49 +                                case pEpColor.pEpColorGreen:
    2.50 +                                    {
    2.51 +                                        // Undo handshake
    2.52 +                                        item.TextButton = pEp.Properties.Resources.PrivacyStatus_StopTrusting;
    2.53 +                                        item.IsButtonVisible = true;
    2.54 +                                        item.ButtonOnClick = (x, y) => { this.UndoHandshake(partnerIdentity.Copy()); };
    2.55  
    2.56 -                                item.IsExpandable = false;
    2.57 -                            }
    2.58 -                            else if (partnerIdentityColor == pEpColor.pEpColorYellow)
    2.59 -                            {
    2.60 -                                // Do handshake
    2.61 -                                item.TextButton = pEp.Properties.Resources.PrivacyStatus_Handshake;
    2.62 -                                item.IsButtonVisible = true;
    2.63 -                                item.ButtonOnClick = (x, y) => { this.DoHandshake(myIdentity.Copy(), partnerIdentity.Copy()); };
    2.64 +                                        item.IsExpandable = false;
    2.65  
    2.66 -                                item.IsExpandable = true;
    2.67 -                                item.ExpandedText = pEp.Properties.Resources.Handshake_ConfirmTrustwordsText + "\n\n" +
    2.68 -                                                    trustwordsShort;
    2.69 +                                        break;
    2.70 +                                    }
    2.71 +                                case pEpColor.pEpColorYellow:
    2.72 +                                    {
    2.73 +                                        // Do handshake
    2.74 +                                        item.TextButton = pEp.Properties.Resources.PrivacyStatus_Handshake;
    2.75 +                                        item.IsButtonVisible = true;
    2.76 +                                        item.ButtonOnClick = (x, y) => { this.DoHandshake(myIdentity.Copy(), partnerIdentity.Copy()); };
    2.77  
    2.78 -                                item.ExpandedButton1Text = pEp.Properties.Resources.Handshake_ConfirmText;
    2.79 -                                item.ExpandedButton1OnClick = (x, y) => { this.ProcessDoHandshakeResult(DialogResult.Yes, partnerIdentity.Copy()); };
    2.80 -                                item.ExpandedButton1Style = (Style)Globals.ResourceDict["StyleConfirmButton"];
    2.81 +                                        item.IsExpandable = true;
    2.82 +                                        item.ExpandedText = pEp.Properties.Resources.Handshake_ConfirmTrustwordsText + "\n\n" +
    2.83 +                                                            trustwordsShort;
    2.84  
    2.85 -                                item.ExpandedButton2Text = pEp.Properties.Resources.Handshake_CancelText;
    2.86 -                                item.ExpandedButton2OnClick = (x, y) =>
    2.87 +                                        item.ExpandedButton1Text = pEp.Properties.Resources.Handshake_ConfirmText;
    2.88 +                                        item.ExpandedButton1OnClick = (x, y) => { this.ProcessDoHandshakeResult(DialogResult.Yes, partnerIdentity.Copy()); };
    2.89 +                                        item.ExpandedButton1Style = (Style)Globals.ResourceDict["StyleConfirmButton"];
    2.90 +
    2.91 +                                        item.ExpandedButton2Text = pEp.Properties.Resources.Handshake_CancelText;
    2.92 +                                        item.ExpandedButton2OnClick = (x, y) =>
    2.93 +                                        {
    2.94 +                                            SelectionItem selItem;
    2.95 +                                            FormControlManagePrivacyStatus.State activeState;
    2.96 +
    2.97 +                                            if (this.managerForm != null)
    2.98 +                                            {
    2.99 +                                                activeState = this.managerForm.FormControl.DisplayState;
   2.100 +
   2.101 +                                                if ((index >= 0) &&
   2.102 +                                                    (index < activeState.Identities.Count))
   2.103 +                                                {
   2.104 +                                                    selItem = activeState.Identities[index];
   2.105 +                                                    selItem.TextButton = pEp.Properties.Resources.PrivacyStatus_Handshake;
   2.106 +                                                    selItem.IsExpanded = false;
   2.107 +                                                    selItem.IsExpandable = false;
   2.108 +                                                }
   2.109 +                                            }
   2.110 +                                        };
   2.111 +                                        item.ExpandedButton2Style = (Style)Globals.ResourceDict["StyleCancelButton"];
   2.112 +
   2.113 +                                        item.ExpandedButton3Text = pEp.Properties.Resources.Handshake_WrongText;
   2.114 +                                        item.ExpandedButton3OnClick = (x, y) => { this.ProcessDoHandshakeResult(DialogResult.No, partnerIdentity.Copy()); };
   2.115 +                                        item.ExpandedButton3Style = (Style)Globals.ResourceDict["StyleWrongButton"];
   2.116 +
   2.117 +                                        break;
   2.118 +                                    }
   2.119 +                                case pEpColor.pEpColorRed:
   2.120                                      {
   2.121 -                                        SelectionItem selItem;
   2.122 -                                        FormControlManagePrivacyStatus.State activeState;
   2.123 +                                        // Redo handshake with confirmation
   2.124 +                                        item.TextButton = pEp.Properties.Resources.PrivacyStatus_Handshake;
   2.125 +                                        item.IsButtonVisible = true;
   2.126 +                                        item.ButtonOnClick = (x, y) => { this.DoHandshakeForMistrustedKey(myIdentity.Copy(), partnerIdentity.Copy()); };
   2.127  
   2.128 -                                        if (this.managerForm != null)
   2.129 -                                        {
   2.130 -                                            activeState = this.managerForm.FormControl.DisplayState;
   2.131 +                                        item.IsExpandable = false;
   2.132  
   2.133 -                                            if ((index >= 0) &&
   2.134 -                                                (index < activeState.Identities.Count))
   2.135 -                                            {
   2.136 -                                                selItem = activeState.Identities[index];
   2.137 -                                                selItem.TextButton = pEp.Properties.Resources.PrivacyStatus_Handshake;
   2.138 -                                                selItem.IsExpanded = false;
   2.139 -                                                selItem.IsExpandable = false;
   2.140 -                                            }
   2.141 -                                        }
   2.142 -                                    };
   2.143 -                                item.ExpandedButton2Style = (Style)Globals.ResourceDict["StyleCancelButton"];
   2.144 -
   2.145 -                                item.ExpandedButton3Text = pEp.Properties.Resources.Handshake_WrongText;
   2.146 -                                item.ExpandedButton3OnClick = (x, y) => { this.ProcessDoHandshakeResult(DialogResult.No, partnerIdentity.Copy()); };
   2.147 -                                item.ExpandedButton3Style = (Style)Globals.ResourceDict["StyleWrongButton"];
   2.148 -                            }
   2.149 -                            else if (partnerIdentityColor == pEpColor.pEpColorRed)
   2.150 -                            {
   2.151 -                                // Redo handshake with confirmation
   2.152 -                                item.TextButton = pEp.Properties.Resources.PrivacyStatus_Handshake;
   2.153 -                                item.IsButtonVisible = true;
   2.154 -                                item.ButtonOnClick = (x, y) => { this.DoHandshakeForMistrustedKey(myIdentity.Copy(), partnerIdentity.Copy()); };
   2.155 -
   2.156 -                                item.IsExpandable = false;
   2.157 -                            }
   2.158 -                            else
   2.159 -                            {
   2.160 -                                item.IsButtonVisible = false;
   2.161 -                                item.IsExpandable = false;
   2.162 +                                        break;
   2.163 +                                    }
   2.164 +                                default:
   2.165 +                                    {
   2.166 +                                        item.IsButtonVisible = false;
   2.167 +                                        item.IsExpandable = false;
   2.168 +                                        break;
   2.169 +                                    }
   2.170                              }
   2.171                          }
   2.172                      }