OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmMain.cs
index 83135c6..453b48a 100644 (file)
@@ -12,20 +12,30 @@ namespace Handbrake
     using System.Drawing;\r
     using System.Globalization;\r
     using System.IO;\r
-    using System.Reflection;\r
     using System.Threading;\r
     using System.Windows.Forms;\r
     using Functions;\r
 \r
+    using HandBrake.Framework.Model;\r
+    using HandBrake.Framework.Services;\r
+    using HandBrake.Framework.Views;\r
+    using HandBrake.ApplicationServices.Functions;\r
     using HandBrake.ApplicationServices.Model;\r
     using HandBrake.ApplicationServices.Parsing;\r
     using HandBrake.ApplicationServices.Services;\r
     using HandBrake.ApplicationServices.Services.Interfaces;\r
 \r
+    using Handbrake.ToolWindows;\r
+\r
     using Model;\r
     using Presets;\r
     using Properties;\r
 \r
+    using Main = Handbrake.Functions.Main;\r
+\r
+    /// <summary>\r
+    /// The Main Window\r
+    /// </summary>\r
     public partial class frmMain : Form\r
     {\r
         // Objects which may be used by one or more other objects *************\r
@@ -90,12 +100,10 @@ namespace Handbrake
 \r
             // Update the users config file with the CLI version data.\r
             Main.SetCliVersionData();\r
-            Main.CheckForValidCliVersion();\r
 \r
             if (Settings.Default.hb_version.Contains("svn"))\r
             {\r
-                Version v = Assembly.GetExecutingAssembly().GetName().Version;\r
-                this.Text += " " + v.ToString(4);\r
+                this.Text += " " + Settings.Default.hb_version;\r
             }\r
 \r
             // Check for new versions, if update checking is enabled\r
@@ -103,7 +111,13 @@ namespace Handbrake
             {\r
                 if (DateTime.Now.Subtract(Settings.Default.lastUpdateCheckDate).TotalDays > Properties.Settings.Default.daysBetweenUpdateCheck)\r
                 {\r
-                    Main.BeginCheckForUpdates(new AsyncCallback(UpdateCheckDone), false);\r
+                    // Set when the last update was\r
+                    Settings.Default.lastUpdateCheckDate = DateTime.Now;\r
+                    Settings.Default.Save();\r
+                    string url = Settings.Default.hb_build.ToString().EndsWith("1")\r
+                                                  ? Settings.Default.appcast_unstable\r
+                                                  : Settings.Default.appcast;\r
+                    UpdateService.BeginCheckForUpdates(new AsyncCallback(UpdateCheckDone), false, url, Settings.Default.hb_build, Settings.Default.skipversion, Settings.Default.hb_version);\r
                 }\r
             }\r
 \r
@@ -169,15 +183,13 @@ namespace Handbrake
                 return;\r
             }\r
 \r
-            UpdateCheckInformation info;\r
-\r
             try\r
             {\r
-                info = Main.EndCheckForUpdates(result);\r
+                UpdateCheckInformation info = UpdateService.EndCheckForUpdates(result);\r
 \r
                 if (info.NewVersionAvailable)\r
                 {\r
-                    frmUpdater updateWindow = new frmUpdater(info.BuildInformation);\r
+                    UpdateInfo updateWindow = new UpdateInfo(info.BuildInformation, Settings.Default.hb_version, Settings.Default.hb_build.ToString());\r
                     updateWindow.ShowDialog();\r
                 }\r
             }\r
@@ -527,7 +539,12 @@ namespace Handbrake
         private void mnu_UpdateCheck_Click(object sender, EventArgs e)\r
         {\r
             lbl_updateCheck.Visible = true;\r
-            Main.BeginCheckForUpdates(new AsyncCallback(this.UpdateCheckDoneMenu), false);\r
+            Settings.Default.lastUpdateCheckDate = DateTime.Now;\r
+            Settings.Default.Save();\r
+            string url = Settings.Default.hb_build.ToString().EndsWith("1")\r
+                                                  ? Settings.Default.appcast_unstable\r
+                                                  : Settings.Default.appcast;\r
+            UpdateService.BeginCheckForUpdates(new AsyncCallback(UpdateCheckDoneMenu), false, url, Settings.Default.hb_build, Settings.Default.skipversion, Settings.Default.hb_version);\r
         }\r
 \r
         /// <summary>\r
