Mercurial > hg
comparison mcabber/src/roster.c @ 236:72fd1273f2b7
[/trunk] Changeset 249 by mikael
* Update TODO
* Add /roster parameters "unread_first" and "unread_next"
* Add Ctrl-q as a shortcut for "/roster unread_next"
* Update Documentation (ctrl-q + unread_*)
* Update ChangeLog
author | mikael |
---|---|
date | Fri, 10 Jun 2005 19:03:06 +0000 |
parents | d5ae42cbe1fa |
children | 57f9005b8844 |
comparison
equal
deleted
inserted
replaced
235:f7f07794d2df | 236:72fd1273f2b7 |
---|---|
40 | 40 |
41 /* ### Variables ### */ | 41 /* ### Variables ### */ |
42 | 42 |
43 static int hide_offline_buddies; | 43 static int hide_offline_buddies; |
44 static GSList *groups; | 44 static GSList *groups; |
45 static GSList *unread_list; | |
45 GList *buddylist; | 46 GList *buddylist; |
46 GList *current_buddy; | 47 GList *current_buddy; |
47 | |
48 #ifdef MCABBER_TESTUNIT | |
49 // Export groups for testing routines | |
50 GSList **pgroups = &groups; | |
51 #endif | |
52 | 48 |
53 | 49 |
54 /* ### Roster functions ### */ | 50 /* ### Roster functions ### */ |
55 | 51 |
56 // Comparison function used to search in the roster (compares jids and types) | 52 // Comparison function used to search in the roster (compares jids and types) |
179 roster_usr = (roster*)sl_user->data; | 175 roster_usr = (roster*)sl_user->data; |
180 if (roster_usr->jid) g_free((gchar*)roster_usr->jid); | 176 if (roster_usr->jid) g_free((gchar*)roster_usr->jid); |
181 if (roster_usr->name) g_free((gchar*)roster_usr->name); | 177 if (roster_usr->name) g_free((gchar*)roster_usr->name); |
182 if (roster_usr->status_msg) g_free((gchar*)roster_usr->status_msg); | 178 if (roster_usr->status_msg) g_free((gchar*)roster_usr->status_msg); |
183 g_free(roster_usr); | 179 g_free(roster_usr); |
180 | |
181 // Remove (if present) from unread messages list | |
182 unread_list = g_slist_delete_link(unread_list, sl_user); | |
184 | 183 |
185 // That's a little complex, we need to dereference twice | 184 // That's a little complex, we need to dereference twice |
186 sl_group = ((roster*)sl_user->data)->list; | 185 sl_group = ((roster*)sl_user->data)->list; |
187 sl_group_listptr = &((roster*)(sl_group->data))->list; | 186 sl_group_listptr = &((roster*)(sl_group->data))->list; |
188 *sl_group_listptr = g_slist_delete_link(*sl_group_listptr, sl_user); | 187 *sl_group_listptr = g_slist_delete_link(*sl_group_listptr, sl_user); |
273 } | 272 } |
274 | 273 |
275 // roster_msg_setflag() | 274 // roster_msg_setflag() |
276 // Set the ROSTER_FLAG_MSG to the given value for the given jid. | 275 // Set the ROSTER_FLAG_MSG to the given value for the given jid. |
277 // It will update the buddy's group message flag. | 276 // It will update the buddy's group message flag. |
277 // Update the unread messages list too. | |
278 void roster_msg_setflag(const char *jid, guint value) | 278 void roster_msg_setflag(const char *jid, guint value) |
279 { | 279 { |
280 GSList *sl_user; | 280 GSList *sl_user; |
281 roster *roster_usr, *roster_grp; | 281 roster *roster_usr, *roster_grp; |
282 | 282 |
289 if (value) { | 289 if (value) { |
290 // Message flag is TRUE. This is easy, we just have to set both flags | 290 // Message flag is TRUE. This is easy, we just have to set both flags |
291 // to TRUE... | 291 // to TRUE... |
292 roster_usr->flags |= ROSTER_FLAG_MSG; | 292 roster_usr->flags |= ROSTER_FLAG_MSG; |
293 roster_grp->flags |= ROSTER_FLAG_MSG; // group | 293 roster_grp->flags |= ROSTER_FLAG_MSG; // group |
294 // Append the roster_usr to unread_list, but avoid duplicates | |
295 if (!g_slist_find(unread_list, roster_usr)) | |
296 unread_list = g_slist_append(unread_list, roster_usr); | |
294 } else { | 297 } else { |
295 // Message flag is FALSE. | 298 // Message flag is FALSE. |
296 guint msg = FALSE; | 299 guint msg = FALSE; |
297 roster_usr->flags &= ~ROSTER_FLAG_MSG; | 300 roster_usr->flags &= ~ROSTER_FLAG_MSG; |
301 if (unread_list) { | |
302 GSList *node = g_slist_find(unread_list, roster_usr); | |
303 if (node) unread_list = g_slist_delete_link(unread_list, node); | |
304 } | |
298 // For the group value we need to watch all buddies in this group; | 305 // For the group value we need to watch all buddies in this group; |
299 // if one is flagged, then the group will be flagged. | 306 // if one is flagged, then the group will be flagged. |
300 // I will re-use sl_user and roster_usr here, as they aren't used | 307 // I will re-use sl_user and roster_usr here, as they aren't used |
301 // anymore. | 308 // anymore. |
302 sl_user = roster_grp->list; | 309 sl_user = roster_grp->list; |
643 } | 650 } |
644 | 651 |
645 return list; | 652 return list; |
646 } | 653 } |
647 | 654 |
655 // unread_msg(rosterdata) | |
656 // Return the next buddy with an unread message. If the parameter is NULL, | |
657 // return the first buddy with an unread message. | |
658 gpointer unread_msg(gpointer rosterdata) | |
659 { | |
660 GSList *unread, *next_unread; | |
661 | |
662 if (!unread_list) return NULL; | |
663 // First unread message | |
664 if (!rosterdata) return unread_list->data; | |
665 | |
666 unread = g_slist_find(unread_list, rosterdata); | |
667 if (!unread) return unread_list->data; | |
668 | |
669 next_unread = g_slist_next(unread); | |
670 if (next_unread) return next_unread->data; | |
671 | |
672 return unread_list->data; | |
673 } | |
674 |