#ifndef UBL_SETTINGS_DISKQUOTA_H
#define UBL_SETTINGS_DISKQUOTA_H
#include "ubl-settings-diskquota.h"

string version_application = "1.6";
bool flag_save = false;
bool flag_save_local = false;
bool flag_save_global = false;
bool flag_load_global = false;
bool flag_lock_help = false;

MainWindow::MainWindow(Glib::RefPtr<Gtk::Builder> builder, View_open_browser* obj_open_browser, int* socket_ext_id_I, int* socket_trd_id_I) {
    this->builder = builder;
    this->socket_ext_id_I = socket_ext_id_I;
    this->socket_trd_id_I = socket_trd_id_I;
    this->set_obj_browser(obj_open_browser);
    // this->settings();
}

void MainWindow::set_map_gui(map_str_str* map_gui_cfg) {
    this->map_gui_cfg = map_gui_cfg;
    obj_wrapper_load_save->set_map_gui(map_gui_cfg);
}

void MainWindow::set_map_global(map_str_str* map_global_cfg) {
    this->map_global_cfg = map_global_cfg;
    obj_wrapper_load_save->set_map_global(map_global_cfg);
}

void MainWindow::set_map_local(map_str_str* map_system_cfg) {
    this->map_system_cfg = map_system_cfg;
    obj_wrapper_load_save->set_map_local(map_system_cfg);
}

void MainWindow::set_obj_wrapper_load_save(Wrapper_load_save* obj_wrapper_load_save) {
    this->obj_wrapper_load_save = obj_wrapper_load_save;
}

void MainWindow::set_obj_view_filters(View_filters* obj_view_filters) {
    this->obj_view_filters = obj_view_filters;
}

void MainWindow::set_obj_view_add(View_add_user_group* obj_view_add) {
    this->obj_view_add = obj_view_add;
}

void MainWindow::set_obj_view_edit(View_edit_user_group* obj_view_edit) {
    this->obj_view_edit = obj_view_edit;
}
void MainWindow::set_obj_view_add_project(View_add_project* obj_view_add_project) {
    this->obj_view_add_project = obj_view_add_project;
}
void MainWindow::set_obj_view_edit_project(View_edit_project* obj_view_edit_project) {
    this->obj_view_edit_project = obj_view_edit_project;
}

void MainWindow::settings() {
    this->get_builder();
    this->lacalization();
    Gtk::Widget *boxWidget;
    builder->get_widget("boxColor", boxWidget);
    HeadOverlay->add_overlay(*boxWidget);
    ubl_make_plugs(boxSave, boxButton, (*socket_ext_id_I), (*socket_trd_id_I));
    this->add_CSS();
    this->flag_block_gui();
    this->init_spin_all();
    if (geteuid() == 0) {
        this->wrapper_load_system();
        this->wrapper_load_global();
        this->event();
    }
    else {
        boxFuncs->set_sensitive(false);
        btnSave->set_sensitive(false);
        btnLoad->set_sensitive(false);
        imgInfo->set_from_icon_name(icon_warning, Gtk::ICON_SIZE_MENU);
        info_status_app(info_box_error_css);
        lblWarning->set_text(program_as_root);
    }
    
}



void MainWindow::set_obj_browser(View_open_browser* obj_open_browser) {
    this->obj_open_browser = obj_open_browser;
    obj_open_browser->get_about()->set_version(version_application);
}

