use strict;
use Irssi;
use HTML::Entities;
use Glib::Object::Introspection; use Encode;
our $VERSION = '1.0.1';
our %IRSSI = (
authors => 'Felipe F. Tonello',
contact => 'eu@felipetonello.com',
name => 'desktop-notify',
description => 'Sends notification using the Desktop Notifications Specification.',
license => 'GPL v3+',
);
my $notify_icon;
my $term_charset;
my $help = '
/set notify_icon <icon-name>
Change notificationicon (default is mail-message-new). A complete list of standard ' .
'icons can be found here: ' .
'http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html#names
';
sub init {
Glib::Object::Introspection->setup(
basename => 'Notify',
version => '0.7',
package => 'Notify');
Notify::init('Irssi');
}
sub UNLOAD {
Notify::uninit();
}
sub setup_changed {
$notify_icon = Irssi::settings_get_str('notify_icon');
$term_charset = Irssi::settings_get_str('term_charset');
}
sub priv_msg {
my ($server, $msg, $nick, $address) = @_;
my $window = Irssi::active_win();
if ($window->{active}->{name} eq $nick) {
return;
}
my $msg = HTML::Entities::encode_entities(Irssi::strip_codes($msg), "\<>&'");
my $network = $server->{tag};
my $noti = Notify::Notification->new($nick . '@' . $network, decode($term_charset, $msg), $notify_icon);
$noti->show();
}
sub hilight {
my ($dest, $text, $stripped) = @_;
my $server = $dest->{server};
my $window = Irssi::active_win();
if (!($server &&
$dest->{level} & (MSGLEVEL_HILIGHT | MSGLEVEL_NOTICES) &&
$server->ischannel($dest->{target}) &&
$window->{refnum} != $dest->{window}->{refnum})) {
return;
}
my $network = $server->{tag};
my $msg = HTML::Entities::encode_entities($stripped, "\'<>&");
my $noti = Notify::Notification->new($dest->{target} . '@' . $network, decode($term_charset, $msg), $notify_icon);
$noti->show();
}
Irssi::settings_add_str('desktop-notify', 'notify_icon', 'mail-message-new');
Irssi::signal_add('setup changed' => \&setup_changed);
Irssi::signal_add_last('message private' => \&priv_msg);
Irssi::signal_add_last('print text' => \&hilight);
Irssi::command_bind('help', sub {
if ($_[0] eq $IRSSI{name}) {
Irssi::print($help, MSGLEVEL_CLIENTCRAP);
Irssi::signal_stop();
}
}
);
init();
setup_changed();