Files
Aaru/DiscImageChef.Gui/frmMain.xeto.cs

229 lines
8.3 KiB
C#
Raw Normal View History

2018-08-27 18:29:55 +01:00
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : frmMain.xeto.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Main window.
//
// --[ Description ] ----------------------------------------------------------
//
// Implements main GUI window.
//
// --[ License ] --------------------------------------------------------------
//
// 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/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2018 Natalia Portillo
// ****************************************************************************/
2018-08-28 23:29:06 +01:00
2018-08-27 15:07:51 +01:00
using System;
2018-08-27 18:25:11 +01:00
using System.ComponentModel;
2018-08-27 15:07:51 +01:00
using System.Linq;
2018-08-27 18:25:11 +01:00
using DiscImageChef.Console;
2018-08-27 15:07:51 +01:00
using DiscImageChef.Devices;
using Eto.Forms;
using Eto.Serialization.Xaml;
namespace DiscImageChef.Gui
{
public class frmMain : Form
{
2018-08-27 18:25:11 +01:00
bool closing;
2018-09-02 01:41:03 +01:00
GridView grdFiles;
Label lblError;
2018-08-27 15:07:51 +01:00
TreeGridView treeImages;
TreeGridItemCollection treeImagesItems;
2018-08-27 18:25:11 +01:00
public frmMain(bool debug, bool verbose)
2018-08-27 15:07:51 +01:00
{
XamlReader.Load(this);
2018-09-02 01:41:03 +01:00
lblError = new Label();
grdFiles = new GridView();
2018-08-27 18:25:11 +01:00
ConsoleHandler.Init();
ConsoleHandler.Debug = debug;
ConsoleHandler.Verbose = verbose;
2018-08-27 15:07:51 +01:00
treeImagesItems = new TreeGridItemCollection();
treeImages.Columns.Add(new GridColumn {HeaderText = "Name", DataCell = new TextBoxCell(0)});
treeImages.AllowMultipleSelection = false;
treeImages.ShowHeader = false;
treeImages.DataStore = treeImagesItems;
2018-08-27 18:25:11 +01:00
imagesRoot = new TreeGridItem {Values = new object[] {"Images"}};
2018-08-27 15:07:51 +01:00
devicesRoot = new TreeGridItem {Values = new object[] {"Devices"}};
treeImagesItems.Add(imagesRoot);
treeImagesItems.Add(devicesRoot);
2018-08-27 18:25:11 +01:00
Closing += OnClosing;
}
void OnClosing(object sender, CancelEventArgs e)
{
// This prevents an infinite loop of crashes :p
if(closing) return;
closing = true;
Application.Instance.Quit();
2018-08-27 15:07:51 +01:00
}
protected void OnMenuOpen(object sender, EventArgs e)
{
MessageBox.Show("Not yet implemented");
}
protected void OnMenuAbout(object sender, EventArgs e)
{
2018-08-27 18:43:18 +01:00
AboutDialog dlgAbout = new AboutDialog
{
Developers = new[] {"Natalia Portillo", "Michael Drüing"},
License = "This program is free software: you can redistribute it and/or modify\n" +
"it under the terms of the GNU General public License as\n" +
"published by the Free Software Foundation, either version 3 of the\n" +
"License, or (at your option) any later version.\n\n" +
"This program is distributed in the hope that it will be useful,\n" +
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
"GNU General public License for more details.\n\n" +
"You should have received a copy of the GNU General public License\n" +
"along with this program. If not, see <http://www.gnu.org/licenses/>.",
ProgramName = "The Disc Image Chef",
Website = new Uri("https://github.com/claunia"),
WebsiteLabel = "Source code on..."
};
dlgAbout.ShowDialog(this);
2018-08-27 15:07:51 +01:00
}
protected void OnMenuQuit(object sender, EventArgs e)
{
Application.Instance.Quit();
}
protected void OnDeviceRefresh(object sender, EventArgs e)
{
RefreshDevices();
}
protected override void OnLoadComplete(EventArgs e)
{
base.OnLoadComplete(e);
RefreshDevices();
}
void RefreshDevices()
{
try
2018-08-27 15:07:51 +01:00
{
DicConsole.WriteLine("Refreshing devices");
devicesRoot.Children.Clear();
2018-08-28 23:29:06 +01:00
foreach(DeviceInfo device in Device.ListDevices().Where(d => d.Supported).OrderBy(d => d.Vendor)
.ThenBy(d => d.Model))
2018-08-27 15:07:51 +01:00
{
DicConsole.DebugWriteLine("Main window",
2018-08-28 23:29:06 +01:00
"Found supported device model {0} by manufacturer {1} on bus {2} and path {3}",
device.Model, device.Vendor, device.Bus, device.Path);
devicesRoot.Children.Add(new TreeGridItem
{
2018-09-02 01:41:03 +01:00
Values = new object[]
{
$"{device.Vendor} {device.Model} ({device.Bus})",
device.Path, null
}
});
}
treeImages.ReloadData();
}
2018-08-28 23:29:06 +01:00
catch(InvalidOperationException ex) { DicConsole.ErrorWriteLine(ex.Message); }
2018-08-27 15:07:51 +01:00
}
2018-08-27 18:25:11 +01:00
protected void OnMenuConsole(object sender, EventArgs e)
{
new frmConsole().Show();
}
2018-08-28 23:29:06 +01:00
protected void OnMenuPlugins(object sender, EventArgs e)
{
new dlgPlugins().ShowModal(this);
}
protected void OnMenuEncodings(object sender, EventArgs e)
{
new dlgEncodings().ShowModal(this);
}
2018-09-02 01:41:03 +01:00
protected void OnTreeImagesSelectedItemChanged(object sender, EventArgs e)
{
if(!(sender is TreeGridView tree)) return;
if(!(tree.SelectedItem is TreeGridItem selectedItem)) return;
splMain.Panel2 = null;
if(selectedItem.Parent != devicesRoot) return;
switch(selectedItem.Values[2])
{
case null:
try
{
Device dev = new Device((string)selectedItem.Values[1]);
if(dev.Error)
{
selectedItem.Values[2] = $"Error {dev.LastError} opening device";
return;
}
Core.Devices.Info.DeviceInfo devInfo = new Core.Devices.Info.DeviceInfo(dev);
selectedItem.Values[2] = new pnlDeviceInfo(devInfo);
splMain.Panel2 = (Panel)selectedItem.Values[2];
dev.Close();
}
catch(SystemException ex)
{
selectedItem.Values[2] = ex.Message;
lblError.Text = ex.Message;
splMain.Panel2 = lblError;
DicConsole.ErrorWriteLine(ex.Message);
}
break;
case string devErrorMessage:
lblError.Text = devErrorMessage;
splMain.Panel2 = lblError;
break;
case Panel devInfoPanel:
splMain.Panel2 = devInfoPanel;
break;
}
}
2018-08-27 15:07:51 +01:00
#region XAML IDs
TreeGridItem devicesRoot;
TreeGridItem imagesRoot;
2018-09-02 01:41:03 +01:00
Splitter splMain;
2018-08-27 15:07:51 +01:00
#endregion
}
}