-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpidgin-notifier-8.pl
78 lines (64 loc) · 2.27 KB
/
pidgin-notifier-8.pl
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
#based off forward2mobile http://code.google.com/p/forward2mobile/
use Purple;
use Encode;
use Cwd;
use HTML::Entities;
%PLUGIN_INFO = (
perl_api_version => 2,
name => "pidgin-toast-8",
version => "0.1",
summary => "Display Windows 8 notifications for new messages.",
description => "Show notifications native to Windows 8 using the console-toast-8 script.",
author => "Adrian Keenan",
url => "http://adriankeenan.co.uk",
load => "plugin_load",
unload => "plugin_unload"
);
sub plugin_init {
return %PLUGIN_INFO;
}
sub plugin_load {
my $plugin = shift;
$convs_handle = Purple::Conversations::get_handle();
Purple::Signal::connect($convs_handle, "receiving-im-msg", $plugin, \&got_msg, "yyy");
Purple::Debug::info("pidgin-toast-8", "plugin_load() - Test Plugin Loaded.\n");
}
sub plugin_unload {
my $plugin = shift;
Purple::Debug::info("pidgin-toast-8", "plugin_unload() - Test Plugin Unloaded.\n");
}
sub got_msg {
my ($account, $who, $msg, $conv, $flags) = @_;
#get buddy name and avatar path
@accounts = Purple::Accounts::get_all();
for ($i = 0; $i <= $#accounts; $i++) {
$sender = Purple::Find::buddy($accounts[$i], $who);
if ($sender) {
$displayName = decode_utf8($sender->get_alias());
$iconPath = $sender->get_icon()->get_full_path();
last;
}
}
if (!$sender) {
$displayName = $who;
$iconPath = "";
}
#html decode and strip tags (only for basic html)
$msg = decode_entities($msg);
while ($msg =~ s/<\S[^<>]*(?:>|$)//gs) {};
#show toast notification if the conversation window does not have focus
if (!$conv->has_focus()) {
show_toast($displayName, $msg, $iconPath);
}
}
sub show_toast {
my($title, $body, $img) = @_;
#get path to working_dir\pidgin.ico
my $dir = getcwd;
$dir =~ tr|/|\\|;
my $icon = sprintf("%s\\pidgin.ico", $dir);
#escape quotes in the message
$body =~ s/"/\\"/g;
#run console-toast8
system(sprintf("console-toast-8.exe --template ToastImageAndText02 --title \"%s\" --line1 \"%s\" --img \"%s\" --icon \"%s\"", $title, $body, $img, $icon));
}