From 03f2c319893046d69ab7f585c9cbe2fb5a2ed16e Mon Sep 17 00:00:00 2001 From: groche97 Date: Sat, 23 May 2020 19:59:55 +0200 Subject: [PATCH] add suport to add users --- ClienteTFG.pro | 6 ++++-- ClienteTFG.pro.user | 2 +- container_window.cpp | 2 +- controller_user_info.cpp | 27 ++++++++++++++++++++++++++- controller_user_info.h | 6 +++++- dialog_add_user.cpp | 37 +++++++++++++++++++++++++++++++++++++ dialog_add_user.h | 37 +++++++++++++++++++++++++++++++++++++ session_manager.cpp | 7 +++++++ session_manager.h | 1 + view_user_info.cpp | 9 +++++++++ view_user_info.h | 6 +++++- 11 files changed, 133 insertions(+), 7 deletions(-) create mode 100644 dialog_add_user.cpp create mode 100644 dialog_add_user.h diff --git a/ClienteTFG.pro b/ClienteTFG.pro index 60d7745..2fe31a8 100644 --- a/ClienteTFG.pro +++ b/ClienteTFG.pro @@ -22,7 +22,8 @@ SOURCES += \ view_info.cpp \ controller_info.cpp \ view_user_info.cpp \ - controller_user_info.cpp + controller_user_info.cpp \ + dialog_add_user.cpp HEADERS += \ conexion.h \ @@ -39,4 +40,5 @@ HEADERS += \ view_info.h \ controller_info.h \ view_user_info.h \ - controller_user_info.h + controller_user_info.h \ + dialog_add_user.h diff --git a/ClienteTFG.pro.user b/ClienteTFG.pro.user index 5ae0ad5..d0e3c07 100644 --- a/ClienteTFG.pro.user +++ b/ClienteTFG.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/container_window.cpp b/container_window.cpp index 93197ec..ce6a8b8 100644 --- a/container_window.cpp +++ b/container_window.cpp @@ -9,7 +9,7 @@ container_window::container_window(conexion *con, Glib::RefPtr< Gtk::Application this->cont_inst=new controller_install(&install, sesion.get()); this->cont_rem=new controller_remove(&remove, sesion.get()); this->cont_info=new controller_info(&info, sesion.get()); - this->con_uinfo=new controller_user_info(&uinfo, sesion.get()); + this->con_uinfo=new controller_user_info(&uinfo, sesion.get(), this); this->app.reset(); this->app=Gtk::Application::create( "org.gtkmm.examples.base"); this->add(this->book); diff --git a/controller_user_info.cpp b/controller_user_info.cpp index 34f543a..dd368b4 100644 --- a/controller_user_info.cpp +++ b/controller_user_info.cpp @@ -1,11 +1,16 @@ #include "controller_user_info.h" +#include "dialog_add_user.h" +#include +#include -controller_user_info::controller_user_info(view_user_info *view, session_manager *sesion) +controller_user_info::controller_user_info(view_user_info *view, session_manager *sesion, Gtk::Window *container) { this->view=view; this->sesion=sesion; + this->container=container; this->load_info(); + this->add_controlers(); } void controller_user_info::load_info(){ @@ -17,6 +22,26 @@ void controller_user_info::load_info(){ } } +void controller_user_info::add_controlers(){ + this->view->b_add_user.signal_clicked().connect(sigc::mem_fun(this, + &controller_user_info::on_button_clicked_add)); + this->view->b_dell_user.signal_clicked().connect(sigc::mem_fun(this, + &controller_user_info::on_button_clicked_remove)); +} + +void controller_user_info::on_button_clicked_add(){ + dialog_add_user dialog(this->container, sesion); + dialog.run(); + this->view->restart_table(); + this->load_info(); +} + +void controller_user_info::on_button_clicked_remove(){ + Gtk::TreeModel::Row row = *this->view->tree.get_selection()->get_selected(); + //row.get_value(this->view->m_Columns.r_user); + std::cout << row.get_value(this->view->m_Columns.r_user) << std::endl; +} + std::string controller_user_info::get_first(std::string &info){ int pos = info.find(":"); std::string ret = info.substr(0, pos); diff --git a/controller_user_info.h b/controller_user_info.h index e7a9db4..36665a6 100644 --- a/controller_user_info.h +++ b/controller_user_info.h @@ -7,11 +7,15 @@ class controller_user_info { public: - controller_user_info(view_user_info *view, session_manager *session); + controller_user_info(view_user_info *view, session_manager *session, Gtk::Window *container); private: view_user_info *view; session_manager *sesion; + Gtk::Window *container; void load_info(); + void add_controlers(); + void on_button_clicked_add(); + void on_button_clicked_remove(); std::string get_first(std::string &info); }; diff --git a/dialog_add_user.cpp b/dialog_add_user.cpp new file mode 100644 index 0000000..90c047d --- /dev/null +++ b/dialog_add_user.cpp @@ -0,0 +1,37 @@ +#include "dialog_add_user.h" + +dialog_add_user::dialog_add_user(Gtk::Window *win, session_manager *sesion) + : Gtk::Dialog("Create user", *win, false), + box_user(Gtk::ORIENTATION_HORIZONTAL), user("user"), + box_pass(Gtk::ORIENTATION_HORIZONTAL), pass("password"), + box_admin(Gtk::ORIENTATION_HORIZONTAL), l_admin("admin permision"), + b_add("create") +{ + this->sesion=sesion; + this->entry_pass.set_visibility(false); + this->b_add.signal_clicked().connect(sigc::mem_fun(this, + &dialog_add_user::on_button_clicked)); + this->add_elements(); + this->show_all_children(); +} + +void dialog_add_user::on_button_clicked(){ + this->sesion->create_user(this->entry_user.get_text(), this->entry_pass.get_text(), this->c_admin.get_active()); + this->hide(); +} + +void dialog_add_user::add_elements(){ + this->box_user.add(this->user); + this->box_user.add(this->entry_user); + + this->box_pass.add(this->pass); + this->box_pass.add(this->entry_pass); + + this->box_admin.add(this->l_admin); + this->box_admin.add(this->c_admin); + + this->get_content_area()->add(this->box_user); + this->get_content_area()->add(this->box_pass); + this->get_content_area()->add(this->box_admin); + this->get_content_area()->add(this->b_add); +} diff --git a/dialog_add_user.h b/dialog_add_user.h new file mode 100644 index 0000000..5c0a9a4 --- /dev/null +++ b/dialog_add_user.h @@ -0,0 +1,37 @@ +#ifndef DIALOG_ADD_USER_H +#define DIALOG_ADD_USER_H + +#include +#include +#include +#include +#include + +#include "session_manager.h" + +class dialog_add_user : public Gtk::Dialog +{ +public: + dialog_add_user(Gtk::Window *win, session_manager *sesion); +private: + session_manager *sesion; + + Gtk::Box box_user; + Gtk::Label user; + Gtk::Entry entry_user; + + Gtk::Box box_pass; + Gtk::Label pass; + Gtk::Entry entry_pass; + + Gtk::Box box_admin; + Gtk::Label l_admin; + Gtk::CheckButton c_admin; + + Gtk::Button b_add; + + void on_button_clicked(); + void add_elements(); +}; + +#endif // DIALOG_ADD_USER_H diff --git a/session_manager.cpp b/session_manager.cpp index 80221a2..4e3eedf 100644 --- a/session_manager.cpp +++ b/session_manager.cpp @@ -60,3 +60,10 @@ std::list session_manager::get_users_info(){ } return ret; } + +void session_manager::create_user(std::string username, std::string password, bool admin){ + this->con->write_string("cusr"); + this->con->write_string(username); + this->con->write_string(password); + this->con->write_string(admin?"t":"f"); +} diff --git a/session_manager.h b/session_manager.h index 393daa6..fb50b2d 100644 --- a/session_manager.h +++ b/session_manager.h @@ -16,6 +16,7 @@ public: int remove_command(std::string package); std::list get_packages_info(); std::list get_users_info(); + void create_user(std::string username, std::string password, bool admin); }; #endif // SESSION_MANAGER_H diff --git a/view_user_info.cpp b/view_user_info.cpp index b9604ec..0fd4ecf 100644 --- a/view_user_info.cpp +++ b/view_user_info.cpp @@ -1,6 +1,8 @@ #include "view_user_info.h" view_user_info::view_user_info() + :Gtk::Box(Gtk::ORIENTATION_VERTICAL), + b_add_user("add user"), b_dell_user("delete user") { this->m_refTreeModel = Gtk::ListStore::create(this->m_Columns); this->tree.set_model(this->m_refTreeModel); @@ -8,4 +10,11 @@ view_user_info::view_user_info() tree.append_column("user", m_Columns.r_user); tree.append_column("config", m_Columns.r_admin); this->add(this->tree); + this->add(this->b_add_user); + this->add(this->b_dell_user); +} + +void view_user_info::restart_table(){ + this->m_refTreeModel = Gtk::ListStore::create(this->m_Columns); + this->tree.set_model(this->m_refTreeModel); } diff --git a/view_user_info.h b/view_user_info.h index f383e56..8f06635 100644 --- a/view_user_info.h +++ b/view_user_info.h @@ -19,8 +19,12 @@ public: Gtk::TreeModelColumn r_admin; }; - ModelColumns m_Columns; + ModelColumns m_Columns; Glib::RefPtr m_refTreeModel; + Gtk::Button b_add_user; + Gtk::Button b_dell_user; + + void restart_table(); }; #endif // VIEW_USER_INFO_H