refactoring, expand interface
This commit is contained in:
		
							parent
							
								
									f9cdde7008
								
							
						
					
					
						commit
						7691c80fb4
					
				| @ -14,7 +14,9 @@ SOURCES += \ | |||||||
|     vista.cpp \ |     vista.cpp \ | ||||||
|     controlador.cpp \ |     controlador.cpp \ | ||||||
|     view_loggin.cpp \ |     view_loggin.cpp \ | ||||||
|     read_uses.cpp |     read_uses.cpp \ | ||||||
|  |     session_manager.cpp \ | ||||||
|  |     container_window.cpp | ||||||
| 
 | 
 | ||||||
| HEADERS += \ | HEADERS += \ | ||||||
|     conexion.h \ |     conexion.h \ | ||||||
| @ -23,4 +25,6 @@ HEADERS += \ | |||||||
|     vista.h \ |     vista.h \ | ||||||
|     controlador.h \ |     controlador.h \ | ||||||
|     view_loggin.h \ |     view_loggin.h \ | ||||||
|     read_uses.h |     read_uses.h \ | ||||||
|  |     session_manager.h \ | ||||||
|  |     container_window.h | ||||||
|  | |||||||
| @ -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-07T01:46:57. --> | <!-- Written by QtCreator 4.8.2, 2020-05-11T02:55:05. --> | ||||||
| <qtcreator> | <qtcreator> | ||||||
|  <data> |  <data> | ||||||
|   <variable>EnvironmentId</variable> |   <variable>EnvironmentId</variable> | ||||||
|  | |||||||
							
								
								
									
										16
									
								
								container_window.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								container_window.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -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); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										22
									
								
								container_window.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								container_window.h
									
									
									
									
									
										Normal file
									
								
							| @ -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
 | ||||||
							
								
								
									
										29
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								main.cpp
									
									
									
									
									
								
							| @ -1,9 +1,6 @@ | |||||||
| #include "conexion_ssl.h" | #include "conexion_ssl.h" | ||||||
| #include "vista.h" |  | ||||||
| #include "controlador.h" |  | ||||||
| #include "view_loggin.h" |  | ||||||
| #include <iostream> | #include <iostream> | ||||||
| #include "read_uses.h" | #include "container_window.h" | ||||||
| 
 | 
 | ||||||
| #define FILE_CONFIG "config" | #define FILE_CONFIG "config" | ||||||
| 
 | 
 | ||||||
| @ -11,9 +8,6 @@ using namespace std; | |||||||
| 
 | 
 | ||||||
| int main(int argc, char *argv[]) | int main(int argc, char *argv[]) | ||||||
| { | { | ||||||
| 
 |  | ||||||
|   auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example"); |  | ||||||
| 
 |  | ||||||
|   config_reader conf = config_reader(FILE_CONFIG); |   config_reader conf = config_reader(FILE_CONFIG); | ||||||
|   conexion* con; |   conexion* con; | ||||||
|   string option; |   string option; | ||||||
| @ -28,24 +22,7 @@ int main(int argc, char *argv[]) | |||||||
|     }else{ |     }else{ | ||||||
|       perror("no securty option found in config"); |       perror("no securty option found in config"); | ||||||
|     } |     } | ||||||
|   /*if(con->check_pass("test","ok")){
 |   auto app=Gtk::Application::create(argc, argv, "org.gtkmm.example"); | ||||||
|      con->write_string("algo"); |   container_window cont(con, app); | ||||||
|      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); |  | ||||||
|     } |  | ||||||
|   return 0; |   return 0; | ||||||
| } | } | ||||||
|  | |||||||
| @ -12,6 +12,10 @@ read_uses::read_uses(std::string name) | |||||||
|   this->exist = file.good(); |   this->exist = file.good(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | bool read_uses::exist_file(){ | ||||||
|  |   return this->exist; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| std::string* read_uses::get_uses(){ | std::string* read_uses::get_uses(){ | ||||||
|   std::string *ret=nullptr; |   std::string *ret=nullptr; | ||||||
|   if(this->exist){ |   if(this->exist){ | ||||||
|  | |||||||
| @ -9,6 +9,7 @@ class read_uses | |||||||
| public: | public: | ||||||
|   read_uses(std::string name); |   read_uses(std::string name); | ||||||
|   std::string* get_uses(); |   std::string* get_uses(); | ||||||
|  |   bool exist_file(); | ||||||
| private: | private: | ||||||
|   std::ifstream file; |   std::ifstream file; | ||||||
|   std::string short_name; |   std::string short_name; | ||||||
|  | |||||||
							
								
								
									
										25
									
								
								session_manager.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								session_manager.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -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()); | ||||||
|  | } | ||||||
							
								
								
									
										17
									
								
								session_manager.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								session_manager.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,17 @@ | |||||||
|  | #ifndef SESSION_MANAGER_H | ||||||
|  | #define SESSION_MANAGER_H | ||||||
|  | 
 | ||||||
|  | #include "conexion.h" | ||||||
|  | 
 | ||||||
|  | #include <string> | ||||||
|  | 
 | ||||||
|  | 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
 | ||||||
| @ -4,12 +4,11 @@ | |||||||
| 
 | 
 | ||||||
| #include <gtkmm/messagedialog.h> | #include <gtkmm/messagedialog.h> | ||||||
| 
 | 
 | ||||||
| view_loggin::view_loggin(conexion *con):button("check"),box(Gtk::ORIENTATION_VERTICAL), | view_loggin::view_loggin(conexion *con):box_user(Gtk::ORIENTATION_HORIZONTAL), box_pass(Gtk::ORIENTATION_HORIZONTAL),button("check"), box(Gtk::ORIENTATION_VERTICAL) | ||||||
|   box_user(Gtk::ORIENTATION_HORIZONTAL), box_pass(Gtk::ORIENTATION_HORIZONTAL) |  | ||||||
| { | { | ||||||
|   this->con=con; |  | ||||||
| 
 | 
 | ||||||
|   set_title("loggin"); |   this->set_title("loggin"); | ||||||
|  |   this->con=con; | ||||||
|   set_border_width(5); |   set_border_width(5); | ||||||
| 
 | 
 | ||||||
|   this->user.set_text("user"); |   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->box.set_spacing(10); | ||||||
| 
 | 
 | ||||||
|   this->add(box); |   this->add(box); | ||||||
| 
 |  | ||||||
|   show_all_children(); |   show_all_children(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -48,7 +46,7 @@ void view_loggin::on_button_clicked(){ | |||||||
|       this->hide(); |       this->hide(); | ||||||
|     }else{ |     }else{ | ||||||
|       this->login=false; |       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.set_secondary_text("Bad password or username"); | ||||||
|       err.run(); |       err.run(); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -3,7 +3,6 @@ | |||||||
| 
 | 
 | ||||||
| vista::vista():m_button("send"),m_VBox(Gtk::ORIENTATION_VERTICAL) | vista::vista():m_button("send"),m_VBox(Gtk::ORIENTATION_VERTICAL) | ||||||
| { | { | ||||||
|   set_title("remote instaler"); |  | ||||||
|   set_border_width(5); |   set_border_width(5); | ||||||
| 
 | 
 | ||||||
|   add(m_VBox); |   add(m_VBox); | ||||||
| @ -27,7 +26,6 @@ vista::vista():m_button("send"),m_VBox(Gtk::ORIENTATION_VERTICAL) | |||||||
|   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); | ||||||
|   // The final step is to display this newly created widget...
 |  | ||||||
|   show_all_children(); |   show_all_children(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user