VERSION 5.00
Begin VB.Form frmJobsList 
   BorderStyle     =   5  'Sizable ToolWindow
   Caption         =   "Jobs List"
   ClientHeight    =   1845
   ClientLeft      =   60
   ClientTop       =   300
   ClientWidth     =   11580
   ControlBox      =   0   'False
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   HelpContextID   =   50
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   1845
   ScaleWidth      =   11580
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Pls_Load_List 
      Caption         =   "Load List"
      Height          =   390
      Left            =   10740
      Style           =   1  'Graphical
      TabIndex        =   6
      ToolTipText     =   "Load Jobs List from an external file"
      Top             =   900
      Visible         =   0   'False
      Width           =   700
   End
   Begin VB.CommandButton Pls_Save_List 
      Caption         =   "Save List"
      Height          =   390
      Left            =   10740
      Style           =   1  'Graphical
      TabIndex        =   5
      ToolTipText     =   "Save Jobs List to external file"
      Top             =   510
      Visible         =   0   'False
      Width           =   700
   End
   Begin VB.CommandButton Pls_Add_Job 
      Caption         =   "Add Job"
      Height          =   390
      Left            =   10020
      Style           =   1  'Graphical
      TabIndex        =   1
      ToolTipText     =   "Add current Job"
      Top             =   120
      Visible         =   0   'False
      Width           =   700
   End
   Begin VB.CommandButton Pls_Move_Up 
      Caption         =   "Move Up Job"
      Height          =   390
      Left            =   10020
      Style           =   1  'Graphical
      TabIndex        =   2
      ToolTipText     =   "Move current Job up"
      Top             =   510
      Visible         =   0   'False
      Width           =   700
   End
   Begin VB.CommandButton Pls_Remove_Job 
      Caption         =   "Remove Job"
      Height          =   390
      Left            =   10020
      Style           =   1  'Graphical
      TabIndex        =   3
      ToolTipText     =   "Remove selected Job"
      Top             =   900
      Visible         =   0   'False
      Width           =   700
   End
   Begin VB.CommandButton Pls_Erase_List 
      Caption         =   "Erase List"
      Height          =   390
      Left            =   10740
      Style           =   1  'Graphical
      TabIndex        =   4
      ToolTipText     =   "Erase all Jobs from Jobs List"
      Top             =   120
      Visible         =   0   'False
      Width           =   700
   End
   Begin VB.CommandButton Pls_Batch_Start 
      Caption         =   "Batch START"
      Height          =   390
      Left            =   10020
      Style           =   1  'Graphical
      TabIndex        =   7
      ToolTipText     =   "Start Jobs List batch encoding"
      Top             =   1320
      Visible         =   0   'False
      Width           =   1425
   End
   Begin VB.ListBox JobsList 
      Height          =   1635
      Left            =   120
      Style           =   1  'Checkbox
      TabIndex        =   0
      Top             =   120
      Width           =   9735
   End
   Begin VB.Image Img_Load_List 
      Height          =   255
      Left            =   10965
      Top             =   960
      Width           =   375
   End
   Begin VB.Image Img_Save_List 
      Height          =   255
      Left            =   10965
      Top             =   600
      Width           =   375
   End
   Begin VB.Image Img_Batch_Start 
      Height          =   255
      Left            =   10605
      Top             =   1380
      Width           =   375
   End
   Begin VB.Image Img_Erase_List 
      Height          =   255
      Left            =   10965
      Top             =   180
      Width           =   375
   End
   Begin VB.Image Img_Remove_Job 
      Height          =   255
      Left            =   10245
      Top             =   960
      Width           =   375
   End
   Begin VB.Image Img_Move_Up 
      Height          =   255
      Left            =   10245
      Top             =   570
      Width           =   375
   End
   Begin VB.Image Img_Add_Job 
      Height          =   255
      Left            =   10245
      Top             =   180
      Width           =   375
   End
End
Attribute VB_Name = "frmJobsList"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' -------------------------------------------------------------------------------
'
'   AVStoDVD - by MrC
'   File: frmJobsList.frm
'   Purpose: List of Jobs for batch encoding
'
' -------------------------------------------------------------------------------


Option Explicit
Option Compare Binary
Option Base 0


Private Type frmDim
    Width As Long
    Height As Long
End Type

Private frmOrigDim As frmDim

Private Sub Form_Load()

    ' Load Language: already loaded in frmMain
    
    frmOrigDim.Height = Me.Height
    frmOrigDim.Width = Me.Width

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Call Reset_Buttons_Visibilty
    
End Sub