void MainWindow::init_spin_all() {
    generalGroupsSizeWeeksSpi->set_range(0, 52);
    generalGroupsSizeWeeksSpi->set_increments(1.0, 1.0);
    generalGroupsSizeWeeksSpi->set_value(0);
    generalGroupsFileWeeksSpin->set_range(0, 52);
    generalGroupsFileWeeksSpin->set_increments(1.0, 1.0);
    generalGroupsFileWeeksSpin->set_value(0);
    generalUsersSizWeeksSpin->set_range(0, 52);
    generalUsersSizWeeksSpin->set_increments(1.0, 1.0);
    generalUsersSizWeeksSpin->set_value(0);
    generalUsersFileWeeksSpin->set_range(0, 52);
    generalUsersFileWeeksSpin->set_increments(1.0, 1.0);
    generalUsersFileWeeksSpin->set_value(0);
    generalGroupsSizeDaySpin->set_range(0, 31);
    generalGroupsSizeDaySpin->set_increments(1.0, 1.0);
    generalGroupsSizeDaySpin->set_value(0);
    generalGroupsFilesDaySpin->set_range(0, 31);
    generalGroupsFilesDaySpin->set_increments(1.0, 1.0);
    generalGroupsFilesDaySpin->set_value(0);
    generalUsersSizeDaySpin->set_range(0, 31);
    generalUsersSizeDaySpin->set_increments(1.0, 1.0);
    generalUsersSizeDaySpin->set_value(0);
    generalUsersFilesDaySpin->set_range(0, 31);
    generalUsersFilesDaySpin->set_increments(1.0, 1.0);
    generalUsersFilesDaySpin->set_value(0);
    generalGroupsSizeHourSpin->set_range(0, 23);
    generalGroupsSizeHourSpin->set_increments(1.0, 1.0);
    generalGroupsSizeHourSpin->set_value(0);
    generalGroupsFilesHourSpin->set_range(0, 23);
    generalGroupsFilesHourSpin->set_increments(1.0, 1.0);
    generalGroupsFilesHourSpin->set_value(0);
    generalUsersSizeHourSpin->set_range(0, 23);
    generalUsersSizeHourSpin->set_increments(1.0, 1.0);
    generalUsersSizeHourSpin->set_value(0);
    generalUsersFilesHoursSpin->set_range(0, 23);
    generalUsersFilesHoursSpin->set_increments(1.0, 1.0);
    generalUsersFilesHoursSpin->set_value(0); 
    generalGroupsSizeMinuteSpin->set_range(0, 59);
    generalGroupsSizeMinuteSpin->set_increments(1.0, 1.0);
    generalGroupsSizeMinuteSpin->set_value(0);  
    generalGroupsFilesMinuteSpin->set_range(0, 59);
    generalGroupsFilesMinuteSpin->set_increments(1.0, 1.0);
    generalGroupsFilesMinuteSpin->set_value(0); 
    generalUsersSizeMinuteSpin->set_range(0, 59);
    generalUsersSizeMinuteSpin->set_increments(1.0, 1.0);
    generalUsersSizeMinuteSpin->set_value(0);  
    generalUsersFilesMinutesSpin->set_range(0, 59);
    generalUsersFilesMinutesSpin->set_increments(1.0, 1.0);
    generalUsersFilesMinutesSpin->set_value(0);    
}

void MainWindow::lacalization() {
    
}

void MainWindow::info_warning_error(int mess, int error_save, int error_load) {
    if (error_save > 0 || error_load > 0) {
        info_status_app(info_box_error_css);
        imgInfo->set_from_icon_name(icon_warning, Gtk::ICON_SIZE_MENU);
        string mess_error = "";
        if (mess == 0) {
            mess_error = string(local_read_error) + str_cmd_error;
            lblWarning->set_text(mess_error);
        }
        else if (mess == 1) {
            mess_error = string(global_read_error) + str_cmd_error;
            lblWarning->set_text(mess_error);
        }
        else if (mess == 2) {
            mess_error = string(local_write_error) + str_cmd_error;
            lblWarning->set_text(mess_error);
        }
        else if (mess == 3) {
            mess_error = string(global_write_error) + str_cmd_error;
            lblWarning->set_text(mess_error);
        }
        else if (mess == 4) {
            mess_error = string(error_save_all) + str_cmd_error;
            lblWarning->set_text(mess_error);
        }
        str_cmd_error = "";
    }
    else {
        info_status_app(info_box_ok_css);
        imgInfo->set_from_icon_name(icon_checked, Gtk::ICON_SIZE_MENU);
        if (mess == 0) {
            lblWarning->set_text(local_load_ok);
        }
        else if (mess == 1) {
            lblWarning->set_text(global_load_ok);
        }
        else if (mess == 2) {
            lblWarning->set_text(local_ok_written);
        }
        else if (mess == 3) {
            lblWarning->set_text(global_ok_written);
        }
        else if (mess == 4) {
            lblWarning->set_text(successfully_save_all);
        }
        else if (mess == 5) {
            lblWarning->set_text(nothing_save);
        }
    }
}

