comparison doc/PERL-HOWTO.dox @ 12340:11d14efe7be2

[gaim-migrate @ 14644] sf patch #1373208, from Will Thompson "In Perl, we have Gaim::Conversation objects. However, all the functions that take Gaim::Conversations as the first argument are in the Gaim::Conv package. This makes the following not work: my $conv = Gaim::Conv::new(); $conv->get_features(); Instead, one has to do the following: my $conv = Gaim::Conv::new(); Gaim::Conv::get_features($conv);" committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 05 Dec 2005 03:53:00 +0000
parents 9563b768e8e2
children 6fd82071a7b8
comparison
equal deleted inserted replaced
12339:fdac1c5e6c68 12340:11d14efe7be2
170 170
171 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. 171 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.
172 172
173 @section conv-api Conversation API 173 @section conv-api Conversation API
174 174
175 The Gaim perl API for @c gaim_conversation_ and @c gaim_conv_window_ allow plugins to interact with open conversations, create new conversations, and modify conversations at will. The following example again replaces the @c plugin_load subroutine. In the example script, a new window is created, displayed and a new conversation instant message is created. The @c Gaim::Conv::Chat package handles the @c gaim_conv_chat_ portion of the API very similarly to the examples that follow. 175 The Gaim perl API for @c gaim_conversation_ and @c gaim_conv_window_ allow
176 176 plugins to interact with open conversations, create new conversations, and
177 @code 177 modify conversations at will. The following example again replaces the @c
178 sub plugin_load { 178 plugin_load subroutine. In the example script, a new window is created,
179 my $plugin = shift; 179 displayed and a new conversation instant message is created. The @c
180 my $protocol = "prpl-oscar"; 180 Gaim::Conversation::Chat package handles the @c gaim_conv_chat_ portion of the
181 181 API very similarly to the examples that follow.
182 $account = Gaim::Accounts::find("USERNAME", $protocol); 182
183 @code
184 sub plugin_load {
185 my $plugin = shift;
186 my $protocol = "prpl-oscar";
187
188 $account = Gaim::Accounts::find("USERNAME", $protocol);
183 189
184 # First we create two new conversations. 190 # First we create two new conversations.
185 print "Testing Gaim::Conv::new()..."; 191 print "Testing Gaim::Conversation::new()...";
186 $conv1 = Gaim::Conv::new(1, $account, "Test Conv. 1"); 192 $conv1 = Gaim::Conversation::new(1, $account, "Test Conversation 1");
187 if ($conv1) { print "ok.\n"; } else { print "fail.\n"; } 193 if ($conv1) { print "ok.\n"; } else { print "fail.\n"; }
188 194
189 print "Testing Gaim::Conv::new()..."; 195 print "Testing Gaim::Conversation::new()...";
190 $conv2 = Gaim::Conv::new(1, $account, "Test Conv. 2"); 196 $conv2 = Gaim::Conversation::new(1, $account, "Test Conversation 2");
191 if ($conv2) { print "ok.\n"; } else { print "fail.\n"; } 197 if ($conv2) { print "ok.\n"; } else { print "fail.\n"; }
192 198
193 # Second we create a window to display the conversations in. 199 # Second we create a window to display the conversations in.
194 # Note that the package here is Gaim::Conv::Window 200 # Note that the package here is Gaim::Conversation::Window
195 print "Testing Gaim::Conv::Window::new()...\n"; 201 print "Testing Gaim::Conversation::Window::new()...\n";
196 $win = Gaim::Conv::Window::new(); 202 $win = Gaim::Conversation::Window::new();
197 203
198 # The third thing to do is to add the two conversations to the windows. 204 # The third thing to do is to add the two conversations to the windows.
199 # The subroutine add_conversation() returns the number of conversations present in the window. 205 # The subroutine add_conversation() returns the number of conversations
200 print "Testing Gaim::Conv::Window::add_conversation()..."; 206 # present in the window.
201 $conv_count = Gaim::Conv::Window::add_conversation($win, $conv1); 207 print "Testing Gaim::Conversation::Window::add_conversation()...";
202 if ($conv_count) { print "ok..." . $conv_count . " conversations...\n"; } else { print "fail.\n"; } 208 $conv_count = $conv1->add_conversation();
203 209 if ($conv_count) {
204 print "Testing Gaim::Conv::Window::add_conversation()..."; 210 print "ok..." . $conv_count . " conversations...\n";
205 $conv_count = Gaim::Conv::Window::add_conversation($win, $conv2); 211 } else {
206 if ($conv_count) { print "ok..." . $conv_count . " conversations...\n"; } else { print "fail.\n"; } 212 print "fail.\n";
213 }
214
215 print "Testing Gaim::Conversation::Window::add_conversation()...";
216 $conv_count = $win->add_conversation($conv2);
217 if ($conv_count) {
218 print "ok..." . $conv_count . " conversations...\n";
219 } else {
220 print "fail.\n";
221 }
207 222
208 # Now the window is displayed to the user. 223 # Now the window is displayed to the user.
209 print "Testing Gaim::Conv::Window::show()...\n"; 224 print "Testing Gaim::Conversation::Window::show()...\n";
210 Gaim::Conv::Window::show($win); 225 $win->show();
211 226
212 # Use Gaim::Conv::get_im_data to get a handle for the conversation 227 # Use get_im_data() to get a handle for the conversation
213 print "Testing Gaim::Conv::get_im_data()...\n"; 228 print "Testing Gaim::Conversation::get_im_data()...\n";
214 $im = Gaim::Conv::get_im_data($conv1); 229 $im = $conv1->get_im_data();
215 if ($im) { print "ok.\n"; } else { print "fail.\n"; } 230 if ($im) { print "ok.\n"; } else { print "fail.\n"; }
216 231
217 # Here we send messages to the conversation 232 # Here we send messages to the conversation
218 print "Testing Gaim::Conv::IM::send()...\n"; 233 print "Testing Gaim::Conversation::IM::send()...\n";
219 Gaim::Conv::IM::send($im, "Message Test."); 234 $im->send("Message Test.");
220 235
221 print "Testing Gaim::Conv::IM::write()...\n"; 236 print "Testing Gaim::Conversation::IM::write()...\n";
222 Gaim::Conv::IM::write($im, "SENDER", "<b>Message</b> Test.", 0, 0); 237 $im->write("SENDER", "<b>Message</b> Test.", 0, 0);
223 } 238 }
224 @endcode 239 @endcode
225 240
226 The next block of code shows how a script can close a known conversation window @c $win. 241 The next block of code shows how a script can close a known conversation window
227 242 @c $win.
228 @code 243
229 print "Testing Gaim::Conv::Window::get_conversation_count()...\n"; 244 @code
230 $conv_count = Gaim::Conv::Window::get_conversation_count($win); 245 print "Testing Gaim::Conversation::Window::get_conversation_count()...\n";
231 if ($conv_count > 0) { 246 $conv_count = $win->get_conversation_count();
232 print "Testing Gaim::Conv::Window::destroy()...\n"; 247 print "...and it returned $conv_count.\n";
233 Gaim::Conv::Window::destroy($win); 248 if ($conv_count > 0) {
234 } 249 print "Testing Gaim::Conversation::Window::destroy()...\n";
250 $win->destroy();
251 }
235 @endcode 252 @endcode
236 253
237 @section plugin-pref-api Plugin Preference and Gtk Preference API 254 @section plugin-pref-api Plugin Preference and Gtk Preference API
238 255
239 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. 256 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.