/* * widgets.c * * Copyright (C) 2007 Pau Espin Pedrol (Sharwin_F) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see */ #include #include #include #include #include #include "events.h" GtkWidget *top_window_crea(int amplada, int altura, int border, const char* titol, bool main_widget) { GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_container_set_border_width (GTK_CONTAINER (window), border); gtk_widget_set_size_request (GTK_WIDGET (window), amplada, altura); gtk_window_set_title(GTK_WINDOW (window), titol); if(main_widget) g_signal_connect( G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL ); else g_signal_connect( G_OBJECT (window), "delete_event", G_CALLBACK (gtk_widget_destroy), window ); gtk_widget_show(window); return window; } GtkWidget *notebook_crea(GtkWidget *parent) { GtkWidget *notebook = gtk_notebook_new(); gtk_notebook_set_tab_pos( GTK_NOTEBOOK (notebook), GTK_POS_TOP ); gtk_container_add(GTK_CONTAINER(parent), notebook); gtk_notebook_set_show_tabs ( GTK_NOTEBOOK (notebook), TRUE ); gtk_notebook_set_show_border ( GTK_NOTEBOOK (notebook), TRUE); return notebook; } GtkWidget *notebook_hbox_crea(GtkWidget *parent) { GtkWidget *box = gtk_hbox_new(0,1); gtk_container_add(GTK_CONTAINER(parent), box); gtk_widget_show(box); gtk_container_set_border_width (GTK_CONTAINER (box), 10); return box; } GtkWidget *notebook_vbox_crea(GtkWidget *parent) { GtkWidget *box = gtk_vbox_new(0,1); gtk_container_add(GTK_CONTAINER(parent), box); gtk_widget_show(box); return box; } GtkWidget *alert(const char *titol, char *text, int error) { char* str_pt = (char*) malloc( strlen(text) + strlen(strerror(error)) + 1 ); GtkWidget *txtspace, *vbox, *button, *window; window = top_window_crea(500,140, 1, titol, FALSE); vbox = gtk_vbox_new(1, 0); gtk_container_add(GTK_CONTAINER(window), vbox); gtk_widget_show(vbox); if(str_pt!=NULL) { sprintf( str_pt, text); strcat( str_pt, strerror(error)); txtspace = gtk_label_new(str_pt); } else txtspace = gtk_label_new("Error greu. No s'ha pogut especificar espai en memoria suficient per a esccriure l'error."); gtk_box_pack_start(GTK_BOX (vbox), txtspace, FALSE, FALSE, 0 ); gtk_widget_show(txtspace); button = gtk_button_new_with_label("D'acord"); gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0); gtk_widget_show(button); g_signal_connect_swapped(G_OBJECT (button), "clicked", G_CALLBACK (gtk_widget_destroy), G_OBJECT (window)); free(str_pt); return window; } GtkWidget *textview_scrolled_crea(GtkWidget *parent, gchar *str){ //creem scroll GtkWidget *scroll = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); gtk_box_pack_start (GTK_BOX (parent), scroll, TRUE, TRUE, 0); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_ETCHED_IN); gtk_widget_show(scroll); GtkWidget *textview = gtk_text_view_new(); GtkTextBuffer *buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW (textview) ); gtk_text_buffer_set_text (buffer, str, -1); gtk_container_add(GTK_CONTAINER(scroll), textview); gtk_widget_show(textview); return textview; } void notebook_assigna_pagina(GtkNotebook *parent, GtkWidget *pagina, gchar *texttab) { GtkWidget *tab = gtk_label_new(texttab); gtk_notebook_append_page( parent, pagina, tab ); gtk_widget_show( pagina ); gtk_widget_show( GTK_WIDGET (parent) ); } GtkWidget *pagina_encrypt_crea(GtkNotebook *parent) { gchar titol[] = "Encriptar"; GtkWidget *pagina, *input, *output, *action, *button_f, *hbox, *vbox; //generals GtkWidget *gfin_path, *gfin_text, *gfout_path, *gfout_text; //entries & textviews GtkWidget *radio_in_path, *radio_in_text, *radio_out_path, *radio_out_text; //radio buttons GtkWidget *password, *button; //action frame pagina = gtk_vbox_new(0,1); //INPUT - frame input = gtk_frame_new("Input:"); gtk_container_set_border_width (GTK_CONTAINER (input), 20); gtk_frame_set_label_align( GTK_FRAME (input) ,0.0, 0.5 ); gtk_container_add(GTK_CONTAINER(pagina), input); gtk_widget_show (input); vbox = notebook_vbox_crea(input); hbox = notebook_hbox_crea(vbox); radio_in_path = gtk_radio_button_new( NULL ); gtk_box_pack_start (GTK_BOX (hbox), radio_in_path, FALSE, FALSE, 5); gtk_widget_show (radio_in_path); gfin_path = gtk_entry_new(); gtk_entry_set_text(GTK_ENTRY (gfin_path),"Inserir text pla des d'un fitxer"); gtk_box_pack_start (GTK_BOX (hbox), gfin_path, TRUE, TRUE, 0); gtk_widget_show(gfin_path); button_f = gtk_button_new_with_label("Cercar"); gtk_box_pack_start (GTK_BOX (hbox), button_f, FALSE, FALSE, 0); gtk_widget_show(button_f); g_signal_connect_swapped(button_f, "clicked", G_CALLBACK (filemanager_obre), G_OBJECT (gfin_path) ); hbox = notebook_hbox_crea(vbox); radio_in_text = gtk_radio_button_new_from_widget( GTK_RADIO_BUTTON (radio_in_path) ); gtk_box_pack_start (GTK_BOX (hbox), radio_in_text, FALSE, FALSE, 5); gtk_widget_show (radio_in_text); gfin_text = textview_scrolled_crea(hbox, "Encriptar aquest text"); //OUTPUT - frame output = gtk_frame_new("Output:"); gtk_container_set_border_width (GTK_CONTAINER (output), 20); gtk_frame_set_label_align( GTK_FRAME (output) ,0.0, 0.5 ); gtk_container_add(GTK_CONTAINER(pagina), output); gtk_widget_show (output); vbox = notebook_vbox_crea(output); hbox = notebook_hbox_crea(vbox); radio_out_path = gtk_radio_button_new( NULL ); gtk_box_pack_start (GTK_BOX (hbox), radio_out_path, FALSE, FALSE, 5); gtk_widget_show (radio_out_path); gfout_path = gtk_entry_new(); gtk_entry_set_text(GTK_ENTRY (gfout_path),"Desar el text encriptat en un fitxer"); gtk_box_pack_start (GTK_BOX (hbox), gfout_path, TRUE, TRUE, 0); gtk_widget_show(gfout_path); button_f = gtk_button_new_with_label("Cercar"); gtk_box_pack_start (GTK_BOX (hbox), button_f, FALSE, FALSE, 0); gtk_widget_show(button_f); g_signal_connect_swapped(button_f, "clicked", G_CALLBACK (filemanager_obre), G_OBJECT (gfout_path) ); hbox = notebook_hbox_crea(vbox); radio_out_text = gtk_radio_button_new_from_widget( GTK_RADIO_BUTTON (radio_out_path) ); gtk_box_pack_start (GTK_BOX (hbox), radio_out_text, FALSE, FALSE, 5); gtk_widget_show (radio_out_text); gfout_text = textview_scrolled_crea(hbox, "Imprimir el text encriptat aqui"); //ACTION - frame action = gtk_frame_new("Contrasenya"); gtk_container_set_border_width (GTK_CONTAINER (action), 20); gtk_frame_set_label_align( GTK_FRAME (action) ,0.0, 0.5 ); gtk_container_add(GTK_CONTAINER(pagina), action); gtk_widget_show (action); hbox = notebook_hbox_crea(action); password = gtk_entry_new(); gtk_entry_set_text(GTK_ENTRY (password),"Inserir la contrasenya"); gtk_box_pack_start (GTK_BOX (hbox), password, TRUE, TRUE, 0); gtk_widget_show(password); button = gtk_button_new_with_label("Encriptar"); gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); gtk_widget_show(button); //array de widgets per a passar-los al signal: GtkWidget **decrypt_array = g_new(GtkWidget*, 9); decrypt_array[0] = radio_in_path; decrypt_array[1] = radio_in_text; decrypt_array[2] = radio_out_path; decrypt_array[3] = radio_out_text; decrypt_array[4] = gfin_path; decrypt_array[5] = gfin_text; decrypt_array[6] = gfout_path; decrypt_array[7] = gfout_text; decrypt_array[8] = password; g_signal_connect_swapped(button, "clicked", G_CALLBACK (encrypt_process), decrypt_array ); notebook_assigna_pagina(parent, pagina, titol); return pagina; } GtkWidget *pagina_decrypt_crea(GtkNotebook *parent) { gchar titol[] = "Desencriptar"; GtkWidget *pagina, *input, *output, *action, *button_f, *hbox, *vbox; //generals GtkWidget *gfin_path, *gfin_text, *gfout_path, *gfout_text; //entries & textviews GtkWidget *radio_in_path, *radio_in_text, *radio_out_path, *radio_out_text; //radio buttons GtkWidget *password, *button; //action frame pagina = gtk_vbox_new(0,1); //INPUT - frame input = gtk_frame_new("Input:"); gtk_container_set_border_width (GTK_CONTAINER (input), 20); gtk_frame_set_label_align( GTK_FRAME (input) ,0.0, 0.5 ); gtk_container_add(GTK_CONTAINER(pagina), input); gtk_widget_show (input); vbox = notebook_vbox_crea(input); hbox = notebook_hbox_crea(vbox); radio_in_path = gtk_radio_button_new( NULL ); gtk_box_pack_start (GTK_BOX (hbox), radio_in_path, FALSE, FALSE, 5); gtk_widget_show (radio_in_path); gfin_path = gtk_entry_new(); gtk_entry_set_text(GTK_ENTRY (gfin_path),"Inserir text encriptat des d'un fitxer"); gtk_box_pack_start (GTK_BOX (hbox), gfin_path, TRUE, TRUE, 0); gtk_widget_show(gfin_path); button_f = gtk_button_new_with_label("Cercar"); gtk_box_pack_start (GTK_BOX (hbox), button_f, FALSE, FALSE, 0); gtk_widget_show(button_f); g_signal_connect_swapped(button_f, "clicked", G_CALLBACK (filemanager_obre), G_OBJECT (gfin_path) ); hbox = notebook_hbox_crea(vbox); radio_in_text = gtk_radio_button_new_from_widget( GTK_RADIO_BUTTON (radio_in_path) ); gtk_box_pack_start (GTK_BOX (hbox), radio_in_text, FALSE, FALSE, 5); gtk_widget_show (radio_in_text); gfin_text = textview_scrolled_crea(hbox, "Desencriptar aquest text"); //OUTPUT - frame output = gtk_frame_new("Output:"); gtk_container_set_border_width (GTK_CONTAINER (output), 20); gtk_frame_set_label_align( GTK_FRAME (output) ,0.0, 0.5 ); gtk_container_add(GTK_CONTAINER(pagina), output); gtk_widget_show (output); vbox = notebook_vbox_crea(output); hbox = notebook_hbox_crea(vbox); radio_out_path = gtk_radio_button_new( NULL ); gtk_box_pack_start (GTK_BOX (hbox), radio_out_path, FALSE, FALSE, 5); gtk_widget_show (radio_out_path); gfout_path = gtk_entry_new(); gtk_entry_set_text(GTK_ENTRY (gfout_path),"Desar el text pla en un fitxer"); gtk_box_pack_start (GTK_BOX (hbox), gfout_path, TRUE, TRUE, 0); gtk_widget_show(gfout_path); button_f = gtk_button_new_with_label("Cercar"); gtk_box_pack_start (GTK_BOX (hbox), button_f, FALSE, FALSE, 0); gtk_widget_show(button_f); g_signal_connect_swapped(button_f, "clicked", G_CALLBACK (filemanager_obre), G_OBJECT (gfout_path) ); hbox = notebook_hbox_crea(vbox); radio_out_text = gtk_radio_button_new_from_widget( GTK_RADIO_BUTTON (radio_out_path) ); gtk_box_pack_start (GTK_BOX (hbox), radio_out_text, FALSE, FALSE, 5); gtk_widget_show (radio_out_text); gfout_text = textview_scrolled_crea(hbox, "Imprimir el text pla aqui"); //ACTION - frame action = gtk_frame_new("Contrasenya"); gtk_container_set_border_width (GTK_CONTAINER (action), 20); gtk_frame_set_label_align( GTK_FRAME (action) ,0.0, 0.5 ); gtk_container_add(GTK_CONTAINER(pagina), action); gtk_widget_show (action); hbox = notebook_hbox_crea(action); password = gtk_entry_new(); gtk_entry_set_text(GTK_ENTRY (password),"Inserir la contrasenya"); gtk_box_pack_start (GTK_BOX (hbox), password, TRUE, TRUE, 0); gtk_widget_show(password); button = gtk_button_new_with_label("Desencriptar"); gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); gtk_widget_show(button); //array de widgets per a passar-los al signal: GtkWidget **decrypt_array = g_new(GtkWidget*, 9); decrypt_array[0] = radio_in_path; decrypt_array[1] = radio_in_text; decrypt_array[2] = radio_out_path; decrypt_array[3] = radio_out_text; decrypt_array[4] = gfin_path; decrypt_array[5] = gfin_text; decrypt_array[6] = gfout_path; decrypt_array[7] = gfout_text; decrypt_array[8] = password; g_signal_connect_swapped(button, "clicked", G_CALLBACK (decrypt_process), decrypt_array ); notebook_assigna_pagina(parent, pagina, titol); return pagina; } GtkWidget *pagina_about_crea(GtkNotebook *parent) { gchar titol[] = "About"; GtkWidget *scroll, *pagina, *frame, *vbox, *label; gchar *str; pagina = gtk_vbox_new(0,1); scroll = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start (GTK_BOX (pagina), scroll, TRUE, TRUE, 0); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_ETCHED_IN); gtk_widget_show(scroll); vbox = gtk_vbox_new(0,1); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW (scroll), vbox); gtk_widget_show(vbox); frame = gtk_frame_new("MPEP Encryption:"); gtk_container_set_border_width (GTK_CONTAINER (frame), 15); gtk_frame_set_label_align( GTK_FRAME (frame) ,0.0, 0.5 ); gtk_container_add(GTK_CONTAINER(vbox), frame); gtk_widget_show (frame); str = "MPEP Encryption és un programa que permet encriptar texts i arxius (en format pla o binari) utiltitzant el seu propi algoritme (mpepencrypt) i desencriptar arxius encriptats amb el mateix algoritme, tot mitjançant una contrasenya.\n\n" \ "Codi font i SVN:\nhttp://espeweb.no-ip.com/svn/mpep-encryption"; label= gtk_label_new(str); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_container_add(GTK_CONTAINER (frame), label); gtk_widget_show(label); frame = gtk_frame_new("Autors:"); gtk_container_set_border_width (GTK_CONTAINER (frame), 15); gtk_frame_set_label_align( GTK_FRAME (frame) ,0.0, 0.5 ); gtk_container_add(GTK_CONTAINER(vbox), frame); gtk_widget_show (frame); str = "Pau Espin Pedrol (Sharwin_F)\n pespin@espeweb.no-ip.com\n\n\n" \ "Marc Espin Pedrol (Spin_555)\n epsilonmajorquezero@gmail.com"; label = gtk_label_new(str); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_container_add(GTK_CONTAINER (frame), label); gtk_widget_show(label); frame = gtk_frame_new("Llicència:"); gtk_container_set_border_width (GTK_CONTAINER (frame), 15); gtk_frame_set_label_align( GTK_FRAME (frame) ,0.0, 0.5 ); gtk_container_add(GTK_CONTAINER(vbox), frame); gtk_widget_show (frame); str = "Copyright (C) 2007 Pau Espin Pedrol (Sharwin_F) \n\n" \ "This program is free software: you can redistribute it and/or modify" \ "it under the terms of the GNU General Public License as published by" \ "the Free Software Foundation, either version 3 of the License, or" \ "(at your option) any later version.\n\n" \ "This program is distributed in the hope that it will be useful," \ "but WITHOUT ANY WARRANTY; without even the implied warranty of" \ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" \ "GNU General Public License for more details.\n\n" \ "You should have received a copy of the GNU General Public License" \ "along with this program. If not, see "; label = gtk_label_new(str); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_container_add(GTK_CONTAINER (frame), label); gtk_widget_show(label); notebook_assigna_pagina(parent, pagina, titol); return pagina; }