void MainWindow::filling_device_combo_box_template(Gtk::ComboBoxText *combo_box, map_str_str &map_device) {
    if (map_device.size() != 0) {
        for (const auto &device : map_device) {
            combo_box->append(device.first.c_str());
        }
        combo_box->set_active(0);
    }
}

void MainWindow::flag_block_gui() {
    if (flag_load_global == true) {
        btnLoadGlob->set_sensitive(false);
    }
    if (flag_save_local == true && flag_save_global == true) {
        btnSave->set_sensitive(false);
    }
    if (flag_save == true) {
        btnSave->set_sensitive(false);
    }
    if (flag_save_local == true) {
        btnSaveLocal->set_sensitive(false);
        btnSaveLocalGlob->set_sensitive(false);
    }
    if (flag_save_global == true) {
        btnSaveGlob->set_sensitive(false);
        btnSaveLocalGlob->set_sensitive(false);
    }
    if (flag_lock_help == true) {
        btnSynopsis->set_sensitive(false);
    }
}

/*
void MainWindow::entry_combo_box_temp(Gtk::ComboBoxText *combo_box, Gtk::Label *label) {
    string text = combo_box->get_active_text();
    if (map_device.find(text) != map_device.end()){
        label->set_text(map_device[text]);
    }
}
*/

void MainWindow::add_CSS() {
    Glib::RefPtr<Gtk::CssProvider> cssProvider = Gtk::CssProvider::create();
    cssProvider->load_from_path(path_css);   
    Glib::RefPtr<Gtk::StyleContext> styleContext = Gtk::StyleContext::create();
    Glib::RefPtr<Gdk::Screen> screen = Gdk::Screen::get_default();//get default screen
    styleContext->add_provider_for_screen(screen, cssProvider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);//add provider for screen in all application
    HeadBackgroundImage->set(path_img_head_background);
    Glib::RefPtr<Gtk::StyleContext> headLabel_css = headLabel->get_style_context();
    Glib::RefPtr<Gtk::StyleContext> boxButton_css = boxButton->get_style_context();
    Glib::RefPtr<Gtk::StyleContext> boxSave_css = boxSave->get_style_context();
    Glib::RefPtr<Gtk::StyleContext> headerBar_css = headerBar->get_style_context();
    if ((*socket_trd_id_I) == 0 && (*socket_ext_id_I) == 0){
        boxButton_css->add_class("bkim_no_plug");
        boxSave_css->add_class("bkim_no_plug");
    }
    headLabel_css->add_class("textHead");
}

