changeset 238:8e30b2bb380e

[/trunk] Changeset 251 by mikael * Add /msay command (multi-line messages)
author mikael
date Sat, 11 Jun 2005 19:12:25 +0000
parents c8df64f43625
children 20111c373ba3
files mcabber/doc/mcabber.1 mcabber/doc/mcabber.1.html mcabber/doc/mcabber.1.txt mcabber/src/commands.c mcabber/src/commands.h mcabber/src/compl.h mcabber/src/screen.c mcabber/src/screen.h
diffstat 8 files changed, 219 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/doc/mcabber.1	Fri Jun 10 19:26:34 2005 +0000
+++ b/mcabber/doc/mcabber.1	Sat Jun 11 19:12:25 2005 +0000
@@ -140,8 +140,12 @@
 Move the current buddy to the requested group\&. If no group is specified, then the buddy is moved to the default group\&. This command only works with users (not agents), at the moment\&.
 
 .TP
-\fB/quit\fR
-Disconnect and leave mcabber(1) 
+\fB/msay\fR begin|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\&.
+
+ \fBbegin\fR enter 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
--- a/mcabber/doc/mcabber.1.html	Fri Jun 10 19:26:34 2005 +0000
+++ b/mcabber/doc/mcabber.1.html	Sat Jun 11 19:12:25 2005 +0000
@@ -353,6 +353,51 @@
 
 </dd>
 <dt><b>
+/msay begin|send|abort
+</b></dt>
+<dd>
+
+        Send a multi-line message.  To write a single message with several
+        lines, the <b>multi-line mode</b> 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.
+
+<table class="hlist">
+<tr valign="top">
+<td>
+<b>begin</b>
+</td>
+<td>
+
+enter multi-line mode
+
+</td>
+</tr>
+<tr valign="top">
+<td>
+<b>send</b>
+</td>
+<td>
+
+send the current multi-line message to the currently selected buddy
+
+</td>
+</tr>
+<tr valign="top">
+<td>
+<b>abort</b>
+</td>
+<td>
+
+leave multi-line mode without sending the message
+
+</td>
+</tr>
+</table>
+</dd>
+<dt><b>
 /quit
 </b></dt>
 <dd>
@@ -498,7 +543,7 @@
 <div id="footer">
 <p>
 Version 0.6.1<br />
-Last updated 10-Jun-2005 22:47:25 CEST
+Last updated 11-Jun-2005 23:08:15 CEST
 </p>
 </div>
 </div>
--- a/mcabber/doc/mcabber.1.txt	Fri Jun 10 19:26:34 2005 +0000
+++ b/mcabber/doc/mcabber.1.txt	Sat Jun 11 19:12:25 2005 +0000
@@ -110,6 +110,18 @@
         specified, then the buddy is moved to the default group.
         This command only works with users (not agents), at the moment.
 
+/msay begin|send|abort::
+        Send a multi-line message.  To write a single message with several
+        lines, the 'multi-line mode' 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.
+
+        'begin';; enter multi-line mode
+        'send';; send the current multi-line message to the currently selected buddy
+        'abort';; leave multi-line mode without sending the message
+
 /quit::
         Disconnect and leave `mcabber(1)`.
 
--- a/mcabber/src/commands.c	Fri Jun 10 19:26:34 2005 +0000
+++ b/mcabber/src/commands.c	Sat Jun 11 19:12:25 2005 +0000
@@ -38,6 +38,7 @@
 void do_del(char *arg);
 void do_group(char *arg);
 void do_say(char *arg);
+void do_msay(char *arg);
 void do_buffer(char *arg);
 void do_clear(char *arg);
 void do_info(char *arg);
@@ -78,6 +79,8 @@
   cmd_add("info", "Show basic infos on current buddy", 0, 0, &do_info);
   cmd_add("move", "Move the current buddy to another group", COMPL_GROUPNAME,
           0, &do_move);
+  cmd_add("msay", "Send a multi-lines message to the selected buddy",
+          COMPL_MULTILINE, 0, &do_msay);
   //cmd_add("nick");
   cmd_add("quit", "Exit the software", 0, 0, NULL);
   cmd_add("rename", "Rename the current buddy", 0, 0, &do_rename);
