[16769] | 1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ |
---|
| 2 | /* evolution-shell-component-utils.c |
---|
| 3 | * |
---|
| 4 | * Copyright (C) 2000, 2001 Ximian, Inc. |
---|
| 5 | * |
---|
| 6 | * This program is free software; you can redistribute it and/or |
---|
[16786] | 7 | * modify it under the terms of version 2 of the GNU General Public |
---|
| 8 | * License as published by the Free Software Foundation. |
---|
[16769] | 9 | * |
---|
| 10 | * This program is distributed in the hope that it will be useful, |
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 13 | * General Public License for more details. |
---|
| 14 | * |
---|
| 15 | * You should have received a copy of the GNU General Public |
---|
| 16 | * License along with this program; if not, write to the |
---|
| 17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
| 18 | * Boston, MA 02111-1307, USA. |
---|
| 19 | * |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #ifdef HAVE_CONFIG_H |
---|
| 23 | #include <config.h> |
---|
| 24 | #endif |
---|
| 25 | |
---|
| 26 | #include "evolution-shell-component-utils.h" |
---|
| 27 | |
---|
| 28 | #include <libgnome/gnome-defs.h> |
---|
[16786] | 29 | #include <libgnome/gnome-i18n.h> |
---|
[16769] | 30 | #include <libgnome/gnome-util.h> |
---|
| 31 | #include <bonobo/bonobo-ui-util.h> |
---|
[16786] | 32 | #include <bonobo/bonobo-moniker-util.h> |
---|
| 33 | #include <bonobo/bonobo-exception.h> |
---|
| 34 | #include <liboaf/oaf.h> |
---|
| 35 | #include <gal/widgets/e-gui-utils.h> |
---|
[16769] | 36 | |
---|
| 37 | static void free_pixmaps (void); |
---|
| 38 | static GSList *inited_arrays = NULL; |
---|
| 39 | |
---|
| 40 | void e_pixmaps_update (BonoboUIComponent *uic, EPixmap *pixcache) |
---|
| 41 | { |
---|
| 42 | static int done_init = 0; |
---|
| 43 | int i; |
---|
| 44 | |
---|
| 45 | if (!done_init) { |
---|
| 46 | g_atexit (free_pixmaps); |
---|
| 47 | done_init = 1; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | if (g_slist_find (inited_arrays, pixcache) == NULL) |
---|
| 51 | inited_arrays = g_slist_prepend (inited_arrays, pixcache); |
---|
| 52 | |
---|
| 53 | for (i = 0; pixcache [i].path; i++) { |
---|
| 54 | if (!pixcache [i].pixbuf) { |
---|
| 55 | char *path; |
---|
| 56 | GdkPixbuf *pixbuf; |
---|
| 57 | |
---|
| 58 | path = g_concat_dir_and_file (EVOLUTION_IMAGES, |
---|
| 59 | pixcache [i].fname); |
---|
| 60 | |
---|
| 61 | pixbuf = gdk_pixbuf_new_from_file (path); |
---|
| 62 | if (pixbuf == NULL) { |
---|
| 63 | g_warning ("Cannot load image -- %s", path); |
---|
| 64 | } else { |
---|
| 65 | pixcache [i].pixbuf = bonobo_ui_util_pixbuf_to_xml (pixbuf); |
---|
| 66 | gdk_pixbuf_unref (pixbuf); |
---|
| 67 | bonobo_ui_component_set_prop (uic, |
---|
| 68 | pixcache [i].path, "pixname", |
---|
| 69 | pixcache [i].pixbuf, NULL); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | g_free (path); |
---|
| 73 | } else { |
---|
| 74 | bonobo_ui_component_set_prop (uic, pixcache [i].path, |
---|
| 75 | "pixname", |
---|
| 76 | pixcache [i].pixbuf, |
---|
| 77 | NULL); |
---|
| 78 | } |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | static void |
---|
| 83 | free_pixmaps (void) |
---|
| 84 | { |
---|
| 85 | int i; |
---|
| 86 | GSList *li; |
---|
| 87 | |
---|
| 88 | for (li = inited_arrays; li != NULL; li = li->next) { |
---|
| 89 | EPixmap *pixcache = li->data; |
---|
| 90 | for (i = 0; pixcache [i].path; i++) |
---|
| 91 | g_free (pixcache [i].pixbuf); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | g_slist_free (inited_arrays); |
---|
| 95 | } |
---|
| 96 | |
---|
[18141] | 97 | |
---|
[16786] | 98 | /** |
---|
| 99 | * e_activation_failure_dialog: |
---|
| 100 | * @parent: parent window of the dialog, or %NULL |
---|
| 101 | * @msg: the context-specific part of the error message |
---|
| 102 | * @oafiid: the OAFIID of the component that failed to start |
---|
| 103 | * @repo_id: the repo_id of the component that failed to start |
---|
| 104 | * |
---|
| 105 | * This puts up an error dialog about a failed component activation |
---|
| 106 | * containing as much information as we can manage to gather about |
---|
| 107 | * why it failed. |
---|
| 108 | **/ |
---|
| 109 | void |
---|
| 110 | e_activation_failure_dialog (GtkWindow *parent, const char *msg, |
---|
| 111 | const char *oafiid, const char *repo_id) |
---|
| 112 | { |
---|
| 113 | Bonobo_Unknown object; |
---|
| 114 | CORBA_Environment ev; |
---|
| 115 | char *errmsg; |
---|
| 116 | |
---|
| 117 | CORBA_exception_init (&ev); |
---|
| 118 | object = bonobo_get_object (oafiid, repo_id, &ev); |
---|
| 119 | if (ev._major == CORBA_NO_EXCEPTION) { |
---|
| 120 | if (object) { |
---|
| 121 | Bonobo_Unknown_unref (object, &ev); |
---|
| 122 | CORBA_Object_release (object, &ev); |
---|
| 123 | } |
---|
| 124 | errmsg = g_strdup_printf (_("%s\n\nUnknown error."), msg); |
---|
| 125 | } else if (strcmp (CORBA_exception_id (&ev), ex_OAF_GeneralError) != 0) { |
---|
| 126 | char *bonobo_err = bonobo_exception_get_text (&ev); |
---|
| 127 | errmsg = g_strdup_printf (_("%s\n\nThe error from the " |
---|
| 128 | "component system is:\n%s"), |
---|
| 129 | msg, bonobo_err); |
---|
| 130 | g_free (bonobo_err); |
---|
| 131 | } else { |
---|
| 132 | OAF_GeneralError *errval = CORBA_exception_value (&ev); |
---|
| 133 | |
---|
| 134 | errmsg = g_strdup_printf (_("%s\n\nThe error from the " |
---|
| 135 | "activation system is:\n%s"), |
---|
| 136 | msg, errval->description); |
---|
| 137 | } |
---|
| 138 | CORBA_exception_free (&ev); |
---|
| 139 | |
---|
| 140 | e_notice (parent, GNOME_MESSAGE_BOX_ERROR, errmsg); |
---|
| 141 | g_free (errmsg); |
---|
| 142 | } |
---|
[18141] | 143 | |
---|
| 144 | |
---|
| 145 | /** |
---|
| 146 | * e_get_activation_failure_msg: |
---|
| 147 | * @ev: An exception returned by an oaf_activate call. |
---|
| 148 | * |
---|
| 149 | * Get a descriptive error message from @ev. |
---|
| 150 | * |
---|
| 151 | * Return value: A newly allocated string with the printable error message. |
---|
| 152 | **/ |
---|
| 153 | char * |
---|
| 154 | e_get_activation_failure_msg (CORBA_Environment *ev) |
---|
| 155 | { |
---|
| 156 | g_return_val_if_fail (ev != NULL, NULL); |
---|
| 157 | |
---|
| 158 | if (CORBA_exception_id (ev) == NULL) |
---|
| 159 | return NULL; |
---|
| 160 | |
---|
| 161 | if (strcmp (CORBA_exception_id (ev), ex_OAF_GeneralError) != 0) { |
---|
| 162 | return bonobo_exception_get_text (ev); |
---|
| 163 | } else { |
---|
| 164 | const OAF_GeneralError *oaf_general_error; |
---|
| 165 | |
---|
| 166 | oaf_general_error = CORBA_exception_value (ev); |
---|
| 167 | return g_strdup (oaf_general_error->description); |
---|
| 168 | } |
---|
| 169 | } |
---|