//
//  Plugin.cs
//
// QuickStep: Acquire, view and identify spectra 
// Copyright (C) 2010-2017  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.Collections.Generic;
using System.Reflection;
using System.IO;
using Gtk;

using Hiperscan.Unix;
using Hiperscan.SGS;
using Hiperscan.Extensions;


namespace Hiperscan.Extensions.FinderSelftest
{

	public class Plugin : IPlugin
	{
		public static readonly string name    = Catalog.GetString("Finder Selftest");
		public static readonly string version = "1.0.0";
		public static readonly string vendor  = "Hiperscan GmbH";
		public static readonly string description = Catalog.GetString("Perform self tests for Finder hardware");
		public static readonly Guid guid = new Guid("c9e31bbe-6ecb-4ac5-a934-54d61f25b4eb");

		private MenuInfo[] menu_infos;
		private ToolbarInfo[] toolbar_infos;

		public static Gdk.Pixbuf[] Icons;

		internal static IHost host;
		private bool active = true;

		public Plugin ()
		{
			string finder_selftest_logo_fname = "FinderSelftest.Resources.checkmark128x128.png";
			Plugin.Icons = new Gdk.Pixbuf[5];
			
			Plugin.Icons[0] = new Gdk.Pixbuf(null, finder_selftest_logo_fname, 16, 16);
			Plugin.Icons[1] = new Gdk.Pixbuf(null, finder_selftest_logo_fname, 32, 32);
			Plugin.Icons[2] = new Gdk.Pixbuf(null, finder_selftest_logo_fname, 48, 48);
			Plugin.Icons[3] = new Gdk.Pixbuf(null, finder_selftest_logo_fname, 64, 64);
			Plugin.Icons[4] = new Gdk.Pixbuf(null, finder_selftest_logo_fname, 128, 128);

			IconSet icon_set = new IconSet();
			foreach (Gdk.Pixbuf pixbuf in Plugin.Icons)
			{
				IconSource icon_source = new IconSource();
				icon_source.Pixbuf = pixbuf;
				icon_set.AddSource(icon_source);
			}
			IconFactory icon_factory = new IconFactory();
			icon_factory.Add("hiperscan.finder_selftest", icon_set);
			icon_factory.AddDefault();

			MenuInfo menu_info1 = new MenuInfo(Catalog.GetString("Start Finder Selftest ..."));
			menu_info1.WatchCursor = true;
			menu_info1.NeedIdleDevice = true;
			menu_info1.NeedSingleDevice = true;
			menu_info1.Invoked += delegate(object sender, EventArgs e) {
				foreach (Device dev in Plugin.host.ActiveDevices.Idle)
				{
					if (dev.IsFinder)
						FinderSelftest.Start(dev);
				}
			};

			this.menu_infos = new MenuInfo[] {menu_info1};

			ToolButton b = new ToolButton("hiperscan.finder_selftest");
			ToolbarInfo toolbar_info1 = new ToolbarInfo(b, 
			                                            Catalog.GetString("Test"),
			                                            Catalog.GetString("Start Finder Selftest"));
			toolbar_info1.WatchCursor = true;
			toolbar_info1.NeedIdleDevice = true;
			toolbar_info1.NeedSingleDevice = true;
			toolbar_info1.Invoked += delegate(object sender, EventArgs e) {
				foreach (Device dev in Plugin.host.ActiveDevices.Idle)
				{
					if (dev.IsFinder)
						FinderSelftest.Start(dev);
				}
			};

			this.toolbar_infos = new ToolbarInfo[] {toolbar_info1};
		}
		
		public void ReplaceGui()
		{
		}
		
		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 Plugin.guid; }
		}
		
		public bool Active
		{
			get { return this.active;  }
			set { this.active = value; }
		}

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