blink-blue.c
//based on http://www.joachim-breitner.de/projects#gaim-thinklight plugin
#define PLUGIN_VERSION "blink-blue"
#define PLUGIN_IDENT "gtk-hiciu-blinker-blue"
#define PLUGIN_SOCKET_TO_CHANGE "/sys/class/leds/gta02-power:blue/brightness"
#define PREF_ROOT "/plugins/gtk/blinkerblue"
#define PREF_TIME_TO_BE_ON "/plugins/gtk/blinkerblue/timetobeon"
#define PREF_TIME_TO_BE_OFF "/plugins/gtk/blinkerblue/timetobeoff"
#define PREF_STOP_AFTER_SEQ "/plugins/gtk/blinkerblue/stopafter"
#include <glib.h>
#include "internal.h"
#include "notify.h"
#include "plugin.h"
#include "version.h"
#include "gtkconv.h"
#include "gtkprefs.h"
#include "prefs.h"
#include "gtkplugin.h"
#include "gtkutils.h"
#include "debug.h"
static gboolean blinker_active = FALSE;
static gint blinker_seq = 0;
static GList * get_pending_list(guint max)
{
GList *l_im = NULL;
GList *l_chat = NULL;
l_im = pidgin_conversations_find_unseen_list(PURPLE_CONV_TYPE_IM,
PIDGIN_UNSEEN_TEXT,
FALSE, max);
l_chat = pidgin_conversations_find_unseen_list(PURPLE_CONV_TYPE_CHAT,
PIDGIN_UNSEEN_NICK,
FALSE, max);
if (l_im != NULL && l_chat != NULL)
return g_list_concat(l_im, l_chat);
else if (l_im != NULL)
return l_im;
else
return l_chat;
}
static void change_blinker_status(char* statuz)
{
FILE *file;
purple_debug_info(PLUGIN_VERSION,"gogo! now it will be... \n");
purple_debug_info(PLUGIN_VERSION,statuz);
file = fopen(PLUGIN_SOCKET_TO_CHANGE, "w");
fprintf(file, "%s", statuz);
fclose(file);
purple_debug_info(PLUGIN_VERSION,"blink blink!\n");
}
static guint blink()
{
/* determine if any ims have unseen messages */
gint ile = g_list_length(get_pending_list(20));
if ((ile == 0) || (blinker_seq >= purple_prefs_get_int(PREF_STOP_AFTER_SEQ)*2
&& purple_prefs_get_int(PREF_STOP_AFTER_SEQ) != 0))
{
blinker_active = FALSE;
blinker_seq = 0;
change_blinker_status("0");
return FALSE;
}
blinker_seq++;
if (blinker_seq % 2 == 0)
{
change_blinker_status("0");
purple_timeout_add(purple_prefs_get_int(PREF_TIME_TO_BE_OFF)*10,(GSourceFunc)blink,NULL);
}
else
{
change_blinker_status("255");
purple_timeout_add(purple_prefs_get_int(PREF_TIME_TO_BE_ON)*10,(GSourceFunc)blink,NULL);
}
return FALSE;
}
static void update_status()
{
purple_debug_info(PLUGIN_VERSION,"received-im-msg or conversation-updated\n");
/* determine if any ims have unseen messages */
if (get_pending_list(1) != NULL)
{
purple_debug_info(PLUGIN_VERSION,"we have pending messages!\n");
if (!blinker_active)
{
blinker_active = TRUE;
blinker_seq = 0;
blink();
}
}
}
static gboolean plugin_load(PurplePlugin *plugin)
{
purple_debug_info(PLUGIN_VERSION,"plugin_load start\n");
purple_signal_connect(purple_conversations_get_handle(), "received-im-msg", plugin, PURPLE_CALLBACK(update_status), NULL);
purple_signal_connect(purple_conversations_get_handle(), "conversation-updated", plugin, PURPLE_CALLBACK(update_status), NULL);
purple_debug_info(PLUGIN_VERSION,"plugin_load done\n");
return TRUE;
}
static GtkWidget *
get_config_frame(PurplePlugin *plugin)
{
GtkWidget *ret = NULL;
GtkWidget *timeout_on = NULL;
GtkWidget *timeout_off = NULL;
GtkWidget *stop_after_seq = NULL;
purple_debug_info(PLUGIN_VERSION,"get_config_frame called!\n");
ret = gtk_vbox_new(FALSE, 18);
gtk_container_set_border_width(GTK_CONTAINER (ret), 12);
timeout_on = pidgin_prefs_labeled_spin_button(ret, _("Time to be on (1/100 s)"), PREF_TIME_TO_BE_ON, 2, 10000, NULL);
timeout_off = pidgin_prefs_labeled_spin_button(ret, _("Time to be off (1/100 s)"), PREF_TIME_TO_BE_OFF, 2, 10000, NULL);
stop_after_seq = pidgin_prefs_labeled_spin_button(ret, _("Sequences (0 = unlimited)"), PREF_STOP_AFTER_SEQ, 0, 10000, NULL);
/* gtk_widget_set_sensitive(widget_size_widgets[i],
purple_prefs_get_bool(widget_size_prefs_set[i]));
g_signal_connect(G_OBJECT(check), "toggled",
G_CALLBACK(pidgin_toggle_sensitive),
timeout_on);*/
gtk_widget_show_all(ret);
purple_debug_info(PLUGIN_VERSION,"get_config_frame .. its ok?!\n");
return ret;
}
static PidginPluginUiInfo ui_info =
{
get_config_frame,
0, /* page_num (Reserved) */
/* padding */
NULL,
NULL,
NULL,
NULL
};
static PurplePluginInfo info =
{
PURPLE_PLUGIN_MAGIC,
PURPLE_MAJOR_VERSION,
PURPLE_MINOR_VERSION,
PURPLE_PLUGIN_STANDARD,
PIDGIN_PLUGIN_TYPE,
0,
NULL,
PURPLE_PRIORITY_DEFAULT,
PLUGIN_IDENT,
PLUGIN_VERSION,
"0.2.1",
PLUGIN_VERSION,
PLUGIN_VERSION,
"hiciu <kwarzecha7@gmail.com>",
"none",
plugin_load,
NULL,
NULL,
&ui_info,
NULL, NULL, NULL, NULL, NULL, NULL, NULL
};
static void init_plugin(PurplePlugin *plugin)
{
purple_debug_info(PLUGIN_VERSION,"init_plugin start\n");
purple_prefs_add_none("/plugins/gtk");
purple_prefs_add_none(PREF_ROOT);
purple_prefs_add_int(PREF_TIME_TO_BE_ON, 50);
purple_prefs_add_int(PREF_TIME_TO_BE_OFF, 50);
purple_prefs_add_int(PREF_STOP_AFTER_SEQ, 0);
}
PURPLE_INIT_PLUGIN(blinker_plugin, init_plugin, info)