// --------------------------------------------------------------------------------------------------------------------
//
// 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.Services.Scan.Model;
using HandBrakeWPF.Model;
using HandBrakeWPF.Properties;
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;
private readonly IUserSettingService userSettingService;
///
/// The ordered by duration.
///
private bool orderedByDuration;
///
/// The ordered by title.
///
private bool orderedByTitle;
///
/// The add to queue.
///
private Action> addToQueue;
///
/// Initializes a new instance of the class.
///
///
/// The Error Service
///
///
/// The user Setting Service.
///
public QueueSelectionViewModel(IErrorService errorService, IUserSettingService userSettingService)
{
this.errorService = errorService;
this.userSettingService = userSettingService;
this.Title = Resources.QueueSelectionViewModel_AddToQueue;
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);
}
}
///
/// Gets a value indicating whether is auto naming enabled.
///
public bool IsAutoNamingEnabled
{
get
{
return this.userSettingService.GetUserSetting(UserSettingConstants.AutoNaming);
}
}
///
/// 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.addToQueue(this.TitleList.Where(c => c.IsSelected));
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.
///
///
/// The add Action.
///
public void Setup(Source scannedSource, string srcName, Action> addAction)
{
this.TitleList.Clear();
this.addToQueue = addAction;
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) { IsSelected = true };
TitleList.Add(title);
}
}
this.NotifyOfPropertyChange(() => this.IsAutoNamingEnabled);
}
}
}