annotate mcabber/mcabber/events.c @ 2239:7625a42eb8a9

Fix event source not being properly initialized Thanks to Holger WeiƟ and Myhailo Danylenko.
author Mikael Berthe <mikael@lilotux.net>
date Tue, 24 Nov 2015 18:58:45 +0100
parents 33483d3324cf
children f5402d705f67
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
1 /*
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
2 * events.c -- Events fonctions
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
3 *
1901
84bb3e893586 Update some file headers
Mikael Berthe <mikael@lilotux.net>
parents: 1868
diff changeset
4 * Copyright (C) 2006-2010 Mikael Berthe <mikael@lilotux.net>
2019
33483d3324cf s/Copyrigth/Copyright/ and so on
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1901
diff changeset
5 * Copyright (C) 2010 Myhailo Danylenko <isbear@ukrpost.net>
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
6 *
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or (at
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
10 * your option) any later version.
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
11 *
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
15 * General Public License for more details.
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
16 *
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
20 * USA
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
21 */
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
22
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
23 #include <glib.h>
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1414
diff changeset
24 #include <string.h>
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
25 #include "events.h"
1868
fdb2f88b908b /event list sets the message flag when the list is long
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
26 #include "screen.h"
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
27
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
28 typedef struct {
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
29 char *id;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
30 char *description;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
31 time_t timeout;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
32 guint source;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
33 evs_callback_t callback;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
34 gpointer data;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
35 GDestroyNotify notify;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
36 } evs_t;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
37
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
38 static GSList *evs_list; // Events list
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
39
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
40 static evs_t *evs_find(const char *evid);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
41
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
42 static gboolean evs_check_timeout (gpointer userdata)
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
43 {
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
44 evs_t *event = userdata;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
45 if (event->callback &&
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
46 !event->callback(EVS_CONTEXT_TIMEOUT, NULL, event->data)) {
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
47 evs_del(event->id);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
48 return FALSE;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
49 }
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
50 return TRUE; // XXX
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
51 }
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
52
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
53 // evs_new(type, timeout)
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
54 // Create new event. If id is omitted, generates unique
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
55 // numerical id (recommended). If timeout is specified, sets
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
56 // up timeout source, that will call handler in timeout
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
57 // context after specified number of seconds. If supplied id
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
58 // already exists, returns NULL, calling destroy notifier, if
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
59 // one is specified.
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
60 const char *evs_new(const char *desc, const char *id, time_t timeout, evs_callback_t callback, gpointer udata, GDestroyNotify notify)
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
61 {
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
62 static guint evs_idn;
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
63 evs_t *event;
751
4a7271e69694 Avoid reusing events ids
Mikael Berthe <mikael@lilotux.net>
parents: 746
diff changeset
64 char *stridn;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
65
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
66 if (!id) {
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
67 if (!++evs_idn)
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
68 evs_idn = 1;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
69 /* Check for wrapping, we shouldn't reuse ids */
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
70 stridn = g_strdup_printf("%d", evs_idn);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
71 if (evs_find(stridn)) {
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
72 g_free(stridn);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
73 // We could try another id but for now giving up should be fine...
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
74 if (notify)
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
75 notify(udata);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
76 return NULL;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
77 }
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
78 } else if (!evs_find(id))
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
79 stridn = g_strdup(id);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
80 else {
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
81 if (notify)
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
82 notify(udata);
751
4a7271e69694 Avoid reusing events ids
Mikael Berthe <mikael@lilotux.net>
parents: 746
diff changeset
83 return NULL;
4a7271e69694 Avoid reusing events ids
Mikael Berthe <mikael@lilotux.net>
parents: 746
diff changeset
84 }
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
85
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
86 event = g_new(evs_t, 1);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
87
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
88 event->id = stridn;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
89 event->description = g_strdup(desc);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
90 event->timeout = timeout;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
91 event->callback = callback;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
92 event->data = udata;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
93 event->notify = notify;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
94
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
95 if (timeout)
2239
7625a42eb8a9 Fix event source not being properly initialized
Mikael Berthe <mikael@lilotux.net>
parents: 2019
diff changeset
96 event->source = g_timeout_add_seconds(timeout, evs_check_timeout, event);
7625a42eb8a9 Fix event source not being properly initialized
Mikael Berthe <mikael@lilotux.net>
parents: 2019
diff changeset
97 else
7625a42eb8a9 Fix event source not being properly initialized
Mikael Berthe <mikael@lilotux.net>
parents: 2019
diff changeset
98 event->source = 0;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
99
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
100 evs_list = g_slist_append(evs_list, event);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
101 return stridn;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
102 }
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
103
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
104 static evs_t *evs_find(const char *evid)
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
105 {
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
106 GSList *p;
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
107
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
108 if (!evid)
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
109 return NULL;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
110
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
111 for (p = evs_list; p; p = g_slist_next(p)) {
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
112 evs_t *i = p->data;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
113 if (!strcmp(evid, i->id))
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
114 return i;
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
115 }
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
116 return NULL;
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
117 }
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
118
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
119 // evs_del(evid)
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
120 // Deletes event.
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
121 // This will not call event handler, however this will
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
122 // call destroy notify function.
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
123 // Returns 0 in case of success, -1 if the evid hasn't been found.
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
124 int evs_del(const char *evid)
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
125 {
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
126 evs_t *event = evs_find(evid);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
127
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
128 if (!event)
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
129 return -1;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
130
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
131 if (event->notify)
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
132 event->notify(event->data);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
133 if (event->source)
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
134 g_source_remove(event->source);
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
135
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
136 evs_list = g_slist_remove(evs_list, event);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
137 g_free(event->id);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
138 g_free(event->description);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
139 g_free(event);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
140
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
141 return 0; // Ok, deleted
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
142 }
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
143
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
144 // evs_callback(evid, evcontext, argument)
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
145 // Callback processing for the specified event.
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
146 // If event handler will return FALSE, event will be destroyed.
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
147 // Return 0 in case of success, -1 if the evid hasn't been found.
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
148 // evcontext and argument are transparently passed to event handler.
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
149 int evs_callback(const char *evid, guint context, const char *arg)
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
150 {
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
151 evs_t *event;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
152
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
153 event = evs_find(evid);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
154 if (!event)
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
155 return -1;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
156
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
157 if (event->callback &&
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
158 !event->callback(context, arg, event->data))
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
159 evs_del(evid);
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
160 return 0;
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
161 }
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
162
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
163 // evs_display_list()
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
164 // Prints list of events to mcabber log window.
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
165 void evs_display_list(void)
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
166 {
1868
fdb2f88b908b /event list sets the message flag when the list is long
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
167 guint count = 0;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
168 GSList *p;
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
169
1868
fdb2f88b908b /event list sets the message flag when the list is long
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
170 scr_LogPrint(LPRINT_NORMAL, "Events list:");
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
171 for (p = evs_list; p; p = g_slist_next(p)) {
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
172 evs_t *i = p->data;
1868
fdb2f88b908b /event list sets the message flag when the list is long
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
173 scr_LogPrint(LPRINT_NORMAL,
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
174 "Id: %-3s %s", i->id,
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
175 (i->description ? i->description : ""));
1868
fdb2f88b908b /event list sets the message flag when the list is long
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
176 count++;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
177 }
1868
fdb2f88b908b /event list sets the message flag when the list is long
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
178 scr_LogPrint(LPRINT_NORMAL, "End of events list.");
fdb2f88b908b /event list sets the message flag when the list is long
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
179 if (count+2 > scr_getlogwinheight()) {
fdb2f88b908b /event list sets the message flag when the list is long
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
180 scr_setmsgflag_if_needed(SPECIAL_BUFFER_STATUS_ID, TRUE);
fdb2f88b908b /event list sets the message flag when the list is long
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
181 scr_setattentionflag_if_needed(SPECIAL_BUFFER_STATUS_ID, TRUE,
fdb2f88b908b /event list sets the message flag when the list is long
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
182 ROSTER_UI_PRIO_STATUS_WIN_MESSAGE, prio_max);
fdb2f88b908b /event list sets the message flag when the list is long
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
183 }
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
184 }
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
185
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
186 // evs_geteventslist()
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
187 // Return a singly-linked-list of events ids.
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
188 // Data in list should not be modified and can disappear,
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
189 // you must strdup them, if you want them to persist.
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
190 // Note: the caller should free the list after use.
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
191 GSList *evs_geteventslist(void)
757
ae23c8826efb Improve completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 753
diff changeset
192 {
ae23c8826efb Improve completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 753
diff changeset
193 GSList *evidlist = NULL, *p;
ae23c8826efb Improve completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 753
diff changeset
194
ae23c8826efb Improve completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 753
diff changeset
195 for (p = evs_list; p; p = g_slist_next(p)) {
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
196 evs_t *i = p->data;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
197 evidlist = g_slist_append(evidlist, i->id);
757
ae23c8826efb Improve completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 753
diff changeset
198 }
ae23c8826efb Improve completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 753
diff changeset
199
ae23c8826efb Improve completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 753
diff changeset
200 return evidlist;
ae23c8826efb Improve completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 753
diff changeset
201 }
ae23c8826efb Improve completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 753
diff changeset
202
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
203 // evs_deinit()
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
204 // Frees all events.
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
205 void evs_deinit(void)
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
206 {
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
207 GSList *eel;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
208 for (eel = evs_list; eel; eel = eel->next) {
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
209 evs_t *event = eel->data;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
210 if (event->notify)
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
211 event->notify(event->data);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
212 if (event->source)
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
213 g_source_remove(event->source);
1729
e6e89b1d7831 Minor style and header updates
Mikael Berthe <mikael@lilotux.net>
parents: 1685
diff changeset
214
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
215 evs_list = g_slist_remove(evs_list, event);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
216 g_free(event->id);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
217 g_free(event->description);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
218 g_free(event);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
219 }
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
220 g_slist_free(evs_list);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
221 evs_list = NULL;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
222 }
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
223
1811
e6d355e50d7a Update Vim modelines
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
224 /* vim: set expandtab cindent cinoptions=>2\:2(0 sw=2 ts=2: For Vim users... */