生成の進捗のビューモデルを追加する
このコミットが含まれているのは:
2ファイル変更
+117
検索条件に一致するファイルはありません
@@ -0,0 +1,62 @@
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using ProxyForge.Encoding;
|
||||
using YukkuriMovieMaker.Commons;
|
||||
|
||||
namespace ProxyForge.ViewModels;
|
||||
|
||||
internal sealed class GenerationItemViewModel : Bindable
|
||||
{
|
||||
public GenerationItemViewModel(ProxyGenerationItem item)
|
||||
{
|
||||
Item = item;
|
||||
PropertyChangedEventManager.AddHandler(item, OnItemChanged, string.Empty);
|
||||
}
|
||||
|
||||
public ProxyGenerationItem Item { get; }
|
||||
|
||||
public string FileName => Item.FileName;
|
||||
|
||||
public string SourcePath => Item.SourcePath;
|
||||
|
||||
public double Percentage => Item.Progress * 100d;
|
||||
|
||||
public bool IsWaiting => Item.Status == ProxyGenerationStatus.Waiting;
|
||||
|
||||
public string StatusText => Item.Status switch
|
||||
{
|
||||
ProxyGenerationStatus.Waiting => Texts.StatusWaiting,
|
||||
ProxyGenerationStatus.Generating => Texts.StatusGenerating,
|
||||
ProxyGenerationStatus.Completed => Texts.StatusCompleted,
|
||||
ProxyGenerationStatus.Cancelled => Texts.StatusCancelled,
|
||||
_ => Item.Failure is { } failure ? string.Concat(Texts.StatusFailed, ": ", DescribeFailure(failure)) : Texts.StatusFailed,
|
||||
};
|
||||
|
||||
public static string DescribeFailure(ProxyEncodeFailure failure) => failure switch
|
||||
{
|
||||
ProxyEncodeFailure.FFmpegUnavailable => Texts.FailureFFmpegUnavailable,
|
||||
ProxyEncodeFailure.SourceUnavailable => Texts.FailureSourceUnavailable,
|
||||
ProxyEncodeFailure.NoFrames => Texts.FailureNoFrames,
|
||||
ProxyEncodeFailure.UnusableSize => Texts.FailureUnusableSize,
|
||||
ProxyEncodeFailure.Transparent => Texts.FailureTransparent,
|
||||
ProxyEncodeFailure.FFmpegFailed => Texts.FailureFFmpegFailed,
|
||||
ProxyEncodeFailure.NoOutput => Texts.FailureNoOutput,
|
||||
ProxyEncodeFailure.SourceChanged => Texts.FailureSourceChanged,
|
||||
_ => failure.ToString(),
|
||||
};
|
||||
|
||||
void OnItemChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
switch (e.PropertyName)
|
||||
{
|
||||
case nameof(ProxyGenerationItem.Progress):
|
||||
OnPropertyChanged(nameof(Percentage));
|
||||
break;
|
||||
case nameof(ProxyGenerationItem.Status):
|
||||
case nameof(ProxyGenerationItem.Failure):
|
||||
OnPropertyChanged(nameof(StatusText));
|
||||
OnPropertyChanged(nameof(IsWaiting));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Windows;
|
||||
using ProxyForge.Encoding;
|
||||
using YukkuriMovieMaker.Commons;
|
||||
|
||||
namespace ProxyForge.ViewModels;
|
||||
|
||||
internal sealed class GenerationProgressViewModel : Bindable
|
||||
{
|
||||
readonly ObservableCollection<ProxyGenerationItem> source;
|
||||
|
||||
public GenerationProgressViewModel(ObservableCollection<ProxyGenerationItem> source)
|
||||
{
|
||||
this.source = source;
|
||||
CollectionChangedEventManager.AddHandler(source, OnSourceChanged);
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
public ObservableCollection<GenerationItemViewModel> Items { get; } = [];
|
||||
|
||||
public bool HasItems => Items.Count > 0;
|
||||
|
||||
void OnSourceChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
switch (e.Action)
|
||||
{
|
||||
case NotifyCollectionChangedAction.Add when e.NewItems is not null:
|
||||
var index = e.NewStartingIndex < 0 ? Items.Count : e.NewStartingIndex;
|
||||
foreach (ProxyGenerationItem item in e.NewItems)
|
||||
Items.Insert(index++, new GenerationItemViewModel(item));
|
||||
break;
|
||||
case NotifyCollectionChangedAction.Remove when e.OldItems is not null:
|
||||
foreach (ProxyGenerationItem item in e.OldItems)
|
||||
{
|
||||
var existing = Items.FirstOrDefault(candidate => ReferenceEquals(candidate.Item, item));
|
||||
if (existing is not null)
|
||||
Items.Remove(existing);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Rebuild();
|
||||
break;
|
||||
}
|
||||
|
||||
OnPropertyChanged(nameof(HasItems));
|
||||
}
|
||||
|
||||
void Rebuild()
|
||||
{
|
||||
Items.Clear();
|
||||
foreach (var item in source)
|
||||
Items.Add(new GenerationItemViewModel(item));
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする