static void headerview_save_contact_pic (HeaderView *headerview, MsgInfo *msginfo) { #ifndef USE_ALT_ADDRBOOK gchar *filename = NULL; GError *error = NULL; GdkPixbuf *picture = NULL; if (!gtk_widget_get_visible(headerview->hbox)) return; if (headerview->image) { picture = gtk_image_get_pixbuf(GTK_IMAGE(headerview->image)); } filename = addrindex_get_picture_file(msginfo->from); if (!filename) return; if (!is_file_exist(filename)) { gdk_pixbuf_save(picture, filename, "png", &error, NULL); if (error) { g_warning("Failed to save image: %s", error->message); g_error_free(error); } } g_free(filename); #else /* new address book */ #endif }
static gboolean notification_trayicon_popup_create(MsgInfo *msginfo, NotificationFolderType nftype) { gchar *summary = NULL; gchar *utf8_str = NULL; GdkPixbuf *pixbuf; GList *caps = NULL; gboolean support_actions = FALSE; /* init libnotify if necessary */ if(!notify_is_initted()) { if(!notify_init("claws-mail")) { debug_print("Notification Plugin: Failed to initialize libnotify. " "No popups will be shown.\n"); return FALSE; } } /* Count messages */ notification_trayicon_popup_count_msgs(nftype); summary = notification_trayicon_popup_assemble_summary(); utf8_str = notification_trayicon_popup_assemble_body(msginfo); #if NOTIFY_CHECK_VERSION(0, 7, 0) popup.notification = notify_notification_new(summary, utf8_str, NULL); #else popup.notification = notify_notification_new(summary, utf8_str, NULL, NULL); notify_notification_attach_to_status_icon(popup.notification, trayicon); #endif g_free(summary); g_free(utf8_str); caps = notify_get_server_caps(); if(caps != NULL) { GList *c; for(c = caps; c != NULL; c = c->next) { if(strcmp((char*)c->data, "actions") == 0 ) { support_actions = TRUE; break; } } g_list_foreach(caps, (GFunc)g_free, NULL); g_list_free(caps); } /* Default action */ if (support_actions) notify_notification_add_action(popup.notification, "default", "Present main window", (NotifyActionCallback) notification_trayicon_popup_default_action_cb, GINT_TO_POINTER(nftype), notification_trayicon_popup_free_func); if(popup.notification == NULL) { debug_print("Notification Plugin: Failed to create a new notification.\n"); return FALSE; } /* Icon */ pixbuf = NULL; #ifndef USE_NEW_ADDRBOOK if(msginfo && msginfo->from) { gchar *icon_path; icon_path = addrindex_get_picture_file(msginfo->from); if(is_file_exist(icon_path)) { GError *error = NULL; gint w, h; gdk_pixbuf_get_file_info(icon_path, &w, &h); if((w > 64) || (h > 64)) pixbuf = gdk_pixbuf_new_from_file_at_scale(icon_path, 64, 64, TRUE, &error); else pixbuf = gdk_pixbuf_new_from_file(icon_path, &error); if(!pixbuf) { debug_print("Could not load picture file: %s\n", error ? error->message : "no details"); g_error_free(error); } } else debug_print("Picture path does not exist: %s\n",icon_path); g_free(icon_path); } #endif if(!pixbuf) pixbuf = g_object_ref(notification_pixbuf_get(NOTIFICATION_CM_LOGO_64x64)); if(pixbuf) { notify_notification_set_icon_from_pixbuf(popup.notification, pixbuf); g_object_unref(pixbuf); } else /* This is not fatal */ debug_print("Notification plugin: Icon could not be loaded.\n"); /* timeout */ notify_notification_set_timeout(popup.notification, notify_config.trayicon_popup_timeout); /* Category */ notify_notification_set_category(popup.notification, "email.arrived"); /* get notified on bubble close */ g_signal_connect(G_OBJECT(popup.notification), "closed", G_CALLBACK(popup_timeout_fun), NULL); /* Show the popup */ notify_notification_set_hint_string(popup.notification, "desktop-entry", "claws-mail"); if(!notify_notification_show(popup.notification, &(popup.error))) { debug_print("Notification Plugin: Failed to send notification: %s\n", popup.error->message); g_clear_error(&(popup.error)); g_object_unref(G_OBJECT(popup.notification)); popup.notification = NULL; return FALSE; } /* Store path to message */ if(nftype == F_TYPE_MAIL) { if(msginfo->folder && msginfo->folder) { gchar *ident; ident = folder_item_get_identifier(msginfo->folder); popup.msg_path = g_strdup_printf("%s%s%u", ident,G_DIR_SEPARATOR_S, msginfo->msgnum); g_free(ident); } else popup.msg_path = NULL; } debug_print("Notification Plugin: Popup created with libnotify.\n"); return TRUE; }
static gboolean notification_libnotify_create(MsgInfo *msginfo, NotificationFolderType nftype) { GdkPixbuf *pixbuf; NotificationPopup *ppopup; gchar *summary = NULL; gchar *text = NULL; gchar *utf8_str = NULL; gchar *subj = NULL; gchar *from = NULL; gchar *foldname = NULL; GList *caps = NULL; gboolean support_actions = FALSE; g_return_val_if_fail(msginfo, FALSE); ppopup = &(popup[nftype]); /* init libnotify if necessary */ if(!notify_is_initted()) { if(!notify_init("claws-mail")) { debug_print("Notification Plugin: Failed to initialize libnotify. " "No popup will be shown.\n"); return FALSE; } } switch(nftype) { case F_TYPE_MAIL: summary = _("New Mail message"); from = notification_libnotify_sanitize_str(msginfo->from ? msginfo->from : _("(No From)")); subj = notification_libnotify_sanitize_str(msginfo->subject ? msginfo->subject : _("(No Subject)")); if (notify_config.popup_display_folder_name) { foldname = notification_libnotify_sanitize_str(msginfo->folder->path); text = g_strconcat(from,"\n\n", subj, "\n\n", foldname, NULL); } else text = g_strconcat(from, "\n\n",subj, NULL); /* Make sure text is valid UTF8 */ utf8_str = notification_validate_utf8_str(text); g_free(text); if(from) g_free(from); if(subj) g_free(subj); if(foldname) g_free(foldname); break; case F_TYPE_NEWS: summary = _("New News post"); utf8_str = g_strdup(_("A new message arrived")); break; case F_TYPE_CALENDAR: summary = _("New Calendar message"); utf8_str = g_strdup(_("A new calendar message arrived")); break; case F_TYPE_RSS: summary = _("New RSS feed article"); utf8_str = g_strdup(_("A new article in a RSS feed arrived")); break; default: summary = _("New unknown message"); utf8_str = g_strdup(_("Unknown message type arrived")); break; } ppopup->notification = notify_notification_new(summary, utf8_str, NULL #if !NOTIFY_CHECK_VERSION(0, 7, 0) , NULL #endif ); g_free(utf8_str); if(ppopup->notification == NULL) { debug_print("Notification Plugin: Failed to create a new " "notification.\n"); return FALSE; } caps = notify_get_server_caps(); if(caps != NULL) { GList *c; for(c = caps; c != NULL; c = c->next) { if(strcmp((char*)c->data, "actions") == 0 ) { support_actions = TRUE; break; } } g_list_foreach(caps, (GFunc)g_free, NULL); g_list_free(caps); } /* Default action */ if (support_actions) notify_notification_add_action(ppopup->notification, "default", _("Present main window"), (NotifyActionCallback)default_action_cb, GINT_TO_POINTER(nftype), notification_libnotify_free_func); /* Icon */ pixbuf = NULL; #ifndef USE_ALT_ADDRBOOK if(msginfo && msginfo->from) { gchar *icon_path; icon_path = addrindex_get_picture_file(msginfo->from); if(is_file_exist(icon_path)) { GError *error = NULL; gint w, h; gdk_pixbuf_get_file_info(icon_path, &w, &h); if((w > 64) || (h > 64)) pixbuf = gdk_pixbuf_new_from_file_at_scale(icon_path, 64, 64, TRUE, &error); else pixbuf = gdk_pixbuf_new_from_file(icon_path, &error); if(!pixbuf) { debug_print("Could not load picture file: %s\n", error ? error->message : "no details"); g_error_free(error); } } else debug_print("Picture path does not exist: %s\n",icon_path); g_free(icon_path); } #endif if(!pixbuf) pixbuf = g_object_ref(notification_pixbuf_get(NOTIFICATION_CM_LOGO_64x64)); if(pixbuf) { notify_notification_set_icon_from_pixbuf(ppopup->notification, pixbuf); g_object_unref(pixbuf); } else /* This is not fatal */ debug_print("Notification plugin: Icon could not be loaded.\n"); /* timeout */ notify_notification_set_timeout(ppopup->notification, notify_config.popup_timeout); /* Category */ notify_notification_set_category(ppopup->notification, "email.arrived"); /* get notified on bubble close */ g_signal_connect(G_OBJECT(popup->notification), "closed", G_CALLBACK(popup_timeout_fun), NULL); /* Show the popup */ notify_notification_set_hint_string(ppopup->notification, "desktop-entry", "claws-mail"); if(!notify_notification_show(ppopup->notification, &(ppopup->error))) { debug_print("Notification Plugin: Failed to send notification: %s\n", ppopup->error->message); g_clear_error(&(ppopup->error)); g_object_unref(G_OBJECT(ppopup->notification)); ppopup->notification = NULL; return FALSE; } debug_print("Notification Plugin: Popup created with libnotify.\n"); ppopup->count = 1; /* Store path to message */ if(nftype == F_TYPE_MAIL) { if(msginfo && msginfo->folder) { gchar *ident; ident = folder_item_get_identifier(msginfo->folder); ppopup->msg_path = g_strdup_printf("%s%s%u", ident,G_DIR_SEPARATOR_S, msginfo->msgnum); g_free(ident); } else ppopup->msg_path = NULL; } return TRUE; }
static gint headerview_show_contact_pic (HeaderView *headerview, MsgInfo *msginfo) { #ifndef USE_ALT_ADDRBOOK GtkWidget *hbox = headerview->hbox; GtkWidget *image; gchar *filename = NULL; GError *error = NULL; GdkPixbuf *picture = NULL; gint w, h; if (!gtk_widget_get_visible(headerview->hbox)) return -1; if (headerview->image) { gtk_widget_destroy(headerview->image); headerview->image = NULL; } filename = addrindex_get_picture_file(msginfo->from); if (!filename) return -1; if (!is_file_exist(filename)) { g_free(filename); return -1; } gdk_pixbuf_get_file_info(filename, &w, &h); if (w > 48 || h > 48) picture = gdk_pixbuf_new_from_file_at_scale(filename, 48, 48, TRUE, &error); else picture = gdk_pixbuf_new_from_file(filename, &error); g_free(filename); if (error) { debug_print("Failed to import image: \n%s", error->message); g_error_free(error); return -1; } if (picture) image = gtk_image_new_from_pixbuf(picture); else return -1; g_object_unref(picture); if (image) { gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); gtk_widget_show(image); } headerview->image = image; if (image == NULL) return -1; else return 0; #else /* new address book */ return -1; #endif }