Skip to content

Commit 20c0fcb

Browse files
committed
Added WiFi profiles section (#671)
1 parent ecbba3b commit 20c0fcb

File tree

6 files changed

+353
-1
lines changed

6 files changed

+353
-1
lines changed

InternetTest/InternetTest/Components/GridItem.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
FontFamily="..\Fonts\#Hauora"
1111
Foreground="{DynamicResource Foreground1}"
1212
mc:Ignorable="d">
13-
<StackPanel Margin="0 5">
13+
<StackPanel Margin="5">
1414
<TextBlock
1515
FontSize="12"
1616
Foreground="{DynamicResource DarkGray}"
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<UserControl
2+
x:Class="InternetTest.Components.WlanProfileItem"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:converters="clr-namespace:InternetTest.Converters"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:lang="clr-namespace:InternetTest.Properties"
8+
xmlns:local="clr-namespace:InternetTest.Components"
9+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
10+
xmlns:vm="clr-namespace:InternetTest.ViewModels.Components"
11+
d:DesignHeight="450"
12+
d:DesignWidth="800"
13+
FontFamily="..\Fonts\#Hauora"
14+
Foreground="{DynamicResource Foreground1}"
15+
mc:Ignorable="d">
16+
<Border
17+
Margin="5"
18+
Padding="5"
19+
Background="{DynamicResource CardBackground}"
20+
BorderBrush="{DynamicResource Border}"
21+
BorderThickness="1"
22+
CornerRadius="5">
23+
<Grid>
24+
<Grid.Resources>
25+
<BooleanToVisibilityConverter x:Key="BoolToVis" />
26+
<converters:BoolToStringConverter x:Key="BoolToString" />
27+
</Grid.Resources>
28+
<Grid.ColumnDefinitions>
29+
<ColumnDefinition Width="Auto" />
30+
<ColumnDefinition />
31+
<ColumnDefinition Width="Auto" />
32+
</Grid.ColumnDefinitions>
33+
<Grid.RowDefinitions>
34+
<RowDefinition Height="Auto" />
35+
<RowDefinition Height="Auto" />
36+
<RowDefinition Height="Auto" />
37+
</Grid.RowDefinitions>
38+
<TextBlock
39+
x:Name="Icon"
40+
Margin="5 0"
41+
VerticalAlignment="Center"
42+
FontFamily="../Fonts/#FluentSystemIcons-Regular"
43+
FontSize="24"
44+
Foreground="{DynamicResource Accent}"
45+
Text="&#xF8AC;" />
46+
<TextBlock
47+
Grid.Column="1"
48+
VerticalAlignment="Center"
49+
d:Text="WiFi Name"
50+
FontWeight="Bold"
51+
Text="{Binding Name}" />
52+
<StackPanel Grid.Column="2" Orientation="Horizontal">
53+
<Button
54+
Margin="5 0"
55+
Background="Transparent"
56+
Command="{Binding QrCodeCommand}"
57+
Content="&#xF635;"
58+
Cursor="Hand"
59+
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
60+
Foreground="{DynamicResource Foreground1}">
61+
<Button.ToolTip>
62+
<ToolTip Content="{x:Static lang:Resources.ShareWithQrCode}" />
63+
</Button.ToolTip>
64+
</Button>
65+
<Button
66+
Margin="5 0"
67+
Background="Transparent"
68+
Command="{Binding CopyCommand}"
69+
Content="&#xF32C;"
70+
Cursor="Hand"
71+
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
72+
Foreground="{DynamicResource Foreground1}">
73+
<Button.ToolTip>
74+
<ToolTip Content="{x:Static lang:Resources.Copy}" />
75+
</Button.ToolTip>
76+
</Button>
77+
<ToggleButton
78+
x:Name="ExpandBtn"
79+
Margin="5 0"
80+
Background="Transparent"
81+
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
82+
Foreground="{DynamicResource Foreground1}"
83+
Style="{DynamicResource ExpanderChevronButton}" />
84+
</StackPanel>
85+
<ItemsControl
86+
Grid.Row="1"
87+
Grid.ColumnSpan="5"
88+
ItemsSource="{Binding Details}"
89+
Visibility="{Binding ElementName=ExpandBtn, Path=IsChecked, Converter={StaticResource BoolToVis}}">
90+
<ItemsControl.ItemsPanel>
91+
<ItemsPanelTemplate>
92+
<Grid>
93+
<Grid.ColumnDefinitions>
94+
<ColumnDefinition />
95+
<ColumnDefinition />
96+
</Grid.ColumnDefinitions>
97+
<Grid.RowDefinitions>
98+
<RowDefinition Height="Auto" />
99+
<RowDefinition Height="Auto" />
100+
</Grid.RowDefinitions>
101+
</Grid>
102+
</ItemsPanelTemplate>
103+
</ItemsControl.ItemsPanel>
104+
<ItemsControl.ItemContainerStyle>
105+
<Style TargetType="ContentPresenter">
106+
<Setter Property="Grid.Row" Value="{Binding GridRow}" />
107+
<Setter Property="Grid.Column" Value="{Binding GridColumn}" />
108+
</Style>
109+
</ItemsControl.ItemContainerStyle>
110+
<ItemsControl.ItemTemplate>
111+
<DataTemplate DataType="{x:Type vm:GridItemViewModel}">
112+
<local:GridItem />
113+
</DataTemplate>
114+
</ItemsControl.ItemTemplate>
115+
</ItemsControl>
116+
<StackPanel
117+
Grid.Row="2"
118+
Grid.ColumnSpan="3"
119+
Margin="5"
120+
Visibility="{Binding ElementName=ExpandBtn, Path=IsChecked, Converter={StaticResource BoolToVis}}">
121+
<TextBlock
122+
FontSize="12"
123+
Foreground="{DynamicResource DarkGray}"
124+
Text="{x:Static lang:Resources.Key}" />
125+
<StackPanel Orientation="Horizontal">
126+
<TextBlock
127+
FontSize="14"
128+
FontWeight="SemiBold"
129+
Text="{Binding Key}" />
130+
<ToggleButton
131+
Margin="5 0"
132+
Background="Transparent"
133+
Content="{Binding KeyVisible, Converter={StaticResource BoolToString}, Mode=TwoWay, ConverterParameter='&#xF3F8;,&#xF3FC;'}"
134+
Cursor="Hand"
135+
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
136+
Foreground="{DynamicResource Foreground1}"
137+
IsChecked="{Binding KeyVisible}">
138+
<ToggleButton.ToolTip>
139+
<ToolTip Content="{x:Static lang:Resources.ShowHideKey}" />
140+
</ToggleButton.ToolTip>
141+
</ToggleButton>
142+
<Button
143+
Margin="5 0"
144+
Background="Transparent"
145+
Command="{Binding CopyKeyCommand}"
146+
Content="&#xF32C;"
147+
Cursor="Hand"
148+
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
149+
Foreground="{DynamicResource Foreground1}">
150+
<Button.ToolTip>
151+
<ToolTip Content="{x:Static lang:Resources.Copy}" />
152+
</Button.ToolTip>
153+
</Button>
154+
</StackPanel>
155+
</StackPanel>
156+
</Grid>
157+
</Border>
158+
</UserControl>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) Léo Corporation
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
using System.Windows.Controls;
25+
26+
namespace InternetTest.Components;
27+
/// <summary>
28+
/// Interaction logic for WlanProfileItem.xaml
29+
/// </summary>
30+
public partial class WlanProfileItem : UserControl
31+
{
32+
public WlanProfileItem()
33+
{
34+
InitializeComponent();
35+
}
36+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) Léo Corporation
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
using InternetTest.Commands;
25+
using InternetTest.Models;
26+
using System.Collections.ObjectModel;
27+
using System.Windows;
28+
using System.Windows.Input;
29+
30+
namespace InternetTest.ViewModels.Components;
31+
public class WlanProfileItemViewModel : ViewModelBase
32+
{
33+
private readonly WlanProfile _wlanProfile;
34+
35+
public ObservableCollection<GridItemViewModel> Details { get; }
36+
37+
private string _name = string.Empty;
38+
public string Name { get => _name; set { _name = value; OnPropertyChanged(nameof(Name)); } }
39+
40+
private string _key = string.Empty;
41+
public string Key { get => _key; set { _key = value; OnPropertyChanged(nameof(Key)); } }
42+
43+
private bool _keyVisible;
44+
public bool KeyVisible
45+
{
46+
get => _keyVisible;
47+
set
48+
{
49+
_keyVisible = value;
50+
Key = !value ? new string('*', _wlanProfile.MSM?.Security?.SharedKey?.KeyMaterial?.Length ?? 0) : _wlanProfile.MSM?.Security?.SharedKey?.KeyMaterial ?? Properties.Resources.Unknown;
51+
OnPropertyChanged(nameof(KeyVisible));
52+
}
53+
}
54+
55+
public ICommand CopyCommand => new RelayCommand(o =>
56+
{
57+
Clipboard.SetDataObject(_wlanProfile.ToString());
58+
});
59+
60+
public ICommand CopyKeyCommand => new RelayCommand(o =>
61+
{
62+
Clipboard.SetDataObject(_wlanProfile.MSM?.Security?.SharedKey?.KeyMaterial ?? Properties.Resources.Unknown);
63+
});
64+
65+
public WlanProfileItemViewModel(WlanProfile wlanProfile)
66+
{
67+
_wlanProfile = wlanProfile;
68+
69+
Name = _wlanProfile.Name ?? Properties.Resources.Unknown;
70+
KeyVisible = false;
71+
72+
Details = [
73+
new (Properties.Resources.Authentication, _wlanProfile.MSM?.Security?.AuthEncryption?.Authentication switch
74+
{
75+
"open" => Properties.Resources.OpenNetwork,
76+
"shared" => Properties.Resources.SharedNetwork,
77+
"WPA" => Properties.Resources.WPANetwork,
78+
"WPAPSK" => Properties.Resources.WPAPSKNetwork,
79+
"WPA2" => Properties.Resources.WPA2Network,
80+
"WPA2PSK" => Properties.Resources.WPA2PSKNetwork,
81+
_ => _wlanProfile.MSM?.Security?.AuthEncryption?.Authentication
82+
} ?? Properties.Resources.Unknown, 0, 0),
83+
new(Properties.Resources.Encryption, _wlanProfile.MSM?.Security?.AuthEncryption?.Encryption ?? Properties.Resources.Unknown, 1, 0),
84+
new(Properties.Resources.ConnectionMode, _wlanProfile.ConnectionMode switch
85+
{
86+
"auto" => Properties.Resources.Automatic,
87+
"manual" => Properties.Resources.Manual,
88+
_ => _wlanProfile.ConnectionMode
89+
} ?? Properties.Resources.Unknown, 0, 1),
90+
new(Properties.Resources.ConnectionType, _wlanProfile.ConnectionType switch
91+
{
92+
"ESS" => Properties.Resources.InfrastructureNetwork,
93+
"IBSS" => Properties.Resources.AdHocNetwork,
94+
_ => _wlanProfile.ConnectionType
95+
} ?? Properties.Resources.Unknown, 1, 1)
96+
];
97+
}
98+
}

