1 /* Notification plugin for Claws-Mail
2 * Copyright (C) 2005-2007 Holger Berndt and the Claws Mail Team.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 /* This module is of course inspired by the trayicon plugin which is
19 * shipped with Claws-Mail, copyrighted by the Claws-Mail Team. */
23 # include "claws-features.h"
27 #include <glib/gi18n.h>
29 #ifdef NOTIFICATION_TRAYICON
31 #include "notification_trayicon.h"
32 #include "notification_prefs.h"
33 #include "notification_core.h"
34 #include "notification_hotkeys.h"
35 #include "notification_pixbuf.h"
36 #include "notification_foldercheck.h"
40 #include "mainwindow.h"
41 #include "prefs_common.h"
42 #include "alertpanel.h"
44 #ifndef USE_NEW_ADDRBOOK
45 #include "addressbook.h"
46 #include "addrindex.h"
48 #include "addressbook-dbus.h"
51 #include "gtk/manage_window.h"
52 #include "common/utils.h"
53 #include "gtk/gtkutils.h"
55 static GdkPixbuf* notification_trayicon_create(void);
57 static void notification_trayicon_on_popup_menu(GtkStatusIcon*,guint,
59 static gboolean notification_trayicon_on_size_changed(GtkStatusIcon*,
62 static void trayicon_get_all_cb(GtkAction*, gpointer);
63 static void trayicon_compose_cb(GtkAction*, gpointer);
64 static void trayicon_compose_acc_cb(GtkMenuItem*, gpointer);
65 static void trayicon_addressbook_cb(GtkAction*, gpointer);
66 static void trayicon_exit_cb(GtkAction*,gpointer);
67 static void trayicon_toggle_offline_cb(GtkAction*,gpointer);
69 static void trayicon_toggle_notify_cb(GtkAction*,gpointer);
73 #include <libnotify/notify.h>
75 #ifndef NOTIFY_CHECK_VERSION
76 # define NOTIFY_CHECK_VERSION(a,b,c) 0
86 NotifyNotification *notification;
88 } NotificationTrayiconPopup;
90 static NotificationTrayiconPopup popup;
92 static gboolean notification_trayicon_popup_add_msg(MsgInfo*,
93 NotificationFolderType);
94 static gboolean notification_trayicon_popup_create(MsgInfo*,
95 NotificationFolderType);
96 static void popup_timeout_fun(NotifyNotification*, gpointer);
97 static void notification_trayicon_popup_free_func(gpointer);
98 static void notification_trayicon_popup_default_action_cb(NotifyNotification*,
100 static gchar* notification_trayicon_popup_assemble_summary(void);
101 static gchar* notification_trayicon_popup_assemble_body(MsgInfo*);
102 static void notification_trayicon_popup_count_msgs(NotificationFolderType);
104 G_LOCK_DEFINE_STATIC(trayicon_popup);
108 static GtkStatusIcon *trayicon;
109 static gboolean updating_menu = FALSE;
110 static GtkWidget *traymenu_popup;
112 static GtkActionEntry trayicon_popup_menu_entries[] = {
113 {"SysTrayiconPopup", NULL, "SysTrayiconPopup" },
114 {"SysTrayiconPopup/GetMail", NULL, N_("_Get Mail"), NULL, NULL, G_CALLBACK(trayicon_get_all_cb) },
115 {"SysTrayiconPopup/---", NULL, "---" },
116 {"SysTrayiconPopup/Email", NULL, N_("_Email"), NULL, NULL, G_CALLBACK(trayicon_compose_cb) },
117 {"SysTrayiconPopup/EmailAcc", NULL, N_("E_mail from account"), NULL, NULL, NULL },
118 {"SysTrayiconPopup/OpenAB", NULL, N_("Open A_ddressbook"), NULL, NULL, G_CALLBACK(trayicon_addressbook_cb) },
119 {"SysTrayiconPopup/Exit", NULL, N_("E_xit Claws Mail"), NULL, NULL, G_CALLBACK(trayicon_exit_cb) },
122 static GtkToggleActionEntry trayicon_popup_toggle_menu_entries[] =
124 {"SysTrayiconPopup/ToggleOffline", NULL, N_("_Work Offline"), NULL, NULL, G_CALLBACK(trayicon_toggle_offline_cb) },
125 #ifdef HAVE_LIBNOTIFY
126 {"SysTrayiconPopup/ShowBubbles", NULL, N_("Show Trayicon Notifications"), NULL, NULL, G_CALLBACK(trayicon_toggle_notify_cb) },
131 void notification_trayicon_msg(MsgInfo *msginfo)
133 #ifndef HAVE_LIBNOTIFY
138 NotificationFolderType nftype;
141 nftype = F_TYPE_MAIL;
143 if(!msginfo || !notify_config.trayicon_enabled ||
144 !notify_config.trayicon_popup_enabled ||
145 !MSG_IS_NEW(msginfo->flags))
148 if(notify_config.trayicon_folder_specific) {
152 gboolean found = FALSE;
154 if(!(msginfo->folder))
157 identifier = folder_item_get_identifier(msginfo->folder);
160 notification_register_folder_specific_list
161 (TRAYICON_SPECIFIC_FOLDER_ID_STR);
162 list = notification_foldercheck_get_list(id);
163 for(; (list != NULL) && !found; list = g_slist_next(list)) {
164 gchar *list_identifier;
165 FolderItem *list_item = (FolderItem*) list->data;
167 list_identifier = folder_item_get_identifier(list_item);
168 if(!strcmp2(list_identifier, identifier))
171 g_free(list_identifier);
177 } /* folder specific */
179 ftype = msginfo->folder->folder->klass->type;
181 G_LOCK(trayicon_popup);
182 /* Check out which type to notify about */
188 nftype = F_TYPE_MAIL;
191 nftype = F_TYPE_NEWS;
194 if((uistr = msginfo->folder->folder->klass->uistr) == NULL) {
195 G_UNLOCK(trayicon_popup);
198 else if(!strcmp(uistr, "vCalendar"))
199 nftype = F_TYPE_CALENDAR;
200 else if(!strcmp(uistr, "RSSyl"))
203 debug_print("Notification Plugin: Unknown folder type %d\n",ftype);
204 G_UNLOCK(trayicon_popup);
209 debug_print("Notification Plugin: Unknown folder type %d\n",ftype);
210 G_UNLOCK(trayicon_popup);
215 notification_trayicon_popup_add_msg(msginfo, nftype);
217 G_UNLOCK(trayicon_popup);
219 #endif /* HAVE_LIBNOTIFY */
222 void notification_trayicon_destroy(void)
225 gtk_status_icon_set_visible(trayicon, FALSE);
226 g_object_unref(trayicon);
231 void notification_update_trayicon()
234 static GdkPixbuf *old_icon = NULL;
237 NotificationMsgCount count;
240 if(!notify_config.trayicon_enabled)
243 if(notify_config.trayicon_folder_specific) {
246 notification_register_folder_specific_list
247 (TRAYICON_SPECIFIC_FOLDER_ID_STR);
248 list = notification_foldercheck_get_list(id);
253 notification_core_get_msg_count(list, &count);
257 #ifdef NOTIFICATION_HOTKEYS
258 notification_hotkeys_update_bindings();
261 old_icon = notification_trayicon_create();
263 debug_print("Notification plugin: Could not create trayicon\n");
269 buf = g_strdup_printf(_("New %d, Unread: %d, Total: %d"),
270 count.new_msgs, count.unread_msgs,
272 gtk_status_icon_set_tooltip_text(trayicon, buf);
277 (prefs_common_get_prefs()->work_offline) ? (offset = 1) : (offset = 0);
279 if((count.new_msgs > 0) && (count.unreadmarked_msgs > 0))
281 notification_pixbuf_get(NOTIFICATION_TRAYICON_NEWMARKEDMAIL+offset);
282 else if(count.new_msgs > 0)
284 notification_pixbuf_get(NOTIFICATION_TRAYICON_NEWMAIL+offset);
285 else if(count.unreadmarked_msgs > 0)
287 notification_pixbuf_get(NOTIFICATION_TRAYICON_UNREADMARKEDMAIL+offset);
288 else if(count.unread_msgs > 0)
290 notification_pixbuf_get(NOTIFICATION_TRAYICON_UNREADMAIL+offset);
293 notification_pixbuf_get(NOTIFICATION_TRAYICON_NOMAIL+offset);
295 if(new_icon != old_icon) {
296 gtk_status_icon_set_from_pixbuf(trayicon, new_icon);
301 gboolean notification_trayicon_main_window_close(gpointer source, gpointer data)
303 if(!notify_config.trayicon_enabled)
307 gboolean *close_allowed = (gboolean*)source;
309 if(notify_config.trayicon_close_to_tray) {
310 MainWindow *mainwin = mainwindow_get_mainwindow();
312 *close_allowed = FALSE;
313 if(mainwin && gtk_widget_get_visible(GTK_WIDGET(mainwin->window)))
314 main_window_hide(mainwin);
320 gboolean notification_trayicon_main_window_got_iconified(gpointer source,
323 MainWindow *mainwin = mainwindow_get_mainwindow();
325 if(!notify_config.trayicon_enabled)
328 if(notify_config.trayicon_hide_when_iconified &&
329 mainwin && gtk_widget_get_visible(GTK_WIDGET(mainwin->window))
330 && !gtk_window_get_skip_taskbar_hint(GTK_WINDOW(mainwin->window))) {
331 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(mainwin->window), TRUE);
336 gboolean notification_trayicon_account_list_changed(gpointer source,
340 GtkWidget *menu, *submenu;
342 PrefsAccount *ac_prefs;
344 GList *account_list = account_get_list();
346 if(!notify_config.trayicon_enabled)
349 menu = gtk_ui_manager_get_widget(gtkut_ui_manager(), "/Menus/SysTrayiconPopup/EmailAcc");
350 gtk_widget_show(menu);
352 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu), NULL);
353 submenu = gtk_menu_new();
355 for(cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
356 ac_prefs = (PrefsAccount *)cur_ac->data;
358 menuitem = gtk_menu_item_new_with_label
359 (ac_prefs->account_name ? ac_prefs->account_name
361 gtk_widget_show(menuitem);
362 gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem);
363 g_signal_connect(G_OBJECT(menuitem), "activate",
364 G_CALLBACK(trayicon_compose_acc_cb),
367 gtk_widget_show(submenu);
368 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu), submenu);
372 static GdkPixbuf* notification_trayicon_create(void)
374 GdkPixbuf *trayicon_nomail;
375 GtkActionGroup *action_group;
377 trayicon_nomail = notification_pixbuf_get(NOTIFICATION_TRAYICON_NOMAIL);
379 notification_trayicon_destroy();
381 trayicon = gtk_status_icon_new_from_pixbuf(trayicon_nomail);
383 g_signal_connect(G_OBJECT(trayicon), "activate",
384 G_CALLBACK(notification_trayicon_on_activate), NULL);
385 g_signal_connect(G_OBJECT(trayicon), "popup-menu",
386 G_CALLBACK(notification_trayicon_on_popup_menu), NULL);
387 g_signal_connect(G_OBJECT(trayicon), "size-changed",
388 G_CALLBACK(notification_trayicon_on_size_changed), NULL);
391 action_group = cm_menu_create_action_group("SysTrayiconPopup", trayicon_popup_menu_entries,
392 G_N_ELEMENTS(trayicon_popup_menu_entries), NULL);
393 gtk_action_group_add_toggle_actions(action_group, trayicon_popup_toggle_menu_entries,
394 G_N_ELEMENTS(trayicon_popup_toggle_menu_entries), NULL);
396 MENUITEM_ADDUI("/Menus", "SysTrayiconPopup", "SysTrayiconPopup", GTK_UI_MANAGER_MENU)
397 MENUITEM_ADDUI("/Menus/SysTrayiconPopup", "GetMail", "SysTrayiconPopup/GetMail", GTK_UI_MANAGER_MENUITEM)
398 MENUITEM_ADDUI("/Menus/SysTrayiconPopup", "Separator1", "SysTrayiconPopup/---", GTK_UI_MANAGER_SEPARATOR)
399 MENUITEM_ADDUI("/Menus/SysTrayiconPopup", "Email", "SysTrayiconPopup/Email", GTK_UI_MANAGER_MENUITEM)
400 MENUITEM_ADDUI("/Menus/SysTrayiconPopup", "EmailAcc", "SysTrayiconPopup/EmailAcc", GTK_UI_MANAGER_MENU)
401 MENUITEM_ADDUI("/Menus/SysTrayiconPopup", "Separator2", "SysTrayiconPopup/---", GTK_UI_MANAGER_SEPARATOR)
402 MENUITEM_ADDUI("/Menus/SysTrayiconPopup", "OpenAB", "SysTrayiconPopup/OpenAB", GTK_UI_MANAGER_MENUITEM)
403 MENUITEM_ADDUI("/Menus/SysTrayiconPopup", "Separator3", "SysTrayiconPopup/---", GTK_UI_MANAGER_SEPARATOR)
404 MENUITEM_ADDUI("/Menus/SysTrayiconPopup", "ToggleOffline", "SysTrayiconPopup/ToggleOffline", GTK_UI_MANAGER_MENUITEM)
405 #ifdef HAVE_LIBNOTIFY
406 MENUITEM_ADDUI("/Menus/SysTrayiconPopup", "ShowBubbles", "SysTrayiconPopup/ShowBubbles", GTK_UI_MANAGER_MENUITEM)
408 MENUITEM_ADDUI("/Menus/SysTrayiconPopup", "Separator4", "SysTrayiconPopup/---", GTK_UI_MANAGER_SEPARATOR)
409 MENUITEM_ADDUI("/Menus/SysTrayiconPopup", "Exit", "SysTrayiconPopup/Exit", GTK_UI_MANAGER_MENUITEM)
411 traymenu_popup = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
412 gtk_ui_manager_get_widget(gtkut_ui_manager(), "/Menus/SysTrayiconPopup")));
415 return trayicon_nomail;
418 void notification_trayicon_on_activate(GtkStatusIcon *status_icon, gpointer user_data)
420 notification_toggle_hide_show_window();
423 static void notification_trayicon_on_popup_menu(GtkStatusIcon *status_icon,
424 guint button, guint activate_time,
427 MainWindow *mainwin = mainwindow_get_mainwindow();
432 /* tell callbacks to skip any event */
433 updating_menu = TRUE;
434 /* initialize checkitems according to current states */
435 cm_toggle_menu_set_active("SysTrayiconPopup/ToggleOffline", prefs_common_get_prefs()->work_offline);
436 #ifdef HAVE_LIBNOTIFY
437 cm_toggle_menu_set_active("SysTrayiconPopup/ShowBubbles", notify_config.trayicon_popup_enabled);
439 cm_menu_set_sensitive("SysTrayiconPopup/GetMail", mainwin->lock_count == 0);
441 updating_menu = FALSE;
443 gtk_menu_popup(GTK_MENU(traymenu_popup), NULL, NULL, NULL, NULL,
444 button, activate_time);
447 static gboolean notification_trayicon_on_size_changed(GtkStatusIcon *icon,
451 notification_update_msg_counts(NULL);
455 /* popup menu callbacks */
456 static void trayicon_get_all_cb(GtkAction *action, gpointer data)
458 MainWindow *mainwin = mainwindow_get_mainwindow();
459 inc_all_account_mail_cb(mainwin, 0, NULL);
462 static void trayicon_compose_cb(GtkAction *action, gpointer data)
464 MainWindow *mainwin = mainwindow_get_mainwindow();
465 compose_mail_cb(mainwin, 0, NULL);
468 static void trayicon_compose_acc_cb(GtkMenuItem *menuitem, gpointer data)
470 compose_new((PrefsAccount *)data, NULL, NULL);
473 static void trayicon_addressbook_cb(GtkAction *action, gpointer data)
475 #ifndef USE_NEW_ADDRBOOK
476 addressbook_open(NULL);
478 GError* error = NULL;
480 addressbook_dbus_open(FALSE, &error);
482 g_warning("%s", error->message);
488 static void trayicon_toggle_offline_cb(GtkAction *action, gpointer data)
490 /* toggle offline mode if menu checkitem has been clicked */
492 MainWindow *mainwin = mainwindow_get_mainwindow();
493 main_window_toggle_work_offline(mainwin, !prefs_common_get_prefs()->work_offline, TRUE);
497 #ifdef HAVE_LIBNOTIFY
498 static void trayicon_toggle_notify_cb(GtkAction *action, gpointer data)
501 notify_config.trayicon_popup_enabled = !notify_config.trayicon_popup_enabled;
506 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
508 if(prefs_common_get_prefs()->confirm_on_exit) {
509 if(alertpanel(_("Exit"), _("Exit Claws Mail?"),
510 GTK_STOCK_CANCEL, GTK_STOCK_OK,
511 NULL) != G_ALERTALTERNATE) {
514 manage_window_focus_in(mainwin->window, NULL, NULL);
517 if (prefs_common_get_prefs()->clean_on_exit) {
518 if (!main_window_empty_trash(mainwin, prefs_common_get_prefs()->ask_on_clean, TRUE))
522 app_will_exit(NULL, mainwin);
525 static void trayicon_exit_cb(GtkAction *action, gpointer data)
527 MainWindow *mainwin = mainwindow_get_mainwindow();
529 if(mainwin->lock_count == 0) {
530 app_exit_cb(mainwin, 0, NULL);
534 #ifdef HAVE_LIBNOTIFY
535 static gboolean notification_trayicon_popup_add_msg(MsgInfo *msginfo,
536 NotificationFolderType nftype)
543 g_return_val_if_fail(msginfo, FALSE);
545 if(!popup.notification)
546 return notification_trayicon_popup_create(msginfo,nftype);
549 notification_trayicon_popup_count_msgs(nftype);
552 g_free(popup.msg_path);
553 popup.msg_path = NULL;
556 summary = notification_trayicon_popup_assemble_summary();
557 utf8_str = notification_trayicon_popup_assemble_body(msginfo);
559 /* make sure we show a logo on many msg arrival */
560 pixbuf = notification_pixbuf_get(NOTIFICATION_CM_LOGO_64x64);
562 notify_notification_set_icon_from_pixbuf(popup.notification, pixbuf);
564 retval = notify_notification_update(popup.notification, summary,
569 debug_print("Notification Plugin: Failed to update notification.\n");
573 notify_notification_set_hint_string(popup.notification, "desktop-entry", "claws-mail");
574 if(!notify_notification_show(popup.notification, &(popup.error))) {
575 debug_print("Notification Plugin: Failed to send updated notification: "
576 "%s\n", popup.error->message);
577 g_clear_error(&(popup.error));
581 debug_print("Notification Plugin: Popup successfully modified "
582 "with libnotify.\n");
587 static gboolean notification_trayicon_popup_create(MsgInfo *msginfo,
588 NotificationFolderType nftype)
590 gchar *summary = NULL;
591 gchar *utf8_str = NULL;
594 gboolean support_actions = FALSE;
596 /* init libnotify if necessary */
597 if(!notify_is_initted()) {
598 if(!notify_init("claws-mail")) {
599 debug_print("Notification Plugin: Failed to initialize libnotify. "
600 "No popups will be shown.\n");
606 notification_trayicon_popup_count_msgs(nftype);
608 summary = notification_trayicon_popup_assemble_summary();
609 utf8_str = notification_trayicon_popup_assemble_body(msginfo);
611 #if NOTIFY_CHECK_VERSION(0, 7, 0)
612 popup.notification = notify_notification_new(summary, utf8_str, NULL);
614 popup.notification = notify_notification_new(summary, utf8_str, NULL, NULL);
615 notify_notification_attach_to_status_icon(popup.notification, trayicon);
621 caps = notify_get_server_caps();
624 for(c = caps; c != NULL; c = c->next) {
625 if(strcmp((char*)c->data, "actions") == 0 ) {
626 support_actions = TRUE;
631 g_list_foreach(caps, (GFunc)g_free, NULL);
637 notify_notification_add_action(popup.notification,
638 "default", _("Present main window"),
639 (NotifyActionCallback)
640 notification_trayicon_popup_default_action_cb,
641 GINT_TO_POINTER(nftype),
642 notification_trayicon_popup_free_func);
644 if(popup.notification == NULL) {
645 debug_print("Notification Plugin: Failed to create a new notification.\n");
651 #ifndef USE_NEW_ADDRBOOK
652 if(msginfo && msginfo->from) {
654 icon_path = addrindex_get_picture_file(msginfo->from);
655 if(is_file_exist(icon_path)) {
656 GError *error = NULL;
659 gdk_pixbuf_get_file_info(icon_path, &w, &h);
660 if((w > 64) || (h > 64))
661 pixbuf = gdk_pixbuf_new_from_file_at_scale(icon_path,
662 64, 64, TRUE, &error);
664 pixbuf = gdk_pixbuf_new_from_file(icon_path, &error);
667 debug_print("Could not load picture file: %s\n",
668 error ? error->message : "no details");
673 debug_print("Picture path does not exist: %s\n",icon_path);
678 pixbuf = g_object_ref(notification_pixbuf_get(NOTIFICATION_CM_LOGO_64x64));
681 notify_notification_set_icon_from_pixbuf(popup.notification, pixbuf);
682 g_object_unref(pixbuf);
684 else /* This is not fatal */
685 debug_print("Notification plugin: Icon could not be loaded.\n");
688 notify_notification_set_timeout(popup.notification, notify_config.trayicon_popup_timeout);
691 notify_notification_set_category(popup.notification, "email.arrived");
693 /* get notified on bubble close */
694 g_signal_connect(G_OBJECT(popup.notification), "closed", G_CALLBACK(popup_timeout_fun), NULL);
697 notify_notification_set_hint_string(popup.notification, "desktop-entry", "claws-mail");
698 if(!notify_notification_show(popup.notification, &(popup.error))) {
699 debug_print("Notification Plugin: Failed to send notification: %s\n",
700 popup.error->message);
701 g_clear_error(&(popup.error));
702 g_object_unref(G_OBJECT(popup.notification));
703 popup.notification = NULL;
707 /* Store path to message */
708 if(nftype == F_TYPE_MAIL) {
709 if(msginfo && msginfo->folder) {
711 ident = folder_item_get_identifier(msginfo->folder);
712 popup.msg_path = g_strdup_printf("%s%s%u", ident,G_DIR_SEPARATOR_S,
717 popup.msg_path = NULL;
720 debug_print("Notification Plugin: Popup created with libnotify.\n");
725 static void popup_timeout_fun(NotifyNotification *nn, gpointer data)
727 G_LOCK(trayicon_popup);
729 g_object_unref(G_OBJECT(popup.notification));
731 popup.notification = NULL;
732 g_clear_error(&(popup.error));
737 popup.num_calendar = 0;
741 g_free(popup.msg_path);
742 popup.msg_path = NULL;
745 G_UNLOCK(trayicon_popup);
748 static void notification_trayicon_popup_free_func(gpointer data)
751 g_free(popup.msg_path);
752 popup.msg_path = NULL;
755 debug_print("Freed notification data\n");
758 static void notification_trayicon_popup_default_action_cb(NotifyNotification
763 if(strcmp("default", action))
767 mainwin = mainwindow_get_mainwindow();
769 NotificationFolderType nftype;
771 /* Let mainwindow pop up */
772 notification_show_mainwindow(mainwin);
773 /* If there is only one new mail message, jump to this message */
774 nftype = (NotificationFolderType)GPOINTER_TO_INT(user_data);
775 if((popup.count == 1) && (nftype == F_TYPE_MAIL)) {
777 G_LOCK(trayicon_popup);
778 select_str = g_strdup(popup.msg_path);
779 G_UNLOCK(trayicon_popup);
780 debug_print("Notification plugin: Select message %s\n", select_str);
781 mainwindow_jump_to(select_str, FALSE);
787 static void notification_trayicon_popup_count_msgs(NotificationFolderType nftype)
796 case F_TYPE_CALENDAR:
797 popup.num_calendar++;
803 debug_print("Notification plugin: Unknown folder type\n");
809 /* The returned value has to be freed by the caller */
810 static gchar* notification_trayicon_popup_assemble_summary(void)
812 gchar *summary = NULL;
814 if(popup.count == 1) {
816 summary = g_strdup(_("New mail message"));
817 else if(popup.num_news)
818 summary = g_strdup(_("New news post"));
819 else if(popup.num_calendar)
820 summary = g_strdup(_("New calendar message"));
822 summary = g_strdup(_("New article in RSS feed"));
823 } /* One new message */
825 summary = g_strdup(_("New messages arrived"));
826 } /* Many new messages */
831 /* The returned value has to be freed by the caller */
832 static gchar* notification_trayicon_popup_assemble_body(MsgInfo *msginfo)
836 if(popup.count == 1) {
837 if(popup.num_mail || popup.num_news) {
841 gchar *foldname = NULL;
843 from = notification_libnotify_sanitize_str(msginfo->from ?
846 subj = notification_libnotify_sanitize_str(msginfo->subject ?
849 if (notify_config.trayicon_display_folder_name) {
850 foldname = notification_libnotify_sanitize_str(msginfo->folder->path);
851 text = g_strconcat(from,"\n\n", subj, "\n\n", foldname, NULL);
854 text = g_strconcat(from, "\n\n",subj, NULL);
857 /* Make sure text is valid UTF8 */
858 utf8_str = notification_validate_utf8_str(text);
861 if(from) g_free(from);
862 if(subj) g_free(subj);
863 if(foldname) g_free(foldname);
865 else if(popup.num_calendar) {
866 utf8_str = g_strdup(_("A new calendar message arrived"));
869 utf8_str = g_strdup(_("A new article in a RSS feed arrived"));
876 gboolean str_empty = TRUE;
878 utf8_str = g_strdup("");
881 msg = g_strdup_printf(ngettext("%d new mail message arrived",
882 "%d new mail messages arrived",
885 tmp = g_strdup_printf("%s%s%s",utf8_str,str_empty?"":"\n",msg);
892 msg = g_strdup_printf(ngettext("%d new news post arrived",
893 "%d new news posts arrived",
896 tmp = g_strdup_printf("%s%s%s",utf8_str,str_empty?"":"\n",msg);
902 if(popup.num_calendar) {
903 msg = g_strdup_printf(ngettext("%d new calendar message arrived",
904 "%d new calendar messages arrived",
907 tmp = g_strdup_printf("%s%s%s",utf8_str,str_empty?"":"\n",msg);
914 msg = g_strdup_printf(ngettext("%d new article in RSS feeds arrived",
915 "%d new articles in RSS feeds arrived",
918 tmp = g_strdup_printf("%s%s%s",utf8_str,str_empty?"":"\n",msg);
924 } /* Many messages */
929 #endif /* HAVE_LIBNOTIFY */
931 gboolean notification_trayicon_is_available(void)
933 gboolean is_available;
934 is_available = FALSE;
937 if(gtk_status_icon_is_embedded(trayicon) &&
938 gtk_status_icon_get_visible(trayicon))
945 #endif /* NOTIFICATION_TRAYICON */