Private Sub Form_Activate()

    With frmMain
        If .WindowState = 0 Then
            frmOrigDim.Width = Me.Width
        End If
        Me.Top = .Top + .Height
        Me.Left = .Left
    End With
    
End Sub

Private Sub Form_Resize()

    If Me.Visible = True And frmMain.WindowState = 0 Then
        If Me.Height < frmOrigDim.Height Then
            Me.Height = frmOrigDim.Height
        Else
            Me.JobsList.Height = Me.Height - 570
        End If
        If Me.Width < frmOrigDim.Width Then
            Me.Width = frmOrigDim.Width
        Else
            Me.JobsList.Width = Me.Width - 2080
            Me.Pls_Add_Job.Left = Me.Width - 1800
            Me.Pls_Move_Up.Left = Me.Pls_Add_Job.Left
            Me.Pls_Remove_Job.Left = Me.Pls_Add_Job.Left
            Me.Img_Add_Job.Left = Me.Width - 1575
            Me.Img_Move_Up.Left = Me.Img_Add_Job.Left
            Me.Img_Remove_Job.Left = Me.Img_Add_Job.Left
            Me.Pls_Erase_List.Left = Me.Width - 1080
            Me.Pls_Load_List.Left = Me.Pls_Erase_List.Left
            Me.Pls_Save_List.Left = Me.Pls_Erase_List.Left
            Me.Img_Erase_List.Left = Me.Width - 855
            Me.Img_Load_List.Left = Me.Img_Erase_List.Left
            Me.Img_Save_List.Left = Me.Img_Erase_List.Left
            Me.Pls_Batch_Start.Left = Me.Pls_Add_Job.Left
            Me.Img_Batch_Start.Left = Me.Width - 1215
        End If
        
    End If

End Sub

Private Sub Form_Unload(Cancel As Integer)

    frmMain.Toolbar.Buttons("Jobs_List").value = tbrUnpressed

End Sub

Private Sub JobsList_Click()

    ' Switch between Jobs
    
    If frmJobsList.Pls_Add_Job.Visible = False Then
        modMain.Load_AVStoDVD_Job JobsListStr(Me.JobsList.ListIndex + 1)
    End If
    
End Sub

Private Sub JobsList_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Call Reset_Buttons_Visibilty
    
End Sub

