Added information about packages installed

This commit is contained in:
Guillermo Roche 2020-05-19 20:34:51 +02:00
parent 9eb45f329a
commit 4fc3d964ce
17 changed files with 202 additions and 20 deletions

View File

@ -16,7 +16,11 @@ SOURCES += \
session_manager.cpp \ session_manager.cpp \
container_window.cpp \ container_window.cpp \
view_install.cpp \ view_install.cpp \
controller_install.cpp controller_install.cpp \
view_remove.cpp \
controller_remove.cpp \
view_info.cpp \
controller_info.cpp
HEADERS += \ HEADERS += \
conexion.h \ conexion.h \
@ -27,4 +31,8 @@ HEADERS += \
session_manager.h \ session_manager.h \
container_window.h \ container_window.h \
view_install.h \ view_install.h \
controller_install.h controller_install.h \
view_remove.h \
controller_remove.h \
view_info.h \
controller_info.h

View File

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

View File

@ -6,11 +6,15 @@ container_window::container_window(conexion *con, Glib::RefPtr< Gtk::Application
this->app=app; this->app=app;
this->app->run(loggin); this->app->run(loggin);
if(this->loggin.login){ 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.reset();
this->app=Gtk::Application::create( "org.gtkmm.examples.base"); this->app=Gtk::Application::create( "org.gtkmm.examples.base");
this->add(this->book); 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->show_all_children();
this->app->run(*this); this->app->run(*this);
} }

View File

@ -5,6 +5,10 @@
#include "controller_install.h" #include "controller_install.h"
#include "conexion.h" #include "conexion.h"
#include "session_manager.h" #include "session_manager.h"
#include "view_remove.h"
#include "controller_remove.h"
#include "view_info.h"
#include "controller_info.h"
#include <gtkmm/notebook.h> #include <gtkmm/notebook.h>
#include <memory> #include <memory>
@ -18,7 +22,11 @@ private:
std::unique_ptr<session_manager> sesion; std::unique_ptr<session_manager> sesion;
view_loggin loggin; view_loggin loggin;
view_install install; 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; Gtk::Notebook book;
}; };

33
controller_info.cpp Normal file
View File

@ -0,0 +1,33 @@
#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)
{
this->view=view;
this->sesion=sesion;
this->load_info();
}
void controller_info::load_info(){
std::list<std::string> 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";*/
}

17
controller_info.h Normal file
View File

@ -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

View File

@ -1,7 +1,5 @@
#include "controller_install.h" #include "controller_install.h"
#include <iostream>
controller_install::controller_install(view_install *vis, session_manager *sesi) controller_install::controller_install(view_install *vis, session_manager *sesi)
{ {
this->vis=vis; this->vis=vis;

17
controller_remove.cpp Normal file
View File

@ -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());
}

18
controller_remove.h Normal file
View File

@ -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

View File

@ -32,3 +32,17 @@ int session_manager::remove_command(std::string package){
this->con->read_string(buffer,2); this->con->read_string(buffer,2);
return atoi(buffer.data()); return atoi(buffer.data());
} }
std::list<std::string> session_manager::get_packages_info(){
std::list<std::string> 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;
}

View File

@ -4,6 +4,7 @@
#include "conexion.h" #include "conexion.h"
#include <string> #include <string>
#include <list>
class session_manager class session_manager
{ {
@ -13,6 +14,7 @@ public:
bool loggin(std::string username, std::string passwd); bool loggin(std::string username, std::string passwd);
int install_command(std::string package); int install_command(std::string package);
int remove_command(std::string package); int remove_command(std::string package);
std::list<std::string> get_packages_info();
}; };
#endif // SESSION_MANAGER_H #endif // SESSION_MANAGER_H

13
view_info.cpp Normal file
View File

@ -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);
}

29
view_info.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef VIEW_INFO_H
#define VIEW_INFO_H
#include <gtkmm/box.h>
#include <gtkmm/treeview.h>
#include <gtkmm/liststore.h>
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<std::string> r_name;
Gtk::TreeModelColumn<std::string> r_date;
Gtk::TreeModelColumn<std::string> r_user;
Gtk::TreeModelColumn<bool> r_config;
};
ModelColumns m_Columns;
Glib::RefPtr<Gtk::ListStore> m_refTreeModel;
};
#endif // VIEW_INFO_H

View File

@ -1,7 +1,7 @@
#include "view_install.h" #include "view_install.h"
#include <iostream> #include <iostream>
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); 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_spacing(5);
m_ButtonBox.set_layout(Gtk::BUTTONBOX_END); 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 = Gtk::TextBuffer::create();
//m_refTextBuffer1->set_text("This is the text from TextBuffer #1."); //m_refTextBuffer1->set_text("This is the text from TextBuffer #1.");
m_TextView.set_buffer(m_refTextBuffer1); m_TextView.set_buffer(m_refTextBuffer1);
show_all_children(); show_all_children();
} }
/*void vista::on_button_clicked(){
std::string salida = m_refTextBuffer1->get_text();
std::cout << salida << std::endl;
}*/

View File

@ -1,7 +1,6 @@
#ifndef VISTA_H #ifndef VISTA_H
#define VISTA_H #define VISTA_H
#include <gtkmm/button.h> #include <gtkmm/button.h>
#include <gtkmm/window.h>
#include <gtkmm/textview.h> #include <gtkmm/textview.h>
#include <gtkmm/buttonbox.h> #include <gtkmm/buttonbox.h>
#include <gtkmm/scrolledwindow.h> #include <gtkmm/scrolledwindow.h>

14
view_remove.cpp Normal file
View File

@ -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);
}

18
view_remove.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef VIEW_REMOVE_H
#define VIEW_REMOVE_H
#include <gtkmm/button.h>
#include <gtkmm/buttonbox.h>
#include <gtkmm/box.h>
#include <gtkmm/entry.h>
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