1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Authors: Michael Zucchi <notzed@ximian.com>
5 * Copyright 2004 Novell, Inc. (www.novell.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
32 #include <gtk/gtkmenu.h>
33 #include <gtk/gtkmenuitem.h>
34 #include <gtk/gtkimagemenuitem.h>
35 #include <gtk/gtkcheckmenuitem.h>
36 #include <gtk/gtkradiomenuitem.h>
37 #include <gtk/gtkseparatormenuitem.h>
38 #include <gtk/gtklabel.h>
39 #include <gtk/gtkimage.h>
41 #include <libgnome/gnome-url.h>
42 #include <libgnomevfs/gnome-vfs-mime.h>
44 #include "em-config.h"
45 #include "libedataserver/e-msgport.h"
46 #include <e-util/e-icon-factory.h>
48 #include "em-composer-utils.h"
50 #include <camel/camel-store.h>
51 #include <camel/camel-folder.h>
52 #include <camel/camel-mime-message.h>
53 #include <camel/camel-string-utils.h>
54 #include <camel/camel-mime-utils.h>
55 #include <camel/camel-mime-part.h>
56 #include <camel/camel-url.h>
58 #include <camel/camel-vee-folder.h>
59 #include <camel/camel-vtrash-folder.h>
61 #include <gconf/gconf.h>
62 #include <gconf/gconf-client.h>
64 #include <e-util/e-util.h>
66 static GObjectClass
*emp_parent
;
68 struct _EMConfigPrivate
{
69 gint account_changed_id
;
75 EMConfig
*emp
= (EMConfig
*)o
;
77 emp
->priv
= g_malloc0(sizeof(*emp
->priv
));
81 emp_finalise(GObject
*o
)
83 struct _EMConfigPrivate
*p
= ((EMConfig
*)o
)->priv
;
85 /* Note we can't be unreffed if a target exists, so the target
86 * will need to be freed first which will clean up any
91 ((GObjectClass
*)emp_parent
)->finalize(o
);
95 emp_target_free(EConfig
*ep
, EConfigTarget
*t
)
97 if (ep
->target
== t
) {
99 case EM_CONFIG_TARGET_FOLDER
: {
100 /*EMConfigTargetFolder *s = (EMConfigTargetFolder *)t;*/
102 case EM_CONFIG_TARGET_PREFS
: {
103 /*EMConfigTargetPrefs *s = (EMConfigTargetPrefs *)t;*/
105 case EM_CONFIG_TARGET_ACCOUNT
: {
106 EMConfigTargetAccount
*s
= (EMConfigTargetAccount
*)t
;
108 if (((EMConfig
*)ep
)->priv
->account_changed_id
) {
109 g_signal_handler_disconnect(s
->account
, ((EMConfig
*)ep
)->priv
->account_changed_id
);
110 ((EMConfig
*)ep
)->priv
->account_changed_id
= 0;
117 case EM_CONFIG_TARGET_FOLDER
: {
118 EMConfigTargetFolder
*s
= (EMConfigTargetFolder
*)t
;
121 camel_object_unref(s
->folder
);
123 case EM_CONFIG_TARGET_PREFS
: {
124 EMConfigTargetPrefs
*s
= (EMConfigTargetPrefs
*)t
;
127 g_object_unref(s
->gconf
);
129 case EM_CONFIG_TARGET_ACCOUNT
: {
130 EMConfigTargetAccount
*s
= (EMConfigTargetAccount
*)t
;
132 g_object_unref(s
->account
);
136 ((EConfigClass
*)emp_parent
)->target_free(ep
, t
);
140 emp_account_changed(struct _EAccount
*ea
, int id
, EMConfig
*emc
)
142 e_config_target_changed((EConfig
*)emc
, E_CONFIG_TARGET_CHANGED_STATE
);
146 emp_set_target(EConfig
*ep
, EConfigTarget
*t
)
148 ((EConfigClass
*)emp_parent
)->set_target(ep
, t
);
152 case EM_CONFIG_TARGET_FOLDER
: {
153 /*EMConfigTargetFolder *s = (EMConfigTargetFolder *)t;*/
155 case EM_CONFIG_TARGET_PREFS
: {
156 /*EMConfigTargetPrefs *s = (EMConfigTargetPrefs *)t;*/
158 case EM_CONFIG_TARGET_ACCOUNT
: {
159 EMConfigTargetAccount
*s
= (EMConfigTargetAccount
*)t
;
161 ((EMConfig
*)ep
)->priv
->account_changed_id
= g_signal_connect(s
->account
, "changed", G_CALLBACK(emp_account_changed
), ep
);
168 emp_class_init(GObjectClass
*klass
)
170 klass
->finalize
= emp_finalise
;
171 ((EConfigClass
*)klass
)->set_target
= emp_set_target
;
172 ((EConfigClass
*)klass
)->target_free
= emp_target_free
;
176 em_config_get_type(void)
178 static GType type
= 0;
181 static const GTypeInfo info
= {
182 sizeof(EMConfigClass
),
184 (GClassInitFunc
)emp_class_init
,
187 (GInstanceInitFunc
)emp_init
189 emp_parent
= g_type_class_ref(e_config_get_type());
190 type
= g_type_register_static(e_config_get_type(), "EMConfig", &info
, 0);
196 EMConfig
*em_config_new(int type
, const char *menuid
)
198 EMConfig
*emp
= g_object_new(em_config_get_type(), 0);
200 e_config_construct(&emp
->config
, type
, menuid
);
205 EMConfigTargetFolder
*
206 em_config_target_new_folder(EMConfig
*emp
, struct _CamelFolder
*folder
, const char *uri
)
208 EMConfigTargetFolder
*t
= e_config_target_new(&emp
->config
, EM_CONFIG_TARGET_FOLDER
, sizeof(*t
));
210 t
->uri
= g_strdup(uri
);
212 camel_object_ref(folder
);
217 EMConfigTargetPrefs
*
218 em_config_target_new_prefs(EMConfig
*emp
, struct _GConfClient
*gconf
)
220 EMConfigTargetPrefs
*t
= e_config_target_new(&emp
->config
, EM_CONFIG_TARGET_PREFS
, sizeof(*t
));
229 EMConfigTargetAccount
*
230 em_config_target_new_account(EMConfig
*emp
, struct _EAccount
*account
)
232 EMConfigTargetAccount
*t
= e_config_target_new(&emp
->config
, EM_CONFIG_TARGET_ACCOUNT
, sizeof(*t
));
234 t
->account
= account
;
235 g_object_ref(account
);
241 /* ********************************************************************** */
243 /* Popup menu plugin handler */
247 class="org.gnome.mail.plugin.popup:1.0"
248 id="org.gnome.mail.plugin.popup.item:1.0"
250 location="/opt/gnome2/lib/camel/1.0/libcamelimap.so"
252 description="IMAP4 and IMAP4v1 mail store">
253 <hook class="org.gnome.mail.popupMenu:1.0"
254 handler="HandlePopup">
255 <menu id="any" target="select">
257 type="item|toggle|radio|image|submenu|bar"
263 activate="emp_view_emacs"/>
269 static void *emph_parent_class
;
270 #define emph ((EMConfigHook *)eph)
272 static const EConfigHookTargetMask emph_no_masks
[] = {
276 static const EConfigHookTargetMap emph_targets
[] = {
277 { "folder", EM_CONFIG_TARGET_FOLDER
, emph_no_masks
},
278 { "prefs", EM_CONFIG_TARGET_PREFS
, emph_no_masks
},
279 { "account", EM_CONFIG_TARGET_ACCOUNT
, emph_no_masks
},
284 emph_finalise(GObject
*o
)
286 /*EPluginHook *eph = (EPluginHook *)o;*/
288 ((GObjectClass
*)emph_parent_class
)->finalize(o
);
292 emph_class_init(EPluginHookClass
*klass
)
296 ((GObjectClass
*)klass
)->finalize
= emph_finalise
;
297 ((EPluginHookClass
*)klass
)->id
= "org.gnome.evolution.mail.config:1.0";
299 for (i
=0;emph_targets
[i
].type
;i
++)
300 e_config_hook_class_add_target_map((EConfigHookClass
*)klass
, &emph_targets
[i
]);
302 ((EConfigHookClass
*)klass
)->config_class
= g_type_class_ref(em_config_get_type());
306 em_config_hook_get_type(void)
308 static GType type
= 0;
311 static const GTypeInfo info
= {
312 sizeof(EMConfigHookClass
), NULL
, NULL
, (GClassInitFunc
) emph_class_init
, NULL
, NULL
,
313 sizeof(EMConfigHook
), 0, (GInstanceInitFunc
) NULL
,
316 emph_parent_class
= g_type_class_ref(e_config_hook_get_type());
317 type
= g_type_register_static(e_config_hook_get_type(), "EMConfigHook", &info
, 0);