Imports Stax
Imports Stax.AppFramework
Imports Stax.UI

Public Class CmdlEncoderForm
    Inherits ExtendedForm

#Region " Designer "

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    Friend WithEvents SmartTagProvider As Stax.UI.Design.SmartTagProvider
    Friend WithEvents bOK As System.Windows.Forms.Button
    Friend WithEvents bCancel As System.Windows.Forms.Button
    Friend WithEvents EncodingCliControl As StaxRip.CmdlScriptControl
    Friend WithEvents cbType As System.Windows.Forms.ComboBox
    Friend WithEvents lOutput As System.Windows.Forms.Label
    Friend WithEvents TipProvider As Stax.UI.TipProvider
    Friend WithEvents CompCheckCliControl As StaxRip.CmdlScriptControl
    Friend WithEvents cbQualityMode As System.Windows.Forms.CheckBox
    Friend WithEvents nudPercent As System.Windows.Forms.NumericUpDown
    Friend WithEvents bHelp As System.Windows.Forms.Button
    Friend WithEvents lAimedQuality As System.Windows.Forms.Label

    Private components As System.ComponentModel.IContainer

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.bOK = New System.Windows.Forms.Button
        Me.bCancel = New System.Windows.Forms.Button
        Me.cbType = New System.Windows.Forms.ComboBox
        Me.lOutput = New System.Windows.Forms.Label
        Me.cbQualityMode = New System.Windows.Forms.CheckBox
        Me.nudPercent = New System.Windows.Forms.NumericUpDown
        Me.CompCheckCliControl = New StaxRip.CmdlScriptControl
        Me.EncodingCliControl = New StaxRip.CmdlScriptControl
        Me.SmartTagProvider = New Stax.UI.Design.SmartTagProvider
        Me.TipProvider = New Stax.UI.TipProvider(Me.components)
        Me.bHelp = New System.Windows.Forms.Button
        Me.lAimedQuality = New System.Windows.Forms.Label
        CType(Me.nudPercent, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.TipProvider, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'bOK
        '
        Me.bOK.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.bOK.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.bOK.Location = New System.Drawing.Point(468, 385)
        Me.bOK.Name = "bOK"
        Me.bOK.Size = New System.Drawing.Size(75, 24)
        Me.bOK.TabIndex = 0
        Me.bOK.Text = "OK"
        '
        'bCancel
        '
        Me.bCancel.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.bCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.bCancel.Location = New System.Drawing.Point(549, 385)
        Me.bCancel.Name = "bCancel"
        Me.bCancel.Size = New System.Drawing.Size(75, 24)
        Me.bCancel.TabIndex = 1
        Me.bCancel.Text = "Cancel"
        '
        'cbType
        '
        Me.cbType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cbType.FormattingEnabled = True
        Me.cbType.Location = New System.Drawing.Point(87, 17)
        Me.cbType.MaxDropDownItems = 20
        Me.cbType.Name = "cbType"
        Me.cbType.Size = New System.Drawing.Size(77, 21)
        Me.cbType.Sorted = True
        Me.cbType.TabIndex = 27
        Me.TipProvider.SetTipName(Me.cbType, "Output Type")
        Me.TipProvider.SetTipText(Me.cbType, "Stream type of the output file.")
        '
        'lOutput
        '
        Me.lOutput.AutoSize = True
        Me.lOutput.Location = New System.Drawing.Point(12, 20)
        Me.lOutput.Name = "lOutput"
        Me.lOutput.Size = New System.Drawing.Size(69, 13)
        Me.lOutput.TabIndex = 28
        Me.lOutput.Text = "Output Type:"
        '
        'cbQualityMode
        '
        Me.cbQualityMode.AutoSize = True
        Me.cbQualityMode.Location = New System.Drawing.Point(202, 20)
        Me.cbQualityMode.Name = "cbQualityMode"
        Me.cbQualityMode.Size = New System.Drawing.Size(88, 17)
        Me.cbQualityMode.TabIndex = 30
        Me.cbQualityMode.Text = "Quality Mode"
        Me.TipProvider.SetTipText(Me.cbQualityMode, "In Quality Mode bitrate related features are disabled.")
        Me.cbQualityMode.UseVisualStyleBackColor = True
        '
        'nudPercent
        '
        Me.nudPercent.Increment = New Decimal(New Integer() {5, 0, 0, 0})
        Me.nudPercent.Location = New System.Drawing.Point(390, 18)
        Me.nudPercent.Maximum = New Decimal(New Integer() {200, 0, 0, 0})
        Me.nudPercent.Name = "nudPercent"
        Me.nudPercent.Size = New System.Drawing.Size(47, 20)
        Me.nudPercent.TabIndex = 31
        Me.nudPercent.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        Me.TipProvider.SetTipName(Me.nudPercent, "Aimed Quality")
        Me.TipProvider.SetTipText(Me.nudPercent, "Adjusts the target file size or image size after the compressibility check. Optim" & _
                "al settings vary between different codecs, codec settings and individual quality" & _
                " requirements.")
        '
        'CompCheckCliControl
        '
        Me.CompCheckCliControl.Location = New System.Drawing.Point(12, 218)
        Me.CompCheckCliControl.Name = "CompCheckCliControl"
        Me.CompCheckCliControl.Size = New System.Drawing.Size(693, 160)
        Me.CompCheckCliControl.TabIndex = 29
        Me.CompCheckCliControl.Text = "Compressibility Check Command Lines"
        '
        'EncodingCliControl
        '
        Me.EncodingCliControl.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.EncodingCliControl.Location = New System.Drawing.Point(12, 52)
        Me.EncodingCliControl.Name = "EncodingCliControl"
        Me.EncodingCliControl.Size = New System.Drawing.Size(693, 160)
        Me.EncodingCliControl.TabIndex = 2
        Me.EncodingCliControl.Text = "Encoding Command Lines"
        '
        'bHelp
        '
        Me.bHelp.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.bHelp.Location = New System.Drawing.Point(630, 385)
        Me.bHelp.Name = "bHelp"
        Me.bHelp.Size = New System.Drawing.Size(75, 24)
        Me.bHelp.TabIndex = 33
        Me.bHelp.Text = "Help"
        Me.bHelp.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText
        Me.bHelp.UseVisualStyleBackColor = True
        '
        'lAimedQuality
        '
        Me.lAimedQuality.AutoSize = True
        Me.lAimedQuality.Location = New System.Drawing.Point(310, 22)
        Me.lAimedQuality.Name = "lAimedQuality"
        Me.lAimedQuality.Size = New System.Drawing.Size(74, 13)
        Me.lAimedQuality.TabIndex = 34
        Me.lAimedQuality.Text = "Aimed Quality:"
        '
        'CmdlEncoderForm
        '
        Me.ClientSize = New System.Drawing.Size(717, 421)
        Me.Controls.Add(Me.lAimedQuality)
        Me.Controls.Add(Me.bHelp)
        Me.Controls.Add(Me.nudPercent)
        Me.Controls.Add(Me.cbQualityMode)
        Me.Controls.Add(Me.CompCheckCliControl)
        Me.Controls.Add(Me.cbType)
        Me.Controls.Add(Me.lOutput)
        Me.Controls.Add(Me.EncodingCliControl)
        Me.Controls.Add(Me.bCancel)
        Me.Controls.Add(Me.bOK)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.HelpButton = True
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "CmdlEncoderForm"
        Me.ShowIcon = False
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "Command Line Encoder"
        CType(Me.nudPercent, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.TipProvider, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private Encoder As CLIEncoder

    Public Sub New(ByVal e As CLIEncoder)
        MyBase.New()
        InitializeComponent()
        Me.Encoder = e

        cbQualityMode.Checked = e.QualityMode
        ListBag(Of StreamType).PopulateList(cbType)
        ListBag(Of StreamType).SelectItem(cbType, e.OutputStreamType)

        EncodingCliControl.CommandLines = e.CommandLines
        EncodingCliControl.HelpFile = e.ParameterFile

        CompCheckCliControl.CommandLines = e.CompCheckCommandLines
        CompCheckCliControl.HelpFile = e.ParameterFile
        nudPercent.Value = e.AutoCompCheckValue
    End Sub

    Private Sub bOK_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bOK.Click
        Encoder.OutputStreamType = ListBag(Of StreamType).GetValue(cbType)
        Encoder.CommandLines = EncodingCliControl.CommandLines
        Encoder.ParameterFile = EncodingCliControl.HelpFile

        Encoder.CompCheckCommandLines = CompCheckCliControl.CommandLines
        Encoder.QualityMode = cbQualityMode.Checked
        Encoder.AutoCompCheckValue = CInt(nudPercent.Value)
    End Sub

    Private Sub EncodingCliControl_ParameterFileTextChanged() Handles EncodingCliControl.ParameterFileTextChanged
        CompCheckCliControl.HelpFile = EncodingCliControl.HelpFile
    End Sub

    Private Sub CompCheckCliControl_ParameterFileTextChanged() Handles CompCheckCliControl.ParameterFileTextChanged
        EncodingCliControl.HelpFile = CompCheckCliControl.HelpFile
    End Sub

    Private Sub bHelp_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bHelp.Click
        Dim f As New HelpForm
        f.Document.WriteStart(Text)
        f.Document.WriteParagraph("The command line encoder allows to configure StaxRip to use any command line compatible encoding application.")
        f.Document.WriteTips(TipProvider.GetTips, EncodingCliControl.TipProvider.GetTips)
        f.Show()
    End Sub

    Private Sub CLIEncoderForm_ActivatedFirstTime() Handles Me.ActivatedFirstTime
        If Not s.StringList.Contains(Me.GetType.FullName) Then
            bHelp.PerformClick()
            s.StringList.Add(Me.GetType.FullName)
        End If
    End Sub
End Class