Update control enabled states

This commit is contained in:
Jaex 2019-11-18 03:00:24 +03:00
parent c35252b081
commit 53cd8feb47
3 changed files with 35 additions and 39 deletions

View file

@ -43,7 +43,6 @@ private void InitializeComponent()
this.btnEncode = new System.Windows.Forms.Button(); this.btnEncode = new System.Windows.Forms.Button();
this.lblArguments = new System.Windows.Forms.Label(); this.lblArguments = new System.Windows.Forms.Label();
this.txtArguments = new System.Windows.Forms.TextBox(); this.txtArguments = new System.Windows.Forms.TextBox();
this.lblVideoQualityCRF = new System.Windows.Forms.Label();
this.pbProgress = new System.Windows.Forms.ProgressBar(); this.pbProgress = new System.Windows.Forms.ProgressBar();
((System.ComponentModel.ISupportInitialize)(this.nudVideoQuality)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudVideoQuality)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
@ -185,15 +184,6 @@ private void InitializeComponent()
this.txtArguments.Size = new System.Drawing.Size(424, 104); this.txtArguments.Size = new System.Drawing.Size(424, 104);
this.txtArguments.TabIndex = 13; 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 // pbProgress
// //
this.pbProgress.Location = new System.Drawing.Point(16, 264); this.pbProgress.Location = new System.Drawing.Point(16, 264);
@ -209,7 +199,6 @@ private void InitializeComponent()
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.Window; this.BackColor = System.Drawing.SystemColors.Window;
this.ClientSize = new System.Drawing.Size(456, 311); this.ClientSize = new System.Drawing.Size(456, 311);
this.Controls.Add(this.lblVideoQualityCRF);
this.Controls.Add(this.txtArguments); this.Controls.Add(this.txtArguments);
this.Controls.Add(this.lblArguments); this.Controls.Add(this.lblArguments);
this.Controls.Add(this.nudVideoQuality); this.Controls.Add(this.nudVideoQuality);
@ -226,6 +215,8 @@ private void InitializeComponent()
this.Controls.Add(this.lblInputFilePath); this.Controls.Add(this.lblInputFilePath);
this.Controls.Add(this.btnEncode); this.Controls.Add(this.btnEncode);
this.Controls.Add(this.pbProgress); this.Controls.Add(this.pbProgress);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "VideoConverterForm"; this.Name = "VideoConverterForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "ShareX - Video converter"; this.Text = "ShareX - Video converter";
@ -252,7 +243,6 @@ private void InitializeComponent()
private System.Windows.Forms.Button btnEncode; private System.Windows.Forms.Button btnEncode;
private System.Windows.Forms.Label lblArguments; private System.Windows.Forms.Label lblArguments;
private System.Windows.Forms.TextBox txtArguments; private System.Windows.Forms.TextBox txtArguments;
private System.Windows.Forms.Label lblVideoQualityCRF;
private System.Windows.Forms.ProgressBar pbProgress; private System.Windows.Forms.ProgressBar pbProgress;
} }
} }

View file

@ -65,7 +65,14 @@ private void UpdateOptions()
Options.VideoCodec = (ConverterVideoCodecs)cbVideoCodec.SelectedIndex; Options.VideoCodec = (ConverterVideoCodecs)cbVideoCodec.SelectedIndex;
Options.VideoQuality = (int)nudVideoQuality.Value; 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(); 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; 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)) using (FFmpegCLIManager manager = new FFmpegCLIManager(FFmpegFilePath))
{ {

View file

@ -35,37 +35,13 @@ public class VideoConverterOptions
public string OutputFolderPath { get; set; } public string OutputFolderPath { get; set; }
public string OutputFileName { 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 public string OutputFilePath
{ {
get get
{ {
string path = Path.Combine(OutputFolderPath, OutputFileName); 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(); 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";
}
}
} }
} }