Updated Traditional Chinese translation.
[evolution.git] / mail / em-config.c
blob9e3e60e9efb9b2393202f42803032fa372ad0275
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
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.
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
27 #include <string.h>
28 #include <stdlib.h>
30 #include <glib.h>
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>
47 #include "em-utils.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;
72 static void
73 emp_init(GObject *o)
75 EMConfig *emp = (EMConfig *)o;
77 emp->priv = g_malloc0(sizeof(*emp->priv));
80 static void
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
87 * listeners */
89 g_free(p);
91 ((GObjectClass *)emp_parent)->finalize(o);
94 static void
95 emp_target_free(EConfig *ep, EConfigTarget *t)
97 if (ep->target == t) {
98 switch (t->type) {
99 case EM_CONFIG_TARGET_FOLDER: {
100 /*EMConfigTargetFolder *s = (EMConfigTargetFolder *)t;*/
101 break; }
102 case EM_CONFIG_TARGET_PREFS: {
103 /*EMConfigTargetPrefs *s = (EMConfigTargetPrefs *)t;*/
104 break; }
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;
112 break; }
116 switch (t->type) {
117 case EM_CONFIG_TARGET_FOLDER: {
118 EMConfigTargetFolder *s = (EMConfigTargetFolder *)t;
120 g_free(s->uri);
121 camel_object_unref(s->folder);
122 break; }
123 case EM_CONFIG_TARGET_PREFS: {
124 EMConfigTargetPrefs *s = (EMConfigTargetPrefs *)t;
126 if (s->gconf)
127 g_object_unref(s->gconf);
128 break; }
129 case EM_CONFIG_TARGET_ACCOUNT: {
130 EMConfigTargetAccount *s = (EMConfigTargetAccount *)t;
132 g_object_unref(s->account);
133 break; }
136 ((EConfigClass *)emp_parent)->target_free(ep, t);
139 static void
140 emp_account_changed(struct _EAccount *ea, int id, EMConfig *emc)
142 e_config_target_changed((EConfig *)emc, E_CONFIG_TARGET_CHANGED_STATE);
145 static void
146 emp_set_target(EConfig *ep, EConfigTarget *t)
148 ((EConfigClass *)emp_parent)->set_target(ep, t);
150 if (t) {
151 switch (t->type) {
152 case EM_CONFIG_TARGET_FOLDER: {
153 /*EMConfigTargetFolder *s = (EMConfigTargetFolder *)t;*/
154 break; }
155 case EM_CONFIG_TARGET_PREFS: {
156 /*EMConfigTargetPrefs *s = (EMConfigTargetPrefs *)t;*/
157 break; }
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);
162 break; }
167 static void
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;
175 GType
176 em_config_get_type(void)
178 static GType type = 0;
180 if (type == 0) {
181 static const GTypeInfo info = {
182 sizeof(EMConfigClass),
183 NULL, NULL,
184 (GClassInitFunc)emp_class_init,
185 NULL, NULL,
186 sizeof(EMConfig), 0,
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);
193 return type;
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);
202 return emp;
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);
211 t->folder = folder;
212 camel_object_ref(folder);
214 return t;
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));
222 t->gconf = gconf;
223 if (gconf)
224 g_object_ref(gconf);
226 return 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);
237 return t;
241 /* ********************************************************************** */
243 /* Popup menu plugin handler */
246 <e-plugin
247 class="org.gnome.mail.plugin.popup:1.0"
248 id="org.gnome.mail.plugin.popup.item:1.0"
249 type="shlib"
250 location="/opt/gnome2/lib/camel/1.0/libcamelimap.so"
251 name="imap"
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">
256 <item
257 type="item|toggle|radio|image|submenu|bar"
258 active
259 path="foo/bar"
260 label="label"
261 icon="foo"
262 mask="select_one"
263 activate="emp_view_emacs"/>
264 </menu>
265 </extension>
269 static void *emph_parent_class;
270 #define emph ((EMConfigHook *)eph)
272 static const EConfigHookTargetMask emph_no_masks[] = {
273 { 0 }
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 },
280 { 0 }
283 static void
284 emph_finalise(GObject *o)
286 /*EPluginHook *eph = (EPluginHook *)o;*/
288 ((GObjectClass *)emph_parent_class)->finalize(o);
291 static void
292 emph_class_init(EPluginHookClass *klass)
294 int i;
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());
305 GType
306 em_config_hook_get_type(void)
308 static GType type = 0;
310 if (!type) {
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);
320 return type;