[GUI] Add device view.

This commit is contained in:
2025-11-19 15:15:58 +00:00
parent 7bee2d7473
commit c67197f977
8 changed files with 375 additions and 21 deletions

View File

@@ -32,9 +32,11 @@
using System;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net.Sockets;
using System.Threading.Tasks;
using System.Windows.Input;
using Aaru.Devices;
using Aaru.Devices.Remote;
using Aaru.Devices.Windows;
@@ -44,6 +46,7 @@ using Aaru.Localization;
using Aaru.Logging;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using JetBrains.Annotations;
using MsBox.Avalonia;
using MsBox.Avalonia.Base;
@@ -60,13 +63,41 @@ public partial class DeviceListViewModel : ViewModelBase
ObservableCollection<DeviceModel> _devices;
[ObservableProperty]
string _remotePath;
[ObservableProperty]
[CanBeNull]
DeviceModel _selectedDevice;
public DeviceListViewModel(DeviceList window) => _window = window;
public DeviceListViewModel(DeviceList window)
{
_window = window;
OpenDeviceCommand = new RelayCommand(OpenDevice);
}
public DeviceListViewModel(DeviceList window, [NotNull] string remotePath)
public DeviceListViewModel(DeviceList window, [JetBrains.Annotations.NotNull] string remotePath)
{
_window = window;
RemotePath = remotePath;
OpenDeviceCommand = new RelayCommand(OpenDevice);
}
public ICommand OpenDeviceCommand { get; }
[SuppressMessage("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator",
"MVVMTK0034:Direct field reference to [ObservableProperty] backing field",
Justification = "False positive, says it's always null, but it's not.")]
void OpenDevice()
{
if(_selectedDevice == null) return;
var deviceView = new DeviceView
{
Topmost = true
};
var vm = new DeviceViewModel(deviceView, _selectedDevice.Path);
deviceView.DataContext = vm;
deviceView.Show();
}
public void LoadData()

View File

@@ -0,0 +1,149 @@
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : DeviceViewModel.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : GUI view models.
//
// --[ Description ] ----------------------------------------------------------
//
// View model for device.
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General public License for more details.
//
// You should have received a copy of the GNU General public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2025 Natalia Portillo
// ****************************************************************************/
using System.Threading.Tasks;
using Aaru.CommonTypes.Enums;
using Aaru.Core;
using Aaru.Devices;
using Aaru.Gui.Views.Windows;
using Aaru.Localization;
using Aaru.Logging;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using Humanizer;
using MsBox.Avalonia;
using MsBox.Avalonia.Base;
using MsBox.Avalonia.Enums;
namespace Aaru.Gui.ViewModels.Windows;
public partial class DeviceViewModel : ViewModelBase
{
readonly DeviceView _window;
Device _dev;
[ObservableProperty]
string _devicePath;
[ObservableProperty]
string _deviceType;
[ObservableProperty]
string _manufacturer;
[ObservableProperty]
string _model;
[ObservableProperty]
bool _removableChecked;
[ObservableProperty]
string _revision;
[ObservableProperty]
string _scsiType;
[ObservableProperty]
string _serial;
[ObservableProperty]
string _statusMessage;
[ObservableProperty]
bool _usbConnected;
public DeviceViewModel(DeviceView window, string devicePath)
{
_window = window;
DevicePath = devicePath;
}
public void LoadData()
{
_ = Task.Run(Worker);
}
void Worker()
{
Dispatcher.UIThread.Invoke(() => StatusMessage = "Opening device...");
var dev = Device.Create(DevicePath, out ErrorNumber devErrno);
if(dev is null)
{
AaruLogging.Error(string.Format(UI.Could_not_open_device_error_0, devErrno));
Dispatcher.UIThread.Invoke(() =>
{
IMsBox<ButtonResult> msbox = MessageBoxManager.GetMessageBoxStandard(UI.Title_Error,
string.Format(UI.Could_not_open_device_error_0, devErrno),
ButtonEnum.Ok,
Icon.Error);
_ = msbox.ShowAsync();
_window.Close();
});
return;
}
if(dev.Error)
{
AaruLogging.Error(Error.Print(dev.LastError));
Dispatcher.UIThread.Invoke(() =>
{
IMsBox<ButtonResult> msbox = MessageBoxManager.GetMessageBoxStandard(UI.Title_Error,
Error.Print(dev.LastError),
ButtonEnum.Ok,
Icon.Error);
_ = msbox.ShowAsync();
_window.Close();
});
return;
}
Dispatcher.UIThread.Invoke(() =>
{
DeviceType = $"[rosybrown]{dev.Type.Humanize()}[/]";
Manufacturer = (dev.Manufacturer != null ? $"[blue]{dev.Manufacturer}[/]" : null)!;
Model = (dev.Model != null ? $"[purple]{dev.Model}[/]" : null)!;
Revision = (dev.FirmwareRevision != null ? $"[teal]{dev.FirmwareRevision}[/]" : null)!;
Serial = (dev.Serial != null ? $"[fuchsia]{dev.Serial}[/]" : null)!;
ScsiType = $"[orange]{dev.ScsiType.Humanize()}[/]";
RemovableChecked = dev.IsRemovable;
UsbConnected = dev.IsUsb;
StatusMessage = "Device opened successfully.";
});
_dev = dev;
}
public void Closed()
{
_dev?.Close();
}
}

