// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// Interaction logic for ShellView.xaml
//
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Views
{
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Resources;
using Caliburn.Micro;
using HandBrakeWPF.Commands;
using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Utilities;
using HandBrakeWPF.ViewModels.Interfaces;
using Application = System.Windows.Application;
using Execute = Caliburn.Micro.Execute;
///
/// Interaction logic for ShellView.xaml
///
public partial class ShellView
{
///
/// The my notify icon.
///
private readonly NotifyIcon notifyIcon;
///
/// Initializes a new instance of the class.
///
public ShellView()
{
this.InitializeComponent();
IUserSettingService userSettingService = IoC.Get();
bool minimiseToTray = userSettingService.GetUserSetting(UserSettingConstants.MainWindowMinimize);
if (minimiseToTray)
{
INotifyIconService notifyIconService = IoC.Get();
this.notifyIcon = new NotifyIcon();
this.notifyIcon.ContextMenu = new ContextMenu(new[] { new MenuItem("Restore", NotifyIconClick), new MenuItem("Mini Status Display", ShowMiniStatusDisplay) });
notifyIconService.RegisterNotifyIcon(this.notifyIcon);
StreamResourceInfo streamResourceInfo = Application.GetResourceStream(new Uri("pack://application:,,,/handbrakepineapple.ico"));
if (streamResourceInfo != null)
{
Stream iconStream = streamResourceInfo.Stream;
this.notifyIcon.Icon = new Icon(iconStream);
}
this.notifyIcon.Click += this.NotifyIconClick;
this.StateChanged += this.ShellViewStateChanged;
}
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.E, ModifierKeys.Control)), new KeyGesture(Key.E, ModifierKeys.Control))); // Start Encode
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.K, ModifierKeys.Control)), new KeyGesture(Key.K, ModifierKeys.Control))); // Stop Encode
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.L, ModifierKeys.Control)), new KeyGesture(Key.L, ModifierKeys.Control))); // Open Log Window
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.Q, ModifierKeys.Control)), new KeyGesture(Key.Q, ModifierKeys.Control))); // Open Queue Window
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.A, ModifierKeys.Control)), new KeyGesture(Key.A, ModifierKeys.Control))); // Add to Queue
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.A, ModifierKeys.Alt)), new KeyGesture(Key.A, ModifierKeys.Alt))); // Add all to Queue
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.A, ModifierKeys.Control | ModifierKeys.Shift)), new KeyGesture(Key.A, ModifierKeys.Control | ModifierKeys.Shift))); // Add selection to Queue
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.O, ModifierKeys.Control)), new KeyGesture(Key.O, ModifierKeys.Control))); // File Scan
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.O, ModifierKeys.Alt)), new KeyGesture(Key.O, ModifierKeys.Alt))); // Scan Window
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.O, ModifierKeys.Control | ModifierKeys.Shift)), new KeyGesture(Key.O, ModifierKeys.Control | ModifierKeys.Shift))); // Scan a Folder
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.G, ModifierKeys.Control | ModifierKeys.Shift)), new KeyGesture(Key.G, ModifierKeys.Control | ModifierKeys.Shift))); // Garbage Colleciton
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.F1, ModifierKeys.None)), new KeyGesture(Key.F1, ModifierKeys.None))); // Help
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.S, ModifierKeys.Control)), new KeyGesture(Key.S, ModifierKeys.Control))); // Browse Destination
// Tabs Switching
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.D1, ModifierKeys.Control)), new KeyGesture(Key.D1, ModifierKeys.Control)));
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.D2, ModifierKeys.Control)), new KeyGesture(Key.D2, ModifierKeys.Control)));
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.D3, ModifierKeys.Control)), new KeyGesture(Key.D3, ModifierKeys.Control)));
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.D4, ModifierKeys.Control)), new KeyGesture(Key.D4, ModifierKeys.Control)));
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.D5, ModifierKeys.Control)), new KeyGesture(Key.D5, ModifierKeys.Control)));
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.D6, ModifierKeys.Control)), new KeyGesture(Key.D6, ModifierKeys.Control)));
this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.D7, ModifierKeys.Control)), new KeyGesture(Key.D7, ModifierKeys.Control)));
// Enable Windows 7 Taskbar progress indication.
if (this.TaskbarItemInfo == null)
{
this.TaskbarItemInfo = Win7.WindowsTaskbar;
}
}
///
/// Check with the user before closing.
///
///
/// The CancelEventArgs.
///
protected override void OnClosing(CancelEventArgs e)
{
IShellViewModel shellViewModel = this.DataContext as IShellViewModel;
if (shellViewModel != null)
{
bool canClose = shellViewModel.CanClose();
if (!canClose)
{
e.Cancel = true;
}
}
if (this.notifyIcon != null)
{
this.notifyIcon.Visible = false;
}
base.OnClosing(e);
}
///
/// The show mini status display.
///
///
/// The sender.
///
///
/// The e.
///
private void ShowMiniStatusDisplay(object sender, EventArgs e)
{
IMiniViewModel titleSpecificView = IoC.Get();
IWindowManager windowManager = IoC.Get();
Execute.OnUIThread(
() =>
{
titleSpecificView.Activate();
windowManager.ShowWindow(titleSpecificView);
});
}
///
/// The notify icon_ click.
///
///
/// The sender.
///
///
/// The e.
///
private void NotifyIconClick(object sender, EventArgs e)
{
this.WindowState = WindowState.Normal;
this.Topmost = true;
}
///
/// The shell view state changed.
///
///
/// The sender.
///
///
/// The e.
///
private void ShellViewStateChanged(object sender, EventArgs e)
{
if (this.notifyIcon != null)
{
if (this.WindowState == WindowState.Minimized)
{
this.ShowInTaskbar = false;
notifyIcon.Visible = true;
}
else if (this.WindowState == WindowState.Normal)
{
notifyIcon.Visible = false;
this.ShowInTaskbar = true;
}
}
}
}
}