Private Sub Pls_Add_Job_Click()

    ' Add current Job from Main Window to Jobs List
    
    Dim JobListName As String
    Dim sJob As String
    
    If NumTitles > 0 Then
        With Me.JobsList
            If .ListCount = MaxJobs Then
                MsgBox "You have reached Jobs number limit (" & MaxJobs & "). No more Jobs can be added.", vbInformation, App.Title
            Else
                JobListName = InputBox("Enter Job name:", App.Title, Title(CurrentTitle).TitleName)
                If JobListName <> "" Then
                    JobListName = JobListName & " (" & Format(Now, "yyyy" & "mm" & "dd" & "hh" & "nn" & "ss") & ")"
                    sJob = modMain.Create_Job_Save_Str(JobListName)
                    If sJob <> "" Then
                        .AddItem JobListName
                        JobsListStr(.ListCount) = sJob
                        .Selected(.ListCount - 1) = True
                        modMain.Save_Log_Video "Job """ & JobListName & """ added to Jobs List."
                    Else
                        modMain.Save_Log_Video "Warning! Errors found when adding Job """ & JobListName & """ to Jobs List.", , True
                    End If
                End If
            End If
        End With
    End If

End Sub

Private Sub Img_Add_Job_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Call Reset_Buttons_Visibilty
    Me.Pls_Add_Job.Visible = True

End Sub

Private Sub Pls_Move_Up_Click()

    ' Move upward active Job
    
    Dim StrTemp As String
    Dim CheckTemp
    
    With Me.JobsList
        If .ListIndex > 0 Then
            StrTemp = JobsListStr(.ListIndex + 1)
            CheckTemp = .Selected(.ListIndex)
            .AddItem .Text, .ListIndex - 1
            JobsListStr(.ListIndex + 1) = JobsListStr(.ListIndex)
            JobsListStr(.ListIndex) = StrTemp
            .RemoveItem .ListIndex + 1
            .Selected(.ListIndex - 1) = True
            If CheckTemp = False Then
                .Selected(.ListIndex) = CheckTemp
            End If
        End If
    End With
        
End Sub

Private Sub Img_move_up_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Call Reset_Buttons_Visibilty
    Me.Pls_Move_Up.Visible = True

End Sub

Private Sub Pls_Remove_Job_Click()
    
    ' Delete selected Job
    
    Dim jj As Integer
    Dim JobListName As String
    
    On Error GoTo Err_Handling
    
    With Me.JobsList
        If .ListCount > 0 Then
            If MsgBox("Do you really want to delete selected Job?", vbQuestion + vbYesNo, App.Title) = vbYes Then
                JobListName = .List(.ListIndex)
                For jj = .ListIndex To .ListCount - 1
                    If jj < .ListCount - 1 Then
                        JobsListStr(jj) = JobsListStr(jj + 1)
                    End If
                Next jj
                .RemoveItem .ListIndex
                If .ListIndex > -1 Then
                    modMain.Load_AVStoDVD_Job JobsListStr(.ListIndex + 1)
                End If
                modMain.Save_Log_Video "Job """ & JobListName & """ removed from Jobs List."
            End If
        End If
    End With
    
    Exit Sub
    
Err_Handling:
MsgBox "Error " & Err.Number & vbCrLf & vbCrLf & Err.Description, vbCritical, App.Title
    
End Sub

Private Sub Img_Remove_Job_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Call Reset_Buttons_Visibilty
    Me.Pls_Remove_Job.Visible = True

End Sub

Private Sub Pls_Erase_List_Click()

    ' Erase all the List
    
    With Me.JobsList
        If .ListCount > 0 Then
            If MsgBox("Do you really want to erase Jobs List?", vbQuestion + vbYesNo, App.Title) = vbYes Then
                Erase JobsListStr
                Do Until .ListCount = 0
                    .RemoveItem .ListCount - 1
                Loop
                modMain.Save_Log_Video "Jobs List erased."
            End If
        End If
    End With

End Sub

Private Sub Img_Erase_List_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Call Reset_Buttons_Visibilty
    Me.Pls_Erase_List.Visible = True

End Sub

Private Sub Img_Save_List_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Call Reset_Buttons_Visibilty
    Me.Pls_Save_List.Visible = True

End Sub

Private Sub Pls_Save_List_Click()

    Dim PathnameSave As String
    Dim StrSave As String
    Dim jj As Integer
    Dim bFlag As Boolean
    
    If NumTitles > 0 Then
        Do
            PathnameSave = modDialog.SaveFile(Me.hwnd, "Save AVStoDVD Jobs List", "AVStoDVD Jobs List File (*.a2djobs)|*.a2djobs|All Files (*.*)|*.*", Preferences.ProjectsPath, "List_" & Format(Now, "yyyy" & "mm" & "dd" & "hh" & "nn" & "ss") & ".a2djobs", cdlOFNFileMustExist + cdlOFNExplorer + cdlOFNLongNames + cdlOFNHideReadOnly)
            If PathnameSave <> "" Then
                If UCase(modFS.ExtOf(PathnameSave)) <> "A2DJOBS" Then
                    PathnameSave = PathnameSave & ".a2djobs"
                End If
            Else
                Exit Sub
            End If
            If modFS.EsisteFile(PathnameSave) = True Then
                If MsgBox(Msgs.FileExistsOverwrite, vbQuestion + vbYesNo, App.Title) = vbYes Then Exit Do
            End If
        Loop Until modFS.EsisteFile(PathnameSave) = False
        'modMain.Save_Preferences_InputPath PathnameSave
            
        With Me.JobsList
            StrSave = ""
            For jj = 1 To .ListCount
                StrSave = StrSave & "JOB " & jj & ": " & .List(jj - 1) & vbCrLf & vbCrLf & JobsListStr(jj) & vbCrLf & vbCrLf & vbCrLf
            Next jj
            If StrSave <> "" Then
                StrSave = Left(StrSave, Len(StrSave) - 6)
                bFlag = modStr.STRtoANSIFile(StrSave, PathnameSave)
            End If
            If bFlag = True Then
                modMain.Save_Log_Video "File '" & PathnameSave & "' successfully saved.", False, True
            Else
                modMain.Save_Log_Video "Warning! File '" & PathnameSave & "' not saved.", False, True
            End If
        End With
    End If


End Sub

Private Sub Img_Load_List_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Call Reset_Buttons_Visibilty
    Me.Pls_Load_List.Visible = True

End Sub

Private Sub Pls_Load_List_Click()

    Dim NomeFileOpen As String
    Dim StrOpen As String
    Dim Str As String
    Dim NumFile As Integer
    Dim JobListName As String
    Dim jj As Integer
    Dim kk As Integer
    
    If Me.JobsList.ListCount > 0 Then
        If MsgBox("Warning! Loading an existing Jobs List will discard current List." & vbCrLf & vbCrLf & "Do you want to continue?", vbExclamation + vbYesNo, App.Title) = vbNo Then
            Exit Sub
        End If
    End If
    
    Erase JobsListStr
    
    ' Open AVStoDVD Jobs List file
    NomeFileOpen = modDialog.OpenFile(Me.hwnd, "Open AVStoDVD Jobs List", "AVStoDVD Jobs List File (*.a2djobs)|*.a2djobs|All Files (*.*)|*.*", Preferences.InputPath, "", cdlOFNFileMustExist Or cdlOFNExplorer Or cdlOFNLongNames)
    If NomeFileOpen <> "" Then
        modMain.Save_Preferences_InputPath NomeFileOpen
        Screen.MousePointer = vbHourglass
        NumFile = FreeFile
        Open NomeFileOpen For Input As #NumFile
            StrOpen = ""
            Do Until EOF(NumFile) = True
                StrOpen = StrOpen & Input(1, #NumFile)
            Loop
            Do
                jj = InStr(1, StrOpen, "JOB " & Me.JobsList.ListCount + 1 & ": ")
                If jj <> 0 Then
                    Str = ""
                    kk = jj
                    Do
                        Str = Str & Mid(StrOpen, kk, 1)
                        kk = kk + 1
                    Loop Until Right(Str, 9) = " - by MrC"
                    JobListName = Left(Str, InStr(1, Str, Chr(13)) - 1)
                    JobListName = Right(JobListName, Len(JobListName) - InStr(1, JobListName, ":"))
                    JobListName = modStr.RemoveCharBegEnd(JobListName, " ")
                    If JobListName <> "" Then
                        With Me.JobsList
                            .AddItem JobListName
                            JobsListStr(.ListCount) = Str
                            .Selected(.ListCount - 1) = True
                        End With
                        modMain.Save_Log_Video "Job """ & JobListName & """ added to Jobs List."
                    End If
                End If
            Loop Until jj = 0
        Screen.MousePointer = vbDefault
        modMain.Save_Log_Video "AVStoDVD Jobs List """ & NomeFileOpen & """ loaded."
    End If

End Sub

Private Sub Pls_Batch_Start_Click()

    ' Start batch encoding
    
    Dim jj As Integer
    Dim bFlagErr As Boolean
    
    On Error GoTo Err_Handling
    
    With Me.JobsList
        If .ListCount > 0 Then
            If MsgBox("Start Batch encoding?", vbQuestion + vbYesNo, App.Title) = vbYes Then
                For jj = 1 To .ListCount
                    If .Selected(jj - 1) = True Then
                        modMain.Load_AVStoDVD_Job JobsListStr(jj)
                        .Tag = jj
                        Me.Caption = "Jobs List - " & .Tag & "/" & .ListCount
                        modMain.Change_Settings
                        modMain.Define_BitRates_DVDSize
                        modStart.Start
                        If frmMain.lViewOper.ListItems.Item(frmMain.lViewOper.ListItems.Count).SmallIcon = 7 Then   ' 7 -> error icon
                            bFlagErr = True
                        End If
                        Unload frmProgress
                    End If
                Next jj
                .Tag = ""
                Select Case frmMain.Cmb_PostProcess.ListIndex
                Case 0
                    Me.Caption = "Jobs List"
                    frmMain.Show
                    frmJobsList.Show
                    If bFlagErr = False Then
                        modMain.Save_Log_Video "Batch encoding succesfully completed.", False, True
                    Else
                        modMain.Save_Log_Video "Warning! One of the Jobs has ended with errors. Check Operations Log for more info.", False, True
                    End If
                Case 1
                    modMain.Quit False
                Case 2
                    modMain.Quit True
                End Select
            End If
        End If
    End With
    
    Exit Sub
    
Err_Handling:
Me.Caption = "Jobs List"
Me.JobsList.Tag = ""
frmMain.Show
frmJobsList.Show
modMain.Save_Log_Video "Error! Batch encoding aborted!", False, True
    
End Sub

Private Sub Img_Batch_Start_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Call Reset_Buttons_Visibilty
    Me.Pls_Batch_Start.Visible = True

End Sub

Private Sub Reset_Buttons_Visibilty()

    Me.Pls_Add_Job.Visible = False
    Me.Pls_Move_Up.Visible = False
    Me.Pls_Remove_Job.Visible = False
    Me.Pls_Erase_List.Visible = False
    Me.Pls_Save_List.Visible = False
    Me.Pls_Load_List.Visible = False
    Me.Pls_Batch_Start.Visible = False

End Sub

