1 /* Notification plugin for Claws Mail
2 * Copyright (C) 2005-2007 Holger Berndt
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"
24 #include <glib/gi18n.h>
26 #ifdef NOTIFICATION_LCDPROC
28 #include "notification_lcdproc.h"
29 #include "notification_prefs.h"
30 #include "notification_core.h"
32 #include "common/socket.h"
35 #include <sys/socket.h>
37 #define NOTIFICATION_LCDPROC_BUFFER_SIZE 8192
39 void notification_sock_puts(SockInfo
*, gchar
*);
40 void notification_lcdproc_send(gchar
*);
42 static SockInfo
*sock
= NULL
;
44 void notification_lcdproc_connect(void)
47 gchar buf
[NOTIFICATION_LCDPROC_BUFFER_SIZE
];
49 if(!notify_config
.lcdproc_enabled
)
53 notification_lcdproc_disconnect();
55 sock
= sock_connect(notify_config
.lcdproc_hostname
,
56 notify_config
.lcdproc_port
);
58 * Quietly return when a connection fails; next attempt
59 * will be made when some folder info has been changed.
61 if(sock
== NULL
|| sock
->state
== CONN_FAILED
) {
62 debug_print("Could not connect to LCDd\n");
63 if(sock
&& sock
->state
== CONN_FAILED
) {
64 sock_close(sock
, TRUE
);
70 debug_print("Connected to LCDd\n");
72 sock_set_nonblocking_mode(sock
, TRUE
);
74 /* Friendly people say "hello" first */
75 notification_sock_puts(sock
, "hello");
77 /* FIXME: Ouch. Is this really the way to go? */
80 while((len
<= 0) && (count
-- >= 0)) {
82 len
= sock_read(sock
, buf
, NOTIFICATION_LCDPROC_BUFFER_SIZE
);
86 * This might not be a LCDProc server.
87 * FIXME: check LCD size, LCDd version etc
91 debug_print("Notification plugin: Can't communicate with "
92 "LCDd server! Are you sure that "
93 "there is a LCDd server running on %s:%d?\n",
94 notify_config
.lcdproc_hostname
, notify_config
.lcdproc_port
);
95 notification_lcdproc_disconnect();
99 notification_lcdproc_send("client_set -name \"{Claws-Mail}\"");
101 notification_lcdproc_send("screen_add msg_counts");
102 notification_lcdproc_send("screen_set msg_counts -name {Claws-Mail Message Count}");
104 notification_lcdproc_send("widget_add msg_counts title title");
105 notification_lcdproc_send("widget_set msg_counts title {Claws-Mail}");
106 notification_lcdproc_send("widget_add msg_counts line1 string");
107 notification_lcdproc_send("widget_add msg_counts line2 string");
108 notification_lcdproc_send("widget_add msg_counts line3 string");
110 notification_update_msg_counts(NULL
);
113 void notification_lcdproc_disconnect(void)
117 shutdown(sock
->sock
, SHUT_RDWR
);
119 sock_close(sock
, TRUE
);
124 void notification_update_lcdproc(void)
126 NotificationMsgCount count
;
129 if(!notify_config
.lcdproc_enabled
|| !sock
)
132 if(!sock
|| sock
->state
== CONN_FAILED
) {
133 notification_lcdproc_connect();
137 notification_core_get_msg_count(NULL
, &count
);
139 if((count
.new_msgs
+ count
.unread_msgs
) > 0) {
141 g_strdup_printf("widget_set msg_counts line1 1 2 {%s: %d}",_("New"),
143 notification_lcdproc_send(buf
);
145 g_strdup_printf("widget_set msg_counts line2 1 3 {%s: %d}",_("Unread"),
147 notification_lcdproc_send(buf
);
149 g_strdup_printf("widget_set msg_counts line3 1 4 {%s: %d}",_("Total"),
151 notification_lcdproc_send(buf
);
154 buf
= g_strdup_printf("widget_set msg_counts line1 1 2 {%s}",
155 _("No new messages"));
156 notification_lcdproc_send(buf
);
157 buf
= g_strdup_printf("widget_set msg_counts line2 1 3 {}");
158 notification_lcdproc_send(buf
);
159 buf
= g_strdup_printf("widget_set msg_counts line3 1 4 {}");
160 notification_lcdproc_send(buf
);
166 void notification_sock_puts(SockInfo
*socket
, gchar
*string
)
168 sock_write(socket
, string
, strlen(string
));
169 sock_write(socket
, "\n", 1);
172 void notification_lcdproc_send(gchar
*string
)
174 notification_sock_puts(sock
, string
);
175 /* TODO: Check return message from LCDd */
178 #endif /* NOTIFICATION_LCDPROC */