void MainWindow::get_builder() {
    builder->set_translation_domain(path_app);
    builder->get_widget("headerTopic", headerTopic);
    builder->get_widget("boxButton", boxButton);
    builder->get_widget("boxSave", boxSave);
    builder->get_widget("HeadOverlay", HeadOverlay);
    builder->get_widget("headerBar", headerBar);
    builder->get_widget("boxFuncs", boxFuncs);
    builder->get_widget("btnLoad", btnLoad);
    builder->get_widget("btnSave", btnSave);
    builder->get_widget("HeadBackgroundImage", HeadBackgroundImage);
    builder->get_widget("imgInfo", imgInfo);
    builder->get_widget("lblWarning", lblWarning);
    builder->get_widget("boxInfoError", boxInfoError);
    builder->get_widget("imgInfo", imgInfo);
    builder->get_widget("generalTabLabel", generalTabLabel);
    builder->get_widget("GroupsTabLabel", GroupsTabLabel);
    builder->get_widget("UsersTabLabel", UsersTabLabel);
    builder->get_widget("generalGroupsFilesLabel", generalGroupsFilesLabel);
    builder->get_widget("generalUsersSizeLabel", generalUsersSizeLabel);
    builder->get_widget("generalUsersFilesLabel", generalUsersFilesLabel);
    builder->get_widget("generalGroupsSizeWeeksLabel", generalGroupsSizeWeeksLabel);
    builder->get_widget("generalGroupsFilesWeeksLabel", generalGroupsFilesWeeksLabel);
    builder->get_widget("generalUsersSizeWeeksLabel", generalUsersSizeWeeksLabel);
    builder->get_widget("generalUsersFilesWeeksLabel", generalUsersFilesWeeksLabel);
    builder->get_widget("generalGroupsSizeDaysLabel", generalGroupsSizeDaysLabel);
    builder->get_widget("generalGroupsFilesDaysLabel", generalGroupsFilesDaysLabel);
    builder->get_widget("generalUsersSizeDaysLabel", generalUsersSizeDaysLabel);
    builder->get_widget("generalUsersFilesDaysLabel", generalUsersFilesDaysLabel);
    builder->get_widget("generalGroupsSizeHoursLabel", generalGroupsSizeHoursLabel);
    builder->get_widget("generalGroupsFilesHoursLabel", generalGroupsFilesHoursLabel);
    builder->get_widget("generalUsersSizeHoursLabel", generalUsersSizeHoursLabel);
    builder->get_widget("generalUsersFilesHoursLabel", generalUsersFilesHoursLabel);
    builder->get_widget("generalGroupsSizeMinutesLabel", generalGroupsSizeMinutesLabel);
    builder->get_widget("generalGroupsFilesMinutesLabel", generalGroupsFilesMinutesLabel);
    builder->get_widget("generalUsersSizeMinutesLabel", generalUsersSizeMinutesLabel);
    builder->get_widget("generalUsersFilesMinutesLabel", generalUsersFilesMinutesLabel);
    builder->get_widget("lblLoad", lblLoad);
    builder->get_widget("lblSave", lblSave);
    builder->get_widget("btnSettings", btnSettings);
    builder->get_widget("groupsDeviceLabel", groupsDeviceLabel);
    builder->get_widget("usersDeviceLabel", usersDeviceLabel);
    builder->get_widget("headLabel", headLabel);
    builder->get_widget("btnLoadGlob", btnLoadGlob);
    builder->get_widget("btnLoadLocal", btnLoadLocal);
    builder->get_widget("btnSynopsis", btnSynopsis);
    builder->get_widget("btnAbout", btnAbout);
    builder->get_widget("btnSaveLocalGlob", btnSaveLocalGlob);
    builder->get_widget("btnSaveGlob", btnSaveGlob);
    builder->get_widget("btnSaveLocal", btnSaveLocal);
    builder->get_widget("GroupsTabLabel", GroupsTabLabel);
    builder->get_widget("groupsQuotasTree", groupsQuotasTree);
    builder->get_widget("usersQuotasTree", usersQuotasTree);
    builder->get_widget("usersDeviceCombo", usersDeviceCombo);
    builder->get_widget("GroupsTabLabel", GroupsTabLabel);
    builder->get_widget("generalTabLabel", generalTabLabel);
    builder->get_widget("groupsDeviceCombo", groupsDeviceCombo);
    builder->get_widget("generalGroupsSizeWeeksSpi", generalGroupsSizeWeeksSpi);
    builder->get_widget("generalGroupsFileWeeksSpin", generalGroupsFileWeeksSpin);
    builder->get_widget("generalGroupsSizeDaySpin", generalGroupsSizeDaySpin);
    builder->get_widget("generalGroupsFilesDaySpin", generalGroupsFilesDaySpin);
    builder->get_widget("generalGroupsSizeHourSpin", generalGroupsSizeHourSpin);
    builder->get_widget("generalGroupsFilesHourSpin", generalGroupsFilesHourSpin);
    builder->get_widget("generalGroupsSizeMinuteSpin", generalGroupsSizeMinuteSpin);
    builder->get_widget("generalGroupsFilesMinuteSpin", generalGroupsFilesMinuteSpin);
    builder->get_widget("generalUsersSizWeeksSpin", generalUsersSizWeeksSpin);
    builder->get_widget("generalUsersFileWeeksSpin", generalUsersFileWeeksSpin);
    builder->get_widget("generalUsersSizeDaySpin", generalUsersSizeDaySpin);
    builder->get_widget("generalUsersFilesDaySpin", generalUsersFilesDaySpin);
    builder->get_widget("generalUsersSizeHourSpin", generalUsersSizeHourSpin);
    builder->get_widget("generalUsersFilesHoursSpin", generalUsersFilesHoursSpin);
    builder->get_widget("generalUsersSizeMinuteSpin", generalUsersSizeMinuteSpin);
    builder->get_widget("generalUsersFilesMinutesSpin", generalUsersFilesMinutesSpin);
    builder->get_widget("GeneralQuotasTree", GeneralQuotasTree);
    builder->get_widget("ProjectQuotasTree", ProjectQuotasTree);
    builder->get_widget("ProjectTabLabel", ProjectTabLabel);
    builder->get_widget("usersProjectLabel", usersProjectLabel);
    builder->get_widget("btnFilterProject", btnFilterProject);
    builder->get_widget("btnFilterUsers", btnFilterUsers);
    builder->get_widget("btnFilterGroups", btnFilterGroups);
    builder->get_widget("chbMangSystemFile", chbMangSystemFile);
    builder->get_widget("btnDelGroups", btnDelGroups);
    builder->get_widget("btnDelProject", btnDelProject);
    builder->get_widget("btnDelUsers", btnDelUsers);
    builder->get_widget("btnAddGroups", btnAddGroups);
    builder->get_widget("btnAddUsers", btnAddUsers);
    builder->get_widget("btnAddProject", btnAddProject);
    builder->get_widget("btnEditProject", btnEditProject);
    builder->get_widget("btnEditUsers", btnEditUsers);
    builder->get_widget("btnEditGroups", btnEditGroups);
    builder->get_widget("usersProjectCombo", usersProjectCombo);
    builder->get_widget("boxResize", boxResize);
    builder->get_widget("boxGroupsWeeks", boxGroupsWeeks);
    builder->get_widget("boxGroupsDays", boxGroupsDays);
    builder->get_widget("boxGroupsHours", boxGroupsHours);
    builder->get_widget("boxGroupsMinutes", boxGroupsMinutes);
    builder->get_widget("boxUsersWeeks", boxUsersWeeks);
    builder->get_widget("boxUsersDays", boxUsersDays);
    builder->get_widget("boxUsersHours", boxUsersHours);
    builder->get_widget("boxUsersMinutes", boxUsersMinutes);
    builder->get_widget("boxProjectWeeks", boxProjectWeeks);
    builder->get_widget("boxProjectDays", boxProjectDays);
    builder->get_widget("boxProjectHours", boxProjectHours);
    builder->get_widget("boxProjectMinutes", boxProjectMinutes);
    GtkBuilder *builder = gtk_builder_new_from_file(path_glade);
    gtk_list_project = GTK_LIST_STORE(gtk_builder_get_object(builder, "ListProject"));
    gtk_list_groups = GTK_LIST_STORE(gtk_builder_get_object(builder, "ListGroups"));
    gtk_list_user = GTK_LIST_STORE(gtk_builder_get_object(builder, "ListUser"));
    gtk_list_general = GTK_LIST_STORE(gtk_builder_get_object(builder, "ListGeneral"));
}
/*
void tree_view_del_line() {
    int index = 0;
    GtkTreeIter iter;
    GtkTreeModel *model = GTK_TREE_MODEL(main_config.list);
    GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeViewMain));
    if(gtk_tree_selection_get_selected(selection, &model, &iter)) {
        char* str_iter = yon_char_new(gtk_tree_model_get_string_from_iter(model, &iter));
        index = atoi(str_iter);
        g_object_ref(main_config.list);
        gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->treeViewMain), NULL);
        gtk_list_store_clear(main_config.list);

        main_fill_tree_view_after_remove();
        gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->treeViewMain), model);
        free(str_iter);
    }
}

void MainWindow::tree_view_select() {
    GtkTreeIter iter;
    GtkTreeModel *model = GTK_TREE_MODEL(gtk_list_user);
    GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(usersQuotasTree->gobj()));
    if(gtk_tree_selection_get_selected(selection, &model, &iter)) {
        gtk_widget_set_sensitive(GTK_WIDGET(btnAddUsers->gobj()),1);
        gtk_widget_set_sensitive(GTK_WIDGET(btnEditUsers->gobj()),1);
        gtk_widget_set_sensitive(GTK_WIDGET(btnDelUsers->gobj()),1);
    } 
    else {
        gtk_widget_set_sensitive(GTK_WIDGET(btnAddUsers->gobj()),1);
        gtk_widget_set_sensitive(GTK_WIDGET(btnEditUsers->gobj()),1);
        gtk_widget_set_sensitive(GTK_WIDGET(btnDelUsers->gobj()),0);
    } 
}
void fill_tree_view(int start, int size, int flag_gui_add) {
    GtkTreeModel *model = GTK_TREE_MODEL(main_config.list);
    if (flag_gui_add == 0) {
        g_object_ref(main_config.list);
        gtk_list_store_clear(main_config.list);
    }
    for (int index = start; index < size; index++) {
        GtkTreeIter iter;
        gtk_list_store_append(main_config.list,&iter);
        char* str_io_read = format_io_limit_in_tree_view(main_config.disk, main_config.i_o_limit_read, main_config.i_o_limit_read_size, index);
        char* str_io_write = format_io_limit_in_tree_view(main_config.disk, main_config.i_o_limit_write, main_config.i_o_limit_write_size, index);
        gtk_list_store_set(main_config.list,&iter,0,main_config.type_quota[index],
                                                1,main_config.quota_volume[index],
                                                2,main_config.soft_raw_limit[index],
                                                3,main_config.hard_raw_limit[index],
                                                4,main_config.swap[index],
                                                5,main_config.cpu_limit[index],
                                                6,str_io_read,
                                                7,str_io_write,-1);
        free(str_io_read);
        free(str_io_write);
    }
    if (flag_gui_add != 0) {
        gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->treeViewMain), model);
    }
}

int tree_view_edit() {
    int index = 0;
    GtkTreeIter iter;
    GtkTreeModel *model = GTK_TREE_MODEL(main_config.list);

    GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeViewMain));
    if(gtk_tree_selection_get_selected(selection, &model, &iter)) {
        char* str_iter = gtk_tree_model_get_string_from_iter(model, &iter);
        index = atoi(str_iter);
        gtk_list_store_set(main_config.list,&iter,0,main_config.type_quota[index],
                                                1,main_config.quota_volume[index],
                                                2,main_config.soft_raw_limit[index],
                                                3,main_config.hard_raw_limit[index],
                                                4,main_config.swap[index],
                                                5,main_config.cpu_limit[index],
                                                6,str_io_read,
                                                7,str_io_write,-1);
        return 1;
    }
    else {
        return 0;
    }
    
}
*/

