Skip to content

Commit

Permalink
Add secret fragment export to QR Code
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxhy committed Oct 25, 2023
1 parent 9bf31aa commit 917408c
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Win32;
using Net.Codecrete.QrCodeGenerator;
using System.Windows.Controls;

namespace Leosac.KeyManager.Library.UI.Domain
Expand All @@ -12,6 +13,10 @@ public KeyCeremonyFragmentControlViewModel()
_fragmentValue = string.Empty;
BrowseCommand = new RelayCommand(Browse);
PrintCommand = new RelayCommand(Print);
GenerateQrCodeCommand = new RelayCommand(() => {
GenerateQrCode();
MaterialDesignThemes.Wpf.Flipper.FlipCommand.Execute(null, null);
});
}

private int _fragment;
Expand All @@ -35,6 +40,21 @@ public bool IsReunification
set => SetProperty(ref _isReunification, value);
}

private byte[]? _qrCode;
public byte[]? QrCode
{
get => _qrCode;
set => SetProperty(ref _qrCode, value);
}

public RelayCommand GenerateQrCodeCommand { get; }

public void GenerateQrCode()
{
var qr = Net.Codecrete.QrCodeGenerator.QrCode.EncodeText(FragmentValue, Net.Codecrete.QrCodeGenerator.QrCode.Ecc.Medium);
QrCode = qr.ToPng(10, 4);
}

public RelayCommand BrowseCommand { get; }

