// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// The Queue Selection View Model
//
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.ViewModels
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using HandBrake.ApplicationServices.Parsing;
using HandBrakeWPF.Model;
using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.ViewModels.Interfaces;
///
/// The Queue Selection View Model
///
public class QueueSelectionViewModel : ViewModelBase, IQueueSelectionViewModel
{
///
/// The error service.
///
private readonly IErrorService errorService;
///
/// The ordered by duration.
///
private bool orderedByDuration;
///
/// The ordered by title.
///
private bool orderedByTitle;
///
/// Initializes a new instance of the class.
///
///
/// The Error Service
///
public QueueSelectionViewModel(IErrorService errorService)
{
this.errorService = errorService;
this.Title = "Add to Queue";
this.TitleList = new BindingList();
this.OrderedByTitle = true;
}
///
/// Gets or sets the source.
///
public string Source { get; set; }
///
/// Gets or sets the selected titles.
///
public BindingList TitleList { get; set; }
///
/// Gets or sets a value indicating whether ordered by title.
///
public bool OrderedByTitle
{
get
{
return this.orderedByTitle;
}
set
{
this.orderedByTitle = value;
this.NotifyOfPropertyChange(() => OrderedByTitle);
}
}
///
/// Gets or sets a value indicating whether ordered by duration.
///
public bool OrderedByDuration
{
get
{
return this.orderedByDuration;
}
set
{
this.orderedByDuration = value;
this.NotifyOfPropertyChange(() => OrderedByDuration);
}
}
///
/// The order by title.
///
public void OrderByTitle()
{
TitleList = new BindingList(TitleList.OrderBy(o => o.Title.TitleNumber).ToList());
this.NotifyOfPropertyChange(() => TitleList);
this.OrderedByTitle = true;
this.OrderedByDuration = false;
}
///
/// The order by duration.
///
public void OrderByDuration()
{
TitleList = new BindingList(TitleList.OrderByDescending(o => o.Title.Duration).ToList());
this.NotifyOfPropertyChange(() => TitleList);
this.OrderedByTitle = false;
this.OrderedByDuration = true;
}
///
/// The select all.
///
public void SelectAll()
{
foreach (var item in TitleList)
{
item.IsSelected = true;
}
}
///
/// The select all.
///
public void UnSelectAll()
{
foreach (var item in TitleList)
{
item.IsSelected = false;
}
}
///
/// Add a Preset
///
public void Add()
{
this.Close();
}
///
/// Cancel adding a preset
///
public void Cancel()
{
this.TitleList.Clear();
this.Close();
}
///
/// Close this window.
///
public void Close()
{
this.TryClose();
}
///
/// The setup.
///
///
/// The scanned source.
///
///
/// The src Name.
///
public void Setup(Source scannedSource, string srcName)
{
this.TitleList.Clear();
if (scannedSource != null)
{
IEnumerable titles = orderedByTitle
? scannedSource.Titles
: scannedSource.Titles.OrderByDescending(o => o.Duration).ToList();
foreach (Title item in titles)
{
SelectionTitle title = new SelectionTitle(item, srcName);
TitleList.Add(title);
}
}
}
}
}