From 4fc3d964ce3087bcba46689f13202bb553dc4e1c Mon Sep 17 00:00:00 2001 From: groche97 Date: Tue, 19 May 2020 20:34:51 +0200 Subject: [PATCH] Added information about packages installed --- ClienteTFG.pro | 12 ++++++++++-- ClienteTFG.pro.user | 2 +- container_window.cpp | 8 ++++++-- container_window.h | 10 +++++++++- controller_info.cpp | 33 +++++++++++++++++++++++++++++++++ controller_info.h | 17 +++++++++++++++++ controller_install.cpp | 2 -- controller_remove.cpp | 17 +++++++++++++++++ controller_remove.h | 18 ++++++++++++++++++ session_manager.cpp | 14 ++++++++++++++ session_manager.h | 2 ++ view_info.cpp | 13 +++++++++++++ view_info.h | 29 +++++++++++++++++++++++++++++ view_install.cpp | 12 +----------- view_install.h | 1 - view_remove.cpp | 14 ++++++++++++++ view_remove.h | 18 ++++++++++++++++++ 17 files changed, 202 insertions(+), 20 deletions(-) create mode 100644 controller_info.cpp create mode 100644 controller_info.h create mode 100644 controller_remove.cpp create mode 100644 controller_remove.h create mode 100644 view_info.cpp create mode 100644 view_info.h create mode 100644 view_remove.cpp create mode 100644 view_remove.h diff --git a/ClienteTFG.pro b/ClienteTFG.pro index 94e0832..940dd5f 100644 --- a/ClienteTFG.pro +++ b/ClienteTFG.pro @@ -16,7 +16,11 @@ SOURCES += \ session_manager.cpp \ container_window.cpp \ view_install.cpp \ - controller_install.cpp + controller_install.cpp \ + view_remove.cpp \ + controller_remove.cpp \ + view_info.cpp \ + controller_info.cpp HEADERS += \ conexion.h \ @@ -27,4 +31,8 @@ HEADERS += \ session_manager.h \ container_window.h \ view_install.h \ - controller_install.h + controller_install.h \ + view_remove.h \ + controller_remove.h \ + view_info.h \ + controller_info.h diff --git a/ClienteTFG.pro.user b/ClienteTFG.pro.user index 9a8c889..b2f83b3 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 abc8e9b..f3cf284 100644 --- a/container_window.cpp +++ b/container_window.cpp @@ -6,11 +6,15 @@ container_window::container_window(conexion *con, Glib::RefPtr< Gtk::Application this->app=app; this->app->run(loggin); if(this->loggin.login){ - this->cont=new controller_install(&install, sesion.get()); + 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->app.reset(); this->app=Gtk::Application::create( "org.gtkmm.examples.base"); this->add(this->book); - this->book.add(install); + this->book.append_page(install,"build"); + this->book.append_page(remove,"remove"); + this->book.append_page(this->info,"info"); this->show_all_children(); this->app->run(*this); } diff --git a/container_window.h b/container_window.h index 45a23b1..f8f7597 100644 --- a/container_window.h +++ b/container_window.h @@ -5,6 +5,10 @@ #include "controller_install.h" #include "conexion.h" #include "session_manager.h" +#include "view_remove.h" +#include "controller_remove.h" +#include "view_info.h" +#include "controller_info.h" #include #include @@ -18,7 +22,11 @@ private: std::unique_ptr sesion; view_loggin loggin; view_install install; - controller_install *cont; + view_remove remove; + view_info info; + controller_install *cont_inst; + controller_remove *cont_rem; + controller_info *cont_info; Gtk::Notebook book; }; diff --git a/controller_info.cpp b/controller_info.cpp new file mode 100644 index 0000000..6dd91b4 --- /dev/null +++ b/controller_info.cpp @@ -0,0 +1,33 @@ +#include "controller_info.h" + +#include + +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) +{ + this->view=view; + this->sesion=sesion; + this->load_info(); +} + +void controller_info::load_info(){ + std::list list=this->sesion->get_packages_info(); + for(std::string data:list){ + Gtk::TreeModel::Row row = *(this->view->m_refTreeModel->append()); + row[this->view->m_Columns.r_name]=get_first(data); + row[this->view->m_Columns.r_date]=get_first(data); + 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";*/ +} + diff --git a/controller_info.h b/controller_info.h new file mode 100644 index 0000000..1e2b92a --- /dev/null +++ b/controller_info.h @@ -0,0 +1,17 @@ +#ifndef CONTROLLER_INFO_H +#define CONTROLLER_INFO_H + +#include "session_manager.h" +#include "view_info.h" + +class controller_info +{ +public: + controller_info(view_info *view, session_manager *sesion); +private: + view_info *view; + session_manager *sesion; + void load_info(); +}; + +#endif // CONTROLLER_INFO_H diff --git a/controller_install.cpp b/controller_install.cpp index 40e8fe8..a9a4295 100644 --- a/controller_install.cpp +++ b/controller_install.cpp @@ -1,7 +1,5 @@ #include "controller_install.h" -#include - controller_install::controller_install(view_install *vis, session_manager *sesi) { this->vis=vis; diff --git a/controller_remove.cpp b/controller_remove.cpp new file mode 100644 index 0000000..32d71fb --- /dev/null +++ b/controller_remove.cpp @@ -0,0 +1,17 @@ +#include "controller_remove.h" + +controller_remove::controller_remove(view_remove *vis, session_manager *sesi) +{ + this->view=vis; + this->session=sesi; + this->add_controlers(); +} + +void controller_remove::add_controlers(){ + this->view->m_button.signal_clicked().connect(sigc::mem_fun(this, + &controller_remove::on_button_clicked)); +} + +void controller_remove::on_button_clicked(){ + this->session->remove_command(this->view->entry.get_text()); +} diff --git a/controller_remove.h b/controller_remove.h new file mode 100644 index 0000000..101bbce --- /dev/null +++ b/controller_remove.h @@ -0,0 +1,18 @@ +#ifndef CONTROLLER_REMOVE_H +#define CONTROLLER_REMOVE_H + +#include "view_remove.h" +#include "session_manager.h" + +class controller_remove +{ +public: + controller_remove(view_remove *view, session_manager *session); +private: + view_remove *view; + session_manager *session; + void add_controlers(); + void on_button_clicked(); +}; + +#endif // CONTROLLER_REMOVE_H diff --git a/session_manager.cpp b/session_manager.cpp index a7bd62b..dd51e88 100644 --- a/session_manager.cpp +++ b/session_manager.cpp @@ -32,3 +32,17 @@ int session_manager::remove_command(std::string package){ this->con->read_string(buffer,2); return atoi(buffer.data()); } + +std::list session_manager::get_packages_info(){ + std::list ret; + std::string read; + this->con->write_string("info"); + while(true){ + this->con->read_string(read,256); + if(read=="end:info"){ + break; + } + ret.push_back(read); + } + return ret; +} diff --git a/session_manager.h b/session_manager.h index 985bcd6..82b634c 100644 --- a/session_manager.h +++ b/session_manager.h @@ -4,6 +4,7 @@ #include "conexion.h" #include +#include class session_manager { @@ -13,6 +14,7 @@ public: bool loggin(std::string username, std::string passwd); int install_command(std::string package); int remove_command(std::string package); + std::list get_packages_info(); }; #endif // SESSION_MANAGER_H diff --git a/view_info.cpp b/view_info.cpp new file mode 100644 index 0000000..4c0e1eb --- /dev/null +++ b/view_info.cpp @@ -0,0 +1,13 @@ +#include "view_info.h" + +view_info::view_info() +{ + this->m_refTreeModel = Gtk::ListStore::create(this->m_Columns); + this->tree.set_model(this->m_refTreeModel); + + tree.append_column("name", m_Columns.r_name); + tree.append_column("date", m_Columns.r_date); + tree.append_column("config", m_Columns.r_config); + tree.append_column("user", m_Columns.r_user); + this->add(this->tree); +} diff --git a/view_info.h b/view_info.h new file mode 100644 index 0000000..1a0c109 --- /dev/null +++ b/view_info.h @@ -0,0 +1,29 @@ +#ifndef VIEW_INFO_H +#define VIEW_INFO_H + +#include +#include +#include + +class view_info: public Gtk::Box +{ +public: + view_info(); + Gtk::TreeView tree; + class ModelColumns : public Gtk::TreeModel::ColumnRecord + { + public: + ModelColumns() + { add(r_name); add(r_date); add(r_user); add(r_config); } + + Gtk::TreeModelColumn r_name; + Gtk::TreeModelColumn r_date; + Gtk::TreeModelColumn r_user; + Gtk::TreeModelColumn r_config; + }; + + ModelColumns m_Columns; + Glib::RefPtr m_refTreeModel; +}; + +#endif // VIEW_INFO_H diff --git a/view_install.cpp b/view_install.cpp index 80340b4..dbd059e 100644 --- a/view_install.cpp +++ b/view_install.cpp @@ -1,7 +1,7 @@ #include "view_install.h" #include -view_install::view_install():m_button("send"),m_VBox(Gtk::ORIENTATION_VERTICAL) +view_install::view_install():m_button("build"),m_VBox(Gtk::ORIENTATION_VERTICAL) { set_border_width(5); @@ -18,18 +18,8 @@ view_install::view_install():m_button("send"),m_VBox(Gtk::ORIENTATION_VERTICAL) m_ButtonBox.set_spacing(5); m_ButtonBox.set_layout(Gtk::BUTTONBOX_END); - // When the button receives the "clicked" signal, it will call the - // on_button_clicked() method defined below. - /*m_button.signal_clicked().connect(sigc::mem_fun(*this, - &vista::on_button_clicked));*/ - m_refTextBuffer1 = Gtk::TextBuffer::create(); //m_refTextBuffer1->set_text("This is the text from TextBuffer #1."); m_TextView.set_buffer(m_refTextBuffer1); show_all_children(); } - -/*void vista::on_button_clicked(){ - std::string salida = m_refTextBuffer1->get_text(); - std::cout << salida << std::endl; -}*/ diff --git a/view_install.h b/view_install.h index 13e0405..62d9a6a 100644 --- a/view_install.h +++ b/view_install.h @@ -1,7 +1,6 @@ #ifndef VISTA_H #define VISTA_H #include -#include #include #include #include diff --git a/view_remove.cpp b/view_remove.cpp new file mode 100644 index 0000000..0f5b1e2 --- /dev/null +++ b/view_remove.cpp @@ -0,0 +1,14 @@ +#include "view_remove.h" + +view_remove::view_remove():m_button("remove"),m_VBox(Gtk::ORIENTATION_VERTICAL) +{ + set_border_width(5); + add(m_VBox); + m_VBox.pack_start(this->entry); + //Add buttons: + m_VBox.pack_start(m_ButtonBox, Gtk::PACK_SHRINK); + m_ButtonBox.pack_start(m_button, Gtk::PACK_SHRINK); + m_ButtonBox.set_border_width(5); + m_ButtonBox.set_spacing(5); + m_ButtonBox.set_layout(Gtk::BUTTONBOX_END); +} diff --git a/view_remove.h b/view_remove.h new file mode 100644 index 0000000..e1d4b8c --- /dev/null +++ b/view_remove.h @@ -0,0 +1,18 @@ +#ifndef VIEW_REMOVE_H +#define VIEW_REMOVE_H +#include +#include +#include +#include + +class view_remove :public Gtk::Box +{ +public: + view_remove(); + Gtk::Button m_button; + Gtk::Box m_VBox; + Gtk::ButtonBox m_ButtonBox; + Gtk::Entry entry; +}; + +#endif // VIEW_REMOVE_H