changeset 974:36f7753dfb59

Add /roster item_{lock,unlock} These commands allow us to lock a contact so it stays visible in the roster when hide_offline_buddies is set.
author Mikael Berthe <mikael@lilotux.net>
date Sat, 30 Sep 2006 22:42:32 +0200
parents e693cbe33802
children c3198eea6c3b
files mcabber/src/commands.c mcabber/src/roster.c mcabber/src/roster.h
diffstat 3 files changed, 49 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/commands.c	Sat Sep 30 19:13:20 2006 +0200
+++ b/mcabber/src/commands.c	Sat Sep 30 22:42:32 2006 +0200
@@ -151,6 +151,8 @@
   compl_add_category_word(COMPL_ROSTER, "hide_offline");
   compl_add_category_word(COMPL_ROSTER, "show_offline");
   compl_add_category_word(COMPL_ROSTER, "toggle_offline");
+  compl_add_category_word(COMPL_ROSTER, "item_lock");
+  compl_add_category_word(COMPL_ROSTER, "item_unlock");
   compl_add_category_word(COMPL_ROSTER, "alternate");
   compl_add_category_word(COMPL_ROSTER, "search");
   compl_add_category_word(COMPL_ROSTER, "unread_first");
@@ -421,6 +423,46 @@
   return process_command(line);
 }
 
+// Helper routine for buffer item_{lock,unlock}
+static void roster_buddylock(char *jid, bool lock)
+{
+  gpointer bud = NULL;
+  bool may_need_refresh = FALSE;
+
+  // Allow special jid "" or "." (current buddy)
+  if (jid && (!*jid || !strcmp(jid, ".")))
+    jid = NULL;
+
+  if (jid) {
+    // The JID has been specified.  Quick check...
+    if (check_jid_syntax(jid)) {
+      scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", jid);
+    } else {
+      // Find the buddy
+      GSList *roster_elt;
+      roster_elt = roster_find(jid, jidsearch,
+                               ROSTER_TYPE_USER|ROSTER_TYPE_ROOM);
+      if (roster_elt)
+        bud = roster_elt->data;
+      else
+        scr_LogPrint(LPRINT_NORMAL, "This jid isn't in the roster.");
+      may_need_refresh = TRUE;
+    }
+  } else {
+    // Use the current buddy
+    if (current_buddy)
+      bud = BUDDATA(current_buddy);
+  }
+
+  // Update the ROSTER_FLAG_USRLOCK flag
+  if (bud) {
+    buddy_setflags(bud, ROSTER_FLAG_USRLOCK, lock);
+    if (may_need_refresh)
+      buddylist_build();
+      update_roster = TRUE;
+  }
+}
+
 /* Commands callback functions */
 /* All these do_*() functions will be called with a "arg" parameter */
 /* (with arg not null)                                              */
@@ -465,6 +507,10 @@
     buddylist_set_hide_offline_buddies(-1);
     buddylist_build();
     update_roster = TRUE;
+  } else if (!strcasecmp(subcmd, "item_lock")) {
+    roster_buddylock(arg, TRUE);
+  } else if (!strcasecmp(subcmd, "item_unlock")) {
+    roster_buddylock(arg, FALSE);
   } else if (!strcasecmp(subcmd, "unread_first")) {
     scr_RosterUnreadMessage(0);
   } else if (!strcasecmp(subcmd, "unread_next")) {
--- a/mcabber/src/roster.c	Sat Sep 30 19:13:20 2006 +0200
+++ b/mcabber/src/roster.c	Sat Sep 30 22:42:32 2006 +0200
@@ -795,7 +795,7 @@
       if (!hide_offline_buddies || roster_usrelt == roster_current_buddy ||
           (buddy_getstatus((gpointer)roster_usrelt, NULL) != offline) ||
           (buddy_getflags((gpointer)roster_usrelt) &
-               (ROSTER_FLAG_LOCK | ROSTER_FLAG_MSG))) {
+               (ROSTER_FLAG_LOCK | ROSTER_FLAG_USRLOCK | ROSTER_FLAG_MSG))) {
         // This user should be added.  Maybe the group hasn't been added yet?
         if (pending_group &&
             (hide_offline_buddies || roster_usrelt == roster_current_buddy)) {
--- a/mcabber/src/roster.h	Sat Sep 30 19:13:20 2006 +0200
+++ b/mcabber/src/roster.h	Sat Sep 30 22:42:32 2006 +0200
@@ -71,7 +71,8 @@
 #define ROSTER_FLAG_MSG     1U      // Message not read
 #define ROSTER_FLAG_HIDE    (1U<<1) // Group hidden (or buddy window closed)
 #define ROSTER_FLAG_LOCK    (1U<<2) // Node should not be removed from buddylist
-// ROSTER_FLAG_LOCAL   (1U<<3) // Buddy not on server's roster  (??)
+#define ROSTER_FLAG_USRLOCK (1U<<3) // Node should not be removed from buddylist
+// ROSTER_FLAG_LOCAL   (1U<<4) // Buddy not on server's roster  (??)
 
 extern GList *buddylist;
 extern GList *current_buddy;