// Created with MonoDevelop
//
//    QuickStep: Acquire, view and identify spectra 
//    Copyright (C) 2022 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 Glade;
using Hiperscan.AnalysisModule;
using Hiperscan.ApoIdentCore;
using Hiperscan.Unix;

namespace Hiperscan.Extensions.ApoIdent
{
    public class IdentServerLicenseDialog
    {
        [Widget] Gtk.Window license_window = null;
        [Widget] Gtk.TextView license_textview = null;

        public static IdentServerLicenseDialog Run(Gtk.Window parent, AppControl control, AnalysisType analysis_type)
        {
            return new IdentServerLicenseDialog(parent, control, analysis_type);
        }

        private IdentServerLicenseDialog(Gtk.Window parent, AppControl control, AnalysisType analysis_type)
        {
            Glade.XML gui = new Glade.XML(null, "ApoIdent.Resources.Glade.FinderWindow.glade", "license_window", "Hiperscan");
            gui.Autoconnect(this);

            ApoIdent.ApoIdentApplication.SetWmcClassName(this.license_window);

            this.license_window.Title = String.Format(Catalog.GetString("{0} License"), analysis_type.GetProductName());
            this.license_window.TransientFor = parent;

            string license_text = control.GetLicenseText(analysis_type);
            if (String.IsNullOrEmpty(license_text))
                license_text = Catalog.GetString("License is currently not available.");

            this.license_textview.Buffer.Text = license_text;

            GuiDesigner.SetSchema(this.license_window);
            this.license_window.ShowAll();
            this.license_window.WidthRequest = this.license_window.Allocation.Width + 50;
        }

        private void OnLicenseCloseButtonClicked(object sender, EventArgs e)
        {
            this.license_window.Destroy();
        }
    }
}
