evolution-3.6.4/calendar/gui/e-select-names-editable.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  *		Mike Kestner  <mkestner@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 <gtk/gtk.h>
 28 #include <gdk/gdkkeysyms.h>
 29 #include <libebook/libebook.h>
 30 #include <shell/e-shell.h>
 31 
 32 #include "e-select-names-editable.h"
 33 
 34 G_DEFINE_TYPE_WITH_CODE (
 35 	ESelectNamesEditable,
 36 	e_select_names_editable,
 37 	E_TYPE_NAME_SELECTOR_ENTRY,
 38 	G_IMPLEMENT_INTERFACE (
 39 		GTK_TYPE_CELL_EDITABLE, NULL))
 40 
 41 static void
 42 e_select_names_editable_class_init (ESelectNamesEditableClass *class)
 43 {
 44 }
 45 
 46 static void
 47 e_select_names_editable_init (ESelectNamesEditable *esne)
 48 {
 49 }
 50 
 51 ESelectNamesEditable *
 52 e_select_names_editable_new (void)
 53 {
 54 	EShell *shell;
 55 
 56 	/* Might be cleaner to have 'registry' passed in, but the call chain
 57 	 * of this widget doesn't have access that low in the functions, thus
 58 	 * making the change without (private) API break. */
 59 	shell = e_shell_get_default ();
 60 
 61 	return g_object_new (
 62 		E_TYPE_SELECT_NAMES_EDITABLE,
 63 		"registry", e_shell_get_registry (shell),
 64 		NULL);
 65 }
 66 
 67 gchar *
 68 e_select_names_editable_get_email (ESelectNamesEditable *esne)
 69 {
 70 	EDestinationStore *destination_store;
 71 	GList *destinations;
 72 	EDestination *destination;
 73 	gchar *result = NULL;
 74 
 75 	g_return_val_if_fail (E_SELECT_NAMES_EDITABLE (esne), NULL);
 76 
 77 	destination_store = e_name_selector_entry_peek_destination_store (E_NAME_SELECTOR_ENTRY (esne));
 78 	destinations = e_destination_store_list_destinations (destination_store);
 79 	if (!destinations)
 80 		return NULL;
 81 
 82 	destination = destinations->data;
 83 	result = g_strdup (e_destination_get_email (destination));
 84 	g_list_free (destinations);
 85 	return result;
 86 }
 87 
 88 GList *
 89 e_select_names_editable_get_emails (ESelectNamesEditable *esne)
 90 {
 91 	EDestinationStore *destination_store;
 92 	GList *destinations, *l;
 93 	EDestination *destination;
 94 	GList *result = NULL;
 95 
 96 	g_return_val_if_fail (E_SELECT_NAMES_EDITABLE (esne), NULL);
 97 
 98 	destination_store = e_name_selector_entry_peek_destination_store (E_NAME_SELECTOR_ENTRY (esne));
 99 	destinations = e_destination_store_list_destinations (destination_store);
100 	if (!destinations)
101 		return NULL;
102 
103 	for (l = destinations; l != NULL; l = l->next) {
104 		destination = l->data;
105 		if (e_destination_is_evolution_list (destination)) {
106 			const GList *list_dests, *l;
107 
108 			list_dests = e_destination_list_get_dests (destination);
109 			for (l = list_dests; l != NULL; l = g_list_next (l)) {
110 				result = g_list_append (result, g_strdup (e_destination_get_email (l->data)));
111 			}
112 		} else {
113 			/* check if the contact is contact list, it does not contain all the email ids  */
114 			/* we dont expand it currently, TODO do we need to expand it by getting it from addressbook*/
115 			if (e_destination_get_contact (destination) &&
116 			    e_contact_get (e_destination_get_contact (destination), E_CONTACT_IS_LIST)) {
117 				/* If its a contact_list which is not expanded, it wont have a email id,
118 				 * so we can use the name as the email id */
119 
120 				result = g_list_append (result, g_strdup (e_destination_get_name (destination)));
121 			} else
122 				result = g_list_append (result, g_strdup (e_destination_get_email (destination)));
123 		}
124 	}
125 
126 	g_list_free (destinations);
127 
128 	return result;
129 }
130 
131 gchar *
132 e_select_names_editable_get_name (ESelectNamesEditable *esne)
133 {
134 	EDestinationStore *destination_store;
135 	GList *destinations;
136 	EDestination *destination;
137 	gchar *result = NULL;
138 
139 	g_return_val_if_fail (E_SELECT_NAMES_EDITABLE (esne), NULL);
140 
141 	destination_store = e_name_selector_entry_peek_destination_store (E_NAME_SELECTOR_ENTRY (esne));
142 	destinations = e_destination_store_list_destinations (destination_store);
143 	if (!destinations)
144 		return NULL;
145 
146 	destination = destinations->data;
147 	result = g_strdup (e_destination_get_name (destination));
148 	g_list_free (destinations);
149 	return result;
150 }
151 
152 GList *
153 e_select_names_editable_get_names (ESelectNamesEditable *esne)
154 {
155 	EDestinationStore *destination_store;
156 	GList *destinations, *l;
157 	EDestination *destination;
158 	GList *result = NULL;
159 
160 	g_return_val_if_fail (E_SELECT_NAMES_EDITABLE (esne), NULL);
161 
162 	destination_store = e_name_selector_entry_peek_destination_store (E_NAME_SELECTOR_ENTRY (esne));
163 	destinations = e_destination_store_list_destinations (destination_store);
164 	if (!destinations)
165 		return NULL;
166 
167 	for (l = destinations; l != NULL; l = l->next) {
168 		destination = l->data;
169 		if (e_destination_is_evolution_list (destination)) {
170 			const GList *list_dests, *l;
171 
172 			list_dests = e_destination_list_get_dests (destination);
173 			for (l = list_dests; l != NULL; l = g_list_next (l)) {
174 				result = g_list_append (result, g_strdup (e_destination_get_name (l->data)));
175 			}
176 		} else {
177 			result = g_list_append (result, g_strdup (e_destination_get_name (destination)));
178 		}
179 	}
180 
181 	g_list_free (destinations);
182 
183 	return result;
184 }
185 
186 void
187 e_select_names_editable_set_address (ESelectNamesEditable *esne,
188                                      const gchar *name,
189                                      const gchar *email)
190 {
191 	EDestinationStore *destination_store;
192 	GList *destinations;
193 	EDestination *destination;
194 
195 	g_return_if_fail (E_IS_SELECT_NAMES_EDITABLE (esne));
196 
197 	destination_store = e_name_selector_entry_peek_destination_store (E_NAME_SELECTOR_ENTRY (esne));
198 	destinations = e_destination_store_list_destinations (destination_store);
199 
200 	if (!destinations)
201 		destination = e_destination_new ();
202 	else
203 		destination = g_object_ref (destinations->data);
204 
205 	e_destination_set_name (destination, name);
206 	e_destination_set_email (destination, email);
207 
208 	if (!destinations)
209 		e_destination_store_append_destination (destination_store, destination);
210 	g_object_unref (destination);
211 }