annotate plugins/perl/scripts/count_down.pl @ 11170:0e9e2b923d09

[gaim-migrate @ 13271] Fixed some bugs and made some additions to the XSUBS. Added some of my test scripts which are incomplete, but mostly functional. GaimPluginPrefs and GaimGtkPluginPrefs--using evals to do the Gtk widgets with gtk2-perl--work. Plugin actions can now be added, but only one for now. committer: Tailor Script <tailor@pidgin.im>
author John H. Kelm <johnkelm@gmail.com>
date Fri, 29 Jul 2005 13:38:00 +0000
parents
children 6fd82071a7b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
1 use Gaim;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
2
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
3 %PLUGIN_INFO = (
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
4 perl_api_version => 2,
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
5 name => "Countdown Info Timer",
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
6 version => "0.1",
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
7 summary => "Makes a countdown in days from today.",
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
8 description => "Long description coming....",
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
9 author => "John H. Kelm <johnhkelm\@gmail.com>",
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
10 url => "http://gaim.sourceforge.net/",
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
11
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
12 load => "plugin_load",
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
13 unload => "plugin_unload"
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
14 );
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
15
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
16 $GLOBAL_TEST_VAR = "STUFF!";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
17
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
18 sub plugin_unload {
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
19 my $plugin = shift;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
20 }
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
21
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
22 sub plugin_init {
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
23 return %PLUGIN_INFO;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
24 }
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
25
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
26
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
27 sub plugin_load {
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
28 my $plugin = shift;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
29
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
30 # Retrieve all the accounts
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
31 @accounts = Gaim::Accounts::get_all();
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
32
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
33 print "NUM OF ACCS: " . $accounts . "\n";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
34 # Search each account's user info for our tag
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
35 foreach $acc (@accounts) {
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
36 print "IN ACCOUNTS\n";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
37 $user_info = Gaim::Account::get_user_info($acc);
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
38 print "USER INFO 1: " . $user_info . "\n";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
39 # Find <countdown> and replace
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
40 $user_info =~ /countdown([0-9]+).([0-9]+).([0-9]+)/;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
41 print "Found: " .$1 . " " . $2 . " " . $3 . "\n";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
42 $days = count_days($1, $2, $3);
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
43 $user_info =~ s/countdown(\d\d\d\d).(\d\d).(\d\d)/$days/;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
44 print "USER INFO 2: " . $user_info . "\n";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
45 # Gaim::Account::set_user_info($acc, $user_info);
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
46
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
47 }
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
48
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
49 eval '
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
50 use Gtk2 \'-init\';
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
51 use Glib;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
52 $window = Gtk2::Window->new(\'toplevel\');
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
53 $window->set_border_width(10);
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
54 $button = Gtk2::Button->new("Hello World");
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
55 $button->signal_connect(clicked => \&hello, $window);
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
56
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
57 $window->add($button);
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
58 $button->show;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
59 $window->show;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
60 # Gtk2->main;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
61
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
62 0;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
63
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
64 '; warn $@ if $@;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
65 }
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
66
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
67 sub hello {
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
68 my ($widget, $window) = @_;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
69 print "Called from sub hello!\n ";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
70 print "Test var: " . $GLOBAL_TEST_VAR . " \n";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
71 @accounts = Gaim::Accounts::get_all();
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
72 $acc = $accounts[0];
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
73 $user_info = Gaim::Account::get_user_info($acc);
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
74 print "USER INFO from sub hello: " . $user_info . "\n";
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
75 $window->destroy;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
76 }
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
77
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
78 sub count_days {
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
79 ($year, $month, $day) = @_;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
80
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
81
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
82 eval '
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
83 use Time::Local;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
84 $future = timelocal(0,0,0,$day,$month-1,$year);
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
85 '; warn $@ if $@;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
86 $today = time();
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
87 $days = int(($future - $today)/(60*60*24));
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
88 return $days;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
89 }