comparison plugins/notify.c @ 5021:00b6af528964

[gaim-migrate @ 5357] Jesse Farmer (vann) writes: "If one enabled "Quote window title" in the message away plugin, receiving multiple messages would cause the plugin to mangle the title. It turns out the parts of code used to modify the number between the brackets ([1],[2], etc.) assumed quoting was off. This patch should fix the problem." normally i'd wait for deryni to look at a notify.c patch, but we are trying to get thigns release-ready committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sat, 05 Apr 2003 04:00:03 +0000
parents 677d3cb193a1
children fefad67de2c7
comparison
equal deleted inserted replaced
5020:29c87c6e75d9 5021:00b6af528964
33 #include <X11/Xutil.h> 33 #include <X11/Xutil.h>
34 #include <X11/Xatom.h> 34 #include <X11/Xatom.h>
35 #include <gdk/gdkx.h> 35 #include <gdk/gdkx.h>
36 36
37 guint type = 1; 37 guint type = 1;
38 #define TYPE_IM 0x00000001 38 #define TYPE_IM 0x00000001
39 #define TYPE_CHAT 0x00000002 39 #define TYPE_CHAT 0x00000002
40 40
41 guint choice = 1; 41 guint choice = 1;
42 #define NOTIFY_FOCUS 0x00000001 42 #define NOTIFY_FOCUS 0x00000001
43 #define NOTIFY_TYPE 0x00000002 43 #define NOTIFY_TYPE 0x00000002
44 #define NOTIFY_IN_FOCUS 0x00000004 44 #define NOTIFY_IN_FOCUS 0x00000004
45 #define NOTIFY_CLICK 0x00000008 45 #define NOTIFY_CLICK 0x00000008
46 46
47 guint method = 1; 47 guint method = 1;
48 #define METHOD_STRING 0x00000001 48 #define METHOD_STRING 0x00000001
49 #define METHOD_QUOTE 0x00000002 49 #define METHOD_QUOTE 0x00000002
50 #define METHOD_URGENT 0x00000004 50 #define METHOD_URGENT 0x00000004
99 guint unnotify(struct gaim_conversation *c, gboolean clean) { 99 guint unnotify(struct gaim_conversation *c, gboolean clean) {
100 struct gaim_gtk_window *gtkwin; 100 struct gaim_gtk_window *gtkwin;
101 guint option = 0; 101 guint option = 0;
102 102
103 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); 103 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c));
104 104
105 /* The top level ifs check whether we are either cleaning all methods, 105 /* The top level ifs check whether we are either cleaning all methods,
106 * or whether we have that method is currently selected. 106 * or whether we have that method is currently selected.
107 * If we do then they are cleaned 107 * If we do then they are cleaned
108 * 108 *
109 * The second level ifs check if we removed something, 109 * The second level ifs check if we removed something,
110 * and if that method is currently selected. 110 * and if that method is currently selected.
111 * If we did and it is then set option so that it can be re-added */ 111 * If we did and it is then set option so that it can be re-added */
112 if (clean || (method & METHOD_QUOTE)) 112 if (clean || (method & METHOD_QUOTE))
113 if (quote_remove(gtkwin->window) && (method & METHOD_QUOTE)) 113 if (quote_remove(gtkwin->window) && (method & METHOD_QUOTE))
114 option ^= METHOD_QUOTE; 114 option ^= METHOD_QUOTE;
115 115
116 if (clean || (method & METHOD_COUNT)) 116 if (clean || (method & METHOD_COUNT))
117 if (count_remove(gtkwin->window) && (method & METHOD_COUNT)) 117 if (count_remove(gtkwin->window) && (method & METHOD_COUNT))
118 option ^= METHOD_COUNT; 118 option ^= METHOD_COUNT;
119 119
120 if (clean || (method & METHOD_STRING)) 120 if (clean || (method & METHOD_STRING))
238 if (c && method & METHOD_URGENT) 238 if (c && method & METHOD_URGENT)
239 urgent_remove(c); 239 urgent_remove(c);
240 return 0; 240 return 0;
241 } 241 }
242 242
243 /* This function returns the number in [ ]'s or 0 */ 243 /* This function returns the number in [ ]'s or 0
244 and sets *length to the number of digits in that number */
244 int counter (char *buf, int *length) { 245 int counter (char *buf, int *length) {
245 char temp[256]; 246 char temp[256];
246 int i = 1; 247 int i = 0;
248 int j = 0;
247 *length = 0; 249 *length = 0;
248 250
251 /* Don't assume buf[0]=='[' */
252 while( buf[i++] != '[' && i<sizeof(buf));
253
249 while (isdigit(buf[i]) && i<sizeof(buf)) { 254 while (isdigit(buf[i]) && i<sizeof(buf)) {
250 temp[i-1] = buf[i]; 255 temp[j++] = buf[i++];
251 (*length)++; 256 (*length)++;
252 i++; 257 }
253 } 258 temp[j] = '\0';
254 temp[i] = '\0';
255 259
256 if (buf[i] != ']') { 260 if (buf[i] != ']') {
257 *length = 0; 261 *length = 0;
258 return (0); 262 return (0);
259 } 263 }
290 int c, length; 294 int c, length;
291 GtkWindow *win = GTK_WINDOW(widget); 295 GtkWindow *win = GTK_WINDOW(widget);
292 296
293 strncpy(buf, win->title, sizeof(buf)); 297 strncpy(buf, win->title, sizeof(buf));
294 c = counter(buf, &length); 298 c = counter(buf, &length);
299
295 if (number) { 300 if (number) {
301 /* This might cause problems in the future.
302 I'm pretty sure if count_add is called after quote_add
303 and number!=0, then this will have problems dealing with
304 the quotation marks. */
296 g_snprintf(buf, sizeof(buf), "[%d] %s", number, win->title); 305 g_snprintf(buf, sizeof(buf), "[%d] %s", number, win->title);
297 } else if (!c) { 306 } else if (!c) {
298 g_snprintf(buf, sizeof(buf), "[1] %s", win->title); 307 g_snprintf(buf, sizeof(buf), "[1] %s", win->title);
299 } else if (buf[0]== '[' ) { 308 } else if (buf[0] == '[' || buf[1] == '[' ) {
300 g_snprintf(buf, sizeof(buf), "[%d] %s", c+1, &win->title[3+length]); 309 /* This has to be so complicated in order to account for METHOD_QUOTE */
310 g_snprintf(buf, sizeof(buf), "[%d] %s", c+1, &win->title[ ((method & METHOD_QUOTE) ? 4 : 3)+length ]);
311 if( buf[ strlen(buf)-1 ] == '"' )
312 buf[ strlen(buf)-1 ] = '\0';
301 } 313 }
302 gtk_window_set_title(win, buf); 314 gtk_window_set_title(win, buf);
303 } 315 }
304 316
305 gboolean count_remove(GtkWidget *widget) { 317 gboolean count_remove(GtkWidget *widget) {