changeset 265:49e9e02dd6d0

Add "/roster search" command
author mikael@frmp8452
date Sat, 02 Jul 2005 19:23:45 +0100
parents b7dd4c337888
children 2b0db4b458eb
files mcabber/doc/mcabber.1 mcabber/doc/mcabber.1.html mcabber/doc/mcabber.1.txt mcabber/src/commands.c mcabber/src/roster.c mcabber/src/roster.h mcabber/src/screen.c mcabber/src/screen.h
diffstat 8 files changed, 119 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/doc/mcabber.1	Sat Jul 02 12:06:10 2005 +0100
+++ b/mcabber/doc/mcabber.1	Sat Jul 02 19:23:45 2005 +0100
@@ -114,7 +114,7 @@
 The buffer command manipulates the current buddy's buffer (chat window)\&.
 
  \fBclear\fR	clear the current buddy chat window
- \fBtop\fR	jump to the top of the current buddy chat buffer
+ \fBtop\fR 	jump to the top of the current buddy chat buffer
  \fBbottom\fR	jump to the bottom of the current buddy chat buffer
 
 .TP
@@ -129,9 +129,9 @@
 \fB/group\fR fold|unfold|toggle
 The group command changes the current group display\&.
 
- \fBfold\fR fold (shrink) the current group tree in the roster
- \fBunfold\fR unfold (expand) the current group tree in the roster
- \fBtoggle\fR toggle the state (fold/unfold) of the current tree
+ \fBfold\fR	fold (shrink) the current group tree in the roster
+ \fBunfold\fR	unfold (expand) the current group tree in the roster
+ \fBtoggle\fR	toggle the state (fold/unfold) of the current tree
 
 .TP
 \fB/info\fR
@@ -145,25 +145,26 @@
 \fB/msay\fR begin|verbatim|send|abort
 Send a multi\-line message\&. To write a single message with several lines, the \fImulti\-line mode\fR should be used\&. In multi\-line mode, each line (except command lines) typed in the input line will be added to the multi\-line message\&. Once the message is finished, it can be sent to the current selected buddy with the "msay /send" command\&. The \fIverbatim\fR multi\-line mode disables commands, so that it is possible to enter lines starting with a slash\&. Only the "/msay" command (with send or abort parameters) can be used to exit verbatim mode\&.
 
- \fBbegin\fR enter multi\-line mode
- \fBverbatim\fR enter verbatim multi\-line mode
- \fBsend\fR send the current multi\-line message to the currently selected buddy
- \fBabort\fR leave multi\-line mode without sending the message
+ \fBbegin\fR	enter multi\-line mode
+ \fBverbatim\fR	enter verbatim multi\-line mode
+ \fBsend\fR	send the current multi\-line message to the currently selected buddy
+ \fBabort\fR	leave multi\-line mode without sending the message
 
 .TP
 \fB/rename\fR nickname
 Rename current buddy to the given nickname\&. This command does not work for groups, at the moment (but you can move the buddies to another group with the /move command)\&.
 
 .TP
-\fB/roster\fR hide_offline|show_offline|top|bottom
-The roster command manipulates the roster/buddylist\&.
+\fB/roster\fR
+The roster command manipulates the roster/buddylist\&.  Here are the available parameters:
 
- \fBhide_offline\fR hide offline buddies
- \fBshow_offline\fR show offline buddies
- \fBtop\fR jump to the top of the roster
- \fBbottom\fR jump to the bottom of the roster
- \fIunread_first\fR jump to the first unread message
- \fIunread_next\fR jump to the next unread message
+ \fBbottom\fR     	jump to the bottom of the roster
+ \fBtop\fR        	jump to the top of the roster
+ \fBhide_offline\fR	hide offline buddies
+ \fBshow_offline\fR	show offline buddies
+ \fBsearch\fR bud	search for a buddy with a name or buddy containing "bud" (only in the displayed buddylist)
+ \fBunread_first\fR	jump to the first unread message
+ \fBunread_next\fR	jump to the next unread message
 
 .TP
 \fB/say\fR text
