diff --git a/ClienteTFG.pro b/ClienteTFG.pro index 8468c9c..fa23e6b 100644 --- a/ClienteTFG.pro +++ b/ClienteTFG.pro @@ -14,7 +14,9 @@ SOURCES += \ vista.cpp \ controlador.cpp \ view_loggin.cpp \ - read_uses.cpp + read_uses.cpp \ + session_manager.cpp \ + container_window.cpp HEADERS += \ conexion.h \ @@ -23,4 +25,6 @@ HEADERS += \ vista.h \ controlador.h \ view_loggin.h \ - read_uses.h + read_uses.h \ + session_manager.h \ + container_window.h diff --git a/ClienteTFG.pro.user b/ClienteTFG.pro.user index 885a57d..5c54b86 100644 --- a/ClienteTFG.pro.user +++ b/ClienteTFG.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/container_window.cpp b/container_window.cpp new file mode 100644 index 0000000..5b8db55 --- /dev/null +++ b/container_window.cpp @@ -0,0 +1,16 @@ +#include "container_window.h" + +container_window::container_window(conexion *con, Glib::RefPtr< Gtk::Application > app):loggin(con) +{ + this->app=app; + this->app->run(loggin); + if(this->loggin.login){ + this->cont=new controlador(&install, con); + this->app.reset(); + this->app=Gtk::Application::create( "org.gtkmm.examples.base"); + this->add(this->book); + this->book.add(install); + this->show_all_children(); + this->app->run(*this); + } +} diff --git a/container_window.h b/container_window.h new file mode 100644 index 0000000..bdab77d --- /dev/null +++ b/container_window.h @@ -0,0 +1,22 @@ +#ifndef CONTAINER_WINDOW_H +#define CONTAINER_WINDOW_H +#include "vista.h" +#include "view_loggin.h" +#include "controlador.h" +#include "conexion.h" + +#include "gtkmm/notebook.h" + +class container_window: public Gtk::Window +{ +public: + container_window(conexion *con, Glib::RefPtr< Gtk::Application > app); +private: + Glib::RefPtr< Gtk::Application > app; + view_loggin loggin; + vista install; + controlador *cont; + Gtk::Notebook book; +}; + +#endif // CONTAINER_WINDOW_H diff --git a/main.cpp b/main.cpp index c0e8edb..e1fdf56 100644 --- a/main.cpp +++ b/main.cpp @@ -1,9 +1,6 @@ #include "conexion_ssl.h" -#include "vista.h" -#include "controlador.h" -#include "view_loggin.h" #include -#include "read_uses.h" +#include "container_window.h" #define FILE_CONFIG "config" @@ -11,9 +8,6 @@ using namespace std; int main(int argc, char *argv[]) { - - auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example"); - config_reader conf = config_reader(FILE_CONFIG); conexion* con; string option; @@ -28,24 +22,7 @@ int main(int argc, char *argv[]) }else{ perror("no securty option found in config"); } - /*if(con->check_pass("test","ok")){ - con->write_string("algo"); - string salida; - con->read_string(salida,10); - cout << salida << endl; - }else{ - cout << "contrasenia incorrecta" << endl; - }*/ - view_loggin login(con); - //Shows the window and returns when it is closed. - //app->add_window(vis); - app->run(login); - if(login.login){ - vista vis; - controlador cont(&vis, con); - app.reset(); - app = Gtk::Application::create(argc, argv, "org.gtkmm.example"); - app->run(vis); - } + auto app=Gtk::Application::create(argc, argv, "org.gtkmm.example"); + container_window cont(con, app); return 0; } diff --git a/read_uses.cpp b/read_uses.cpp index d9c6edc..87d1065 100644 --- a/read_uses.cpp +++ b/read_uses.cpp @@ -12,6 +12,10 @@ read_uses::read_uses(std::string name) this->exist = file.good(); } +bool read_uses::exist_file(){ + return this->exist; +} + std::string* read_uses::get_uses(){ std::string *ret=nullptr; if(this->exist){ diff --git a/read_uses.h b/read_uses.h index f3d8bca..68ff653 100644 --- a/read_uses.h +++ b/read_uses.h @@ -9,6 +9,7 @@ class read_uses public: read_uses(std::string name); std::string* get_uses(); + bool exist_file(); private: std::ifstream file; std::string short_name; diff --git a/session_manager.cpp b/session_manager.cpp new file mode 100644 index 0000000..5be03ac --- /dev/null +++ b/session_manager.cpp @@ -0,0 +1,25 @@ +#include "session_manager.h" +#include "read_uses.h" + +session_manager::session_manager(conexion* con) +{ + this->con=con; +} + +bool session_manager::loggin(std::string username, std::string passwd){ + return this->con->check_pass(username, passwd); +} + +int session_manager::install_command(std::string package){ + read_uses uses(package); + this->con->write_string(package); + if(uses.exist_file()){ + this->con->write_string("y"); + this->con->write_string(*uses.get_uses()); + }else{ + this->con->write_string("n"); + } + std::string buffer; + this->con->read_string(buffer,2); + return atoi(buffer.data()); +} diff --git a/session_manager.h b/session_manager.h new file mode 100644 index 0000000..e08b23a --- /dev/null +++ b/session_manager.h @@ -0,0 +1,17 @@ +#ifndef SESSION_MANAGER_H +#define SESSION_MANAGER_H + +#include "conexion.h" + +#include + +class session_manager +{ +public: + session_manager(conexion* con); + conexion* con; + bool loggin(std::string username, std::string passwd); + int install_command(std::string package); +}; + +#endif // SESSION_MANAGER_H diff --git a/view_loggin.cpp b/view_loggin.cpp index 8c787f8..ad9fe6c 100644 --- a/view_loggin.cpp +++ b/view_loggin.cpp @@ -4,12 +4,11 @@ #include -view_loggin::view_loggin(conexion *con):button("check"),box(Gtk::ORIENTATION_VERTICAL), - box_user(Gtk::ORIENTATION_HORIZONTAL), box_pass(Gtk::ORIENTATION_HORIZONTAL) +view_loggin::view_loggin(conexion *con):box_user(Gtk::ORIENTATION_HORIZONTAL), box_pass(Gtk::ORIENTATION_HORIZONTAL),button("check"), box(Gtk::ORIENTATION_VERTICAL) { - this->con=con; - set_title("loggin"); + this->set_title("loggin"); + this->con=con; set_border_width(5); this->user.set_text("user"); @@ -35,7 +34,6 @@ view_loggin::view_loggin(conexion *con):button("check"),box(Gtk::ORIENTATION_VER this->box.set_spacing(10); this->add(box); - show_all_children(); } @@ -48,7 +46,7 @@ void view_loggin::on_button_clicked(){ this->hide(); }else{ this->login=false; - Gtk::MessageDialog err(*this,"error", false, Gtk::MessageType::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); + Gtk::MessageDialog err("error", false, Gtk::MessageType::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); err.set_secondary_text("Bad password or username"); err.run(); } diff --git a/vista.cpp b/vista.cpp index 5969e81..460f11f 100644 --- a/vista.cpp +++ b/vista.cpp @@ -3,7 +3,6 @@ vista::vista():m_button("send"),m_VBox(Gtk::ORIENTATION_VERTICAL) { - set_title("remote instaler"); set_border_width(5); add(m_VBox); @@ -27,7 +26,6 @@ vista::vista():m_button("send"),m_VBox(Gtk::ORIENTATION_VERTICAL) m_refTextBuffer1 = Gtk::TextBuffer::create(); //m_refTextBuffer1->set_text("This is the text from TextBuffer #1."); m_TextView.set_buffer(m_refTextBuffer1); - // The final step is to display this newly created widget... show_all_children(); } diff --git a/vista.h b/vista.h index 4da3041..db4d5e6 100644 --- a/vista.h +++ b/vista.h @@ -7,7 +7,7 @@ #include #include -class vista : public Gtk::Window +class vista : public Gtk::Box { public: vista();