annotate mcabber/doc/HOWTO_modules.txt @ 1624:a75611931642

Hook handler flags updates to howto
author Myhailo Danylenko <isbear@ukrpost.net>
date Thu, 15 Oct 2009 12:50:54 +0300
parents 2a82e6654c04
children e3b93594ee6c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1619
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
1
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
2 ===========================================
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
3
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
4 Mcabber module writing brief howto
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
5
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
6 ===========================================
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
7
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
8 Mcabber loads modules via glib's GModule.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
9
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
10 Thus, in your module you can provide functions
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
11
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
12 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
13 const gchar* g_module_check_init (GModule *module);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
14 void g_module_unload (GModule *module);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
15 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
16
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
17 to do something when module is loaded and unloaded.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
18
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
19 As module is loaded, you can use mcabber functions,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
20 declared in mcabber's header files (though you should
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
21 consider, that they may change their calling conventions
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
22 some day).
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
23
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
24 I will not explain them all, there are too much of
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
25 them, but will provide description for those, provided
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
26 especially for module writers.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
27
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
28 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
29 #include "commands.h"
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
30
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
31 void cmd_add (const char *name, const char *help,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
32 guint flags1, guint flags2,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
33 void (*f)(char*), gpointer userdata);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
34 void cmd_del (const char *name);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
35 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
36
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
37 These two functions are provided to declare mcabber
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
38 commands, offered by your module.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
39 - name is a command name.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
40 - help is a short description of your command, however
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
41 for now it is not used at all and can be omitted.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
42 - flags are completion identifiers for first and second
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
43 command arguments, for list of built-in completions,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
44 see compl.h. You can declare your own completion
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
45 lists, using functions from compl.h, described later.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
46 - f is a user-provided callback function, that will be
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
47 called upon executing mcabber command. If you will
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
48 provide non-NULL userdata, function must be of type
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
49 void (*f) (char *commandline, gpointer userdata).
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
50 - userdata is a pointer to data, transparently passed
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
51 to callback. See f description.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
52
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
53 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
54 #include "compl.h"
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
55
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
56 guint compl_new_category (void);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
57 void compl_del_category (guint id);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
58
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
59 void compl_add_category_word (guint categ,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
60 const char *command);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
61 void compl_del_category_word (guint categ,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
62 const char *word);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
63 GSList *compl_get_category_list (guint cat_flags,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
64 guint *dynlist);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
65 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
66
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
67 These functions allow you to define and manage word
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
68 lists for completion categories, used by your commands.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
69 First you need to obtain handle for completion type,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
70 that you later will supply as flags, when declaring
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
71 your commands. For that use function compl_new_category.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
72 It returns new category id or zero, if mcabber runs
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
73 out of completion ids (for now there are only 32 ids
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
74 available, and 20 of them are already taken by builtin
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
75 commands). compl_del_category allows you to delete
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
76 user-defined category, deleting all words in it too.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
77
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
78 Now, that you have a completion category, you can at any
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
79 time add or delete words from it's completion list.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
80 For that use functions compl_add_category_word and
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
81 compl_del_category_word. You can obtain current contents
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
82 of category by using gompl_get_category_list. If after
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
83 execution dynlist is TRUE, you should free obtained
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
84 list of commands.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
85
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
86 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
87 #include "hooks.h"
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
88
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
89 typedef struct {
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
90 const char *name;
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
91 const char *value;
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
92 } hk_arg_t;
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
93
1624
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
94 typedef void (*hk_handler_t) (guint32 hookid,
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
95 hk_arg_t *args,
1619
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
96 gpointer userdata);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
97
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
98 void hk_add_handler (hk_handler_t handler,
1624
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
99 guint32 flags,
1619
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
100 gpointer userdata);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
101 void hk_del_handler (hk_handler_t handler,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
102 gpointer userdata);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
103 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
104
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
105 These functions allow your module to react to events,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
106 such as incoming and outgoing messages, buddy status
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
107 changes and sever connection establishment or breakup.
1624
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
108 Flags field specifies mask of events, upon which this
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
109 handler should be called. Flags, that comprise this
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
110 mask can be found in hooks.h. You can specify not yet
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
111 used flags in mask, if you need to handle all events.
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
112 Handler can determine, which event is occured by
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
113 hookid argument and by a "hook" field in args, that
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
114 may provide more precise information in some cases.
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
115 Args argument is a list of hk_arg_t structures,
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
116 terminated by structure, whose name field is set to
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
117 NULL. Usually the "hook" field is in the first
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
118 structure of the list, however it is not guaranted,
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
119 that this will be so forever.
1619
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
120
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
121 Currently there are next events possible:
1624
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
122 - hook-message-in (HOOK_MESSAGE_IN) with parameters
1619
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
123 * jid - sender of the incoming message
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
124 * message - message body, converted to locale
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
125 charset
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
126 * groupchat ("true" or "false")
1624
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
127 - hook-message-out (HOOK_MESSAGE_OUT) with parameters
1619
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
128 * jid - recipient of the outgoing message
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
129 * message - message body, converted to locale
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
130 charset
1624
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
131 - hook-status-change (HOOK_STATUS_CHANGE) with
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
132 parameters
1619
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
133 * jid - buddy, whose status has changed
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
134 * resource - resource, whose status has changed
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
135 * old_status - old status of the buddy, one-char
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
136 string, representing mcabber status letter -
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
137 one of 'ofdna?_'.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
138 * new_status - new buddy status. The same as
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
139 old_status.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
140 * message - new status message. Old one should be
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
141 still available to module as the current buddy's
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
142 message.
1624
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
143 - hook-my-status-change (HOOK_MY_STATUS_CHANGE) with
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
144 parameters
1619
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
145 * new_status - user's new status, see
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
146 hook-status-change. Old one should still be
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
147 available as the current status of the user.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
148 * message - new status message
1624
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
149 - hook-post-connect (HOOK_INTERNAL) with no parameters
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
150 - hook-pre-disconnect (HOOK_INTERNAL) with no
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
151 parameters
1619
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
152
1624
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
153 --------------------------------------------------------
1619
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
154 #include "xmpp_helper.h"
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
155
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
156 void xmpp_add_feature (const char *xmlns);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
157 void xmpp_del_feature (const char *xmlns);
1624
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
158 --------------------------------------------------------
1619
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
159
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
160 These functions may be useful, if your module implements
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
161 some additional functionality to mcabber, that should be
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
162 advertised in a client's discovery features list.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
163
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
164 =====================
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
165
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
166 Example: hello
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
167
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
168 =====================
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
169
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
170 Now, let's write a simple module, called "hello", that
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
171 will do no more than just print something on loading
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
172 and unloading.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
173
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
174 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
175 #include <glib.h>
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
176 #include <gmodule.h>
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
177
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
178 /* We will use scr_LogPrint mcabber function,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
179 that does mcabber's messages output */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
180 #include "logprint.h"
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
181
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
182 /* Print something on module loading */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
183 const gchar* g_module_check_init (GModule *module)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
184 {
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
185 scr_LogPrint (LPRINT_LOGNORM, "Hello, World!");
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
186 return NULL;
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
187 }
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
188
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
189 /* ... and unloading */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
190 void g_module_unload (GModule *module)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
191 {
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
192 scr_LogPrint (LPRINT_LOGNORM, "Bye, World!");
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
193 }
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
194
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
195 /* The End */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
196 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
197
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
198 Now, compile this file (hello.c) with
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
199
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
200 libtool --mode=compile gcc `pkg-config --cflags glib-2.0 \
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
201 gmodule-2.0` -c hello.c
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
202 libtool --mode=link gcc -module -rpath /usr/lib/mcabber/ \
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
203 `pkg-config --libs glib-2.0 gmodule-2.0` -o libhello.la \
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
204 hello.lo
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
205
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
206 (you should substitute /usr/lib/mcabber to directory, where
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
207 your modules are located) and then install obtained module with
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
208
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
209 libtool --mode=install install libhello.la \
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
210 /usr/lib/mcabber/libhello.la
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
211
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
212 Note, that you, most likely need not run suggested by libtool
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
213 finish action, as we're working with module object, not system-
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
214 wide library, but maybe some systems require that.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
215
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
216 Now, set modules_dir mcabber variable to point to your modules
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
217 dir, and try to run /load hello. If all goes well, you should
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
218 see in status buffer message "Hello World!".
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
219 Now unload module by running command /unload hello, that
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
220 should bring up message "Bye, World!".
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
221
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
222 That's it, you just created very simple dynamically loadable
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
223 mcabber module.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
224
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
225 =======================
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
226
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
227 Example: command
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
228
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
229 =======================
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
230
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
231 Now, let's allow our module to do some real work.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
232
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
233 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
234 #include <glib.h>
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
235 #include <gmodule.h>
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
236
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
237 #include "logprint.h"
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
238 #include "commands.h"
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
239
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
240 /* Handler for command */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
241 void do_hello (char *args)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
242 {
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
243 /* args contains command line with command
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
244 * name and any spaces after it stripped */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
245 scr_LogPrint (LPRINT_LOGNORM, "Hello, %s!",
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
246 *args != '\0' ? args : "World");
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
247 }
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
248
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
249 /* Register command */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
250 const gchar* g_module_check_init (GModule *module)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
251 {
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
252 cmd_add ("hello", "", 0, 0, do_hello, NULL);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
253 return NULL;
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
254 }
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
255
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
256 /* Unregister command */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
257 void g_module_unload (GModule *module)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
258 {
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
259 cmd_del ("hello");
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
260 }
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
261
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
262 /* The End */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
263 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
264
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
265 There we will need also config.h with defined MODULES_ENABLE
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
266 to satisfy ifdefs in commands.h. You can get one from mcabber
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
267 build tree, generated by configure or just provide your own:
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
268
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
269 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
270 #ifndef LOCAL_CONFIG_H
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
271 #define LOCAL_CONFIG_H
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
272
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
273 #define MODULES_ENABLE 1
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
274
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
275 #endif
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
276 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
277
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
278 Now, compile it and try to load and run /hello with some
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
279 arguments.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
280
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
281 Note, that we used one-argument version of command
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
282 handler, as we specified no userdata.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
283
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
284 ==========================
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
285
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
286 Example: completion
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
287
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
288 ==========================
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
289
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
290 Now le's investigate how to provide custom completion to
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
291 your commands. You can as well use built-in completions,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
292 their IDs are listed in compl.h.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
293
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
294 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
295 #include <glib.h>
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
296 #include <gmodule.h>
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
297
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
298 #include "logprint.h"
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
299 #include "commands.h"
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
300 #include "compl.h"
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
301
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
302 static guint hello_cid = 0;
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
303
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
304 /* hello command handler */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
305 void do_hello (char *args)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
306 {
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
307 /* If argument is provided, add it to
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
308 * completions list. */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
309 if (hello_cid && *args != '\0')
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
310 compl_add_category_word (hello_cid,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
311 args);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
312 scr_LogPrint (LPRINT_LOGNORM, "Hello, %s!",
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
313 *args != '\0' ? args : "World");
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
314 }
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
315
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
316 /* Initialization */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
317 const gchar* g_module_check_init (GModule *module)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
318 {
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
319 /* Obtain handle for our completion
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
320 * category */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
321 hello_cid = compl_new_category ();
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
322 if (hello_cid)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
323 /* Add known default word to
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
324 * completion list */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
325 compl_add_category_word (hello_cid,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
326 "World");
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
327 cmd_add ("hello", "", hello_cid, 0, do_hello,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
328 NULL);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
329 return NULL;
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
330 }
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
331
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
332 /* Deinitialization */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
333 void g_module_unload (GModule *module)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
334 {
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
335 /* Give back category handle */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
336 if (hello_cid)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
337 compl_del_category (hello_cid);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
338 cmd_del ("hello");
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
339 }
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
340
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
341 /* The End */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
342 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
343
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
344 Now you can use completion for hello command. Note, that
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
345 this code have some serious simplifications, made for
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
346 simplicity reasons. For now, compl_add_category_word
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
347 does not checks, if word already exists in completions
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
348 list (although it is marked as TODO, so, some day it
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
349 will), so, we should check it ourselves. Also, we should
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
350 check, that args contains only one word, or this will
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
351 confuse completion system, so, it will stop on this
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
352 completion.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
353
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
354 =====================
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
355
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
356 Example: hooks
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
357
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
358 =====================
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
359
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
360 Now let's implement our own beeper. Why anyone may wish
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
361 to do this? I am not satisfied with default mcabber's
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
362 builtin beeper flexibility. I wanted beeping on any
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
363 muc conference message, not just ones, directed to me.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
364
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
365 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
366 #include <glib.h>
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
367 #include <gmodule.h>
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
368 #include <string.h>
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
369
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
370 #include "logprint.h"
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
371 #include "commands.h"
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
372 #include "compl.h"
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
373 #include "hooks.h"
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
374 #include "screen.h"
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
375 #include "settings.h"
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
376
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
377 static guint beep_cid = 0;
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
378
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
379 /* Event handler */
1624
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
380 void beep_hh (guint32 hid, hk_arg_t *args, gpointer userdata)
1619
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
381 {
1624
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
382 /* Check if beeping is enabled */
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
383 if (settings_opt_get_int ("beep_enable"))
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
384 /* *BEEP*! */
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
385 scr_Beep ();
1619
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
386 }
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
387
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
388 /* beep command handler */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
389 void do_beep (char *args)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
390 {
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
391 /* Check arguments, and if recognized,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
392 * set mcabber option accordingly */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
393 if (!strcmp (args, "enable") ||
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
394 !strcmp (args, "on") ||
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
395 !strcmp (args, "yes") ||
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
396 !strcmp (args, "1"))
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
397 settings_set (SETTINGS_TYPE_OPTION,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
398 "beep_enable", "1");
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
399 else if (!strcmp (args, "disable") ||
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
400 !strcmp (args, "off") ||
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
401 !strcmp (args, "no") ||
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
402 !strcmp (args, "0"))
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
403 settings_set (SETTINGS_TYPE_OPTION,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
404 "beep_enable", "0");
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
405
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
406 /* Output current state, either if state is
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
407 * changed and if argument is not recognized */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
408 if (settings_opt_get_int ("beep_enable"))
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
409 scr_LogPrint (LPRINT_NORMAL,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
410 "Beep on messages is enabled");
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
411 else
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
412 scr_LogPrint (LPRINT_NORMAL,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
413 "Beep on messages is disabled");
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
414 }
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
415
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
416 /* Initialization */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
417 const gchar* g_module_check_init (GModule *module)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
418 {
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
419 /* Create completions */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
420 beep_cid = compl_new_category ();
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
421 if (beep_cid) {
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
422 compl_add_category_word (beep_cid, "enable");
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
423 compl_add_category_word (beep_cid, "disable");
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
424 }
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
425 /* Add command */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
426 cmd_add ("beep", "", beep_cid, 0, do_beep, NULL);
1624
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
427 /* Add handler
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
428 * We are only interested in incoming message events
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
429 */
a75611931642 Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1619
diff changeset
430 hk_add_handler (beep_hh, HOOK_MESSAGE_IN, NULL);
1619
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
431 return NULL;
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
432 }
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
433
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
434 /* Deinitialization */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
435 void g_module_unload (GModule *module)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
436 {
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
437 /* Unregister event handler */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
438 hk_del_handler (beep_hh, NULL);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
439 /* Unregister command */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
440 cmd_del ("beep");
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
441 /* Give back completion handle */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
442 if (beep_cid)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
443 compl_del_category (beep_cid);
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
444 }
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
445
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
446 /* The End */
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
447 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
448
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
449 As you can see, here we used the fact, that right now
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
450 all the hooks provide "hook" argument as a first element
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
451 in args, however this can change in future.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
452
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
453 Note, that to compile this we also need to add loudmouth-1.0
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
454 to pkg-config command line and to add -I. to compilation
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
455 mode gcc command line (specify include directory with our
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
456 config.h as system include directory), so, you will have
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
457 something like
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
458
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
459 libtool --mode=compile gcc `pkg-config --cflags glib-2.0 \
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
460 gmodule-2.0 loudmouth-1.0` -I. -c beep.c
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
461 libtool --mode=link gcc -module -rpath /usr/lib/mcabber/ \
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
462 `pkg-config --cflags glib-2.0 gmodule-2.0 loudmouth-1.0` \
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
463 -o libbeep.la beep.lo
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
464 libtool --mode=install install libbeep.la \
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
465 /usr/lib/mcabber/libbeep.la
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
466
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
467 If you use CMake (as do I), corresponding CMakeLists.txt
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
468 snippet:
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
469
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
470 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
471 cmake_minimum_required(VERSION 2.6)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
472 project(beep C)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
473
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
474 add_library(beep MODULE beep.c)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
475
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
476 set(MCABBER_INCLUDE_DIR "${beep_SOURCE_DIR}/include"
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
477 CACHE FILEPATH "Path to mcabber headers")
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
478
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
479 find_package(PkgConfig REQUIRED)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
480 pkg_check_modules(GLIB REQUIRED glib-2.0)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
481 pkg_check_modules(GMODULE REQUIRED gmodule-2.0)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
482 pkg_check_modules(LM REQUIRED loudmouth-1.0)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
483
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
484 include_directories(SYSTEM ${GLIB_INCLUDE_DIRS}
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
485 ${GMODULE_INCLUDE_DIRS}
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
486 ${LM_INCLUDE_DIRS})
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
487 target_link_libraries(beep ${GLIB_LIBRARIES}
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
488 ${GMODULE_LIBRARIES})
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
489 include_directories(${beep_SOURCE_DIR}
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
490 ${beep_BINARY_DIR}
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
491 ${MCABBER_INCLUDE_DIR})
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
492
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
493 install(TARGETS beep DESTINATION lib/mcabber)
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
494 --------------------------------------------------------
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
495
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
496 ==============
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
497
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
498 Further
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
499
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
500 ==============
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
501
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
502 As mcabber-lm uses glib mainloop, you can use glib's
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
503 event sources, for example, fifo reading can be easily
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
504 modularized with GIOChannels.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
505
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
506 You can extend xmpp part of mcabber functionality by
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
507 providing lm message handlers with high priority and
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
508 allowing unhandled by your handler messages be taken
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
509 care by mcabber's handlers on normal priority level.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
510 This is where you may need to modify set of advertised
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
511 supported disco features.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
512
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
513 Many useful examples can be found in my mcabber-lua
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
514 module.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
515
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
516 If you think, that your module needs to change
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
517 something, hardcoded in current implementation - feel
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
518 free to mail me or join mcabber's MUC room and
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
519 discuss this - for now I have only implemented things,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
520 that I found necessary for mcabber-lua module.
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
521
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
522 Also I am not native English speaker, so, if you find
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
523 some errors or non-natural constructs in this howto,
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
524 please, inform me (I will be glad, if you also provide
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
525 a more suitable version of text in question).
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
526
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
527 -- Myhailo Danylenko <isbear@ukrpost.net>
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
528 -- Mon, 05 Oct 2009 00:00:00 +0300
2a82e6654c04 Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
529