/* frmAddPreset.cs $ This file is part of the HandBrake source code. Homepage: . It may be used under the terms of the GNU General Public License. */ namespace Handbrake { using System; using System.Windows.Forms; using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Services; using Handbrake.Functions; using Handbrake.Model; /// /// The Add Preset Window /// public partial class frmAddPreset : Form { private readonly frmMain mainWindow; /// /// The Preset Handler /// private readonly PresetService presetCode; /// /// Initializes a new instance of the class. /// /// /// The Main Window /// /// /// The preset handler. /// public frmAddPreset(frmMain mainWindow, PresetService presetHandler) { InitializeComponent(); this.mainWindow = mainWindow; presetCode = presetHandler; cb_usePictureSettings.SelectedIndex = 0; } /// /// Handle the Add button event. /// /// /// The sender. /// /// /// The e. /// private void BtnAddClick(object sender, EventArgs e) { if (string.IsNullOrEmpty(txt_preset_name.Text.Trim())) { MessageBox.Show("You must enter a preset name!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } QueryPictureSettingsMode pictureSettingsMode; switch (cb_usePictureSettings.SelectedIndex) { case 0: pictureSettingsMode = QueryPictureSettingsMode.None; break; case 1: pictureSettingsMode = QueryPictureSettingsMode.Custom; break; case 2: pictureSettingsMode = QueryPictureSettingsMode.SourceMaximum; break; default: pictureSettingsMode = QueryPictureSettingsMode.None; break; } string query = QueryGenerator.GenerateQueryForPreset(mainWindow, pictureSettingsMode, check_useFilters.Checked, Convert.ToInt32(maxWidth.Value), Convert.ToInt32(maxHeight.Value)); Preset preset = new Preset { Name = this.txt_preset_name.Text, Query = query, CropSettings = pictureSettingsMode != QueryPictureSettingsMode.None, Description = string.Empty }; if (presetCode.Add(preset)) { this.DialogResult = DialogResult.OK; this.Close(); } else MessageBox.Show("Sorry, that preset name already exists. Please choose another!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } /// /// Handle the Cancel button event /// /// /// The sender. /// /// /// The e. /// private void BtnCancelClick(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } /// /// Picutre Settings option changed. /// /// The Sender /// The Event Args private void cb_usePictureSettings_SelectedIndexChanged(object sender, EventArgs e) { if (cb_usePictureSettings.SelectedItem.ToString().Contains("Custom")) { maxWidth.Visible = true; maxHeight.Visible = true; lbl_x.Visible = true; } else { maxWidth.Visible = false; maxHeight.Visible = false; lbl_x.Visible = false; } } } }