add user list

This commit is contained in:
Guillermo Roche 2020-05-20 00:09:18 +02:00
parent 4fc3d964ce
commit 021139d669
12 changed files with 115 additions and 15 deletions

View File

@ -20,7 +20,9 @@ SOURCES += \
view_remove.cpp \
controller_remove.cpp \
view_info.cpp \
controller_info.cpp
controller_info.cpp \
view_user_info.cpp \
controller_user_info.cpp
HEADERS += \
conexion.h \
@ -35,4 +37,6 @@ HEADERS += \
view_remove.h \
controller_remove.h \
view_info.h \
controller_info.h
controller_info.h \
view_user_info.h \
controller_user_info.h

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.8.2, 2020-05-18T00:49:30. -->
<!-- Written by QtCreator 4.8.2, 2020-05-20T00:08:38. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@ -9,12 +9,14 @@ 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->app.reset();
this->app=Gtk::Application::create( "org.gtkmm.examples.base");
this->add(this->book);
this->book.append_page(install,"build");
this->book.append_page(remove,"remove");
this->book.append_page(this->info,"info");
this->book.append_page(this->uinfo,"users");
this->show_all_children();
this->app->run(*this);
}

View File

@ -9,6 +9,8 @@
#include "controller_remove.h"
#include "view_info.h"
#include "controller_info.h"
#include "view_user_info.h"
#include "controller_user_info.h"
#include <gtkmm/notebook.h>
#include <memory>
@ -24,9 +26,11 @@ private:
view_install install;
view_remove remove;
view_info info;
view_user_info uinfo;
controller_install *cont_inst;
controller_remove *cont_rem;
controller_info *cont_info;
controller_user_info *con_uinfo;
Gtk::Notebook book;
};

View File

@ -1,13 +1,5 @@
#include "controller_info.h"
#include <iostream>
std::string 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;
}
controller_info::controller_info(view_info *view, session_manager *sesion)
{
@ -25,9 +17,11 @@ void controller_info::load_info(){
row[this->view->m_Columns.r_config]=(get_first(data)=="t");
row[this->view->m_Columns.r_user]=get_first(data);
}
/*row[this->view->m_Columns.r_name] = "firefox";
row[this->view->m_Columns.r_date] = "2020-10-2";
row[this->view->m_Columns.r_config] = true;
row[this->view->m_Columns.r_user] = "pepe";*/
}
std::string controller_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;
}

View File

@ -12,6 +12,7 @@ private:
view_info *view;
session_manager *sesion;
void load_info();
std::string get_first(std::string &info);
};
#endif // CONTROLLER_INFO_H

25
controller_user_info.cpp Normal file
View File

@ -0,0 +1,25 @@
#include "controller_user_info.h"
controller_user_info::controller_user_info(view_user_info *view, session_manager *sesion)
{
this->view=view;
this->sesion=sesion;
this->load_info();
}
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");
}
}
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;
}

18
controller_user_info.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef CONTROLLER_USER_INFO_H
#define CONTROLLER_USER_INFO_H
#include "view_user_info.h"
#include "session_manager.h"
class controller_user_info
{
public:
controller_user_info(view_user_info *view, session_manager *session);
private:
view_user_info *view;
session_manager *sesion;
void load_info();
std::string get_first(std::string &info);
};
#endif // CONTROLLER_USER_INFO_H

View File

@ -46,3 +46,17 @@ std::list<std::string> session_manager::get_packages_info(){
}
return ret;
}
std::list<std::string> session_manager::get_users_info(){
std::list<std::string> ret;
std::string read;
this->con->write_string("uinf");
while(true){
this->con->read_string(read,256);
if(read=="end:info"){
break;
}
ret.push_back(read);
}
return ret;
}

View File

@ -15,6 +15,7 @@ public:
int install_command(std::string package);
int remove_command(std::string package);
std::list<std::string> get_packages_info();
std::list<std::string> get_users_info();
};
#endif // SESSION_MANAGER_H

11
view_user_info.cpp Normal file
View File

@ -0,0 +1,11 @@
#include "view_user_info.h"
view_user_info::view_user_info()
{
this->m_refTreeModel = Gtk::ListStore::create(this->m_Columns);
this->tree.set_model(this->m_refTreeModel);
tree.append_column("user", m_Columns.r_user);
tree.append_column("config", m_Columns.r_admin);
this->add(this->tree);
}

26
view_user_info.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef VIEW_USER_INFO_H
#define VIEW_USER_INFO_H
#include <gtkmm/box.h>
#include <gtkmm/treeview.h>
#include <gtkmm/liststore.h>
class view_user_info: public Gtk::Box
{
public:
view_user_info();
Gtk::TreeView tree;
class ModelColumns : public Gtk::TreeModel::ColumnRecord
{
public:
ModelColumns()
{ add(r_user); add(r_admin); }
Gtk::TreeModelColumn<std::string> r_user;
Gtk::TreeModelColumn<bool> r_admin;
};
ModelColumns m_Columns;
Glib::RefPtr<Gtk::ListStore> m_refTreeModel;
};
#endif // VIEW_USER_INFO_H