// 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 Glade;
using Gtk;
using Hiperscan.Unix;


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


        public static readonly string ServiceForRepeatedError = Catalog.GetString("\n\n" +
                                               "If the problem persits, please consult an authorized HiperScan " +
                                               "representative:\n" +
                                               "Email: kundenservice@apo-ident.de\n" +
                                                "Telefon: +49 (0)351 212 496 33");

        private void __QSShowInfoMessage(string message)
        {
            this.Control.Host.ShowInfoMessage(this.MainWindow, true, message);
        }

        private void __QSShowInfoMessage(string message, EventHandler handler, string stock)
        {
            this.Control.Host.ShowInfoMessage(this.MainWindow, stock, handler, true, message);
        }


        private void __DialogShow(string title,
                                Gtk.DialogFlags dialo_flag,
                                Gtk.MessageType message_type,
                                Gtk.ButtonsType button_type,
                                string message,
                                int time_out = 0)
        {

            Gtk.MessageDialog dialog = new Gtk.MessageDialog(this.MainWindow,
                                                             dialo_flag,
                                                             message_type,
                                                             button_type,
                                                             message);

            this.DialogResponse = Gtk.ResponseType.None;
            dialog.WindowPosition = Gtk.WindowPosition.CenterOnParent;
            if (time_out > 0)
            {
                GLib.Timeout.Add((uint)time_out, delegate
                {
                    dialog.Destroy();
                    return false;
                });
            }


            dialog.IconList = ApoIdentStock.FinderIcons;
            this.DialogResponse = (Gtk.ResponseType)dialog.Run();
            dialog.Destroy();
        }

        private bool __QSShowHintMessage(string message, bool dont_show_again)
        {
            if (dont_show_again == true)
                return true;

            this.Control.Host.ShowInfoMessage(this.MainWindow, ref dont_show_again, true, message);
            return dont_show_again;
        }

        private void __ShowMissIdentificationDialog(string message)
        {
            if (this.Config.GuiSettings.DontShowHintMessageAgain)
                return;

            message += "\n\n" + Catalog.GetString("Do you need further information?");
           MessageDialog dialog = new MessageDialog(this.MainWindow,
                                                     DialogFlags.Modal,
                                                     Gtk.MessageType.Question,
                                                     ButtonsType.YesNo,
                                                     message);

            CheckButton cb = new CheckButton(Catalog.GetString("Don't show this dialog again during current session"))
            {
                Active = this.Config.GuiSettings.DontShowHintMessageAgain,
                CanFocus = false
            };
            dialog.VBox.PackStart(cb);
            cb.Show();

            dialog.IconList = ApoIdentStock.FinderIcons;
            this.DialogResponse = (ResponseType)dialog.Run();
            this.Config.GuiSettings.DontShowHintMessageAgain = cb.Active;
            dialog.Destroy();
        }

        private void __ShowRemindSavingDialog()
        {
            Glade.XML gui = new Glade.XML(null, "ApoIdent.Resources.Glade.FinderWindow.glade", "remind_saving_dialog", "Hiperscan");
            gui.Autoconnect(this);

            this.remind_saving_dialog.SetWmclass(Plugin.name.ToLower(),
                                           Plugin.name.ToLower());

            this.remind_saving_dialog.TransientFor = this.MainWindow;
            this.remind_saving_dialog.IconList = ApoIdentStock.FinderIcons;

            this.DialogResponse = (ResponseType)this.remind_saving_dialog.Run();
            this.remind_saving_dialog.Destroy();
        }
    }
}