Mercurial > pidgin
comparison libpurple/plugins/perl/scripts/plugin_pref.pl @ 23618:fb86dbeb2b15
Add support to the Perl plugin loader for listing for pref changes.
The Prefs Functions Test plugin (plugin_pref.pl) includes an example.
Fixes #6383
| author | Daniel Atallah <daniel.atallah@gmail.com> |
|---|---|
| date | Wed, 30 Jul 2008 03:51:26 +0000 |
| parents | 2f8274ce570a |
| children | 0646207f360f |
comparison
equal
deleted
inserted
replaced
| 23617:f5e614bc6606 | 23618:fb86dbeb2b15 |
|---|---|
| 42 | 42 |
| 43 | 43 |
| 44 $ppref = Purple::PluginPref->new_with_name_and_label( | 44 $ppref = Purple::PluginPref->new_with_name_and_label( |
| 45 "/plugins/core/perl_test/choice", "Choice Preference"); | 45 "/plugins/core/perl_test/choice", "Choice Preference"); |
| 46 $ppref->set_type(1); | 46 $ppref->set_type(1); |
| 47 $ppref->add_choice("ch0", $frame); | 47 $ppref->add_choice("ch0", "ch0-val"); |
| 48 $ppref->add_choice("ch1", $frame); | 48 $ppref->add_choice("ch1", "ch1-val"); |
| 49 $frame->add($ppref); | 49 $frame->add($ppref); |
| 50 | 50 |
| 51 $ppref = Purple::PluginPref->new_with_name_and_label( | 51 $ppref = Purple::PluginPref->new_with_name_and_label( |
| 52 "/plugins/core/perl_test/text", "Text Box Preference"); | 52 "/plugins/core/perl_test/text", "Text Box Preference"); |
| 53 $ppref->set_max_length(16); | 53 $ppref->set_max_length(16); |
| 54 $frame->add($ppref); | 54 $frame->add($ppref); |
| 55 | 55 |
| 56 return $frame; | 56 return $frame; |
| 57 } | 57 } |
| 58 | 58 |
| 59 sub pref_cb { | |
| 60 my ($pref, $type, $value, $data) = @_; | |
| 61 | |
| 62 print "pref changed: [$pref]($type)=$value data=$data\n"; | |
| 63 } | |
| 64 | |
| 59 sub plugin_init { | 65 sub plugin_init { |
| 60 | 66 |
| 61 return %PLUGIN_INFO; | 67 return %PLUGIN_INFO; |
| 62 } | 68 } |
| 63 | |
| 64 | 69 |
| 65 # This is the sub defined in %PLUGIN_INFO to be called when the plugin is loaded | 70 # This is the sub defined in %PLUGIN_INFO to be called when the plugin is loaded |
| 66 # Note: The plugin has a reference to itself on top of the argument stack. | 71 # Note: The plugin has a reference to itself on top of the argument stack. |
| 67 sub plugin_load { | 72 sub plugin_load { |
| 68 my $plugin = shift; | 73 my $plugin = shift; |
| 73 | 78 |
| 74 Purple::Prefs::add_none("/plugins/core/perl_test"); | 79 Purple::Prefs::add_none("/plugins/core/perl_test"); |
| 75 Purple::Prefs::add_bool("/plugins/core/perl_test/bool", 1); | 80 Purple::Prefs::add_bool("/plugins/core/perl_test/bool", 1); |
| 76 Purple::Prefs::add_string("/plugins/core/perl_test/choice", "ch1"); | 81 Purple::Prefs::add_string("/plugins/core/perl_test/choice", "ch1"); |
| 77 Purple::Prefs::add_string("/plugins/core/perl_test/text", "Foobar"); | 82 Purple::Prefs::add_string("/plugins/core/perl_test/text", "Foobar"); |
| 78 | 83 |
| 84 Purple::Prefs::connect_callback($plugin, "/plugins/core/perl_test", \&pref_cb, "none"); | |
| 85 Purple::Prefs::connect_callback($plugin, "/plugins/core/perl_test/bool", \&pref_cb, "bool"); | |
| 86 Purple::Prefs::connect_callback($plugin, "/plugins/core/perl_test/choice", \&pref_cb, "choice"); | |
| 87 Purple::Prefs::connect_callback($plugin, "/plugins/core/perl_test/text", \&pref_cb, "text"); | |
| 79 | 88 |
| 80 print "\n\n" . "#" x 80 . "\n\n"; | 89 print "\n\n" . "#" x 80 . "\n\n"; |
| 81 } | 90 } |
| 82 | 91 |
| 83 sub plugin_unload { | 92 sub plugin_unload { |
