~ubuntu-branches/ubuntu/trusty/shutter/trusty

« back to all changes in this revision

Viewing changes to share/shutter/resources/modules/Net/DBus/Skype.pm

  • Committer: Bazaar Package Importer
  • Author(s): Ryan Niebur
  • Date: 2009-08-06 16:29:32 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806162932-g00c3k4obbdddb4u
Tags: 0.80.1-1
* New Upstream Version
  - update copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package Net::DBus::Skype;
 
2
 
 
3
use Moose;
 
4
use File::Basename;
 
5
use Carp;
 
6
 
 
7
use Net::DBus;
 
8
 
 
9
our $VERSION = '0.02';
 
10
 
 
11
has 'debug' => ( isa => 'Bool', is => 'ro', default => 0 );
 
12
 
 
13
has 'dbus' => (
 
14
        isa       => 'Net::DBus'
 
15
        , is      => 'ro'
 
16
        , lazy    => 1
 
17
        , default => sub { Net::DBus->session }
 
18
);
 
19
 
 
20
has 'skype' => (
 
21
        isa            => 'Net::DBus::RemoteObject'
 
22
        , is           => 'rw'
 
23
        , lazy_build   => 1
 
24
);
 
25
 
 
26
around '_build_skype' => sub {
 
27
        my ( $sub, $self, @args ) = @_;
 
28
        my $skype = $self->$sub;
 
29
        $self->skype( $skype );
 
30
        $self->_init_skype;
 
31
        $skype;
 
32
};
 
33
 
 
34
sub _build_skype {
 
35
        my $self = shift;
 
36
        
 
37
        my $objects = $self->dbus
 
38
                ->get_service("org.freedesktop.DBus")
 
39
                ->get_object("/org/freedesktop/DBus")
 
40
        ;
 
41
 
 
42
        my $skype_found = grep $_ eq 'com.Skype.API', @{$objects->ListNames};
 
43
        die 'No running API-capable Skype found'
 
44
                unless $skype_found
 
45
        ;
 
46
        
 
47
        my $skype = $self->dbus
 
48
                ->get_service('com.Skype.API')
 
49
                ->get_object('/com/Skype', 'com.Skype.API')
 
50
        ;
 
51
 
 
52
}
 
53
 
 
54
sub _init_skype {
 
55
        my $self = shift;
 
56
 
 
57
        {
 
58
                my $name = $0 eq '-e' ? 'action_handle' : File::Basename::basename($0);
 
59
                my $answer = $self->raw_skype("NAME $name");
 
60
                die 'Error communicating with Skype!'
 
61
                        if $answer ne 'OK'
 
62
                ;
 
63
        }
 
64
 
 
65
        {
 
66
                my $answer = $self->raw_skype('PROTOCOL 7');
 
67
                die 'Skype client too old!'
 
68
                        if $answer ne 'PROTOCOL 7'
 
69
                ;
 
70
        }
 
71
 
 
72
}
 
73
 
 
74
sub action {
 
75
        my ( $self, $arg ) = @_;
 
76
 
 
77
        my ( $user, $cmd, $multiuser );
 
78
        if ( $arg =~ /
 
79
                ^
 
80
                (?:skype|callto|tel)
 
81
                :\/{0,2}
 
82
                ([^?]+)
 
83
                (?:\??(.*))?
 
84
                $
 
85
        /x ) {
 
86
                $user = $1;
 
87
                $cmd  = $2 || 'call';
 
88
        }
 
89
        else {
 
90
                croak "Invalid argument! (format: skype:echo123?call)\n";
 
91
        }
 
92
 
 
93
        $multiuser = 1
 
94
                if $user =~ s/;/, /g
 
95
        ;
 
96
 
 
97
        $cmd = lc($cmd);
 
98
        if ($cmd eq 'add') {
 
99
                croak "Command add takes only one user!\n"
 
100
                        if $multiuser
 
101
                ;
 
102
                $self->raw_skype("OPEN ADDAFRIEND $user")
 
103
        }
 
104
        
 
105
        elsif ($cmd eq 'call') {
 
106
                $self->raw_skype("CALL $user");
 
107
        }
 
108
        
 
109
        elsif ($cmd eq 'chat') {
 
110
                my $answer = $self->raw_skype("CHAT CREATE $user");
 
111
                my @chats = split(' ', $answer);
 
112
                $self->raw_skype("OPEN CHAT ".$chats[1]);
 
113
        }
 
114
        
 
115
        elsif ($cmd eq 'sendfile') {
 
116
                $self->raw_skype("OPEN FILETRANSFER $user");
 
117
        }
 
118
        
 
119
        elsif ($cmd eq 'userinfo') {
 
120
                croak "Command userinfo takes only one user!\n"
 
121
                        if $multiuser
 
122
                ;
 
123
                $self->raw_skype("OPEN USERINFO $user");
 
124
        }
 
125
 
 
126
        else {
 
127
                croak "Command $cmd currently unhandled!\n";
 
128
        }
 
129
 
 
130
}
 
