// Created with MonoDevelop
//
//    QuickStep: Acquire, view and identify spectra 
//    Copyright (C) 2021 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.IO;

using Glade;

using Hiperscan.Spectroscopy.IdentModule;


namespace Hiperscan.Extensions.ApoIdent
{
    public partial class ApoIdentApplication
    {
        [Widget] Gtk.Toolbar protocol_toolbar = null;

        [Widget] Gtk.Label big_protocol_label = null;
        [Widget] Gtk.ToolButton protocol_save_toolbutton = null;
        [Widget] Gtk.ToolButton protocol_pdf_toolbutton = null;
        [Widget] Gtk.ToolButton protocol_print_toolbutton = null;
        [Widget] Gtk.ToolButton protocol_label_print_toolbutton = null;

        [Widget] Gtk.Label protocol_test_id_label = null;
        [Widget] Gtk.Label protocol_test_id_output_label = null;


        private void UpdateProtocolSection(bool only_toolbuttons)
        {
            bool section_active = this.Control.QuitRequested == false &&
                this.Control.ConnectionSuccess &&
                                      this.Control.ProtocolState.HasFlag(ProtocolStates.ProtocolSectionActive);

            bool create_protocol = section_active;
            this.protocol_save_toolbutton.Sensitive = create_protocol && 
                this.Control.ProtocolState.HasFlag(ProtocolStates.ProtocolNotSaved);
            this.protocol_pdf_toolbutton.Sensitive = create_protocol;
            this.protocol_print_toolbutton.Sensitive = create_protocol;
            this.protocol_label_print_toolbutton.Sensitive = section_active && this.Control.ProtocolState.HasFlag(ProtocolStates.HasLabelPrinter);

            this.SetProtocolButtonStates();

            this.big_protocol_label.Sensitive = section_active;
            this.protocol_test_id_label.Sensitive = section_active;
            this.protocol_test_id_output_label.Sensitive = section_active;

            if (only_toolbuttons == true)
                return;

            this.SetProtocolTestId();
        }

        private void SetProtocolTestId()
        {

            this.protocol_test_id_output_label.Markup = "<b>" + this.GetProtocolTestId() + "</b>";
        }

        private void SetProtocolButtonStates()
        {
            this.SetToolButtonActiveState(this.protocol_save_toolbutton);
            this.SetToolButtonActiveState(this.protocol_pdf_toolbutton);
            this.SetToolButtonActiveState(this.protocol_print_toolbutton);
            this.SetToolButtonActiveState(this.protocol_label_print_toolbutton);
        }
    }
}