InternetTest/InternetTest/ViewModels/WiFiPageViewModel.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public ObservableCollection<NetworkAdapterItemViewModel> Adapters
4343
}
4444

4545
public ObservableCollection<ConnectWiFiItemViewModel> WiFiNetworks { get; set; } = [];
46+
public ObservableCollection<WlanProfileItemViewModel> WlanProfiles { get; set; } = [];
4647

4748
private bool _showHidden = false;
4849
public bool ShowHidden { get => _showHidden; set { _showHidden = value; OnPropertyChanged(nameof(ShowHidden)); GetAdapters(); } }
@@ -67,6 +68,8 @@ public WiFiPageViewModel(Settings settings)
6768
WiFiNetworks = [.. WiFiNetwork.GetWiFis().Select(x => new ConnectWiFiItemViewModel(x, currentSsid))];
6869
NoNetworks = WiFiNetworks.Count == 0;
6970

71+
RefreshProfiles();
72+
7073
RefreshWiFiCommand = new RelayCommand(o =>
7174
{
7275
IsRefreshing = true;
@@ -98,4 +101,11 @@ internal void GetAdapters()
98101
MessageBox.Show(ex.Message, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
99102
}
100103
}
104+
105+
private async void RefreshProfiles()
106+
{
107+
var profiles = await WlanProfile.GetProfilesAsync();
108+
WlanProfiles.Clear();
109+
profiles.ForEach(x => WlanProfiles.Add(new WlanProfileItemViewModel(x)));
110+
}
101111
}