131
 
 
132
 
 
133
sub raw_skype {
 
134
        my ($self, $cmd) = @_;
 
135
 
 
136
        my $answer = $self->skype->Invoke($cmd);
 
137
        print "$cmd: $answer\n" if $self->debug;
 
138
        
 
139
        return $answer;
 
140
}
 
141
 
 
142
1;
 
143
 
 
144
__END__
 
145
 
 
146
=head1 NAME
 
147
 
 
148
Net::DBus::Skype - Perl access to Skype's DBus API
 
149
 
 
150
=head1 DESCRIPTION
 
151
 
 
152
This module supplies a perl API into Skype via DBus. It was inspired by the discussion at L<http://forum.skype.com/lofiversion/index.php/t92761.html>, and adapted from Philipp Kolmann's code base. Nothing much of Philipps code remains other than his choice of error messagses.
 
153
 
 
154
B<If what your doing isn't specific to Skype, use the non proprietary "callto" protocol in your code! Example, href="callto:8325555555">
 
155
 
 
156
=head1 SYNOPSIS
 
157
 
 
158
        use Net::DBus::Skype;
 
159
 
 
160
        my $s = Net::DBus::Skype->new;
 
161
        my $s = Net::DBus::Skype->new({ debug => 1 });
 
162
 
 
163
        $s->action('skype:echo123?call');
 
164
        # -or-
 
165
        $s->action('skype:echo123');
 
166
        # -or-
 
167
        $s->action('skype://echo123');
 
168
        # -or-
 
169
        $s->raw_skype('CALL echo123');
 
170
 
 
171
=head1 SCRIPTS
 
172
 
 
173
This module also installs two scripts, B<skype-action-handler>, and B<skype-simple-dialer>. The first script, skype-action-handler, takes Skype action uris on the command line and simply creates an instance and feeds them to C<-E<gt>action>. The second script, skype-simple-dialer, takes a phone number, and simply feeds it to the C<-E<gt>raw_skype> CALL. The skype-action-handler script should be fully compatable with the C program by the same name that once was distributed with Skype.
 
174
 
 
175
=head1 METHODS
 
176
 
 
177
=head2 ->action
 
178
 
 
179
Takes a skype pseudo-uri, or pseudo-url, ex. skype://echo123?call. This is parsed into three components: protocol, user, and command. Valid options for protocol are "skype", "callto", and "tel". It is then translated into raw_skype and sent off through the DBus communication link. The default command is I<call>.
 
180
 
 
181
=head2 ->raw_skype
 
182
 
 
183
Issuess raw_skype commands exposed through the DBus API. An example of this command would be, "CALL echo123".
 
184
 
 
185
=head1 AUTHOR
 
186
 
 
187
Evan Carroll, C<< <me at evancarroll.com> >>
 
188
 
 
189
=head1 BUGS
 
190
 
 
191
Please report any bugs or feature requests to C<bug-net-dbus-skype at rt.cpan.org>, or through
 
192
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-DBus-Skype>.  I will be notified, and then you'll
 
193
automatically be notified of progress on your bug as I make changes.
 
194
 
 
195
=head1 SUPPORT
 
196
 
 
197
You can find documentation for this module with the perldoc command.
 
198
 
 
199
perldoc Net::DBus::Skype
 
200
 
 
201
 
 
202
You can also look for information at:
 
203
 
 
204
=over 4
 
205
 
 
206
=item * RT: CPAN's request tracker
 
207
 
 
208
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-DBus-Skype>
 
209
 
 
210
=item * AnnoCPAN: Annotated CPAN documentation
 
211
 
 
212
L<http://annocpan.org/dist/Net-DBus-Skype>
 
213
 
 
214
=item * CPAN Ratings
 
215
 
 
216
L<http://cpanratings.perl.org/d/Net-DBus-Skype>
 
217
 
 
218
=item * Search CPAN
 
219
 
 
220
L<http://search.cpan.org/dist/Net-DBus-Skype>
 
221
 
 
222
=back
 
223
 
 
224
 
 
225
=head1 ACKNOWLEDGEMENTS
 
226
 
 
227
 
 
228
=head1 COPYRIGHT & LICENSE
 
229
 
 
230
Copyright 2008 Evan Carroll, all rights reserved.
 
231
 
 
232
This program is free software; you can redistribute it and/or modify it
 
233
under the same terms as Perl itself.
 
234
 
 
235
 
 
236
=cut