Mercurial > ~mikael > mcabber > hg
comparison mcabber/modules/beep/beep.c @ 1671:411269409f34
Add in-tree beep example module
author | Myhailo Danylenko <isbear@ukrpost.net> |
---|---|
date | Mon, 18 Jan 2010 16:11:34 +0200 |
parents | |
children | 5093b5ca1572 |
comparison
equal
deleted
inserted
replaced
1670:efee21002ffb | 1671:411269409f34 |
---|---|
1 | |
2 /* Copyright 2009 Myhailo Danylenko | |
3 | |
4 This file is part of mcabber module writing howto examples. | |
5 | |
6 Examples are free software: you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation, either version 2 of the License, or | |
9 (at your option) any later version. | |
10 | |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
18 | |
19 #include <glib.h> | |
20 #include <gmodule.h> | |
21 #include <string.h> | |
22 | |
23 #include <mcabber/logprint.h> | |
24 #include <mcabber/commands.h> | |
25 #include <mcabber/compl.h> | |
26 #include <mcabber/hooks.h> | |
27 #include <mcabber/screen.h> | |
28 #include <mcabber/settings.h> | |
29 | |
30 static guint beep_cid = 0; | |
31 | |
32 /* Event handler */ | |
33 void beep_hh (guint32 hid, hk_arg_t *args, gpointer userdata) | |
34 { | |
35 /* Check if beeping is enabled */ | |
36 if (settings_opt_get_int ("beep_enable")) | |
37 /* *BEEP*! */ | |
38 scr_Beep (); | |
39 } | |
40 | |
41 /* beep command handler */ | |
42 void do_beep (char *args) | |
43 { | |
44 /* Check arguments, and if recognized, | |
45 * set mcabber option accordingly */ | |
46 if (!strcmp (args, "enable") || | |
47 !strcmp (args, "on") || | |
48 !strcmp (args, "yes") || | |
49 !strcmp (args, "1")) | |
50 settings_set (SETTINGS_TYPE_OPTION, | |
51 "beep_enable", "1"); | |
52 else if (!strcmp (args, "disable") || | |
53 !strcmp (args, "off") || | |
54 !strcmp (args, "no") || | |
55 !strcmp (args, "0")) | |
56 settings_set (SETTINGS_TYPE_OPTION, | |
57 "beep_enable", "0"); | |
58 | |
59 /* Output current state, either if state is | |
60 * changed and if argument is not recognized */ | |
61 if (settings_opt_get_int ("beep_enable")) | |
62 scr_LogPrint (LPRINT_NORMAL, | |
63 "Beep on messages is enabled"); | |
64 else | |
65 scr_LogPrint (LPRINT_NORMAL, | |
66 "Beep on messages is disabled"); | |
67 } | |
68 | |
69 /* Initialization */ | |
70 const gchar* g_module_check_init (GModule *module) | |
71 { | |
72 /* Create completions */ | |
73 beep_cid = compl_new_category (); | |
74 if (beep_cid) { | |
75 compl_add_category_word (beep_cid, "enable"); | |
76 compl_add_category_word (beep_cid, "disable"); | |
77 } | |
78 /* Add command */ | |
79 cmd_add ("beep", "", beep_cid, 0, do_beep, NULL); | |
80 /* Add handler | |
81 * We are only interested in incoming message events | |
82 */ | |
83 hk_add_handler (beep_hh, HOOK_MESSAGE_IN, NULL); | |
84 return NULL; | |
85 } | |
86 | |
87 /* Deinitialization */ | |
88 void g_module_unload (GModule *module) | |
89 { | |
90 /* Unregister event handler */ | |
91 hk_del_handler (beep_hh, NULL); | |
92 /* Unregister command */ | |
93 cmd_del ("beep"); | |
94 /* Give back completion handle */ | |
95 if (beep_cid) | |
96 compl_del_category (beep_cid); | |
97 } | |
98 | |
99 /* The End */ |