#ifndef UBL_SETTINGS_QUOTAS_H
#define UBL_SETTINGS_QUOTAS_H

#include <dlfcn.h>
#include "view_open_browser.h"
#include "../project_lib.h"
#include "../my_type.h"
#include "ubl-util-standard.c"
#include "../var.h"
#include "model/wrapper_load_save.h"
#include "view_filters.h"
#include "view_add_user_group.h"
#include "view_edit_user_group.h"
#include "view_add_project.h"
#include "view_edit_project.h"

using namespace std;

#define yon_gtk_builder_get_widget(builder, widget_name) GTK_WIDGET(gtk_builder_get_object(builder, widget_name))


extern bool flag_save;
extern bool flag_save_local;
extern bool flag_save_global;
extern bool flag_load_global;
extern bool flag_lock_help;



class MainWindow {
    public:
        class ModelColumns : public Gtk::TreeModel::ColumnRecord {
            public:
                ModelColumns() {add(name), add(quotas); add(size),
                add(soft_limit_size), add(hard_limit_size); add(deferring_size),
                add(files); add(soft_limit_files),
                add(hard_limit_delay), add(deferring_files); }
                Gtk::TreeModelColumn<Glib::ustring> name;
                Gtk::TreeModelColumn<Glib::ustring> quotas;
                Gtk::TreeModelColumn<Glib::ustring> size;
                Gtk::TreeModelColumn<Glib::ustring> soft_limit_size;
                Gtk::TreeModelColumn<Glib::ustring> hard_limit_size;
                Gtk::TreeModelColumn<Glib::ustring> deferring_size;
                Gtk::TreeModelColumn<Glib::ustring> files;
                Gtk::TreeModelColumn<Glib::ustring> soft_limit_files;
                Gtk::TreeModelColumn<Glib::ustring> hard_limit_delay;
                Gtk::TreeModelColumn<Glib::ustring> deferring_files;
        };
        class ModelColumnsGeneral : public Gtk::TreeModel::ColumnRecord {
            public:
                ModelColumnsGeneral() {add(status), add(type_quotas); add(device),
                add(user), add(group), add(projects); add(soft_limit_size),
                add(hard_limit_size); add(soft_limit_files), add(hard_limit_files), add(deferring_size),
                add(deferring_files); }
                Gtk::TreeModelColumn<bool> status;
                Gtk::TreeModelColumn<Glib::ustring> type_quotas;
                Gtk::TreeModelColumn<Glib::ustring> device;
                Gtk::TreeModelColumn<Glib::ustring> user;
                Gtk::TreeModelColumn<Glib::ustring> group;
                Gtk::TreeModelColumn<Glib::ustring> projects;
                Gtk::TreeModelColumn<Glib::ustring> soft_limit_size;
                Gtk::TreeModelColumn<Glib::ustring> hard_limit_size;
                Gtk::TreeModelColumn<Glib::ustring> soft_limit_files;
                Gtk::TreeModelColumn<Glib::ustring> hard_limit_files;
                Gtk::TreeModelColumn<Glib::ustring> deferring_size;
                Gtk::TreeModelColumn<Glib::ustring> deferring_files;
        };
        ModelColumns m_columns;
        ModelColumnsGeneral m_columnsGeneral;
        Glib::RefPtr<Gtk::Builder> builder;
        template<typename Type>
        struct Result{
            Type response;
            int error;
        };
        Gtk::Label *headerTopic;
        Gtk::Overlay *HeadOverlay;
        Gtk::HeaderBar *headerBar;
        Gtk::Widget *boxSave;
        Gtk::Widget *boxButton;
        Gtk::Box *boxFuncs;
        Gtk::Box* boxResize;
        Gtk::MenuButton *btnSave;
        Gtk::MenuButton *btnLoad;
        Gtk::MenuButton *btnSettings;
        Gtk::Image *HeadBackgroundImage;
        Gtk::Image *imgInfo;
        Gtk::Box *boxInfoError;
        Gtk::Label *lblWarning;
        Gtk::Label *generalTabLabel;
        Gtk::Label *UsersTabLabel;
        Gtk::Label *GroupsTabLabel;
        Gtk::Label *generalGroupsFilesLabel;
        Gtk::Label *generalUsersSizeLabel;
        Gtk::Label *generalUsersFilesLabel;
        Gtk::Label *generalGroupsSizeWeeksLabel;
        Gtk::Label *generalGroupsFilesWeeksLabel;
        Gtk::Label *generalUsersSizeWeeksLabel;
        Gtk::Label *generalUsersFilesWeeksLabel;
        Gtk::Label *generalGroupsSizeDaysLabel;
        Gtk::Label *generalGroupsFilesDaysLabel;
        Gtk::Label *generalUsersSizeDaysLabel;
        Gtk::Label *generalUsersFilesDaysLabel;
        Gtk::Label *generalGroupsSizeHoursLabel;
        Gtk::Label *generalGroupsFilesHoursLabel;
        Gtk::Label *generalUsersSizeHoursLabel;
        Gtk::Label *generalUsersFilesHoursLabel;
        Gtk::Label *generalGroupsSizeMinutesLabel;
        Gtk::Label *generalGroupsFilesMinutesLabel;
        Gtk::Label *generalUsersSizeMinutesLabel;
        Gtk::Label *generalUsersFilesMinutesLabel;
        Gtk::Label *ProjectTabLabel;
        Gtk::Label *usersProjectLabel;
        Gtk::Label *lblLoad;
        Gtk::Label *lblSave;
        Gtk::MenuItem *btnLoadGlob;
        Gtk::MenuItem *btnLoadLocal;
        Gtk::MenuItem *btnSynopsis;
        Gtk::MenuItem *btnAbout;
        Gtk::MenuItem *btnSaveLocalGlob;
        Gtk::MenuItem *btnSaveGlob;
        Gtk::MenuItem *btnSaveLocal;
        Gtk::Label *groupsDeviceLabel;
        Gtk::Label *usersDeviceLabel;
        Gtk::Label *headLabel;
        
