| 1 |
package Plagger::Plugin::Notify::Balloon; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use base qw( Plagger::Plugin ); |
|---|
| 4 |
|
|---|
| 5 |
our $VERSION = '0.01'; |
|---|
| 6 |
|
|---|
| 7 |
use File::Spec; |
|---|
| 8 |
use Encode (); |
|---|
| 9 |
|
|---|
| 10 |
sub register { |
|---|
| 11 |
my($self, $context) = @_; |
|---|
| 12 |
|
|---|
| 13 |
if ($^O eq 'MSWin32') { |
|---|
| 14 |
if ($self->has_balloon_notify) { |
|---|
| 15 |
$context->register_hook( |
|---|
| 16 |
$self, |
|---|
| 17 |
'publish.entry' => \¬ify, |
|---|
| 18 |
'plugin.init' => \&initialize, |
|---|
| 19 |
); |
|---|
| 20 |
} else { |
|---|
| 21 |
$context->log(error => "BalloonNotify is not in your PATH."); |
|---|
| 22 |
} |
|---|
| 23 |
} else { |
|---|
| 24 |
$context->log(error => "This plugin only works on Win32 systems"); |
|---|
| 25 |
} |
|---|
| 26 |
} |
|---|
| 27 |
|
|---|
| 28 |
sub has_balloon_notify { |
|---|
| 29 |
my $self = shift; |
|---|
| 30 |
grep { -e File::Spec->catfile($_, 'BalloonNotify.exe') } File::Spec->path; |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
sub initialize { |
|---|
| 34 |
my($self, $context) = @_; |
|---|
| 35 |
|
|---|
| 36 |
return if $self->conf->{encoding}; |
|---|
| 37 |
|
|---|
| 38 |
my $cp = eval { |
|---|
| 39 |
require Win32::Console; |
|---|
| 40 |
Win32::Console::OutputCP(); |
|---|
| 41 |
}; |
|---|
| 42 |
$cp ||= 932; |
|---|
| 43 |
$self->conf->{encoding} = "cp$cp"; |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
sub notify { |
|---|
| 47 |
my($self, $context, $args) = @_; |
|---|
| 48 |
|
|---|
| 49 |
my $title = $self->scrub($args->{entry}->title); |
|---|
| 50 |
my $message = $self->scrub($args->{entry}->body_text); |
|---|
| 51 |
|
|---|
| 52 |
my @command = ('BalloonNotify', '/o', 5, '/t', $title, '/c', $message); |
|---|
| 53 |
!system(@command) or $context->log(error => $?); |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
sub scrub { |
|---|
| 57 |
my($self, $string) = @_; |
|---|
| 58 |
$string =~ s/\s+/ /g; |
|---|
| 59 |
Encode::encode($self->conf->{encoding}, $string); |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
1; |
|---|
| 63 |
|
|---|
| 64 |
__END__ |
|---|
| 65 |
|
|---|
| 66 |
=head1 NAME |
|---|
| 67 |
|
|---|
| 68 |
Plagger::Plugin::Notify::Balloon - Notify feed updates using Win32 BalloonNotify |
|---|
| 69 |
|
|---|
| 70 |
=head1 SYNOPSIS |
|---|
| 71 |
|
|---|
| 72 |
- module: Notify::Balloon |
|---|
| 73 |
|
|---|
| 74 |
=head1 DESCRIPTION |
|---|
| 75 |
|
|---|
| 76 |
This plugin uses Windows Balloon notification system to notify feed |
|---|
| 77 |
updates to users. |
|---|
| 78 |
|
|---|
| 79 |
You need to install BalloonNotify.exe command line tool from |
|---|
| 80 |
L<http://www.gertrud.jp/soft/balloonnotify.html>. |
|---|
| 81 |
|
|---|
| 82 |
=head1 TODO |
|---|
| 83 |
|
|---|
| 84 |
=over 4 |
|---|
| 85 |
|
|---|
| 86 |
=item Rewrite using Win32::GUI |
|---|
| 87 |
|
|---|
| 88 |
=back |
|---|
| 89 |
|
|---|
| 90 |
=head1 AUTHOR |
|---|
| 91 |
|
|---|
| 92 |
Tatsuhiko Miyagawa |
|---|
| 93 |
|
|---|
| 94 |
Original code was taken from http://yaplog.jp/sumikko/archive/34 |
|---|
| 95 |
|
|---|
| 96 |
=head1 SEE ALSO |
|---|
| 97 |
|
|---|
| 98 |
L<Plagger> |
|---|
| 99 |
|
|---|
| 100 |
=cut |
|---|