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