evolution-3.6.4/mail/em-event.c

No issues found

  1 /*
  2  * This program is free software; you can redistribute it and/or
  3  * modify it under the terms of the GNU Lesser General Public
  4  * License as published by the Free Software Foundation; either
  5  * version 2 of the License, or (at your option) version 3.
  6  *
  7  * This program is distributed in the hope that it will be useful,
  8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 10  * Lesser General Public License for more details.
 11  *
 12  * You should have received a copy of the GNU Lesser General Public
 13  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 14  *
 15  *
 16  * Authors:
 17  *		Michael Zucchi <notzed@ximian.com>
 18  *
 19  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 20  *
 21  */
 22 
 23 #ifdef HAVE_CONFIG_H
 24 #include <config.h>
 25 #endif
 26 
 27 #include <string.h>
 28 #include <stdlib.h>
 29 
 30 #include "em-event.h"
 31 #include "composer/e-msg-composer.h"
 32 
 33 static EMEvent *em_event;
 34 
 35 G_DEFINE_TYPE (EMEvent, em_event, E_TYPE_EVENT)
 36 
 37 static void
 38 eme_target_free (EEvent *ep,
 39                  EEventTarget *t)
 40 {
 41 	switch (t->type) {
 42 	case EM_EVENT_TARGET_FOLDER: {
 43 		EMEventTargetFolder *s = (EMEventTargetFolder *) t;
 44 		if (s->store != NULL)
 45 			g_object_unref (s->store);
 46 		g_free (s->folder_name);
 47 		g_free (s->display_name);
 48 		g_free (s->msg_uid);
 49 		g_free (s->msg_sender);
 50 		g_free (s->msg_subject);
 51 		break; }
 52 	case EM_EVENT_TARGET_MESSAGE: {
 53 		EMEventTargetMessage *s = (EMEventTargetMessage *) t;
 54 
 55 		if (s->folder)
 56 			g_object_unref (s->folder);
 57 		if (s->message)
 58 			g_object_unref (s->message);
 59 		g_free (s->uid);
 60 		if (s->composer)
 61 			g_object_unref (s->composer);
 62 		break; }
 63 	case EM_EVENT_TARGET_COMPOSER : {
 64 		EMEventTargetComposer *s = (EMEventTargetComposer *) t;
 65 
 66 		if (s->composer)
 67 			g_object_unref (s->composer);
 68 		break; }
 69 	}
 70 
 71 	/* Chain up to parent's target_free() method. */
 72 	E_EVENT_CLASS (em_event_parent_class)->target_free (ep, t);
 73 }
 74 
 75 static void
 76 em_event_class_init (EMEventClass *class)
 77 {
 78 	EEventClass *event_class;
 79 
 80 	event_class = E_EVENT_CLASS (class);
 81 	event_class->target_free = eme_target_free;
 82 }
 83 
 84 static void
 85 em_event_init (EMEvent *event)
 86 {
 87 }
 88 
 89 /**
 90  * em_event_peek:
 91  * @void:
 92  *
 93  * Get the singular instance of the mail event handler.
 94  *
 95  * Return value:
 96  **/
 97 EMEvent *
 98 em_event_peek (void)
 99 {
100 	if (em_event == NULL) {
101 		em_event = g_object_new (EM_TYPE_EVENT, NULL);
102 		e_event_construct (
103 			&em_event->popup,
104 			"org.gnome.evolution.mail.events");
105 	}
106 
107 	return em_event;
108 }
109 
110 EMEventTargetFolder *
111 em_event_target_new_folder (EMEvent *eme,
112                             CamelStore *store,
113                             const gchar *folder_name,
114                             guint new,
115                             const gchar *msg_uid,
116                             const gchar *msg_sender,
117                             const gchar *msg_subject)
118 {
119 	EMEventTargetFolder *t;
120 	guint32 flags = new ? EM_EVENT_FOLDER_NEWMAIL : 0;
121 
122 	g_return_val_if_fail (CAMEL_IS_STORE (store), NULL);
123 	g_return_val_if_fail (folder_name != NULL, NULL);
124 
125 	t = e_event_target_new (
126 		&eme->popup, EM_EVENT_TARGET_FOLDER, sizeof (*t));
127 
128 	t->store = g_object_ref (store);
129 	t->folder_name = g_strdup (folder_name);
130 	t->target.mask = ~flags;
131 	t->new = new;
132 	t->msg_uid = g_strdup (msg_uid);
133 	t->msg_sender = g_strdup (msg_sender);
134 	t->msg_subject = g_strdup (msg_subject);
135 
136 	return t;
137 }
138 
139 EMEventTargetComposer *
140 em_event_target_new_composer (EMEvent *eme,
141                               EMsgComposer *composer,
142                               guint32 flags)
143 {
144 	EMEventTargetComposer *t;
145 
146 	t = e_event_target_new (
147 		&eme->popup, EM_EVENT_TARGET_COMPOSER, sizeof (*t));
148 
149 	t->composer = g_object_ref (composer);
150 	t->target.mask = ~flags;
151 
152 	return t;
153 }
154 
155 EMEventTargetMessage *
156 em_event_target_new_message (EMEvent *eme,
157                              CamelFolder *folder,
158                              CamelMimeMessage *message,
159                              const gchar *uid,
160                              guint32 flags,
161                              EMsgComposer *composer)
162 {
163 	EMEventTargetMessage *t;
164 
165 	t = e_event_target_new (
166 		&eme->popup, EM_EVENT_TARGET_MESSAGE, sizeof (*t));
167 
168 	t->uid = g_strdup (uid);
169 	t->folder = folder;
170 	if (folder)
171 		g_object_ref (folder);
172 	t->message = message;
173 	if (message)
174 		g_object_ref (message);
175 	t->target.mask = ~flags;
176 	if (composer)
177 		t->composer = g_object_ref (G_OBJECT (composer));
178 
179 	return t;
180 }
181 
182 EMEventTargetSendReceive *
183 em_event_target_new_send_receive (EMEvent *eme,
184                                   GtkWidget *grid,
185                                   gpointer data,
186                                   gint row,
187                                   guint32 flags)
188 {
189 	EMEventTargetSendReceive *t;
190 
191 	t = e_event_target_new (
192 		&eme->popup, EM_EVENT_TARGET_SEND_RECEIVE, sizeof (*t));
193 
194 	t->grid = grid;
195 	t->data = data;
196 	t->row = row;
197 	t->target.mask = ~flags;
198 
199 	return t;
200 }
201 
202 EMEventTargetCustomIcon *
203 em_event_target_new_custom_icon (EMEvent *eme,
204                                  GtkTreeStore *store,
205                                  GtkTreeIter *iter,
206                                  const gchar *folder_name,
207                                  guint32 flags)
208 {
209 	EMEventTargetCustomIcon *t;
210 
211 	t = e_event_target_new (
212 		&eme->popup, EM_EVENT_TARGET_CUSTOM_ICON, sizeof (*t));
213 
214 	t->store = store;
215 	t->iter = iter;
216 	t->folder_name = folder_name;
217 	t->target.mask = ~flags;
218 
219 	return t;
220 }