123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- From e84e1f23168ebfb51fc73c272061c295ed9952d8 Mon Sep 17 00:00:00 2001
- From: intrigeri <intrigeri@boum.org>
- Date: Sun, 8 Mar 2015 23:22:02 +0000
- Subject: [PATCH] Add support for a user-defined function to be called whenever
- an action is invoked.
- ---
- lib/Desktop/Notify.pm | 30 +++++++++++++++++++++++++++++-
- lib/Desktop/Notify/Notification.pm | 18 +++++++++++-------
- 2 files changed, 40 insertions(+), 8 deletions(-)
- diff --git a/lib/Desktop/Notify.pm b/lib/Desktop/Notify.pm
- index b8bb248..78f31d4 100644
- --- a/usr/share/perl5/Desktop/Notify.pm
- +++ b/usr/share/perl5/Desktop/Notify.pm
- @@ -106,6 +106,8 @@ sub new {
- $self->{app_name} = $opts{app_name} || basename($0);
- $self->{notify}->connect_to_signal('NotificationClosed',
- sub {$self->_close_cb(@_)});
- + $self->{notify}->connect_to_signal('ActionInvoked',
- + sub {$self->_action_cb(@_)});
-
- bless $self, $class;
- }
- @@ -140,6 +142,17 @@ sub _close_cb {
- delete $self->{notes}->{$nid};
- }
-
- +sub _action_cb {
- + my ($self, $nid, $action_key) = @_;
- + print __PACKAGE__, ": action invoked\n";
- + if ($self->{action_callback})
- + {
- + print "invoking callback\n";
- + $self->{action_callback}->($self->{notes}->{$nid}, $action_key);
- + }
- + # delete $self->{notes}->{$nid};
- +}
- +
- =head2 close_callback $coderef
-
- Sets a user-specified function to be called whenever a notification is closed.
- @@ -151,10 +164,25 @@ just closed.
- sub close_callback {
- my ($self, $cb) = @_;
-
- - print "callback is $cb\n";
- + print "close callback is $cb\n";
- $self->{close_callback} = $cb;
- }
-
- +=head2 action_callback $coderef
- +
- +Sets a user-specified function to be called whenever an action is invoked.
- +It will be called with two arguments, which are the Notification object on which
- +an action was invoked, and the key of the action invoked.
- +
- +=cut
- +
- +sub action_callback {
- + my ($self, $cb) = @_;
- +
- + print "action callback is $cb\n";
- + $self->{action_callback} = $cb;
- +}
- +
- =head1 AUTHOR
-
- Stephen Cavilia, C<< <sac at atomicradi.us> >>
- diff --git a/lib/Desktop/Notify/Notification.pm b/lib/Desktop/Notify/Notification.pm
- index ee3fe4a..e7710e8 100644
- --- a/usr/share/perl5/Desktop/Notify/Notification.pm
- +++ b/usr/share/perl5/Desktop/Notify/Notification.pm
- @@ -59,6 +59,7 @@ sub new {
- my $self = \%params;
- $self->{server} = $server;
- $self->{id} = undef;
- + $self->{actions} ||= {};
- bless $self, $class;
- }
-
- @@ -81,7 +82,7 @@ sub show {
- '',
- $self->{summary},
- $self->{body},
- - [],
- + [%{$self->{actions}}],
- {},
- $self->{timeout} || 0,
- );
- @@ -125,6 +126,15 @@ The summary text briefly describing the notification.
-
- The optional detailed body text. Can be empty.
-
- +=item actions
- +
- +Actions are sent over as a list of pairs. Each even element in the list
- +(starting at index 0) represents the identifier for the action. Each odd
- +element in the list is the localized string that will be displayed to the user.
- +
- +A user-specified function to be called whenever an action is invoked can be
- +specified with L<Desktop::Notify>'s L<action_callback> method.
- +
- =item timeout
-
- The timeout time in milliseconds since the display of the notification at which
- @@ -145,12 +155,6 @@ supported by L<Desktop::Notify> at this time
-
- The optional program icon of the calling application.
-
- -=item actions
- -
- -Actions are sent over as a list of pairs. Each even element in the list
- -(starting at index 0) represents the identifier for the action. Each odd
- -element in the list is the localized string that will be displayed to the user.
- -
- =item hints
-
- Optional hints that can be passed to the server from the client program.
- --
- 2.1.4
|