Mercurial > hg
annotate mcabber/doc/HOWTO_modules.txt @ 1669:004739237999
Update modules howto
author | Myhailo Danylenko <isbear@ukrpost.net> |
---|---|
date | Mon, 18 Jan 2010 15:53:20 +0200 |
parents | e3b93594ee6c |
children | b09f82f61745 |
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 -------------------------------------------------------- |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
31 #include <mcabber/commands.h> |
1619
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 -------------------------------------------------------- |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
56 #include <mcabber/compl.h> |
1619
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 -------------------------------------------------------- |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
89 #include <mcabber/hooks.h> |
1619
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 -------------------------------------------------------- |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
156 #include <mcabber/xmpp_helper.h> |
1619
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 */ |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
182 #include <mcabber/logprint.h> |
1619
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 { |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
187 scr_LogPrint (LPRINT_NORMAL, "Hello, World!"); |
1619
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 { |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
194 scr_LogPrint (LPRINT_NORMAL, "Bye, World!"); |
1619
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 |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
239 #include <mcabber/logprint.h> |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
240 #include <mcabber/commands.h> |
1619
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 */ |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
247 scr_LogPrint (LPRINT_NORMAL, "Hello, %s!", |
1619
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 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
|
268 arguments. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
269 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
270 Note, that we used one-argument version of command |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
271 handler, as we specified no userdata. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
272 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
273 ========================== |
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 Example: completion |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
276 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
277 ========================== |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
278 |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
279 Now let's investigate how to provide custom completion to |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
280 your commands. You can as well use built-in completions, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
281 their IDs are listed in compl.h. |
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 -------------------------------------------------------- |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
284 #include <glib.h> |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
285 #include <gmodule.h> |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
286 |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
287 #include <mcabber/logprint.h> |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
288 #include <mcabber/commands.h> |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
289 #include <mcabber/compl.h> |
1619
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 static guint hello_cid = 0; |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
292 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
293 /* hello command handler */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
294 void do_hello (char *args) |
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 /* If argument is provided, add it to |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
297 * completions list. */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
298 if (hello_cid && *args != '\0') |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
299 compl_add_category_word (hello_cid, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
300 args); |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
301 scr_LogPrint (LPRINT_NORMAL, "Hello, %s!", |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
302 *args != '\0' ? args : "World"); |
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 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
305 /* Initialization */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
306 const gchar* g_module_check_init (GModule *module) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
307 { |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
308 /* Obtain handle for our completion |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
309 * category */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
310 hello_cid = compl_new_category (); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
311 if (hello_cid) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
312 /* Add known default word to |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
313 * completion list */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
314 compl_add_category_word (hello_cid, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
315 "World"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
316 cmd_add ("hello", "", hello_cid, 0, do_hello, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
317 NULL); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
318 return NULL; |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
319 } |
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 /* Deinitialization */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
322 void g_module_unload (GModule *module) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
323 { |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
324 /* Give back category handle */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
325 if (hello_cid) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
326 compl_del_category (hello_cid); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
327 cmd_del ("hello"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
328 } |
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 /* The End */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
331 -------------------------------------------------------- |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
332 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
333 Now you can use completion for hello command. Note, that |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
334 this code have some serious simplifications, made for |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
335 simplicity reasons. For now, compl_add_category_word |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
336 does not checks, if word already exists in completions |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
337 list (although it is marked as TODO, so, some day it |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
338 will), so, we should check it ourselves. |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
339 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
340 ===================== |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
341 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
342 Example: hooks |
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 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
|
347 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
|
348 builtin beeper flexibility. I wanted beeping on any |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
349 muc conference message, not just ones, directed to me. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
350 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
351 -------------------------------------------------------- |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
352 #include <glib.h> |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
353 #include <gmodule.h> |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
354 #include <string.h> |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
355 |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
356 #include <mcabber/logprint.h> |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
357 #include <mcabber/commands.h> |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
358 #include <mcabber/compl.h> |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
359 #include <mcabber/hooks.h> |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
360 #include <mcabber/screen.h> |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
361 #include <mcabber/settings.h> |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
362 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
363 static guint beep_cid = 0; |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
364 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
365 /* Event handler */ |
1624
a75611931642
Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1619
diff
changeset
|
366 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
|
367 { |
1624
a75611931642
Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1619
diff
changeset
|
368 /* Check if beeping is enabled */ |
a75611931642
Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1619
diff
changeset
|
369 if (settings_opt_get_int ("beep_enable")) |
a75611931642
Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1619
diff
changeset
|
370 /* *BEEP*! */ |
a75611931642
Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1619
diff
changeset
|
371 scr_Beep (); |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
372 } |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
373 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
374 /* beep command handler */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
375 void do_beep (char *args) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
376 { |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
377 /* Check arguments, and if recognized, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
378 * set mcabber option accordingly */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
379 if (!strcmp (args, "enable") || |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
380 !strcmp (args, "on") || |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
381 !strcmp (args, "yes") || |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
382 !strcmp (args, "1")) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
383 settings_set (SETTINGS_TYPE_OPTION, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
384 "beep_enable", "1"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
385 else if (!strcmp (args, "disable") || |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
386 !strcmp (args, "off") || |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
387 !strcmp (args, "no") || |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
388 !strcmp (args, "0")) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
389 settings_set (SETTINGS_TYPE_OPTION, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
390 "beep_enable", "0"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
391 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
392 /* Output current state, either if state is |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
393 * changed and if argument is not recognized */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
394 if (settings_opt_get_int ("beep_enable")) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
395 scr_LogPrint (LPRINT_NORMAL, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
396 "Beep on messages is enabled"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
397 else |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
398 scr_LogPrint (LPRINT_NORMAL, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
399 "Beep on messages is disabled"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
400 } |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
401 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
402 /* Initialization */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
403 const gchar* g_module_check_init (GModule *module) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
404 { |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
405 /* Create completions */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
406 beep_cid = compl_new_category (); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
407 if (beep_cid) { |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
408 compl_add_category_word (beep_cid, "enable"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
409 compl_add_category_word (beep_cid, "disable"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
410 } |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
411 /* Add command */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
412 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
|
413 /* Add handler |
a75611931642
Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1619
diff
changeset
|
414 * We are only interested in incoming message events |
a75611931642
Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1619
diff
changeset
|
415 */ |
a75611931642
Hook handler flags updates to howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1619
diff
changeset
|
416 hk_add_handler (beep_hh, HOOK_MESSAGE_IN, NULL); |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
417 return NULL; |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
418 } |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
419 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
420 /* Deinitialization */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
421 void g_module_unload (GModule *module) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
422 { |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
423 /* Unregister event handler */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
424 hk_del_handler (beep_hh, NULL); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
425 /* Unregister command */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
426 cmd_del ("beep"); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
427 /* Give back completion handle */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
428 if (beep_cid) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
429 compl_del_category (beep_cid); |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
430 } |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
431 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
432 /* The End */ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
433 -------------------------------------------------------- |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
434 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
435 Note, that to compile this we also need to add loudmouth-1.0 |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
436 to pkg-config command line, so, you will have something like |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
437 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
438 libtool --mode=compile gcc `pkg-config --cflags glib-2.0 \ |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
439 gmodule-2.0 loudmouth-1.0` -c beep.c |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
440 libtool --mode=link gcc -module -rpath /usr/lib/mcabber/ \ |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
441 `pkg-config --cflags glib-2.0 gmodule-2.0` -o libbeep.la \ |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
442 beep.lo |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
443 libtool --mode=install install libbeep.la \ |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
444 /usr/lib/mcabber/libbeep.la |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
445 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
446 If you use CMake (as do I), corresponding CMakeLists.txt |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
447 snippet: |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
448 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
449 -------------------------------------------------------- |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
450 cmake_minimum_required(VERSION 2.6) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
451 project(beep C) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
452 |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
453 set(MCABBER_INCLUDE_DIR "/usr/include" CACHE FILEPATH |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
454 "Path to mcabber headers") |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
455 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
456 find_package(PkgConfig REQUIRED) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
457 pkg_check_modules(GLIB REQUIRED glib-2.0) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
458 pkg_check_modules(GMODULE REQUIRED gmodule-2.0) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
459 pkg_check_modules(LM REQUIRED loudmouth-1.0) |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
460 # this one should be before any target definitions |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
461 link_directories(${GLIB_LIBRARY_DIRS} |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
462 ${GMODULE_LIBRARY_DIRS}) |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
463 |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
464 add_library(beep MODULE beep.c) |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
465 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
466 include_directories(SYSTEM ${GLIB_INCLUDE_DIRS} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
467 ${GMODULE_INCLUDE_DIRS} |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
468 ${LM_INCLUDE_DIRS} |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
469 ${MCABBER_INCLUDE_DIR}) |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
470 target_link_libraries(beep ${GLIB_LIBRARIES} |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
471 ${GMODULE_LIBRARIES}) |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
472 include_directories(${beep_SOURCE_DIR} |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
473 ${beep_BINARY_DIR}) |
1619
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 install(TARGETS beep DESTINATION lib/mcabber) |
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 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
478 ============== |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
479 |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
480 Further |
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 ============== |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
483 |
1625 | 484 As mcabber now uses glib mainloop, you can use glib's |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
485 event sources, for example, fifo reading already uses |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
486 GIOChannels for non-blocking IO. |
1619
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 You can extend xmpp part of mcabber functionality by |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
489 providing lm message handlers with high priority and |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
490 allowing unhandled by your handler messages be taken |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
491 care by mcabber's handlers on normal priority level. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
492 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
|
493 supported disco features. |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
494 |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
495 Many useful examples can be found in my modules, that |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
496 can be found at http://isbear.unixzone.org.ua/source. |
1619
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 If you think, that your module needs to change |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
499 something, hardcoded in current implementation - feel |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
500 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
|
501 discuss this - for now I have only implemented things, |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
502 that I found necessary for written by me modules. |
1619
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 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
|
505 some errors or non-natural constructs in this howto, |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
506 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
|
507 a more suitable version of text in question). |
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
508 |
1669
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
509 -- Myhailo Danylenko |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
510 -- mailto:isbear@ukrpost.net |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
511 -- xmpp:isbear@unixzone.org.ua |
004739237999
Update modules howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1625
diff
changeset
|
512 -- Mon, 18 Jan 2010 15:52:40 +0200 |
1619
2a82e6654c04
Add a module writing howto
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
513 |