Mercurial > hg
annotate mcabber/doc/HOWTO_modules.txt @ 1619:2a82e6654c04
Add a module writing howto
author | Myhailo Danylenko <isbear@ukrpost.net> |
---|---|
date | Mon, 12 Oct 2009 21:31:15 +0200 |
parents | |
children | a75611931642 |
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 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
94 typedef void (*hk_handler_t) (hk_arg_t *args, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
95 gpointer userdata); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
96 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
97 void hk_add_handler (hk_handler_t handler, |
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 void hk_del_handler (hk_handler_t handler, |
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 -------------------------------------------------------- |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
102 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
103 These functions allow your module to react to events, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
104 such as incoming and outgoing messages, buddy status |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
105 changes and sever connection establishment or breakup. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
106 In fact, you specify only one handler (well, you can |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
107 specify as many, as you want, but they all will be |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
108 called on any event, that will occur). Which event is |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
109 occured can be determined from args, which is a list of |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
110 hk_arg_t structures, terminated with structure, whose |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
111 name field is set to NULL. Event type is specified in |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
112 the structure with name set to "hook". Usually this is |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
113 the first structure of the list, however it is not |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
114 guaranted, that this will be so forever. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
115 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
116 Currently there are next events possible: |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
117 - hook-message-in with parameters |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
118 * jid - sender of the incoming message |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
119 * message - message body, converted to locale |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
120 charset |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
121 * groupchat ("true" or "false") |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
122 - hook-message-out with parameters |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
123 * jid - recipient of the outgoing 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 - hook-status-change wih parameters |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
127 * jid - buddy, whose status has changed |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
128 * resource - resource, whose status has changed |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
129 * old_status - old status of the buddy, one-char |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
130 string, representing mcabber status letter - |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
131 one of 'ofdna?_'. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
132 * new_status - new buddy status. The same as |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
133 old_status. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
134 * message - new status message. Old one should be |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
135 still available to module as the current buddy's |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
136 message. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
137 - hook-my-status-change with parameters |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
138 * new_status - user's new status, see |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
139 hook-status-change. Old one should still be |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
140 available as the current status of the user. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
141 * message - new status message |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
142 - hook-post-connect with no parameters |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
143 - hook-pre-disconnect with no parameters |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
144 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
145 #include "xmpp_helper.h" |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
146 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
147 void xmpp_add_feature (const char *xmlns); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
148 void xmpp_del_feature (const char *xmlns); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
149 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
150 These functions may be useful, if your module implements |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
151 some additional functionality to mcabber, that should be |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
152 advertised in a client's discovery features list. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
153 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
154 ===================== |
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 Example: hello |
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 ===================== |
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 Now, let's write a simple module, called "hello", that |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
161 will do no more than just print something on loading |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
162 and unloading. |
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 #include <glib.h> |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
166 #include <gmodule.h> |
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 /* We will use scr_LogPrint mcabber function, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
169 that does mcabber's messages output */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
170 #include "logprint.h" |
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 /* Print something on module loading */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
173 const gchar* g_module_check_init (GModule *module) |
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 scr_LogPrint (LPRINT_LOGNORM, "Hello, World!"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
176 return NULL; |
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 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
179 /* ... and unloading */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
180 void g_module_unload (GModule *module) |
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 scr_LogPrint (LPRINT_LOGNORM, "Bye, World!"); |
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 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
185 /* The End */ |
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 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
188 Now, compile this file (hello.c) with |
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 libtool --mode=compile gcc `pkg-config --cflags glib-2.0 \ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
191 gmodule-2.0` -c hello.c |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
192 libtool --mode=link gcc -module -rpath /usr/lib/mcabber/ \ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
193 `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
|
194 hello.lo |
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 (you should substitute /usr/lib/mcabber to directory, where |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
197 your modules are located) and then install obtained module with |
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 libtool --mode=install install libhello.la \ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
200 /usr/lib/mcabber/libhello.la |
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 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
|
203 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
|
204 wide library, but maybe some systems require that. |
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 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
|
207 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
|
208 see in status buffer message "Hello World!". |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
209 Now unload module by running command /unload hello, that |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
210 should bring up message "Bye, World!". |
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 That's it, you just created very simple dynamically loadable |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
213 mcabber module. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
214 |
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 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
217 Example: command |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
218 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
219 ======================= |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
220 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
221 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
|
222 |
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 #include <glib.h> |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
225 #include <gmodule.h> |
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 #include "logprint.h" |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
228 #include "commands.h" |
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 /* Handler for command */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
231 void do_hello (char *args) |
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 /* args contains command line with command |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
234 * name and any spaces after it stripped */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
235 scr_LogPrint (LPRINT_LOGNORM, "Hello, %s!", |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
236 *args != '\0' ? args : "World"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
237 } |
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 /* Register command */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
240 const gchar* g_module_check_init (GModule *module) |
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 cmd_add ("hello", "", 0, 0, do_hello, NULL); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
243 return NULL; |
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 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
246 /* Unregister command */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
247 void g_module_unload (GModule *module) |
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 cmd_del ("hello"); |
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 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
252 /* The End */ |
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 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
255 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
|
256 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
|
257 build tree, generated by configure or just provide your own: |
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 -------------------------------------------------------- |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
260 #ifndef LOCAL_CONFIG_H |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
261 #define LOCAL_CONFIG_H |
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 #define MODULES_ENABLE 1 |
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 #endif |
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 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
268 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
|
269 arguments. |
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 Note, that we used one-argument version of command |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
272 handler, as we specified no userdata. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
273 |
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 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
276 Example: completion |
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 ========================== |
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 le's investigate how to provide custom completion to |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
281 your commands. You can as well use built-in completions, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
282 their IDs are listed in compl.h. |
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 #include <glib.h> |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
286 #include <gmodule.h> |
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 #include "logprint.h" |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
289 #include "commands.h" |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
290 #include "compl.h" |
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 static guint hello_cid = 0; |
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 /* hello command handler */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
295 void do_hello (char *args) |
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 /* If argument is provided, add it to |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
298 * completions list. */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
299 if (hello_cid && *args != '\0') |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
300 compl_add_category_word (hello_cid, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
301 args); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
302 scr_LogPrint (LPRINT_LOGNORM, "Hello, %s!", |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
303 *args != '\0' ? args : "World"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
304 } |
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 /* Initialization */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
307 const gchar* g_module_check_init (GModule *module) |
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 /* Obtain handle for our completion |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
310 * category */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
311 hello_cid = compl_new_category (); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
312 if (hello_cid) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
313 /* Add known default word to |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
314 * completion list */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
315 compl_add_category_word (hello_cid, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
316 "World"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
317 cmd_add ("hello", "", hello_cid, 0, do_hello, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
318 NULL); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
319 return NULL; |
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 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
322 /* Deinitialization */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
323 void g_module_unload (GModule *module) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
324 { |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
325 /* Give back category handle */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
326 if (hello_cid) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
327 compl_del_category (hello_cid); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
328 cmd_del ("hello"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
329 } |
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 /* The End */ |
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 Now you can use completion for hello command. Note, that |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
335 this code have some serious simplifications, made for |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
336 simplicity reasons. For now, compl_add_category_word |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
337 does not checks, if word already exists in completions |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
338 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
|
339 will), so, we should check it ourselves. Also, we should |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
340 check, that args contains only one word, or this will |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
341 confuse completion system, so, it will stop on this |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
342 completion. |
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 ===================== |
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 Example: hooks |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
347 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
348 ===================== |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
349 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
350 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
|
351 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
|
352 builtin beeper flexibility. I wanted beeping on any |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
353 muc conference message, not just ones, directed to me. |
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 #include <glib.h> |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
357 #include <gmodule.h> |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
358 #include <string.h> |
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 #include "logprint.h" |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
361 #include "commands.h" |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
362 #include "compl.h" |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
363 #include "hooks.h" |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
364 #include "screen.h" |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
365 #include "settings.h" |
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 static guint beep_cid = 0; |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
368 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
369 /* Event handler */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
370 void beep_hh (hk_arg_t *args, gpointer userdata) |
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 /* We are interested only in incoming |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
373 * message events */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
374 if (!strcmp (args[0].value, "hook-message-in")) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
375 /* Check if beeping is enabled */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
376 if (settings_opt_get_int ("beep_enable")) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
377 /* *BEEP*! */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
378 scr_Beep (); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
379 } |
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 /* beep command handler */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
382 void do_beep (char *args) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
383 { |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
384 /* Check arguments, and if recognized, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
385 * set mcabber option accordingly */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
386 if (!strcmp (args, "enable") || |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
387 !strcmp (args, "on") || |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
388 !strcmp (args, "yes") || |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
389 !strcmp (args, "1")) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
390 settings_set (SETTINGS_TYPE_OPTION, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
391 "beep_enable", "1"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
392 else if (!strcmp (args, "disable") || |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
393 !strcmp (args, "off") || |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
394 !strcmp (args, "no") || |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
395 !strcmp (args, "0")) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
396 settings_set (SETTINGS_TYPE_OPTION, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
397 "beep_enable", "0"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
398 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
399 /* Output current state, either if state is |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
400 * changed and if argument is not recognized */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
401 if (settings_opt_get_int ("beep_enable")) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
402 scr_LogPrint (LPRINT_NORMAL, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
403 "Beep on messages is enabled"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
404 else |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
405 scr_LogPrint (LPRINT_NORMAL, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
406 "Beep on messages is disabled"); |
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 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
409 /* Initialization */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
410 const gchar* g_module_check_init (GModule *module) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
411 { |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
412 /* Create completions */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
413 beep_cid = compl_new_category (); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
414 if (beep_cid) { |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
415 compl_add_category_word (beep_cid, "enable"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
416 compl_add_category_word (beep_cid, "disable"); |
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 /* Add command */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
419 cmd_add ("beep", "", beep_cid, 0, do_beep, NULL); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
420 /* Add handler */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
421 hk_add_handler (beep_hh, NULL); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
422 return NULL; |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
423 } |
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 /* Deinitialization */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
426 void g_module_unload (GModule *module) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
427 { |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
428 /* Unregister event handler */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
429 hk_del_handler (beep_hh, NULL); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
430 /* Unregister command */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
431 cmd_del ("beep"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
432 /* Give back completion handle */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
433 if (beep_cid) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
434 compl_del_category (beep_cid); |
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 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
437 /* The End */ |
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 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
440 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
|
441 all the hooks provide "hook" argument as a first element |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
442 in args, however this can change in future. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
443 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
444 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
|
445 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
|
446 mode gcc command line (specify include directory with our |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
447 config.h as system include directory), so, you will have |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
448 something like |
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 libtool --mode=compile gcc `pkg-config --cflags glib-2.0 \ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
451 gmodule-2.0 loudmouth-1.0` -I. -c beep.c |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
452 libtool --mode=link gcc -module -rpath /usr/lib/mcabber/ \ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
453 `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
|
454 -o libbeep.la beep.lo |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
455 libtool --mode=install install libbeep.la \ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
456 /usr/lib/mcabber/libbeep.la |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
457 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
458 If you use CMake (as do I), corresponding CMakeLists.txt |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
459 snippet: |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
460 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
461 -------------------------------------------------------- |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
462 cmake_minimum_required(VERSION 2.6) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
463 project(beep C) |
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 add_library(beep MODULE beep.c) |
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 set(MCABBER_INCLUDE_DIR "${beep_SOURCE_DIR}/include" |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
468 CACHE FILEPATH "Path to mcabber headers") |
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 find_package(PkgConfig REQUIRED) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
471 pkg_check_modules(GLIB REQUIRED glib-2.0) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
472 pkg_check_modules(GMODULE REQUIRED gmodule-2.0) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
473 pkg_check_modules(LM REQUIRED loudmouth-1.0) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
474 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
475 include_directories(SYSTEM ${GLIB_INCLUDE_DIRS} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
476 ${GMODULE_INCLUDE_DIRS} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
477 ${LM_INCLUDE_DIRS}) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
478 target_link_libraries(beep ${GLIB_LIBRARIES} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
479 ${GMODULE_LIBRARIES}) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
480 include_directories(${beep_SOURCE_DIR} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
481 ${beep_BINARY_DIR} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
482 ${MCABBER_INCLUDE_DIR}) |
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 install(TARGETS beep DESTINATION lib/mcabber) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
485 -------------------------------------------------------- |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
486 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
487 ============== |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
488 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
489 Further |
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 ============== |
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 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
|
494 event sources, for example, fifo reading can be easily |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
495 modularized with GIOChannels. |
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 You can extend xmpp part of mcabber functionality by |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
498 providing lm message handlers with high priority and |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
499 allowing unhandled by your handler messages be taken |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
500 care by mcabber's handlers on normal priority level. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
501 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
|
502 supported disco features. |
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 Many useful examples can be found in my mcabber-lua |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
505 module. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
506 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
507 If you think, that your module needs to change |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
508 something, hardcoded in current implementation - feel |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
509 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
|
510 discuss this - for now I have only implemented things, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
511 that I found necessary for mcabber-lua module. |
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 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
|
514 some errors or non-natural constructs in this howto, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
515 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
|
516 a more suitable version of text in question). |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
517 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
518 -- Myhailo Danylenko <isbear@ukrpost.net> |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
519 -- Mon, 05 Oct 2009 00:00:00 +0300 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
520 |