        Gtk::TreeView *groupsQuotasTree; 
        Gtk::TreeView *usersQuotasTree;
        Gtk::TreeView *ProjectQuotasTree;
        Gtk::TreeView *GeneralQuotasTree;
        Gtk::Label *quotegroupGroupQuotasLabel;
        
        
        Gtk::ComboBoxText *usersDeviceCombo;
        Gtk::ComboBoxText *groupsDeviceCombo;
        Gtk::ComboBoxText *generalDeviceCombo;
        Gtk::ComboBoxText *usersProjectCombo;
        Gtk::Label *lblFstypeGroups;
        Gtk::SpinButton *generalGroupsSizeWeeksSpi;
        Gtk::SpinButton *generalGroupsFileWeeksSpin;
        Gtk::SpinButton *generalGroupsSizeDaySpin;
        Gtk::SpinButton *generalGroupsFilesDaySpin;
        Gtk::SpinButton *generalGroupsSizeHourSpin;
        Gtk::SpinButton *generalGroupsFilesHourSpin;
        Gtk::SpinButton *generalGroupsSizeMinuteSpin;
        Gtk::SpinButton *generalGroupsFilesMinuteSpin;
        Gtk::SpinButton *generalUsersSizWeeksSpin;
        Gtk::SpinButton *generalUsersFileWeeksSpin;
        Gtk::SpinButton *generalUsersSizeDaySpin;
        Gtk::SpinButton *generalUsersFilesDaySpin;
        Gtk::SpinButton *generalUsersSizeHourSpin;
        Gtk::SpinButton *generalUsersFilesHoursSpin;
        Gtk::SpinButton *generalUsersSizeMinuteSpin;
        Gtk::SpinButton *generalUsersFilesMinutesSpin;
        
        
        Gtk::Button *btnFilterGroups;
        Gtk::Button *btnFilterUsers;
        Gtk::Button *btnFilterProject;
        Gtk::CheckMenuItem *chbMangSystemFile;
        Gtk::Button* btnDelGroups;
        Gtk::Button* btnDelProject;
        Gtk::Button* btnDelUsers;
        Gtk::Button* btnAddGroups;
        Gtk::Button* btnAddUsers;
        Gtk::Button* btnAddProject;
        Gtk::Button* btnEditProject;
        Gtk::Button* btnEditUsers;
        Gtk::Button* btnEditGroups;

        Gtk::Box* boxGroupsWeeks;
        Gtk::Box* boxGroupsDays;
        Gtk::Box* boxGroupsHours;
        Gtk::Box* boxGroupsMinutes;
        Gtk::Box* boxUsersWeeks;
        Gtk::Box* boxUsersDays;
        Gtk::Box* boxUsersHours;
        Gtk::Box* boxUsersMinutes;
        Gtk::Box* boxProjectWeeks;
        Gtk::Box* boxProjectDays;
        Gtk::Box* boxProjectHours;
        Gtk::Box* boxProjectMinutes;
        GtkListStore* gtk_list_project;
        GtkListStore* gtk_list_groups;
        GtkListStore* gtk_list_user;
        GtkListStore* gtk_list_general;

