evolution-3.6.4/composer/e-composer-from-header.c

No issues found

  1 /*
  2  *
  3  * This program is free software; you can redistribute it and/or
  4  * modify it under the terms of the GNU Lesser General Public
  5  * License as published by the Free Software Foundation; either
  6  * version 2 of the License, or (at your option) version 3.
  7  *
  8  * This program is distributed in the hope that it will be useful,
  9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 11  * Lesser General Public License for more details.
 12  *
 13  * You should have received a copy of the GNU Lesser General Public
 14  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 15  *
 16  *
 17  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 18  *
 19  */
 20 
 21 #ifdef HAVE_CONFIG_H
 22 #include <config.h>
 23 #endif
 24 
 25 #include "e-composer-from-header.h"
 26 
 27 #include <misc/e-mail-identity-combo-box.h>
 28 
 29 G_DEFINE_TYPE (
 30 	EComposerFromHeader,
 31 	e_composer_from_header,
 32 	E_TYPE_COMPOSER_HEADER)
 33 
 34 static void
 35 composer_from_header_changed_cb (EMailIdentityComboBox *combo_box,
 36                                  EComposerFromHeader *header)
 37 {
 38 	g_signal_emit_by_name (header, "changed");
 39 }
 40 
 41 static void
 42 composer_from_header_constructed (GObject *object)
 43 {
 44 	ESourceRegistry *registry;
 45 	EComposerHeader *header;
 46 	GtkWidget *widget;
 47 
 48 	header = E_COMPOSER_HEADER (object);
 49 	registry = e_composer_header_get_registry (header);
 50 
 51 	/* Input widget must be set before chaining up. */
 52 
 53 	widget = e_mail_identity_combo_box_new (registry);
 54 	g_signal_connect (
 55 		widget, "changed",
 56 		G_CALLBACK (composer_from_header_changed_cb), header);
 57 	header->input_widget = g_object_ref_sink (widget);
 58 
 59 	/* Chain up to parent's constructed() method. */
 60 	G_OBJECT_CLASS (e_composer_from_header_parent_class)->
 61 		constructed (object);
 62 }
 63 
 64 static void
 65 e_composer_from_header_class_init (EComposerFromHeaderClass *class)
 66 {
 67 	GObjectClass *object_class;
 68 
 69 	object_class = G_OBJECT_CLASS (class);
 70 	object_class->constructed = composer_from_header_constructed;
 71 }
 72 
 73 static void
 74 e_composer_from_header_init (EComposerFromHeader *from_header)
 75 {
 76 }
 77 
 78 EComposerHeader *
 79 e_composer_from_header_new (ESourceRegistry *registry,
 80                             const gchar *label)
 81 {
 82 	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
 83 
 84 	return g_object_new (
 85 		E_TYPE_COMPOSER_FROM_HEADER,
 86 		"label", label, "button", FALSE,
 87 		"registry", registry, NULL);
 88 }
 89 
 90 const gchar *
 91 e_composer_from_header_get_active_id (EComposerFromHeader *header)
 92 {
 93 	GtkComboBox *combo_box;
 94 
 95 	g_return_val_if_fail (E_IS_COMPOSER_FROM_HEADER (header), NULL);
 96 
 97 	combo_box = GTK_COMBO_BOX (E_COMPOSER_HEADER (header)->input_widget);
 98 
 99 	return gtk_combo_box_get_active_id (combo_box);
100 }
101 
102 void
103 e_composer_from_header_set_active_id (EComposerFromHeader *header,
104                                       const gchar *active_id)
105 {
106 	GtkComboBox *combo_box;
107 
108 	g_return_if_fail (E_IS_COMPOSER_FROM_HEADER (header));
109 
110 	if (!active_id)
111 		return;
112 
113 	combo_box = GTK_COMBO_BOX (E_COMPOSER_HEADER (header)->input_widget);
114 
115 	if (!gtk_combo_box_set_active_id (combo_box, active_id) && active_id && *active_id) {
116 		ESourceRegistry *registry;
117 		GtkTreeModel *model;
118 		GtkTreeIter iter;
119 		gint id_column;
120 
121 		registry = e_composer_header_get_registry (E_COMPOSER_HEADER (header));
122 		id_column = gtk_combo_box_get_id_column (combo_box);
123 		model = gtk_combo_box_get_model (combo_box);
124 
125 		if (gtk_tree_model_get_iter_first (model, &iter)) {
126 			do {
127 				gchar *identity_uid = NULL;
128 
129 				gtk_tree_model_get (model, &iter, id_column, &identity_uid, -1);
130 
131 				if (identity_uid) {
132 					ESource *source;
133 
134 					source = e_source_registry_ref_source (registry, identity_uid);
135 					if (source) {
136 						if (g_strcmp0 (e_source_get_parent (source), active_id) == 0) {
137 							g_object_unref (source);
138 							gtk_combo_box_set_active_id (combo_box, identity_uid);
139 							g_free (identity_uid);
140 							break;
141 						}
142 						g_object_unref (source);
143 					}
144 
145 					g_free (identity_uid);
146 				}
147 			} while (gtk_tree_model_iter_next (model, &iter));
148 		}
149 	}
150 }