/*
* ThreadPilot - Advanced Windows Process and Power Plan Manager
* Copyright (C) 2025 Prime Build
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3 only.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using ThreadPilot.Services;
using ThreadPilot.ViewModels;
namespace ThreadPilot.Views
{
///
/// Interaction logic for LogViewerView.xaml
///
public partial class LogViewerView : System.Windows.Controls.UserControl
{
public LogViewerView()
{
InitializeComponent();
Loaded += OnLoaded;
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
TaskSafety.FireAndForget(OnLoadedAsync(), _ =>
{
// Keep the view loaded even if background initialization fails.
});
}
private async Task OnLoadedAsync()
{
if (DataContext is LogViewerViewModel viewModel)
{
await viewModel.InitializeAsync();
}
}
}
///
/// Converter to convert bytes to megabytes for display
///
public class BytesToMegabytesConverter : IValueConverter
{
public static readonly BytesToMegabytesConverter Instance = new();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is long bytes)
{
return bytes / (1024.0 * 1024.0);
}
return 0.0;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
///
/// Converter to invert boolean values
///
public class InverseBooleanConverter : IValueConverter
{
public static readonly InverseBooleanConverter Instance = new();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
return !boolValue;
}
return true;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
return !boolValue;
}
return false;
}
}
///
/// Converter to invert boolean values for visibility
///
public class InverseBooleanToVisibilityConverter : IValueConverter
{
public static readonly InverseBooleanToVisibilityConverter Instance = new();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
return boolValue ? Visibility.Collapsed : Visibility.Visible;
}
return Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}