@@ -116,14 +119,19 @@
   compl_add_category_word(COMPL_GROUP, "expand");
   compl_add_category_word(COMPL_GROUP, "shrink");
   compl_add_category_word(COMPL_GROUP, "toggle");
+
+  // Multi-line (msay) category
+  compl_add_category_word(COMPL_MULTILINE, "abort");
+  compl_add_category_word(COMPL_MULTILINE, "begin");
+  compl_add_category_word(COMPL_MULTILINE, "send");
 }
 
 //  cmd_get
 // Finds command in the command list structure.
 // Returns a pointer to the cmd entry, or NULL if command not found.
-cmd *cmd_get(char *command)
+cmd *cmd_get(const char *command)
 {
-  char *p1, *p2;
+  const char *p1, *p2;
   char *com;
   GSList *sl_com;
   // Ignore leading '/'
@@ -150,7 +158,7 @@
 //  send_message(msg)
 // Write the message in the buddy's window and send the message on
 // the network.
-void send_message(char *msg)
+void send_message(const char *msg)
 {
   const char *jid;
       
@@ -182,6 +190,10 @@
   cmd *curcmd;
 
   if (!*line) { // User only pressed enter
+    if (scr_get_multimode()) {
+      scr_append_multiline("");
+      return 0;
+    }
     if (current_buddy) {
       scr_set_chatmode(TRUE);
       buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE);
@@ -191,7 +203,10 @@
   }
 
   if (*line != '/') {
-    do_say(line);
+    if (scr_get_multimode())
+      scr_append_multiline(line);
+    else
+      do_say(line);
     return 0;
   }
 
@@ -374,6 +389,54 @@
   send_message(arg);
 }
 
+void do_msay(char *arg)
+{
+  /* begin abort send */
+  gpointer bud;
+
+  if (!strcasecmp(arg, "abort")) {
+    scr_set_multimode(FALSE);
+    return;
+  } else if (!strcasecmp(arg, "begin")) {
+    scr_set_multimode(TRUE);
+    scr_LogPrint("Entered multi-line message mode.");
+    scr_LogPrint("Select a buddy and use \"/msay send\" "
+                 "when your message is ready.");
+    return;
+  } else if (*arg == 0) {
+    scr_LogPrint("Please read the manual before using the /msay command.");
+    scr_LogPrint("(Use /msay begin to enter multi-line mode...)");
+    return;
+  } else if (strcasecmp(arg, "send")) {
+    scr_LogPrint("Unrecognized parameter!");
+    return;
+  }
+
+  // send command
+
+  if (!scr_get_multimode()) {
+    scr_LogPrint("No message to send.  Use \"/msay begin\" first.");
+    return;
+  }
+
+  scr_set_chatmode(TRUE);
+
+  if (!current_buddy) {
+    scr_LogPrint("Who are you talking to??");
+    return;
+  }
+
+  bud = BUDDATA(current_buddy);
+  if (!(buddy_gettype(bud) & ROSTER_TYPE_USER)) {
+    scr_LogPrint("This is not a user");
+    return;
+  }
+
+  buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE);
+  send_message(scr_get_multiline());
+  scr_set_multimode(FALSE);
+}
+
 void do_buffer(char *arg)
 {
   if (!strcasecmp(arg, "top")) {
--- a/mcabber/src/commands.h	Fri Jun 10 19:26:34 2005 +0000
+++ b/mcabber/src/commands.h	Sat Jun 11 19:12:25 2005 +0000
@@ -12,7 +12,7 @@
 } cmd;
 
 void cmd_init(void);
-cmd *cmd_get(char *command);
+cmd *cmd_get(const char *command);
 int  process_line(char *line);
 
 #endif /* __COMMANDS_H__ */
--- a/mcabber/src/compl.h	Fri Jun 10 19:26:34 2005 +0000
+++ b/mcabber/src/compl.h	Sat Jun 11 19:12:25 2005 +0000
@@ -3,16 +3,17 @@
 
 #include <glib.h>
 
-#define COMPL_CMD         1
-#define COMPL_JID         2
-#define COMPL_URLJID      4     // Not implemented yet
-#define COMPL_NAME        8     // Not implemented yet
-#define COMPL_STATUS     16
-#define COMPL_FILENAME   32     // Not implemented yet
-#define COMPL_ROSTER     64
-#define COMPL_BUFFER    128
-#define COMPL_GROUP     256
-#define COMPL_GROUPNAME 512
+#define COMPL_CMD         (1<<0)
+#define COMPL_JID         (1<<2)
+#define COMPL_URLJID      (1<<3)  // Not implemented yet
+#define COMPL_NAME        (1<<4)  // Not implemented yet
+#define COMPL_STATUS      (1<<5)
+#define COMPL_FILENAME    (1<<6)  // Not implemented yet
+#define COMPL_ROSTER      (1<<7)
+#define COMPL_BUFFER      (1<<8)
+#define COMPL_GROUP       (1<<9)
+#define COMPL_GROUPNAME   (1<<10)
+#define COMPL_MULTILINE   (1<<11)
 
 void    compl_add_category_word(guint, const char *command);
 GSList *compl_get_category_list(guint cat_flags);
--- a/mcabber/src/screen.c	Fri Jun 10 19:26:34 2005 +0000
+++ b/mcabber/src/screen.c	Sat Jun 11 19:12:25 2005 +0000
@@ -43,6 +43,8 @@
 static window_entry_t *currentWindow;
 
 static int chatmode;
+static int multimode;
+static char *multiline;
 int update_roster;
 int utf8_mode = 0;
 
@@ -1086,6 +1088,75 @@
   chatmode = enable;
 }
 