View File

@@ -16,7 +16,7 @@
<Design.DataContext>
<windows:DeviceListViewModel />
</Design.DataContext>
<Grid RowDefinitions="Auto,*"
<Grid RowDefinitions="Auto,*, Auto"
RowSpacing="8"
Margin="12">
<Grid Grid.Row="0"
@@ -35,6 +35,7 @@
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalScrollBarVisibility="Visible"
SelectedItem="{Binding SelectedDevice, Mode=TwoWay}"
ColumnHeaderHeight="32">
<DataGrid.Styles>
<Style Selector="DataGridCell">
@@ -123,5 +124,13 @@
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<StackPanel Grid.Row="2"
Orientation="Horizontal"
HorizontalAlignment="Right"
Spacing="8">
<Button Command="{Binding OpenDeviceCommand}">
<TextBlock Text="Open device" />
</Button>
</StackPanel>
</Grid>
</Window>

View File

@@ -0,0 +1,92 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:windows="clr-namespace:Aaru.Gui.ViewModels.Windows"
xmlns:controls="clr-namespace:Aaru.Gui.Controls"
xmlns:localization="clr-namespace:Aaru.Localization;assembly=Aaru.Localization"
mc:Ignorable="d"
d:DesignWidth="800"
d:DesignHeight="450"
Height="480"
Width="640"
x:Class="Aaru.Gui.Views.Windows.DeviceView"
x:DataType="windows:DeviceViewModel"
Title="DeviceView">
<Grid RowDefinitions="Auto,*, Auto"
RowSpacing="8"
Margin="12">
<StackPanel Grid.Row="0"
Orientation="Vertical"
Spacing="8">
<Grid ColumnDefinitions="Auto, *"
ColumnSpacing="8"
IsVisible="{Binding DevicePath, Converter={x:Static StringConverters.IsNotNullOrEmpty}, Mode=OneWay}">
<controls:SpectreTextBlock Grid.Column="0"
Text="{x:Static localization:UI.Title_Device_path}" />
<TextBlock Grid.Column="1"
Foreground="Green"
Text="{Binding DevicePath, Mode=OneWay}" />
</Grid>
<Grid ColumnDefinitions="Auto, *"
ColumnSpacing="8"
IsVisible="{Binding DeviceType, Converter={x:Static StringConverters.IsNotNullOrEmpty}, Mode=OneWay}">
<controls:SpectreTextBlock Grid.Column="0"
Text="{x:Static localization:UI.Title_Device_type}" />
<controls:SpectreTextBlock Grid.Column="1"
Text="{Binding DeviceType}" />
</Grid>
<Grid ColumnDefinitions="Auto, *"
ColumnSpacing="8"
IsVisible="{Binding Manufacturer, Converter={x:Static StringConverters.IsNotNullOrEmpty}, Mode=OneWay}">
<controls:SpectreTextBlock Grid.Column="0"
Text="{x:Static localization:UI.Title_Manufacturer}" />
<controls:SpectreTextBlock Grid.Column="1"
Text="{Binding Manufacturer}" />
</Grid>
<Grid ColumnDefinitions="Auto, *"
ColumnSpacing="8"
IsVisible="{Binding Model, Converter={x:Static StringConverters.IsNotNullOrEmpty}, Mode=OneWay}">
<controls:SpectreTextBlock Grid.Column="0"
Text="{x:Static localization:UI.Title_Model}" />
<controls:SpectreTextBlock Grid.Column="1"
Text="{Binding Model}" />
</Grid>
<Grid ColumnDefinitions="Auto, *"
ColumnSpacing="8"
IsVisible="{Binding Revision, Converter={x:Static StringConverters.IsNotNullOrEmpty}, Mode=OneWay}">
<controls:SpectreTextBlock Grid.Column="0"
Text="{x:Static localization:UI.Title_Revision}" />
<controls:SpectreTextBlock Grid.Column="1"
Text="{Binding Revision}" />
</Grid>
<Grid ColumnDefinitions="Auto, *"
ColumnSpacing="8"
IsVisible="{Binding Serial, Converter={x:Static StringConverters.IsNotNullOrEmpty}, Mode=OneWay}">
<controls:SpectreTextBlock Grid.Column="0"
Text="{x:Static localization:UI.Title_Serial_number}" />
<controls:SpectreTextBlock Grid.Column="1"
Text="{Binding Serial}" />
</Grid>
<Grid ColumnDefinitions="Auto, *"
ColumnSpacing="8"
IsVisible="{Binding ScsiType, Converter={x:Static StringConverters.IsNotNullOrEmpty}, Mode=OneWay}">
<controls:SpectreTextBlock Grid.Column="0"
Text="{x:Static localization:UI.Title_Peripheral_device_type}" />
<controls:SpectreTextBlock Grid.Column="1"
Text="{Binding ScsiType}" />
</Grid>
<CheckBox IsChecked="{Binding RemovableChecked}"
IsEnabled="False">
<controls:SpectreTextBlock Text="{x:Static localization:UI.Title_Removable_media}" />
</CheckBox>
<CheckBox IsChecked="{Binding UsbConnected}"
IsEnabled="False">
<controls:SpectreTextBlock Text="{x:Static localization:UI.Title_Connected_by_USB}" />
</CheckBox>
</StackPanel>
<Panel Grid.Row="1" />
<TextBox Grid.Row="2"
Text="{Binding StatusMessage, Mode=OneWay}" />
</Grid>
</Window>