@@ -910,7 +927,7 @@ namespace Handbrake
             MessageBox.Show("This feature has not been implimented yet.", "Not Implimented", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
             return;\r
 \r
-            SaveFileDialog savefiledialog = new SaveFileDialog();\r
+            /*SaveFileDialog savefiledialog = new SaveFileDialog();\r
             savefiledialog.Filter = "plist|*.plist";\r
 \r
             if (treeView_presets.SelectedNode != null)\r
@@ -921,7 +938,7 @@ namespace Handbrake
                     Preset preset = presetHandler.GetPreset(treeView_presets.SelectedNode.Text);\r
                     PlistPresetHandler.Export(savefiledialog.FileName, preset);\r
                 }\r
-            }\r
+            }*/\r
         }\r
 \r
         #endregion\r
@@ -1106,7 +1123,7 @@ namespace Handbrake
             // Make sure the destination path exists.\r
             if (!Directory.Exists(Path.GetDirectoryName(jobDestination)))\r
             {\r
-                MessageBox.Show("Destination Path does not exist.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+                MessageBox.Show(string.Format("Destination Path does not exist.\nPath: {0}\n\nThis item was not added to the Queue.", Path.GetDirectoryName(jobDestination)), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
                 return;\r
             }\r
 \r
@@ -1115,7 +1132,7 @@ namespace Handbrake
             {\r
                 DialogResult result =\r
                     MessageBox.Show(\r
-                        "There is already a queue item for this destination path. \n\n If you continue, the encode will be overwritten. Do you wish to continue?",\r
+                        string.Format("There is already a queue item for this destination path.\nDestination Path: {0} \n\nIf you continue, the encode will be overwritten. Do you wish to continue?", jobDestination),\r
                         "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);\r
                 if (result == DialogResult.Yes)\r
                     encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));\r
@@ -1126,7 +1143,6 @@ namespace Handbrake
             lbl_encode.Text = encodeQueue.Count + " encode(s) pending in the queue";\r
 \r
             queueWindow.Show();\r
-\r
         }\r
 \r
         /// <summary>\r
@@ -1257,29 +1273,31 @@ namespace Handbrake
         #region Main Window and Tab Control\r
 \r
         // Source\r
-        private void btn_dvd_source_Click(object sender, EventArgs e)\r
+        private void BtnFolderScanClicked(object sender, EventArgs e)\r
         {\r
+            this.btn_source.HideDropDown();\r
             if (DVD_Open.ShowDialog() == DialogResult.OK)\r
             {\r
                 this.selectedSourceType = SourceType.Folder;\r
-                SelectSource(DVD_Open.SelectedPath);\r
+                SelectSource(DVD_Open.SelectedPath, 0);\r
             }\r
             else\r
                 UpdateSourceLabel();\r
         }\r
 \r
-        private void btn_file_source_Click(object sender, EventArgs e)\r
+        private void BtnFileScanClicked(object sender, EventArgs e)\r
         {\r
+            this.btn_source.HideDropDown();\r
             if (ISO_Open.ShowDialog() == DialogResult.OK)\r
             {\r
                 this.selectedSourceType = SourceType.VideoFile;\r
-                SelectSource(ISO_Open.FileName);\r
+                SelectSource(ISO_Open.FileName, 0);\r
             }\r
             else\r
                 UpdateSourceLabel();\r
         }\r
 \r