InternetTest/InternetTest/Views/WiFiPage.xaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,56 @@
9797
<RowDefinition Height="Auto" />
9898
</Grid.RowDefinitions>
9999
<Border
100+
Margin="10"
101+
Padding="10"
102+
Background="{DynamicResource CardBackground}"
103+
BorderBrush="{DynamicResource Border}"
104+
BorderThickness="1"
105+
CornerRadius="10">
106+
<Grid>
107+
<Grid.RowDefinitions>
108+
<RowDefinition Height="Auto" />
109+
<RowDefinition />
110+
</Grid.RowDefinitions>
111+
<Grid.ColumnDefinitions>
112+
<ColumnDefinition />
113+
<ColumnDefinition Width="Auto" />
114+
</Grid.ColumnDefinitions>
115+
<StackPanel>
116+
<StackPanel Orientation="Horizontal">
117+
<TextBlock
118+
VerticalAlignment="Center"
119+
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
120+
FontSize="16"
121+
Text="&#xF8B4;" />
122+
<TextBlock
123+
Margin="5 0 0 0"
124+
VerticalAlignment="Center"
125+
FontSize="14"
126+
FontWeight="Bold"
127+
Text="{x:Static lang:Resources.WifiPasswords}" />
128+
</StackPanel>
129+
<TextBlock Foreground="{DynamicResource DarkGray}" Text="{x:Static lang:Resources.WiFiPasswordsDesc}" />
130+
</StackPanel>
131+
<ItemsControl
132+
Grid.Row="1"
133+
Grid.ColumnSpan="2"
134+
ItemsSource="{Binding WlanProfiles}">
135+
<ItemsControl.ItemsPanel>
136+
<ItemsPanelTemplate>
137+
<StackPanel />
138+
</ItemsPanelTemplate>
139+
</ItemsControl.ItemsPanel>
140+
<ItemsControl.ItemTemplate>
141+
<DataTemplate DataType="{x:Type vm:WlanProfileItemViewModel}">
142+
<components:WlanProfileItem />
143+
</DataTemplate>
144+
</ItemsControl.ItemTemplate>
145+
</ItemsControl>
146+
</Grid>
147+
</Border>
148+
<Border
149+
Grid.Row="1"
100150
Margin="10"
101151
Padding="10"
102152
Background="{DynamicResource CardBackground}"

0 commit comments

Comments
 (0)