Improve some sieve-related translations
[claws.git] / src / plugins / notification / notification_lcdproc.c
blob0f131d107abcc758eb1e86e74c6e34b2b5e481be
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/>.
18 #ifdef HAVE_CONFIG_H
19 # include "config.h"
20 # include "claws-features.h"
21 #endif
23 #include <glib.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"
34 #include <string.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)
46 gint len, count;
47 gchar buf[NOTIFICATION_LCDPROC_BUFFER_SIZE];
49 if(!notify_config.lcdproc_enabled)
50 return;
52 if(sock)
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);
65 sock = NULL;
67 return;
69 else
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? */
78 count = 50;
79 len = 0;
80 while((len <= 0) && (count-- >= 0)) {
81 g_usleep(125000);
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
90 if (len <= 0) {
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();
96 return;
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)
115 if(sock) {
116 #ifndef G_OS_WIN32
117 shutdown(sock->sock, SHUT_RDWR);
118 #endif
119 sock_close(sock, TRUE);
120 sock = NULL;
124 void notification_update_lcdproc(void)
126 NotificationMsgCount count;
127 gchar *buf;
129 if(!notify_config.lcdproc_enabled || !sock)
130 return;
132 if(!sock || sock->state == CONN_FAILED) {
133 notification_lcdproc_connect();
134 return;
137 notification_core_get_msg_count(NULL, &count);
139 if((count.new_msgs + count.unread_msgs) > 0) {
140 buf =
141 g_strdup_printf("widget_set msg_counts line1 1 2 {%s: %d}",_("New"),
142 count.new_msgs);
143 notification_lcdproc_send(buf);
144 buf =
145 g_strdup_printf("widget_set msg_counts line2 1 3 {%s: %d}",_("Unread"),
146 count.unread_msgs);
147 notification_lcdproc_send(buf);
148 buf =
149 g_strdup_printf("widget_set msg_counts line3 1 4 {%s: %d}",_("Total"),
150 count.total_msgs);
151 notification_lcdproc_send(buf);
153 else {
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);
163 g_free(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 */