+//  scr_get_multimode()
+// Public fonction to get multimode status...
+inline int scr_get_multimode()
+{
+  return multimode;
+}
+
+//  scr_set_multimode()
+// Public fonction to (un)set multimode...
+inline void scr_set_multimode(int enable)
+{
+  if (multiline) {
+    g_free(multiline);
+    multiline = NULL;
+  }
+  if (enable)
+    multimode = TRUE;
+  else
+    multimode = FALSE;
+}
+
+//  scr_get_multiline()
+// Public fonction to get multimode status...
+inline const char *scr_get_multiline()
+{
+  if (multimode && multiline)
+    return multiline;
+  else
+    return "";
+}
+
+//  scr_append_multiline(line)
+// Public function to append a line to the current multi-line message.
+// Skip empty leading lines.
+void scr_append_multiline(const char *line)
+{
+  static int num;
+
+  if (!multimode) {
+    scr_LogPrint("Error: Not in multi-line message mode!");
+    return;
+  }
+  if (multiline) {
+    int len = strlen(multiline)+strlen(line)+2;
+    if (len >= HBB_BLOCKSIZE) {
+      // We don't handle single messages with size > HBB_BLOCKSIZE
+      // (see hbuf)
+      scr_LogPrint("Your multi-line message is too big, this line has "
+                   "not been added.");
+      scr_LogPrint("Please send this part now...");
+      return;
+    }
+    multiline = g_renew(char, multiline, len);
+    strcat(multiline, "\n");
+    strcat(multiline, line);
+    num++;
+  } else {
+    // First message line (we skip leading empty lines)
+    num = 0;
+    if (line[0]) {
+      multiline = g_new(char, strlen(line)+1);
+      strcpy(multiline, line);
+      num++;
+    } else
+      return;
+  }
+  scr_LogPrint("Multi-line mode: line #%d added  [%.25s...", num, line);
+}
+
 //  scr_cmdhisto_addline()
 // Add a line to the inputLine history
 inline void scr_cmdhisto_addline(char *line)
@@ -1371,7 +1442,7 @@
             check_offset(-1);
           }
           break;
-      case KEY_DC:
+      case KEY_DC:// Del
           if (*ptr_inputline)
             strcpy(ptr_inputline, ptr_inputline+1);
           break;
--- a/mcabber/src/screen.h	Fri Jun 10 19:26:34 2005 +0000
+++ b/mcabber/src/screen.h	Sat Jun 11 19:12:25 2005 +0000
@@ -30,6 +30,10 @@
 void scr_ShowBuddyWindow(void);
 void scr_LogPrint(const char *fmt, ...);
 inline void scr_set_chatmode(int enable);
+inline void scr_set_multimode(int enable);
+inline int  scr_get_multimode();
+void scr_append_multiline(const char *line);
+inline const char *scr_get_multiline();
 
 WINDOW *scr_GetInputWindow(void);