    public:
        map_str_str* map_gui_cfg = NULL;
        map_str_str* map_global_cfg = NULL;
        map_str_str* map_system_cfg = NULL;
        Wrapper_load_save* obj_wrapper_load_save = NULL;
        View_edit_user_group* obj_view_edit = NULL;
        View_filters* obj_view_filters = NULL;
        View_add_user_group* obj_view_add = NULL;
        View_add_project* obj_view_add_project = NULL;
        View_edit_project* obj_view_edit_project = NULL;
        //Devices::Parted obj_device = Devices::Parted();
        //Quotas_sys::Quotas_sys obj_quotas_sys = Quotas_sys::Quotas_sys();
        //Quotas_ubconfig::Quotas_ubconfig obj_quotas_ubconfig = Quotas_ubconfig::Quotas_ubconfig();
        vector<string> vec_param_names;
        map_str_str map_device;
        string str_cmd_error;
        string save_user_or_group;
        string sys_or_ubconfig;
        string hw_or_sw = "";
        string mode_quota = "ubconfig";
        Glib::RefPtr<Gtk::ListStore> list_store_groups;
        Glib::RefPtr<Gtk::ListStore> list_store_users;
        Glib::RefPtr<Gtk::ListStore> list_store_project;
        Gtk::TreeModel::iterator iter_groups;
        Gtk::TreeModel::iterator iter_users;
        Gtk::TreeModel::iterator iter_project;
        bool flag_validate_del_groups = false;
        bool flag_validate_del_users = false;
        bool flag_validate_del_project = false;
        Gtk::TreeModel::Row row;
        int* socket_ext_id_I = NULL;
        int* socket_trd_id_I = NULL;
        View_open_browser* obj_open_browser;
        const struct tv_g_u_p obj_tv_g_u_p {"", "", "", "", "", "", "", "", "",""};
    public:
        // MainWindow(BaseObjectType* obj, Glib::RefPtr<Gtk::Builder> const& builder);
        MainWindow(Glib::RefPtr<Gtk::Builder> builder, View_open_browser* obj_open_browser, int* socket_ext_id_I, int* socket_trd_id_I);
        ~MainWindow();
        void settings();
        void flag_block_gui();
        void tree_view_select();
        void lacalization();
        void add_CSS();
        void resize_widget();
        void get_builder();
        void event();
        void open_browser();
        void info_warning_error(int mess, int error_save, int error_load);
        void init_work_tv_g_u_p();
        void remove_line_template(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter, Gtk::TreeModel::iterator& iter_del, bool& flag_del);
        void remove_template(Glib::RefPtr<Gtk::ListStore>* list_store, const Gtk::TreeModel::iterator* iter, bool& flag_validate_del);
        void init_tree_view_general();
        void entry_combo_box_temp(Gtk::ComboBoxText *combo_box, Gtk::Label *label);
        void info_status_app(string stule);
        void filters_show();
        void set_obj_wrapper_load_save(Wrapper_load_save* obj_wrapper_load_save);
        void init_tree_view();
        void del_columns();
        void set_obj_browser(View_open_browser* obj_open_browser);
        void set_add_tv_g_u_p(string name, Gtk::TreeView* tree_view, Gtk::TreeModel::Row &row, Glib::RefPtr<Gtk::ListStore>& list_store, struct tv_g_u_p obj_tv_g_u_p);
        void off_quota_system(Gtk::ComboBoxText* combo_box, string quota_type);
        void mode_switch_quota();
        void save_quotegroupSaveButton();
        void filling_device_combo_box_template(Gtk::ComboBoxText *combo_box, map_str_str &map_device);
        void wrapper_settings_quotas_temp(string save_user_or_group);
        void off_quota_ubconfig(Gtk::ComboBoxText* combo_box, string quota_type);
        void init_spin_all();
        void view_add_columns(Gtk::TreeView &treeView);
        void format_cmd_quotas_system(struct struct_quotas& _struct_quota);
        void format_cmd_quotas_ubconfig(struct struct_quotas& _struct_quota);
        struct partition_cmd wrapper_settings_quotas();
        void set_map_gui(map_str_str* map_gui_cfg);
        void set_map_global(map_str_str* map_global_cfg);
        void set_map_local(map_str_str* map_system_cfg);
        void wrapper_load_system();
        void wrapper_load_global();
        void wrapper_save_all();
        void wrapper_save_system();
        void wrapper_save_global();
        void set_obj_view_filters(View_filters* obj_view_filters);
        bool check_space(Gtk::TreeView* tree_view);
        void set_obj_view_add(View_add_user_group* obj_view_edit);
        void add_quota_show(string name);
        void edit_quota_show(string name);
        void set_obj_view_edit(View_edit_user_group* obj_view_edit);
        void set_obj_view_add_project(View_add_project* obj_view_add_project);
        void set_obj_view_edit_project(View_edit_project* obj_view_edit_project);
        void edit_quota_project_show();
};
void wrapper_help_show(GtkWidget *self, char* link, gpointer user_data);
void help();
#endif
