summaryrefslogtreecommitdiff
path: root/plugin/blinkyfications.pl
blob: aa068d3594b3f43d621914d714e795035fc776e2 (plain) (blame)
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
#
# blinkyfication
#
#
# Copyright (C) 2016 Christian Pointner <equinox@spreadspace.org>
#
# This file is part of blinkyfication.
#
# blinkyfication is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3
# as published by the Free Software Foundation.
#
# blinkyfication is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with blinkyfication. If not, see <http://www.gnu.org/licenses/>.
#
use Purple;

%PLUGIN_INFO = (
  perl_api_version => 2,
  name => "blinkyfications",
  version => "0.1",
  summary => "Make notifications blink again!",
  description => "Blink when there are messages or other events.",
  author => "Christian Pointner <equinox\@spreadspace.org>",
  url => "https://git.spreadspace.org/blinkyfications.git",
  load => "plugin_load",
  unload => "plugin_unload",
  prefs_info => "prefs_info_cb"
);

sub plugin_init {
  return %PLUGIN_INFO;
}

sub plugin_load {
  my $plugin = shift;

  # Prefrences
  Purple::Debug::info("blinkyfications", "make notifications blink again!\n");
  Purple::Prefs::add_none("/plugins/core/blinkyfications");
  Purple::Prefs::add_string("/plugins/core/blinkyfications/device", "/dev/ttyACM0");

  # Signals/Callbacks
  my $conv_handle = Purple::Conversations::get_handle();
  Purple::Signal::connect($conv_handle, "received-im-msg", $plugin, \&received_msg_cb, $plugin);
#  Purple::Signal::connect($conv_handle, "received-chat-msg", $plugin, \&received_msg_cb, $plugin);
}

sub plugin_unload {
  my $plugin = shift;
  Purple::Debug::info("blinkyfications", "i get it, i'm just too damn blinky... bye-bye!\n");
}

sub prefs_info_cb {
  $frame = Purple::PluginPref::Frame->new();

  $ppref = Purple::PluginPref->new_with_name_and_label("/plugins/core/blinkyfications/device", "Blinky-Device");
  $ppref->set_type(2);
  $ppref->set_max_length(256);
  $frame->add($ppref);

  return $frame;
}

sub received_msg_cb {
  my ($account, $sender, $message, $conv, $flags, $plugin) = @_;
  Purple::Debug::misc("blinkyfications",  $account->get_username() . ": $sender says '$message'\n");

  my $device = Purple::Prefs::get_string("/plugins/core/blinkyfications/device");
  open(my $fh, '>', $device) or return Purple::Debug::error("blinkyfications", "can't open device: " . $device .": " . $! . "\n");
  print $fh "r";
  close $fh;

  Purple::timeout_add($plugin, 0.3, \&timeout_cb, $plugin);
  return 0;
}

sub timeout_cb {
  my $plugin = shift;

  my $device = Purple::Prefs::get_string("/plugins/core/blinkyfications/device");
  open(my $fh, '>', $device) or return Purple::Debug::error("blinkyfications", "can't open device: " . $device .": " . $! . "\n");
  print $fh "0";
  close $fh;
}