-        private void mnu_dvd_drive_Click(object sender, EventArgs e)\r
+        private void MnuDvdDriveClick(object sender, EventArgs e)\r
         {\r
             ToolStripMenuItem item = sender as ToolStripMenuItem;\r
             if (item != null)\r
@@ -1288,18 +1306,55 @@ namespace Handbrake
                 int id;\r
                 if (int.TryParse(driveId, out id))\r
                 {\r
-\r
                     this.dvdDrivePath = drives[id].RootDirectory;\r
                     this.dvdDriveLabel = drives[id].VolumeLabel;\r
 \r
                     if (this.dvdDrivePath == null) return;\r
                     this.selectedSourceType = SourceType.DvdDrive;\r
-                    SelectSource(this.dvdDrivePath);\r
+                    SelectSource(this.dvdDrivePath, 0);\r
+                }\r
+            }\r
+        }\r
+\r
+        private void VideoTitleSpecificScanClick(object sender, EventArgs e)\r
+        {\r
+            this.btn_source.HideDropDown();\r
+            if (ISO_Open.ShowDialog() == DialogResult.OK)\r
+            {\r
+                this.selectedSourceType = SourceType.VideoFile;\r
+\r
+                int sourceTitle = 0;\r
+                TitleSpecificScan title = new TitleSpecificScan();\r
+                if (title.ShowDialog() == DialogResult.OK)\r
+                {\r
+                    sourceTitle = title.Title;\r
+                    SelectSource(ISO_Open.FileName, sourceTitle);\r
                 }\r
             }\r
+            else\r
+                UpdateSourceLabel();\r
         }\r
 \r
-        private void SelectSource(string file)\r
+        private void FolderTitleSpecificScanClick(object sender, EventArgs e)\r
+        {\r
+            this.btn_source.HideDropDown();\r
+            if (DVD_Open.ShowDialog() == DialogResult.OK)\r
+            {\r
+                this.selectedSourceType = SourceType.Folder;\r
+\r
+                int sourceTitle = 0;\r
+                TitleSpecificScan title = new TitleSpecificScan();\r
+                if (title.ShowDialog() == DialogResult.OK)\r
+                {\r
+                    sourceTitle = title.Title;\r
+                    SelectSource(DVD_Open.SelectedPath, sourceTitle);\r
+                }\r
+            }\r
+            else\r
+                UpdateSourceLabel();\r
+        }\r
+\r
+        private void SelectSource(string file, int titleSpecific)\r
         {\r
             Check_ChapterMarkers.Enabled = true;\r
             sourcePath = string.Empty;\r
@@ -1311,7 +1366,7 @@ namespace Handbrake
             }\r
 \r
             sourcePath = Path.GetFileName(file);\r
-            StartScan(file, 0);\r
+            StartScan(file, titleSpecific);\r
         }\r
 \r
         private void drp_dvdtitle_Click(object sender, EventArgs e)\r
@@ -1349,6 +1404,12 @@ namespace Handbrake
                     for (int i = 1; i <= selectedTitle.AngleCount; i++)\r
                         drop_angle.Items.Add(i.ToString());\r
 \r
+                    if (drop_angle.Items.Count == 0)\r
+                    {\r
+                        drop_angle.Visible = false;\r
+                        lbl_angle.Visible = false;\r
+                    }\r
+\r
                     if (drop_angle.Items.Count != 0)\r
                         drop_angle.SelectedIndex = 0;\r
                 }\r
@@ -1371,7 +1432,7 @@ namespace Handbrake
                     drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();\r
 \r
                 // Populate the Audio Channels Dropdown\r
-                AudioSettings.SetTrackList(selectedTitle, this.currentlySelectedPreset);\r
+                AudioSettings.SetTrackListFromPreset(selectedTitle, this.currentlySelectedPreset);\r
 \r
                 // Populate the Subtitles dropdown\r
                 Subtitles.SetSubtitleTrackAuto(selectedTitle.Subtitles.ToArray());\r
@@ -1389,7 +1450,7 @@ namespace Handbrake
                     text_destination.Text = autoPath;\r
                 else\r
                     MessageBox.Show(\r
-                        "You currently have \"Automatically name output files\" enabled for the destination file box, but you do not have a default directory set.\n\nYou should set a \"Default Path\" in HandBrakes preferences. (See 'Tools' menu -> 'Options' -> 'General' Tab -> 'Default Path')",\r
+                        "You currently have \"Automatically name output files\" enabled for the destination file box, but you do not have a valid default directory set.\n\nYou should set a \"Default Path\" in HandBrakes preferences. (See 'Tools' menu -> 'Options' -> 'General' Tab -> 'Default Path')",\r
                         "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
             }\r
 \r