--- a/mcabber/doc/mcabber.1.html	Sat Jul 02 12:06:10 2005 +0100
+++ b/mcabber/doc/mcabber.1.html	Sat Jul 02 19:23:45 2005 +0100
@@ -351,13 +351,32 @@
         the buddies to another group with the /move command).
 </dd>
 <dt><b>
-/roster hide_offline|show_offline|top|bottom
+/roster bottom|top|hide_offline|show_offline|unread_first|unread_next
+</b></dt>
+<dt><b>
+/roster search bud
 </b></dt>
 <dd>
-        The <b>roster</b> command manipulates the roster/buddylist.
+        The <b>roster</b> command manipulates the roster/buddylist.  Here are the available parameters:
 <table class="hlist">
 <tr valign="top">
 <td>
+<b>bottom</b>
+</td>
+<td>
+jump to the bottom of the roster
+</td>
+</tr>
+<tr valign="top">
+<td>
+<b>top</b>
+</td>
+<td>
+jump to the top of the roster
+</td>
+</tr>
+<tr valign="top">
+<td>
 <b>hide_offline</b>
 </td>
 <td>
@@ -374,18 +393,10 @@
 </tr>
 <tr valign="top">
 <td>
-<b>top</b>
+<b>search</b> bud
 </td>
 <td>
-jump to the top of the roster
-</td>
-</tr>
-<tr valign="top">
-<td>
-<b>bottom</b>
-</td>
-<td>
-jump to the bottom of the roster
+search for a buddy with a name or buddy containing "bud" (only in the displayed buddylist)
 </td>
 </tr>
 <tr valign="top">
@@ -444,7 +455,7 @@
 <div id="footer">
 <p>
 Version 0.6.2<br />
-Last updated 02-Jul-2005 13:00:02 CEST
+Last updated 02-Jul-2005 20:05:04 CEST
 </p>
 </div>
 </div>
--- a/mcabber/doc/mcabber.1.txt	Sat Jul 02 12:06:10 2005 +0100
+++ b/mcabber/doc/mcabber.1.txt	Sat Jul 02 19:23:45 2005 +0100
@@ -135,13 +135,15 @@
         This command does not work for groups, at the moment (but you can move
         the buddies to another group with the /move command).
 
-/roster hide_offline|show_offline|top|bottom::
-        The 'roster' command manipulates the roster/buddylist.
+/roster bottom|top|hide_offline|show_offline|unread_first|unread_next::
+/roster search bud::
+        The 'roster' command manipulates the roster/buddylist.  Here are the available parameters:
 
+        'bottom';;       jump to the bottom of the roster
+        'top';;          jump to the top of the roster
         'hide_offline';; hide offline buddies
         'show_offline';; show offline buddies
-        'top';;          jump to the top of the roster
-        'bottom';;       jump to the bottom of the roster
+        'search' bud;;   search for a buddy with a name or buddy containing "bud" (only in the displayed buddylist)
         'unread_first';; jump to the first unread message
         'unread_next';;  jump to the next unread message
 
--- a/mcabber/src/commands.c	Sat Jul 02 12:06:10 2005 +0100
+++ b/mcabber/src/commands.c	Sat Jul 02 19:23:45 2005 +0100
@@ -104,9 +104,10 @@
 
   // Roster category
   compl_add_category_word(COMPL_ROSTER, "bottom");
+  compl_add_category_word(COMPL_ROSTER, "top");
   compl_add_category_word(COMPL_ROSTER, "hide_offline");
   compl_add_category_word(COMPL_ROSTER, "show_offline");
-  compl_add_category_word(COMPL_ROSTER, "top");
+  compl_add_category_word(COMPL_ROSTER, "search");
   compl_add_category_word(COMPL_ROSTER, "unread_first");
   compl_add_category_word(COMPL_ROSTER, "unread_next");
 
@@ -276,6 +277,20 @@
     scr_RosterUnreadMessage(0);
   } else if (!strcasecmp(arg, "unread_next")) {
     scr_RosterUnreadMessage(1);
+  } else if (!strncasecmp(arg, "search", 6)) {
+    char *string = arg+6;
+    if (*string && (*string != ' ')) {
+      scr_LogPrint("Unrecognized parameter!");
+      return;
+    }
+    while (*string == ' ')
+      string++;
+    if (!*string) {
+      scr_LogPrint("What name or jid are you looking for?");
+      return;
+    }
+    scr_RosterSearch(string);
+    update_roster = TRUE;
   } else
     scr_LogPrint("Unrecognized parameter!");
 }
