evolution-3.6.4/calendar/gui/e-cal-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 <gtk/gtk.h>
 28 
 29 #include "e-cal-config.h"
 30 
 31 #define E_CAL_CONFIG_GET_PRIVATE(obj) \
 32 	(G_TYPE_INSTANCE_GET_PRIVATE \
 33 	((obj), E_TYPE_CAL_CONFIG, ECalConfigPrivate))
 34 
 35 struct _ECalConfigPrivate {
 36 	guint source_changed_id;
 37 };
 38 
 39 G_DEFINE_TYPE (ECalConfig, e_cal_config, E_TYPE_CONFIG)
 40 
 41 static void
 42 ecp_target_free (EConfig *ec,
 43                  EConfigTarget *t)
 44 {
 45 	ECalConfigPrivate *p = E_CAL_CONFIG (ec)->priv;
 46 
 47 	if (ec->target == t) {
 48 		switch (t->type) {
 49 		case EC_CONFIG_TARGET_SOURCE: {
 50 			ECalConfigTargetSource *s = (ECalConfigTargetSource *) t;
 51 
 52 			if (p->source_changed_id) {
 53 				g_signal_handler_disconnect (
 54 					s->source, p->source_changed_id);
 55 				p->source_changed_id = 0;
 56 			}
 57 			break; }
 58 		case EC_CONFIG_TARGET_PREFS: {
 59 			break; }
 60 		}
 61 	}
 62 
 63 	switch (t->type) {
 64 	case EC_CONFIG_TARGET_SOURCE: {
 65 		ECalConfigTargetSource *s = (ECalConfigTargetSource *) t;
 66 		if (s->source)
 67 			g_object_unref (s->source);
 68 		break; }
 69 	case EC_CONFIG_TARGET_PREFS: {
 70 		ECalConfigTargetPrefs *s = (ECalConfigTargetPrefs *) t;
 71 		if (s->settings)
 72 			g_object_unref (s->settings);
 73 		break; }
 74 	}
 75 
 76 	((EConfigClass *) e_cal_config_parent_class)->target_free (ec, t);
 77 }
 78 
 79 static void
 80 ecp_source_changed (ESource *source,
 81                     EConfig *ec)
 82 {
 83 	e_config_target_changed (ec, E_CONFIG_TARGET_CHANGED_STATE);
 84 }
 85 
 86 static void
 87 ecp_set_target (EConfig *ec,
 88                 EConfigTarget *t)
 89 {
 90 	ECalConfigPrivate *p = E_CAL_CONFIG_GET_PRIVATE (ec);
 91 
 92 	((EConfigClass *) e_cal_config_parent_class)->set_target (ec, t);
 93 
 94 	if (t) {
 95 		switch (t->type) {
 96 		case EC_CONFIG_TARGET_SOURCE: {
 97 			ECalConfigTargetSource *s = (ECalConfigTargetSource *) t;
 98 
 99 			p->source_changed_id = g_signal_connect (
100 				s->source, "changed",
101 				G_CALLBACK (ecp_source_changed), ec);
102 			break; }
103 		case EC_CONFIG_TARGET_PREFS: {
104 			/* ECalConfigTargetPrefs *s = (ECalConfigTargetPrefs *)t; */
105 			break; }
106 		}
107 	}
108 }
109 
110 static void
111 e_cal_config_class_init (ECalConfigClass *class)
112 {
113 	EConfigClass *config_class;
114 
115 	g_type_class_add_private (class, sizeof (ECalConfigPrivate));
116 
117 	config_class = E_CONFIG_CLASS (class);
118 	config_class->set_target = ecp_set_target;
119 	config_class->target_free = ecp_target_free;
120 }
121 
122 static void
123 e_cal_config_init (ECalConfig *cfg)
124 {
125 	cfg->priv = E_CAL_CONFIG_GET_PRIVATE (cfg);
126 }
127 
128 ECalConfig *
129 e_cal_config_new (gint type,
130                   const gchar *menuid)
131 {
132 	ECalConfig *ecp = g_object_new (e_cal_config_get_type (), NULL);
133 	e_config_construct (&ecp->config, type, menuid);
134 	return ecp;
135 }
136 
137 ECalConfigTargetSource *
138 e_cal_config_target_new_source (ECalConfig *ecp,
139                                 ESource *source)
140 {
141 	ECalConfigTargetSource *t;
142 
143 	t = e_config_target_new (
144 		&ecp->config, EC_CONFIG_TARGET_SOURCE, sizeof (*t));
145 
146 	t->source = g_object_ref (source);
147 
148 	return t;
149 }
150 
151 ECalConfigTargetPrefs *
152 e_cal_config_target_new_prefs (ECalConfig *ecp)
153 {
154 	ECalConfigTargetPrefs *t;
155 
156 	t = e_config_target_new (
157 		&ecp->config, EC_CONFIG_TARGET_PREFS, sizeof (*t));
158 
159 	t->settings = g_settings_new ("org.gnome.evolution.calendar");
160 
161 	return t;
162 }