/***********************************************************************************

    Copyright (C) 2007-2020 Ahmet Öztürk (aoz_2@yahoo.com)

    This file is part of Lifeograph.

    Lifeograph 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.

    Lifeograph 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 Lifeograph.  If not, see <http://www.gnu.org/licenses/>.

***********************************************************************************/


#ifndef LIFEOGRAPH_DIALOG_EXPORT_HEADER
#define LIFEOGRAPH_DIALOG_EXPORT_HEADER

// TODO: rename this file to cover all of its current functions


#include <gtkmm.h>

#include "diary.hpp"


namespace LIFEO
{

// FILE SAVE DIALOGS ===============================================================================
class DialogSaveGeneric : public Gtk::FileChooserDialog
{
    public:
                                    DialogSaveGeneric( const Glib::ustring& );
                                    DialogSaveGeneric( BaseObjectType*,
                                                       const Glib::RefPtr< Gtk::Builder >& );

        std::string                 get_filename( const std::string& = "" );
};

class DialogSaveDiary : public DialogSaveGeneric
{
	public:
                                    DialogSaveDiary( BaseObjectType*,
                                                     const Glib::RefPtr< Gtk::Builder >& );

        static int                  launch( std::string&, std::string& );

	protected:
        void                        handle_encryption_toggled();
        void                        handle_password_changed();

        static DialogSaveDiary*     ptr;

        Gtk::Frame*                 m_frame_encrypt;
        Gtk::Grid*                  m_grid_password;
        Gtk::CheckButton*           m_check_encrypt;
        Gtk::Entry*                 m_entry_password;
        Gtk::Entry*                 m_entry_confirm;
};

// FILE OPEN DIALOG ================================================================================
class DialogOpenDiary : public Gtk::FileChooserDialog
{
    public:
                                    DialogOpenDiary();

        // FILTERING
        static void                 init_filters();

        static Glib::RefPtr< Gtk::FileFilter >
                                    filter_any;
        static Glib::RefPtr< Gtk::FileFilter >
                                    filter_diary;

    protected:
        void                        handle_selection_changed();

        static bool                 flag_filters_created;
};

// EXPORTERS =======================================================================================
class Diarysaver
{
    public:
    typedef sigc::signal< void, bool >
                                    Signal_void_bool;

        virtual Gtk::Widget*        draw_options() = 0;
        virtual bool                is_ready() = 0;
        virtual Result              save( bool ) = 0;

        Glib::ustring               get_name()
        { return m_name; }

        Signal_void_bool            signal_updated()
        { return m_signal_updated; }

    protected:
                                    Diarysaver( const Glib::ustring&, Diary* );
        virtual                     ~Diarysaver() {}

        Glib::ustring               m_name;
        Diary*                      m_ptr2diary;

        Signal_void_bool            m_signal_updated;
};

class ExporterLifeograph : public Diarysaver
{
    public:
        explicit                    ExporterLifeograph( Diary* );
        Gtk::Widget*                draw_options()
        { return nullptr; }

        bool                        is_ready()
        { return true; }

        Result                      save( bool );

//        void                        handle_passphrase_changed();
//        void                        handle_encryption_changed();

    private:

};

class ExporterText : public Diarysaver
{
    public:
        explicit                    ExporterText( Diary* );
        Gtk::Widget*                draw_options()
        { return nullptr; }

        bool                        is_ready()
        { return true; }

        Result                      save( bool );
};

// EXPORT DIALOG ===================================================================================
class DialogExport : public DialogEvent
{
    public:
                                    DialogExport( BaseObjectType*,
                                                  const Glib::RefPtr< Gtk::Builder >& );

        void                        add_saver( Diarysaver* );

    protected:
        virtual void                on_response( int );

        void                        handle_savetype_changed();
        void                        handle_saver_updated( bool );

        Gtk::ComboBoxText*          m_combo_type;
        Gtk::ComboBoxText*          m_CB_extent;
        Gtk::Button*                m_B_export;
        Gtk::Alignment*             m_align_options;
        Gtk::Frame*                 m_F_options;
        Gtk::Widget*                m_ptr2widget_options;

        std::vector< Diarysaver* >  m_savers;
        Diarysaver*                 m_saver_cur;

        Diary*                      m_ptr2diary;
        bool                        m_flag_saverready;

    private:

};

} // end of namespace LIFEO

#endif
