Refactor value converters refactor_dialogs
authorThomas
Mon, 26 Aug 2019 12:49:21 +0200
branchrefactor_dialogs
changeset 2722bb256cdca493
parent 2721 6d930924131b
child 2723 6c5506fa5fed
Refactor value converters
UI/FormControlOptions.xaml
UI/KeySyncWizard.xaml
UI/ValueConverters.cs
UI/ViewModels/HandshakeViewModel.cs
UI/Views/HandshakeView.xaml
     1.1 --- a/UI/FormControlOptions.xaml	Mon Aug 26 09:24:05 2019 +0200
     1.2 +++ b/UI/FormControlOptions.xaml	Mon Aug 26 12:49:21 2019 +0200
     1.3 @@ -14,7 +14,7 @@
     1.4          <ResourceDictionary>
     1.5              <!-- Converters -->
     1.6              <BooleanToVisibilityConverter x:Key="BoolToVisibility" />
     1.7 -            <local:IsReleaseModeConverter x:Key="IsReleaseMode" />
     1.8 +            <local:ReleaseModeToBooleanConverter x:Key="ReleaseModeToBool" />
     1.9              <local:InvertBoolConverter x:Key="InvertBool" />
    1.10              <local:MultiBooleanToVisibilityConverter x:Key="MultiBooleanToVisibility" />
    1.11              <local:ValueConverterGroup x:Key="IsSyncEnabledToColor">
    1.12 @@ -25,8 +25,8 @@
    1.13                  <local:InvertBoolConverter />
    1.14                  <BooleanToVisibilityConverter />
    1.15              </local:ValueConverterGroup>
    1.16 -            <local:ValueConverterGroup x:Key="IsReleaseModeToVisibility">
    1.17 -                <local:IsReleaseModeConverter />
    1.18 +            <local:ValueConverterGroup x:Key="ReleaseModeToVisibility">
    1.19 +                <local:ReleaseModeToBooleanConverter />
    1.20                  <BooleanToVisibilityConverter />
    1.21              </local:ValueConverterGroup>
    1.22              <local:ValueConverterGroup x:Key="IsStringEmptyToVisibility">
    1.23 @@ -409,7 +409,7 @@
    1.24                              <CheckBox.Visibility>
    1.25                                  <MultiBinding Converter="{StaticResource MultiBooleanToVisibility}">
    1.26                                      <Binding Path="ReleaseMode"
    1.27 -                                             Converter="{StaticResource IsReleaseMode}"
    1.28 +                                             Converter="{StaticResource ReleaseModeToBool}"
    1.29                                               ConverterParameter="Standard" />
    1.30                                      <Binding Path="IsAdvancedEnabled" />
    1.31                                  </MultiBinding>
    1.32 @@ -431,7 +431,7 @@
    1.33                              <CheckBox.Visibility>
    1.34                                  <MultiBinding Converter="{StaticResource MultiBooleanToVisibility}">
    1.35                                      <Binding Path="ReleaseMode"
    1.36 -                                             Converter="{StaticResource IsReleaseMode}"
    1.37 +                                             Converter="{StaticResource ReleaseModeToBool}"
    1.38                                               ConverterParameter="Standard" />
    1.39                                      <Binding Path="IsAdvancedEnabled" />
    1.40                                  </MultiBinding>
    1.41 @@ -453,7 +453,7 @@
    1.42                              <CheckBox.Visibility>
    1.43                                  <MultiBinding Converter="{StaticResource MultiBooleanToVisibility}">
    1.44                                      <Binding Path="ReleaseMode"
    1.45 -                                             Converter="{StaticResource IsReleaseMode}"
    1.46 +                                             Converter="{StaticResource ReleaseModeToBool}"
    1.47                                               ConverterParameter="Standard" />
    1.48                                      <Binding Path="IsAdvancedEnabled" />
    1.49                                  </MultiBinding>
    1.50 @@ -556,7 +556,7 @@
    1.51                                VerticalContentAlignment="Top"
    1.52                                IsThreeState="False"
    1.53                                IsChecked="{Binding Path=IsUnencryptedSubjectEnabled, Mode=TwoWay}"
    1.54 -                              Visibility="{Binding Path=ReleaseMode, Mode=OneWay, Converter={StaticResource IsReleaseModeToVisibility}, ConverterParameter='Standard'}">
    1.55 +                              Visibility="{Binding Path=ReleaseMode, Mode=OneWay, Converter={StaticResource ReleaseModeToVisibility}, ConverterParameter=Standard}">
    1.56                          <CheckBox.Margin>
    1.57                              <Thickness Bottom="0"
    1.58                                         Left="{StaticResource PageLeftSpacing}"
    1.59 @@ -576,7 +576,7 @@
    1.60                          <TextBlock.Visibility>
    1.61                              <MultiBinding Converter="{StaticResource MultiBooleanToVisibility}">
    1.62                                  <Binding Path="ReleaseMode"
    1.63 -                                         Converter="{StaticResource IsReleaseMode}"
    1.64 +                                         Converter="{StaticResource ReleaseModeToBool}"
    1.65                                           ConverterParameter="Standard" />
    1.66                                  <Binding Path="IsAdvancedEnabled" />
    1.67                              </MultiBinding>
    1.68 @@ -592,7 +592,7 @@
    1.69                          <Separator.Visibility>
    1.70                              <MultiBinding Converter="{StaticResource MultiBooleanToVisibility}">
    1.71                                  <Binding Path="ReleaseMode"
    1.72 -                                         Converter="{StaticResource IsReleaseMode}"
    1.73 +                                         Converter="{StaticResource ReleaseModeToBool}"
    1.74                                           ConverterParameter="Standard" />
    1.75                                  <Binding Path="IsAdvancedEnabled" />
    1.76                              </MultiBinding>
    1.77 @@ -604,7 +604,7 @@
    1.78                          <Grid.Visibility>
    1.79                              <MultiBinding Converter="{StaticResource MultiBooleanToVisibility}">
    1.80                                  <Binding Path="ReleaseMode"
    1.81 -                                         Converter="{StaticResource IsReleaseMode}"
    1.82 +                                         Converter="{StaticResource ReleaseModeToBool}"
    1.83                                           ConverterParameter="Standard" />
    1.84                                  <Binding Path="IsAdvancedEnabled" />
    1.85                              </MultiBinding>
     2.1 --- a/UI/KeySyncWizard.xaml	Mon Aug 26 09:24:05 2019 +0200
     2.2 +++ b/UI/KeySyncWizard.xaml	Mon Aug 26 12:49:21 2019 +0200
     2.3 @@ -33,7 +33,7 @@
     2.4                  <local:InvertBoolConverter />
     2.5                  <BooleanToVisibilityConverter />
     2.6              </local:ValueConverterGroup>
     2.7 -            <local:IsWizardTypeConverter x:Key="IsWizardType" />
     2.8 +            <local:WizardTypeToBooleanConverter x:Key="IsWizardType" />
     2.9  
    2.10              <!--Dictionary-->
    2.11              <ResourceDictionary.MergedDictionaries>
     3.1 --- a/UI/ValueConverters.cs	Mon Aug 26 09:24:05 2019 +0200
     3.2 +++ b/UI/ValueConverters.cs	Mon Aug 26 12:49:21 2019 +0200
     3.3 @@ -1,5 +1,6 @@
     3.4  ´╗┐using pEp.UI.Models;
     3.5  using pEp.UI.ViewModels;
     3.6 +using pEpCOMServerAdapterLib;
     3.7  using System;
     3.8  using System.Collections;
     3.9  using System.Collections.Generic;
    3.10 @@ -39,6 +40,57 @@
    3.11      }
    3.12  
    3.13      /// <summary>
    3.14 +    /// Converter to check if a given color matches the expected one.
    3.15 +    /// </summary>
    3.16 +    public class ColorToBooleanConverter : IValueConverter
    3.17 +    {
    3.18 +        public object Convert(object value,
    3.19 +                              Type targetType,
    3.20 +                              object parameter,
    3.21 +                              CultureInfo culture)
    3.22 +        {
    3.23 +            if ((value is pEpColor val) &&
    3.24 +                Enum.TryParse(parameter as string, out pEpColor param))
    3.25 +            {
    3.26 +                return (val == param);
    3.27 +            }
    3.28 +            else
    3.29 +            {
    3.30 +                throw new ArgumentException();
    3.31 +            }
    3.32 +        }
    3.33 +
    3.34 +        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    3.35 +        {
    3.36 +            throw new NotImplementedException();
    3.37 +        }
    3.38 +    }
    3.39 +
    3.40 +    public class DialogTypeToBooleanConverter : IValueConverter
    3.41 +    {
    3.42 +        public object Convert(object value,
    3.43 +                              Type targetType,
    3.44 +                              object parameter,
    3.45 +                              CultureInfo culture)
    3.46 +        {
    3.47 +            if ((value is Dialog.DialogType val) &&
    3.48 +                Enum.TryParse(parameter as string, out Dialog.DialogType param))
    3.49 +            {
    3.50 +                return (val == param);
    3.51 +            }
    3.52 +            else
    3.53 +            {
    3.54 +                throw new ArgumentException();
    3.55 +            }
    3.56 +        }
    3.57 +
    3.58 +        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    3.59 +        {
    3.60 +            throw new NotImplementedException();
    3.61 +        }
    3.62 +    }
    3.63 +
    3.64 +    /// <summary>
    3.65      /// Converter to check whether a PEPMessage has attachments that are not
    3.66      /// inline attachments.
    3.67      /// </summary>
    3.68 @@ -166,29 +218,15 @@
    3.69                                object parameter,
    3.70                                CultureInfo culture)
    3.71          {
    3.72 -            bool result = false;
    3.73 -            string param = null;
    3.74 -            string val = null;
    3.75 -
    3.76 -            param = parameter as string;
    3.77 -
    3.78 -            try
    3.79 +            if ((value is HandshakeViewModel.Tabs val) &&
    3.80 +                Enum.TryParse(parameter as string, out HandshakeViewModel.Tabs param))
    3.81              {
    3.82 -                val = Enum.GetName(typeof(HandshakeViewModel.Tabs), value);
    3.83 +                return (val == param);
    3.84              }
    3.85 -            catch
    3.86 +            else
    3.87              {
    3.88 -                val = null;
    3.89 +                throw new ArgumentException();
    3.90              }
    3.91 -
    3.92 -            if ((param != null) &&
    3.93 -                (val != null) &&
    3.94 -                (val == param))
    3.95 -            {
    3.96 -                result = true;
    3.97 -            }
    3.98 -
    3.99 -            return result;
   3.100          }
   3.101  
   3.102          public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
   3.103 @@ -267,6 +305,9 @@
   3.104          }
   3.105      }
   3.106  
   3.107 +    /// <summary>
   3.108 +    /// Returns true if the value is of type KeySync or KeyImport.
   3.109 +    /// </summary>
   3.110      public class IsWizardModeToBoolConverter : IValueConverter
   3.111      {
   3.112          public object Convert(object value,
   3.113 @@ -274,112 +315,16 @@
   3.114                               object parameter,
   3.115                               CultureInfo culture)
   3.116          {
   3.117 -            try
   3.118 +            if (value is Dialog.DialogType val)
   3.119              {
   3.120 -                if ((Enum.GetName(typeof(Dialog.DialogType), value) is string val) &&
   3.121 -                    ((val.Equals(Enum.GetName(typeof(Dialog.DialogType), Dialog.DialogType.KeySync))) ||
   3.122 -                     (val.Equals(Enum.GetName(typeof(Dialog.DialogType), Dialog.DialogType.KeyImportPEP))) ||
   3.123 -                     (val.Equals(Enum.GetName(typeof(Dialog.DialogType), Dialog.DialogType.KeyImportPGP)))))
   3.124 -                {
   3.125 -                    return true;
   3.126 -                }
   3.127 -            }
   3.128 -            catch (Exception ex)
   3.129 -            {
   3.130 -                Log.Error("IsWizardModeToBoolConverter: Error occured. " + ex.ToString());
   3.131 -            }
   3.132 -
   3.133 -            return false;
   3.134 -        }
   3.135 -
   3.136 -        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
   3.137 -        {
   3.138 -            throw new NotImplementedException();
   3.139 -        }
   3.140 -    }
   3.141 -
   3.142 -    /// <summary>
   3.143 -    /// Returns a bool value indicating if the release mode matches the given parameter.
   3.144 -    /// </summary>
   3.145 -    public class IsReleaseModeConverter : IValueConverter
   3.146 -    {
   3.147 -        public object Convert(object value,
   3.148 -                              Type targetType,
   3.149 -                              object parameter,
   3.150 -                              CultureInfo culture)
   3.151 -        {
   3.152 -            bool success;
   3.153 -            Globals.ReleaseMode param;
   3.154 -
   3.155 -            if ((value is Globals.ReleaseMode) &&
   3.156 -                (parameter is string))
   3.157 -            {
   3.158 -                success = Enum.TryParse((parameter as string), out param);
   3.159 -
   3.160 -                if (success)
   3.161 -                {
   3.162 -                    if (((Globals.ReleaseMode)value) == param)
   3.163 -                    {
   3.164 -                        return (true);
   3.165 -                    }
   3.166 -                    else
   3.167 -                    {
   3.168 -                        return (false);
   3.169 -                    }
   3.170 -                }
   3.171 -                else
   3.172 -                {
   3.173 -                    throw new ArgumentException();
   3.174 -                }
   3.175 +                return ((val == Dialog.DialogType.KeySync) ||
   3.176 +                        (val == Dialog.DialogType.KeyImportPEP) ||
   3.177 +                        (val == Dialog.DialogType.KeyImportPGP));
   3.178              }
   3.179              else
   3.180              {
   3.181                  throw new ArgumentException();
   3.182 -            }
   3.183 -        }
   3.184 -
   3.185 -        public object ConvertBack(object value,
   3.186 -                                  Type targetType,
   3.187 -                                  object parameter,
   3.188 -                                  CultureInfo culture)
   3.189 -        {
   3.190 -            throw new NotImplementedException();
   3.191 -        }
   3.192 -    }
   3.193 -
   3.194 -    /// <summary>
   3.195 -    /// Returns true if given parameter is equal to HandshakeMode.Standard. Otherwise false
   3.196 -    /// </summary>
   3.197 -    public class IsStandardModeToBoolConverter : IValueConverter
   3.198 -    {
   3.199 -        public object Convert(object value,
   3.200 -                              Type targetType,
   3.201 -                              object parameter,
   3.202 -                              CultureInfo culture)
   3.203 -        {
   3.204 -            bool result = false;
   3.205 -            string param = null;
   3.206 -            string val = null;
   3.207 -
   3.208 -            param = parameter as string;
   3.209 -
   3.210 -            try
   3.211 -            {
   3.212 -                val = Enum.GetName(typeof(Handshake.HandshakeMode), value);
   3.213 -            }
   3.214 -            catch
   3.215 -            {
   3.216 -                val = null;
   3.217 -            }
   3.218 -
   3.219 -            if ((param != null) &&
   3.220 -                (val != null) &&
   3.221 -                (val == param))
   3.222 -            {
   3.223 -                result = true;
   3.224 -            }
   3.225 -
   3.226 -            return result;
   3.227 +            }          
   3.228          }
   3.229  
   3.230          public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
   3.231 @@ -398,10 +343,13 @@
   3.232                                object parameter,
   3.233                                CultureInfo culture)
   3.234          {
   3.235 -            if ((value == null) ||
   3.236 -                (value is string))
   3.237 +            if (value == null)
   3.238              {
   3.239 -                return (string.IsNullOrEmpty(value as string));
   3.240 +                return true;
   3.241 +            }
   3.242 +            else if (value is string val)
   3.243 +            {
   3.244 +                return string.IsNullOrEmpty(val);
   3.245              }
   3.246              else
   3.247              {
   3.248 @@ -419,29 +367,24 @@
   3.249      }
   3.250  
   3.251      /// <summary>
   3.252 -    /// Returns true if given parameter is one of the sync modes. Otherwise false
   3.253 +    /// Returns true if the given parameter matches the expected value.
   3.254      /// </summary>
   3.255 -    public class IsSyncModeToBoolConverter : IValueConverter
   3.256 +    public class HandshakeModeToBooleanConverter : IValueConverter
   3.257      {
   3.258          public object Convert(object value,
   3.259                                Type targetType,
   3.260                                object parameter,
   3.261                                CultureInfo culture)
   3.262          {
   3.263 -            try
   3.264 +            if ((value is Handshake.HandshakeMode val) &&
   3.265 +                Enum.TryParse(parameter as string, out Handshake.HandshakeMode param))
   3.266              {
   3.267 -                if ((Enum.GetName(typeof(Dialog.DialogType), value) is string val) &&
   3.268 -                    val.Equals(Enum.GetName(typeof(Dialog.DialogType), Dialog.DialogType.KeySync)))
   3.269 -                {
   3.270 -                    return true;
   3.271 -                }
   3.272 +                return (val == param);
   3.273              }
   3.274 -            catch (Exception ex)
   3.275 +            else
   3.276              {
   3.277 -                Log.Error("IsSyncModeToBoolConverter: Error occured. " + ex.ToString());
   3.278 +                throw new ArgumentException();
   3.279              }
   3.280 -
   3.281 -            return false;
   3.282          }
   3.283  
   3.284          public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
   3.285 @@ -451,38 +394,6 @@
   3.286      }
   3.287  
   3.288      /// <summary>
   3.289 -    /// Returns true if the Wizard is in the given state.
   3.290 -    /// </summary>
   3.291 -    public class IsWizardTypeConverter : IValueConverter
   3.292 -    {
   3.293 -        public object Convert(object value,
   3.294 -                              Type targetType,
   3.295 -                              object parameter,
   3.296 -                              CultureInfo culture)
   3.297 -        {
   3.298 -            string val = null;
   3.299 -            string param = parameter as string;
   3.300 -
   3.301 -            try
   3.302 -            {
   3.303 -                val = Enum.GetName(typeof(KeySyncWizard.WizardType), value);
   3.304 -            }
   3.305 -            catch
   3.306 -            {
   3.307 -                val = null;
   3.308 -            }
   3.309 -
   3.310 -            return (param?.Equals(val) == true);
   3.311 -        }
   3.312 -
   3.313 -        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
   3.314 -        {
   3.315 -            throw new NotImplementedException();
   3.316 -        }
   3.317 -    }
   3.318 -
   3.319 -
   3.320 -    /// <summary>
   3.321      /// Converter to AND several bool values and convert to Visibility.
   3.322      /// </summary>
   3.323      public class MultiBooleanToVisibilityConverter : IMultiValueConverter
   3.324 @@ -526,6 +437,36 @@
   3.325      }
   3.326  
   3.327      /// <summary>
   3.328 +    /// Returns true if the given parameter matches the expected value.
   3.329 +    /// </summary>
   3.330 +    public class ReleaseModeToBooleanConverter : IValueConverter
   3.331 +    {
   3.332 +        public object Convert(object value,
   3.333 +                              Type targetType,
   3.334 +                              object parameter,
   3.335 +                              CultureInfo culture)
   3.336 +        {
   3.337 +            if ((value is Globals.ReleaseMode val) &&
   3.338 +                Enum.TryParse(parameter as string, out Globals.ReleaseMode param))
   3.339 +            {
   3.340 +                return (val == param);
   3.341 +            }
   3.342 +            else
   3.343 +            {
   3.344 +                throw new ArgumentException();
   3.345 +            }
   3.346 +        }
   3.347 +
   3.348 +        public object ConvertBack(object value,
   3.349 +                                  Type targetType,
   3.350 +                                  object parameter,
   3.351 +                                  CultureInfo culture)
   3.352 +        {
   3.353 +            throw new NotImplementedException();
   3.354 +        }
   3.355 +    }
   3.356 +
   3.357 +    /// <summary>
   3.358      /// Converter to chain together multiple converters.
   3.359      /// </summary>
   3.360      public class ValueConverterGroup : List<IValueConverter>, IValueConverter
   3.361 @@ -562,4 +503,31 @@
   3.362              return (curValue);
   3.363          }
   3.364      }
   3.365 +
   3.366 +    /// <summary>
   3.367 +    /// Returns true if the Wizard is of the given type.
   3.368 +    /// </summary>
   3.369 +    public class WizardTypeToBooleanConverter : IValueConverter
   3.370 +    {
   3.371 +        public object Convert(object value,
   3.372 +                              Type targetType,
   3.373 +                              object parameter,
   3.374 +                              CultureInfo culture)
   3.375 +        {
   3.376 +            if ((value is KeySyncWizard.WizardType val) &&
   3.377 +                Enum.TryParse(parameter as string, out KeySyncWizard.WizardType param))
   3.378 +            {
   3.379 +                return (val == param);
   3.380 +            }
   3.381 +            else
   3.382 +            {
   3.383 +                throw new ArgumentException();
   3.384 +            }
   3.385 +        }
   3.386 +
   3.387 +        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
   3.388 +        {
   3.389 +            throw new NotImplementedException();
   3.390 +        }
   3.391 +    }
   3.392  }
     4.1 --- a/UI/ViewModels/HandshakeViewModel.cs	Mon Aug 26 09:24:05 2019 +0200
     4.2 +++ b/UI/ViewModels/HandshakeViewModel.cs	Mon Aug 26 12:49:21 2019 +0200
     4.3 @@ -331,6 +331,54 @@
     4.4              this.Dialog = dialog;
     4.5              this.CloseWindowAction = closeWindow;
     4.6  
     4.7 +            this.InitializeHandshakeView();
     4.8 +        }             
     4.9 +
    4.10 +        #endregion
    4.11 +
    4.12 +        #region Commands
    4.13 +
    4.14 +        /// <summary>
    4.15 +        /// Command to execute when the Confirm button is clicked.
    4.16 +        /// </summary>
    4.17 +        public RelayCommand ButtonConfirmOnClick
    4.18 +        {
    4.19 +            get
    4.20 +            {
    4.21 +                if (this._ButtonConfirmOnClick == null)
    4.22 +                {
    4.23 +                    this._ButtonConfirmOnClick = new RelayCommand(p => this.TrustKeyAndCloseDialog());
    4.24 +                }
    4.25 +
    4.26 +                return this._ButtonConfirmOnClick;
    4.27 +            }
    4.28 +        }
    4.29 +
    4.30 +        /// <summary>
    4.31 +        /// Command to execute when the Wrong button is clicked.
    4.32 +        /// </summary>
    4.33 +        public RelayCommand ButtonWrongOnClick
    4.34 +        {
    4.35 +            get
    4.36 +            {
    4.37 +                if (this._ButtonWrongOnClick == null)
    4.38 +                {
    4.39 +                    this._ButtonWrongOnClick = new RelayCommand(p => this.MistrustKeyAndCloseDialog());
    4.40 +                }
    4.41 +
    4.42 +                return this._ButtonWrongOnClick;
    4.43 +            }
    4.44 +        }
    4.45 +
    4.46 +        #endregion
    4.47 +
    4.48 +        #region Methods
    4.49 +
    4.50 +        /// <summary>
    4.51 +        /// Initializes the handshake view.
    4.52 +        /// </summary>
    4.53 +        private void InitializeHandshakeView()
    4.54 +        {
    4.55              // Create User Ids
    4.56              this.UIDMyself = this.Myself?.UserName + " <" + this.Myself?.Address + ">";
    4.57              this.UIDPartner = this.Partner?.UserName + " <" + this.Partner?.Address + ">";
    4.58 @@ -338,8 +386,31 @@
    4.59              // Set Name
    4.60              this.PartnerDisplayName = this.UIDPartner;
    4.61  
    4.62 -            // Set image
    4.63 -            this.SetPartnerIcon();
    4.64 +            // Set color related properties
    4.65 +            switch (this.Partner.Color)
    4.66 +            {
    4.67 +                case pEpColor.pEpColorYellow:
    4.68 +                    {
    4.69 +                        this.PEPColorIcon = new BitmapImage(new Uri("pack://application:,,,/pEp;component/Resources/ImagePrivacyStatusYellow.png", UriKind.RelativeOrAbsolute));
    4.70 +                    }
    4.71 +                    break;
    4.72 +                case pEpColor.pEpColorGreen:
    4.73 +                    {
    4.74 +                        this.PEPColorIcon = new BitmapImage(new Uri("pack://application:,,,/pEp;component/Resources/ImagePrivacyStatusGreen.png", UriKind.RelativeOrAbsolute));
    4.75 +                    }
    4.76 +                    break;
    4.77 +                case pEpColor.pEpColorRed:
    4.78 +                    {
    4.79 +                        this.PEPColorIcon = new BitmapImage(new Uri("pack://application:,,,/pEp;component/Resources/ImagePrivacyStatusRed.png", UriKind.RelativeOrAbsolute));
    4.80 +                    }
    4.81 +                    break;
    4.82 +                case pEpColor.pEpColorNoColor:
    4.83 +                default:
    4.84 +                    {
    4.85 +                        this.PEPColorIcon = new BitmapImage(new Uri("pack://application:,,,/pEp;component/Resources/ImagePrivacyStatusNoColor.png", UriKind.RelativeOrAbsolute));
    4.86 +                    }
    4.87 +                    break;
    4.88 +            }
    4.89  
    4.90              // Set Trustwords culture and update the Trustwords itself
    4.91              this.TrustwordsCulture = Globals.ThisAddIn.Settings.TrustwordsCulture;
    4.92 @@ -420,69 +491,6 @@
    4.93          }
    4.94  
    4.95          /// <summary>
    4.96 -        /// Sets the partner's pEp color icon.
    4.97 -        /// </summary>
    4.98 -        private void SetPartnerIcon()
    4.99 -        {
   4.100 -            switch (this.Partner?.Color ?? pEpColor.pEpColorNoColor)
   4.101 -            {
   4.102 -                case pEpColor.pEpColorYellow:
   4.103 -                    this.PEPColorIcon = new BitmapImage(new Uri("pack://application:,,,/pEp;component/Resources/ImagePrivacyStatusYellow.png", UriKind.RelativeOrAbsolute));
   4.104 -                    break;
   4.105 -                case pEpColor.pEpColorGreen:
   4.106 -                    this.PEPColorIcon = new BitmapImage(new Uri("pack://application:,,,/pEp;component/Resources/ImagePrivacyStatusGreen.png", UriKind.RelativeOrAbsolute));
   4.107 -                    break;
   4.108 -                case pEpColor.pEpColorRed:
   4.109 -                    this.PEPColorIcon = new BitmapImage(new Uri("pack://application:,,,/pEp;component/Resources/ImagePrivacyStatusRed.png", UriKind.RelativeOrAbsolute));
   4.110 -                    break;
   4.111 -                case pEpColor.pEpColorNoColor:
   4.112 -                default:
   4.113 -                    this.PEPColorIcon = new BitmapImage(new Uri("pack://application:,,,/pEp;component/Resources/ImagePrivacyStatusNoColor.png", UriKind.RelativeOrAbsolute));
   4.114 -                    break;
   4.115 -            }
   4.116 -        }
   4.117 -
   4.118 -        #endregion
   4.119 -
   4.120 -        #region Commands
   4.121 -
   4.122 -        /// <summary>
   4.123 -        /// Command to execute when the Confirm button is clicked.
   4.124 -        /// </summary>
   4.125 -        public RelayCommand ButtonConfirmOnClick
   4.126 -        {
   4.127 -            get
   4.128 -            {
   4.129 -                if (this._ButtonConfirmOnClick == null)
   4.130 -                {
   4.131 -                    this._ButtonConfirmOnClick = new RelayCommand(p => this.TrustKeyAndCloseDialog());
   4.132 -                }
   4.133 -
   4.134 -                return this._ButtonConfirmOnClick;
   4.135 -            }
   4.136 -        }
   4.137 -
   4.138 -        /// <summary>
   4.139 -        /// Command to execute when the Wrong button is clicked.
   4.140 -        /// </summary>
   4.141 -        public RelayCommand ButtonWrongOnClick
   4.142 -        {
   4.143 -            get
   4.144 -            {
   4.145 -                if (this._ButtonWrongOnClick == null)
   4.146 -                {
   4.147 -                    this._ButtonWrongOnClick = new RelayCommand(p => this.MistrustKeyAndCloseDialog());
   4.148 -                }
   4.149 -
   4.150 -                return this._ButtonWrongOnClick;
   4.151 -            }
   4.152 -        }
   4.153 -
   4.154 -        #endregion
   4.155 -
   4.156 -        #region Methods
   4.157 -
   4.158 -        /// <summary>
   4.159          /// Mistrusts the partner's identity key and closes the dialog.
   4.160          /// </summary>
   4.161          private void MistrustKeyAndCloseDialog()
     5.1 --- a/UI/Views/HandshakeView.xaml	Mon Aug 26 09:24:05 2019 +0200
     5.2 +++ b/UI/Views/HandshakeView.xaml	Mon Aug 26 12:49:21 2019 +0200
     5.3 @@ -10,6 +10,10 @@
     5.4          <ResourceDictionary>
     5.5              <!-- Converters -->
     5.6              <BooleanToVisibilityConverter x:Key="BoolToVisibility" />
     5.7 +            <ui:ValueConverterGroup x:Key="ColorToVisibility">
     5.8 +                <ui:ColorToBooleanConverter />
     5.9 +                <BooleanToVisibilityConverter />
    5.10 +            </ui:ValueConverterGroup>
    5.11              <ui:IsActiveTabToBoolConverter x:Key="IsActiveTabToBool" />
    5.12              <ui:IsEnabledToColorConverter x:Key="IsEnabledToColor" />
    5.13              <ui:ValueConverterGroup x:Key="InvertBoolToVisibility">
    5.14 @@ -29,8 +33,8 @@
    5.15                  <ui:InvertBoolConverter/>
    5.16                  <BooleanToVisibilityConverter/>
    5.17              </ui:ValueConverterGroup>
    5.18 -            <ui:ValueConverterGroup x:Key="IsSyncModeToVisibility">
    5.19 -                <ui:IsSyncModeToBoolConverter />
    5.20 +            <ui:ValueConverterGroup x:Key="DialogTypeToVisibility">
    5.21 +                <ui:DialogTypeToBooleanConverter />
    5.22                  <BooleanToVisibilityConverter />
    5.23              </ui:ValueConverterGroup>
    5.24              
    5.25 @@ -56,7 +60,7 @@
    5.26                    IsEditable="True"
    5.27                    IsReadOnly="True"
    5.28                    Focusable="False"
    5.29 -                  Visibility="{Binding DialogType, Converter={StaticResource IsSyncModeToVisibility}}">
    5.30 +                  Visibility="{Binding DialogType, Converter={StaticResource DialogTypeToVisibility}, ConverterParameter=KeySync}">
    5.31              <ComboBox.ItemTemplate>
    5.32                  <DataTemplate>
    5.33                      <StackPanel Orientation="Horizontal">
    5.34 @@ -89,74 +93,77 @@
    5.35                         Text="{Binding Path=PartnerDisplayName, Mode=OneWay}" />
    5.36          </StackPanel>
    5.37  
    5.38 -        <!--Tabs-->
    5.39 -        <StackPanel Orientation="Horizontal"
    5.40 +        <!--Interaction area-->
    5.41 +        <StackPanel Visibility="{Binding Partner.Color, Converter={StaticResource ColorToVisibility}, ConverterParameter=pEpColorYellow}">
    5.42 +
    5.43 +            <!--Tabs-->
    5.44 +            <StackPanel Orientation="Horizontal"
    5.45                      HorizontalAlignment="Right">
    5.46 -            <Label Name="TabControlTrustwords"
    5.47 +                <Label Name="TabControlTrustwords"
    5.48                     MouseLeftButtonUp="TabControlTrustwords_MouseLeftButtonUp"
    5.49                     Content="{x:Static p:Resources.Handshake_TrustwordsText}"
    5.50                     Visibility="{Binding Path=AreTabControlsVisible, Converter={StaticResource BoolToVisibility}}">
    5.51 -                <Label.Style>
    5.52 -                    <Style TargetType="Label">
    5.53 -                        <Setter Property="BorderBrush"
    5.54 +                    <Label.Style>
    5.55 +                        <Style TargetType="Label">
    5.56 +                            <Setter Property="BorderBrush"
    5.57                                  Value="LightGray" />
    5.58 -                        <Setter Property="Background"
    5.59 +                            <Setter Property="Background"
    5.60                                  Value="{Binding Path=ActiveTab, Converter={StaticResource IsActiveTabToBackground}, ConverterParameter=Trustwords}" />
    5.61 -                        <Setter Property="BorderThickness"
    5.62 +                            <Setter Property="BorderThickness"
    5.63                                  Value="1" />
    5.64 -                        <Setter Property="Padding"
    5.65 +                            <Setter Property="Padding"
    5.66                                  Value="10,5" />
    5.67 -                        <Style.Triggers>
    5.68 -                            <MultiDataTrigger>
    5.69 -                                <MultiDataTrigger.Conditions>
    5.70 -                                    <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMouseOver}"
    5.71 +                            <Style.Triggers>
    5.72 +                                <MultiDataTrigger>
    5.73 +                                    <MultiDataTrigger.Conditions>
    5.74 +                                        <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMouseOver}"
    5.75                                                 Value="True" />
    5.76 -                                    <Condition Binding="{Binding Path=ActiveTab, Converter={StaticResource IsActiveTabToBool}, ConverterParameter=Trustwords}"
    5.77 +                                        <Condition Binding="{Binding Path=ActiveTab, Converter={StaticResource IsActiveTabToBool}, ConverterParameter=Trustwords}"
    5.78                                                 Value="False" />
    5.79 -                                </MultiDataTrigger.Conditions>
    5.80 -                                <Setter Property="Background"
    5.81 +                                    </MultiDataTrigger.Conditions>
    5.82 +                                    <Setter Property="Background"
    5.83                                          Value="AliceBlue" />
    5.84 -                                <Setter Property="BorderBrush"
    5.85 +                                    <Setter Property="BorderBrush"
    5.86                                          Value="LightSkyBlue" />
    5.87 -                            </MultiDataTrigger>
    5.88 -                        </Style.Triggers>
    5.89 -                    </Style>
    5.90 -                </Label.Style>
    5.91 -            </Label>
    5.92 -            <Label Name="TabControlFingerprint"
    5.93 +                                </MultiDataTrigger>
    5.94 +                            </Style.Triggers>
    5.95 +                        </Style>
    5.96 +                    </Label.Style>
    5.97 +                </Label>
    5.98 +                <Label Name="TabControlFingerprint"
    5.99                     MouseLeftButtonUp="TabControlFingerprint_MouseLeftButtonUp"
   5.100                     Content="{x:Static p:Resources.Handshake_FingerprintText}"
   5.101                     Visibility="{Binding Path=AreTabControlsVisible, Converter={StaticResource BoolToVisibility}}">
   5.102 -                <Label.Style>
   5.103 -                    <Style TargetType="Label">
   5.104 -                        <Setter Property="BorderBrush"
   5.105 +                    <Label.Style>
   5.106 +                        <Style TargetType="Label">
   5.107 +                            <Setter Property="BorderBrush"
   5.108                                  Value="LightGray" />
   5.109 -                        <Setter Property="Background"
   5.110 +                            <Setter Property="Background"
   5.111                                  Value="{Binding Path=ActiveTab, Converter={StaticResource IsActiveTabToBackground}, ConverterParameter=Fingerprint}" />
   5.112 -                        <Setter Property="BorderThickness"
   5.113 +                            <Setter Property="BorderThickness"
   5.114                                  Value="1" />
   5.115 -                        <Setter Property="Padding"
   5.116 +                            <Setter Property="Padding"
   5.117                                  Value="10,5" />
   5.118 -                        <Style.Triggers>
   5.119 -                            <MultiDataTrigger>
   5.120 -                                <MultiDataTrigger.Conditions>
   5.121 -                                    <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMouseOver}"
   5.122 +                            <Style.Triggers>
   5.123 +                                <MultiDataTrigger>
   5.124 +                                    <MultiDataTrigger.Conditions>
   5.125 +                                        <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMouseOver}"
   5.126                                                 Value="True" />
   5.127 -                                    <Condition Binding="{Binding Path=ActiveTab, Converter={StaticResource IsActiveTabToBool}, ConverterParameter=Fingerprint}"
   5.128 +                                        <Condition Binding="{Binding Path=ActiveTab, Converter={StaticResource IsActiveTabToBool}, ConverterParameter=Fingerprint}"
   5.129                                                 Value="False" />
   5.130 -                                </MultiDataTrigger.Conditions>
   5.131 -                                <Setter Property="Background"
   5.132 +                                    </MultiDataTrigger.Conditions>
   5.133 +                                    <Setter Property="Background"
   5.134                                          Value="AliceBlue" />
   5.135 -                                <Setter Property="BorderBrush"
   5.136 +                                    <Setter Property="BorderBrush"
   5.137                                          Value="LightSkyBlue" />
   5.138 -                            </MultiDataTrigger>
   5.139 -                        </Style.Triggers>
   5.140 -                    </Style>
   5.141 -                </Label.Style>
   5.142 -            </Label>
   5.143 +                                </MultiDataTrigger>
   5.144 +                            </Style.Triggers>
   5.145 +                        </Style>
   5.146 +                    </Label.Style>
   5.147 +                </Label>
   5.148  
   5.149 -            <!--Language selector-->
   5.150 -            <ComboBox Padding="10,2"
   5.151 +                <!--Language selector-->
   5.152 +                <ComboBox Padding="10,2"
   5.153                        VerticalContentAlignment="Center"
   5.154                        ItemsSource="{Binding Path=TrustwordsCultureList, Mode=OneWay}"
   5.155                        DisplayMemberPath="Value"
   5.156 @@ -164,62 +171,64 @@
   5.157                        SelectedValue="{Binding Path=TrustwordsCulture, Mode=TwoWay}"
   5.158                        IsEnabled="{Binding Path=ActiveTab, Converter={StaticResource IsActiveTabToBool}, ConverterParameter=Trustwords}"
   5.159                        Foreground="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, Converter={StaticResource IsEnabledToColor}}" />
   5.160 -        </StackPanel>
   5.161 +            </StackPanel>
   5.162  
   5.163 -        <!-- Trustwords -->
   5.164 -        <StackPanel Background="White"
   5.165 +            <!-- Trustwords -->
   5.166 +            <StackPanel Background="White"
   5.167                      Visibility="{Binding Path=ActiveTab, Converter={StaticResource IsActiveTabToVisibility}, ConverterParameter=Trustwords}">
   5.168 -            <TextBox Background="Transparent"
   5.169 +                <TextBox Background="Transparent"
   5.170                       BorderThickness="0"
   5.171                       Text="{Binding Path=TrustwordsShort}"
   5.172                       Visibility="{Binding Path=AreTrustwordsExpanded, Converter={StaticResource InvertBoolToVisibility}}"
   5.173                       IsReadOnly="True"
   5.174                       TextWrapping="Wrap" 
   5.175                       Padding="10"/>
   5.176 -            <TextBox Background="Transparent"
   5.177 +                <TextBox Background="Transparent"
   5.178                       BorderThickness="0"
   5.179                       Text="{Binding Path=TrustwordsFull}"
   5.180                       Visibility="{Binding Path=AreTrustwordsExpanded, Converter={StaticResource BoolToVisibility}}"
   5.181                       IsReadOnly="True"
   5.182                       TextWrapping="Wrap"
   5.183                       Padding="10" />
   5.184 -            <Expander ExpandDirection="Down"
   5.185 +                <Expander ExpandDirection="Down"
   5.186                        Margin="10,10,5,5"
   5.187                        ToolTip="{Binding Path=ExpanderToolTip, Mode=OneWay}"                     
   5.188                        Collapsed="ExpanderTrustwords_Toggled"
   5.189                        Expanded="ExpanderTrustwords_Toggled" />
   5.190 -        </StackPanel>
   5.191 +            </StackPanel>
   5.192  
   5.193 -        <!--Fingerprints-->
   5.194 -        <StackPanel Background="White"
   5.195 +            <!--Fingerprints-->
   5.196 +            <StackPanel Background="White"
   5.197                      Visibility="{Binding Path=ActiveTab, Converter={StaticResource IsActiveTabToVisibility}, ConverterParameter=Fingerprint}">
   5.198 -            <TextBlock Text="{Binding Path=UIDPartner}"
   5.199 +                <TextBlock Text="{Binding Path=UIDPartner}"
   5.200                         Margin="10,10,10,2" />
   5.201 -            <TextBlock Text="{Binding Path=FingerprintPartner}"
   5.202 +                <TextBlock Text="{Binding Path=FingerprintPartner}"
   5.203                         Margin="10,2,10,22" />
   5.204 -            <TextBlock Text="{Binding Path=UIDMyself}"
   5.205 +                <TextBlock Text="{Binding Path=UIDMyself}"
   5.206                         Margin="10,10,10,2" />
   5.207 -            <TextBlock Text="{Binding Path=FingerprintMyself}"
   5.208 +                <TextBlock Text="{Binding Path=FingerprintMyself}"
   5.209                         Margin="10,2,10,10" />
   5.210 -        </StackPanel>
   5.211 +            </StackPanel>
   5.212  
   5.213 -        <!-- Buttons -->
   5.214 -        <StackPanel Grid.Row="5"
   5.215 +            <!-- Buttons -->
   5.216 +            <StackPanel Grid.Row="5"
   5.217                      Orientation="Horizontal"
   5.218                      HorizontalAlignment="Right"
   5.219                      Margin="0,5,0,0"
   5.220                      Visibility="{Binding DialogType, Converter={StaticResource IsNotWizardModeToVisibility}}">
   5.221 -            <Button Style="{StaticResource StyleButtonWrong}"
   5.222 +                <Button Style="{StaticResource StyleButtonWrong}"
   5.223                      HorizontalAlignment="Center"
   5.224                      Margin="0,5,5,5"
   5.225                      Content="{Binding Path=ButtonWrongText, FallbackValue=Wrong}"
   5.226                      Command="{Binding ButtonWrongOnClick}"/>
   5.227 -            <Button Style="{StaticResource StyleButtonConfirm}"
   5.228 +                <Button Style="{StaticResource StyleButtonConfirm}"
   5.229                      HorizontalAlignment="Center"
   5.230                      Margin="5,5,0,5"
   5.231                      Content="{Binding Path=ButtonConfirmText, FallbackValue=Confirm}"
   5.232                      Command="{Binding ButtonConfirmOnClick}"
   5.233                      IsDefault="True"/>
   5.234 +            </StackPanel>
   5.235 +
   5.236          </StackPanel>
   5.237      </StackPanel>
   5.238