--- a/mcabber/src/roster.c	Sat Jul 02 12:06:10 2005 +0100
+++ b/mcabber/src/roster.c	Sat Jul 02 19:23:45 2005 +0100
@@ -19,6 +19,7 @@
  * USA
  */
 
+#define _GNU_SOURCE     /* for strcasestr() */
 #include <string.h>
 
 #include "roster.h"
@@ -627,6 +628,31 @@
   return roster_usr->flags;
 }
 
+//  buddy_search(string)
+// Look for a buddy whose name or jid contains string.
+// Search begins at current_buddy; if no match is found in the the buddylist,
+// return NULL;
+GList *buddy_search(char *string)
+{
+  GList *buddy = current_buddy;
+  roster *roster_usr;
+  if (!buddylist || !current_buddy) return NULL;
+  for (;;) {
+    buddy = g_list_next(buddy);
+    if (!buddy)
+      buddy = buddylist;
+
+    roster_usr = (roster*)buddy->data;
+    if (roster_usr->jid && strcasestr(roster_usr->jid, string))
+      return buddy;
+    if (roster_usr->name && strcasestr(roster_usr->name, string))
+      return buddy;
+
+    if (buddy == current_buddy)
+      return NULL; // Back to the beginning, and no match found
+  }
+}
+
 //  compl_list(type)
 // Returns a list of jid's or groups.  (For commands completion)
 // type: ROSTER_TYPE_USER (jid's) or ROSTER_TYPE_GROUP (group names)
--- a/mcabber/src/roster.h	Sat Jul 02 12:06:10 2005 +0100
+++ b/mcabber/src/roster.h	Sat Jul 02 19:23:45 2005 +0100
@@ -60,6 +60,7 @@
 const char *buddy_getstatusmsg(gpointer rosterdata);
 void    buddy_setflags(gpointer rosterdata, guint flags, guint value);
 guint   buddy_getflags(gpointer rosterdata);
+GList  *buddy_search(char *string);
 gpointer unread_msg(gpointer rosterdata);
 
 GSList *compl_list(guint type);
--- a/mcabber/src/screen.c	Sat Jul 02 12:06:10 2005 +0100
+++ b/mcabber/src/screen.c	Sat Jul 02 19:23:45 2005 +0100
@@ -843,6 +843,34 @@
     scr_ShowBuddyWindow();
 }
 
+//  scr_RosterSearch(str)
+// Look forward for a buddy with jid/name containing str.
+void scr_RosterSearch(char *str)
+{
+  GList *matching_buddy;
+  enum imstatus prev_st = imstatus_size; // undef
+
+  if (current_buddy) {
+    matching_buddy = buddy_search(str);
+    if (matching_buddy) {
+      prev_st = buddy_getstatus(BUDDATA(current_buddy));
+      buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
+      current_buddy = matching_buddy;
+      if (chatmode)
+        buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE);
+      // We should rebuild the buddylist but not everytime
+      // Here we check if we were locking a buddy who is actually offline,
+      // and hide_offline_buddies is TRUE.  In which case we need to rebuild.
+      if (prev_st == offline && buddylist_get_hide_offline_buddies())
+        buddylist_build();
+      update_roster = TRUE;
+    }
+  }
+
+  if (chatmode)
+    scr_ShowBuddyWindow();
+}
+
 //  scr_RosterUnreadMessage(next)
 // Go to a new message.  If next is not null, try to go to the next new
 // message.  If it is not possible or if next is NULL, go to the first new
--- a/mcabber/src/screen.h	Sat Jul 02 12:06:10 2005 +0100
+++ b/mcabber/src/screen.h	Sat Jul 02 19:23:45 2005 +0100
@@ -44,6 +44,7 @@
 // For commands...
 void scr_RosterTop(void);
 void scr_RosterBottom(void);
+void scr_RosterSearch(char *);
 void scr_BufferTop(void);
 void scr_BufferBottom(void);
 void scr_Clear(void);