public void Browse()
Expand Down
5 changes: 1 addition & 4 deletions KeyManager.Library.UI/FavoriteKeyStoreSelectionControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
xmlns:properties="clr-namespace:Leosac.KeyManager.Library.UI.Properties"
mc:Ignorable="d"
d:DesignHeight="120" d:DesignWidth="500">
<UserControl.Resources>
<materialDesign:BooleanToVisibilityConverter x:Key="ReverseBoolToVisibleConverter" TrueValue="Collapsed" FalseValue="Visible" />
</UserControl.Resources>
<StackPanel>
<materialDesign:DialogHost DialogTheme="Inherit"
Identifier="FavSelectionDialog">
Expand All @@ -38,6 +35,6 @@
Style="{StaticResource MaterialDesignFloatingHintRevealPasswordBox}"
materialDesign:PasswordBoxAssist.Password="{Binding SelectedKeyStoreFavorite.Properties.Secret,ElementName=userControl}"
MaxLength="{Binding SelectedKeyStoreFavorite.Properties.SecretMaxLength, ElementName=userControl, Mode=OneWay}"
Visibility="{Binding SelectedKeyStoreFavorite.Properties.StoreSecret, ElementName=userControl, Converter={StaticResource ReverseBoolToVisibleConverter}}"/>
Visibility="{Binding SelectedKeyStoreFavorite.Properties.StoreSecret, ElementName=userControl, Converter={StaticResource InverseBooleanToVisibilityConverter}}"/>
</StackPanel>
</UserControl>
4 changes: 2 additions & 2 deletions KeyManager.Library.UI/KeyCeremonyDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
mc:Ignorable="d"
Title="{x:Static properties:Resources.KeyCeremony}"
d:DataContext="{d:DesignInstance domain:KeyCeremonyDialogViewModel}"
d:DesignHeight="450" d:DesignWidth="800"
Height="450" Width="800"
d:DesignHeight="550" d:DesignWidth="800"
Height="550" Width="800"
DataContextChanged="UserControl_DataContextChanged"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
Background="{DynamicResource MaterialDesignPaper}"
Expand Down
22 changes: 20 additions & 2 deletions KeyManager.Library.UI/KeyCeremonyFragmentControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:local="clr-namespace:Leosac.KeyManager.Library.UI"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:properties="clr-namespace:Leosac.KeyManager.Library.UI.Properties"
xmlns:wpfappdomain="clr-namespace:Leosac.WpfApp.Domain;assembly=WpfApp"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance domain:KeyCeremonyFragmentControlViewModel}"
d:DesignHeight="300" d:DesignWidth="500">
Expand All @@ -15,7 +16,6 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Flipper.xaml" />
</ResourceDictionary.MergedDictionaries>
<materialDesign:BooleanToVisibilityConverter x:Key="ReverseBoolToVisibleConverter" TrueValue="Collapsed" FalseValue="Visible" />
</ResourceDictionary>
</UserControl.Resources>
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
Expand Down Expand Up @@ -64,7 +64,7 @@
</DockPanel>
</materialDesign:Flipper.BackContent>
</materialDesign:Flipper>
<materialDesign:Flipper Style="{StaticResource MaterialDesignCardFlipper}" Visibility="{Binding IsReunification, Converter={StaticResource ReverseBoolToVisibleConverter}}" Margin="3">
<materialDesign:Flipper Style="{StaticResource MaterialDesignCardFlipper}" Visibility="{Binding IsReunification, Converter={StaticResource InverseBooleanToVisibilityConverter}}" Margin="3">
<materialDesign:Flipper.FrontContent>
<Button Width="200" MinHeight="100" Margin="8" Command="{x:Static materialDesign:Flipper.FlipCommand}" Style="{StaticResource MaterialDesignFlatButton}">
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
Expand All @@ -82,6 +82,24 @@
</DockPanel>
</materialDesign:Flipper.BackContent>
</materialDesign:Flipper>
<materialDesign:Flipper Style="{StaticResource MaterialDesignCardFlipper}" Visibility="{Binding IsReunification, Converter={StaticResource InverseBooleanToVisibilityConverter}}" Margin="3">
<materialDesign:Flipper.FrontContent>
<Button Width="200" MinHeight="100" Margin="8" Style="{StaticResource MaterialDesignFlatButton}" Command="{Binding GenerateQrCodeCommand}">
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
<materialDesign:PackIcon Kind="Qrcode" Width="64" Height="64" HorizontalAlignment="Center" />
<TextBlock Text="{x:Static properties:Resources.QrCode}" HorizontalAlignment="Center" />
</StackPanel>
</Button>
</materialDesign:Flipper.FrontContent>
<materialDesign:Flipper.BackContent>
<DockPanel LastChildFill="True" Width="200" MinHeight="100" Margin="8">
<Button DockPanel.Dock="Bottom" Width="184" Margin="5" Command="{x:Static materialDesign:Flipper.FlipCommand}" Content="Back" Style="{StaticResource MaterialDesignFlatButton}" />
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
<Image Source="{Binding QrCode}" Width="128" Height="128" Margin="8" />
</StackPanel>
</DockPanel>
</materialDesign:Flipper.BackContent>
</materialDesign:Flipper>
</WrapPanel>
<Button Margin="48"
Command="{x:Static materialDesign:Transitioner.MoveNextCommand}"
Expand Down
9 changes: 9 additions & 0 deletions KeyManager.Library.UI/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions KeyManager.Library.UI/Properties/Resources.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@
<data name="PublishKeyStore" xml:space="preserve">
<value>Publier vers un autre magasin de clés</value>
</data>
<data name="QrCode" xml:space="preserve">
<value>Qr Code</value>
</data>
<data name="Random" xml:space="preserve">
<value>Aléatoire</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions KeyManager.Library.UI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@
<data name="PublishKeyStore" xml:space="preserve">
<value>Publish to another Key Store</value>
</data>
<data name="QrCode" xml:space="preserve">
<value>Qr Code</value>
</data>
<data name="Random" xml:space="preserve">
<value>Random</value>
</data>
Expand Down
3 changes: 1 addition & 2 deletions KeyManager/FavoritesControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
Loaded="userControl_Loaded"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<materialDesign:BooleanToVisibilityConverter x:Key="ReverseBoolToVisibleConverter" TrueValue="Collapsed" FalseValue="Visible" />
<CollectionViewSource x:Key='Favorites' Source="{Binding Favorites.KeyStores}">
<CollectionViewSource.SortDescriptions>
<componentModel:SortDescription PropertyName="Name" />
Expand Down Expand Up @@ -61,7 +60,7 @@
Style="{StaticResource MaterialDesignFloatingHintRevealPasswordBox}"
materialDesign:PasswordBoxAssist.Password="{Binding Properties.Secret, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
MaxLength="{Binding Properties.SecretMaxLength, Mode=OneWay}"
Visibility="{Binding Properties.StoreSecret, Converter={StaticResource ReverseBoolToVisibleConverter}}"/>
Visibility="{Binding Properties.StoreSecret, Converter={StaticResource InverseBooleanToVisibilityConverter}}"/>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
<Button Margin="0,8,8,0" CommandParameter="{Binding}" Command="{Binding DataContext.OpenFavoriteCommand, ElementName=userControl}" Content="{x:Static properties:Resources.OK}" IsDefault="True" Style="{StaticResource MaterialDesignFlatButton}" />
<Button Margin="0,8,8,0" Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" Content="{x:Static properties:Resources.Cancel}" IsCancel="True" Style="{StaticResource MaterialDesignFlatButton}" />
Expand Down

0 comments on commit 917408c

Please sign in to comment.