ClienteTFG/controller_user_info.cpp

55 lines
1.7 KiB
C++
Raw Normal View History

2020-05-20 00:09:18 +02:00
#include "controller_user_info.h"
2020-05-23 19:59:55 +02:00
#include "dialog_add_user.h"
2020-05-20 00:09:18 +02:00
2020-05-23 19:59:55 +02:00
#include <gtkmm/messagedialog.h>
#include <iostream>
2020-05-20 00:09:18 +02:00
2020-05-23 19:59:55 +02:00
controller_user_info::controller_user_info(view_user_info *view, session_manager *sesion, Gtk::Window *container)
2020-05-20 00:09:18 +02:00
{
this->view=view;
this->sesion=sesion;
2020-05-23 19:59:55 +02:00
this->container=container;
2020-05-20 00:09:18 +02:00
this->load_info();
2020-05-23 19:59:55 +02:00
this->add_controlers();
2020-05-20 00:09:18 +02:00
}
void controller_user_info::load_info(){
std::list<std::string> list=this->sesion->get_users_info();
for(std::string data:list){
Gtk::TreeModel::Row row = *(this->view->m_refTreeModel->append());
row[this->view->m_Columns.r_user]=get_first(data);
row[this->view->m_Columns.r_admin]=(get_first(data)=="t");
}
}
2020-05-23 19:59:55 +02:00
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();
2020-05-26 01:37:11 +02:00
std::string name=row.get_value(this->view->m_Columns.r_user);
if(name.find("Gtk-CRITICAL **:")==std::string::npos){
this->sesion->remove_user(name);
}
this->view->restart_table();
this->load_info();
2020-05-23 19:59:55 +02:00
}
2020-05-20 00:09:18 +02:00
std::string controller_user_info::get_first(std::string &info){
int pos = info.find(":");
std::string ret = info.substr(0, pos);
info=info.substr(pos+1, info.size()+1);
return ret;
}