evolution-3.6.4/addressbook/gui/widgets/eab-config.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  *		David Trowbridge <trowbrds@cs.colorado.edu>
 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 "eab-config.h"
 28 
 29 #define EAB_CONFIG_GET_PRIVATE(obj) \
 30 	(G_TYPE_INSTANCE_GET_PRIVATE \
 31 	((obj), EAB_TYPE_CONFIG, EABConfigPrivate))
 32 
 33 struct _EABConfigPrivate {
 34 	guint source_changed_id;
 35 };
 36 
 37 G_DEFINE_TYPE (EABConfig, eab_config, E_TYPE_CONFIG)
 38 
 39 static void
 40 eab_config_init (EABConfig *cfg)
 41 {
 42 	cfg->priv = EAB_CONFIG_GET_PRIVATE (cfg);
 43 }
 44 
 45 static void
 46 ecp_target_free (EConfig *ec,
 47                  EConfigTarget *t)
 48 {
 49 	struct _EABConfigPrivate *p = EAB_CONFIG (ec)->priv;
 50 
 51 	if (ec->target == t) {
 52 		switch (t->type) {
 53 		case EAB_CONFIG_TARGET_SOURCE: {
 54 			EABConfigTargetSource *s = (EABConfigTargetSource *) t;
 55 
 56 			if (p->source_changed_id) {
 57 				g_signal_handler_disconnect (s->source, p->source_changed_id);
 58 				p->source_changed_id = 0;
 59 			}
 60 			break; }
 61 		case EAB_CONFIG_TARGET_PREFS:
 62 			break;
 63 		}
 64 	}
 65 
 66 	switch (t->type) {
 67 	case EAB_CONFIG_TARGET_SOURCE: {
 68 		EABConfigTargetSource *s = (EABConfigTargetSource *) t;
 69 
 70 		if (s->source)
 71 			g_object_unref (s->source);
 72 		break; }
 73 	case EAB_CONFIG_TARGET_PREFS: {
 74 		EABConfigTargetPrefs *s = (EABConfigTargetPrefs *) t;
 75 
 76 		if (s->settings)
 77 			g_object_unref (s->settings);
 78 		break; }
 79 	}
 80 
 81 	((EConfigClass *) eab_config_parent_class)->target_free (ec, t);
 82 }
 83 
 84 static void
 85 ecp_source_changed (ESource *source,
 86                     EConfig *ec)
 87 {
 88 	e_config_target_changed (ec, E_CONFIG_TARGET_CHANGED_STATE);
 89 }
 90 
 91 static void
 92 ecp_set_target (EConfig *ec,
 93                 EConfigTarget *t)
 94 {
 95 	struct _EABConfigPrivate *p = EAB_CONFIG_GET_PRIVATE (ec);
 96 
 97 	((EConfigClass *) eab_config_parent_class)->set_target (ec, t);
 98 
 99 	if (t) {
100 		switch (t->type) {
101 		case EAB_CONFIG_TARGET_SOURCE: {
102 			EABConfigTargetSource *s = (EABConfigTargetSource *) t;
103 
104 			p->source_changed_id = g_signal_connect (
105 				s->source, "changed",
106 				G_CALLBACK (ecp_source_changed), ec);
107 			break; }
108 		case EAB_CONFIG_TARGET_PREFS:
109 			break;
110 		}
111 	}
112 }
113 
114 static void
115 eab_config_class_init (EABConfigClass *class)
116 {
117 	EConfigClass *config_class;
118 
119 	g_type_class_add_private (class, sizeof (struct _EABConfigPrivate));
120 
121 	config_class = E_CONFIG_CLASS (class);
122 	config_class->set_target = ecp_set_target;
123 	config_class->target_free = ecp_target_free;
124 }
125 
126 EABConfig *
127 eab_config_new (gint type,
128                 const gchar *menuid)
129 {
130 	EABConfig *ecp = g_object_new (eab_config_get_type (), NULL);
131 	e_config_construct (&ecp->config, type, menuid);
132 	return ecp;
133 }
134 
135 EABConfigTargetSource *
136 eab_config_target_new_source (EABConfig *ecp,
137                               ESource *source)
138 {
139 	EABConfigTargetSource *t = e_config_target_new (
140 		&ecp->config, EAB_CONFIG_TARGET_SOURCE, sizeof (*t));
141 
142 	t->source = source;
143 	g_object_ref (source);
144 
145 	return t;
146 }
147 
148 EABConfigTargetPrefs *
149 eab_config_target_new_prefs (EABConfig *ecp,
150                              GSettings *settings)
151 {
152 	EABConfigTargetPrefs *t = e_config_target_new (
153 		&ecp->config, EAB_CONFIG_TARGET_PREFS, sizeof (*t));
154 
155 	if (settings)
156 		t->settings = g_object_ref (settings);
157 	else
158 		t->settings = NULL;
159 
160 	return t;
161 }