// Created with MonoDevelop
//
//    QuickStep: Acquire, view and identify spectra 
//    Copyright (C) 2012 Thomas Klose & Torsten Schache, Hiperscan GmbH Dresden, Germany
//
//    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.Reflection;
using Gtk;
using Hiperscan.Extensions.ApoIdent.Widgets;
using Hiperscan.SGS;
using Hiperscan.SGS.Benchtop;
using Hiperscan.Unix;


namespace Hiperscan.Extensions.ApoIdent
{
    public class Plugin : IPlugin
    {
        public static readonly string name    = Catalog.GetString("Apo-Ident"); 
        public static readonly string version = "2.4.9";
        public static readonly string copyright_year = "2022";
        public static readonly string vendor  = "Hiperscan GmbH";
        public static readonly string description = Catalog.GetString("Chemometrics plug-in for QuickStep");
        public static readonly string guid        = "d49f4f0a-5425-4d20-87c9-ed2abc8e2e0a";
        public static bool replace_gui = false;
        
        public static readonly string [] authors = new string [] {
            "Alexander Höpfner",
            "René Rietzschel",
            "Walter Kochte",
        };

        public static readonly string license = Catalog.GetString(@"
    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/ .
");
 
        internal static IHost host;
        private MenuInfo[] menu_infos;
        private ToolbarInfo[] toolbar_infos;
        private bool active = true;
      
        public Plugin()
        {
            ApoIdentStock.Init();

            MenuInfo menu_info1 = new MenuInfo(Catalog.GetString("Apo-Ident"));
            menu_info1.Invoked += delegate(object sender, EventArgs e) {
                ApoIdentApplication.Start(Plugin.host);
                               
            };
            
            
            MenuInfo menu_info2 = new MenuInfo(Catalog.GetString("Initial position"));
            menu_info2.WatchCursor = true;
            menu_info2.NeedIdleDevice = true;
            menu_info2.Invoked += delegate(object sender, EventArgs e) {
                foreach (IDevice dev in Plugin.host.ActiveDevices.Idle)
                {
                    dev.SetFinderWheel(FinderWheelPosition.Initial, host.ProcessEvents);
                }
            };
            
            MenuInfo menu_info3 = new MenuInfo(Catalog.GetString("White reference"));
            menu_info3.WatchCursor = true;
            menu_info3.NeedIdleDevice = true;
            menu_info3.Invoked += delegate(object sender, EventArgs e) {
                foreach (IDevice dev in Plugin.host.ActiveDevices.Idle)
                {
                    dev.SetFinderWheel(FinderWheelPosition.White, host.ProcessEvents);
                }
            };
            
            MenuInfo menu_info4 = new MenuInfo(Catalog.GetString("Calibration reference"));
            menu_info4.WatchCursor = true;
            menu_info4.NeedIdleDevice = true;
            menu_info4.Invoked += delegate(object sender, EventArgs e) {
                foreach (IDevice dev in Plugin.host.ActiveDevices.Idle)
                {
                    dev.SetFinderWheel(FinderWheelPosition.Reference, host.ProcessEvents);
                }
            };
            
            MenuInfo menu_info5 = new MenuInfo(Catalog.GetString("Specimen"));
            menu_info5.WatchCursor = true;
            menu_info5.NeedIdleDevice = true;
            menu_info5.Invoked += delegate(object sender, EventArgs e) {
                foreach (IDevice dev in Plugin.host.ActiveDevices.Idle)
                {
                    dev.SetFinderWheel(FinderWheelPosition.Sample, host.ProcessEvents);
                }
            };

//            MenuInfo menu_info6 = new MenuInfo(Catalog.GetString("Reserved Position"));
//            menu_info6.WatchCursor = true;
//            menu_info6.NeedIdleDevice = true;
//            menu_info6.Invoked += delegate(object sender, EventArgs e) {
//                foreach (Device dev in Plugin.host.ActiveDevices.Idle)
//                {
//                    dev.SetFinderWheel(FinderWheelPosition.Reserved1, host.ProcessEvents);
//                }
//            };

            this.menu_infos = new MenuInfo[] {menu_info1, menu_info2, menu_info3, menu_info4, menu_info5}; //, menu_info6};

            ToolButton b1 = new ToolButton(ApoIdentStock.FINDER);
            ToolbarInfo toolbar_info1 = new ToolbarInfo(b1, 
                                                        Catalog.GetString("Apo-Ident"), 
                                                        Catalog.GetString("Apo-Ident"));
            toolbar_info1.Invoked += delegate(object sender, EventArgs e) {
                ApoIdentApplication.Start(Plugin.host);
            };
            
            this.toolbar_infos = new ToolbarInfo[] {toolbar_info1};
        }

        public void ReplaceGui()
        {
            Plugin.replace_gui = true;
            ApoIdentApplication.Start(host);
        } 
        
        public MenuInfo[] MenuInfos
        {
            get { return this.menu_infos; }
        }
        
        public ToolbarInfo[] ToolbarInfos
        {
            get { return this.toolbar_infos; }
        }
        
        public PlotTypeInfo[] PlotTypeInfos
        {
            get { return null; }
        }

        public FileTypeInfo[] FileTypeInfos
        {
            get { return null; }
        }

        public void Initialize(IHost host)
        {
            Plugin.host = host;
        }
        
        public string Name
        {
            get { return Plugin.name; }
        }
        
        public string Version
        {
            get { return Plugin.version; }
        }
        
        public string Vendor
        {
            get { return Plugin.vendor; }
        }
        
        public Assembly Assembly
        {
            get { return Assembly.GetExecutingAssembly(); }
        }

        public string Description
        {
            get { return Plugin.description; }
        }
        
        public Guid Guid
        {
            get { return new Guid(Plugin.guid); }
        }
        
        public bool Active
        {
            get { return this.active;  }
            set { this.active = value; }
        }

        public bool CanReplaceGui
        {
            get { return true; }
        }
    }
}
