diff options
author | Michael Zucci <zucchi@src.gnome.org> | 2004-09-20 13:59:55 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2004-09-20 13:59:55 +0800 |
commit | ef6a3af717132e0750f226fa8a0ee0f3c98e19f0 (patch) | |
tree | f4ed25f7a247a8ccb855a8d940777e7a3d21a3e3 /mail/em-popup.c | |
parent | 96111b1f1487ca3fe454b340a73ba927cc6bfb83 (diff) | |
download | gsoc2013-evolution-ef6a3af717132e0750f226fa8a0ee0f3c98e19f0.tar.gz gsoc2013-evolution-ef6a3af717132e0750f226fa8a0ee0f3c98e19f0.tar.zst gsoc2013-evolution-ef6a3af717132e0750f226fa8a0ee0f3c98e19f0.zip |
Merged notzed-eplugin-2-branch to head.
svn path=/trunk/; revision=27300
Diffstat (limited to 'mail/em-popup.c')
-rw-r--r-- | mail/em-popup.c | 800 |
1 files changed, 312 insertions, 488 deletions
diff --git a/mail/em-popup.c b/mail/em-popup.c index 28e5121c51..8b580e3147 100644 --- a/mail/em-popup.c +++ b/mail/em-popup.c @@ -40,6 +40,7 @@ #include <libgnome/gnome-url.h> #include <libgnomevfs/gnome-vfs-mime.h> +#include <libgnome/gnome-i18n.h> #include "em-popup.h" #include "e-util/e-msgport.h" @@ -63,71 +64,69 @@ #include <gal/util/e-util.h> -static void emp_standard_menu_factory(EMPopup *emp, EMPopupTarget *target, void *data); - -struct _EMPopupFactory { - struct _EMPopupFactory *next, *prev; - - char *menuid; - EMPopupFactoryFunc factory; - void *factory_data; -}; - -struct _menu_node { - struct _menu_node *next, *prev; - - GSList *menu; - GDestroyNotify freefunc; -}; - -struct _EMPopupPrivate { - EDList menus; -}; - -static EDList emp_factories = E_DLIST_INITIALISER(emp_factories); +static void emp_standard_menu_factory(EPopup *emp, void *data); static GObjectClass *emp_parent; static void emp_init(GObject *o) { - EMPopup *emp = (EMPopup *)o; - struct _EMPopupPrivate *p; - - p = emp->priv = g_malloc0(sizeof(struct _EMPopupPrivate)); - - e_dlist_init(&p->menus); + /*EMPopup *emp = (EMPopup *)o; */ } static void emp_finalise(GObject *o) { - EMPopup *emp = (EMPopup *)o; - struct _EMPopupPrivate *p = emp->priv; - struct _menu_node *mnode, *nnode; + ((GObjectClass *)emp_parent)->finalize(o); +} + +static void +emp_target_free(EPopup *ep, EPopupTarget *t) +{ + switch (t->type) { + case EM_POPUP_TARGET_SELECT: { + EMPopupTargetSelect *s = (EMPopupTargetSelect *)t; + + if (s->folder) + camel_object_unref(s->folder); + g_free(s->uri); + if (s->uids) + em_utils_uids_free(s->uids); + break; } + case EM_POPUP_TARGET_URI: { + EMPopupTargetURI *s = (EMPopupTargetURI *)t; - g_free(emp->menuid); + g_free(s->uri); + break; } + case EM_POPUP_TARGET_PART: { + EMPopupTargetPart *s = (EMPopupTargetPart *)t; - mnode = (struct _menu_node *)p->menus.head; - nnode = mnode->next; - while (nnode) { - if (mnode->freefunc) - mnode->freefunc(mnode->menu); + camel_object_unref(s->part); + g_free(s->mime_type); + break; } + case EM_POPUP_TARGET_FOLDER: { + EMPopupTargetFolder *s = (EMPopupTargetFolder *)t; - g_free(mnode); - mnode = nnode; - nnode = nnode->next; - } + g_free(s->uri); + break; } + case EM_POPUP_TARGET_ATTACHMENTS: { + EMPopupTargetAttachments *s = (EMPopupTargetAttachments *)t; - g_free(p); + g_slist_foreach(s->attachments, (GFunc)g_object_unref, NULL); + g_slist_free(s->attachments); + break; } + } - ((GObjectClass *)emp_parent)->finalize(o); + ((EPopupClass *)emp_parent)->target_free(ep, t); } static void 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 @@ -144,11 +143,8 @@ em_popup_get_type(void) sizeof(EMPopup), 0, (GInstanceInitFunc)emp_init }; - emp_parent = g_type_class_ref(G_TYPE_OBJECT); - type = g_type_register_static(G_TYPE_OBJECT, "EMPopup", &info, 0); - - /* FIXME: this should probably sit somewhere in global setup */ - em_popup_static_add_factory(NULL, (EMPopupFactoryFunc)emp_standard_menu_factory, NULL); + emp_parent = g_type_class_ref(e_popup_get_type()); + type = g_type_register_static(e_popup_get_type(), "EMPopup", &info, 0); } return type; @@ -158,291 +154,12 @@ EMPopup *em_popup_new(const char *menuid) { EMPopup *emp = g_object_new(em_popup_get_type(), 0); - emp->menuid = g_strdup(menuid); + e_popup_construct(&emp->popup, menuid); return emp; } /** - * em_popup_add_items: - * @emp: - * @items: - * @freefunc: - * - * Add new EMPopupItems to the menu's. Any with the same path - * will override previously defined menu items, at menu building - * time. - **/ -void -em_popup_add_items(EMPopup *emp, GSList *items, GDestroyNotify freefunc) -{ - struct _menu_node *node; - - node = g_malloc(sizeof(*node)); - node->menu = items; - node->freefunc = freefunc; - e_dlist_addtail(&emp->priv->menus, (EDListNode *)node); -} - -/** - * em_popup_add_static_items: - * @emp: - * @target: Target of this menu. - * - * Will load up any matching menu items from an installed - * popup factory. If the menuid of @emp is NULL, then this - * has no effect. - * - **/ -void -em_popup_add_static_items(EMPopup *emp, EMPopupTarget *target) -{ - struct _EMPopupFactory *f; - - if (emp->menuid == NULL || target == NULL) - return; - - /* setup the menu itself */ - f = (struct _EMPopupFactory *)emp_factories.head; - while (f->next) { - if (f->menuid == NULL - || !strcmp(f->menuid, emp->menuid)) { - f->factory(emp, target, f->factory_data); - } - f = f->next; - } -} - -static int -emp_cmp(const void *ap, const void *bp) -{ - struct _EMPopupItem *a = *((void **)ap); - struct _EMPopupItem *b = *((void **)bp); - - return strcmp(a->path, b->path); -} - -/** - * em_popup_create: - * @menuitems: - * @hide_mask: used to hide menu items, not sure of it's utility, - * since you could just 'not add them' in the first place. Saves - * copying logic anyway. - * @disable_mask: used to disable menu items. - * - * TEMPORARY code to create a menu from a list of items. - * - * The menu items are merged based on their path element, and - * built into a menu tree. - * - * Return value: - **/ -GtkMenu * -em_popup_create_menu(EMPopup *emp, guint32 hide_mask, guint32 disable_mask) -{ - struct _EMPopupPrivate *p = emp->priv; - struct _menu_node *mnode, *nnode; - GPtrArray *items = g_ptr_array_new(); - GSList *l; - GString *ppath = g_string_new(""); - GtkMenu *topmenu; - GHashTable *menu_hash = g_hash_table_new(g_str_hash, g_str_equal), - *group_hash = g_hash_table_new(g_str_hash, g_str_equal); - /*char *domain = NULL;*/ - int i; - - /* FIXME: need to override old ones with new names */ - mnode = (struct _menu_node *)p->menus.head; - nnode = mnode->next; - while (nnode) { - for (l=mnode->menu; l; l = l->next) - g_ptr_array_add(items, l->data); - mnode = nnode; - nnode = nnode->next; - } - - qsort(items->pdata, items->len, sizeof(items->pdata[0]), emp_cmp); - - topmenu = (GtkMenu *)gtk_menu_new(); - for (i=0;i<items->len;i++) { - GtkWidget *label; - struct _EMPopupItem *item = items->pdata[i]; - GtkMenu *thismenu; - GtkMenuItem *menuitem; - char *tmp; - - /* for bar's, the mask is exclusive or */ - if (item->mask) { - if ((item->type & EM_POPUP_TYPE_MASK) == EM_POPUP_BAR) { - if ((item->mask & hide_mask) == item->mask) - continue; - } else if (item->mask & hide_mask) - continue; - } - - g_string_truncate(ppath, 0); - tmp = strrchr(item->path, '/'); - if (tmp) { - g_string_append_len(ppath, item->path, tmp-item->path); - thismenu = g_hash_table_lookup(menu_hash, ppath->str); - g_assert(thismenu != NULL); - } else { - thismenu = topmenu; - } - - switch (item->type & EM_POPUP_TYPE_MASK) { - case EM_POPUP_ITEM: - if (item->image) { - GdkPixbuf *pixbuf; - GtkWidget *image; - - pixbuf = e_icon_factory_get_icon ((char *)item->image, E_ICON_SIZE_MENU); - image = gtk_image_new_from_pixbuf (pixbuf); - g_object_unref (pixbuf); - - gtk_widget_show(image); - menuitem = (GtkMenuItem *)gtk_image_menu_item_new(); - gtk_image_menu_item_set_image((GtkImageMenuItem *)menuitem, image); - } else { - menuitem = (GtkMenuItem *)gtk_menu_item_new(); - } - break; - case EM_POPUP_TOGGLE: - menuitem = (GtkMenuItem *)gtk_check_menu_item_new(); - gtk_check_menu_item_set_active((GtkCheckMenuItem *)menuitem, item->type & EM_POPUP_ACTIVE); - break; - case EM_POPUP_RADIO: - menuitem = (GtkMenuItem *)gtk_radio_menu_item_new(g_hash_table_lookup(group_hash, ppath->str)); - g_hash_table_insert(group_hash, ppath->str, gtk_radio_menu_item_get_group((GtkRadioMenuItem *)menuitem)); - gtk_check_menu_item_set_active((GtkCheckMenuItem *)menuitem, item->type & EM_POPUP_ACTIVE); - break; - case EM_POPUP_IMAGE: - menuitem = (GtkMenuItem *)gtk_image_menu_item_new(); - gtk_image_menu_item_set_image((GtkImageMenuItem *)menuitem, item->image); - break; - case EM_POPUP_SUBMENU: { - GtkMenu *submenu = (GtkMenu *)gtk_menu_new(); - - g_hash_table_insert(menu_hash, item->path, submenu); - menuitem = (GtkMenuItem *)gtk_menu_item_new(); - gtk_menu_item_set_submenu(menuitem, (GtkWidget *)submenu); - break; } - case EM_POPUP_BAR: - /* TODO: double-bar, end-bar stuff? */ - menuitem = (GtkMenuItem *)gtk_separator_menu_item_new(); - break; - default: - continue; - } - - if (item->label) { - label = gtk_label_new_with_mnemonic(_(item->label)); - gtk_misc_set_alignment((GtkMisc *)label, 0.0, 0.5); - gtk_widget_show(label); - gtk_container_add((GtkContainer *)menuitem, label); - } - - if (item->activate) - g_signal_connect(menuitem, "activate", item->activate, item->activate_data); - - gtk_menu_shell_append((GtkMenuShell *)thismenu, (GtkWidget *)menuitem); - - if (item->mask & disable_mask) - gtk_widget_set_sensitive((GtkWidget *)menuitem, FALSE); - - gtk_widget_show((GtkWidget *)menuitem); - } - - g_string_free(ppath, TRUE); - g_ptr_array_free(items, TRUE); - g_hash_table_destroy(menu_hash); - g_hash_table_destroy(group_hash); - - return topmenu; -} - -static void -emp_popup_done(GtkWidget *w, EMPopup *emp) -{ - gtk_widget_destroy(w); - g_object_unref(emp); -} - -/** - * em_popup_create_menu_once: - * @emp: EMPopup, once the menu is shown, this cannot be - * considered a valid pointer. - * @target: If set, the target of the selection. Static menu - * items will be added. The target will be freed once complete. - * @hide_mask: - * @disable_mask: - * - * Like popup_create_menu, but automatically sets up the menu - * so that it is destroyed once a selection takes place, and - * the EMPopup is unreffed. - * - * Return value: A menu, to popup. - **/ -GtkMenu * -em_popup_create_menu_once(EMPopup *emp, EMPopupTarget *target, guint32 hide_mask, guint32 disable_mask) -{ - GtkMenu *menu; - - if (target) - em_popup_add_static_items(emp, target); - - menu = em_popup_create_menu(emp, hide_mask, disable_mask); - - if (target) - g_signal_connect_swapped(menu, "selection_done", G_CALLBACK(em_popup_target_free), target); - g_signal_connect(menu, "selection_done", G_CALLBACK(emp_popup_done), emp); - - return menu; -} - -/* ********************************************************************** */ - -/** - * em_popup_static_add_factory: - * @menuid: - * @func: - * @data: - * - * Add a popup factory which will be called to add_items() any - * extra menu's if wants to do the current PopupTarget. - * - * TODO: Make the menuid a pattern? - * - * Return value: A handle to the factory. - **/ -EMPopupFactory * -em_popup_static_add_factory(const char *menuid, EMPopupFactoryFunc func, void *data) -{ - struct _EMPopupFactory *f = g_malloc0(sizeof(*f)); - - f->menuid = g_strdup(menuid); - f->factory = func; - f->factory_data = data; - e_dlist_addtail(&emp_factories, (EDListNode *)f); - - return f; -} - -/** - * em_popup_static_remove_factory: - * @f: - * - * Remove a popup factory. - **/ -void -em_popup_static_remove_factory(EMPopupFactory *f) -{ - e_dlist_remove((EDListNode *)f); - g_free(f->menuid); - g_free(f); -} - -/** * em_popup_target_new_select: * @folder: The selection will ref this for the life of it. * @folder_uri: @@ -452,21 +169,20 @@ em_popup_static_remove_factory(EMPopupFactory *f) * * Return value: **/ -EMPopupTarget * -em_popup_target_new_select(struct _CamelFolder *folder, const char *folder_uri, GPtrArray *uids) +EMPopupTargetSelect * +em_popup_target_new_select(EMPopup *emp, struct _CamelFolder *folder, const char *folder_uri, GPtrArray *uids) { - EMPopupTarget *t = g_malloc0(sizeof(*t)); + EMPopupTargetSelect *t = e_popup_target_new(&emp->popup, EM_POPUP_TARGET_SELECT, sizeof(*t)); guint32 mask = ~0; int i; const char *tmp; - t->type = EM_POPUP_TARGET_SELECT; - t->data.select.uids = uids; - t->data.select.folder = folder; - t->data.select.folder_uri = g_strdup(folder_uri); + t->uids = uids; + t->folder = folder; + t->uri = g_strdup(folder_uri); if (folder == NULL) { - t->mask = mask; + t->target.mask = mask; return t; } @@ -531,19 +247,18 @@ em_popup_target_new_select(struct _CamelFolder *folder, const char *folder_uri, camel_folder_free_message_info(folder, info); } - t->mask = mask; + t->target.mask = mask; return t; } -EMPopupTarget * -em_popup_target_new_uri(const char *uri) +EMPopupTargetURI * +em_popup_target_new_uri(EMPopup *emp, const char *uri) { - EMPopupTarget *t = g_malloc0(sizeof(*t)); + EMPopupTargetURI *t = e_popup_target_new(&emp->popup, EM_POPUP_TARGET_URI, sizeof(*t)); guint32 mask = ~0; - t->type = EM_POPUP_TARGET_URI; - t->data.uri = g_strdup(uri); + t->uri = g_strdup(uri); if (g_ascii_strncasecmp(uri, "http:", 5) == 0 || g_ascii_strncasecmp(uri, "https:", 6) == 0) @@ -553,48 +268,46 @@ em_popup_target_new_uri(const char *uri) else mask &= ~EM_POPUP_URI_NOT_MAILTO; - t->mask = mask; + t->target.mask = mask; return t; } -EMPopupTarget * -em_popup_target_new_part(struct _CamelMimePart *part, const char *mime_type) +EMPopupTargetPart * +em_popup_target_new_part(EMPopup *emp, struct _CamelMimePart *part, const char *mime_type) { - EMPopupTarget *t = g_malloc0(sizeof(*t)); + EMPopupTargetPart *t = e_popup_target_new(&emp->popup, EM_POPUP_TARGET_PART, sizeof(*t)); guint32 mask = ~0; - t->type = EM_POPUP_TARGET_PART; - t->data.part.part = part; + t->part = part; camel_object_ref(part); if (mime_type) - t->data.part.mime_type = g_strdup(mime_type); + t->mime_type = g_strdup(mime_type); else - t->data.part.mime_type = camel_data_wrapper_get_mime_type((CamelDataWrapper *)part); + t->mime_type = camel_data_wrapper_get_mime_type((CamelDataWrapper *)part); - camel_strdown(t->data.part.mime_type); + camel_strdown(t->mime_type); if (CAMEL_IS_MIME_MESSAGE(camel_medium_get_content_object((CamelMedium *)part))) mask &= ~EM_POPUP_PART_MESSAGE; - if (strncmp(t->data.part.mime_type, "image/", 6) == 0) + if (strncmp(t->mime_type, "image/", 6) == 0) mask &= ~EM_POPUP_PART_IMAGE; - t->mask = mask; + t->target.mask = mask; return t; } /* TODO: This should be based on the CamelFolderInfo, but ... em-folder-tree doesn't keep it? */ -EMPopupTarget * -em_popup_target_new_folder (const char *uri, guint32 info_flags, guint32 popup_flags) +EMPopupTargetFolder * +em_popup_target_new_folder (EMPopup *emp, const char *uri, guint32 info_flags, guint32 popup_flags) { - EMPopupTarget *t = g_malloc0(sizeof(*t)); + EMPopupTargetFolder *t = e_popup_target_new(&emp->popup, EM_POPUP_TARGET_FOLDER, sizeof(*t)); guint32 mask = ~0; CamelURL *url; - t->type = EM_POPUP_TARGET_FOLDER; - t->data.folder.folder_uri = g_strdup(uri); + t->uri = g_strdup(uri); if (popup_flags & EM_POPUP_FOLDER_STORE) mask &= ~(EM_POPUP_FOLDER_STORE|EM_POPUP_FOLDER_INFERIORS); @@ -629,91 +342,63 @@ em_popup_target_new_folder (const char *uri, guint32 info_flags, guint32 popup_f camel_url_free(url); done: - t->mask = mask; + t->target.mask = mask; return t; } -void -em_popup_target_free(EMPopupTarget *t) -{ - switch (t->type) { - case EM_POPUP_TARGET_SELECT: - if (t->data.select.folder) - camel_object_unref(t->data.select.folder); - g_free(t->data.select.folder_uri); - if (t->data.select.uids) - em_utils_uids_free(t->data.select.uids); - break; - case EM_POPUP_TARGET_URI: - g_free(t->data.uri); - break; - case EM_POPUP_TARGET_PART: - camel_object_unref(t->data.part.part); - g_free(t->data.part.mime_type); - break; - case EM_POPUP_TARGET_FOLDER: - g_free(t->data.folder.folder_uri); - break; - } - - g_free(t); -} - -/* ********************************************************************** */ - -#if 0 -/* TODO: flesh these out where possible */ -static void -emp_popup_open(GtkWidget *w, EMFolderView *emfv) +/** + * em_popup_target_new_attachments: + * @emp: + * @attachments: A list of EMsgComposerAttachment objects, reffed for + * the list. Will be unreff'd once finished with. + * + * Owns the list @attachments and their items after they're passed in. + * + * Return value: + **/ +EMPopupTargetAttachments * +em_popup_target_new_attachments(EMPopup *emp, GSList *attachments) { - em_folder_view_open_selected(emfv); -} + EMPopupTargetAttachments *t = e_popup_target_new(&emp->popup, EM_POPUP_TARGET_ATTACHMENTS, sizeof(*t)); + guint32 mask = ~0; + int len = g_slist_length(attachments); -static void -emp_popup_edit (GtkWidget *w, EMPopupTarget *t) -{ - if (!em_utils_check_user_can_send_mail(t->widget)) - return; - - em_utils_edit_messages(t->widget, t->data.select.folder, em_utils_uids_copy(t->data.select.uids), FALSE); -} + t->attachments = attachments; + if (len > 0) + mask &= ~ EM_POPUP_ATTACHMENTS_MANY; + if (len == 1) + mask &= ~ EM_POPUP_ATTACHMENTS_ONE; + t->target.mask = mask; -static void -emp_popup_saveas(GtkWidget *w, EMPopupTarget *t) -{ - em_utils_save_messages(t->widget, t->data.select.folder, em_utils_uids_copy(t->data.select.uids)); + return t; } -static EMPopupItem emp_standard_select_popups[] = { - /*{ EM_POPUP_ITEM, "00.select.00", N_("_Open"), G_CALLBACK(emp_popup_open), NULL, NULL, 0 },*/ - { EM_POPUP_ITEM, "00.select.01", N_("_Edit as New Message..."), G_CALLBACK(emp_popup_edit), NULL, NULL, EM_POPUP_SELECT_EDIT }, - { EM_POPUP_ITEM, "00.select.02", N_("_Save As..."), G_CALLBACK(emp_popup_saveas), NULL, "stock_save-as", 0 }, -}; -#endif - /* ********************************************************************** */ static void -emp_part_popup_saveas(GtkWidget *w, EMPopupTarget *t) +emp_part_popup_saveas(EPopup *ep, EPopupItem *item, void *data) { - em_utils_save_part(w, _("Save As..."), t->data.part.part); + EMPopupTargetPart *t = (EMPopupTargetPart *)ep->target; + + em_utils_save_part(ep->target->widget, _("Save As..."), t->part); } static void -emp_part_popup_set_background(GtkWidget *w, EMPopupTarget *t) +emp_part_popup_set_background(EPopup *ep, EPopupItem *item, void *data) { + EMPopupTargetPart *t = (EMPopupTargetPart *)ep->target; GConfClient *gconf; char *str, *filename, *path, *extension; unsigned int i=1; - filename = g_strdup(camel_mime_part_get_filename(t->data.part.part)); + filename = g_strdup(camel_mime_part_get_filename(t->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(t->data.part.part); + ct = camel_mime_part_get_content_type(t->part); g_free (filename); filename = g_strdup_printf (_("untitled_image.%s"), ct->subtype); } @@ -737,7 +422,7 @@ emp_part_popup_set_background(GtkWidget *w, EMPopupTarget *t) g_free(filename); - if (em_utils_save_part_to_file(w, path, t->data.part.part)) { + if (em_utils_save_part_to_file(ep->target->widget, path, t->part)) { gconf = gconf_client_get_default(); /* if the filename hasn't changed, blank the filename before @@ -767,64 +452,68 @@ emp_part_popup_set_background(GtkWidget *w, EMPopupTarget *t) } static void -emp_part_popup_reply_sender (GtkWidget *w, EMPopupTarget *t) +emp_part_popup_reply_sender(EPopup *ep, EPopupItem *item, void *data) { + EMPopupTargetPart *t = (EMPopupTargetPart *)ep->target; CamelMimeMessage *message; - message = (CamelMimeMessage *) camel_medium_get_content_object ((CamelMedium *) t->data.part.part); - em_utils_reply_to_message (NULL, NULL, message, REPLY_MODE_SENDER, NULL); + message = (CamelMimeMessage *)camel_medium_get_content_object((CamelMedium *)t->part); + em_utils_reply_to_message(NULL, NULL, message, REPLY_MODE_SENDER, NULL); } static void -emp_part_popup_reply_list (GtkWidget *w, EMPopupTarget *t) +emp_part_popup_reply_list (EPopup *ep, EPopupItem *item, void *data) { + EMPopupTargetPart *t = (EMPopupTargetPart *)ep->target; CamelMimeMessage *message; - message = (CamelMimeMessage *) camel_medium_get_content_object ((CamelMedium *) t->data.part.part); - em_utils_reply_to_message (NULL, NULL, message, REPLY_MODE_LIST, NULL); + message = (CamelMimeMessage *)camel_medium_get_content_object((CamelMedium *)t->part); + em_utils_reply_to_message(NULL, NULL, message, REPLY_MODE_LIST, NULL); } static void -emp_part_popup_reply_all (GtkWidget *w, EMPopupTarget *t) +emp_part_popup_reply_all (EPopup *ep, EPopupItem *item, void *data) { + EMPopupTargetPart *t = (EMPopupTargetPart *)ep->target; CamelMimeMessage *message; - message = (CamelMimeMessage *) camel_medium_get_content_object ((CamelMedium *) t->data.part.part); - em_utils_reply_to_message (NULL, NULL, message, REPLY_MODE_ALL, NULL); + message = (CamelMimeMessage *)camel_medium_get_content_object((CamelMedium *)t->part); + em_utils_reply_to_message(NULL, NULL, message, REPLY_MODE_ALL, NULL); } static void -emp_part_popup_forward (GtkWidget *w, EMPopupTarget *t) +emp_part_popup_forward (EPopup *ep, EPopupItem *item, void *data) { + EMPopupTargetPart *t = (EMPopupTargetPart *)ep->target; CamelMimeMessage *message; /* TODO: have a emfv specific override so we can get the parent folder uri */ - message = (CamelMimeMessage *) camel_medium_get_content_object ((CamelMedium *) t->data.part.part); - em_utils_forward_message (message, NULL); + message = (CamelMimeMessage *)camel_medium_get_content_object((CamelMedium *) t->part); + em_utils_forward_message(message, NULL); } static EMPopupItem emp_standard_object_popups[] = { - { EM_POPUP_ITEM, "00.part.00", N_("_Save As..."), G_CALLBACK(emp_part_popup_saveas), NULL, "stock_save-as", 0 }, - { EM_POPUP_ITEM, "00.part.10", N_("Set as _Background"), G_CALLBACK(emp_part_popup_set_background), NULL, NULL, EM_POPUP_PART_IMAGE }, - { EM_POPUP_BAR, "10.part", NULL, NULL, NULL, NULL, EM_POPUP_PART_MESSAGE }, - { EM_POPUP_ITEM, "10.part.00", N_("_Reply to sender"), G_CALLBACK(emp_part_popup_reply_sender), NULL, "stock_mail-reply" , EM_POPUP_PART_MESSAGE }, - { EM_POPUP_ITEM, "10.part.01", N_("Reply to _List"), G_CALLBACK(emp_part_popup_reply_list), NULL, NULL, EM_POPUP_PART_MESSAGE}, - { EM_POPUP_ITEM, "10.part.03", N_("Reply to _All"), G_CALLBACK(emp_part_popup_reply_all), NULL, "stock_mail-reply-to-all", EM_POPUP_PART_MESSAGE}, - { EM_POPUP_BAR, "20.part", NULL, NULL, NULL, NULL, EM_POPUP_PART_MESSAGE }, - { EM_POPUP_ITEM, "20.part.00", N_("_Forward"), G_CALLBACK(emp_part_popup_forward), NULL, "stock_mail-forward", EM_POPUP_PART_MESSAGE }, - + { E_POPUP_ITEM, "00.part.00", N_("_Save As..."), emp_part_popup_saveas, NULL, "stock_save-as", 0 }, + { E_POPUP_ITEM, "00.part.10", N_("Set as _Background"), emp_part_popup_set_background, NULL, NULL, EM_POPUP_PART_IMAGE }, + { E_POPUP_BAR, "10.part", NULL, NULL, NULL, NULL, EM_POPUP_PART_MESSAGE }, + { E_POPUP_ITEM, "10.part.00", N_("_Reply to sender"), emp_part_popup_reply_sender, NULL, "stock_mail-reply" , EM_POPUP_PART_MESSAGE }, + { E_POPUP_ITEM, "10.part.01", N_("Reply to _List"), emp_part_popup_reply_list, NULL, NULL, EM_POPUP_PART_MESSAGE}, + { E_POPUP_ITEM, "10.part.03", N_("Reply to _All"), emp_part_popup_reply_all, NULL, "stock_mail-reply-to-all", EM_POPUP_PART_MESSAGE}, + { E_POPUP_BAR, "20.part", NULL, NULL, NULL, NULL, EM_POPUP_PART_MESSAGE }, + { E_POPUP_ITEM, "20.part.00", N_("_Forward"), emp_part_popup_forward, NULL, "stock_mail-forward", EM_POPUP_PART_MESSAGE }, }; -static const EMPopupItem emp_standard_part_apps_bar = { EM_POPUP_BAR, "99.object" }; +static const EPopupItem emp_standard_part_apps_bar = { E_POPUP_BAR, "99.object" }; /* ********************************************************************** */ static void -emp_uri_popup_link_open(GtkWidget *w, EMPopupTarget *t) +emp_uri_popup_link_open(EPopup *ep, EPopupItem *item, void *data) { + EMPopupTargetURI *t = (EMPopupTargetURI *)ep->target; GError *err = NULL; - gnome_url_show(t->data.uri, &err); + gnome_url_show(t->uri, &err); if (err) { g_warning("gnome_url_show: %s", err->message); g_error_free(err); @@ -832,33 +521,36 @@ emp_uri_popup_link_open(GtkWidget *w, EMPopupTarget *t) } static void -emp_uri_popup_address_send (GtkWidget *w, EMPopupTarget *t) +emp_uri_popup_address_send(EPopup *ep, EPopupItem *item, void *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->data.uri, NULL); + em_utils_compose_new_message_with_mailto(t->uri, NULL); } static void -emp_uri_popup_address_add(GtkWidget *w, EMPopupTarget *t) +emp_uri_popup_address_add(EPopup *ep, EPopupItem *item, void *data) { + EMPopupTargetURI *t = (EMPopupTargetURI *)ep->target; CamelURL *url; - url = camel_url_new(t->data.uri, NULL); + url = camel_url_new(t->uri, NULL); if (url == NULL) { - g_warning("cannot parse url '%s'", t->data.uri); + g_warning("cannot parse url '%s'", t->uri); return; } if (url->path && url->path[0]) - em_utils_add_address(w, url->path); + em_utils_add_address(ep->target->widget, url->path); camel_url_free(url); } -static EMPopupItem emp_standard_uri_popups[] = { - { EM_POPUP_ITEM, "00.uri.00", N_("_Open Link in Browser"), G_CALLBACK(emp_uri_popup_link_open), NULL, NULL, EM_POPUP_URI_NOT_MAILTO }, - { EM_POPUP_ITEM, "00.uri.10", N_("Se_nd message to..."), G_CALLBACK(emp_uri_popup_address_send), NULL, NULL, EM_POPUP_URI_MAILTO }, - { EM_POPUP_ITEM, "00.uri.20", N_("_Add to Addressbook"), G_CALLBACK(emp_uri_popup_address_add), NULL, NULL, EM_POPUP_URI_MAILTO }, +static EPopupItem emp_standard_uri_popups[] = { + { E_POPUP_ITEM, "00.uri.00", N_("_Open Link in Browser"), emp_uri_popup_link_open, NULL, NULL, EM_POPUP_URI_NOT_MAILTO }, + { E_POPUP_ITEM, "00.uri.10", N_("Se_nd message to..."), emp_uri_popup_address_send, NULL, NULL, EM_POPUP_URI_MAILTO }, + { E_POPUP_ITEM, "00.uri.20", N_("_Add to Addressbook"), emp_uri_popup_address_add, NULL, NULL, EM_POPUP_URI_MAILTO }, }; /* ********************************************************************** */ @@ -867,23 +559,21 @@ static EMPopupItem emp_standard_uri_popups[] = { #include <libgnomevfs/gnome-vfs-mime-handlers.h> -struct _open_in_item { - EMPopupItem item; - EMPopupTarget *target; - GnomeVFSMimeApplication *app; -}; + EMPopupTargetPart *target; static void -emp_apps_open_in(GtkWidget *w, struct _open_in_item *item) +emp_apps_open_in(EPopup *ep, EPopupItem *item, void *data) { char *path; + EMPopupTargetPart *target = (EMPopupTargetPart *)ep->target; - path = em_utils_temp_save_part(item->target->widget, item->target->data.part.part); + path = em_utils_temp_save_part(target->target.widget, target->part); if (path) { - int douri = (item->app->expects_uris == GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS); + GnomeVFSMimeApplication *app = item->user_data; + int douri = (app->expects_uris == GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS); char *command; - if (item->app->requires_terminal) { + if (app->requires_terminal) { char *term, *args = NULL; GConfClient *gconf; @@ -896,11 +586,11 @@ emp_apps_open_in(GtkWidget *w, struct _open_in_item *item) return; command = g_strdup_printf ("%s%s%s %s %s%s &", term, args ? " " : "", args ? args : "", - item->app->command, douri ? "file://" : "", path); + app->command, douri ? "file://" : "", path); g_free (term); g_free (args); } else { - command = g_strdup_printf ("%s %s%s &", item->app->command, douri ? "file://" : "", path); + command = g_strdup_printf ("%s %s%s &", app->command, douri ? "file://" : "", path); } /* FIXME: Do not use system here */ @@ -911,14 +601,14 @@ emp_apps_open_in(GtkWidget *w, struct _open_in_item *item) } static void -emp_apps_popup_free(GSList *free_list) +emp_apps_popup_free(EPopup *ep, GSList *free_list, void *data) { while (free_list) { GSList *n = free_list->next; - struct _open_in_item *item = free_list->data; + EPopupItem *item = free_list->data; - g_free(item->item.path); - g_free(item->item.label); + g_free(item->path); + g_free(item->label); g_free(item); g_slist_free_1(free_list); @@ -927,13 +617,19 @@ emp_apps_popup_free(GSList *free_list) } static void -emp_standard_menu_factory(EMPopup *emp, EMPopupTarget *target, void *data) +emp_standard_items_free(EPopup *ep, GSList *items, void *data) +{ + g_slist_free(items); +} + +static void +emp_standard_menu_factory(EPopup *emp, void *data) { int i, len; - EMPopupItem *items; + EPopupItem *items; GSList *menus = NULL; - switch (target->type) { + switch (emp->target->type) { #if 0 case EM_POPUP_TARGET_SELECT: return; @@ -941,18 +637,21 @@ emp_standard_menu_factory(EMPopup *emp, EMPopupTarget *target, void *data) len = LEN(emp_standard_select_popups); break; #endif - case EM_POPUP_TARGET_URI: + case EM_POPUP_TARGET_URI: { + /*EMPopupTargetURI *t = (EMPopupTargetURI *)target;*/ + items = emp_standard_uri_popups; len = LEN(emp_standard_uri_popups); - break; + break; } case EM_POPUP_TARGET_PART: { - GList *apps = gnome_vfs_mime_get_short_list_applications(target->data.part.mime_type); + EMPopupTargetPart *t = (EMPopupTargetPart *)emp->target; + GList *apps = gnome_vfs_mime_get_short_list_applications(t->mime_type); /* FIXME: use the snoop_part stuff from em-format.c */ - if (apps == NULL && strcmp(target->data.part.mime_type, "application/octet-stream") == 0) { + if (apps == NULL && strcmp(t->mime_type, "application/octet-stream") == 0) { const char *filename, *name_type; - filename = camel_mime_part_get_filename(target->data.part.part); + filename = camel_mime_part_get_filename(t->part); if (filename) { /* GNOME-VFS will misidentify TNEF attachments as MPEG */ @@ -974,25 +673,23 @@ emp_standard_menu_factory(EMPopup *emp, EMPopupTarget *target, void *data) for (l = apps, i = 0; l; l = l->next, i++) { GnomeVFSMimeApplication *app = l->data; - struct _open_in_item *item; + EPopupItem *item; if (app->requires_terminal) continue; item = g_malloc0(sizeof(*item)); - item->item.type = EM_POPUP_ITEM; - item->item.path = g_strdup_printf("99.object.%02d", i); - item->item.label = g_strdup_printf(_("Open in %s..."), app->name); - item->item.activate = G_CALLBACK(emp_apps_open_in); - item->item.activate_data = item; - item->target = target; - item->app = app; + item->type = E_POPUP_ITEM; + item->path = g_strdup_printf("99.object.%02d", i); + item->label = g_strdup_printf(_("Open in %s..."), app->name); + item->activate = emp_apps_open_in; + item->user_data = app; open_menus = g_slist_prepend(open_menus, item); } if (open_menus) - em_popup_add_items(emp, open_menus, (GDestroyNotify)emp_apps_popup_free); + e_popup_add_items(emp, open_menus, emp_apps_popup_free, NULL); g_string_free(label, TRUE); g_list_free(apps); @@ -1007,12 +704,139 @@ emp_standard_menu_factory(EMPopup *emp, EMPopupTarget *target, void *data) } for (i=0;i<len;i++) { - if ((items[i].mask & target->mask) == 0) { - items[i].activate_data = target; + if ((items[i].visible & emp->target->mask) == 0) menus = g_slist_prepend(menus, &items[i]); - } } if (menus) - em_popup_add_items(emp, menus, (GDestroyNotify)g_slist_free); + e_popup_add_items(emp, menus, emp_standard_items_free, NULL); +} + +/* ********************************************************************** */ + +/* Popup menu plugin handler */ + +/* +<e-plugin + class="com.ximian.mail.plugin.popup:1.0" + id="com.ximian.mail.plugin.popup.item:1.0" + type="shlib" + location="/opt/gnome2/lib/camel/1.0/libcamelimap.so" + name="imap" + description="IMAP4 and IMAP4v1 mail store"> + <hook class="com.ximian.mail.popupMenu:1.0" + handler="HandlePopup"> + <menu id="any" target="select"> + <item + type="item|toggle|radio|image|submenu|bar" + active + path="foo/bar" + label="label" + icon="foo" + mask="select_one" + activate="emp_view_emacs"/> + </menu> + </extension> + +*/ + +static void *emph_parent_class; +#define emph ((EMPopupHook *)eph) + +static const EPopupHookTargetMask emph_select_masks[] = { + { "one", EM_POPUP_SELECT_ONE }, + { "many", EM_POPUP_SELECT_MANY }, + { "mark_read", EM_POPUP_SELECT_MARK_READ }, + { "mark_unread", EM_POPUP_SELECT_MARK_UNREAD }, + { "delete", EM_POPUP_SELECT_DELETE }, + { "undelete", EM_POPUP_SELECT_UNDELETE }, + { "mailing_list", EM_POPUP_SELECT_MAILING_LIST }, + { "resend", EM_POPUP_SELECT_EDIT }, + { "mark_important", EM_POPUP_SELECT_MARK_IMPORTANT }, + { "mark_unimportant", EM_POPUP_SELECT_MARK_UNIMPORTANT }, + { "flag_followup", EM_POPUP_SELECT_FLAG_FOLLOWUP }, + { "flag_completed", EM_POPUP_SELECT_FLAG_COMPLETED }, + { "flag_clear", EM_POPUP_SELECT_FLAG_CLEAR }, + { "add_sender", EM_POPUP_SELECT_ADD_SENDER }, + { "mark_junk", EM_POPUP_SELECT_MARK_JUNK }, + { "mark_nojunk", EM_POPUP_SELECT_MARK_NOJUNK }, + { "folder", EM_POPUP_SELECT_FOLDER }, + { 0 } +}; + +static const EPopupHookTargetMask emph_uri_masks[] = { + { "http", EM_POPUP_URI_HTTP }, + { "mailto", EM_POPUP_URI_MAILTO }, + { "notmailto", EM_POPUP_URI_NOT_MAILTO }, + { 0 } +}; + +static const EPopupHookTargetMask emph_part_masks[] = { + { "message", EM_POPUP_PART_MESSAGE }, + { "image", EM_POPUP_PART_IMAGE }, + { 0 } +}; + +static const EPopupHookTargetMask emph_folder_masks[] = { + { "folder", EM_POPUP_FOLDER_FOLDER }, + { "store", EM_POPUP_FOLDER_STORE }, + { "inferiors", EM_POPUP_FOLDER_INFERIORS }, + { "delete", EM_POPUP_FOLDER_DELETE }, + { "select", EM_POPUP_FOLDER_SELECT }, + { 0 } +}; + +static const EPopupHookTargetMask emph_attachments_masks[] = { + { "one", EM_POPUP_ATTACHMENTS_ONE }, + { "many", EM_POPUP_ATTACHMENTS_MANY }, + { 0 } +}; + +static const EPopupHookTargetMap emph_targets[] = { + { "select", EM_POPUP_TARGET_SELECT, emph_select_masks }, + { "uri", EM_POPUP_TARGET_URI, emph_uri_masks }, + { "part", EM_POPUP_TARGET_PART, emph_part_masks }, + { "folder", EM_POPUP_TARGET_FOLDER, emph_folder_masks }, + { "attachments", EM_POPUP_TARGET_ATTACHMENTS, emph_attachments_masks }, + { 0 } +}; + +static void +emph_finalise(GObject *o) +{ + /*EPluginHook *eph = (EPluginHook *)o;*/ + + ((GObjectClass *)emph_parent_class)->finalize(o); +} + +static void +emph_class_init(EPluginHookClass *klass) +{ + int i; + + ((GObjectClass *)klass)->finalize = emph_finalise; + ((EPluginHookClass *)klass)->id = "com.ximian.evolution.mail.popup:1.0"; + + for (i=0;emph_targets[i].type;i++) + e_popup_hook_class_add_target_map((EPopupHookClass *)klass, &emph_targets[i]); + + ((EPopupHookClass *)klass)->popup_class = g_type_class_ref(em_popup_get_type()); +} + +GType +em_popup_hook_get_type(void) +{ + static GType type = 0; + + if (!type) { + static const GTypeInfo info = { + sizeof(EMPopupHookClass), NULL, NULL, (GClassInitFunc) emph_class_init, NULL, NULL, + sizeof(EMPopupHook), 0, (GInstanceInitFunc) NULL, + }; + + emph_parent_class = g_type_class_ref(e_popup_hook_get_type()); + type = g_type_register_static(e_popup_hook_get_type(), "EMPopupHook", &info, 0); + } + + return type; } |