annotate mcabber/modules/beep/beep.c @ 1735:5093b5ca1572

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