#include "controller.h"

int socket_ext_id_I = 0;
int socket_trd_id_I = 0;

Controller::Controller(BaseObjectType* obj, Glib::RefPtr<Gtk::Builder> const& builder)
    :Gtk::ApplicationWindow(obj), builder{builder} {
    this->builder = builder;
    this->settings();
}

Controller::Controller(Glib::RefPtr<Gtk::Builder> const& builder) {
    this->builder =  builder;
    this->settings();
}

Controller::~Controller()
{
}

void Controller::settings() {
    obj_open_browser->set_obj_about(obj_view_about);
    obj_main_window = new MainWindow(builder, obj_open_browser, &socket_ext_id_I, &socket_trd_id_I);
    obj_main_window->set_obj_wrapper_load_save(obj_wrapper_load_save);
    obj_open_browser->settings();
    obj_main_window->set_map_gui(&map_gui_cfg);
    obj_main_window->set_map_global(&map_global_cfg);
    obj_main_window->set_map_local(&map_system_cfg);
    obj_main_window->set_obj_view_filters(&obj_view_filters);
    obj_main_window->set_obj_view_edit(&obj_view_edit);
    obj_main_window->set_obj_view_add(&obj_view_add);
    obj_main_window->set_obj_view_add_project(&obj_view_add_project);
    obj_main_window->set_obj_view_edit_project(&obj_view_edit_project);
    obj_main_window->settings();
}

CmdArgParser::CmdArgParser(const std::string& p_name, const std::string& p_description, const std::string& p_help)
: Glib::OptionGroup{p_name, p_description, p_help} {
    Glib::OptionEntry socketIDArg;
    socketIDArg.set_long_name("socket-id");
    socketIDArg.set_flags(Glib::OptionEntry::FLAG_IN_MAIN);
    socketIDArg.set_description("Settings manager socket");
    Glib::OptionEntry socketExtId;
    socketExtId.set_long_name("socket-ext-id");
    socketExtId.set_flags(Glib::OptionEntry::FLAG_IN_MAIN);
    socketExtId.set_description("Settings manager secondary socket");
    Glib::OptionEntry socketTrdId;
    socketTrdId.set_long_name("socket-trd-id");
    socketTrdId.set_flags(Glib::OptionEntry::FLAG_IN_MAIN);
    socketTrdId.set_description("Settings manager secondary socket");
    add_entry(socketIDArg, m_socketID);
    add_entry(socketExtId, socket_ext_id_I);
    add_entry(socketTrdId, socket_trd_id_I);
}

::Window CmdArgParser::GetSocketID() const{
    return m_socketID;
}

SettingsPlug::SettingsPlug(::Window p_socketID, Glib::RefPtr<Gtk::Builder> builder)
    :Gtk::Plug{p_socketID} {
    Controller* wnd = nullptr;
    builder->get_widget_derived("window", wnd);
    builder->get_widget("plugBox", plugBox);
    plugBox->get_parent()->remove(*plugBox);
    add(*plugBox);
    show_all_children();
}