#include "view_add_user_group.h"


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

View_add_user_group::~View_add_user_group() {
}

void View_add_user_group::settings() {
    this->get_builder();
    this->lacalization();
    check_limit(quotegroupSizeSoftLimitCheck
        ,quotegroupSizeSoftLimitSpin
        ,quotegroupSizeSoftLimitCombo);
    check_limit(quotegroupSizeHardLimitCheck
        ,quotegroupSizeHardLimitSpin
        ,quotegroupSizeHardLimitCombo);
    check_limit(quotegroupFilesSoftLimitCheck
        ,quotegroupFilesSoftLimitSpin
        ,quotegroupFilesSoftLimitlabel);
    check_limit(quotegroupFilesHardLimitCheck
        ,quotegroupFilesHardLimitSpin
        ,quotegroupFilesHarLimitLabel);
    this->event();
}

void View_add_user_group::event() {
    quotegroupCancelButton->signal_clicked().connect([&]() {QuotasEditWindow->hide();});
    quotegroupSaveButton->signal_clicked().connect([&]() {});
    quotegroupSizeSoftLimitCheck->signal_toggled().connect([&]() {
        check_limit(quotegroupSizeSoftLimitCheck
        ,quotegroupSizeSoftLimitSpin
        ,quotegroupSizeSoftLimitCombo);
    });
    quotegroupSizeHardLimitCheck->signal_toggled().connect([&]() {
        check_limit(quotegroupSizeHardLimitCheck
        ,quotegroupSizeHardLimitSpin
        ,quotegroupSizeHardLimitCombo);
    });
    quotegroupFilesSoftLimitCheck->signal_toggled().connect([&]() {
        check_limit(quotegroupFilesSoftLimitCheck
        ,quotegroupFilesSoftLimitSpin
        ,quotegroupFilesSoftLimitlabel);
    });
    quotegroupFilesHardLimitCheck->signal_toggled().connect([&]() {
        check_limit(quotegroupFilesHardLimitCheck
        ,quotegroupFilesHardLimitSpin
        ,quotegroupFilesHarLimitLabel);
    });
    
}

void View_add_user_group::get_builder() {
    builder->get_widget("lblSetDevice", lblSetDevice);
    builder->get_widget("lblQuotasStatus", lblQuotasStatus);
    builder->get_widget("lblSetUGP", lblSetUGP);
    builder->get_widget("lblSetNameDevice", lblSetNameDevice);
    builder->get_widget("lblSetQuotasStatus", lblSetQuotasStatus);
    builder->get_widget("cmbSetNameUGP", cmbSetNameUGP);
    builder->get_widget("quotegroupSizeFrameLabel", quotegroupSizeFrameLabel);
    builder->get_widget("quotegroupFilesFrameLabel", quotegroupFilesFrameLabel);
    builder->get_widget("quotegroupSizeCurrentlyLabel", quotegroupSizeCurrentlyLabel);
    builder->get_widget("quotegroupFilesCurrentlyLabel", quotegroupFilesCurrentlyLabel);
    builder->get_widget("quotegroupSizeSoftLimitLabel", quotegroupSizeSoftLimitLabel);
    builder->get_widget("quoteSizeHardLimitLabel", quoteSizeHardLimitLabel);
    builder->get_widget("quotegroupFilesSoftLimitLabel", quotegroupFilesSoftLimitLabel);
    builder->get_widget("quoteFilesHardLimitLabel", quoteFilesHardLimitLabel);
    builder->get_widget("quotegroupFilesHarLimitLabel", quotegroupFilesHarLimitLabel);
    builder->get_widget("QuotasEditWindow", QuotasEditWindow);
    builder->get_widget("lblHeadQuotasEditWindow", lblHeadQuotasEditWindow);
    builder->get_widget("quotegroupCancelButton", quotegroupCancelButton);
    builder->get_widget("quotegroupSaveButton", quotegroupSaveButton);
    builder->get_widget("quotegroupSizeSoftLimitSpin", quotegroupSizeSoftLimitSpin);
    builder->get_widget("quotegroupSizeHardLimitSpin", quotegroupSizeHardLimitSpin);
    builder->get_widget("quotegroupFilesSoftLimitSpin", quotegroupFilesSoftLimitSpin);
    builder->get_widget("quotegroupFilesHardLimitSpin", quotegroupFilesHardLimitSpin);
    builder->get_widget("quotegroupFilesSoftLimitlabel", quotegroupFilesSoftLimitlabel);
    builder->get_widget("quotegroupSizeSoftLimitCombo", quotegroupSizeSoftLimitCombo);
    builder->get_widget("quotegroupSizeHardLimitCombo", quotegroupSizeHardLimitCombo);
    builder->get_widget("quotegroupSizeSoftLimitCheck", quotegroupSizeSoftLimitCheck);
    builder->get_widget("quotegroupSizeHardLimitCheck", quotegroupSizeHardLimitCheck);
    builder->get_widget("quotegroupFilesSoftLimitCheck", quotegroupFilesSoftLimitCheck);
    builder->get_widget("quotegroupFilesHardLimitCheck", quotegroupFilesHardLimitCheck);
    
}

void View_add_user_group::show() {
    QuotasEditWindow->show();
}

void View_add_user_group::lacalization() {
    this->fill_in_pow_memory(quotegroupSizeSoftLimitCombo);
    this->fill_in_pow_memory(quotegroupSizeHardLimitCombo);
    
}

void View_add_user_group::check_limit(Gtk::CheckButton *check_button, Gtk::SpinButton *spin, Gtk::ComboBoxText *combo_box) {
    spin->set_sensitive(check_button->get_active());
    combo_box->set_sensitive(check_button->get_active());
}
void View_add_user_group::check_limit(Gtk::CheckButton *check_button, Gtk::SpinButton *spin, Gtk::Label *combo_box) {
    spin->set_sensitive(check_button->get_active());
    combo_box->set_sensitive(check_button->get_active());
}

void View_add_user_group::fill_in_pow_memory(Gtk::ComboBoxText *cb_text) {
    cb_text->append(str_prefix_KB);
    cb_text->append(str_prefix_MB);
    cb_text->append(str_prefix_GB);
    cb_text->append(str_prefix_TB);
}

void View_add_user_group::set_label_type_quota(string name) {
    lblSetUGP->set_text(name);
}