void MainWindow::open_browser() {
    obj_open_browser->open_help();
}

void MainWindow::wrapper_save_system() {
    int id_mess = obj_wrapper_load_save->wrapper_save_system_cfg();
    int error_save = obj_wrapper_load_save->get_error_save();
    int error_load = obj_wrapper_load_save->get_error_load();
    this->info_warning_error(id_mess, error_save, error_load);
}
void MainWindow::wrapper_save_global() {
    int id_mess = obj_wrapper_load_save->wrapper_save_global_cfg();
    int error_save = obj_wrapper_load_save->get_error_save();
    int error_load = obj_wrapper_load_save->get_error_load();
    this->info_warning_error(id_mess, error_save, error_load);
}

void MainWindow::wrapper_save_all() {
    int id_mess = obj_wrapper_load_save->wrapper_save_all_cfg();
    int error_save = obj_wrapper_load_save->get_error_save();
    int error_load = obj_wrapper_load_save->get_error_load();
    this->info_warning_error(id_mess, error_save, error_load);
}

void MainWindow::wrapper_load_system() {
    int id_mess = obj_wrapper_load_save->load_system_cfg();
    int error_save = obj_wrapper_load_save->get_error_save();
    int error_load = obj_wrapper_load_save->get_error_load();
    this->info_warning_error(id_mess, error_save, error_load);
    this->init_work_tv_g_u_p();
}

