Mercurial > pidgin.yaz
comparison gtk/plugins/notify.c @ 14264:d171bdecf17b
[gaim-migrate @ 16946]
Use the gtk conversation unseen_count instead of keeping my own count.
committer: Tailor Script <tailor@pidgin.im>
author | Etan Reisner <pidgin@unreliablesource.net> |
---|---|
date | Mon, 21 Aug 2006 06:06:54 +0000 |
parents | 009db0b357b5 |
children | a0a360de39d8 |
comparison
equal
deleted
inserted
replaced
14263:d7b40a686355 | 14264:d171bdecf17b |
---|---|
105 #define NOTIFY_PLUGIN_ID "gtk-x11-notify" | 105 #define NOTIFY_PLUGIN_ID "gtk-x11-notify" |
106 | 106 |
107 static GaimPlugin *my_plugin = NULL; | 107 static GaimPlugin *my_plugin = NULL; |
108 | 108 |
109 /* notification set/unset */ | 109 /* notification set/unset */ |
110 static int notify(GaimConversation *conv, gboolean increment); | 110 static int notify(GaimConversation *conv); |
111 static void notify_win(GaimGtkWindow *gaimwin); | 111 static void notify_win(GaimGtkWindow *gaimwin); |
112 static void unnotify(GaimConversation *conv, gboolean reset); | 112 static void unnotify(GaimConversation *conv, gboolean reset); |
113 static int unnotify_cb(GtkWidget *widget, gpointer data, GaimConversation *conv); | 113 static int unnotify_cb(GtkWidget *widget, gpointer data, GaimConversation *conv); |
114 | 114 |
115 /* gtk widget callbacks for prefs panel */ | 115 /* gtk widget callbacks for prefs panel */ |
133 static void handle_raise(GaimGtkWindow *gaimwin); | 133 static void handle_raise(GaimGtkWindow *gaimwin); |
134 | 134 |
135 /****************************************/ | 135 /****************************************/ |
136 /* Begin doing stuff below this line... */ | 136 /* Begin doing stuff below this line... */ |
137 /****************************************/ | 137 /****************************************/ |
138 static guint | |
139 count_messages(GaimGtkWindow *gaimwin) | |
140 { | |
141 guint count = 0; | |
142 GList *gtkconvs = NULL; | |
143 | |
144 for (gtkconvs = gaimwin->gtkconvs; gtkconvs != NULL; | |
145 gtkconvs = gtkconvs->next) { | |
146 GaimGtkConversation *gtkconv = gtkconvs->data; | |
147 count += gtkconv->unseen_count; | |
148 } | |
149 | |
150 return count; | |
151 } | |
152 | |
138 static int | 153 static int |
139 count_messages(GaimGtkWindow *gaimwin) | 154 notify(GaimConversation *conv) |
140 { | 155 { |
141 gint count = 0; | 156 gboolean has_focus; |
142 GList *convs = NULL, *l; | |
143 | |
144 for (convs = gaimwin->gtkconvs; convs != NULL; convs = convs->next) { | |
145 GaimGtkConversation *conv = convs->data; | |
146 for (l = conv->convs; l != NULL; l = l->next) { | |
147 count += GPOINTER_TO_INT(gaim_conversation_get_data(l->data, "notify-message-count")); | |
148 } | |
149 } | |
150 | |
151 return count; | |
152 } | |
153 | |
154 static int | |
155 notify(GaimConversation *conv, gboolean increment) | |
156 { | |
157 GaimGtkWindow *gaimwin = NULL; | 157 GaimGtkWindow *gaimwin = NULL; |
158 gint count; | |
159 gboolean has_focus; | |
160 | 158 |
161 if (conv == NULL) | 159 if (conv == NULL) |
162 return 0; | 160 return 0; |
163 | 161 |
164 /* We want to remove the notifications, but not reset the counter */ | 162 /* We want to remove the notifications, but not reset the counter */ |
176 g_object_get(G_OBJECT(gaimwin->window), | 174 g_object_get(G_OBJECT(gaimwin->window), |
177 "has-toplevel-focus", &has_focus, NULL); | 175 "has-toplevel-focus", &has_focus, NULL); |
178 | 176 |
179 if (gaim_prefs_get_bool("/plugins/gtk/X11/notify/type_focused") || | 177 if (gaim_prefs_get_bool("/plugins/gtk/X11/notify/type_focused") || |
180 !has_focus) { | 178 !has_focus) { |
181 if (increment) { | |
182 count = GPOINTER_TO_INT(gaim_conversation_get_data(conv, "notify-message-count")); | |
183 count++; | |
184 gaim_conversation_set_data(conv, "notify-message-count", GINT_TO_POINTER(count)); | |
185 } | |
186 | |
187 notify_win(gaimwin); | 179 notify_win(gaimwin); |
188 } | 180 } |
189 | 181 |
190 return 0; | 182 return 0; |
191 } | 183 } |
223 if (reset) { | 215 if (reset) { |
224 /* Only need to actually remove the urgent hinting here, since removing it | 216 /* Only need to actually remove the urgent hinting here, since removing it |
225 * just to have it readded in re-notify is an unnecessary couple extra RTs | 217 * just to have it readded in re-notify is an unnecessary couple extra RTs |
226 * to the server */ | 218 * to the server */ |
227 handle_urgent(gaimwin, FALSE); | 219 handle_urgent(gaimwin, FALSE); |
228 gaim_conversation_set_data(conv, "notify-message-count", GINT_TO_POINTER(0)); | |
229 } | 220 } |
230 | 221 |
231 return; | 222 return; |
232 } | 223 } |
233 | 224 |
234 static int | 225 static int |
235 unnotify_cb(GtkWidget *widget, gpointer data, GaimConversation *conv) | 226 unnotify_cb(GtkWidget *widget, gpointer data, GaimConversation *conv) |
236 { | 227 { |
237 if (GPOINTER_TO_INT(gaim_conversation_get_data(conv, "notify-message-count")) != 0) | 228 GaimGtkConversation *gtkconv = NULL; |
229 | |
230 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
231 | |
232 if (gtkconv->unseen_count > 0) | |
238 unnotify(conv, TRUE); | 233 unnotify(conv, TRUE); |
239 | 234 |
240 return 0; | 235 return 0; |
241 } | 236 } |
242 | 237 |
248 gaim_prefs_get_bool("/plugins/gtk/X11/notify/type_chat_nick") && | 243 gaim_prefs_get_bool("/plugins/gtk/X11/notify/type_chat_nick") && |
249 !(flags & GAIM_MESSAGE_NICK))) | 244 !(flags & GAIM_MESSAGE_NICK))) |
250 return FALSE; | 245 return FALSE; |
251 | 246 |
252 if ((flags & GAIM_MESSAGE_RECV) && !(flags & GAIM_MESSAGE_DELAYED)) | 247 if ((flags & GAIM_MESSAGE_RECV) && !(flags & GAIM_MESSAGE_DELAYED)) |
253 notify(conv, TRUE); | 248 notify(conv); |
254 | 249 |
255 return FALSE; | 250 return FALSE; |
256 } | 251 } |
257 | 252 |
258 static void | 253 static void |
351 ids = gaim_conversation_get_data(conv, "notify-entry-signals"); | 346 ids = gaim_conversation_get_data(conv, "notify-entry-signals"); |
352 for (l = ids; l != NULL; l = l->next) | 347 for (l = ids; l != NULL; l = l->next) |
353 g_signal_handler_disconnect(gtkconv->entry, GPOINTER_TO_INT(l->data)); | 348 g_signal_handler_disconnect(gtkconv->entry, GPOINTER_TO_INT(l->data)); |
354 g_slist_free(ids); | 349 g_slist_free(ids); |
355 | 350 |
356 gaim_conversation_set_data(conv, "notify-message-count", GINT_TO_POINTER(0)); | |
357 | |
358 gaim_conversation_set_data(conv, "notify-imhtml-signals", NULL); | 351 gaim_conversation_set_data(conv, "notify-imhtml-signals", NULL); |
359 gaim_conversation_set_data(conv, "notify-entry-signals", NULL); | 352 gaim_conversation_set_data(conv, "notify-entry-signals", NULL); |
360 } | 353 } |
361 | 354 |
362 static void | 355 static void |
363 conv_created(GaimConversation *conv) | 356 conv_created(GaimConversation *conv) |
364 { | 357 { |
365 gaim_conversation_set_data(conv, "notify-message-count", GINT_TO_POINTER(0)); | |
366 | |
367 /* always attach the signals, notify() will take care of conversation type | 358 /* always attach the signals, notify() will take care of conversation type |
368 * checking */ | 359 * checking */ |
369 attach_signals(conv); | 360 attach_signals(conv); |
370 } | 361 } |
371 | 362 |
378 | 369 |
379 /* | 370 /* |
380 * If the conversation was switched, then make sure we re-notify | 371 * If the conversation was switched, then make sure we re-notify |
381 * because Gaim will have overwritten our custom window title. | 372 * because Gaim will have overwritten our custom window title. |
382 */ | 373 */ |
383 notify(conv, FALSE); | 374 notify(conv); |
384 | 375 |
385 #if 0 | 376 #if 0 |
386 printf("conv_switched - %p - %p\n", old_conv, new_conv); | 377 printf("conv_switched - %p - %p\n", old_conv, new_conv); |
387 printf("count - %d\n", count_messages(gaimwin)); | 378 printf("count - %d\n", count_messages(gaimwin)); |
388 if (gaim_prefs_get_bool("/plugins/gtk/X11/notify/notify_switch")) | 379 if (gaim_prefs_get_bool("/plugins/gtk/X11/notify/notify_switch")) |
404 detach_signals(conv); | 395 detach_signals(conv); |
405 | 396 |
406 gaimwin = GAIM_GTK_CONVERSATION(conv)->win; | 397 gaimwin = GAIM_GTK_CONVERSATION(conv)->win; |
407 | 398 |
408 handle_urgent(gaimwin, FALSE); | 399 handle_urgent(gaimwin, FALSE); |
409 gaim_conversation_set_data(conv, "notify-message-count", GINT_TO_POINTER(0)); | |
410 | 400 |
411 return; | 401 return; |
412 | 402 |
413 #if 0 | 403 #if 0 |
414 /* i think this line crashes */ | 404 /* i think this line crashes */ |
590 } | 580 } |
591 | 581 |
592 static void | 582 static void |
593 apply_method() { | 583 apply_method() { |
594 GList *convs; | 584 GList *convs; |
595 GaimGtkWindow *gaimwin = NULL; | |
596 | 585 |
597 for (convs = gaim_get_conversations(); convs != NULL; convs = convs->next) { | 586 for (convs = gaim_get_conversations(); convs != NULL; convs = convs->next) { |
598 GaimConversation *conv = (GaimConversation *)convs->data; | 587 GaimConversation *conv = NULL; |
588 GaimGtkConversation *gtkconv = NULL; | |
589 | |
590 conv = (GaimConversation *) convs->data; | |
591 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
599 | 592 |
600 /* remove notifications */ | 593 /* remove notifications */ |
601 unnotify(conv, FALSE); | 594 unnotify(conv, FALSE); |
602 | 595 |
603 gaimwin = GAIM_GTK_CONVERSATION(conv)->win; | 596 if (gtkconv->unseen_count > 0) { |
604 if (GPOINTER_TO_INT(gaim_conversation_get_data(conv, "notify-message-count")) != 0) | |
605 /* reattach appropriate notifications */ | 597 /* reattach appropriate notifications */ |
606 notify(conv, FALSE); | 598 notify(conv); |
599 } | |
607 } | 600 } |
608 } | 601 } |
609 | 602 |
610 static void | 603 static void |
611 apply_notify() | 604 apply_notify() |