View File

@@ -0,0 +1,61 @@
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : DeviceView.axaml.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : GUI views.
//
// --[ Description ] ----------------------------------------------------------
//
// View for device.
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General public License for more details.
//
// You should have received a copy of the GNU General public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2025 Natalia Portillo
// ****************************************************************************/
using System;
using Aaru.Gui.ViewModels.Windows;
using Avalonia;
using Avalonia.Controls;
namespace Aaru.Gui.Views.Windows;
public class DeviceView : Window
{
public DeviceView()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
}
/// <inheritdoc />
protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);
if(DataContext is DeviceViewModel vm)
{
Closed += (_, _) => vm?.Closed();
vm?.LoadData();
}
}
}

View File

@@ -6525,5 +6525,11 @@ namespace Aaru.Localization {
return ResourceManager.GetString("Unknown_network_error", resourceCulture);
}
}
public static string Title_Device_path {
get {
return ResourceManager.GetString("Title_Device_path", resourceCulture);
}
}
}
}

View File

@@ -2193,7 +2193,7 @@ Probadores:
<value>Comentarios</value>
</data>
<data name="Title_Connected_by_USB" xml:space="preserve">
<value>Conectado por USB</value>
<value>[bold][slateblue1]Conectado por USB[/][/]</value>
</data>
<data name="Title_Console" xml:space="preserve">
<value>Consola</value>
@@ -2235,7 +2235,7 @@ Probadores:
<value>Información del dispositivo</value>
</data>
<data name="Title_Device_type" xml:space="preserve">
<value>Tipo del dispositivo</value>
<value>[bold][slateblue1]Tipo del dispositivo[/][/]</value>
</data>
<data name="Title_Disc_Manufacturing_Information" xml:space="preserve">
<value>Información del fabricante del disco</value>
@@ -2427,7 +2427,7 @@ Probadores:
<value>Registro</value>
</data>
<data name="Title_Manufacturer" xml:space="preserve">
<value>[bold][blue]Fabricante[/][/]</value>
<value>[bold][slateblue1]Fabricante[/][/]</value>
</data>
<data name="Title_Media" xml:space="preserve">
<value>[bold][green]Medio[/][/]</value>
@@ -2487,7 +2487,7 @@ Probadores:
<value>[bold][purple_2]Modo[/][/]</value>
</data>
<data name="Title_Model" xml:space="preserve">
<value>[bold][purple]Modelo[/][/]</value>
<value>[bold][slateblue1]Modelo[/][/]</value>
</data>
<data name="Title_Model_ID" xml:space="preserve">
<value>[bold][slateblue1]ID de modelo[/][/]</value>
@@ -2535,7 +2535,7 @@ Probadores:
<value>[bold][blue]Dispositivo PCMCIA[/][/]</value>
</data>
<data name="Title_Peripheral_device_type" xml:space="preserve">
<value>Tipo de periférico del dispositivo</value>
<value>[bold][slateblue1]Tipo de periférico del dispositivo[/][/]</value>
</data>
<data name="Title_Plextor" xml:space="preserve">
<value>Plextor</value>
@@ -2559,13 +2559,13 @@ Probadores:
<value>[bold][slateblue1]Etiquetas de sector legibles[/][/]</value>
</data>
<data name="Title_Removable_media" xml:space="preserve">
<value>Medio extraíble</value>
<value>[bold][slateblue1]Medio extraíble[/][/]</value>
</data>
<data name="Title_Reports" xml:space="preserve">
<value>Reportes</value>
</data>
<data name="Title_Revision" xml:space="preserve">
<value>[bold][teal]Revisión[/][/]</value>
<value>[bold][slateblue1]Revisión[/][/]</value>
</data>
<data name="Title_Scheme" xml:space="preserve">
<value>[bold][purple]Esquema[/][/]</value>
@@ -2604,7 +2604,7 @@ Probadores:
<value>Sector de Seguridad</value>
</data>
<data name="Title_Serial_number" xml:space="preserve">
<value>[bold][fuchsia]Número de serie[/][/]</value>
<value>[bold][slateblue1]Número de serie[/][/]</value>
</data>
<data name="Title_Sessions" xml:space="preserve">
<value>Sesiones</value>
@@ -3263,4 +3263,7 @@ Probadores:
<data name="Unknown_network_error" xml:space="preserve">
<value>Error de red desconocido.</value>
</data>
<data name="Title_Device_path" xml:space="preserve">
<value>[bold][slateblue1]Ruta al dispositivo[/][/]</value>
</data>
</root>