void MainWindow::wrapper_load_global() {
    int id_mess = obj_wrapper_load_save->load_global_cfg();
    int error_save = obj_wrapper_load_save->get_error_save();
    int error_load = obj_wrapper_load_save->get_error_load();
    this->info_warning_error(id_mess, error_save, error_load);
    this->init_work_tv_g_u_p();
}

void MainWindow::event() {
    boxResize->signal_check_resize().connect(sigc::mem_fun(*this, &MainWindow::resize_widget));
    btnFilterGroups->signal_clicked().connect([&]() {this->filters_show();});
    btnFilterUsers->signal_clicked().connect([&]() {this->filters_show();});
    btnFilterProject->signal_clicked().connect([&]() {this->filters_show();});
    btnSynopsis->signal_activate().connect([&]() {this->open_browser();});
    btnAbout->signal_activate().connect([&]() {obj_open_browser->get_about()->aboutWindows->show();});
    btnSaveLocalGlob->signal_activate().connect([&]() {this->wrapper_save_all();});
    btnSaveGlob->signal_activate().connect([&]() {this->wrapper_save_global();});
    btnSaveLocal->signal_activate().connect([&]() {this->wrapper_save_system();});
    btnLoadGlob->signal_activate().connect([&]() {this->wrapper_load_global();});
    btnLoadLocal->signal_activate().connect([&]() {this->wrapper_load_system();});
    btnEditGroups->signal_clicked().connect(sigc::bind<string> (sigc::mem_fun( *this, 
        &MainWindow::edit_quota_show), str_groups));
    btnEditUsers->signal_clicked().connect(sigc::bind<string> (sigc::mem_fun( *this, 
        &MainWindow::edit_quota_show), str_users));
    btnEditProject->signal_clicked().connect([&]() {this->edit_quota_project_show();});
    chbMangSystemFile->signal_toggled().connect([&]() {this->mode_switch_quota();});
    btnDelGroups->signal_clicked().connect( 
        sigc::bind<Glib::RefPtr<Gtk::ListStore>*, const Gtk::TreeModel::iterator*, bool&> (sigc::mem_fun( *this, 
        &MainWindow::remove_template), &list_store_groups, &iter_groups, flag_validate_del_groups));
    btnDelUsers->signal_clicked().connect( 
        sigc::bind<Glib::RefPtr<Gtk::ListStore>*, const Gtk::TreeModel::iterator*, bool&> (sigc::mem_fun( *this, 
        &MainWindow::remove_template), &list_store_users, &iter_users, flag_validate_del_users));
    btnDelProject->signal_clicked().connect( 
        sigc::bind<Glib::RefPtr<Gtk::ListStore>*, const Gtk::TreeModel::iterator*, bool&> (sigc::mem_fun( *this, 
        &MainWindow::remove_template), &list_store_project, &iter_project, flag_validate_del_project));
    btnAddProject->signal_clicked().connect([&]() {this->obj_view_add_project->show();});
    btnAddUsers->signal_clicked().connect( 
        sigc::bind<string,Gtk::TreeView*, Gtk::TreeModel::Row&, Glib::RefPtr<Gtk::ListStore>&,  struct tv_g_u_p> (sigc::mem_fun( *this, 
        &MainWindow::set_add_tv_g_u_p), str_users, usersQuotasTree, row, list_store_users, obj_tv_g_u_p));
    btnAddGroups->signal_clicked().connect( 
        sigc::bind<string,Gtk::TreeView*, Gtk::TreeModel::Row&, Glib::RefPtr<Gtk::ListStore>&,  struct tv_g_u_p> (sigc::mem_fun( *this, 
        &MainWindow::set_add_tv_g_u_p), str_groups, groupsQuotasTree, row, list_store_groups, obj_tv_g_u_p));
    usersQuotasTree->signal_cursor_changed().connect([&]() {this->obj_view_add_project->show();});
}

