# HG changeset patch # User Myhailo Danylenko # Date 1263823894 -7200 # Node ID 411269409f341d54e013572d7d61b496f1448219 # Parent efee21002ffb42f9996fdd4a8845229161ff88ae Add in-tree beep example module diff -r efee21002ffb -r 411269409f34 mcabber/Makefile.am --- a/mcabber/Makefile.am Mon Jan 18 15:36:19 2010 +0200 +++ b/mcabber/Makefile.am Mon Jan 18 16:11:34 2010 +0200 @@ -1,2 +1,2 @@ -SUBDIRS = mcabber doc +SUBDIRS = mcabber doc modules ACLOCAL_AMFLAGS = -I macros diff -r efee21002ffb -r 411269409f34 mcabber/configure.ac --- a/mcabber/configure.ac Mon Jan 18 15:36:19 2010 +0200 +++ b/mcabber/configure.ac Mon Jan 18 16:11:34 2010 +0200 @@ -8,7 +8,7 @@ AM_CONFIG_HEADER(mcabber/config.h) AC_CONFIG_HEADER(include/config.h) -#AC_PROG_LIBTOOL +AC_PROG_LIBTOOL AC_PROG_RANLIB # Checks for programs. @@ -260,6 +260,8 @@ CFLAGS="$CFLAGS -D_GNU_SOURCE" AC_CONFIG_FILES([mcabber/Makefile + modules/Makefile + modules/beep/Makefile doc/Makefile doc/guide/Makefile doc/help/Makefile diff -r efee21002ffb -r 411269409f34 mcabber/modules/Makefile.am --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mcabber/modules/Makefile.am Mon Jan 18 16:11:34 2010 +0200 @@ -0,0 +1,1 @@ +SUBDIRS = beep diff -r efee21002ffb -r 411269409f34 mcabber/modules/beep/Makefile.am --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mcabber/modules/beep/Makefile.am Mon Jan 18 16:11:34 2010 +0200 @@ -0,0 +1,10 @@ + +if INSTALL_HEADERS +pkglib_LTLIBRARIES = libbeep.la +libbeep_la_SOURCES = beep.c +libbeep_la_LDFLAGS = -module -avoid-version -shared + +LDADD = $(GLIB_LIBS) +AM_CPPFLAGS = -I$(top_srcdir) $(GLIB_CFLAGS) $(LOUDMOUTH_CFLAGS) +endif + diff -r efee21002ffb -r 411269409f34 mcabber/modules/beep/beep.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mcabber/modules/beep/beep.c Mon Jan 18 16:11:34 2010 +0200 @@ -0,0 +1,99 @@ + +/* Copyright 2009 Myhailo Danylenko + +This file is part of mcabber module writing howto examples. + +Examples are free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program 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 this program. If not, see . */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +static guint beep_cid = 0; + +/* Event handler */ +void beep_hh (guint32 hid, hk_arg_t *args, gpointer userdata) +{ + /* Check if beeping is enabled */ + if (settings_opt_get_int ("beep_enable")) + /* *BEEP*! */ + scr_Beep (); +} + +/* beep command handler */ +void do_beep (char *args) +{ + /* Check arguments, and if recognized, + * set mcabber option accordingly */ + if (!strcmp (args, "enable") || + !strcmp (args, "on") || + !strcmp (args, "yes") || + !strcmp (args, "1")) + settings_set (SETTINGS_TYPE_OPTION, + "beep_enable", "1"); + else if (!strcmp (args, "disable") || + !strcmp (args, "off") || + !strcmp (args, "no") || + !strcmp (args, "0")) + settings_set (SETTINGS_TYPE_OPTION, + "beep_enable", "0"); + + /* Output current state, either if state is + * changed and if argument is not recognized */ + if (settings_opt_get_int ("beep_enable")) + scr_LogPrint (LPRINT_NORMAL, + "Beep on messages is enabled"); + else + scr_LogPrint (LPRINT_NORMAL, + "Beep on messages is disabled"); +} + +/* Initialization */ +const gchar* g_module_check_init (GModule *module) +{ + /* Create completions */ + beep_cid = compl_new_category (); + if (beep_cid) { + compl_add_category_word (beep_cid, "enable"); + compl_add_category_word (beep_cid, "disable"); + } + /* Add command */ + cmd_add ("beep", "", beep_cid, 0, do_beep, NULL); + /* Add handler + * We are only interested in incoming message events + */ + hk_add_handler (beep_hh, HOOK_MESSAGE_IN, NULL); + return NULL; +} + +/* Deinitialization */ +void g_module_unload (GModule *module) +{ + /* Unregister event handler */ + hk_del_handler (beep_hh, NULL); + /* Unregister command */ + cmd_del ("beep"); + /* Give back completion handle */ + if (beep_cid) + compl_del_category (beep_cid); +} + +/* The End */