From 53cd8feb473c65ce803ead141da10efee3380e4f Mon Sep 17 00:00:00 2001 From: Jaex Date: Mon, 18 Nov 2019 03:00:24 +0300 Subject: [PATCH] Update control enabled states --- .../Forms/VideoConverterForm.Designer.cs | 14 +----- ShareX.MediaLib/Forms/VideoConverterForm.cs | 10 +++- ShareX.MediaLib/VideoConverterOptions.cs | 50 +++++++++---------- 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/ShareX.MediaLib/Forms/VideoConverterForm.Designer.cs b/ShareX.MediaLib/Forms/VideoConverterForm.Designer.cs index cd732e7a7..5e7ad049d 100644 --- a/ShareX.MediaLib/Forms/VideoConverterForm.Designer.cs +++ b/ShareX.MediaLib/Forms/VideoConverterForm.Designer.cs @@ -43,7 +43,6 @@ private void InitializeComponent() this.btnEncode = new System.Windows.Forms.Button(); this.lblArguments = new System.Windows.Forms.Label(); this.txtArguments = new System.Windows.Forms.TextBox(); - this.lblVideoQualityCRF = new System.Windows.Forms.Label(); this.pbProgress = new System.Windows.Forms.ProgressBar(); ((System.ComponentModel.ISupportInitialize)(this.nudVideoQuality)).BeginInit(); this.SuspendLayout(); @@ -185,15 +184,6 @@ private void InitializeComponent() this.txtArguments.Size = new System.Drawing.Size(424, 104); this.txtArguments.TabIndex = 13; // - // lblVideoQualityCRF - // - this.lblVideoQualityCRF.AutoSize = true; - this.lblVideoQualityCRF.Location = new System.Drawing.Point(200, 112); - this.lblVideoQualityCRF.Name = "lblVideoQualityCRF"; - this.lblVideoQualityCRF.Size = new System.Drawing.Size(28, 13); - this.lblVideoQualityCRF.TabIndex = 15; - this.lblVideoQualityCRF.Text = "CRF"; - // // pbProgress // this.pbProgress.Location = new System.Drawing.Point(16, 264); @@ -209,7 +199,6 @@ private void InitializeComponent() this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.SystemColors.Window; this.ClientSize = new System.Drawing.Size(456, 311); - this.Controls.Add(this.lblVideoQualityCRF); this.Controls.Add(this.txtArguments); this.Controls.Add(this.lblArguments); this.Controls.Add(this.nudVideoQuality); @@ -226,6 +215,8 @@ private void InitializeComponent() this.Controls.Add(this.lblInputFilePath); this.Controls.Add(this.btnEncode); this.Controls.Add(this.pbProgress); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; this.Name = "VideoConverterForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "ShareX - Video converter"; @@ -252,7 +243,6 @@ private void InitializeComponent() private System.Windows.Forms.Button btnEncode; private System.Windows.Forms.Label lblArguments; private System.Windows.Forms.TextBox txtArguments; - private System.Windows.Forms.Label lblVideoQualityCRF; private System.Windows.Forms.ProgressBar pbProgress; } } \ No newline at end of file diff --git a/ShareX.MediaLib/Forms/VideoConverterForm.cs b/ShareX.MediaLib/Forms/VideoConverterForm.cs index 159e0b9bb..fac3b100b 100644 --- a/ShareX.MediaLib/Forms/VideoConverterForm.cs +++ b/ShareX.MediaLib/Forms/VideoConverterForm.cs @@ -65,7 +65,14 @@ private void UpdateOptions() Options.VideoCodec = (ConverterVideoCodecs)cbVideoCodec.SelectedIndex; Options.VideoQuality = (int)nudVideoQuality.Value; + nudVideoQuality.Enabled = Options.VideoCodec == ConverterVideoCodecs.x264 || Options.VideoCodec == ConverterVideoCodecs.x265 || + Options.VideoCodec == ConverterVideoCodecs.vp8 || Options.VideoCodec == ConverterVideoCodecs.vp9 || + Options.VideoCodec == ConverterVideoCodecs.xvid; + txtArguments.Text = Options.GetFFmpegArgs(); + + btnEncode.Enabled = !string.IsNullOrEmpty(Options.InputFilePath) && !string.IsNullOrEmpty(Options.OutputFolderPath) && + !string.IsNullOrEmpty(Options.OutputFileName); } } @@ -73,7 +80,8 @@ private bool StartEncoding() { bool result = false; - if (!string.IsNullOrEmpty(Options.InputFilePath) && File.Exists(Options.InputFilePath) && !string.IsNullOrEmpty(Options.OutputFilePath)) + if (!string.IsNullOrEmpty(Options.InputFilePath) && File.Exists(Options.InputFilePath) && !string.IsNullOrEmpty(Options.OutputFolderPath) && + !string.IsNullOrEmpty(Options.OutputFileName)) { using (FFmpegCLIManager manager = new FFmpegCLIManager(FFmpegFilePath)) { diff --git a/ShareX.MediaLib/VideoConverterOptions.cs b/ShareX.MediaLib/VideoConverterOptions.cs index 9c44094cc..6b867af87 100644 --- a/ShareX.MediaLib/VideoConverterOptions.cs +++ b/ShareX.MediaLib/VideoConverterOptions.cs @@ -35,37 +35,13 @@ public class VideoConverterOptions public string OutputFolderPath { get; set; } public string OutputFileName { get; set; } - public string OutputFileNameExtension - { - get - { - switch (VideoCodec) - { - default: - case ConverterVideoCodecs.x264: - case ConverterVideoCodecs.x265: - return "mp4"; - case ConverterVideoCodecs.vp8: - case ConverterVideoCodecs.vp9: - return "webm"; - case ConverterVideoCodecs.xvid: - return "avi"; - case ConverterVideoCodecs.gif: - return "gif"; - case ConverterVideoCodecs.webp: - return "webp"; - case ConverterVideoCodecs.apng: - return "apng"; - } - } - } - public string OutputFilePath { get { string path = Path.Combine(OutputFolderPath, OutputFileName); - return Path.ChangeExtension(path, OutputFileNameExtension); + string extension = GetFileExtension(); + return Path.ChangeExtension(path, extension); } } @@ -130,5 +106,27 @@ public string GetFFmpegArgs() return args.ToString(); } + + public string GetFileExtension() + { + switch (VideoCodec) + { + default: + case ConverterVideoCodecs.x264: + case ConverterVideoCodecs.x265: + return "mp4"; + case ConverterVideoCodecs.vp8: + case ConverterVideoCodecs.vp9: + return "webm"; + case ConverterVideoCodecs.xvid: + return "avi"; + case ConverterVideoCodecs.gif: + return "gif"; + case ConverterVideoCodecs.webp: + return "webp"; + case ConverterVideoCodecs.apng: + return "apng"; + } + } } } \ No newline at end of file