feat(uploader): uploader window, dialogs, tray icon and screenshot mode
Single 760x560 window after the Uploader mockup: header with server, user, connection glyph and quota; first-run connect form with LAN servers and a TOFU fingerprint dialog; drop zone with an IFileOpenDialog browse menu (files or folder/card); target choice; queue line, pause/stop and MB/s limit; progress and per-file states with retry; watch-folder chips; options, with a destructive confirmation before "Delete after upload"; in-window settings panel. Shell_NotifyIcon tray icon (program icon, Show/Pause/Exit menu, balloon on completion), app bootstrap with logging, language, theme, single instance hand-over, and --capture rendering connect/queue/settings in dark and light from a design-time sample provider. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
15 files changed
+2572
-1
No files matched your search
@@ -0,0 +1,22 @@
|
||||
<ui:TitanoWindow x:Class="Titano.Uploader.Shell.ConfirmDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="clr-namespace:Titano.Ui.Controls;assembly=Titano.Ui"
|
||||
xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui"
|
||||
Title="{l:Loc Uploader.App.Title}"
|
||||
IsDialog="True" ResizeMode="NoResize" SizeToContent="Height" Width="440"
|
||||
WindowStartupLocation="CenterOwner" ShowInTaskbar="False">
|
||||
<!-- DESIGN §4 dialog: two buttons, safe action left and default, the action on the right. -->
|
||||
<StackPanel Margin="24,18,24,20">
|
||||
<TextBlock Text="{Binding Heading}" Style="{StaticResource Text.Title}" TextWrapping="Wrap" TextTrimming="None" />
|
||||
<TextBlock Text="{Binding Message}" Margin="0,8,0,0" Foreground="{DynamicResource Brush.TextMuted}" TextWrapping="Wrap" />
|
||||
<Border Style="{StaticResource Border.Card}" Margin="0,16,0,0" Padding="12,10" ToolTip="{Binding DetailToolTip}"
|
||||
Visibility="{Binding Detail, Converter={x:Static ui:NullToCollapsedConverter.Instance}}">
|
||||
<TextBlock Text="{Binding Detail}" FontFamily="{StaticResource Font.Mono}" FontSize="{StaticResource Size.Secondary}" TextWrapping="Wrap" LineHeight="18" />
|
||||
</Border>
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,24,0,0">
|
||||
<Button Content="{Binding SafeText}" ToolTip="{Binding SafeToolTip}" IsDefault="True" IsCancel="True" MinWidth="96" Click="OnSafe" />
|
||||
<Button x:Name="Action" Content="{Binding ActionText}" ToolTip="{Binding ActionToolTip}" MinWidth="96" Margin="8,0,0,0" Click="OnAction" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</ui:TitanoWindow>
|
||||
@@ -0,0 +1,47 @@
|
||||
using System.Windows;
|
||||
using Titano.Ui.Controls;
|
||||
|
||||
namespace Titano.Uploader.Shell;
|
||||
|
||||
/// <summary>Texts of a <see cref="ConfirmDialog"/>.</summary>
|
||||
public sealed record ConfirmRequest
|
||||
{
|
||||
public required string Heading { get; init; }
|
||||
public required string Message { get; init; }
|
||||
|
||||
/// <summary>Monospaced detail (certificate fingerprint); null hides it.</summary>
|
||||
public string? Detail { get; init; }
|
||||
|
||||
public string? DetailToolTip { get; init; }
|
||||
public required string SafeText { get; init; }
|
||||
public required string SafeToolTip { get; init; }
|
||||
public required string ActionText { get; init; }
|
||||
public required string ActionToolTip { get; init; }
|
||||
|
||||
/// <summary>Warning-outlined action (never a primary) for data-destroying choices.</summary>
|
||||
public bool IsDestructive { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>Modal confirmation used for trusting a certificate and for destructive options (BRIEF §12.1).</summary>
|
||||
public sealed partial class ConfirmDialog : TitanoWindow
|
||||
{
|
||||
private ConfirmDialog(ConfirmRequest request)
|
||||
{
|
||||
DataContext = request;
|
||||
InitializeComponent();
|
||||
Action.SetResourceReference(StyleProperty, request.IsDestructive ? "Button.Destructive" : "Button.Primary");
|
||||
}
|
||||
|
||||
/// <summary>True when the user chose the action.</summary>
|
||||
public static bool Ask(Window? owner, ConfirmRequest request)
|
||||
{
|
||||
var dialog = new ConfirmDialog(request);
|
||||
if (owner is { IsVisible: true }) dialog.Owner = owner;
|
||||
else dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
return dialog.ShowDialog() == true;
|
||||
}
|
||||
|
||||
private void OnSafe(object sender, RoutedEventArgs e) => DialogResult = false;
|
||||
|
||||
private void OnAction(object sender, RoutedEventArgs e) => DialogResult = true;
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Ui.Mvvm;
|
||||
using Titano.Uploader.Server;
|
||||
|
||||
namespace Titano.Uploader.Shell;
|
||||
|
||||
/// <summary>
|
||||
/// First-run and signed-out form: server address (with servers found on the LAN), user, password. A self-signed
|
||||
/// certificate is shown to the user once (trust on first use) before the password is sent.
|
||||
/// </summary>
|
||||
public sealed class ConnectViewModel : ObservableObject
|
||||
{
|
||||
private readonly IServerSession _session;
|
||||
private readonly IUploaderDialogs _dialogs;
|
||||
private string _address;
|
||||
private string _username;
|
||||
private string? _errorText;
|
||||
private bool _isBusy;
|
||||
|
||||
public ConnectViewModel(IServerSession session, IUploaderDialogs dialogs, string? address, string? username)
|
||||
{
|
||||
_session = session;
|
||||
_dialogs = dialogs;
|
||||
_address = Display(address);
|
||||
_username = username ?? string.Empty;
|
||||
SignInCommand = new AsyncRelayCommand(SignInAsync);
|
||||
UseServerCommand = new RelayCommand(p =>
|
||||
{
|
||||
if (p is DiscoveredServer s) Address = s.Address;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>Servers that announced themselves on this network.</summary>
|
||||
public ObservableCollection<DiscoveredServer> Discovered { get; } = [];
|
||||
|
||||
public ICommand SignInCommand { get; }
|
||||
public ICommand UseServerCommand { get; }
|
||||
|
||||
public string Address
|
||||
{
|
||||
get => _address;
|
||||
set => Set(ref _address, value);
|
||||
}
|
||||
|
||||
public string Username
|
||||
{
|
||||
get => _username;
|
||||
set => Set(ref _username, value);
|
||||
}
|
||||
|
||||
/// <summary>Set from the view's PasswordBox; never stored.</summary>
|
||||
public string Password { private get; set; } = string.Empty;
|
||||
|
||||
public bool IsBusy
|
||||
{
|
||||
get => _isBusy;
|
||||
private set => Set(ref _isBusy, value);
|
||||
}
|
||||
|
||||
/// <summary>One sentence saying what went wrong; the retry action sits next to it.</summary>
|
||||
public string? ErrorText
|
||||
{
|
||||
get => _errorText;
|
||||
private set => Set(ref _errorText, value);
|
||||
}
|
||||
|
||||
/// <summary>Shows the server address without the trailing slash of the stored base URL.</summary>
|
||||
public static string Display(string? address) => address?.TrimEnd('/') ?? string.Empty;
|
||||
|
||||
public void AddDiscovered(DiscoveredServer server)
|
||||
{
|
||||
if (Discovered.Any(d => d.Address == server.Address)) return;
|
||||
Discovered.Add(server);
|
||||
if (Address.Length == 0 && Discovered.Count == 1) Address = server.Address;
|
||||
}
|
||||
|
||||
private async Task SignInAsync()
|
||||
{
|
||||
ErrorText = null;
|
||||
IsBusy = true;
|
||||
try
|
||||
{
|
||||
var (result, fingerprint) = await _session.SignInAsync(Address, Username.Trim(), Password, CancellationToken.None);
|
||||
if (result == SignInResult.Untrusted && fingerprint is not null)
|
||||
{
|
||||
if (!_dialogs.ConfirmTrust(Display(Address), fingerprint))
|
||||
{
|
||||
ErrorText = Loc.L("Uploader.Connect.Error.Untrusted");
|
||||
return;
|
||||
}
|
||||
_session.Trust(fingerprint);
|
||||
(result, _) = await _session.SignInAsync(Address, Username.Trim(), Password, CancellationToken.None);
|
||||
}
|
||||
ErrorText = result switch
|
||||
{
|
||||
SignInResult.Success => null,
|
||||
SignInResult.InvalidAddress => Loc.L("Uploader.Connect.Error.InvalidAddress"),
|
||||
SignInResult.Unreachable => Loc.L("Uploader.Connect.Error.Unreachable"),
|
||||
SignInResult.NotTitano => Loc.L("Uploader.Connect.Error.NotTitano"),
|
||||
SignInResult.BadCredentials => Loc.L("Uploader.Connect.Error.BadCredentials"),
|
||||
SignInResult.Untrusted => Loc.L("Uploader.Connect.Error.Untrusted"),
|
||||
_ => Loc.L("Uploader.Connect.Error.Failed"),
|
||||
};
|
||||
if (result == SignInResult.Success) Address = Display(_session.Address);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Ui.Controls;
|
||||
using Titano.Uploader.Text;
|
||||
using Titano.Uploader.Uploads;
|
||||
|
||||
namespace Titano.Uploader.Shell;
|
||||
|
||||
/// <summary><see cref="UploadItemState"/> → status glyph kind (DESIGN §4: colour always paired with a glyph and a word).</summary>
|
||||
public sealed class UploadStateKindConverter : IValueConverter
|
||||
{
|
||||
public static UploadStateKindConverter Instance { get; } = new();
|
||||
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) => value switch
|
||||
{
|
||||
UploadItemState.Hashing => StatusKind.Analysing,
|
||||
UploadItemState.Uploading => StatusKind.Running,
|
||||
UploadItemState.Verified => StatusKind.Done,
|
||||
UploadItemState.Skipped => StatusKind.Synced,
|
||||
UploadItemState.Failed => StatusKind.Failed,
|
||||
_ => StatusKind.Queued,
|
||||
};
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary><see cref="UploadItemState"/> → its localized word.</summary>
|
||||
public sealed class UploadStateTextConverter : IValueConverter
|
||||
{
|
||||
public static UploadStateTextConverter Instance { get; } = new();
|
||||
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) => value switch
|
||||
{
|
||||
UploadItemState.Hashing => Loc.L("Uploader.State.Hashing"),
|
||||
UploadItemState.Uploading => Loc.L("Uploader.State.Uploading"),
|
||||
UploadItemState.Verified => Loc.L("Uploader.State.Verified"),
|
||||
UploadItemState.Skipped => Loc.L("Uploader.State.Skipped"),
|
||||
UploadItemState.Failed => Loc.L("Uploader.State.Failed"),
|
||||
_ => Loc.L("Uploader.State.Queued"),
|
||||
};
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>(<see cref="UploadFailure"/>, detail) → one sentence for the tooltip of a failed item; null otherwise.</summary>
|
||||
public sealed class FailureTextConverter : IMultiValueConverter
|
||||
{
|
||||
public static FailureTextConverter Instance { get; } = new();
|
||||
|
||||
public object? Convert(object?[] values, Type targetType, object? parameter, CultureInfo culture) =>
|
||||
values is [UploadFailure failure, var detail, ..] ? Describe(failure, detail as string) : null;
|
||||
|
||||
public object[] ConvertBack(object? value, Type[] targetTypes, object? parameter, CultureInfo culture) => throw new NotSupportedException();
|
||||
|
||||
private static string? Describe(UploadFailure failure, string? detail) => failure switch
|
||||
{
|
||||
UploadFailure.FileMissing => Loc.L("Uploader.Failure.FileMissing"),
|
||||
UploadFailure.FileUnreadable => Loc.L("Uploader.Failure.FileUnreadable"),
|
||||
UploadFailure.FileChanged => Loc.L("Uploader.Failure.FileChanged"),
|
||||
UploadFailure.ServerRejected => Loc.L("Uploader.Failure.ServerRejected", detail ?? string.Empty),
|
||||
UploadFailure.Unexpected => Loc.L("Uploader.Failure.Unexpected"),
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>Visible only for <see cref="UploadItemState.Failed"/>; hidden (keeping its space) otherwise so rows stay aligned.</summary>
|
||||
public sealed class FailedToVisibleConverter : IValueConverter
|
||||
{
|
||||
public static FailedToVisibleConverter Instance { get; } = new();
|
||||
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
|
||||
value is UploadItemState.Failed ? Visibility.Visible : Visibility.Hidden;
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>Byte count → "25.4 MB".</summary>
|
||||
public sealed class SizeConverter : IValueConverter
|
||||
{
|
||||
public static SizeConverter Instance { get; } = new();
|
||||
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
|
||||
value is long bytes ? UploaderText.Bytes(bytes, Loc.Culture) : string.Empty;
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotSupportedException();
|
||||
}
|
||||
@@ -0,0 +1,548 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using Titano.Core.Diagnostics;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Ui.Controls;
|
||||
using Titano.Ui.Mvvm;
|
||||
using Titano.Uploader.Infrastructure;
|
||||
using Titano.Uploader.Server;
|
||||
using Titano.Uploader.Sources;
|
||||
using Titano.Uploader.Text;
|
||||
using Titano.Uploader.Uploads;
|
||||
using Titano.Uploader.Watching;
|
||||
|
||||
namespace Titano.Uploader.Shell;
|
||||
|
||||
/// <summary>A sequence offered as upload target.</summary>
|
||||
public sealed record SequenceOption(Guid Id, string Title);
|
||||
|
||||
/// <summary>Everything the window works with; the capture mode passes design-time implementations.</summary>
|
||||
public sealed record UploaderServices(
|
||||
UploaderSettings Settings,
|
||||
Action SaveSettings,
|
||||
IServerSession Session,
|
||||
UploadQueue Queue,
|
||||
IUploadEngine Engine,
|
||||
IStartupRegistration Startup,
|
||||
IUploaderDialogs Dialogs,
|
||||
WatchFolderService Watch,
|
||||
ProcessedFileMemory Memory,
|
||||
string LogDirectory);
|
||||
|
||||
/// <summary>State of the uploader window (BRIEF §15, mockup Uploader.html).</summary>
|
||||
public sealed class MainViewModel : LocalizedViewModel
|
||||
{
|
||||
private readonly UploaderServices _s;
|
||||
private readonly DispatcherTimer _refresh;
|
||||
private UploadTargetMode _target;
|
||||
private SequenceOption? _selectedSequence;
|
||||
private bool _loadingSequences;
|
||||
private string _newTitle;
|
||||
private bool _isSettingsOpen;
|
||||
private bool _startWithWindows;
|
||||
private string _queueText = string.Empty;
|
||||
private string _progressText = string.Empty;
|
||||
private string? _currentFileText;
|
||||
private double _progress;
|
||||
private UploadItem? _currentItem;
|
||||
|
||||
public MainViewModel(UploaderServices services)
|
||||
{
|
||||
_s = services;
|
||||
_target = services.Settings.Target;
|
||||
_newTitle = services.Settings.NewSequenceTitle ?? string.Empty;
|
||||
_startWithWindows = services.Startup.IsEnabled;
|
||||
Connect = new ConnectViewModel(services.Session, services.Dialogs, services.Settings.ServerUrl, services.Settings.Username);
|
||||
foreach (var w in services.Settings.WatchFolders) WatchFolders.Add(NewWatchFolder(w.Path, w.IntervalSeconds));
|
||||
|
||||
OpenSettingsCommand = new RelayCommand(() => IsSettingsOpen = true);
|
||||
CloseSettingsCommand = new RelayCommand(() => IsSettingsOpen = false);
|
||||
SignOutCommand = new AsyncRelayCommand(SignOutAsync);
|
||||
BrowseFilesCommand = new AsyncRelayCommand(() => EnqueueAsync(_s.Dialogs.PickFiles()));
|
||||
BrowseFolderCommand = new AsyncRelayCommand(() => _s.Dialogs.PickFolder() is { } folder ? EnqueueAsync([folder]) : Task.CompletedTask);
|
||||
RefreshSequencesCommand = new AsyncRelayCommand(LoadSequencesAsync);
|
||||
PauseCommand = new RelayCommand(TogglePause, () => HasItems);
|
||||
StopCommand = new RelayCommand(() => _s.Engine.StopAndClear(), () => HasItems);
|
||||
RetryItemCommand = new RelayCommand(p =>
|
||||
{
|
||||
if (p is UploadItem item) _s.Engine.Retry(item);
|
||||
});
|
||||
AddWatchFolderCommand = new RelayCommand(AddWatchFolder);
|
||||
ToggleDeleteAfterUploadCommand = new RelayCommand(ToggleDeleteAfterUpload);
|
||||
|
||||
_s.Session.PropertyChanged += OnSessionChanged;
|
||||
_s.Session.SessionEnded += OnSessionEnded;
|
||||
_s.Engine.PropertyChanged += (_, _) => RefreshQueue();
|
||||
_s.Engine.Drained += OnDrained;
|
||||
_s.Queue.Items.CollectionChanged += (_, _) =>
|
||||
{
|
||||
OnPropertyChanged(nameof(HasItems));
|
||||
CommandManager.InvalidateRequerySuggested();
|
||||
};
|
||||
_refresh = new DispatcherTimer(DispatcherPriority.Background) { Interval = TimeSpan.FromMilliseconds(500) };
|
||||
_refresh.Tick += (_, _) => RefreshQueue();
|
||||
RefreshQueue();
|
||||
}
|
||||
|
||||
/// <summary>Raised when the queue finished while work was done, with the number of files the server confirmed.</summary>
|
||||
public event Action<int>? UploadsCompleted;
|
||||
|
||||
public ConnectViewModel Connect { get; }
|
||||
|
||||
/// <summary>In-window notifications; the window forwards them to its <see cref="ToastHost"/>.</summary>
|
||||
public ObservableCollection<Toast> PendingToasts { get; } = [];
|
||||
|
||||
public ICommand OpenSettingsCommand { get; }
|
||||
public ICommand CloseSettingsCommand { get; }
|
||||
public ICommand SignOutCommand { get; }
|
||||
public ICommand BrowseFilesCommand { get; }
|
||||
public ICommand BrowseFolderCommand { get; }
|
||||
public ICommand RefreshSequencesCommand { get; }
|
||||
public ICommand PauseCommand { get; }
|
||||
public ICommand StopCommand { get; }
|
||||
public ICommand RetryItemCommand { get; }
|
||||
public ICommand AddWatchFolderCommand { get; }
|
||||
public ICommand ToggleDeleteAfterUploadCommand { get; }
|
||||
|
||||
// ---------------- Header ----------------
|
||||
|
||||
public string ServerText => _s.Session.State == ConnectionState.NotConfigured
|
||||
? Loc.L("Uploader.Header.NotConnected")
|
||||
: ConnectViewModel.Display(_s.Session.Address);
|
||||
|
||||
public string? UserText => _s.Session.State is ConnectionState.Connected or ConnectionState.Offline or ConnectionState.SigningIn ? _s.Session.Username : null;
|
||||
|
||||
public StatusKind ConnectionKind => _s.Session.State switch
|
||||
{
|
||||
ConnectionState.Connected => StatusKind.Online,
|
||||
ConnectionState.SigningIn => StatusKind.Running,
|
||||
_ => StatusKind.Offline,
|
||||
};
|
||||
|
||||
/// <summary>Null on first run, when the server line already says "Not connected".</summary>
|
||||
public string? ConnectionText => _s.Session.State switch
|
||||
{
|
||||
ConnectionState.Connected => Loc.L("Uploader.Status.Connected"),
|
||||
ConnectionState.SigningIn => Loc.L("Uploader.Status.SigningIn"),
|
||||
ConnectionState.Offline => Loc.L("Uploader.Status.Offline"),
|
||||
ConnectionState.SignedOut => Loc.L("Uploader.Status.SignedOut"),
|
||||
_ => null,
|
||||
};
|
||||
|
||||
/// <summary>"1.9 TB free of 5 TB"; null without a quota.</summary>
|
||||
public string? QuotaText => _s.Session.State == ConnectionState.Connected && _s.Session.QuotaBytes > 0
|
||||
? Loc.L("Uploader.Header.Quota", UploaderText.Bytes(Math.Max(0, _s.Session.QuotaBytes - _s.Session.UsedBytes), Loc.Culture), UploaderText.Bytes(_s.Session.QuotaBytes, Loc.Culture))
|
||||
: null;
|
||||
|
||||
/// <summary>The sign-in form replaces the queue on first run and after signing out.</summary>
|
||||
public bool IsConnectVisible => _s.Session.State is ConnectionState.NotConfigured or ConnectionState.SignedOut;
|
||||
|
||||
public bool IsSettingsOpen
|
||||
{
|
||||
get => _isSettingsOpen;
|
||||
set => Set(ref _isSettingsOpen, value);
|
||||
}
|
||||
|
||||
// ---------------- Target ----------------
|
||||
|
||||
public bool IsSessionsTarget
|
||||
{
|
||||
get => _target == UploadTargetMode.Sessions;
|
||||
set => SetTarget(value, UploadTargetMode.Sessions);
|
||||
}
|
||||
|
||||
public bool IsSequenceTarget
|
||||
{
|
||||
get => _target == UploadTargetMode.Sequence;
|
||||
set => SetTarget(value, UploadTargetMode.Sequence);
|
||||
}
|
||||
|
||||
public bool IsNewTarget
|
||||
{
|
||||
get => _target == UploadTargetMode.NewSequence;
|
||||
set => SetTarget(value, UploadTargetMode.NewSequence);
|
||||
}
|
||||
|
||||
public ObservableCollection<SequenceOption> Sequences { get; } = [];
|
||||
|
||||
public SequenceOption? SelectedSequence
|
||||
{
|
||||
get => _selectedSequence;
|
||||
set
|
||||
{
|
||||
if (_loadingSequences || !Set(ref _selectedSequence, value)) return;
|
||||
_s.Settings.TargetSequenceId = value?.Id;
|
||||
_s.SaveSettings();
|
||||
}
|
||||
}
|
||||
|
||||
public string NewTitle
|
||||
{
|
||||
get => _newTitle;
|
||||
set
|
||||
{
|
||||
if (!Set(ref _newTitle, value)) return;
|
||||
_s.Settings.NewSequenceTitle = value;
|
||||
_s.SaveSettings();
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------- Queue ----------------
|
||||
|
||||
public ObservableCollection<UploadItem> Items => _s.Queue.Items;
|
||||
|
||||
public bool HasItems => _s.Queue.Items.Count > 0;
|
||||
|
||||
/// <summary>"4,812 files · 96.2 GB · 38 MB/s · 41 min left".</summary>
|
||||
public string QueueText
|
||||
{
|
||||
get => _queueText;
|
||||
private set => Set(ref _queueText, value);
|
||||
}
|
||||
|
||||
/// <summary>"2,214 of 4,812 sent · 2,201 verified by the server · 0 retries".</summary>
|
||||
public string ProgressText
|
||||
{
|
||||
get => _progressText;
|
||||
private set => Set(ref _progressText, value);
|
||||
}
|
||||
|
||||
public string? CurrentFileText
|
||||
{
|
||||
get => _currentFileText;
|
||||
private set => Set(ref _currentFileText, value);
|
||||
}
|
||||
|
||||
public double Progress
|
||||
{
|
||||
get => _progress;
|
||||
private set => Set(ref _progress, value);
|
||||
}
|
||||
|
||||
/// <summary>The item being uploaded; the list keeps it in view.</summary>
|
||||
public UploadItem? CurrentItem
|
||||
{
|
||||
get => _currentItem;
|
||||
private set => Set(ref _currentItem, value);
|
||||
}
|
||||
|
||||
public bool IsPaused => _s.Queue.IsPaused;
|
||||
|
||||
public string PauseToolTip => Loc.L(IsPaused ? "Tooltips.Uploader.Resume" : "Tooltips.Uploader.Pause");
|
||||
|
||||
/// <summary>Accessible name of the pause/resume button (also the tray menu entry).</summary>
|
||||
public string PauseLabel => Loc.L(IsPaused ? "Uploader.Action.Resume" : "Uploader.Action.Pause");
|
||||
|
||||
/// <summary>Upload limit in MB/s; 0 = unlimited.</summary>
|
||||
public int BandwidthLimit
|
||||
{
|
||||
get => _s.Session.BandwidthLimit;
|
||||
set
|
||||
{
|
||||
var clamped = Math.Clamp(value, 0, 100_000);
|
||||
if (clamped == _s.Session.BandwidthLimit) return;
|
||||
_s.Session.BandwidthLimit = clamped;
|
||||
_s.Settings.BandwidthLimit = clamped;
|
||||
_s.SaveSettings();
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Tray hover text.</summary>
|
||||
public string TrayText => Loc.L("Uploader.App.Title") + (HasItems ? " · " + QueueText : string.Empty);
|
||||
|
||||
// ---------------- Watch folders ----------------
|
||||
|
||||
public ObservableCollection<WatchFolderViewModel> WatchFolders { get; } = [];
|
||||
|
||||
// ---------------- Options ----------------
|
||||
|
||||
/// <summary>Turned on only through <see cref="ToggleDeleteAfterUploadCommand"/>, which asks first.</summary>
|
||||
public bool DeleteAfterUpload => _s.Settings.DeleteAfterUpload;
|
||||
|
||||
public bool StartWithWindows
|
||||
{
|
||||
get => _startWithWindows;
|
||||
set
|
||||
{
|
||||
_s.Startup.SetEnabled(value);
|
||||
// Read back: the registry may refuse the change.
|
||||
_startWithWindows = _s.Startup.IsEnabled;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public bool MinimizeToTray
|
||||
{
|
||||
get => _s.Settings.MinimizeToTray;
|
||||
set
|
||||
{
|
||||
if (_s.Settings.MinimizeToTray == value) return;
|
||||
_s.Settings.MinimizeToTray = value;
|
||||
_s.SaveSettings();
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------- Actions ----------------
|
||||
|
||||
/// <summary>Starts the periodic refresh and, when signed in, loads the sequence list.</summary>
|
||||
public void Start()
|
||||
{
|
||||
_refresh.Start();
|
||||
if (_s.Session.State == ConnectionState.Connected) _ = LoadSequencesAsync();
|
||||
}
|
||||
|
||||
/// <summary>Starts watching every configured folder.</summary>
|
||||
public void StartWatching()
|
||||
{
|
||||
foreach (var w in WatchFolders) _s.Watch.Watch(w.Path, TimeSpan.FromSeconds(w.IntervalSeconds));
|
||||
}
|
||||
|
||||
/// <summary>Adds the photos under <paramref name="paths"/> (files, folders, card roots) to the queue.</summary>
|
||||
public async Task EnqueueAsync(IReadOnlyList<string> paths)
|
||||
{
|
||||
if (paths.Count == 0) return;
|
||||
if (_target == UploadTargetMode.Sequence && SelectedSequence is null)
|
||||
{
|
||||
ShowToast(Loc.L("Uploader.Toast.ChooseSequence"));
|
||||
return;
|
||||
}
|
||||
var found = await Task.Run(() => PhotoScanner.Scan(paths));
|
||||
var fresh = found.Where(f => !_s.Queue.ContainsPath(f.Path)).ToList();
|
||||
if (fresh.Count == 0)
|
||||
{
|
||||
ShowToast(Loc.L("Uploader.Toast.NothingFound"));
|
||||
return;
|
||||
}
|
||||
var batch = new UploadBatch
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
Mode = _target,
|
||||
SequenceId = _target == UploadTargetMode.Sequence ? SelectedSequence?.Id : null,
|
||||
Title = _target == UploadTargetMode.NewSequence ? NewTitle.Trim() : null,
|
||||
};
|
||||
var entries = _target == UploadTargetMode.Sessions
|
||||
? SessionEntries(fresh, null, null, out _)
|
||||
: [.. fresh.OrderBy(f => f.CapturedAt).Select(f => new QueueEntry(f.Path, f.Size, f.ModifiedUtc, f.CapturedAt, null, null))];
|
||||
var added = Add(batch, entries);
|
||||
Log.Info("queue", $"{added} file(s) added from {paths.Count} path(s), target {_target}");
|
||||
ShowToast(Loc.Plural("Uploader.Toast.Added", added));
|
||||
}
|
||||
|
||||
/// <summary>Queues stable new photos of a watch folder; they join the folder's last session when close in time.</summary>
|
||||
public void OnWatchFilesReady(string root, IReadOnlyList<SourceFile> files)
|
||||
{
|
||||
var fresh = files.Where(f => !_s.Queue.ContainsPath(f.Path)).ToList();
|
||||
if (fresh.Count == 0) return;
|
||||
var entries = SessionEntries(fresh, root, _s.Memory.GetSession(root), out var last);
|
||||
Add(new UploadBatch { Id = Guid.CreateVersion7(), Mode = UploadTargetMode.Sessions }, entries);
|
||||
_s.Memory.SetSession(root, last);
|
||||
}
|
||||
|
||||
public void OnWatchAvailabilityChanged(string root, bool available)
|
||||
{
|
||||
var folder = WatchFolders.FirstOrDefault(w => string.Equals(w.Path, root, StringComparison.OrdinalIgnoreCase));
|
||||
if (folder is not null) folder.IsAvailable = available;
|
||||
}
|
||||
|
||||
/// <summary>Errors are one sentence plus one action (BRIEF §0.2 rule 6).</summary>
|
||||
public void ReportError(Exception ex)
|
||||
{
|
||||
Log.Error("ui", "Operation failed", ex);
|
||||
ShowToast(Loc.L("Errors.Unexpected"), Loc.L("Common.OpenLogs"), Loc.L("Tooltips.Common.OpenLogs"), new RelayCommand(OpenLogs));
|
||||
}
|
||||
|
||||
public void TogglePause()
|
||||
{
|
||||
if (_s.Queue.IsPaused) _s.Engine.Resume();
|
||||
else _s.Engine.Pause();
|
||||
RefreshQueue();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
_refresh.Stop();
|
||||
_s.Session.PropertyChanged -= OnSessionChanged;
|
||||
_s.Session.SessionEnded -= OnSessionEnded;
|
||||
_s.Engine.Drained -= OnDrained;
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
private int Add(UploadBatch batch, IReadOnlyList<QueueEntry> entries)
|
||||
{
|
||||
// A new batch after a finished one starts a fresh count.
|
||||
if (!_s.Queue.HasPending) _s.Queue.RemoveCompleted();
|
||||
var added = _s.Queue.Add(batch, entries);
|
||||
_s.Engine.Pump();
|
||||
RefreshQueue();
|
||||
return added;
|
||||
}
|
||||
|
||||
/// <summary>Session keys per source folder (BRIEF §13 rules), entries in capture order.</summary>
|
||||
private static List<QueueEntry> SessionEntries(IReadOnlyList<SourceFile> files, string? watchRoot, SessionContinuation? previous, out SessionContinuation? last)
|
||||
{
|
||||
var entries = new List<QueueEntry>(files.Count);
|
||||
last = previous;
|
||||
foreach (var group in files.GroupBy(f => watchRoot ?? f.Root, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
var ordered = group.OrderBy(f => f.CapturedAt).ToList();
|
||||
var assignment = SessionGrouper.Assign([.. ordered.Select(f => f.CapturedAt)], SessionGrouper.SourceTag(group.Key), watchRoot is null ? null : previous);
|
||||
for (var i = 0; i < ordered.Count; i++)
|
||||
{
|
||||
var f = ordered[i];
|
||||
entries.Add(new QueueEntry(f.Path, f.Size, f.ModifiedUtc, f.CapturedAt, assignment.Keys[i], watchRoot));
|
||||
}
|
||||
last = assignment.Last;
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
/// <summary>Recomputes the queue line, progress and current file (also every 500 ms once started).</summary>
|
||||
public void RefreshQueue()
|
||||
{
|
||||
var summary = QueueSummary.From(_s.Queue.Items);
|
||||
var rate = _s.Engine.BytesPerSecond;
|
||||
var activity = summary.Files == 0 ? QueueActivity.Idle : _s.Engine.Status switch
|
||||
{
|
||||
EngineStatus.Paused => QueueActivity.Paused,
|
||||
EngineStatus.WaitingForServer => QueueActivity.WaitingForServer,
|
||||
EngineStatus.Running => QueueActivity.Running,
|
||||
_ => QueueActivity.Done,
|
||||
};
|
||||
QueueText = UploaderText.QueueLine(summary, activity, rate, RateMeter.TimeLeft(summary.RemainingBytes, rate), Loc.Culture);
|
||||
ProgressText = summary.Files == 0 ? string.Empty : UploaderText.ProgressLine(summary, Loc.Culture);
|
||||
Progress = summary.Progress;
|
||||
CurrentFileText = summary.CurrentFile;
|
||||
CurrentItem = _s.Queue.Items.FirstOrDefault(i => i.State == UploadItemState.Uploading) ?? _s.Queue.Items.FirstOrDefault(i => i.IsActive);
|
||||
OnPropertyChanged(nameof(IsPaused));
|
||||
OnPropertyChanged(nameof(PauseToolTip));
|
||||
OnPropertyChanged(nameof(PauseLabel));
|
||||
OnPropertyChanged(nameof(TrayText));
|
||||
}
|
||||
|
||||
private void SetTarget(bool selected, UploadTargetMode mode)
|
||||
{
|
||||
if (!selected || _target == mode) return;
|
||||
_target = mode;
|
||||
_s.Settings.Target = mode;
|
||||
_s.SaveSettings();
|
||||
OnPropertyChanged(nameof(IsSessionsTarget));
|
||||
OnPropertyChanged(nameof(IsSequenceTarget));
|
||||
OnPropertyChanged(nameof(IsNewTarget));
|
||||
if (mode == UploadTargetMode.Sequence && Sequences.Count == 0) _ = LoadSequencesAsync();
|
||||
}
|
||||
|
||||
private async Task LoadSequencesAsync()
|
||||
{
|
||||
var list = await _s.Session.ListSequencesAsync(CancellationToken.None);
|
||||
if (list.Count == 0 && Sequences.Count > 0) return;
|
||||
_loadingSequences = true;
|
||||
try
|
||||
{
|
||||
Sequences.Clear();
|
||||
foreach (var s in list.OrderBy(s => s.DisplayTitle, StringComparer.CurrentCultureIgnoreCase)) Sequences.Add(new SequenceOption(s.Id, s.DisplayTitle));
|
||||
}
|
||||
finally
|
||||
{
|
||||
_loadingSequences = false;
|
||||
}
|
||||
_selectedSequence = Sequences.FirstOrDefault(s => s.Id == _s.Settings.TargetSequenceId);
|
||||
OnPropertyChanged(nameof(SelectedSequence));
|
||||
}
|
||||
|
||||
private async Task SignOutAsync()
|
||||
{
|
||||
IsSettingsOpen = false;
|
||||
await _s.Session.SignOutAsync();
|
||||
}
|
||||
|
||||
private void ToggleDeleteAfterUpload()
|
||||
{
|
||||
var enable = !_s.Settings.DeleteAfterUpload;
|
||||
if (enable && !_s.Dialogs.ConfirmDeleteAfterUpload())
|
||||
{
|
||||
// The check box toggled itself; put it back.
|
||||
OnPropertyChanged(nameof(DeleteAfterUpload));
|
||||
return;
|
||||
}
|
||||
_s.Settings.DeleteAfterUpload = enable;
|
||||
_s.SaveSettings();
|
||||
Log.Info("settings", "Delete after verified upload " + (enable ? "on" : "off"));
|
||||
OnPropertyChanged(nameof(DeleteAfterUpload));
|
||||
}
|
||||
|
||||
private void AddWatchFolder()
|
||||
{
|
||||
if (_s.Dialogs.PickWatchFolder() is not { } path) return;
|
||||
if (WatchFolders.Any(w => string.Equals(w.Path, path, StringComparison.OrdinalIgnoreCase))) return;
|
||||
var interval = (int)WatchFolderService.DefaultInterval(path).TotalSeconds;
|
||||
_s.Settings.WatchFolders.Add(new UploaderSettings.WatchFolderSettings { Path = path, IntervalSeconds = interval });
|
||||
_s.SaveSettings();
|
||||
WatchFolders.Add(NewWatchFolder(path, interval));
|
||||
_s.Watch.Watch(path, TimeSpan.FromSeconds(interval));
|
||||
}
|
||||
|
||||
private WatchFolderViewModel NewWatchFolder(string path, int intervalSeconds) =>
|
||||
new(path, intervalSeconds, WatchFolderService.IsNetworkPath(path), SetWatchInterval, RemoveWatchFolder);
|
||||
|
||||
private void SetWatchInterval(WatchFolderViewModel folder, int seconds)
|
||||
{
|
||||
folder.IntervalSeconds = seconds;
|
||||
foreach (var w in _s.Settings.WatchFolders.Where(w => string.Equals(w.Path, folder.Path, StringComparison.OrdinalIgnoreCase))) w.IntervalSeconds = seconds;
|
||||
_s.SaveSettings();
|
||||
_s.Watch.Watch(folder.Path, TimeSpan.FromSeconds(seconds));
|
||||
}
|
||||
|
||||
private void RemoveWatchFolder(WatchFolderViewModel folder)
|
||||
{
|
||||
_s.Watch.Stop(folder.Path);
|
||||
_s.Memory.RemoveFolder(folder.Path);
|
||||
_s.Settings.WatchFolders.RemoveAll(w => string.Equals(w.Path, folder.Path, StringComparison.OrdinalIgnoreCase));
|
||||
_s.SaveSettings();
|
||||
WatchFolders.Remove(folder);
|
||||
}
|
||||
|
||||
private void OnSessionChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged(nameof(ServerText));
|
||||
OnPropertyChanged(nameof(UserText));
|
||||
OnPropertyChanged(nameof(ConnectionKind));
|
||||
OnPropertyChanged(nameof(ConnectionText));
|
||||
OnPropertyChanged(nameof(QuotaText));
|
||||
OnPropertyChanged(nameof(IsConnectVisible));
|
||||
OnPropertyChanged(nameof(BandwidthLimit));
|
||||
if (e.PropertyName != nameof(IServerSession.State)) return;
|
||||
if (_s.Session.State == ConnectionState.Connected) _ = LoadSequencesAsync();
|
||||
if (IsConnectVisible)
|
||||
{
|
||||
Connect.Address = ConnectViewModel.Display(_s.Session.Address);
|
||||
Connect.Username = _s.Session.Username ?? Connect.Username;
|
||||
}
|
||||
CommandManager.InvalidateRequerySuggested();
|
||||
}
|
||||
|
||||
private void OnSessionEnded(object? sender, ServerProblem problem) =>
|
||||
ShowToast(Loc.L(problem == ServerProblem.CertificateChanged ? "Uploader.Toast.CertificateChanged" : "Uploader.Toast.SignedOut"));
|
||||
|
||||
private void OnDrained(object? sender, EventArgs e)
|
||||
{
|
||||
// The queue restarts its count with each new batch, so every confirmed item belongs to this run.
|
||||
var confirmed = _s.Queue.Items.Count(i => i.IsDone);
|
||||
RefreshQueue();
|
||||
_ = _s.Session.RefreshAsync();
|
||||
if (confirmed > 0) UploadsCompleted?.Invoke(confirmed);
|
||||
}
|
||||
|
||||
private void ShowToast(string title, string? actionText = null, string? actionToolTip = null, ICommand? action = null) =>
|
||||
PendingToasts.Add(new Toast { Title = title, ActionText = actionText, ActionToolTip = actionToolTip, ActionCommand = action });
|
||||
|
||||
private void OpenLogs()
|
||||
{
|
||||
if (Directory.Exists(_s.LogDirectory)) Process.Start(new ProcessStartInfo(_s.LogDirectory) { UseShellExecute = true, Verb = "explore" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,429 @@
|
||||
<ui:TitanoWindow x:Class="Titano.Uploader.Shell.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="clr-namespace:Titano.Ui.Controls;assembly=Titano.Ui"
|
||||
xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui"
|
||||
xmlns:s="clr-namespace:Titano.Uploader.Shell"
|
||||
xmlns:u="clr-namespace:Titano.Uploader.Uploads"
|
||||
Title="{l:Loc Uploader.App.Title}"
|
||||
Width="760" Height="560" MinWidth="640" MinHeight="480"
|
||||
WindowStartupLocation="CenterScreen" AllowDrop="True">
|
||||
<Window.Resources>
|
||||
<Style x:Key="Text.Label" TargetType="TextBlock" BasedOn="{StaticResource Text.Base}">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.TextMuted}" />
|
||||
<Setter Property="MinWidth" Value="92" />
|
||||
<Setter Property="Margin" Value="0,0,12,0" />
|
||||
</Style>
|
||||
|
||||
<!-- Watch-folder chip (mockup: 28 px pill, Card fill, status dot). -->
|
||||
<Style x:Key="Button.Chip" TargetType="Button" BasedOn="{StaticResource Button.Base}">
|
||||
<Setter Property="Height" Value="28" />
|
||||
<Setter Property="Padding" Value="10,0" />
|
||||
<Setter Property="ui:ControlState.CornerRadius" Value="14" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="Button.Round" TargetType="Button" BasedOn="{StaticResource Button.Icon}">
|
||||
<Setter Property="Width" Value="28" />
|
||||
<Setter Property="MinWidth" Value="28" />
|
||||
<Setter Property="Height" Value="28" />
|
||||
<Setter Property="ui:ControlState.CornerRadius" Value="14" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="Button.Square" TargetType="Button" BasedOn="{StaticResource Button.Icon}">
|
||||
<Setter Property="Width" Value="30" />
|
||||
<Setter Property="MinWidth" Value="30" />
|
||||
<Setter Property="Height" Value="30" />
|
||||
</Style>
|
||||
|
||||
<!-- Queue rows: hover only, no selection. -->
|
||||
<Style x:Key="QueueRow" TargetType="ListBoxItem">
|
||||
<Setter Property="Focusable" Value="False" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ListBoxItem">
|
||||
<Border x:Name="Bd" Background="Transparent" CornerRadius="{StaticResource Radius.Control}" Padding="10,0,4,0">
|
||||
<ContentPresenter />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource Brush.Card}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="WatchMenuItem" TargetType="MenuItem" BasedOn="{StaticResource {x:Type MenuItem}}">
|
||||
<Setter Property="Header" Value="{Binding Text}" />
|
||||
<Setter Property="Command" Value="{Binding Command}" />
|
||||
<Setter Property="IsChecked" Value="{Binding IsChecked, Mode=OneWay}" />
|
||||
<Setter Property="ToolTip" Value="{Binding ToolTip}" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsSeparator}" Value="True">
|
||||
<Setter Property="Height" Value="9" />
|
||||
<Setter Property="IsEnabled" Value="False" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="MenuItem">
|
||||
<Border Height="1" Margin="4" Background="{DynamicResource Brush.Stroke}" />
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Header: server · user · connection, quota, settings. -->
|
||||
<Border Height="40" Background="{DynamicResource Brush.Surface}" BorderBrush="{DynamicResource Brush.Stroke}" BorderThickness="0,0,0,1" Padding="16,0,10,0">
|
||||
<DockPanel LastChildFill="True">
|
||||
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Square}" ui:ButtonIcon.Glyph="{StaticResource Icon.Settings}"
|
||||
Command="{Binding OpenSettingsCommand}" ToolTip="{l:Loc Tooltips.Uploader.Settings}" AutomationProperties.Name="{l:Loc Uploader.Settings.Title}" />
|
||||
<TextBlock DockPanel.Dock="Right" Text="{Binding QuotaText}" Style="{StaticResource Text.Secondary}" Margin="12,0,12,0"
|
||||
ToolTip="{l:Loc Tooltips.Uploader.Quota}" Visibility="{Binding QuotaText, Converter={x:Static ui:NullToCollapsedConverter.Instance}}" />
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<ui:Icon Glyph="{StaticResource Icon.Server}" Foreground="{DynamicResource Brush.Accent}" Margin="0,0,10,0" VerticalAlignment="Center" />
|
||||
<TextBlock Text="{Binding ServerText}" Style="{StaticResource Text.Body}" MaxWidth="320" />
|
||||
<StackPanel Orientation="Horizontal" Visibility="{Binding UserText, Converter={x:Static ui:NullToCollapsedConverter.Instance}}">
|
||||
<TextBlock Text="·" Foreground="{DynamicResource Brush.TextFaint}" Margin="10,0" VerticalAlignment="Center" />
|
||||
<TextBlock Text="{Binding UserText}" Style="{StaticResource Text.Body}" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Visibility="{Binding ConnectionText, Converter={x:Static ui:NullToCollapsedConverter.Instance}}">
|
||||
<TextBlock Text="·" Foreground="{DynamicResource Brush.TextFaint}" Margin="10,0" VerticalAlignment="Center" />
|
||||
<ui:StatusGlyph Kind="{Binding ConnectionKind}" Text="{Binding ConnectionText}" FontSize="{StaticResource Size.Body}" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
</Border>
|
||||
|
||||
<!-- First run / signed out: connect form. -->
|
||||
<Grid Grid.Row="1" Visibility="{Binding IsConnectVisible, Converter={StaticResource BoolToVisibility}}">
|
||||
<StackPanel DataContext="{Binding Connect}" Width="440" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<ui:BrandMarkIcon Width="48" Height="48" HorizontalAlignment="Center" />
|
||||
<TextBlock Text="{l:Loc Uploader.Connect.Title}" Style="{StaticResource Text.Title}" HorizontalAlignment="Center" Margin="0,14,0,20" />
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" MinWidth="92" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Text="{l:Loc Uploader.Connect.Server}" Style="{StaticResource Text.Label}" />
|
||||
<TextBox x:Name="Address" Grid.Column="1" Text="{Binding Address, UpdateSourceTrigger=PropertyChanged}" ui:Field.Glyph="{StaticResource Icon.Server}"
|
||||
ui:Field.Placeholder="{l:Loc Uploader.Connect.AddressPlaceholder}" ToolTip="{l:Loc Tooltips.Uploader.ServerAddress}" AutomationProperties.Name="{l:Loc Uploader.Connect.Server}" />
|
||||
|
||||
<TextBlock Grid.Row="1" Text="{l:Loc Uploader.Connect.Found}" Style="{StaticResource Text.Label}" Margin="0,8,12,0" VerticalAlignment="Top"
|
||||
Visibility="{Binding Discovered.Count, Converter={x:Static ui:ZeroToCollapsedConverter.Instance}}" />
|
||||
<ItemsControl Grid.Row="1" Grid.Column="1" ItemsSource="{Binding Discovered}" Margin="0,8,0,0" Focusable="False"
|
||||
Visibility="{Binding Discovered.Count, Converter={x:Static ui:ZeroToCollapsedConverter.Instance}}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Button Style="{StaticResource Button.Chip}" Margin="0,0,8,4" Command="{Binding DataContext.UseServerCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
|
||||
CommandParameter="{Binding}" ToolTip="{l:Loc Tooltips.Uploader.DiscoveredServer}" AutomationProperties.Name="{Binding Name}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Ellipse Width="8" Height="8" Fill="{DynamicResource Brush.Accent}" Margin="0,0,8,0" VerticalAlignment="Center" />
|
||||
<TextBlock Text="{Binding Name}" VerticalAlignment="Center" />
|
||||
<TextBlock Text="{Binding Address}" Foreground="{DynamicResource Brush.TextMuted}" Margin="8,0,0,0" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<TextBlock Grid.Row="2" Text="{l:Loc Uploader.Connect.User}" Style="{StaticResource Text.Label}" Margin="0,12,12,0" />
|
||||
<TextBox Grid.Row="2" Grid.Column="1" Margin="0,12,0,0" Text="{Binding Username, UpdateSourceTrigger=PropertyChanged}" ui:Field.Glyph="{StaticResource Icon.User}"
|
||||
ToolTip="{l:Loc Tooltips.Uploader.User}" AutomationProperties.Name="{l:Loc Uploader.Connect.User}" />
|
||||
|
||||
<TextBlock Grid.Row="3" Text="{l:Loc Uploader.Connect.Password}" Style="{StaticResource Text.Label}" Margin="0,12,12,0" />
|
||||
<PasswordBox x:Name="Password" Grid.Row="3" Grid.Column="1" Margin="0,12,0,0" PasswordChanged="OnPasswordChanged"
|
||||
ToolTip="{l:Loc Tooltips.Uploader.Password}" AutomationProperties.Name="{l:Loc Uploader.Connect.Password}" />
|
||||
|
||||
<Border Grid.Row="4" Grid.Column="1" Margin="0,12,0,0" Padding="10,6,6,6" CornerRadius="{StaticResource Radius.Control}" Background="{DynamicResource Brush.ErrorSubtle}"
|
||||
Visibility="{Binding ErrorText, Converter={x:Static ui:NullToCollapsedConverter.Instance}}">
|
||||
<DockPanel>
|
||||
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Compact}" Content="{l:Loc Uploader.Action.Retry}" Command="{Binding SignInCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Uploader.Retry}" Margin="8,0,0,0" />
|
||||
<ui:Icon Glyph="{StaticResource Icon.ErrorCircle}" Foreground="{DynamicResource Brush.Error}" Margin="0,0,8,0" VerticalAlignment="Center" />
|
||||
<TextBlock Text="{Binding ErrorText}" TextWrapping="Wrap" VerticalAlignment="Center" />
|
||||
</DockPanel>
|
||||
</Border>
|
||||
|
||||
<Button Grid.Row="5" Grid.Column="1" Margin="0,20,0,0" HorizontalAlignment="Left" Style="{StaticResource Button.Primary}" MinWidth="120" IsDefault="True"
|
||||
Content="{l:Loc Uploader.Connect.SignIn}" Command="{Binding SignInCommand}" ToolTip="{l:Loc Tooltips.Uploader.SignIn}" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- Signed in: drop zone, target, queue, watch folders, options. -->
|
||||
<Grid Grid.Row="1" Margin="16,14,16,14" Grid.IsSharedSizeScope="True"
|
||||
Visibility="{Binding IsConnectVisible, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Drop zone: the empty state's sentence and button. -->
|
||||
<Grid x:Name="DropZone" Height="150" Background="Transparent">
|
||||
<Rectangle x:Name="DropBorder" RadiusX="8" RadiusY="8" StrokeThickness="2" StrokeDashArray="3 2" SnapsToDevicePixels="True"
|
||||
Stroke="{DynamicResource Brush.Stroke}" Fill="Transparent" />
|
||||
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<ui:Icon Glyph="{StaticResource Icon.Upload}" Size="28" Foreground="{DynamicResource Brush.TextMuted}" HorizontalAlignment="Center" />
|
||||
<TextBlock Text="{l:Loc Uploader.Drop.Message}" FontSize="{StaticResource Size.Section}" Foreground="{DynamicResource Brush.TextMuted}"
|
||||
HorizontalAlignment="Center" Margin="0,10,0,10" />
|
||||
<Button x:Name="BrowseButton" Content="{l:Loc Uploader.Browse.Button}" Height="30" Padding="14,0" HorizontalAlignment="Center"
|
||||
ToolTip="{l:Loc Tooltips.Uploader.Browse}" Click="OnBrowseClick">
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="{l:Loc Uploader.Browse.Files}" Command="{Binding BrowseFilesCommand}" ToolTip="{l:Loc Tooltips.Uploader.BrowseFiles}" />
|
||||
<MenuItem Header="{l:Loc Uploader.Browse.Folder}" Command="{Binding BrowseFolderCommand}" ToolTip="{l:Loc Tooltips.Uploader.BrowseFolder}" />
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- Target -->
|
||||
<Grid Grid.Row="1" Margin="0,12,0,0" MinHeight="30">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="Label" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{l:Loc Uploader.Target.Label}" Style="{StaticResource Text.Label}" />
|
||||
<WrapPanel Grid.Column="1" VerticalAlignment="Center">
|
||||
<RadioButton GroupName="Target" Content="{l:Loc Uploader.Target.Sessions}" IsChecked="{Binding IsSessionsTarget}" Margin="0,0,16,0" VerticalAlignment="Center"
|
||||
ToolTip="{l:Loc Tooltips.Uploader.TargetSessions}" />
|
||||
<RadioButton GroupName="Target" Content="{l:Loc Uploader.Target.Sequence}" IsChecked="{Binding IsSequenceTarget}" Margin="0,0,8,0" VerticalAlignment="Center"
|
||||
ToolTip="{l:Loc Tooltips.Uploader.TargetSequence}" />
|
||||
<ComboBox Width="170" Height="30" Margin="0,0,16,0" ItemsSource="{Binding Sequences}" SelectedItem="{Binding SelectedSequence}" DisplayMemberPath="Title"
|
||||
IsEnabled="{Binding IsSequenceTarget}" DropDownOpened="OnSequencesDropDownOpened" ToolTip="{l:Loc Tooltips.Uploader.ChooseSequence}"
|
||||
AutomationProperties.Name="{l:Loc Uploader.Target.Sequence}" />
|
||||
<RadioButton GroupName="Target" Content="{l:Loc Uploader.Target.New}" IsChecked="{Binding IsNewTarget}" Margin="0,0,8,0" VerticalAlignment="Center"
|
||||
ToolTip="{l:Loc Tooltips.Uploader.TargetNew}" />
|
||||
<TextBox Width="150" Height="30" Text="{Binding NewTitle}" ui:Field.Placeholder="{l:Loc Uploader.Target.TitlePlaceholder}"
|
||||
Visibility="{Binding IsNewTarget, Converter={StaticResource BoolToVisibility}}" ToolTip="{l:Loc Tooltips.Uploader.NewTitle}"
|
||||
AutomationProperties.Name="{l:Loc Uploader.Target.TitlePlaceholder}" />
|
||||
</WrapPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- Queue line, pause/stop, bandwidth limit -->
|
||||
<Grid Grid.Row="2" Margin="0,12,0,0" MinHeight="30">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="Label" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{l:Loc Uploader.Queue.Label}" Style="{StaticResource Text.Label}" />
|
||||
<TextBlock Grid.Column="1" Text="{Binding QueueText}" Style="{StaticResource Text.Body}" Typography.NumeralAlignment="Tabular" />
|
||||
<StackPanel Grid.Column="2" Orientation="Horizontal" Margin="10,0,0,0">
|
||||
<Button Command="{Binding PauseCommand}" ToolTip="{Binding PauseToolTip}" AutomationProperties.Name="{Binding PauseLabel}">
|
||||
<Button.Style>
|
||||
<Style TargetType="Button" BasedOn="{StaticResource Button.Square}">
|
||||
<Setter Property="ui:ButtonIcon.Glyph" Value="{StaticResource Icon.Pause}" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsPaused}" Value="True">
|
||||
<Setter Property="ui:ButtonIcon.Glyph" Value="{StaticResource Icon.Play}" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
</Button>
|
||||
<Button Style="{StaticResource Button.Square}" Margin="10,0,0,0" ui:ButtonIcon.Glyph="{StaticResource Icon.Stop}" Command="{Binding StopCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Uploader.Stop}" AutomationProperties.Name="{l:Loc Uploader.Action.Stop}" />
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="3" Orientation="Horizontal" Margin="16,0,0,0">
|
||||
<TextBlock Text="{l:Loc Uploader.Limit.Label}" Style="{StaticResource Text.Base}" Foreground="{DynamicResource Brush.TextMuted}" Margin="0,0,6,0" />
|
||||
<TextBox Width="58" Height="30" Text="{Binding BandwidthLimit}" TextAlignment="Right" ToolTip="{l:Loc Tooltips.Uploader.Limit}"
|
||||
AutomationProperties.Name="{l:Loc Uploader.Limit.Label}" />
|
||||
<TextBlock Text="{l:Loc Uploader.Limit.Unit}" Style="{StaticResource Text.Base}" Foreground="{DynamicResource Brush.TextMuted}" Margin="6,0,0,0" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- Progress: bar, current file, counts -->
|
||||
<StackPanel Grid.Row="3" Margin="0,12,0,0" Visibility="{Binding HasItems, Converter={StaticResource BoolToVisibility}}">
|
||||
<ProgressBar Height="8" Maximum="1" Value="{Binding Progress, Mode=OneWay}" />
|
||||
<Grid Margin="0,5,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{Binding CurrentFileText}" Style="{StaticResource Text.Secondary}" />
|
||||
<TextBlock Grid.Column="1" Text="{Binding ProgressText}" Style="{StaticResource Text.Secondary}" Margin="12,0,0,0" Typography.NumeralAlignment="Tabular" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Watch folders -->
|
||||
<Grid Grid.Row="4" Margin="0,12,0,0" MinHeight="30">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="Label" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{l:Loc Uploader.Watch.Label}" Style="{StaticResource Text.Label}" VerticalAlignment="Top" Margin="0,6,12,0" />
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal">
|
||||
<ItemsControl ItemsSource="{Binding WatchFolders}" Focusable="False">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Horizontal" />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type s:WatchFolderViewModel}">
|
||||
<Button Style="{StaticResource Button.Chip}" Margin="0,0,10,0" Click="OnWatchChipClick" ToolTip="{Binding ToolTip}" AutomationProperties.Name="{Binding Path}">
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding MenuOptions}" ItemContainerStyle="{StaticResource WatchMenuItem}" />
|
||||
</Button.ContextMenu>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Ellipse x:Name="Dot" Width="8" Height="8" Margin="0,0,8,0" VerticalAlignment="Center" StrokeThickness="1.5"
|
||||
Fill="{DynamicResource Brush.Success}" />
|
||||
<TextBlock Text="{Binding Text}" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<DataTemplate.Triggers>
|
||||
<!-- Unreachable: hollow ring (shape, not colour alone), reason in the tooltip. -->
|
||||
<DataTrigger Binding="{Binding IsAvailable}" Value="False">
|
||||
<Setter TargetName="Dot" Property="Fill" Value="Transparent" />
|
||||
<Setter TargetName="Dot" Property="Stroke" Value="{DynamicResource Brush.Error}" />
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<Button Style="{StaticResource Button.Round}" ui:ButtonIcon.Glyph="{StaticResource Icon.Plus}" Command="{Binding AddWatchFolderCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Uploader.AddWatchFolder}" AutomationProperties.Name="{l:Loc Uploader.Action.AddFolder}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- Per-file state -->
|
||||
<Border Grid.Row="5" Margin="0,12,0,0" Style="{StaticResource Border.Panel}" Padding="4"
|
||||
Visibility="{Binding HasItems, Converter={StaticResource BoolToVisibility}}">
|
||||
<ListBox x:Name="ItemList" ItemsSource="{Binding Items}" ItemContainerStyle="{StaticResource QueueRow}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type u:UploadItem}">
|
||||
<Grid Height="28">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" MinWidth="120" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{Binding FileName}" Style="{StaticResource Text.Body}" />
|
||||
<TextBlock Grid.Column="1" Text="{Binding Size, Converter={x:Static s:SizeConverter.Instance}}" Style="{StaticResource Text.Secondary}"
|
||||
Typography.NumeralAlignment="Tabular" Margin="12,0,0,0" />
|
||||
<ui:StatusGlyph Grid.Column="2" Margin="16,0,0,0" FontSize="{StaticResource Size.Secondary}" VerticalAlignment="Center"
|
||||
Kind="{Binding State, Converter={x:Static s:UploadStateKindConverter.Instance}}"
|
||||
Text="{Binding State, Converter={x:Static s:UploadStateTextConverter.Instance}}">
|
||||
<ui:StatusGlyph.ToolTip>
|
||||
<MultiBinding Converter="{x:Static s:FailureTextConverter.Instance}">
|
||||
<Binding Path="Failure" />
|
||||
<Binding Path="FailureDetail" />
|
||||
</MultiBinding>
|
||||
</ui:StatusGlyph.ToolTip>
|
||||
</ui:StatusGlyph>
|
||||
<Button Grid.Column="3" Style="{StaticResource Button.IconSubtle}" Width="26" Height="26" MinWidth="26" Margin="4,0,0,0"
|
||||
ui:ButtonIcon.Glyph="{StaticResource Icon.Retry}" CommandParameter="{Binding}"
|
||||
Command="{Binding DataContext.RetryItemCommand, RelativeSource={RelativeSource AncestorType=ListBox}}"
|
||||
Visibility="{Binding State, Converter={x:Static s:FailedToVisibleConverter.Instance}}"
|
||||
ToolTip="{l:Loc Tooltips.Uploader.RetryItem}" AutomationProperties.Name="{l:Loc Uploader.Action.Retry}" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</Border>
|
||||
|
||||
<!-- Options -->
|
||||
<WrapPanel Grid.Row="6" Margin="0,12,0,0" MinHeight="30">
|
||||
<CheckBox Content="{l:Loc Uploader.Options.DeleteSource}" IsChecked="{Binding DeleteAfterUpload, Mode=OneWay}" Command="{Binding ToggleDeleteAfterUploadCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Uploader.DeleteSource}" Margin="0,0,22,0" VerticalAlignment="Center" />
|
||||
<CheckBox Content="{l:Loc Uploader.Options.StartWithWindows}" IsChecked="{Binding StartWithWindows}" ToolTip="{l:Loc Tooltips.Uploader.StartWithWindows}"
|
||||
Margin="0,0,22,0" VerticalAlignment="Center" />
|
||||
<CheckBox Content="{l:Loc Uploader.Options.MinimizeToTray}" IsChecked="{Binding MinimizeToTray}" ToolTip="{l:Loc Tooltips.Uploader.MinimizeToTray}"
|
||||
VerticalAlignment="Center" />
|
||||
</WrapPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- Settings panel over the window content. -->
|
||||
<Grid Grid.RowSpan="2" Visibility="{Binding IsSettingsOpen, Converter={StaticResource BoolToVisibility}}">
|
||||
<Border Background="{DynamicResource Brush.Scrim}">
|
||||
<Border.InputBindings>
|
||||
<MouseBinding MouseAction="LeftClick" Command="{Binding CloseSettingsCommand}" />
|
||||
</Border.InputBindings>
|
||||
</Border>
|
||||
<Border HorizontalAlignment="Right" Width="340" Background="{DynamicResource Brush.Surface}" BorderBrush="{DynamicResource Brush.Stroke}" BorderThickness="1,0,0,0">
|
||||
<DockPanel Margin="20,12,12,20">
|
||||
<DockPanel DockPanel.Dock="Top" Margin="0,0,0,12">
|
||||
<Button DockPanel.Dock="Right" Style="{StaticResource Button.IconSubtle}" ui:ButtonIcon.Glyph="{StaticResource Icon.Close}" Command="{Binding CloseSettingsCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Uploader.CloseSettings}" AutomationProperties.Name="{l:Loc Uploader.Action.Close}" />
|
||||
<TextBlock Text="{l:Loc Uploader.Settings.Title}" Style="{StaticResource Text.Title}" />
|
||||
</DockPanel>
|
||||
<Grid Margin="0,0,8,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" MinWidth="100" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="36" />
|
||||
<RowDefinition Height="36" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="44" />
|
||||
<RowDefinition Height="36" />
|
||||
<RowDefinition Height="36" />
|
||||
<RowDefinition Height="36" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Text="{l:Loc Uploader.Settings.Server}" Style="{StaticResource Text.Label}" MinWidth="0" />
|
||||
<TextBlock Grid.Column="1" Text="{Binding ServerText}" Style="{StaticResource Text.Body}" />
|
||||
<TextBlock Grid.Row="1" Text="{l:Loc Uploader.Settings.User}" Style="{StaticResource Text.Label}" MinWidth="0" />
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding UserText}" Style="{StaticResource Text.Body}" />
|
||||
<Button Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" Margin="0,4,0,8" Content="{l:Loc Uploader.Settings.SignOut}" Command="{Binding SignOutCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Uploader.SignOut}" Visibility="{Binding IsConnectVisible, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
|
||||
|
||||
<TextBlock Grid.Row="3" Text="{l:Loc Uploader.Settings.Bandwidth}" Style="{StaticResource Text.Label}" MinWidth="0" />
|
||||
<StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="{l:Loc Uploader.Limit.Label}" Style="{StaticResource Text.Base}" Foreground="{DynamicResource Brush.TextMuted}" Margin="0,0,6,0" />
|
||||
<TextBox Width="58" Height="30" Text="{Binding BandwidthLimit}" TextAlignment="Right" ToolTip="{l:Loc Tooltips.Uploader.Limit}"
|
||||
AutomationProperties.Name="{l:Loc Uploader.Limit.Label}" />
|
||||
<TextBlock Text="{l:Loc Uploader.Limit.Unit}" Style="{StaticResource Text.Base}" Foreground="{DynamicResource Brush.TextMuted}" Margin="6,0,0,0" />
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Grid.Row="4" Text="{l:Loc Uploader.Settings.Startup}" Style="{StaticResource Text.Label}" MinWidth="0" />
|
||||
<CheckBox Grid.Row="4" Grid.Column="1" Content="{l:Loc Uploader.Options.StartWithWindows}" IsChecked="{Binding StartWithWindows}"
|
||||
ToolTip="{l:Loc Tooltips.Uploader.StartWithWindows}" VerticalAlignment="Center" />
|
||||
<CheckBox Grid.Row="5" Grid.Column="1" Content="{l:Loc Uploader.Options.MinimizeToTray}" IsChecked="{Binding MinimizeToTray}"
|
||||
ToolTip="{l:Loc Tooltips.Uploader.MinimizeToTray}" VerticalAlignment="Center" />
|
||||
|
||||
<TextBlock Grid.Row="6" Text="{l:Loc Uploader.Settings.Files}" Style="{StaticResource Text.Label}" MinWidth="0" />
|
||||
<CheckBox Grid.Row="6" Grid.Column="1" Content="{l:Loc Uploader.Options.DeleteSource}" IsChecked="{Binding DeleteAfterUpload, Mode=OneWay}"
|
||||
Command="{Binding ToggleDeleteAfterUploadCommand}" ToolTip="{l:Loc Tooltips.Uploader.DeleteSource}" VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</DockPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
<ui:ToastHost x:Name="Toasts" Grid.RowSpan="2" Margin="0,0,16,16" />
|
||||
</Grid>
|
||||
</ui:TitanoWindow>
|
||||
@@ -0,0 +1,139 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using Titano.Ui.Controls;
|
||||
using Titano.Uploader.Infrastructure;
|
||||
|
||||
namespace Titano.Uploader.Shell;
|
||||
|
||||
/// <summary>The uploader's single window (mockup Uploader.html).</summary>
|
||||
public sealed partial class MainWindow : TitanoWindow
|
||||
{
|
||||
private readonly MainViewModel _vm;
|
||||
private readonly UploaderSettings _settings;
|
||||
|
||||
public MainWindow(MainViewModel vm, UploaderSettings settings)
|
||||
{
|
||||
_vm = vm;
|
||||
_settings = settings;
|
||||
DataContext = vm;
|
||||
InitializeComponent();
|
||||
vm.PendingToasts.CollectionChanged += OnToastRequested;
|
||||
vm.PropertyChanged += OnViewModelChanged;
|
||||
PreviewKeyDown += OnPreviewKeyDown;
|
||||
RestorePlacement();
|
||||
}
|
||||
|
||||
/// <summary>Remembers size and position (also when the window only hides to the tray).</summary>
|
||||
public void SavePlacement()
|
||||
{
|
||||
var b = RestoreBounds;
|
||||
if (b.IsEmpty || b.Width < MinWidth || b.Height < MinHeight) return;
|
||||
_settings.Window = new UploaderSettings.WindowPlacement { Left = b.Left, Top = b.Top, Width = b.Width, Height = b.Height };
|
||||
}
|
||||
|
||||
protected override void OnDragOver(DragEventArgs e)
|
||||
{
|
||||
var accepted = CanDrop(e);
|
||||
e.Effects = accepted ? DragDropEffects.Copy : DragDropEffects.None;
|
||||
SetDropHighlight(accepted);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
protected override void OnDragLeave(DragEventArgs e) => SetDropHighlight(false);
|
||||
|
||||
protected override void OnDrop(DragEventArgs e)
|
||||
{
|
||||
SetDropHighlight(false);
|
||||
if (!CanDrop(e) || e.Data.GetData(DataFormats.FileDrop) is not string[] paths) return;
|
||||
e.Handled = true;
|
||||
_ = EnqueueAsync(paths);
|
||||
}
|
||||
|
||||
private async Task EnqueueAsync(IReadOnlyList<string> paths)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _vm.EnqueueAsync(paths);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// UI boundary: a drop must never take the window down.
|
||||
_vm.ReportError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanDrop(DragEventArgs e) => !_vm.IsConnectVisible && e.Data.GetDataPresent(DataFormats.FileDrop);
|
||||
|
||||
private void SetDropHighlight(bool on)
|
||||
{
|
||||
DropBorder.SetResourceReference(Shape.StrokeProperty, on ? "Brush.Accent" : "Brush.Stroke");
|
||||
if (on) DropBorder.SetResourceReference(Shape.FillProperty, "Brush.AccentSubtle");
|
||||
else DropBorder.Fill = Brushes.Transparent;
|
||||
}
|
||||
|
||||
private void OnBrowseClick(object sender, RoutedEventArgs e) => OpenMenu((Button)sender);
|
||||
|
||||
private void OnWatchChipClick(object sender, RoutedEventArgs e) => OpenMenu((Button)sender);
|
||||
|
||||
/// <summary>Opens a button's menu under it on a normal click.</summary>
|
||||
private static void OpenMenu(Button button)
|
||||
{
|
||||
if (button.ContextMenu is not { } menu) return;
|
||||
menu.DataContext = button.DataContext;
|
||||
menu.PlacementTarget = button;
|
||||
menu.Placement = PlacementMode.Bottom;
|
||||
menu.IsOpen = true;
|
||||
}
|
||||
|
||||
private void OnSequencesDropDownOpened(object? sender, EventArgs e) => _vm.RefreshSequencesCommand.Execute(null);
|
||||
|
||||
private void OnPasswordChanged(object sender, RoutedEventArgs e) => _vm.Connect.Password = Password.Password;
|
||||
|
||||
/// <summary>DESIGN §4 inputs: Enter commits, Esc reverts; Esc also closes the settings panel.</summary>
|
||||
private void OnPreviewKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.OriginalSource is TextBox box && (e.Key is Key.Enter or Key.Escape) && box.GetBindingExpression(TextBox.TextProperty) is { } binding)
|
||||
{
|
||||
if (e.Key == Key.Enter) binding.UpdateSource();
|
||||
else binding.UpdateTarget();
|
||||
if (e.Key == Key.Escape) e.Handled = true;
|
||||
return;
|
||||
}
|
||||
if (e.Key == Key.Escape && _vm.IsSettingsOpen)
|
||||
{
|
||||
_vm.IsSettingsOpen = false;
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnViewModelChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(MainViewModel.CurrentItem) && _vm.CurrentItem is { } item) ItemList.ScrollIntoView(item);
|
||||
if (e.PropertyName == nameof(MainViewModel.IsConnectVisible) && _vm.IsConnectVisible) Password.Clear();
|
||||
}
|
||||
|
||||
private void OnToastRequested(object? sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
if (e.Action != NotifyCollectionChangedAction.Add || e.NewItems is null) return;
|
||||
foreach (Toast t in e.NewItems) Toasts.Show(t);
|
||||
Dispatcher.BeginInvoke(() => _vm.PendingToasts.Clear());
|
||||
}
|
||||
|
||||
private void RestorePlacement()
|
||||
{
|
||||
if (_settings.Window is not { } p || p.Width < MinWidth || p.Height < MinHeight) return;
|
||||
var screen = new Rect(SystemParameters.VirtualScreenLeft, SystemParameters.VirtualScreenTop, SystemParameters.VirtualScreenWidth, SystemParameters.VirtualScreenHeight);
|
||||
if (!screen.IntersectsWith(new Rect(p.Left, p.Top, p.Width, p.Height))) return;
|
||||
WindowStartupLocation = WindowStartupLocation.Manual;
|
||||
Left = p.Left;
|
||||
Top = p.Top;
|
||||
Width = p.Width;
|
||||
Height = p.Height;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Threading;
|
||||
using Titano.Core.Diagnostics;
|
||||
using Titano.Ui.Theming;
|
||||
using Titano.Uploader.DesignTime;
|
||||
|
||||
namespace Titano.Uploader.Shell;
|
||||
|
||||
/// <summary>
|
||||
/// <c>Titano.Uploader.exe --capture <dir></c>: renders the window at 760×560 in the dark and light themes —
|
||||
/// first run (connect), queue running, settings panel — from <see cref="SampleData"/>, then exits.
|
||||
/// </summary>
|
||||
public static class ScreenCapture
|
||||
{
|
||||
public static void Run(MainWindow window, MainViewModel vm, SampleData sample, string directory)
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
window.WindowStartupLocation = WindowStartupLocation.Manual;
|
||||
window.Left = -20000;
|
||||
window.Top = -20000;
|
||||
window.Width = 760;
|
||||
window.Height = 560;
|
||||
window.ShowActivated = false;
|
||||
window.ShowInTaskbar = false;
|
||||
window.Show();
|
||||
|
||||
window.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var theme in new[] { AppTheme.Dark, AppTheme.Light })
|
||||
{
|
||||
var suffix = theme.ToString().ToLowerInvariant();
|
||||
ThemeManager.Apply(theme);
|
||||
sample.ShowConnect();
|
||||
Save(window, Path.Combine(directory, $"uploader-connect-{suffix}.png"));
|
||||
sample.ShowQueue();
|
||||
Save(window, Path.Combine(directory, $"uploader-queue-{suffix}.png"));
|
||||
vm.IsSettingsOpen = true;
|
||||
Save(window, Path.Combine(directory, $"uploader-settings-{suffix}.png"));
|
||||
vm.IsSettingsOpen = false;
|
||||
}
|
||||
Log.Info("capture", $"Screenshots written to {Path.GetFullPath(directory)}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("capture", "Capture failed", ex);
|
||||
Environment.ExitCode = 1;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void Save(Window window, string path)
|
||||
{
|
||||
// Let bindings, templates and deferred layout complete.
|
||||
window.UpdateLayout();
|
||||
window.Dispatcher.Invoke(DispatcherPriority.ApplicationIdle, () => { });
|
||||
window.UpdateLayout();
|
||||
if (VisualTreeHelper.GetChildrenCount(window) == 0) return;
|
||||
var root = (FrameworkElement)VisualTreeHelper.GetChild(window, 0);
|
||||
var dpi = VisualTreeHelper.GetDpi(window);
|
||||
var width = (int)Math.Ceiling(root.ActualWidth * dpi.DpiScaleX);
|
||||
var height = (int)Math.Ceiling(root.ActualHeight * dpi.DpiScaleY);
|
||||
if (width <= 0 || height <= 0) return;
|
||||
var bitmap = new RenderTargetBitmap(width, height, dpi.PixelsPerInchX, dpi.PixelsPerInchY, PixelFormats.Pbgra32);
|
||||
bitmap.Render(root);
|
||||
var encoder = new PngBitmapEncoder();
|
||||
encoder.Frames.Add(BitmapFrame.Create(bitmap));
|
||||
using var stream = File.Create(path);
|
||||
encoder.Save(stream);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
using Titano.Core.Imaging;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Uploader.Interop;
|
||||
|
||||
namespace Titano.Uploader.Shell;
|
||||
|
||||
/// <summary>Pickers and confirmations the view model asks for.</summary>
|
||||
public interface IUploaderDialogs
|
||||
{
|
||||
/// <summary>Photos to add; empty when cancelled.</summary>
|
||||
IReadOnlyList<string> PickFiles();
|
||||
|
||||
/// <summary>A folder or card root to add; null when cancelled.</summary>
|
||||
string? PickFolder();
|
||||
|
||||
/// <summary>A folder to watch; null when cancelled.</summary>
|
||||
string? PickWatchFolder();
|
||||
|
||||
/// <summary>Trust-on-first-use: shows the certificate fingerprint; true when the user trusts it.</summary>
|
||||
bool ConfirmTrust(string address, string fingerprint);
|
||||
|
||||
/// <summary>Destructive confirmation for "Delete after upload"; true when the user turns it on.</summary>
|
||||
bool ConfirmDeleteAfterUpload();
|
||||
}
|
||||
|
||||
/// <summary>Window-owned implementation: shell Open dialogs and <see cref="ConfirmDialog"/>.</summary>
|
||||
public sealed class UploaderDialogs : IUploaderDialogs
|
||||
{
|
||||
/// <summary>Owner of the dialogs; set once the main window exists.</summary>
|
||||
public Window? Owner { get; set; }
|
||||
|
||||
private IntPtr OwnerHandle => Owner is null ? IntPtr.Zero : new WindowInteropHelper(Owner).Handle;
|
||||
|
||||
public IReadOnlyList<string> PickFiles()
|
||||
{
|
||||
var photos = string.Join(';', ImageFormatInfo.Known.SelectMany(f => f.Extensions).Select(e => "*." + e));
|
||||
return FileDialogs.PickFiles(OwnerHandle, Loc.L("Uploader.Browse.FilesTitle"),
|
||||
[
|
||||
new FileFilter(Loc.L("Uploader.Browse.Photos"), photos),
|
||||
new FileFilter(Loc.L("Uploader.Browse.AllFiles"), "*.*"),
|
||||
]);
|
||||
}
|
||||
|
||||
public string? PickFolder() => FileDialogs.PickFolder(OwnerHandle, Loc.L("Uploader.Browse.FolderTitle"));
|
||||
|
||||
public string? PickWatchFolder() => FileDialogs.PickFolder(OwnerHandle, Loc.L("Uploader.Browse.WatchTitle"));
|
||||
|
||||
public bool ConfirmTrust(string address, string fingerprint) => ConfirmDialog.Ask(Owner, new ConfirmRequest
|
||||
{
|
||||
Heading = Loc.L("Uploader.Trust.Title"),
|
||||
Message = Loc.L("Uploader.Trust.Message"),
|
||||
Detail = address + "\n" + FormatFingerprint(fingerprint),
|
||||
DetailToolTip = Loc.L("Tooltips.Uploader.Fingerprint"),
|
||||
SafeText = Loc.L("Uploader.Trust.Cancel"),
|
||||
SafeToolTip = Loc.L("Tooltips.Uploader.CancelTrust"),
|
||||
ActionText = Loc.L("Uploader.Trust.Accept"),
|
||||
ActionToolTip = Loc.L("Tooltips.Uploader.Trust"),
|
||||
IsDestructive = false,
|
||||
});
|
||||
|
||||
public bool ConfirmDeleteAfterUpload() => ConfirmDialog.Ask(Owner, new ConfirmRequest
|
||||
{
|
||||
Heading = Loc.L("Uploader.Delete.Title"),
|
||||
Message = Loc.L("Uploader.Delete.Message"),
|
||||
SafeText = Loc.L("Uploader.Delete.Keep"),
|
||||
SafeToolTip = Loc.L("Tooltips.Uploader.KeepFiles"),
|
||||
ActionText = Loc.L("Uploader.Delete.Accept"),
|
||||
ActionToolTip = Loc.L("Tooltips.Uploader.ConfirmDelete"),
|
||||
IsDestructive = true,
|
||||
});
|
||||
|
||||
/// <summary>Splits the 32-byte SHA-256 fingerprint into two readable lines of 16 bytes.</summary>
|
||||
public static string FormatFingerprint(string fingerprint)
|
||||
{
|
||||
var bytes = fingerprint.Split(':');
|
||||
return bytes.Length <= 16 ? fingerprint : string.Join(':', bytes.Take(16)) + "\n" + string.Join(':', bytes.Skip(16));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using System.Windows.Input;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Ui.Mvvm;
|
||||
using Titano.Uploader.Text;
|
||||
|
||||
namespace Titano.Uploader.Shell;
|
||||
|
||||
/// <summary>An entry of a watch folder chip's menu: an interval choice, a separator (no text) or "Remove".</summary>
|
||||
public sealed record WatchMenuOption(string? Text, string? ToolTip, ICommand? Command, bool IsChecked)
|
||||
{
|
||||
public bool IsSeparator => Text is null;
|
||||
}
|
||||
|
||||
/// <summary>One watch folder chip: path, interval, reachability.</summary>
|
||||
public sealed class WatchFolderViewModel : ObservableObject
|
||||
{
|
||||
/// <summary>Intervals offered in the chip menu.</summary>
|
||||
public static readonly int[] IntervalChoices = [30, 60, 300, 900];
|
||||
|
||||
private readonly Action<WatchFolderViewModel, int> _setInterval;
|
||||
private readonly Action<WatchFolderViewModel> _remove;
|
||||
private int _intervalSeconds;
|
||||
private bool? _isAvailable;
|
||||
|
||||
public WatchFolderViewModel(string path, int intervalSeconds, bool isNetwork, Action<WatchFolderViewModel, int> setInterval, Action<WatchFolderViewModel> remove)
|
||||
{
|
||||
Path = path;
|
||||
IsNetwork = isNetwork;
|
||||
_intervalSeconds = intervalSeconds;
|
||||
_setInterval = setInterval;
|
||||
_remove = remove;
|
||||
}
|
||||
|
||||
public string Path { get; }
|
||||
public bool IsNetwork { get; }
|
||||
|
||||
public int IntervalSeconds
|
||||
{
|
||||
get => _intervalSeconds;
|
||||
set
|
||||
{
|
||||
if (!Set(ref _intervalSeconds, value)) return;
|
||||
OnPropertyChanged(nameof(Text));
|
||||
OnPropertyChanged(nameof(ToolTip));
|
||||
OnPropertyChanged(nameof(MenuOptions));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Null until the first check finished.</summary>
|
||||
public bool? IsAvailable
|
||||
{
|
||||
get => _isAvailable;
|
||||
set
|
||||
{
|
||||
if (Set(ref _isAvailable, value)) OnPropertyChanged(nameof(ToolTip));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>"D:\Cam\Roof · every 1 min".</summary>
|
||||
public string Text => Loc.L("Uploader.Watch.Chip", Path, Interval(IntervalSeconds));
|
||||
|
||||
public string ToolTip => IsAvailable == false ? Loc.L("Tooltips.Uploader.WatchFolderMissing", Interval(IntervalSeconds))
|
||||
: IsNetwork ? Loc.L("Tooltips.Uploader.WatchFolderNetwork", Interval(IntervalSeconds))
|
||||
: Loc.L("Tooltips.Uploader.WatchFolder", Interval(IntervalSeconds));
|
||||
|
||||
public IReadOnlyList<WatchMenuOption> MenuOptions =>
|
||||
[
|
||||
.. IntervalChoices.Select(s => new WatchMenuOption(
|
||||
Loc.L("Uploader.Watch.Every", Interval(s)),
|
||||
Loc.L("Tooltips.Uploader.WatchInterval"),
|
||||
new RelayCommand(() => _setInterval(this, s)),
|
||||
s == IntervalSeconds)),
|
||||
new WatchMenuOption(null, null, null, false),
|
||||
new WatchMenuOption(Loc.L("Uploader.Watch.Remove"), Loc.L("Tooltips.Uploader.RemoveWatchFolder"), new RelayCommand(() => _remove(this)), false),
|
||||
];
|
||||
|
||||
private static string Interval(int seconds) => UploaderText.Duration(TimeSpan.FromSeconds(seconds), Loc.Culture);
|
||||
}
|
||||
Reference in new issue
Block a user