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 <libindicate/server.h>
33 #include <libindicate/indicator.h>
34 #include <libindicate/indicator-messages.h>
36 static IndicateServer *server = NULL;
37 static GHashTable *indicators = NULL;
38 static gulong mainwin_state_changed_signal_id = 0;
40 void notification_indicator_destroy(void)
43 g_hash_table_destroy(indicators);
47 indicate_server_hide(server);
48 g_object_unref(server);
51 if(mainwin_state_changed_signal_id != 0) {
53 if((mainwin = mainwindow_get_mainwindow()) != NULL)
54 g_signal_handler_disconnect(mainwin->window, mainwin_state_changed_signal_id);
55 mainwin_state_changed_signal_id = 0;
60 static void show_claws_mail(IndicateIndicator *indicator, guint dummy, gpointer data)
64 if((mainwin = mainwindow_get_mainwindow()) == NULL)
67 notification_show_mainwindow(mainwin);
69 Folder *folder = data;
70 FolderItem *item = folder->inbox;
72 gchar *path = folder_item_get_identifier(item);
73 mainwindow_jump_to(path, FALSE);
78 static void set_indicator_unread_count(IndicateIndicator *indicator, gint new, gint unread)
82 count_str = g_strdup_printf("%d / %d", new, unread);
83 indicate_indicator_set_property(indicator, INDICATE_INDICATOR_MESSAGES_PROP_COUNT, count_str);
87 static void create_indicators(void)
89 IndicateIndicator *indicator;
92 indicators = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref);
94 for(cur_mb = folder_get_list(); cur_mb; cur_mb = cur_mb->next) {
96 Folder *folder = cur_mb->data;
99 debug_print("Notification plugin: Warning: Ignoring unnamed mailbox in indicator applet\n");
102 name = g_strdup(folder->name);
104 indicator = indicate_indicator_new();
105 indicate_indicator_set_property(indicator, INDICATE_INDICATOR_MESSAGES_PROP_NAME, name);
106 set_indicator_unread_count(indicator, 0, 0);
107 g_object_set_data(G_OBJECT(indicator), "new_msgs", GINT_TO_POINTER(0));
108 g_object_set_data(G_OBJECT(indicator), "unread_msgs", GINT_TO_POINTER(0));
109 g_signal_connect(indicator, "user-display", G_CALLBACK (show_claws_mail), folder);
110 indicate_indicator_show(indicator);
111 g_hash_table_insert(indicators, name, indicator);
115 static gboolean mainwin_state_event(GtkWidget *widget, GdkEventWindowState *event, gpointer user_data)
117 if(notify_config.indicator_hide_minimized) {
120 if((mainwin = mainwindow_get_mainwindow()) == NULL)
123 if((event->changed_mask & GDK_WINDOW_STATE_ICONIFIED) && (event->new_window_state & GDK_WINDOW_STATE_ICONIFIED)) {
124 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(mainwin->window), TRUE);
126 else if((event->changed_mask & GDK_WINDOW_STATE_ICONIFIED) && !(event->new_window_state & GDK_WINDOW_STATE_ICONIFIED)) {
127 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(mainwin->window), FALSE);
133 void notification_update_indicator(void)
138 if(!mainwin_state_changed_signal_id) {
141 if((mainwin = mainwindow_get_mainwindow()) != NULL)
142 mainwin_state_changed_signal_id = g_signal_connect(G_OBJECT(mainwin->window), "window-state-event", G_CALLBACK(mainwin_state_event), NULL);
146 if(!notify_config.indicator_enabled)
150 server = indicate_server_ref_default();
151 indicate_server_set_type (server, "message.mail");
152 indicate_server_set_desktop_file(server, get_desktop_file());
153 g_signal_connect(server, "server-display", G_CALLBACK(show_claws_mail), NULL);
154 indicate_server_show(server);
160 /* check accounts for new/unread counts */
161 g_hash_table_iter_init(&iter, indicators);
162 while(g_hash_table_iter_next(&iter, &key, &value)) {
163 NotificationMsgCount count;
164 gchar *foldername = key;
165 IndicateIndicator *indicator = value;
167 notification_core_get_msg_count_of_foldername(foldername, &count);
169 set_indicator_unread_count(indicator, count.new_msgs, count.unread_msgs);
170 indicate_indicator_set_property(indicator, INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION,
171 (count.new_msgs > 0) ? "true" : "false");
172 g_object_set_data(G_OBJECT(indicator), "new_msgs", GINT_TO_POINTER(count.new_msgs));
173 g_object_set_data(G_OBJECT(indicator), "unread_msgs", GINT_TO_POINTER(count.unread_msgs));
177 #endif /* NOTIFICATION_INDICATOR */