void MainWindow::resize_widget() {
    // boxGroupsWeeks = boxGroupsWeeks(Gtk::ORIENTATION_HORIZONTAL);
}

void MainWindow::add_quota_show(string name) {
    obj_view_add->set_label_type_quota(name);
    obj_view_add->show();
}

void MainWindow::edit_quota_show(string name) {
    obj_view_edit->set_label_type_quota(name);
    obj_view_edit->show();
}
void MainWindow::edit_quota_project_show() {
    obj_view_edit_project->show();
}
void MainWindow::remove_template(Glib::RefPtr<Gtk::ListStore>* list_store, const Gtk::TreeModel::iterator* iter, bool& flag_validate_del) {
    if (flag_validate_del && (*list_store)->iter_is_valid(*(iter))) {
        Gtk::TreeModel::Row row = *(*iter);
        if(row) {
            // string name = row[m_columns.name] + "";
            // TODO: : check
            // string key = "GRUB_PASSWORD[" + name + "]";
            // map_gui_cfg[key] = "";
        }
        (*list_store)->erase((*iter));
        flag_validate_del = false;
        info_status_app(info_box_ok_css);
        imgInfo->set_from_icon_name(icon_checked, Gtk::ICON_SIZE_MENU);
        // lblWarning->set_text("");
    }
    flag_validate_del = false;
}