@@ -1761,7 +1822,7 @@ namespace Handbrake
             }\r
         }\r
 \r
-        private double _cachedCqStep = Properties.Settings.Default.x264cqstep;\r
+        private double cachedCqStep = Properties.Settings.Default.x264cqstep;\r
 \r
         /// <summary>\r
         /// Update the CQ slider for x264 for a new CQ step. This is set from option\r
@@ -1769,7 +1830,7 @@ namespace Handbrake
         public void setQualityFromSlider()\r
         {\r
             // Work out the current RF value.\r
-            double cqStep = _cachedCqStep;\r
+            double cqStep = this.cachedCqStep;\r
             double rfValue = 51.0 - slider_videoQuality.Value * cqStep;\r
 \r
             // Change the maximum value for the slider\r
@@ -1788,7 +1849,7 @@ namespace Handbrake
             }\r
 \r
             // Cache the CQ step for the next calculation\r
-            _cachedCqStep = Properties.Settings.Default.x264cqstep;\r
+            this.cachedCqStep = Properties.Settings.Default.x264cqstep;\r
         }\r
 \r
         private void slider_videoQuality_Scroll(object sender, EventArgs e)\r
@@ -1989,7 +2050,7 @@ namespace Handbrake
                 BeginInvoke(new UpdateWindowHandler(UpdateScanStatusLabel));\r
                 return;\r
             }\r
-            lbl_encode.Text = SourceScan.ScanStatus;\r
+            labelSource.Text = SourceScan.ScanStatus;\r
         }\r
 \r
         /// <summary>\r
@@ -2070,7 +2131,6 @@ namespace Handbrake
             {\r
                 if (InvokeRequired)\r
                     BeginInvoke(new UpdateWindowHandler(EnableGUI));\r
-                lbl_encode.Text = "Scan Completed";\r
                 foreach (Control ctrl in Controls)\r
                     ctrl.Enabled = true;\r
                 btn_start.Enabled = true;\r
@@ -2095,8 +2155,9 @@ namespace Handbrake
                 if (!(ctrl is StatusStrip || ctrl is MenuStrip || ctrl is ToolStrip))\r
                     ctrl.Enabled = false;\r
 \r
-            lbl_encode.Visible = true;\r
-            lbl_encode.Text = "Scanning ...";\r
+            labelSource.Enabled = true;\r
+            labelStaticSource.Enabled = true;\r
+            SourceLayoutPanel.Enabled = true;\r
             btn_source.Enabled = false;\r
             btn_start.Enabled = false;\r
             btn_showQueue.Enabled = false;\r
@@ -2295,7 +2356,7 @@ namespace Handbrake
                             Text = drive.RootDirectory + " (" + drive.VolumeLabel + ")",\r
                             Image = Resources.disc_small\r
                         };\r
-                    menuItem.Click += new EventHandler(mnu_dvd_drive_Click);\r
+                    menuItem.Click += new EventHandler(MnuDvdDriveClick);\r
                     menuItems.Add(menuItem);\r
                 }\r
 \r
@@ -2359,11 +2420,11 @@ namespace Handbrake
             try\r
             {\r
                 // Get the information about the new build, if any, and close the window\r
-                info = Main.EndCheckForUpdates(result);\r
+                info = UpdateService.EndCheckForUpdates(result);\r
 \r
                 if (info.NewVersionAvailable && info.BuildInformation != null)\r
                 {\r
-                    frmUpdater updateWindow = new frmUpdater(info.BuildInformation);\r
+                    UpdateInfo updateWindow = new UpdateInfo(info.BuildInformation, Settings.Default.hb_version, Settings.Default.hb_build.ToString());\r
                     updateWindow.ShowDialog();\r
                 }\r
                 else\r