diff options
Diffstat (limited to 'mail/em-popup.c')
-rw-r--r-- | mail/em-popup.c | 416 |
1 files changed, 0 insertions, 416 deletions
diff --git a/mail/em-popup.c b/mail/em-popup.c index 4fc912ba07..f9caf9de0c 100644 --- a/mail/em-popup.c +++ b/mail/em-popup.c @@ -55,8 +55,6 @@ #include <e-util/e-util.h> #include "e-attachment.h" -static void emp_standard_menu_factory(EPopup *emp, gpointer data); - static GObjectClass *emp_parent; static void @@ -110,8 +108,6 @@ emp_class_init(GObjectClass *klass) { klass->finalize = emp_finalise; ((EPopupClass *)klass)->target_free = emp_target_free; - - e_popup_class_add_factory((EPopupClass *)klass, NULL, emp_standard_menu_factory, NULL); } GType @@ -353,418 +349,6 @@ done: /* ********************************************************************** */ -static void -emp_part_popup_saveas(EPopup *ep, EPopupItem *item, gpointer data) -{ - EPopupTarget *t = ep->target; - CamelMimePart *part = NULL; - - part = ((EMPopupTargetPart *) t)->part; - - em_utils_save_part(ep->target->widget, _("Save As..."), part); -} - -static void -emp_part_popup_set_background(EPopup *ep, EPopupItem *item, gpointer data) -{ - EPopupTarget *t = ep->target; - GConfClient *gconf; - gchar *str, *filename, *path, *extension; - guint i=1; - CamelMimePart *part = NULL; - - part = ((EMPopupTargetPart *) t)->part; - - if (!part) - return; - - filename = g_strdup(camel_mime_part_get_filename(part)); - - /* if filename is blank, create a default filename based on MIME type */ - if (!filename || !filename[0]) { - CamelContentType *ct; - - ct = camel_mime_part_get_content_type(part); - g_free (filename); - filename = g_strdup_printf (_("untitled_image.%s"), ct->subtype); - } - - e_filename_make_safe(filename); - - path = g_build_filename(g_get_home_dir(), ".gnome2", "wallpapers", filename, NULL); - - extension = strrchr(filename, '.'); - if (extension) - *extension++ = 0; - - /* if file exists, stick a (number) on the end */ - while (g_file_test(path, G_FILE_TEST_EXISTS)) { - gchar *name; - name = g_strdup_printf(extension?"%s (%d).%s":"%s (%d)", filename, i++, extension); - g_free(path); - path = g_build_filename(g_get_home_dir(), ".gnome2", "wallpapers", name, NULL); - g_free(name); - } - - g_free(filename); - - if (em_utils_save_part_to_file(ep->target->widget, path, part)) { - gconf = gconf_client_get_default(); - - /* if the filename hasn't changed, blank the filename before - * setting it so that gconf detects a change and updates it */ - if ((str = gconf_client_get_string(gconf, "/desktop/gnome/background/picture_filename", NULL)) != NULL - && strcmp (str, path) == 0) { - gconf_client_set_string(gconf, "/desktop/gnome/background/picture_filename", "", NULL); - } - - g_free (str); - gconf_client_set_string(gconf, "/desktop/gnome/background/picture_filename", path, NULL); - - /* if GNOME currently doesn't display a picture, set to "wallpaper" - * display mode, otherwise leave it alone */ - if ((str = gconf_client_get_string(gconf, "/desktop/gnome/background/picture_options", NULL)) == NULL - || strcmp(str, "none") == 0) { - gconf_client_set_string(gconf, "/desktop/gnome/background/picture_options", "wallpaper", NULL); - } - - gconf_client_suggest_sync(gconf, NULL); - - g_free(str); - g_object_unref(gconf); - } - - g_free(path); -} - -static void -emp_part_popup_reply_sender(EPopup *ep, EPopupItem *item, gpointer data) -{ - EPopupTarget *t = ep->target; - CamelMimeMessage *message; - CamelMimePart *part; - - part = ((EMPopupTargetPart *) t)->part; - - message = (CamelMimeMessage *)camel_medium_get_content_object((CamelMedium *)part); - em_utils_reply_to_message(NULL, NULL, message, REPLY_MODE_SENDER, NULL); -} - -static void -emp_part_popup_reply_list (EPopup *ep, EPopupItem *item, gpointer data) -{ - EPopupTarget *t = ep->target; - CamelMimeMessage *message; - CamelMimePart *part; - - part = ((EMPopupTargetPart *) t)->part; - - message = (CamelMimeMessage *)camel_medium_get_content_object((CamelMedium *)part); - em_utils_reply_to_message(NULL, NULL, message, REPLY_MODE_LIST, NULL); -} - -static void -emp_part_popup_reply_all (EPopup *ep, EPopupItem *item, gpointer data) -{ - EPopupTarget *t = ep->target; - CamelMimeMessage *message; - CamelMimePart *part; - - part = ((EMPopupTargetPart *) t)->part; - - message = (CamelMimeMessage *)camel_medium_get_content_object((CamelMedium *)part); - em_utils_reply_to_message(NULL, NULL, message, REPLY_MODE_ALL, NULL); -} - -static void -emp_part_popup_forward (EPopup *ep, EPopupItem *item, gpointer data) -{ - EPopupTarget *t = ep->target; - CamelMimeMessage *message; - CamelMimePart *part; - - part = ((EMPopupTargetPart *) t)->part; - - /* TODO: have a emfv specific override so we can get the parent folder uri */ - message = (CamelMimeMessage *)camel_medium_get_content_object((CamelMedium *) part); - em_utils_forward_message(message, NULL); -} - -static EMPopupItem emp_standard_object_popups[] = { - { E_POPUP_ITEM, (gchar *) "00.part.00", (gchar *) N_("_Save As..."), emp_part_popup_saveas, NULL, (gchar *) "document-save-as", 0 }, - { E_POPUP_ITEM, (gchar *) "00.part.10", (gchar *) N_("Set as _Background"), emp_part_popup_set_background, NULL, NULL, EM_POPUP_PART_IMAGE }, - { E_POPUP_BAR, (gchar *) "10.part", NULL, NULL, NULL, NULL, EM_POPUP_PART_MESSAGE }, - { E_POPUP_ITEM, (gchar *) "10.part.00", (gchar *) N_("_Reply to sender"), emp_part_popup_reply_sender, NULL, (gchar *) "mail-reply-sender" , EM_POPUP_PART_MESSAGE }, - { E_POPUP_ITEM, (gchar *) "10.part.01", (gchar *) N_("Reply to _List"), emp_part_popup_reply_list, NULL, NULL, EM_POPUP_PART_MESSAGE}, - { E_POPUP_ITEM, (gchar *) "10.part.03", (gchar *) N_("Reply to _All"), emp_part_popup_reply_all, NULL, (gchar *) "mail-reply-all", EM_POPUP_PART_MESSAGE}, - { E_POPUP_BAR, (gchar *) "20.part", NULL, NULL, NULL, NULL, EM_POPUP_PART_MESSAGE }, - { E_POPUP_ITEM, (gchar *) "20.part.00", (gchar *) N_("_Forward"), emp_part_popup_forward, NULL, (gchar *) "mail-forward", EM_POPUP_PART_MESSAGE }, -}; - -static const EPopupItem emp_standard_part_apps_bar = { E_POPUP_BAR, (gchar *) "99.object" }; - -/* ********************************************************************** */ - -static void -emp_uri_popup_link_open(EPopup *ep, EPopupItem *item, gpointer data) -{ - EMPopupTargetURI *t = (EMPopupTargetURI *)ep->target; - - /* FIXME Pass a parent window. */ - e_show_uri (NULL, t->uri); -} - -static void -emp_uri_popup_address_send(EPopup *ep, EPopupItem *item, gpointer data) -{ - EMPopupTargetURI *t = (EMPopupTargetURI *)ep->target; - - /* TODO: have an emfv specific override to get the from uri */ - em_utils_compose_new_message_with_mailto(t->uri, NULL); -} - -static void -emp_uri_popup_address_add(EPopup *ep, EPopupItem *item, gpointer data) -{ - EMPopupTargetURI *t = (EMPopupTargetURI *)ep->target; - CamelURL *url; - - url = camel_url_new(t->uri, NULL); - if (url == NULL) { - g_warning("cannot parse url '%s'", t->uri); - return; - } - - if (url->path && url->path[0]) - em_utils_add_address(ep->target->widget, url->path); - - camel_url_free(url); -} - -static EPopupItem emp_standard_uri_popups[] = { - { E_POPUP_ITEM, (gchar *) "00.uri.00", (gchar *) N_("_Open Link in Browser"), emp_uri_popup_link_open, NULL, NULL, EM_POPUP_URI_HTTP }, - { E_POPUP_ITEM, (gchar *) "00.uri.10", (gchar *) N_("_Send New Message To..."), emp_uri_popup_address_send, NULL, (gchar *) "mail-message-new", EM_POPUP_URI_MAILTO }, - { E_POPUP_ITEM, (gchar *) "00.uri.20", (gchar *) N_("_Add to Address Book"), emp_uri_popup_address_add, NULL, (gchar *) "contact-new", EM_POPUP_URI_MAILTO }, -}; - -/* ********************************************************************** */ - -#define LEN(x) (sizeof(x)/sizeof(x[0])) - -static void -emp_apps_open_in(EPopup *ep, EPopupItem *item, gpointer data) -{ - gchar *path; - EPopupTarget *target = ep->target; - CamelMimePart *part; - - part = ((EMPopupTargetPart *) target)->part; - - path = em_utils_temp_save_part(target->widget, part, TRUE); - if (path) { - GAppInfo *app = item->user_data; - GList *uris = NULL; - GError *error = NULL; - - if (g_app_info_supports_files (app)) { - GFile *file = g_file_new_for_path (path); - - uris = g_list_append (uris, file); - g_app_info_launch (app, uris, NULL, &error); - g_object_unref (file); - } else { - gchar *uri; - - uri = e_util_filename_to_uri (path); - uris = g_list_append (uris, uri); - - g_app_info_launch_uris (app, uris, NULL, &error); - g_free (uri); - } - - if (error) { - g_warning ("%s", error->message); - g_error_free (error); - } - - g_list_free (uris); - g_free (path); - } -} - -static void -emp_apps_popup_free(EPopup *ep, GSList *free_list, gpointer data) -{ - while (free_list) { - GSList *n = free_list->next; - EPopupItem *item = free_list->data; - - if (item->user_data && item->activate == emp_apps_open_in) - g_object_unref (item->user_data); - - g_free(item->path); - g_free(item->label); - g_free(item); - g_slist_free_1(free_list); - - free_list = n; - } -} - -static void -emp_standard_items_free(EPopup *ep, GSList *items, gpointer data) -{ - g_slist_free(items); -} - -static void -emp_add_vcard (EPopup *ep, EPopupItem *item, gpointer data) -{ - EPopupTarget *target = ep->target; - CamelMimePart *part; - CamelDataWrapper *content; - CamelStreamMem *mem; - - part = ((EMPopupTargetPart *) target)->part; - - if (!part) - return; - - content = camel_medium_get_content_object (CAMEL_MEDIUM (part)); - mem = CAMEL_STREAM_MEM (camel_stream_mem_new ()); - - if (camel_data_wrapper_decode_to_stream (content, CAMEL_STREAM (mem)) == -1 || - !mem->buffer->data) - g_warning ("Read part's content failed!"); - else { - GString *vcard = g_string_new_len ((const gchar *) mem->buffer->data, mem->buffer->len); - - em_utils_add_vcard (target->widget, vcard->str); - - g_string_free (vcard, TRUE); - } - - camel_object_unref (mem); -} - -static void -emp_standard_menu_factory(EPopup *emp, gpointer data) -{ - gint i, len; - EPopupItem *items; - GSList *menus = NULL; - GList *apps = NULL; - gchar *mime_type = NULL; - const gchar *filename = NULL; - - switch (emp->target->type) { -#if 0 - case EM_POPUP_TARGET_SELECT: - return; - items = emp_standard_select_popups; - len = LEN(emp_standard_select_popups); - break; -#endif - case EM_POPUP_TARGET_URI: { - /*EMPopupTargetURI *t = (EMPopupTargetURI *)target;*/ - - items = emp_standard_uri_popups; - len = LEN(emp_standard_uri_popups); - break; } - case EM_POPUP_TARGET_PART: { - EMPopupTargetPart *t = (EMPopupTargetPart *)emp->target; - mime_type = camel_data_wrapper_get_mime_type((CamelDataWrapper *)t->part); - filename = camel_mime_part_get_filename(t->part); - - items = emp_standard_object_popups; - len = LEN(emp_standard_object_popups); - break; } - default: - items = NULL; - len = 0; - } - - if (mime_type) { - gchar *cp; - - /* GIO expects lowercase MIME types. */ - for (cp = mime_type; *cp != '\0'; cp++) - *cp = g_ascii_tolower (*cp); - - cp = g_content_type_from_mime_type (mime_type); - apps = g_app_info_get_all_for_type (cp ? cp : mime_type); - g_free (cp); - - if (apps == NULL || strcmp (mime_type, "application/octet-stream") == 0) { - if (filename != NULL) { - gchar *name_type; - - name_type = e_util_guess_mime_type (filename, FALSE); - cp = g_content_type_from_mime_type (name_type); - /* show alternative apps first */ - apps = g_list_concat (g_app_info_get_all_for_type (cp ? cp : name_type), apps); - g_free (cp); - g_free (name_type); - } - } - - if (apps) { - GString *label = g_string_new(""); - GSList *open_menus = NULL; - GList *l; - - menus = g_slist_prepend(menus, (gpointer)&emp_standard_part_apps_bar); - - for (l = apps, i = 0; l; l = l->next, i++) { - GAppInfo *app = l->data; - EPopupItem *item; - - item = g_malloc0(sizeof(*item)); - item->type = E_POPUP_ITEM; - item->path = g_strdup_printf("99.object.%02d", i); - item->label = g_strdup_printf(_("Open in %s..."), g_app_info_get_name (app)); - item->activate = emp_apps_open_in; - item->user_data = app; - - open_menus = g_slist_prepend(open_menus, item); - } - - if (open_menus) - e_popup_add_items(emp, open_menus, NULL, emp_apps_popup_free, NULL); - - g_string_free(label, TRUE); - g_list_free(apps); - } - - if (g_ascii_strcasecmp (mime_type, "text/x-vcard") == 0|| - g_ascii_strcasecmp (mime_type, "text/vcard") == 0) { - EPopupItem *item; - - item = g_malloc0 (sizeof (*item)); - item->type = E_POPUP_ITEM; - item->path = (gchar *) "00.00.vcf.00"; /* make it first item */ - item->label = _("_Add to Address Book"); - item->activate = emp_add_vcard; - item->user_data = NULL; - item->image = (gchar *) "contact-new"; - - e_popup_add_items (emp, g_slist_append (NULL, item), NULL, NULL, NULL); - } - - g_free (mime_type); - } - - for (i=0;i<len;i++) { - if ((items[i].visible & emp->target->mask) == 0) - menus = g_slist_prepend(menus, &items[i]); - } - - if (menus) - e_popup_add_items(emp, menus, NULL, emp_standard_items_free, NULL); -} - -/* ********************************************************************** */ - /* Popup menu plugin handler */ /* |