Mercurial > pidgin
annotate src/notify.c @ 5520:11be8ae32937
[gaim-migrate @ 5920]
E-mail notification uses the new API.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Mon, 26 May 2003 00:52:24 +0000 |
parents | 9bcd8cd625ae |
children | a3e6a5ef49b5 |
rev | line source |
---|---|
5437 | 1 /** |
2 * @file notify.c Notification API | |
3 * @ingroup core | |
4 * | |
5 * gaim | |
6 * | |
7 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
8 * | |
9 * This program is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 */ | |
23 #include "notify.h" | |
24 | |
25 static GaimNotifyUiOps *notify_ui_ops = NULL; | |
26 static GList *handles = NULL; | |
27 | |
28 typedef struct | |
29 { | |
30 GaimNotifyType type; | |
31 void *handle; | |
5476
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
32 void *ui_handle; |
5437 | 33 |
34 } GaimNotifyInfo; | |
35 | |
36 void * | |
37 gaim_notify_message(void *handle, GaimNotifyType type, | |
38 const char *title, const char *primary, | |
39 const char *secondary, GCallback cb, void *user_data) | |
40 { | |
41 GaimNotifyUiOps *ops; | |
42 | |
43 g_return_val_if_fail(primary != NULL, NULL); | |
44 | |
45 ops = gaim_get_notify_ui_ops(); | |
46 | |
47 if (ops != NULL && ops->notify_message != NULL) { | |
48 GaimNotifyInfo *info; | |
49 | |
5476
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
50 info = g_new0(GaimNotifyInfo, 1); |
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
51 info->type = GAIM_NOTIFY_MESSAGE; |
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
52 info->handle = handle; |
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
53 info->ui_handle = ops->notify_message(type, title, primary, |
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
54 secondary, cb, user_data); |
5437 | 55 |
56 handles = g_list_append(handles, info); | |
57 | |
5476
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
58 return info->ui_handle; |
5437 | 59 } |
60 | |
61 return NULL; | |
62 } | |
63 | |
64 void * | |
65 gaim_notify_email(void *handle, const char *subject, const char *from, | |
66 const char *to, const char *url, GCallback cb, | |
67 void *user_data) | |
68 { | |
69 GaimNotifyUiOps *ops; | |
70 | |
71 ops = gaim_get_notify_ui_ops(); | |
72 | |
73 if (ops != NULL && ops->notify_email != NULL) { | |
74 GaimNotifyInfo *info; | |
75 | |
5476
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
76 info = g_new0(GaimNotifyInfo, 1); |
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
77 info->type = GAIM_NOTIFY_EMAIL; |
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
78 info->handle = handle; |
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
79 info->ui_handle = ops->notify_email(subject, from, to, url, cb, |
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
80 user_data); |
5437 | 81 |
82 handles = g_list_append(handles, info); | |
83 | |
5476
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
84 return info->ui_handle; |
5437 | 85 } |
86 | |
87 return NULL; | |
88 } | |
89 | |
90 void * | |
91 gaim_notify_emails(void *handle, size_t count, const char **subjects, | |
92 const char **froms, const char **tos, const char **urls, | |
93 GCallback cb, void *user_data) | |
94 { | |
95 GaimNotifyUiOps *ops; | |
96 | |
97 g_return_val_if_fail(count != 0, NULL); | |
98 | |
99 ops = gaim_get_notify_ui_ops(); | |
100 | |
101 if (ops != NULL && ops->notify_emails != NULL) { | |
102 GaimNotifyInfo *info; | |
103 | |
5476
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
104 info = g_new0(GaimNotifyInfo, 1); |
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
105 info->type = GAIM_NOTIFY_EMAILS; |
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
106 info->handle = handle; |
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
107 info->ui_handle = ops->notify_emails(count, subjects, froms, tos, |
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
108 urls, cb, user_data); |
5437 | 109 |
110 handles = g_list_append(handles, info); | |
111 | |
5476
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
112 return info->ui_handle; |
5437 | 113 } |
114 | |
115 return NULL; | |
116 } | |
117 | |
118 void | |
5476
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
119 gaim_notify_close(GaimNotifyType type, void *ui_handle) |
5437 | 120 { |
121 GList *l; | |
122 GaimNotifyUiOps *ops; | |
123 | |
5476
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
124 g_return_if_fail(ui_handle != NULL); |
5437 | 125 |
126 ops = gaim_get_notify_ui_ops(); | |
127 | |
128 for (l = handles; l != NULL; l = l->next) { | |
129 GaimNotifyInfo *info = l->data; | |
130 | |
5476
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
131 if (info->ui_handle == ui_handle) { |
5437 | 132 handles = g_list_remove(handles, info); |
133 | |
134 if (ops != NULL && ops->close_notify != NULL) | |
5476
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
135 ops->close_notify(info->type, ui_handle); |
5437 | 136 |
137 g_free(info); | |
138 | |
139 break; | |
140 } | |
141 } | |
142 } | |
143 | |
144 void | |
145 gaim_notify_close_with_handle(void *handle) | |
146 { | |
147 GList *l, *l_next; | |
148 GaimNotifyUiOps *ops; | |
149 | |
150 g_return_if_fail(handle != NULL); | |
151 | |
152 ops = gaim_get_notify_ui_ops(); | |
153 | |
154 for (l = handles; l != NULL; l = l_next) { | |
155 GaimNotifyInfo *info = l->data; | |
156 | |
157 l_next = l->next; | |
158 | |
159 if (info->handle == handle) { | |
160 handles = g_list_remove(handles, info); | |
161 | |
162 if (ops != NULL && ops->close_notify != NULL) | |
5476
9bcd8cd625ae
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
163 ops->close_notify(info->type, info->ui_handle); |
5437 | 164 |
165 g_free(info); | |
166 } | |
167 } | |
168 } | |
169 | |
170 void | |
171 gaim_set_notify_ui_ops(GaimNotifyUiOps *ops) | |
172 { | |
173 notify_ui_ops = ops; | |
174 } | |
175 | |
176 GaimNotifyUiOps * | |
177 gaim_get_notify_ui_ops(void) | |
178 { | |
179 return notify_ui_ops; | |
180 } | |
181 |