summaryrefslogtreecommitdiffstats
path: root/config/chroot_local-patches/Desktop-Notify:_0001-support_notification_actions.patch
blob: 7d41d92bf1d089129b42a7a4aead53d3e2208ed3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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