~ubuntu-branches/debian/jessie/shutter/jessie

« back to all changes in this revision

Viewing changes to share/shutter/resources/modules/Shutter/App/Notification.pm

  • Committer: Bazaar Package Importer
  • Author(s): Ryan Niebur
  • Date: 2009-12-24 21:47:06 UTC
  • mfrom: (1.1.2 upstream) (2.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20091224214706-l90f8dus01qsjvmm
* New Upstream Version
* update and change some deps
* update email address
* set Standards-Version to 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
###################################################
 
2
#
 
3
#  Copyright (C) 2008, 2009 Mario Kemper <mario.kemper@googlemail.com> and Shutter Team
 
4
#
 
5
#  This file is part of Shutter.
 
6
#
 
7
#  Shutter is free software; you can redistribute it and/or modify
 
8
#  it under the terms of the GNU General Public License as published by
 
9
#  the Free Software Foundation; either version 3 of the License, or
 
10
#  (at your option) any later version.
 
11
#
 
12
#  Shutter is distributed in the hope that it will be useful,
 
13
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#  GNU General Public License for more details.
 
16
#
 
17
#  You should have received a copy of the GNU General Public License
 
18
#  along with Shutter; if not, write to the Free Software
 
19
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
20
#
 
21
###################################################
 
22
 
 
23
package Shutter::App::Notification;
 
24
 
 
25
#modules
 
26
#--------------------------------------
 
27
use utf8;
 
28
use strict;
 
29
use warnings;
 
30
 
 
31
use Net::DBus;
 
32
 
 
33
#Gettext and filename parsing
 
34
use POSIX qw/setlocale strftime/;
 
35
use Locale::gettext;
 
36
 
 
37
#define constants
 
38
#--------------------------------------
 
39
use constant TRUE  => 1;
 
40
use constant FALSE => 0;
 
41
 
 
42
#--------------------------------------
 
43
 
 
44
sub new {
 
45
        my $class = shift;
 
46
 
 
47
        my $self = { _name => shift };
 
48
 
 
49
        #Use notifications object
 
50
        eval{
 
51
                $self->{_notifications_service} = Net::DBus->session->get_service('org.freedesktop.Notifications');
 
52
                $self->{_notifications_object} = $self->{_notifications_service}->get_object('/org/freedesktop/Notifications', 'org.freedesktop.Notifications');
 
53
        };
 
54
        if($@){
 
55
                print "Warning: $@", "\n";      
 
56
        }
 
57
 
 
58
        #last nid
 
59
        $self->{_nid} = 0;
 
60
 
 
61
        bless $self, $class;
 
62
        return $self;
 
63
}
 
64
 
 
65
sub show {
 
66
        my $self        = shift;
 
67
        my $summary = shift;
 
68
        my $body        = shift;
 
69
        my $nid         = shift || $self->{_nid};
 
70
 
 
71
        #notification
 
72
        eval{
 
73
                if(defined $self->{_notifications_object}){
 
74
                        $self->{_nid} = $self->{_notifications_object}->Notify('Shutter', $nid, "gtk-dialog-info", $summary, $body, [], {}, -1);
 
75
                }
 
76
        };
 
77
        if($@){
 
78
                print "NotifyWarning: $@", "\n";                
 
79
        }
 
80
        
 
81
        return $self->{_nid};
 
82
}
 
83
 
 
84
sub close {
 
85
        my $self        = shift;
 
86
        my $nid         = shift || $self->{_nid};
 
87
        
 
88
        #close notification
 
89
        if($nid){
 
90
                eval{
 
91
                        if(defined $self->{_notifications_object}){
 
92
                                $self->{_notifications_object}->CloseNotification($nid);
 
93
                        }
 
94
                };
 
95
                if($@){
 
96
                        print "CloseNotificationWarning: $@", "\n";             
 
97
                }
 
98
                return TRUE;    
 
99
        }
 
100
 
 
101
        return FALSE;
 
102
}
 
103
 
 
104
1;