#include "view_filters.h"

View_filters::View_filters(/* args */){
    builder = Gtk::Builder::create_from_file(path_glade);
    this->settings();
}

View_filters::~View_filters()
{
}

void View_filters::settings() {
    this->get_builder();
    this->lacalization();
    this->set_map_flag(chbFilterName);
    this->set_map_flag(chbFilterQuotas);
    this->set_map_flag(chbFilterSize);
    this->set_map_flag(chbFilterSoftLimitSize);
    this->set_map_flag(chbFilterHardLimitSize);
    this->set_map_flag(chbFilterHardLimitSizeDelay);
    this->set_map_flag(chbFilterFiles);
    this->set_map_flag(chbFilterSoftLimitFile);
    this->set_map_flag(chbFilterHardLimitFile);
    this->set_map_flag(chbFilterHardLimitFileDelay);
    this->event();
}

void View_filters::get_builder() {
    builder->get_widget("wndFilters", wndFilters);
    builder->get_widget("chbFilterName", chbFilterName);
    builder->get_widget("chbFilterQuotas", chbFilterQuotas);
    builder->get_widget("chbFilterSize", chbFilterSize);
    builder->get_widget("chbFilterSoftLimitSize", chbFilterSoftLimitSize);
    builder->get_widget("chbFilterHardLimitSize", chbFilterHardLimitSize);
    builder->get_widget("chbFilterHardLimitSizeDelay", chbFilterHardLimitSizeDelay);
    builder->get_widget("chbFilterFiles", chbFilterFiles);
    builder->get_widget("chbFilterSoftLimitFile", chbFilterSoftLimitFile);
    builder->get_widget("chbFilterHardLimitFile", chbFilterHardLimitFile);
    builder->get_widget("chbFilterHardLimitFileDelay", chbFilterHardLimitFileDelay);
    builder->get_widget("lblFiltersHead", lblFiltersHead);
    builder->get_widget("btnFiltersSave", btnFiltersSave);
    builder->get_widget("btnFiltersCancel", btnFiltersCancel);
    lblFiltersHead->set_label(str_filters);
}

void View_filters::show() {
    this->set_map_flag_false();
    wndFilters->show();
}

void View_filters::lacalization() {
    /*
    chbFilterName->set_label(str_name);
    chbFilterQuotas->set_label(str_quotas);
    chbFilterSize->set_label(str_size);
    chbFilterSoftLimitSize->set_label(str_soft_limit_size);
    chbFilterHardLimitSize->set_label(str_hard_limit_size);
    chbFilterHardLimitSizeDelay->set_label(str_deferring_hard_limit_size);
    chbFilterFiles->set_label(str_files);
    chbFilterSoftLimitFile->set_label(str_soft_restriction_files);
    chbFilterHardLimitFile->set_label(str_severe_limitation_files);
    chbFilterHardLimitFileDelay->set_label(str_deferring_limit_files);
    */
}

void View_filters::event() {
    chbFilterName->signal_toggled().connect( 
        sigc::bind<Gtk::CheckButton*> (sigc::mem_fun(*this, 
        &View_filters::set_map_flag), chbFilterName));
    chbFilterQuotas->signal_toggled().connect( 
        sigc::bind<Gtk::CheckButton*> (sigc::mem_fun(*this, 
        &View_filters::set_map_flag), chbFilterQuotas));
    chbFilterSize->signal_toggled().connect( 
        sigc::bind<Gtk::CheckButton*> (sigc::mem_fun(*this, 
        &View_filters::set_map_flag), chbFilterSize));
    chbFilterSoftLimitSize->signal_toggled().connect( 
        sigc::bind<Gtk::CheckButton*> (sigc::mem_fun(*this, 
        &View_filters::set_map_flag), chbFilterSoftLimitSize));
    chbFilterHardLimitSize->signal_toggled().connect( 
        sigc::bind<Gtk::CheckButton*> (sigc::mem_fun(*this, 
        &View_filters::set_map_flag), chbFilterHardLimitSize));
    chbFilterHardLimitSizeDelay->signal_toggled().connect( 
        sigc::bind<Gtk::CheckButton*> (sigc::mem_fun(*this, 
        &View_filters::set_map_flag), chbFilterHardLimitSizeDelay));
    chbFilterFiles->signal_toggled().connect( 
        sigc::bind<Gtk::CheckButton*> (sigc::mem_fun(*this, 
        &View_filters::set_map_flag), chbFilterFiles));
    chbFilterSoftLimitFile->signal_toggled().connect( 
        sigc::bind<Gtk::CheckButton*> (sigc::mem_fun(*this, 
        &View_filters::set_map_flag), chbFilterSoftLimitFile));
    chbFilterHardLimitFile->signal_toggled().connect( 
        sigc::bind<Gtk::CheckButton*> (sigc::mem_fun(*this, 
        &View_filters::set_map_flag), chbFilterHardLimitFile));
    chbFilterHardLimitFileDelay->signal_toggled().connect( 
        sigc::bind<Gtk::CheckButton*> (sigc::mem_fun(*this, 
        &View_filters::set_map_flag), chbFilterHardLimitFileDelay));
    btnFiltersSave->signal_clicked().connect(sigc::mem_fun(*this, 
        &View_filters::btn_save));
    btnFiltersCancel->signal_clicked().connect(sigc::mem_fun(*this, 
        &View_filters::btn_cancel));
}

void View_filters::set_map_flag(Gtk::CheckButton* check_button) {
    map_filters_flag[check_button->get_label()] = check_button->get_active();
}

void View_filters::btn_save() {
    wndFilters->hide();
}

void View_filters::btn_cancel() {
    wndFilters->hide();
}

map<string, bool> View_filters::get_filters() {
    return map_filters_flag;
}

void View_filters::set_map_flag_false() {
    for (auto& [key, value]: map_filters_flag) {
        map_filters_flag[key] = false;
    }
}