1 /* Notification plugin for Claws Mail
2 * Copyright (C) 2005-2009 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/>.
20 # include "claws-features.h"
23 #ifdef NOTIFICATION_INDICATOR
25 #include "notification_indicator.h"
26 #include "notification_prefs.h"
27 #include "notification_core.h"
30 #include "common/utils.h"
32 #include <messaging-menu.h>
35 #define CLAWS_DESKTOP_FILE "claws-mail.desktop"
37 static MessagingMenuApp
*mmapp
= NULL
;
38 static gboolean mmapp_registered
= FALSE
;
39 static UnityLauncherEntry
*launcher
= NULL
;
40 static gulong mainwin_state_changed_signal_id
= 0;
42 static void show_claws_mail(MessagingMenuApp
*mmapp
, const gchar
*id
, gpointer data
);
44 void notification_indicator_setup(void)
47 mmapp
= messaging_menu_app_new(CLAWS_DESKTOP_FILE
);
49 if(notify_config
.indicator_enabled
&& !mmapp_registered
) {
50 messaging_menu_app_register(MESSAGING_MENU_APP(mmapp
));
51 g_signal_connect(mmapp
, "activate-source", G_CALLBACK(show_claws_mail
), NULL
);
52 mmapp_registered
= TRUE
;
55 launcher
= unity_launcher_entry_get_for_desktop_id(CLAWS_DESKTOP_FILE
);
59 void notification_indicator_destroy(void)
62 unity_launcher_entry_set_count_visible(launcher
, FALSE
);
64 if(mmapp_registered
) {
65 messaging_menu_app_unregister(mmapp
);
66 mmapp_registered
= FALSE
;
68 if(mainwin_state_changed_signal_id
!= 0) {
70 if((mainwin
= mainwindow_get_mainwindow()) != NULL
)
71 g_signal_handler_disconnect(mainwin
->window
, mainwin_state_changed_signal_id
);
72 mainwin_state_changed_signal_id
= 0;
76 static void show_claws_mail(MessagingMenuApp
*mmapp
, const gchar
*id
, gpointer data
)
80 if((mainwin
= mainwindow_get_mainwindow()) == NULL
)
83 notification_show_mainwindow(mainwin
);
85 Folder
*folder
= data
;
86 FolderItem
*item
= folder
->inbox
;
88 gchar
*path
= folder_item_get_identifier(item
);
89 mainwindow_jump_to(path
, FALSE
);
94 static gboolean
mainwin_state_event(GtkWidget
*widget
, GdkEventWindowState
*event
, gpointer user_data
)
96 if(notify_config
.indicator_hide_minimized
) {
99 if((mainwin
= mainwindow_get_mainwindow()) == NULL
)
102 if((event
->changed_mask
& GDK_WINDOW_STATE_ICONIFIED
) && (event
->new_window_state
& GDK_WINDOW_STATE_ICONIFIED
)) {
103 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(mainwin
->window
), TRUE
);
105 else if((event
->changed_mask
& GDK_WINDOW_STATE_ICONIFIED
) && !(event
->new_window_state
& GDK_WINDOW_STATE_ICONIFIED
)) {
106 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(mainwin
->window
), FALSE
);
112 void notification_update_indicator(void)
115 gint total_message_count
;
117 if(!mainwin_state_changed_signal_id
) {
120 if((mainwin
= mainwindow_get_mainwindow()) != NULL
)
121 mainwin_state_changed_signal_id
= g_signal_connect(G_OBJECT(mainwin
->window
), "window-state-event", G_CALLBACK(mainwin_state_event
), NULL
);
124 if(!notify_config
.indicator_enabled
)
127 total_message_count
= 0;
128 /* check accounts for new/unread counts */
129 for(cur_mb
= folder_get_list(); cur_mb
; cur_mb
= cur_mb
->next
) {
130 Folder
*folder
= cur_mb
->data
;
131 NotificationMsgCount count
;
134 debug_print("Notification plugin: Warning: Ignoring unnamed mailbox in indicator applet\n");
137 gchar
*id
= folder
->name
;
138 notification_core_get_msg_count_of_foldername(folder
->name
, &count
);
140 total_message_count
+= count
.unread_msgs
;
142 if(count
.new_msgs
> 0) {
143 gchar
*strcount
= g_strdup_printf("%d / %d", count
.new_msgs
, count
.unread_msgs
);
145 if(messaging_menu_app_has_source(MESSAGING_MENU_APP(mmapp
), id
))
146 messaging_menu_app_set_source_string(MESSAGING_MENU_APP(mmapp
), id
, strcount
);
148 messaging_menu_app_append_source_with_string(MESSAGING_MENU_APP(mmapp
), id
, NULL
, id
, strcount
);
151 messaging_menu_app_draw_attention(MESSAGING_MENU_APP(mmapp
), id
);
154 if(messaging_menu_app_has_source(MESSAGING_MENU_APP(mmapp
), id
)) {
155 messaging_menu_app_remove_attention(MESSAGING_MENU_APP(mmapp
), id
);
156 messaging_menu_app_remove_source(MESSAGING_MENU_APP(mmapp
), id
);
161 unity_launcher_entry_set_count(launcher
, total_message_count
);
162 unity_launcher_entry_set_count_visible(launcher
, total_message_count
> 0);
165 #endif /* NOTIFICATION_INDICATOR */