diff --git a/Application/FileConverter/FileConverter.csproj b/Application/FileConverter/FileConverter.csproj index 3b3278a..b0c0174 100644 --- a/Application/FileConverter/FileConverter.csproj +++ b/Application/FileConverter/FileConverter.csproj @@ -165,8 +165,10 @@ + + diff --git a/Application/FileConverter/ValueConverters/ConversionJobsToProgressState.cs b/Application/FileConverter/ValueConverters/ConversionJobsToProgressState.cs new file mode 100644 index 0000000..0a5f0cf --- /dev/null +++ b/Application/FileConverter/ValueConverters/ConversionJobsToProgressState.cs @@ -0,0 +1,48 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +namespace FileConverter.ValueConverters +{ + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Windows.Data; + using System.Windows.Shell; + + using FileConverter.ConversionJobs; + + public class ConversionJobsToProgressState : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (!(value is IEnumerable)) + { + return TaskbarItemProgressState.None; + } + + IEnumerable jobs = (IEnumerable)value; + + TaskbarItemProgressState progressState = TaskbarItemProgressState.None; + foreach (ConversionJob job in jobs) + { + if (job.State == ConversionJob.ConversionState.Failed) + { + progressState = TaskbarItemProgressState.Error; + break; + } + + if (job.State == ConversionJob.ConversionState.InProgress) + { + progressState = TaskbarItemProgressState.Normal; + break; + } + } + + return progressState; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Application/FileConverter/ValueConverters/ConversionJobsToProgressValue.cs b/Application/FileConverter/ValueConverters/ConversionJobsToProgressValue.cs new file mode 100644 index 0000000..95c75a7 --- /dev/null +++ b/Application/FileConverter/ValueConverters/ConversionJobsToProgressValue.cs @@ -0,0 +1,40 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +namespace FileConverter.ValueConverters +{ + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Windows.Data; + using System.Windows.Shell; + + using FileConverter.ConversionJobs; + + public class ConversionJobsToProgressValue : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (!(value is IEnumerable)) + { + return TaskbarItemProgressState.None; + } + + IEnumerable jobs = (IEnumerable)value; + + int jobCount = 0; + float progressValue = 0f; + foreach (ConversionJob job in jobs) + { + progressValue += job.Progress; + jobCount++; + } + + return jobCount > 0 ? progressValue / jobCount : 0f; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +}