/* This file is part of AHD Subtitles Maker Professional
   A program can create and edit subtitles

   Copyright © Ala I Hadid 2009 - 2012

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AHD.MKV;
using AHD.SM.ASMP;
using AHD.Forms;
using System.Reflection;
using System.Resources;
namespace AHD.SM.Forms
{
    public partial class Frm_MatroskaRipper : Form
    {
        public Frm_MatroskaRipper(Project project)
        {
            InitializeComponent();
            this.project = project;
            MKVFile file = new MKVFile(project.MediaPath);
            if (!file.IsVaild)
            {
                MessageDialog.ShowErrorMessage(resources.GetString("Message_UnableToOpenMKV"), resources.GetString("Error"));
                this.Close();
                return;
            }
            //load tracks 
            foreach (MkvSubtitlesTrackInfo track in file.SubtitleTracks)
            {
                comboBox1.Items.Add(track);
            }
            comboBox1.SelectedIndex = 0;
        }
        Project project;
        SubtitlesTrack track;
        ResourceManager resources = new ResourceManager("AHD.SM.Forms.LanguageResources.Resource",
         Assembly.GetExecutingAssembly());

        public SubtitlesTrack SubtitlesTrackGenerated
        { get { return track; } }
        //ok
        private void button1_Click(object sender, EventArgs e)
        {
            MkvSubtitlesTrackInfo trck = (MkvSubtitlesTrackInfo)comboBox1.SelectedItem;
            MKVFile file = new MKVFile(project.MediaPath);
            if (file.IsVaild)
            {
                track = file.GetSubtitlesTrack(project.MediaPath, trck);
                if (track != null)
                { 
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    Close(); 
                    return;
                }
                else
                {
                    MessageBox.Show(resources.GetString("Message_CantRipThisTrackOrCanceledByUser"));
                    return;
                }
            }
            MessageBox.Show(resources.GetString("Message_InvaildeMkv"));
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
