Advertisement
hackloper775

sPerlBrowser 4.5.1

Feb 20th, 2013
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 12.45 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. #
  4. # Instalar Gtk3 y Gtk3::WebKit por CPAN,para funcionar correctamente
  5. # Programa de prueba para Tiempo de Tux <http://www.itimetux.com>
  6. # Por Demianx864
  7. # Eres libre de estudiar modificar y añadir nuevas cosas a el programa,que te diviertas :D
  8. # Simple PerlBrowser 4.5.1
  9. # Gracias al modulo WebKit <http://webkitgtk.org/>
  10. #
  11.  
  12. use strict;
  13. use feature ':5.14';
  14. use feature qw{ switch };
  15. use Glib qw/TRUE FALSE/;
  16. use Gtk3 -init;
  17. use Gtk3::WebKit;
  18. binmode STDOUT, ":utf8";
  19. use utf8;
  20. use JSON;
  21.  
  22. my $json; &json; my $unscreen = "unfullscreen";
  23.  
  24. my $confP = decode_json($json);
  25.  
  26. my $iniP = $confP->{'pantalla'}->{'inicio'}->[0];
  27.  
  28.  
  29. my $ventana = Gtk3::Window->new('toplevel');
  30. my $icono = 'icon.xpm';
  31. if ( -e $icono ) {
  32.    $ventana->set_icon_from_file($icono);
  33.  
  34. }
  35. my $inicio; my $titulo = "Simple Perl Browser";
  36. $ventana->set_default_size(800, 600);
  37. $ventana->maximize(TRUE);  
  38. $ventana->set_title($titulo);  
  39. $ventana->set_border_width(2);
  40. $ventana->$unscreen;
  41. $ventana->signal_connect(delete_event => \&salir);
  42.  
  43. my $table = Gtk3::Grid->new;
  44.  
  45. my @entries = (
  46. [ "Opciones", undef, "_Opciones" ],
  47. ["Acerca de", 'gtk-about', "_Acerca de", '<control>B', "Acerca de", \&activate_action ],
  48. ["Configuracion", 'gtk-properties', "_Configuracion",'<control>S',
  49. "Configuracion", \&activate_action ],
  50. ["Salir", 'gtk-quit', "_Salir", '<control>Q', "Salir", \&activate_action ],
  51. [ "Quit", 'gtk-quit', "_Quit", "<control>Q", "Quitar", \&activate_action ],
  52. [ "About", undef, "_About", "<control>A", "About", \&activate_action ],
  53. [ "Logo", "demo-gtk-logo", undef, undef, "GTK+", \&activate_action ],
  54. );
  55.  
  56. my @toggle_entries = (                      
  57. ["Completa",undef, "_Pantalla Completa", undef,    
  58. "Pantalla completa", \&activate_action, FALSE ],                              
  59. ["HideTitlebar", undef, "_Hide Titlebar", undef,
  60. "Hide Titlebar",  \&activate_action,FALSE]
  61. );
  62.    
  63. my $action_group = Gtk3::ActionGroup->new('AppWindowActions');
  64. $action_group->add_actions( \@entries, undef );
  65. $action_group->add_toggle_actions( \@toggle_entries, undef );
  66.  
  67. my $ui = Gtk3::UIManager->new();
  68. $ui->insert_action_group( $action_group, 0 );
  69. $ventana->add_accel_group( $ui->get_accel_group );
  70. my $ui_info = get_ui();
  71. $ui->add_ui_from_string( $ui_info, length($ui_info) );
  72. $table->attach( $ui->get_widget('/MenuBar'), 0, 0, 1, 1 );
  73.  
  74. my $uri = shift @ARGV || $iniP ;
  75. my $ver = Gtk3::WebKit::WebView->new(); &web();
  76.        
  77. my $scrolls = Gtk3::ScrolledWindow->new(); $scrolls->add($ver);
  78.        
  79. my $entry = Gtk3::Entry->new;  
  80. $entry->signal_connect( "activate" => \&entrada, undef );
  81. my $entrycio = Gtk3::Entry->new;
  82. $entry->set_icon_from_stock( 'secondary', 'gtk-apply' );
  83. $entry->signal_connect( 'icon-press' => \&entrada, undef );
  84. $entrycio->signal_connect( "activate" => \&confinicio, undef );
  85.  
  86. my $brg = Gtk3::ToolButton->new_from_stock('gtk-quit');
  87. my $fresh = Gtk3::ToolButton->new_from_stock('gtk-refresh');
  88. my $frenar = Gtk3::ToolButton->new_from_stock('gtk-stop');    
  89. my $batras = Gtk3::ToolButton->new_from_stock('gtk-go-back');
  90. my $belante = Gtk3::ToolButton->new_from_stock('gtk-go-forward');
  91. my $vermenos = Gtk3::ToolButton->new_from_stock('gtk-zoom-in');
  92. my $vermas = Gtk3::ToolButton->new_from_stock('gtk-zoom-out');
  93. my $home = Gtk3::ToolButton->new_from_stock('gtk-home');
  94. my $label = Gtk3::Label->new("");
  95. my $spinner = Gtk3::Spinner->new();
  96.  
  97. $fresh->signal_connect ( "clicked" => \&recargar );    
  98. $frenar->signal_connect ( "clicked" => \&parar );      
  99. $batras->signal_connect( "clicked" => \&atras );
  100. $belante->signal_connect ( "clicked" => \&adelante );
  101. $vermenos->signal_connect ( "clicked" => \&zomin );
  102. $vermas->signal_connect ( "clicked" => \&zomout);
  103. $home->signal_connect ( "clicked" => \&home);
  104.  
  105. my $botones = Gtk3::Notebook->new();
  106. $botones->set_show_tabs(FALSE);
  107. $botones->set_show_border(FALSE);
  108. $botones->append_page($fresh);
  109. $botones->append_page($frenar);
  110.  
  111. my $hbox = Gtk3::Box->new("horizontal", 0);
  112. $hbox->pack_start($entry, TRUE,TRUE , 0);
  113. $hbox->pack_start($home, FALSE,FALSE , 0);
  114. $hbox->pack_start($botones, FALSE,FALSE , 0);
  115. $hbox->pack_start($label, FALSE,FALSE , 5);
  116. $hbox->pack_start($spinner, FALSE,FALSE , 5);
  117. $hbox->pack_start($vermas, FALSE,FALSE , 0);
  118. $hbox->pack_start($vermenos, FALSE,FALSE , 0);
  119. $hbox->pack_start($batras, FALSE, FALSE, 0);
  120. $hbox->pack_start($belante, FALSE, FALSE, 0);
  121. $hbox->pack_start($table,FALSE, FALSE, 0);
  122.  
  123. my $vbox = Gtk3::Box->new("vertical", 0);
  124. $vbox->pack_start($hbox, FALSE, FALSE, 0);
  125. $vbox->pack_start($scrolls, TRUE, TRUE,  0);
  126.  
  127. $ventana->add($vbox);
  128.        
  129. $ventana->show_all();
  130.      
  131. Gtk3->main();  
  132.  
  133. sub salir {
  134. Gtk3->main_quit;
  135. }
  136.  
  137. sub adelante{
  138.  
  139. $ver->go_forward;
  140.  
  141. &cargar();
  142.  
  143. }
  144.  
  145. sub atras{
  146.  
  147. $ver->go_back;
  148.  
  149. &cargar();
  150.  
  151. }
  152.  
  153. sub entrada{
  154.  
  155. &cargar();
  156. &json;
  157.  
  158. my $motorb = $confP->{'pantalla'}->{'inicio'}->[1];
  159.  
  160. my $uri = $entry->get_text;
  161.  
  162. given ($uri) {
  163.  
  164. when (substr($uri,0,7) eq "http://") {
  165.         $uri = $uri;
  166.     }
  167. when (substr($uri,0,5) eq "https") {  
  168.         $uri = $uri;
  169.     }
  170. when($uri =~ /\s/) {
  171.     $uri = "$motorb" . "$uri";
  172.     }
  173. when($uri =~ /[.]/) {
  174.     $uri = "http://" . $uri;
  175.     }
  176. default {
  177.     $uri = "$motorb" . "$uri";
  178. }
  179. }
  180.  
  181. $ver->load_uri($uri);
  182. $botones->set_current_page(1);
  183. }
  184.  
  185. sub zomin { $ver->zoom_in }
  186.  
  187. sub zomout { $ver->zoom_out }
  188.  
  189. sub progreso{
  190. &cargar();
  191. my $ctitulo;
  192. my $carga = $ver->get('progress');
  193. $spinner->start();
  194.  
  195. for ( $ctitulo < 100 ) {
  196.    my $ctitul = sprintf ("%2d%%", 100 * $carga);
  197.    $label->set_markup("$ctitul");  
  198.    if ($ctitul == 100) {
  199.    $botones->set_current_page(0);
  200.    $spinner->stop();
  201.  
  202.                 }
  203.         }
  204. }
  205.  
  206. sub titulo {
  207. my $titul2 = $ver->get_title();
  208. my $url_sitio = $ver->get_uri();
  209. if ($titul2){
  210. $ventana->set_title( $titul2 );}
  211. my $titulp = substr($titul2,0,7);
  212. $entry->set_text("$url_sitio");
  213. }
  214.  
  215. sub recargar {
  216. &cargar();
  217. $ver->reload;
  218. }
  219.  
  220. sub parar {
  221. $ver->stop_loading;  
  222. $botones->set_current_page(0);
  223. }
  224.  
  225. sub cargar { $botones->set_current_page(1); }
  226.  
  227. sub acerca_de {
  228.  
  229. my $texto =<<EOF;
  230.  
  231. SimplePerlBrowser
  232.  
  233. Navegador Web escrito en Perl
  234.  
  235. Por: Tiempo de Tux
  236.  
  237. Version: 4.5.1
  238.  
  239. EOF
  240.  
  241. my $dialog = Gtk3::MessageDialog->new(
  242. $ventana,'destroy-with-parent', 'info', 'close', $texto);
  243. $dialog->signal_connect( response => sub { $dialog->destroy } );
  244. $dialog->show();
  245. }
  246.  
  247. sub web {
  248. $ver->load_uri( $uri );
  249. $ver->signal_connect( 'notify::progress' => \&progreso, undef );
  250. $ver->signal_connect( 'notify::title' => \&titulo, undef );
  251. }
  252.  
  253. sub activate_action {
  254. my $action = shift;
  255. my $name = $action->get_name;
  256.  
  257. given ($name) {
  258.   when( $name eq 'Completa' ) { &pantallacompleta($unscreen);}
  259.   when( $name eq 'HideTitlebar'){
  260.     my $value = $ventana->get_hide_titlebar_when_maximized();
  261.     if ( $value == 0 ) {
  262.       $ventana->set_hide_titlebar_when_maximized (TRUE);
  263.     } else{ $ventana->set_hide_titlebar_when_maximized (FALSE); }
  264.    }
  265.    when ( $name eq 'Acerca de'){ &acerca_de(); }
  266.    when ( $name eq 'Configuracion'){ &buscador_actual(); }
  267.    when ( $name eq 'Salir'){ &salir(); }
  268. }
  269. }
  270.  
  271. sub buscador_actual {
  272.  
  273. &json;
  274.  
  275. my $data;
  276.  
  277. my $buscador_actual = $confP->{'pantalla'}->{'inicio'}->[1];
  278.  
  279. if ( $buscador_actual =~ m/google/ ) {
  280.  
  281. $data = "Google";
  282.  
  283. } elsif ( $buscador_actual =~ m/bing/) {
  284.  
  285. $data = "Bing";
  286.  
  287. } elsif ( $buscador_actual =~ m/duck/) {
  288.  
  289. $data = "Duckduckgo";
  290.  
  291. } else {
  292.  
  293. $data = "No tienes configurado JSON";
  294.  
  295. }
  296.  
  297. &inicioconf($data);
  298.  
  299. }
  300.  
  301. sub inicioconf {
  302.  
  303.     my $motor_actual = shift;
  304.  
  305.         $inicio = Gtk3::Window->new('toplevel');
  306.        
  307.         $inicio->set_default_size(280, 100);
  308.         $inicio->set_title("Pagina de inicio");
  309.         $inicio->set_resizable(FALSE);
  310.         $inicio->set_border_width(5);
  311.         $inicio->set_position("center");  
  312.         $inicio->set_decorated(FALSE);
  313.         $inicio->signal_connect (delete_event => sub {$inicio->destroy });
  314.        
  315.         $entrycio->set_icon_from_stock( 'secondary', 'gtk-apply' );
  316.         my $config = Gtk3::RadioButton->new_with_label_from_widget(undef, "Actual: $motor_actual");
  317.         my $config0 = Gtk3::RadioButton->new_with_label_from_widget($config, "Google");
  318.         my $config1 = Gtk3::RadioButton->new_with_label_from_widget($config, "Duckduckgo");
  319.     my $config2 = Gtk3::RadioButton->new_with_label_from_widget($config, "Bing");
  320.         my $separador0 = Gtk3::Separator->new('horizontal');
  321.         my $separador1 = Gtk3::Separator->new('horizontal');
  322.         my $separador2 = Gtk3::Separator->new('horizontal');
  323.         my $labl0 = Gtk3::Label->new("Opciones");
  324.         my $labl1 = Gtk3::Label->new("http://");
  325.         my $labl2 = Gtk3::Label->new("Pagina de inicio");
  326.         my $labl3 = Gtk3::Label->new("Buscador");
  327.         my $ok = Gtk3::Button->new_from_stock('gtk-ok');
  328.         my $cerrar = Gtk3::Button->new_from_stock('gtk-quit');
  329.  
  330.         $entrycio->signal_connect( 'icon-press' => \&confinicio );
  331.     $config0->signal_connect (toggled => \&confnav, "Google");
  332.     $config1->signal_connect (toggled => \&confnav, "Duck");  
  333.     $config2->signal_connect (toggled => \&confnav, "Bing");  
  334.     $cerrar->signal_connect ( "clicked" => sub {$inicio->destroy });
  335.     $ok->signal_connect ( "clicked" => \&confinicio, 'ok' );
  336.         &seticio;
  337.  
  338.         my $hcio = Gtk3::Box->new("horizontal", 0);
  339.         $hcio->pack_start($labl1, FALSE, FALSE, 0);
  340.         $hcio->pack_start($entrycio, FALSE, FALSE, 0);
  341.        
  342.         my $ayc = Gtk3::Box->new("horizontal", 0);
  343.         $ayc->pack_start($ok, FALSE, FALSE, 30);
  344.         $ayc->pack_start($cerrar, FALSE, FALSE, 30);
  345.        
  346.         my $vcio = Gtk3::Box->new("vertical", 2);
  347.         $vcio->pack_start($labl0, FALSE, FALSE, 0);
  348.         $vcio->pack_start($separador0, FALSE, FALSE, 0);
  349.         $vcio->pack_start($labl2, FALSE, FALSE, 0);
  350.         $vcio->pack_start($hcio, FALSE, FALSE, 2);
  351.         $vcio->pack_start($separador1, FALSE, FALSE, 5);
  352.         $vcio->pack_start($labl3, FALSE, FALSE, 5);
  353.         $vcio->pack_start($config, FALSE, FALSE, 5);
  354.         $vcio->pack_start($config0, FALSE, FALSE, 5);
  355.         $vcio->pack_start($config1, FALSE, FALSE, 5);
  356.         $vcio->pack_start($config2, FALSE, FALSE, 5);
  357.         $vcio->pack_start($separador2, FALSE, FALSE, 5);
  358.         $vcio->pack_start($ayc, FALSE, FALSE, 5);
  359.         $vcio->set_homogeneous(TRUE);
  360.         $inicio->add($vcio);
  361.  
  362.         $inicio->show_all();  
  363. }
  364.  
  365.  
  366. sub get_ui {
  367.     return "<ui>
  368.        <menubar name='MenuBar'>
  369.   <menu action='Opciones'>
  370.          <menuitem action='Completa'/>
  371.          <menuitem action='HideTitlebar'/>
  372.          <menuitem action='Configuracion'/>
  373.          <menuitem action='Acerca de'/>
  374.          <menuitem action='Salir'/>
  375.   </menu>
  376. </menubar>
  377. </ui>";
  378. }
  379.  
  380. sub confinicio {
  381.  
  382. my ($widget,$text) = @_;
  383.  
  384. my $paginicio = $entrycio->get_text;
  385.  
  386. if (substr($paginicio,0,7) eq 'http://') {
  387.    &opensettings(0,$paginicio);    
  388. }
  389.  
  390. elsif ($paginicio ne "") {
  391.    &opensettings(0,"http://" . $paginicio);
  392. }
  393.  
  394. else {
  395. my $texto =<<EOF;
  396.  
  397. No tienes bien configurado conf.json
  398.  
  399. EOF
  400.  
  401. my $dialog = Gtk3::MessageDialog->new(
  402. $ventana,'destroy-with-parent', 'info', 'close', $texto);
  403. $dialog->signal_connect( response => sub { $dialog->destroy } );
  404. $dialog->show();
  405.  
  406. }
  407. if ($text eq 'ok') {
  408.    &opensettings(0,"http://" . $paginicio);
  409.    $inicio->destroy;
  410.  
  411. } }
  412.  
  413. sub pantallacompleta {
  414.  
  415. my $setting = shift;
  416.  
  417. given($setting) {
  418. when($setting eq 'unfullscreen') { $unscreen = 'fullscreen'}
  419. when($setting eq 'fullscreen') { $unscreen = 'unfullscreen'}
  420. }
  421.  
  422. $ventana->$unscreen();
  423.  
  424. }
  425.  
  426. sub json {
  427.  
  428. {
  429.   local $/;
  430.   open my $cf, "<", "conf.json";
  431.   $json = <$cf>;
  432.   close $cf;
  433. }
  434.  
  435. }
  436.  
  437. sub seticio {
  438. $iniP = $confP->{'pantalla'}->{'inicio'}->[0];
  439. my @text = split(m/^http[:]\/\//,$iniP);
  440.  
  441. $entrycio->set_text($text[1]);
  442.    
  443. }
  444.  
  445. sub confnav {
  446.    
  447. my ($widget,$buscador) = @_;
  448.  
  449. my @motores = (
  450.  
  451. "http://www.bing.com/search?q=",
  452.  
  453. "https://duckduckgo.com/?q=",
  454.  
  455. "http://www.google.com/search?q="
  456.  
  457. );
  458.  
  459. if ($buscador eq 'Bing') {
  460.     &opensettings(1,$motores[0]);
  461. }
  462. elsif($buscador eq 'Duck' ) {
  463.     &opensettings(1,$motores[1]);
  464. }
  465. elsif ($buscador eq 'Google' ){
  466.     &opensettings(1,$motores[2]);
  467. }
  468.  
  469. }
  470.  
  471. sub opensettings {
  472.  
  473. my ($number,$setting) = @_;
  474.  
  475. $unscreen = $confP->{'pantalla'}->{'inicio'}->[$number] = "$setting";
  476.  
  477. open my $cfn, ">", "conf.json";
  478. print $cfn encode_json($confP);
  479. close $cfn;
  480. }
  481.  
  482. sub home {
  483.  
  484. $uri = $iniP;
  485.  
  486. &web;
  487.  
  488. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement