Desktop-Notify-0.05/0000755000175000017500000000000012525466436013370 5ustar stevesteveDesktop-Notify-0.05/lib/0000755000175000017500000000000012525466436014136 5ustar stevesteveDesktop-Notify-0.05/lib/Desktop/0000755000175000017500000000000012525466436015547 5ustar stevesteveDesktop-Notify-0.05/lib/Desktop/Notify.pm0000644000175000017500000001360012525466263017353 0ustar stevestevepackage Desktop::Notify; use warnings; use strict; use Net::DBus; use File::Basename; use Data::Dumper; use Desktop::Notify::Notification; =head1 NAME Desktop::Notify - Communicate with the Desktop Notifications framework =head1 VERSION Version 0.04 =cut our $VERSION = '0.05'; =head1 SYNOPSIS use Desktop::Notify; # Open a connection to the notification daemon my $notify = Desktop::Notify->new(); # Create a notification to display my $notification = $notify->create(summary => 'Desktop::Notify', body => 'Hello, world!', timeout => 5000); # Display the notification $notification->show(); # Close the notification later $notification->close(); =head1 DESCRIPTION This module provides a Perl interface to the Desktop Notifications framework. The framework allows applications to display pop-up notifications on an X desktop. This is implemented with two components: a daemon that displays the notifications, and a client library used by applications to send notifications to the daemon. These components communicate through the DBus message bus protocol. More information is available from L This module serves the same purpose as C, in an object-oriented Perl interface. It is not, however, an interface to C itself, but a separate implementation of the specification using L. =head1 METHODS =head2 new %opts Connect to the notification daemon. %opts can include the following options: =over =item app_name The application name to use for notifications. Default is C =item app_icon Path to an image to use for notification icons. =item bus The Net::DBus mesage bus to use. Default is to call Net::DBus->session, which is usually where notification-daemon can be reached. =item service The DBus service name of the daemon. Default is I. =item objpath The path to the notifications DBus object. Default is I. =item objiface The DBus interface to access the notifications object as. Default is I. =back =cut sub new { my ($class, %opts) = @_; my $self = {}; $self->{bus} = $opts{bus} || Net::DBus->session; $self->{service} = $self->{bus} ->get_service($opts{service} || 'org.freedesktop.Notifications'); $self->{notify} = $self->{service} ->get_object($opts{objpath} || '/org/freedesktop/Notifications', $opts{objiface} || 'org.freedesktop.Notifications'); $self->{app_name} = $opts{app_name} || basename($0); $self->{app_icon} = $opts{app_icon} || ''; $self->{notify}->connect_to_signal('NotificationClosed', sub {$self->_close_cb(@_)}); $self->{notify}->connect_to_signal('ActionInvoked', sub {$self->_action_cb(@_)}); bless $self, $class; } =head2 create %params Creates a new notification object that can be displayed later. This will return a L object; see that module for information about using it. =cut sub create { my ($self, %params) = @_; return new Desktop::Notify::Notification($self, %params); } sub _register_notification { my ($self, $n) = @_; $self->{notes}->{$n->{id}} = $n; } sub _close_cb { my ($self, $nid) = @_; print __PACKAGE__, ": notification closed\n"; if ($self->{close_callback}) { print "invoking callback\n"; $self->{close_callback}->($self->{notes}->{$nid}); } 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. It will be called with one argument, which is the Notification object that was just closed. =cut sub close_callback { my ($self, $cb) = @_; 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<< >> =head1 SEE ALSO L L L =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc Desktop::Notify You can also look for information at: =over 4 =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * RT: CPAN's request tracker L =item * Search CPAN L =back =head1 ACKNOWLEDGEMENTS =head1 COPYRIGHT & LICENSE Copyright 2007 Stephen Cavilia, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # End of Desktop::Notify Desktop-Notify-0.05/lib/Desktop/Notify/0000755000175000017500000000000012525466436017017 5ustar stevesteveDesktop-Notify-0.05/lib/Desktop/Notify/Notification.pm0000644000175000017500000000750512525465113022001 0ustar stevestevepackage Desktop::Notify::Notification; use strict; use warnings; use base qw/Class::Accessor/; Desktop::Notify::Notification->mk_accessors(qw/summary body timeout/); =head1 NAME Desktop::Notify::Notification - a notification object for the desktop notifications framework =head1 VERSION Version 0.03 =cut our $VERSION = '0.03'; =head1 SYNOPSIS # $notify is an existing Desktop::Notify object my $note = $notify->create(summary => 'Rebuilding FooBar', body => 'Progress: 10%'); $note->show; ... # Update the notification later $note->body('Progress: 20%'); $note->show; ... # Take it off the screen $note->close; =head1 DESCRIPTION Desktop notification objects are represented as objects of this class. They are created by a L object. Displaying, closing, and modifying the notification is done by using methods in this class. =head1 METHODS =head2 new $notify, %params This is called internally by L to create a new notification object. =cut sub new { my ($class, $server, %params) = @_; my $self = \%params; $self->{server} = $server; $self->{id} = undef; $self->{actions} ||= {}; $self->{hints} ||= {}; bless $self, $class; } =head2 show Display the notification on the screen. If this notification had previously been shown and not closed yet, it will replace the existing notification. Show can be called multiple times on the same notification, probably with attribute changes between calls, and later show calls will cause the server to seamlessly replace the existing notification. =cut sub show { my $self = shift; $self->{id} = $self->{server}->{notify} ->Notify($self->{server}->{app_name}, $self->{id} || 0, $self->{server}->{app_icon}, $self->{summary}, $self->{body}, [%{$self->{actions}}], $self->{hints}, $self->{timeout} || 0, ); $self->{server}->_register_notification($self); return $self; } =head2 close Close the notification if it is already being displayed. =cut sub close { my $self = shift; if (defined $self->{id}) { $self->{server}->{notify}->CloseNotification($self->{id}); delete $self->{id}; } else { warn "Trying to close notification that has not been shown."; } return $self; } =head1 ATTRIBUTES The following parameters can be set when creating the object or later modified using accessors (descriptions are from the specification at L) =over =item summary The summary text briefly describing the notification. =item body 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's L method. =item hints Optional hints that can be passed to the server from the client program. =back =over =item timeout The timeout time in milliseconds since the display of the notification at which the notification should automatically close. If -1, the notification's expiration time is dependent on the notification server's settings, and may vary for the type of notification. If 0, never expire. =back The following extra parameters are included in the specification but not supported by L at this time =over =item app_icon The optional program icon of the calling application. =back =cut 1; # End of Desktop::Notify::Notification Desktop-Notify-0.05/README0000644000175000017500000000160410616551263014241 0ustar stevesteveDesktop-Notify This module provides a Perl interface to the Desktop Notifications framework. INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install SUPPORT AND DOCUMENTATION After installing, you can find documentation for this module with the perldoc command. perldoc Desktop::Notify You can also look for information at: Search CPAN http://search.cpan.org/dist/Desktop-Notify CPAN Request Tracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=Desktop-Notify AnnoCPAN, annotated CPAN documentation: http://annocpan.org/dist/Desktop-Notify CPAN Ratings: http://cpanratings.perl.org/d/Desktop-Notify COPYRIGHT AND LICENCE Copyright (C) 2007 Stephen Cavilia This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Desktop-Notify-0.05/t/0000755000175000017500000000000012525466436013633 5ustar stevesteveDesktop-Notify-0.05/t/00-load.t0000644000175000017500000000023310616541035015136 0ustar stevesteve#!perl -T use Test::More tests => 1; BEGIN { use_ok( 'Desktop::Notify' ); } diag( "Testing Desktop::Notify $Desktop::Notify::VERSION, Perl $], $^X" ); Desktop-Notify-0.05/t/01-connect.t0000644000175000017500000000112612525466010015653 0ustar stevesteve#!perl -T use Test::More; unless ($ENV{DBUS_SESSION_BUS_ADDRESS}) { plan skip_all => 'D-Bus session bus not running'; exit 0; } plan tests => 3; use_ok('Desktop::Notify'); my $notify; eval { $notify = new Desktop::Notify }; ok($notify, 'connect with default options'); $notify = undef; eval { $notify = new Desktop::Notify (bus => Net::DBus->session, service => 'org.freedesktop.Notifications', objpath => '/org/freedesktop/Notifications', objiface => 'org.freedesktop.Notifications') }; ok($notify, 'connect with explicit options'); Desktop-Notify-0.05/t/pod.t0000644000175000017500000000036512525465374014606 0ustar stevesteve#!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; plan skip_all => "These tests are for author only" unless $ENV{AUTHOR_TESTING} or $ENV{RELEASE_TESTING}; all_pod_files_ok(); Desktop-Notify-0.05/t/pod-coverage.t0000644000175000017500000000042512525465434016371 0ustar stevesteve#!perl -T use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; plan skip_all => "These tests are for author only" unless $ENV{AUTHOR_TESTING} or $ENV{RELEASE_TESTING}; all_pod_coverage_ok(); Desktop-Notify-0.05/t/boilerplate.t0000644000175000017500000000232510616541035016310 0ustar stevesteve#!perl -T use strict; use warnings; use Test::More tests => 3; sub not_in_file_ok { my ($filename, %regex) = @_; open my $fh, "<", $filename or die "couldn't open $filename for reading: $!"; my %violated; while (my $line = <$fh>) { while (my ($desc, $regex) = each %regex) { if ($line =~ $regex) { push @{$violated{$desc}||=[]}, $.; } } } if (%violated) { fail("$filename contains boilerplate text"); diag "$_ appears on lines @{$violated{$_}}" for keys %violated; } else { pass("$filename contains no boilerplate text"); } } not_in_file_ok(README => "The README is used..." => qr/The README is used/, "'version information here'" => qr/to provide version information/, ); not_in_file_ok(Changes => "placeholder date/time" => qr(Date/time) ); sub module_boilerplate_ok { my ($module) = @_; not_in_file_ok($module => 'the great new $MODULENAME' => qr/ - The great new /, 'boilerplate description' => qr/Quick summary of what the module/, 'stub function definition' => qr/function[12]/, ); } module_boilerplate_ok('lib/Desktop/Notify.pm'); Desktop-Notify-0.05/MANIFEST0000644000175000017500000000043712525466436014525 0ustar stevesteveChanges MANIFEST META.yml # Will be created by "make dist" Makefile.PL README lib/Desktop/Notify.pm lib/Desktop/Notify/Notification.pm t/00-load.t t/01-connect.t t/boilerplate.t t/pod-coverage.t t/pod.t META.json Module JSON meta-data (added by MakeMaker) Desktop-Notify-0.05/Changes0000644000175000017500000000147612525466311014663 0ustar stevesteveRevision history for Desktop-Notify 0.05 2015-05-15 Cleanup documentation and tests 0.04 2015-05-13 Add app_icon option Add support for passing hints to the notification server. (patch from intrigeri) Add support for a user-defined function to be called whenever an action is invoked. (patch from intrigeri) 0.03 2009-12-25 Fixed regression in 0.02 when creating notification with timeout Show a warning when closing a notification that has not been shown 0.02 2009-12-24 Fixed non-numeric id/timeout bugs 0.01 2007-05-07 Stuff that works: creating/displaying/modifying/updating/closing nofitications catching close signals Stuff that's not implemented yet: actions hints icons Desktop-Notify-0.05/META.yml0000644000175000017500000000107212525466436014641 0ustar stevesteve--- abstract: 'Communicate with the Desktop Notifications framework' author: - 'Stephen Cavilia ' build_requires: ExtUtils::MakeMaker: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.04, CPAN::Meta::Converter version 2.140640' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Desktop-Notify no_index: directory: - t - inc requires: Class::Accessor: '0' Net::DBus: '0' Test::More: '0' version: '0.05' Desktop-Notify-0.05/Makefile.PL0000644000175000017500000000111611314712242015321 0ustar stevesteveuse strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Desktop::Notify', AUTHOR => 'Stephen Cavilia ', VERSION_FROM => 'lib/Desktop/Notify.pm', ABSTRACT_FROM => 'lib/Desktop/Notify.pm', PL_FILES => {}, PREREQ_PM => { 'Test::More' => 0, 'Net::DBus' => 0, 'Class::Accessor' => 0, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Desktop-Notify-*' }, ); Desktop-Notify-0.05/META.json0000644000175000017500000000171612525466436015016 0ustar stevesteve{ "abstract" : "Communicate with the Desktop Notifications framework", "author" : [ "Stephen Cavilia " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.04, CPAN::Meta::Converter version 2.140640", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Desktop-Notify", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Class::Accessor" : "0", "Net::DBus" : "0", "Test::More" : "0" } } }, "release_status" : "stable", "version" : "0.05" }