Mon, 05 Dec 2005 23:54:34 +0000
[gaim-migrate @ 14668]
sf patch #1373688, from Will Thompson
"Make the Perl bindings more Perl-ish"
committer: Mark Doliner <markdoliner@pidgin.im>
| 11170 | 1 | use Gaim; |
| 2 | ||
| 3 | %PLUGIN_INFO = ( | |
| 4 | perl_api_version => 2, | |
| 5 | name => "Countdown Info Timer", | |
| 6 | version => "0.1", | |
| 7 | summary => "Makes a countdown in days from today.", | |
| 8 | description => "Long description coming....", | |
| 9 | author => "John H. Kelm <johnhkelm\@gmail.com>", | |
| 10 | url => "http://gaim.sourceforge.net/", | |
| 11 | ||
| 12 | load => "plugin_load", | |
| 13 | unload => "plugin_unload" | |
| 14 | ); | |
| 15 | ||
| 16 | $GLOBAL_TEST_VAR = "STUFF!"; | |
| 17 | ||
| 18 | sub plugin_unload { | |
| 19 | my $plugin = shift; | |
| 20 | } | |
| 21 | ||
| 22 | sub plugin_init { | |
| 23 | return %PLUGIN_INFO; | |
| 24 | } | |
| 25 | ||
| 26 | ||
| 27 | sub plugin_load { | |
| 28 | my $plugin = shift; | |
| 29 | ||
| 30 | # Retrieve all the accounts | |
| 31 | @accounts = Gaim::Accounts::get_all(); | |
| 32 | ||
| 33 | print "NUM OF ACCS: " . $accounts . "\n"; | |
| 34 | # Search each account's user info for our tag | |
| 35 | foreach $acc (@accounts) { | |
| 36 | print "IN ACCOUNTS\n"; | |
| 12364 | 37 | $user_info = $acc->get_user_info(); |
| 11170 | 38 | print "USER INFO 1: " . $user_info . "\n"; |
| 39 | # Find <countdown> and replace | |
| 40 | $user_info =~ /countdown([0-9]+).([0-9]+).([0-9]+)/; | |
| 41 | print "Found: " .$1 . " " . $2 . " " . $3 . "\n"; | |
| 42 | $days = count_days($1, $2, $3); | |
| 43 | $user_info =~ s/countdown(\d\d\d\d).(\d\d).(\d\d)/$days/; | |
| 44 | print "USER INFO 2: " . $user_info . "\n"; | |
| 12364 | 45 | # $acc->set_user_info($user_info); |
| 11170 | 46 | |
| 47 | } | |
| 48 | ||
| 49 | eval ' | |
| 50 | use Gtk2 \'-init\'; | |
| 51 | use Glib; | |
| 52 | $window = Gtk2::Window->new(\'toplevel\'); | |
| 53 | $window->set_border_width(10); | |
| 54 | $button = Gtk2::Button->new("Hello World"); | |
| 55 | $button->signal_connect(clicked => \&hello, $window); | |
| 56 | ||
| 57 | $window->add($button); | |
| 58 | $button->show; | |
| 59 | $window->show; | |
| 60 | # Gtk2->main; | |
| 61 | ||
| 62 | 0; | |
| 63 | ||
| 64 | '; warn $@ if $@; | |
| 65 | } | |
| 66 | ||
| 67 | sub hello { | |
| 68 | my ($widget, $window) = @_; | |
| 69 | print "Called from sub hello!\n "; | |
| 70 | print "Test var: " . $GLOBAL_TEST_VAR . " \n"; | |
| 71 | @accounts = Gaim::Accounts::get_all(); | |
| 72 | $acc = $accounts[0]; | |
| 12364 | 73 | $user_info = $acc->get_user_info(); |
| 11170 | 74 | print "USER INFO from sub hello: " . $user_info . "\n"; |
| 75 | $window->destroy; | |
| 76 | } | |
| 77 | ||
| 78 | sub count_days { | |
| 79 | ($year, $month, $day) = @_; | |
| 80 | ||
| 81 | ||
| 82 | eval ' | |
| 83 | use Time::Local; | |
| 84 | $future = timelocal(0,0,0,$day,$month-1,$year); | |
| 85 | '; warn $@ if $@; | |
| 86 | $today = time(); | |
| 87 | $days = int(($future - $today)/(60*60*24)); | |
| 88 | return $days; | |
| 89 | } |