restructure configure so pkg-config derived SSL flags get used
[rofl0r-ixchat.git] / plugins / perl / char_count.pl
blob418046f4767db47d54b4102a5eca6a4fb00ebed0
2 use strict;
3 use warnings;
4 use Xchat qw(:all);
5 use Glib qw(TRUE FALSE);
6 use Gtk2 -init;
8 sub get_inputbox {
9 my $widget = Glib::Object->new_from_pointer( get_info( "win_ptr" ), 0 );
10 my $input_box;
12 my @containers = ($widget);
14 while( @containers ) {
15 my $container = shift @containers;
17 for my $child ( $container->get_children ) {
18 if( $child->get( "name" ) eq 'xchat-inputbox' ) {
19 $input_box = $child;
20 last;
21 } elsif( $child->isa( "Gtk2::Container" ) ) {
22 push @containers, $child;
26 return $input_box;
29 sub get_hbox {
30 my $widget = shift;
31 my $hbox;
33 while( $widget->parent ) {
34 if( $widget->parent->isa( "Gtk2::HBox" ) ) {
35 return $widget->parent;
37 $widget = $widget->parent;
42 my $input_box = get_inputbox();
44 if( $input_box ) {
45 my $hbox = get_hbox( $input_box );
46 if( $hbox ) {
47 my $label = Gtk2::Label->new();
48 $label->set_alignment( 0.5, ($label->get_alignment)[1] );
49 $hbox->pack_end( $label, 0, 0, 5 );
50 $label->show();
52 my $update_label = sub {
53 my $ctx_type = context_info->{"type"};
54 hook_timer( 0, sub {
55 if( $ctx_type == 2 || $ctx_type == 3 ) {
56 my $count = length get_info "inputbox";
57 $label->set_text( $count ? $count : "" );
58 } else {
59 $label->set_text( "" );
61 return REMOVE;
62 });
63 return EAT_NONE;
66 hook_print( "Key Press", $update_label );
67 hook_print( "Focus Tab", $update_label );
68 hook_print( "Focus Window", $update_label );
69 hook_command( "",
70 sub {
71 $label->set_text( "" );
72 return EAT_NONE;
76 my @handlers;
77 my $buffer = $input_box->get_buffer;
78 my $handler = sub { $update_label->(); return TRUE };
80 if( $buffer->isa( "Gtk2::TextBuffer" ) ) {
81 push @handlers, $buffer->signal_connect( "changed", $handler );
82 } elsif( $buffer->isa( "Gtk2::EntryBuffer" ) ) {
83 push @handlers,
84 $buffer->signal_connect( "deleted-text", $handler );
85 $buffer->signal_connect( "inserted-text", $handler );
88 register( "Character Counter", "1.0.0",
89 "Display the number of characters in the inputbox",
90 sub {
91 $hbox->remove( $label );
92 $buffer->signal_handler_disconnect( $_ ) for @handlers;
95 } else {
96 prnt "Counldn't find hbox";
99 } else {
100 prnt "Couldn't fint input box";