annotate doc/PERL-HOWTO.dox @ 12364:6fd82071a7b8

[gaim-migrate @ 14668] sf patch #1373688, from Will Thompson "Make the Perl bindings more Perl-ish" committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 05 Dec 2005 23:54:34 +0000
parents 11d14efe7be2
children 967dd29cc4ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1 /** @page perl-howto Perl Scripting HOWTO
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
2
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
3 @section Introduction
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
4 Gaim Perl Plugins are setup very similarly to their C counterparts. Most of the API calls are implemented and are divided into pacakges. There are some significant differences between the Perl and C API. Much like the C API, the best place to seek guidances is the source located in the plugins/perl/common directory. The tutorial that follows will be example based and attempt to touch on the salient features of the embedded perl interpreter. It is also important to note that some of the C API is missing in Gaim's perl API.
10408
f53c59c95f03 [gaim-migrate @ 11656]
Mark Doliner <mark@kingant.net>
parents: 10161
diff changeset
5
11501
9563b768e8e2 [gaim-migrate @ 13746]
Richard Laager <rlaager@wiktel.com>
parents: 11377
diff changeset
6 It is possible to get Gtk2-Perl to work with Gaim's perl API, however you must not load the module with @c use but with @c require. If you are uninterested in using Gtk with your perl plugins than this still has bearing on you if you would like to use certain perl modules that are dynamically loaded. By always using @c require instead of @c use the problem is avoided.
6602
76683fe3c96d [gaim-migrate @ 7126]
Christian Hammond <chipx86@chipx86.com>
parents: 6598
diff changeset
7
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
8 @section first-script Writing your first script
6602
76683fe3c96d [gaim-migrate @ 7126]
Christian Hammond <chipx86@chipx86.com>
parents: 6598
diff changeset
9
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
10 Let us start with a simple example of a Gaim perl plugin. The following code sample is a complete plugin that can be copied and used as is.
6602
76683fe3c96d [gaim-migrate @ 7126]
Christian Hammond <chipx86@chipx86.com>
parents: 6598
diff changeset
11
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
12 @code
6602
76683fe3c96d [gaim-migrate @ 7126]
Christian Hammond <chipx86@chipx86.com>
parents: 6598
diff changeset
13 use Gaim;
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
14
6602
76683fe3c96d [gaim-migrate @ 7126]
Christian Hammond <chipx86@chipx86.com>
parents: 6598
diff changeset
15 %PLUGIN_INFO = (
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
16 perl_api_version => 2,
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
17 name => "Perl Test Plugin",
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
18 version => "0.1",
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
19 summary => "Test plugin for the Perl interpreter.",
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
20 description => "Your description here",
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
21 author => "John H. Kelm <johnhkelm\@gmail.com",
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
22 url => "http://gaim.sourceforge.net/",
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
23
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
24 load => "plugin_load",
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
25 unload => "plugin_unload"
7182
65acffe70a6d [gaim-migrate @ 7750]
Christian Hammond <chipx86@chipx86.com>
parents: 6720
diff changeset
26 );
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
27
6602
76683fe3c96d [gaim-migrate @ 7126]
Christian Hammond <chipx86@chipx86.com>
parents: 6598
diff changeset
28 sub plugin_init {
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
29 return %PLUGIN_INFO;
6602
76683fe3c96d [gaim-migrate @ 7126]
Christian Hammond <chipx86@chipx86.com>
parents: 6598
diff changeset
30 }
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
31
6602
76683fe3c96d [gaim-migrate @ 7126]
Christian Hammond <chipx86@chipx86.com>
parents: 6598
diff changeset
32 sub plugin_load {
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
33 my $plugin = shift;
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
34 Gaim::debug_info("plugin_load()", "Test Plugin Loaded.");
6602
76683fe3c96d [gaim-migrate @ 7126]
Christian Hammond <chipx86@chipx86.com>
parents: 6598
diff changeset
35 }
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
36
6602
76683fe3c96d [gaim-migrate @ 7126]
Christian Hammond <chipx86@chipx86.com>
parents: 6598
diff changeset
37 sub plugin_unload {
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
38 my $plugin = shift;
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
39 Gaim::debug_info("plugin_unload()", "Test Plugin Unloaded.");
6602
76683fe3c96d [gaim-migrate @ 7126]
Christian Hammond <chipx86@chipx86.com>
parents: 6598
diff changeset
40 }
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
41 @endcode
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
42
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
43 It is necessary to load the Gaim perl package with the line @code use Gaim; @endcode which will make all the Gaim perl API available to the script. The @c \%PLUGIN_INFO has contains all the information that will be displayed in the Plugin frame of the Preferences dialog. In addition to information needed to describe the plugin to the user, information about how the plugin is to be handled is present. The keys @c load and @c unload specify and action to take when the plugin is loaded and when it is unloaded from the Preferences dialog respectively. There are other key values that may be present in the @c \%PLUGIN_INFO hash that will be covered in the following sections.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
44
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
45 The Perl subroutine @c plugin_init is executed when the plugin is probed by the plugin subsystem. What this means is as soon as Gaim is started, this subroutine is run once, regardless of whether the plugin is loaded or not. The other two subroutines present are those defined by the @c \%PLUGIN_INFO hash and take the plugin handle as an argument. When the plugin is loaded and subsequently unloaded it will print a message to the debug window using the @c Gaim::debug_info() Gaim perl API call.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
46
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
47 The last step is to save the script with a .pl file extention in your ~/.gaim/plugins directory. After restarting gaim the plugin "Perl Test Plugin" should now appear under "Tools->Preferences->Plugins". To view the messages make sure you run Gaim from the console with the '-d' flag or open the Debug Window from inside Gaim under "Help". When you enable the checkbox next the plugin you should see a message appear in the Debug Window (or console) and when you disable the checkbox you should see another message appear. You have now created the framework that will allow you to create almost any kind of Gaim plugin you can imagine.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
48
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
49 @section account-api Account and Account Option Functions
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
50
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
51 The Account API is in the @c Gaim::Account:: and @c Gaim::Accounts:: packages
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
52 and both are nearly identical to their C counterparts @c gaim_account_ and @c
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
53 gaim_accounts_. The Account Option API is in the package @c
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
54 Gaim::Account::Option and is identical to its C implementation @c
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
55 gaim_account_option.
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
56
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
57 The Account* APIs allow for scripts to create, remove, and edit accounts of the
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
58 type GaimAccount. (Note: Gaim types have no real meaning in perl scripts other
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
59 than the types of the arguments of the perl subroutines need to be of the
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
60 expected type.) This section will not go into detail about the @c
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
61 Gaim::Account::Option package for its use in building protocol plugins which
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
62 are outside the scope of this document. However, most of the API calls for the
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
63 @c Gaim::Account::Option package should function as expected so if there is a
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
64 need to access any of the Account Options the function calls necessary are
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
65 avaialbe in the Gaim perl API.
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
66
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
67 To reduce redundant code the following code examples are going to use the
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
68 template shown in the previous section. To highlight some of the more useful
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
69 features of the Account API we will be replacing the @c plugin_load perl
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
70 subroutine. For testing purposes we will display output on the command line by
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
71 using perl @c print commands.
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
72
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
73 @code
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
74 sub plugin_load {
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
75 $plugin = shift;
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
76
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
77 # Testing was done using Oscar, but this should work regardless of the protocol chosen
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
78 my $protocol = "prpl-oscar";
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
79
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
80 # Create a new Account
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
81 print "Testing: Gaim::Account::new()... ";
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
82 $account = Gaim::Account->new($TEST_NAME, $PROTOCOL_ID);
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
83 if ($account) { print "ok.\n"; } else { print "fail.\n"; }
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
84
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
85 # Add a new Account
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
86 print "Testing: Gaim::Account::add()...";
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
87 Gaim::Accounts::add($account);
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
88 print "pending find...\n";
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
89
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
90 # Find the account we just added to verify its existence
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
91 print "Testing: Gaim::Accounts::find()...";
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
92 $account = Gaim::Accounts::find("TEST_NAME", $protocol);
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
93 if ($account) { print "ok.\n"; } else { print "fail.\n"; }
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
94
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
95 # Return the username
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
96 print "Testing: Gaim::Account::get_username()... ";
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
97 $user_name = $account->get_username();
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
98 if ($user_name) {
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
99 print "Success: $user_name.\n";
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
100 } else {
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
101 print "Failed!\n";
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
102 }
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
103 # Verify if the user is connected
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
104 print "Testing: Gaim::Account::is_connected()";
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
105 if ($account->is_connected()) {
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
106 print " Connected.\n";
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
107 } else {
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
108 print " Disconnected.\n";
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
109 }
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
110
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
111 # The status mechanism is how users are Connected, set Away,
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
112 # Disconnected (status set to Offline), etc
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
113 # $status is now a Gaim::Status perl type.
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
114 print "Testing: Gaim::Accounts::get_active_status()... ";
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
115 if ($account->get_active_status()) {
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
116 print "Okay.\n";
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
117 } else {
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
118 print "Failed!\n";
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
119 }
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
120
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
121 # It follows that to connect a user you mest set the account status to
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
122 # "available" similarly we can disconnect a user by setting the account
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
123 # status to "offline"
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
124
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
125 $account = Gaim::Accounts::find("TEST_NAME", $protocol);
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
126 print "Testing: Gaim::Accounts::connect()...pending...\n";
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
127
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
128 $account->set_status("available", TRUE);
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
129 $account->connect();
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
130
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
131 }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
132 @endcode
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
133
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
134 For the most part the code listed above is explained by the comments, however
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
135 there are a few other points to make. The variables above are all specialized
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
136 Perl types that contain pointers to the actual Gaim types. They can be
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
137 reasigned at will just like any other variable in Perl. The only way to edit
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
138 the values of a Gaim type from within perl are through accessor methods such as
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
139 @c Gaim::Account::get_username(). For arguments that you would make @c NULL in
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
140 C should be set to @c undef in Perl.
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
141
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
142 @section buddylist-api Buddylist, Group and Chat API
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
143
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
144 The BuddList, Group and Chat APIs are very similar and whatever is shown for the @c Gaim::BuddlyList API should carry over to @c Gaim::Chat and @c Gaim::Group. Note that there is a @c Gaim::Find pacakge that was created to keep the naming consistent with how these functions are named in the C API.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
145
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
146 @code
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
147 sub plugin_load {
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
148 my $plugin = shift;
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
149 my $protocol = "prpl-oscar";
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
150
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
151 # This is how we get an account to use in the following tests. You should replace the username
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
152 # with an existent user
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
153 $account = Gaim::Accounts::find("USERNAME", $protocol);
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
154
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
155 # Testing a find function: Note Gaim::Find not Gaim::Buddy:find!
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
156 # Furthermore, this should work the same for chats and groups
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
157 print "Testing: Gaim::Find::buddy()...";
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
158 $buddy = Gaim::Find::buddy($account, "BUDDYNAME");
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
159 if ($buddy) { print "ok.\n"; } else { print "fail.\n"; }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
160
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
161 # If you should need the handle for some reason, here is how you do it
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
162 print "Testing: Gaim::BuddyList::get_handle()...";
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
163 $handle = Gaim::BuddyList::get_handle();
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
164 if ($handle) { print "ok.\n"; } else { print "fail.\n"; }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
165
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
166 # This gets the Gaim::BuddyList and references it by $blist
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
167 print "Testing: Gaim::BuddyList::get_blist()...";
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
168 $blist = Gaim::BuddyList::get_blist();
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
169 if ($blist) { print "ok.\n"; } else { print "fail.\n"; }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
170
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
171 # This is how you would add a buddy named "NEWNAME" with the alias "ALIAS"
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
172 print "Testing: Gaim::Buddy::new...";
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
173 $buddy = Gaim::Buddy::new($account, "NEWNAME", "ALIAS");
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
174 if ($buddy) { print "ok.\n"; } else { print "fail.\n"; }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
175
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
176 # Here we add the new buddy '$buddy' to the group "GROUP"
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
177 # so first we must find the group
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
178 print "Testing: Gaim::Find::group...";
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
179 $group = Gaim::Find::group("GROUP");
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
180 if ($group) { print "ok.\n"; } else { print "fail.\n"; }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
181
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
182 # To add the buddy we need to have the buddy, contact, group and node for insertion.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
183 # For this example we can let contact be undef and set the insertion node as the group
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
184 print "Testing: Gaim::BuddyList::add_buddy...";
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
185 Gaim::BuddyList::add_buddy($buddy, undef, $group, $group);
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
186 if ($buddy) { print "ok.\n"; } else { print "fail.\n"; }
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
187
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
188 # The example that follows gives an indiction of how an API call that returns a list is handled.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
189 # In this case the buddies of the account found earlier are retrieved and put in an array '@buddy_array'
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
190 # Further down an accessor method is used, 'get_name()' -- see source for details on the full set of methods
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
191 print "Testing: Gaim::Find::buddies...\n";
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
192 @buddy_array = Gaim::Find::buddies($account, "USERNAME");
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
193 if (@buddy_array) {
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
194 print "Buddies in list (" . @buddy_array . "): \n";
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
195 foreach $bud (@buddy_array) {
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
196 print Gaim::Buddy::get_name($bud) . "\n";
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
197 }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
198 }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
199 }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
200 @endcode
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
201
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
202 The BuddyList API allows for plugins to edit buddies in the list, find the buddies on a given account, set alias, and manipulate the structer as needed. It is also contains the methods for accessing @c Gaim::Group and @c Gaim::Chat types.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
203
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
204 @section conn-api Connection API
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
205
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
206 The @c Gaim::Connection API is one of the many packages that will not be covered in depth in this tutorial. They are more useful to protocol plugin developers. However, the entire @c gaim_connection_ API has corresponding, functioning perl subroutines.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
207
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
208 @section conv-api Conversation API
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
209
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
210 The Gaim perl API for @c gaim_conversation_ and @c gaim_conv_window_ allow
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
211 plugins to interact with open conversations, create new conversations, and
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
212 modify conversations at will. The following example again replaces the @c
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
213 plugin_load subroutine. In the example script, a new window is created,
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
214 displayed and a new conversation instant message is created. The @c
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
215 Gaim::Conversation::Chat package handles the @c gaim_conv_chat_ portion of the
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
216 API very similarly to the examples that follow.
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
217
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
218 @code
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
219 sub plugin_load {
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
220 my $plugin = shift;
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
221 my $protocol = "prpl-oscar";
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
222
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
223 $account = Gaim::Accounts::find("USERNAME", $protocol);
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
224
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
225 # First we create two new conversations.
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
226 print "Testing Gaim::Conversation::new()...";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
227 $conv1 = Gaim::Conversation::new(1, $account, "Test Conversation 1");
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
228 if ($conv1) { print "ok.\n"; } else { print "fail.\n"; }
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
229
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
230 print "Testing Gaim::Conversation::new()...";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
231 $conv2 = Gaim::Conversation::new(1, $account, "Test Conversation 2");
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
232 if ($conv2) { print "ok.\n"; } else { print "fail.\n"; }
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
233
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
234 # Second we create a window to display the conversations in.
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
235 # Note that the package here is Gaim::Conversation::Window
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
236 print "Testing Gaim::Conversation::Window::new()...\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
237 $win = Gaim::Conversation::Window::new();
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
238
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
239 # The third thing to do is to add the two conversations to the windows.
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
240 # The subroutine add_conversation() returns the number of conversations
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
241 # present in the window.
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
242 print "Testing Gaim::Conversation::Window::add_conversation()...";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
243 $conv_count = $conv1->add_conversation();
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
244 if ($conv_count) {
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
245 print "ok..." . $conv_count . " conversations...\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
246 } else {
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
247 print "fail.\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
248 }
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
249
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
250 print "Testing Gaim::Conversation::Window::add_conversation()...";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
251 $conv_count = $win->add_conversation($conv2);
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
252 if ($conv_count) {
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
253 print "ok..." . $conv_count . " conversations...\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
254 } else {
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
255 print "fail.\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
256 }
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
257
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
258 # Now the window is displayed to the user.
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
259 print "Testing Gaim::Conversation::Window::show()...\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
260 $win->show();
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
261
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
262 # Use get_im_data() to get a handle for the conversation
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
263 print "Testing Gaim::Conversation::get_im_data()...\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
264 $im = $conv1->get_im_data();
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
265 if ($im) { print "ok.\n"; } else { print "fail.\n"; }
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
266
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
267 # Here we send messages to the conversation
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
268 print "Testing Gaim::Conversation::IM::send()...\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
269 $im->send("Message Test.");
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
270
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
271 print "Testing Gaim::Conversation::IM::write()...\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
272 $im->write("SENDER", "<b>Message</b> Test.", 0, 0);
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
273 }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
274 @endcode
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
275
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
276 The next block of code shows how a script can close a known conversation window
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
277 @c $win.
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
279 @code
12340
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
280 print "Testing Gaim::Conversation::Window::get_conversation_count()...\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
281 $conv_count = $win->get_conversation_count();
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
282 print "...and it returned $conv_count.\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
283 if ($conv_count > 0) {
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
284 print "Testing Gaim::Conversation::Window::destroy()...\n";
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
285 $win->destroy();
11d14efe7be2 [gaim-migrate @ 14644]
Mark Doliner <mark@kingant.net>
parents: 11501
diff changeset
286 }
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
287 @endcode
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
288
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
289 @section plugin-pref-api Plugin Preference and Gtk Preference API
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
290
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
291 The plugin preference API allows the plugin to display options in a preference pane that the user can change to manipulate the behaviour of the particular perl plugin. The method used for creating the pane in C does not allow a direct mapping into perl. Therefore perl plugin writers must be aware that there will be significant differences in how they create plugin preference panes.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
292
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
293 To first create a standard plugin preference tab we need to add some key/value pairs to the @c \%PLUGIN_INFO hash. The first line contains the perl subroutine that must be provided and will return a @c Gaim::Pref::Frame.
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
294
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
295 @code
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
296 %PLUGIN_INFO = {
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
297 ...,
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
298 prefs_info => "prefs_info_cb"
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
299 };
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
300 @endcode
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
301
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
302 The perl subroutine @c prefs_info_cb will be called to create the tab for the perl plugin in the Preferences dialog. An example of this function will explain the details of creating a preference frame. However, it is necessary to first create the preferences from @c plugin_load as follows.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
303
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
304 @code
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
305 sub plugin_load {
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
306 my $plugin = shift;
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
307
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
308 # Here we are adding a set of preferences
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
309 # The second argument is the default value for the preference.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
310 Gaim::Prefs::add_none("/plugins/core/perl_test");
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
311 Gaim::Prefs::add_bool("/plugins/core/perl_test/bool", 1);
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
312 Gaim::Prefs::add_string("/plugins/core/perl_test/choice", "ch1");
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
313 Gaim::Prefs::add_string("/plugins/core/perl_test/text", "Foobar");
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
314 }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
315 @endcode
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
316
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
317 Now we can add these preferences from inside our function specified in @c \%PLUGIN_INFO .
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
318
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
319 @code
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
320 sub prefs_info_cb {
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
321 # The first step is to initialize the Gaim::Pref::Frame that will be returned
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
322 $frame = Gaim::PluginPref::Frame->new();
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
323
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
324 # Create a new boolean option with a label "Boolean Label" and then add
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
325 # it to the frame
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
326 $ppref = Gaim::Pref->new_with_label("Boolean Label");
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
327 $frame->add($ppref);
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
328
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
329 $ppref = Gaim::PluginPref->new_with_name_and_label(
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
330 "/plugins/core/perl_test/bool", "Boolean Preference");
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
331 $frame->add($ppref);
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
332
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
333 # Create a set of choices. To do so we must set the type to 1 which is
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
334 # the numerical equivelant of the GaimPrefType for choice.
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
335 $ppref = Gaim::PluginPref->new_with_name_and_label(
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
336 "/plugins/core/perl_test/choice", "Choice Preference");
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
337 $ppref->set_type(1);
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
338 $ppref->add_choice("ch0", $frame);
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
339 # The following will be the default value as set from plugin_load
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
340 $ppref->add_choice("ch1", $frame);
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
341 $frame->add($ppref);
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
342
12364
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
343 # Create a text box. The default value will be "Foobar" as set by
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
344 # plugin_load
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
345 $ppref = Gaim::PluginPref->new_with_name_and_label(
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
346 "/plugins/core/perl_test/text", "Text Box Preference");
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
347 $ppref->set_max_length(16);
6fd82071a7b8 [gaim-migrate @ 14668]
Mark Doliner <mark@kingant.net>
parents: 12340
diff changeset
348 $frame->add($ppref);
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
349
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
350 return $frame;
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
351 }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
352 @endcode
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
353
11377
5c3a0e641520 [gaim-migrate @ 13603]
John H. Kelm <johnkelm@gmail.com>
parents: 11278
diff changeset
354 Using the Gtk2-Perl module for Perl it is possible to create tailored @c GtkFrame elements and display them in a preference window. Note that Gtk2-Perl must be loaded with @c require and not @c use . The first step is to create the proper key/value pairs in the @c \%PLUGIN_INFO hash noting that the @c prefs_info key is no longer valid. Instead the keys @c GTK_UI and @c gtk_prefs_info must be set as follows.
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
355
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
356 @code
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
357 %PLUGIN_INFO = {
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
358 ...,
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
359 # Used to differentiate between a regular and a Gtk preference frame
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
360 GTK_UI => TRUE,
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
361 gtk_prefs_info => "gtk_prefs_info_cb",
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
362 }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
363 @endcode
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
364
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
365 To finish this example @c gtk_prefs_info_cb needs to be defined. To introduce some of the flexibility of using Gtk2-Perl the example also includes a button and a callback for the button. Explaining Gtk2-Perl is beyond the scope of this tutorial and more info can be found at the project's website <a href="http://gtk2-perl.sourceforge.net/">http://gtk2-perl.sourceforge.net/</a>.
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
366
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
367 @code
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
368 # A simple call back that prints out whatever value it is given as an argument.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
369 sub button_cb {
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
370 my $widget = shift;
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
371 my $data = shift;
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
372 print "Clicked button with message: " . $data . "\n";
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
373 }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
374
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
375 sub gtk_prefs_info_cb {
11377
5c3a0e641520 [gaim-migrate @ 13603]
John H. Kelm <johnkelm@gmail.com>
parents: 11278
diff changeset
376 # Create a button that prints a message to the console and places it in the frame.
5c3a0e641520 [gaim-migrate @ 13603]
John H. Kelm <johnkelm@gmail.com>
parents: 11278
diff changeset
377 use Glib;
5c3a0e641520 [gaim-migrate @ 13603]
John H. Kelm <johnkelm@gmail.com>
parents: 11278
diff changeset
378 require Gtk2;
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
379
11377
5c3a0e641520 [gaim-migrate @ 13603]
John H. Kelm <johnkelm@gmail.com>
parents: 11278
diff changeset
380 $frame = Gtk2::Frame->new(\'Gtk Test Frame\');
5c3a0e641520 [gaim-migrate @ 13603]
John H. Kelm <johnkelm@gmail.com>
parents: 11278
diff changeset
381 $button = Gtk2::Button->new(\'Print Message\');
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
382
11377
5c3a0e641520 [gaim-migrate @ 13603]
John H. Kelm <johnkelm@gmail.com>
parents: 11278
diff changeset
383 $frame->set_border_width(10);
5c3a0e641520 [gaim-migrate @ 13603]
John H. Kelm <johnkelm@gmail.com>
parents: 11278
diff changeset
384 $button->set_border_width(150);
5c3a0e641520 [gaim-migrate @ 13603]
John H. Kelm <johnkelm@gmail.com>
parents: 11278
diff changeset
385 $button->signal_connect("clicked" => \&button_cb, "Message Text");
5c3a0e641520 [gaim-migrate @ 13603]
John H. Kelm <johnkelm@gmail.com>
parents: 11278
diff changeset
386 $frame->add($button);
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
387
11377
5c3a0e641520 [gaim-migrate @ 13603]
John H. Kelm <johnkelm@gmail.com>
parents: 11278
diff changeset
388 $button->show();
5c3a0e641520 [gaim-migrate @ 13603]
John H. Kelm <johnkelm@gmail.com>
parents: 11278
diff changeset
389 $frame->show();
5c3a0e641520 [gaim-migrate @ 13603]
John H. Kelm <johnkelm@gmail.com>
parents: 11278
diff changeset
390
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
391 return $frame;
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
392 }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
393 @endcode
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
394
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
395 @section request-api Request Dialog Box API
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
396
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
397 The @c Gaim::Request package allows for plugins to have interactive dialog boxes without the need for creating them in Gtk creating a seperation between the user interfaace and the plugin. The portion of the Request API available to perl scripts is listed below followed by an example illustrating their use.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
398
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
399 These arguments are the same for each of the three request types:
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
400 @arg @em handle - The plugin handle.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
401 @arg @em title - String title for the dialog.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
402 @arg @em primary - The first sub-heading.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
403 @arg @em secondary - The second sub-heading.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
404 @arg @em ok_text - The Text for the OK button.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
405 @arg @em ok_cb - The string name of the perl subroutine to call when the OK button is clicked.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
406 @arg @em cancel_text - The text for the Cancel button.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
407 @arg @em cancel_cb - The string name of the perl subroutine to call when the Cancel button is clicked.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
408 @arg @em default_value - Default text string to display in the input box.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
409 @arg @em multiline - Boolean where true indicates multiple line input boxes are allowed.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
410 @arg @em masked - Boolean indicating if the user can edit the text.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
411 @arg @em hint - See source for more information - can be left blank.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
412 @arg @em filename - String defualt file name value.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
413 @arg @em savedialog - Boolean where true indicates use as a save file dialog and false indicates an open file dialog.
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
414
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
415 @code
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
416 # Create a simple text input box
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
417 Gaim::Request::input(handle, title, primary, secondary, default_value, multiline, masked, hint, ok_text, ok_cb, cancel_text, cancel_cb);
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
418
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
419 # Propt user to select a file
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
420 Gaim::Request::file(handle, title, filename, savedialog, ok_cb, cancel_cb);
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
421
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
422 # Create a unique input dialog as shown in the following example
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
423 Gaim::Request::fields(handle, title, primary, secondary, fields, ok_text, ok_cb, cancel_text, cancel_cb);
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
424 @endcode
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
425
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
426 What follows is an example of a @c Gaim::Request::fields() dialog box with two callbacks for an OK button and a Cancel Button.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
427
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
428 @code
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
429 sub ok_cb_test{
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
430 # The $fields is passed to the callback function when the button is clicked.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
431 # To get the values they must be extracted from $fields by name.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
432 $fields = shift;
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
433 $account = Gaim::Request::fields_get_account($fields, "acct_test");
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
434 $int = Gaim::Request::fields_get_integer($fields, "int_test");
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
435 $choice = Gaim::Request::fields_get_choice($fields, "ch_test");
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
436 }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
437
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
438 sub cancel_cb_test{
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
439 # Cancel does nothing but is symmetric to the ok_cb_test
6602
76683fe3c96d [gaim-migrate @ 7126]
Christian Hammond <chipx86@chipx86.com>
parents: 6598
diff changeset
440 }
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
441
6602
76683fe3c96d [gaim-migrate @ 7126]
Christian Hammond <chipx86@chipx86.com>
parents: 6598
diff changeset
442 sub plugin_load {
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
443 my $plugin = shift;
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
444
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
445 # Create a group to pool together mutltiple fields.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
446 $group = Gaim::Request::field_group_new("Group Name");
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
447
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
448 # Each fields is created with Gaim::Request::*_new(), is made viewable with Gaim::Request::field_*_set_show_all()
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
449 # and is then added to the group with Gaim::Request::field_group_add_field()
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
450
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
451 # Add an account drop down list showing all active accounts
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
452 $field = Gaim::Request::field_account_new("acct_test", "Account Text", undef);
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
453 Gaim::Request::field_account_set_show_all($field, 0);
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
454 Gaim::Request::field_group_add_field($group, $field);
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
455
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
456 # Add an integer input box
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
457 $field = Gaim::Request::field_int_new("int_test", "Integer Text", 33);
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
458 Gaim::Request::field_group_add_field($group, $field);
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
459
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
460 # Add a list of choices
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
461 $field = Gaim::Request::field_choice_new("ch_test", "Choice Text", 1);
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
462 Gaim::Request::field_choice_add($field, "Choice 0");
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
463 Gaim::Request::field_choice_add($field, "Choice 1");
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
464 Gaim::Request::field_choice_add($field, "Choice 2");
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
465
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
466 Gaim::Request::field_group_add_field($group, $field);
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
467
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
468 # Create a Gaim::Request and add the group that was just created.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
469 $request = Gaim::Request::fields_new();
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
470 Gaim::Request::fields_add_group($request, $group);
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
471
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
472 # Display the dialog box with the input fields added earlier with the appropriate titles.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
473 Gaim::Request::fields(
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
474 $plugin,
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
475 "Request Title!",
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
476 "Primary Title",
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
477 "Secondary Title",
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
478 $request,
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
479 "Ok Text", "ok_cb_test",
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
480 "Cancel Text", "cancel_cb_test");
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
481 }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
482 @endcode
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
483
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
484 @section timeout-cb Misc: Plugin Actions, Timeouts and Callbacks
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
485
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
486 This section of the manual covers some of the more important features that can be added to Gaim perl Plugins. Plugin actions are callback functions that are accessible to the user from the Gaim main window under "Tools->Plugin Actions". Timeouts allow a plugin to exectue a perl subroutine after a given period of time. Note that timeouts only occur once, so if the timeout must occur periodically just add a new timeout at the end of the timeout callback function. Callbacks are functions that are called when an event occurs such as a buddy signing-on or a message being received. These three tools will be discussed in the following three examples.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
487
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
488 The Plugin Action requires the @c \%PLUGIN_INFO hash to have two key/value pairs added and a callback perl subroutine defined. Note the difference between the C API that allows for a GList of actions--only one plugin action is allowed in Gaim perl plugins.
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
489
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
490 @code
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
491 %PLUGIN_INFO = {
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
492 ...,
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
493 # The callback subroutine that is called when "Tools->Plugin Action->Plugin Action Label" is selected
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
494 plugin_action => "plugin_action_cb",
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
495 plugin_action_label => "Plugin Action Label"
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
496 }
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
497
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
498 sub plugin_action_cb {
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
499 # Note the function receives the plugin handle as its argument
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
500 $plugin = shift;
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
501 print "Plugin Action Selected.\n";
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
502 }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
503 @endcode
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
504
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
505 Timeouts allow a perl subroutine to be exectued after a specified time. They only occur once, so as stated earlier the timeout must be reregistered after every time it is called.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
506
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
507 @code
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
508 sub timeout_cb {
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
509 my $plugin = shift;
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
510 print "Timeout occured.";
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
511
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
512 # Reschedule timeout
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
513 Gaim::timeout_add($plugin, 10, \&timeout_cb, $plugin);
6602
76683fe3c96d [gaim-migrate @ 7126]
Christian Hammond <chipx86@chipx86.com>
parents: 6598
diff changeset
514 }
6603
21084026030b [gaim-migrate @ 7127]
Christian Hammond <chipx86@chipx86.com>
parents: 6602
diff changeset
515
6602
76683fe3c96d [gaim-migrate @ 7126]
Christian Hammond <chipx86@chipx86.com>
parents: 6598
diff changeset
516 sub plugin_load {
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
517 $plugin = shift;
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
518
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
519 # Schedule a timeout for ten seconds from now
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
520 Gaim::timeout_add($plugin, 10, \&timeout_cb, $plugin);
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
521 }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
522 @endcode
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
523
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
524 Callbacks are handled by creating a perl subroutine to serve as the callback and then attaching the callback to a signal. To use callbacks it is necessary to first obtain the plugin handle with the @c Gaim::Plugin::get_handle() subroutine to pass as an argument for the callback.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
525
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
526 @code
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
527 sub signal_cb {
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
528 # The handle and the user data come in as arguments
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
529 my ($handle, $data) = @_;
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
530 print "User just connected.";
6602
76683fe3c96d [gaim-migrate @ 7126]
Christian Hammond <chipx86@chipx86.com>
parents: 6598
diff changeset
531 }
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
532
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
533 sub plugin_load {
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
534 $plugin = shift;
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
535
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
536 # User data to be given as an argument to the callback perl subroutine.
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
537 $data = "";
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
538
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
539 # A pointer to the actual plugin handle needed by the callback function
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
540 $plugin_handle = Gaim::Accounts::get_handle();
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
541
11278
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
542 # Connect the perl subroutine 'signal_cb' to the event 'account-connecting'
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
543 Gaim::signal_connect($plugin_handle, "account-connecting", $plugin, \&signal_cb, $data);
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
544 }
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
545 @endcode
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
546
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
547 @section Resources
93258e8fb6d2 [gaim-migrate @ 13470]
John H. Kelm <johnkelm@gmail.com>
parents: 10814
diff changeset
548 @see API Documentation
6602
76683fe3c96d [gaim-migrate @ 7126]
Christian Hammond <chipx86@chipx86.com>
parents: 6598
diff changeset
549
6598
2f6850c7d980 [gaim-migrate @ 7122]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
550 */