evolution-3.6.4/composer/e-composer-activity.c

No issues found

  1 /*
  2  * e-composer-activity.c
  3  *
  4  * This program is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2 of the License, or (at your option) version 3.
  8  *
  9  * This program is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 16  *
 17  */
 18 
 19 #ifdef HAVE_CONFIG_H
 20 #include <config.h>
 21 #endif
 22 
 23 #include "e-composer-private.h"
 24 
 25 #define E_COMPOSER_ACTIVITY_GET_PRIVATE(obj) \
 26 	(G_TYPE_INSTANCE_GET_PRIVATE \
 27 	((obj), E_TYPE_COMPOSER_ACTIVITY, EComposerActivityPrivate))
 28 
 29 struct _EComposerActivityPrivate {
 30 	EMsgComposer *composer;
 31 	gboolean saved_editable;
 32 };
 33 
 34 enum {
 35 	PROP_0,
 36 	PROP_COMPOSER
 37 };
 38 
 39 G_DEFINE_TYPE (
 40 	EComposerActivity,
 41 	e_composer_activity,
 42 	E_TYPE_ACTIVITY)
 43 
 44 static void
 45 composer_activity_lock_interface (EComposerActivity *activity)
 46 {
 47 	GtkActionGroup *action_group;
 48 	EMsgComposer *composer;
 49 	EWebViewGtkHTML *web_view;
 50 	gboolean editable;
 51 
 52 	composer = e_composer_activity_get_composer (activity);
 53 
 54 	web_view = e_msg_composer_get_web_view (composer);
 55 	editable = e_web_view_gtkhtml_get_editable (web_view);
 56 	e_web_view_gtkhtml_set_editable (web_view, FALSE);
 57 	activity->priv->saved_editable = editable;
 58 
 59 	action_group = composer->priv->async_actions;
 60 	gtk_action_group_set_sensitive (action_group, FALSE);
 61 }
 62 
 63 static void
 64 composer_activity_unlock_interface (EComposerActivity *activity)
 65 {
 66 	GtkActionGroup *action_group;
 67 	EMsgComposer *composer;
 68 	EWebViewGtkHTML *web_view;
 69 	gboolean editable;
 70 
 71 	composer = e_composer_activity_get_composer (activity);
 72 
 73 	editable = activity->priv->saved_editable;
 74 	web_view = e_msg_composer_get_web_view (composer);
 75 	e_web_view_gtkhtml_set_editable (web_view, editable);
 76 
 77 	action_group = composer->priv->async_actions;
 78 	gtk_action_group_set_sensitive (action_group, TRUE);
 79 }
 80 
 81 static void
 82 composer_activity_set_composer (EComposerActivity *activity,
 83                                 EMsgComposer *composer)
 84 {
 85 	g_return_if_fail (E_IS_MSG_COMPOSER (composer));
 86 	g_return_if_fail (activity->priv->composer == NULL);
 87 
 88 	activity->priv->composer = g_object_ref (composer);
 89 
 90 	composer_activity_lock_interface (activity);
 91 }
 92 
 93 static void
 94 composer_activity_set_property (GObject *object,
 95                                 guint property_id,
 96                                 const GValue *value,
 97                                 GParamSpec *pspec)
 98 {
 99 	switch (property_id) {
100 		case PROP_COMPOSER:
101 			composer_activity_set_composer (
102 				E_COMPOSER_ACTIVITY (object),
103 				g_value_get_object (value));
104 			return;
105 	}
106 
107 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
108 }
109 
110 static void
111 composer_activity_get_property (GObject *object,
112                                 guint property_id,
113                                 GValue *value,
114                                 GParamSpec *pspec)
115 {
116 	switch (property_id) {
117 		case PROP_COMPOSER:
118 			g_value_set_object (
119 				value, e_composer_activity_get_composer (
120 				E_COMPOSER_ACTIVITY (object)));
121 			return;
122 	}
123 
124 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
125 }
126 
127 static void
128 composer_activity_dispose (GObject *object)
129 {
130 	EComposerActivity *activity;
131 
132 	activity = E_COMPOSER_ACTIVITY (object);
133 
134 	if (activity->priv->composer != NULL) {
135 		composer_activity_unlock_interface (activity);
136 		g_object_unref (activity->priv->composer);
137 		activity->priv->composer = NULL;
138 	}
139 
140 	/* Chain up to parent's dispose() method. */
141 	G_OBJECT_CLASS (e_composer_activity_parent_class)->dispose (object);
142 }
143 
144 static void
145 e_composer_activity_class_init (EComposerActivityClass *class)
146 {
147 	GObjectClass *object_class;
148 
149 	g_type_class_add_private (class, sizeof (EComposerActivityPrivate));
150 
151 	object_class = G_OBJECT_CLASS (class);
152 	object_class->set_property = composer_activity_set_property;
153 	object_class->get_property = composer_activity_get_property;
154 	object_class->dispose = composer_activity_dispose;
155 
156 	g_object_class_install_property (
157 		object_class,
158 		PROP_COMPOSER,
159 		g_param_spec_object (
160 			"composer",
161 			NULL,
162 			NULL,
163 			E_TYPE_MSG_COMPOSER,
164 			G_PARAM_READWRITE |
165 			G_PARAM_CONSTRUCT_ONLY));
166 }
167 
168 static void
169 e_composer_activity_init (EComposerActivity *activity)
170 {
171 	activity->priv = E_COMPOSER_ACTIVITY_GET_PRIVATE (activity);
172 }
173 
174 EActivity *
175 e_composer_activity_new (EMsgComposer *composer)
176 {
177 	return g_object_new (
178 		E_TYPE_COMPOSER_ACTIVITY,
179 		"composer", composer, NULL);
180 }
181 
182 EMsgComposer *
183 e_composer_activity_get_composer (EComposerActivity *activity)
184 {
185 	g_return_val_if_fail (E_IS_COMPOSER_ACTIVITY (activity), NULL);
186 
187 	return activity->priv->composer;
188 }