# # blinkyfication # # # Copyright (C) 2016 Christian Pointner # # 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 . # 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 ", 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; }