View File

@@ -186,13 +186,13 @@
<value>[bold][blue]Device statistics[/][/]</value>
</data>
<data name="Title_Manufacturer" xml:space="preserve">
<value>[bold][blue]Manufacturer[/][/]</value>
<value>[bold][slateblue1]Manufacturer[/][/]</value>
</data>
<data name="Title_Model" xml:space="preserve">
<value>[bold][purple]Model[/][/]</value>
<value>[bold][slateblue1]Model[/][/]</value>
</data>
<data name="Title_Revision" xml:space="preserve">
<value>[bold][teal]Revision[/][/]</value>
<value>[bold][slateblue1]Revision[/][/]</value>
</data>
<data name="Title_Bus" xml:space="preserve">
<value>[bold][rosybrown]Bus[/][/]</value>
@@ -1933,16 +1933,16 @@ Testers:
<value>USB</value>
</data>
<data name="Title_Connected_by_USB" xml:space="preserve">
<value>Connected by USB</value>
<value>[bold][slateblue1]Connected by USB[/][/]</value>
</data>
<data name="Title_Removable_media" xml:space="preserve">
<value>Removable media</value>
<value>[bold][slateblue1]Removable media[/][/]</value>
</data>
<data name="Title_Peripheral_device_type" xml:space="preserve">
<value>Peripheral device type</value>
<value>[bold][slateblue1]Peripheral device type[/][/]</value>
</data>
<data name="Title_Device_type" xml:space="preserve">
<value>Device type</value>
<value>[bold][slateblue1]Device type[/][/]</value>
</data>
<data name="Title_General" xml:space="preserve">
<value>General</value>
@@ -3338,4 +3338,7 @@ Do you want to continue?</value>
<data name="Unknown_network_error" xml:space="preserve">
<value>Unknown network error.</value>
</data>
<data name="Title_Device_path" xml:space="preserve">
<value>[bold][slateblue1]Device path[/][/]</value>
</data>
</root>