#include "view_add_project.h"
#include <vector>

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

View_add_project::~View_add_project()
{
}

void View_add_project::setting() {
    this->get_builder();
    this->lacalization();
    check_limit(quotegroupSizeSoftLimitCheckProject
        ,quotegroupSizeSoftLimitSpinProject
        ,quotegroupSizeSoftLimitComboProject);
    check_limit(quotegroupSizeHardLimitCheckProject
        ,quotegroupSizeHardLimitSpin1
        ,quotegroupSizeHardLimitComboProject);
    check_limit(quotegroupFilesSoftLimitCheckProject
        ,quotegroupFilesSoftLimitSpinProject
        ,quotegroupFilesSoftLimitlabelProject);
    check_limit(quotegroupFilesHardLimitCheckProject
        ,quotegroupFilesHardLimitSpinProject
        ,quotegroupFilesHarLimitLabelProject);
    this->event();
    // ector<string> vec_user = pars_users();
    
}

void View_add_project::load_combo_box_UGP(vector<string> vec_UGP) {
    cmbSetNameUGP->remove_all();
    for (auto& iter: vec_UGP) {
        cmbSetNameUGP->append(iter);
    }
}

void View_add_project::event() {
    quotegroupSizeSoftLimitCheckProject->signal_toggled().connect([&]() {
        check_limit(quotegroupSizeSoftLimitCheckProject
            ,quotegroupSizeSoftLimitSpinProject
            ,quotegroupSizeSoftLimitComboProject);
    });
    quotegroupSizeHardLimitCheckProject->signal_toggled().connect([&]() {
        check_limit(quotegroupSizeHardLimitCheckProject
            ,quotegroupSizeHardLimitSpin1
            ,quotegroupSizeHardLimitComboProject);
    });
    quotegroupFilesSoftLimitCheckProject->signal_toggled().connect([&]() {
        check_limit(quotegroupFilesSoftLimitCheckProject
            ,quotegroupFilesSoftLimitSpinProject
            ,quotegroupFilesSoftLimitlabelProject);
    });
    quotegroupFilesHardLimitCheckProject->signal_toggled().connect([&]() {
        check_limit(quotegroupFilesHardLimitCheckProject
            ,quotegroupFilesHardLimitSpinProject
            ,quotegroupFilesHarLimitLabelProject);
    });
    quotegroupCancelButtonAdd->signal_clicked().connect([&]() {this->close_wnd();});
    quotegroupSaveButtonAdd->signal_clicked().connect([&]() {this->save();});
    btnReviewProject->signal_clicked().connect([&]() {show_file_manager();});
    btnFilemangerOk->signal_clicked().connect([&]() {save_file_manager();});
    btnFilemangerExit->signal_clicked().connect([&]() {wndChooseFileWallpaper->hide();});
}

void View_add_project::show_file_manager() {
    wndChooseFileWallpaper->set_current_folder(open_dir_file_manager);
    wndChooseFileWallpaper->show();
}

void View_add_project::save_file_manager() {
    entryCatalogProject->set_text(wndChooseFileWallpaper->get_filename());
    wndChooseFileWallpaper->hide();
}
void View_add_project::close_wnd() {
    wndQuotasAddProject->hide();
}

void View_add_project::save() {
    wndQuotasAddProject->hide();
}

void View_add_project::show() {
    wndQuotasAddProject->show();
}

void View_add_project::get_builder() {
    builder->get_widget("wndQuotasAddProject", wndQuotasAddProject);
    builder->get_widget("quotegroupSizeFrameLabelProject", quotegroupSizeFrameLabelProject);
    builder->get_widget("quotegroupFilesFrameLabelProject", quotegroupFilesFrameLabelProject);
    builder->get_widget("quotegroupSizeCurrentlyLabelProject", quotegroupSizeCurrentlyLabelProject);
    builder->get_widget("quotegroupFilesCurrentlyLabelProject", quotegroupFilesCurrentlyLabelProject);
    builder->get_widget("quotegroupSizeSoftLimitLabelProject", quotegroupSizeSoftLimitLabelProject);
    builder->get_widget("quotegroupFilesSoftLimitLabelProject", quotegroupFilesSoftLimitLabelProject);
    builder->get_widget("quoteSizeHardLimitLabelProject", quoteSizeHardLimitLabelProject);
    builder->get_widget("quoteFilesHardLimitLabelProject", quoteFilesHardLimitLabelProject);
    builder->get_widget("quotegroupFilesSoftLimitlabelProject", quotegroupFilesSoftLimitlabelProject);
    builder->get_widget("quotegroupFilesHarLimitLabelProject", quotegroupFilesHarLimitLabelProject);
    builder->get_widget("quotegroupCancelButtonAdd", quotegroupCancelButtonAdd);
    builder->get_widget("quotegroupSaveButtonAdd", quotegroupSaveButtonAdd);
    builder->get_widget("lblDeviceProject", lblDeviceProject);
    builder->get_widget("lblStatusQuotaProject", lblStatusQuotaProject);
    builder->get_widget("lblCatalogProject", lblCatalogProject);
    builder->get_widget("lblProjectId", lblProjectId);
    builder->get_widget("lblProjectName", lblProjectName);
    builder->get_widget("btnReviewProject", btnReviewProject);
    builder->get_widget("btnGenerateProject", btnGenerateProject);
    builder->get_widget("chbAuto", chbAuto);
    builder->get_widget("entryCatalogProject", entryCatalogProject);
    builder->get_widget("entryProjectId", entryProjectId);
    builder->get_widget("entryProjectName", entryProjectName);
    builder->get_widget("quotegroupSizeSoftLimitCheckProject", quotegroupSizeSoftLimitCheckProject);
    builder->get_widget("quotegroupSizeHardLimitCheckProject", quotegroupSizeHardLimitCheckProject);
    builder->get_widget("quotegroupFilesSoftLimitCheckProject", quotegroupFilesSoftLimitCheckProject);
    builder->get_widget("quotegroupFilesHardLimitCheckProject", quotegroupFilesHardLimitCheckProject);
    builder->get_widget("quotegroupSizeSoftLimitSpinProject", quotegroupSizeSoftLimitSpinProject);
    builder->get_widget("quotegroupSizeHardLimitSpin1", quotegroupSizeHardLimitSpin1);
    builder->get_widget("quotegroupFilesSoftLimitSpinProject", quotegroupFilesSoftLimitSpinProject);
    builder->get_widget("quotegroupFilesHardLimitSpinProject", quotegroupFilesHardLimitSpinProject);
    builder->get_widget("quotegroupSizeSoftLimitComboProject", quotegroupSizeSoftLimitComboProject);
    builder->get_widget("quotegroupSizeHardLimitComboProject", quotegroupSizeHardLimitComboProject);
    builder->get_widget("wndChooseFileWallpaper", wndChooseFileWallpaper);
    builder->get_widget("btnFilemangerExit", btnFilemangerExit);
    builder->get_widget("btnFilemangerOk", btnFilemangerOk);
}

void View_add_project::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_project::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());
}