void MainWindow::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) {
    if (this->check_space(tree_view)) {
        row = *(list_store->append());
        row[m_columns.name] = obj_tv_g_u_p.name;
        row[m_columns.quotas] = obj_tv_g_u_p.quotas;
        row[m_columns.size] = obj_tv_g_u_p.size;
        row[m_columns.soft_limit_size] = obj_tv_g_u_p.soft_limit_size; 
        row[m_columns.hard_limit_size] = obj_tv_g_u_p.hard_limit_size; 
        row[m_columns.deferring_size] = obj_tv_g_u_p.deferring_size; 
        row[m_columns.files] = obj_tv_g_u_p.files; 
        row[m_columns.soft_limit_files] = obj_tv_g_u_p.soft_limit_files; 
        row[m_columns.hard_limit_delay] = obj_tv_g_u_p.hard_limit_delay; 
        row[m_columns.deferring_files] = obj_tv_g_u_p.deferring_files;
        this->add_quota_show(name);
    }
}

void MainWindow::mode_switch_quota() {
    // Todo: check
    if (chbMangSystemFile->get_active()) {
        mode_quota = "filesystem";
    }
    else {
        mode_quota = "ubconfig";
    }
}

void MainWindow::filters_show() {
    obj_view_filters->show();
}

bool MainWindow::check_space(Gtk::TreeView* tree_view) {
    Glib::RefPtr<Gtk::TreeModel> tree_view_model = tree_view->get_model();
    Gtk::TreeModel::Children children = tree_view_model->children();
    string name = "";
    string quotas = "";
    for(Gtk::TreeModel::iterator iter = children.begin(); iter != children.end(); ++iter) {
        Gtk::TreeModel::Row row = *iter;
        name = row[m_columns.name] + "";
        quotas = row[m_columns.quotas] + "";
        if (name.length() == 0 || quotas.length() == 0) {
            return false;
        }
    }
    return true;
}

void MainWindow::info_status_app(string stule) {
    Glib::RefPtr<Gtk::StyleContext> boxInfo = boxInfoError->get_style_context();
    boxInfo->remove_class(info_box_ok_css);
    boxInfo->remove_class(info_box_error_css);
    boxInfo->add_class(stule);
}

void MainWindow::init_work_tv_g_u_p() {
    // Todo: remove
    //groupsQuotasTree->remove_all_columns();
    //ProjectQuotasTree->remove_all_columns();
    //usersQuotasTree->remove_all_columns();
    list_store_groups = Gtk::ListStore::create(m_columns);
    list_store_project = Gtk::ListStore::create(m_columns);
    list_store_users = Gtk::ListStore::create(m_columns);
    groupsQuotasTree->set_model(list_store_groups);
    ProjectQuotasTree->set_model(list_store_project);
    usersQuotasTree->set_model(list_store_users);
    Glib::RefPtr<Gtk::TreeModel> groupsQuotasTreeModel = groupsQuotasTree->get_model();
    groupsQuotasTreeModel->signal_row_changed().connect(sigc::bind<Gtk::TreeModel::iterator&, bool&> 
    (sigc::mem_fun(*this, &MainWindow::remove_line_template), iter_groups, flag_validate_del_groups));
    Glib::RefPtr<Gtk::TreeModel> ProjectQuotasTreeModel = ProjectQuotasTree->get_model();
    ProjectQuotasTreeModel->signal_row_changed().connect(sigc::bind<Gtk::TreeModel::iterator&, bool&> 
    (sigc::mem_fun(*this, &MainWindow::remove_line_template), iter_project, flag_validate_del_project));
    Glib::RefPtr<Gtk::TreeModel> usersQuotasTreeModel = usersQuotasTree->get_model();
    usersQuotasTreeModel->signal_row_changed().connect(sigc::bind<Gtk::TreeModel::iterator&, bool&> 
    (sigc::mem_fun(*this, &MainWindow::remove_line_template),iter_users, flag_validate_del_users));
}

void MainWindow::remove_line_template(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter, Gtk::TreeModel::iterator& iter_del, bool& flag_del) {
    iter_del = iter;
    flag_del = true;
}

void help() {
    string version = string(str_version) + version_application + "\n";
    cout << version.c_str();
    cout << str_help_h;
}

MainWindow::~MainWindow() {}

#endif

