Mercurial > ~mikael > mcabber > hg
comparison mcabber/modules/beep/beep.c @ 1829:c059c5c98de6
Update beep module coding style
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sat, 27 Mar 2010 13:00:46 +0100 |
parents | 1aa89ccfb626 |
children | ad77110343d6 |
comparison
equal
deleted
inserted
replaced
1828:8f7d7c05f275 | 1829:c059c5c98de6 |
---|---|
1 | 1 /* |
2 /* Copyright 2009 Myhailo Danylenko | 2 * Module "beep" -- Beep on all incoming messages |
3 | 3 * |
4 This file is part of mcabber module writing howto examples. | 4 * Copyright 2009 Myhailo Danylenko |
5 | 5 * This file is part of mcabber module writing howto examples. |
6 Examples are free software: you can redistribute it and/or modify | 6 * |
7 it under the terms of the GNU General Public License as published by | 7 * This module is free software; you can redistribute it and/or modify |
8 the Free Software Foundation, either version 2 of the License, or | 8 * it under the terms of the GNU General Public License as published by |
9 (at your option) any later version. | 9 * the Free Software Foundation; either version 2 of the License, or (at |
10 | 10 * your option) any later version. |
11 This program is distributed in the hope that it will be useful, | 11 * |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * This program is distributed in the hope that it will be useful, but |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
14 GNU General Public License for more details. | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | 15 * General Public License for more details. |
16 You should have received a copy of the GNU General Public License | 16 * |
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | 17 * You should have received a copy of the GNU General Public License |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 */ | |
18 | 20 |
19 #include <string.h> | 21 #include <string.h> |
20 | 22 |
21 #include <mcabber/logprint.h> | 23 #include <mcabber/logprint.h> |
22 #include <mcabber/commands.h> | 24 #include <mcabber/commands.h> |
30 static void beep_init (void); | 32 static void beep_init (void); |
31 static void beep_uninit (void); | 33 static void beep_uninit (void); |
32 | 34 |
33 /* Module description */ | 35 /* Module description */ |
34 module_info_t info_beep = { | 36 module_info_t info_beep = { |
35 .branch = MCABBER_BRANCH, | 37 .branch = MCABBER_BRANCH, |
36 .api = MCABBER_API_VERSION, | 38 .api = MCABBER_API_VERSION, |
37 .version = MCABBER_VERSION, | 39 .version = MCABBER_VERSION, |
38 .description = "Simple beeper module\n" | 40 .description = "Simple beeper module\n" |
39 " Recognizes option beep_enable\n" | 41 " Recognizes option beep_enable\n" |
40 " Provides command /beep", | 42 " Provides command /beep", |
41 .requires = NULL, | 43 .requires = NULL, |
42 .init = beep_init, | 44 .init = beep_init, |
43 .uninit = beep_uninit, | 45 .uninit = beep_uninit, |
44 .next = NULL, | 46 .next = NULL, |
45 }; | 47 }; |
46 | 48 |
47 static guint beep_cid = 0; | 49 static guint beep_cid = 0; /* Command completion category id */ |
48 static guint beep_hid; | 50 static guint beep_hid = 0; /* Hook handler id */ |
49 | 51 |
50 /* Event handler */ | 52 /* Event handler */ |
51 static guint beep_hh (const gchar *hookname, hk_arg_t *args, gpointer userdata) | 53 static guint beep_hh(const gchar *hookname, hk_arg_t *args, gpointer userdata) |
52 { | 54 { |
53 /* Check if beeping is enabled */ | 55 /* Check if beeping is enabled */ |
54 if (settings_opt_get_int ("beep_enable")) | 56 if (settings_opt_get_int("beep_enable")) |
55 scr_beep (); /* *BEEP*! */ | 57 scr_beep(); /* *BEEP*! */ |
56 return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS; | 58 |
59 /* We're done, let the other handlers do their job! */ | |
60 return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS; | |
57 } | 61 } |
58 | 62 |
59 /* beep command handler */ | 63 /* beep command handler */ |
60 static void do_beep (char *args) | 64 static void do_beep(char *args) |
61 { | 65 { |
62 /* Check arguments, and if recognized, | 66 /* Check arguments, and if recognized, |
63 * set mcabber option accordingly */ | 67 * set mcabber option accordingly */ |
64 if (!strcmp (args, "enable") || | 68 if (!strcmp(args, "enable") || |
65 !strcmp (args, "on") || | 69 !strcmp(args, "on") || |
66 !strcmp (args, "yes") || | 70 !strcmp(args, "yes") || |
67 !strcmp (args, "1")) | 71 !strcmp(args, "1")) |
68 settings_set (SETTINGS_TYPE_OPTION, | 72 settings_set(SETTINGS_TYPE_OPTION, "beep_enable", "1"); |
69 "beep_enable", "1"); | 73 else if (!strcmp(args, "disable") || |
70 else if (!strcmp (args, "disable") || | 74 !strcmp(args, "off") || |
71 !strcmp (args, "off") || | 75 !strcmp(args, "no") || |
72 !strcmp (args, "no") || | 76 !strcmp(args, "0")) |
73 !strcmp (args, "0")) | 77 settings_set(SETTINGS_TYPE_OPTION, "beep_enable", "0"); |
74 settings_set (SETTINGS_TYPE_OPTION, | |
75 "beep_enable", "0"); | |
76 | 78 |
77 /* Output current state, either if state is | 79 /* Output current state, either if state is |
78 * changed and if argument is not recognized */ | 80 * changed or if argument is not recognized */ |
79 if (settings_opt_get_int ("beep_enable")) | 81 if (settings_opt_get_int("beep_enable")) |
80 scr_LogPrint (LPRINT_NORMAL, | 82 scr_log_print(LPRINT_NORMAL, "Beep on messages is enabled"); |
81 "Beep on messages is enabled"); | 83 else |
82 else | 84 scr_log_print(LPRINT_NORMAL, "Beep on messages is disabled"); |
83 scr_LogPrint (LPRINT_NORMAL, | |
84 "Beep on messages is disabled"); | |
85 } | 85 } |
86 | 86 |
87 /* Initialization */ | 87 /* Initialization */ |
88 static void beep_init (void) | 88 static void beep_init(void) |
89 { | 89 { |
90 /* Create completions */ | 90 /* Create completions */ |
91 beep_cid = compl_new_category (); | 91 beep_cid = compl_new_category(); |
92 if (beep_cid) { | 92 if (beep_cid) { |
93 compl_add_category_word (beep_cid, "enable"); | 93 compl_add_category_word(beep_cid, "enable"); |
94 compl_add_category_word (beep_cid, "disable"); | 94 compl_add_category_word(beep_cid, "disable"); |
95 } | 95 } |
96 /* Add command */ | 96 /* Add command */ |
97 cmd_add ("beep", "", beep_cid, 0, do_beep, NULL); | 97 cmd_add("beep", "", beep_cid, 0, do_beep, NULL); |
98 /* Add handler | 98 /* Add handler |
99 * We are only interested in incoming message events | 99 * We are only interested in incoming message events |
100 */ | 100 */ |
101 beep_hid = hk_add_handler (beep_hh, HOOK_POST_MESSAGE_IN, | 101 beep_hid = hk_add_handler(beep_hh, HOOK_POST_MESSAGE_IN, |
102 G_PRIORITY_DEFAULT_IDLE, NULL); | 102 G_PRIORITY_DEFAULT_IDLE, NULL); |
103 } | 103 } |
104 | 104 |
105 /* Deinitialization */ | 105 /* Uninitialization */ |
106 static void beep_uninit (void) | 106 static void beep_uninit(void) |
107 { | 107 { |
108 /* Unregister event handler */ | 108 /* Unregister event handler */ |
109 hk_del_handler (HOOK_POST_MESSAGE_IN, beep_hid); | 109 hk_del_handler(HOOK_POST_MESSAGE_IN, beep_hid); |
110 /* Unregister command */ | 110 /* Unregister command */ |
111 cmd_del ("beep"); | 111 cmd_del("beep"); |
112 /* Give back completion handle */ | 112 /* Give back completion handle */ |
113 if (beep_cid) | 113 if (beep_cid) |
114 compl_del_category (beep_cid); | 114 compl_del_category(beep_cid); |
115 } | 115 } |
116 | 116 |
117 /* The End */ | 117 /* The End */ |
118 /* vim: set et cindent cinoptions=>2\:2(0 ts=2 sw=2: For Vim users... */ |