# HG changeset patch # User Mikael Berthe # Date 1145040191 -7200 # Node ID f6cda389db48caf3955dd0e187e2bfceaff41131 # Parent 3521e34f722a46b9ca0d08c4108d6ff0497bd239 Allow messages with a subject (/msay) diff -r 3521e34f722a -r f6cda389db48 mcabber/src/commands.c --- a/mcabber/src/commands.c Fri Apr 14 20:38:35 2006 +0200 +++ b/mcabber/src/commands.c Fri Apr 14 20:43:11 2006 +0200 @@ -269,7 +269,7 @@ // send_message(msg) // Write the message in the buddy's window and send the message on // the network. -static void send_message(const char *msg) +static void send_message(const char *msg, const char *subj) { const char *jid; @@ -291,11 +291,17 @@ if (buddy_gettype(BUDDATA(current_buddy)) != ROSTER_TYPE_ROOM) { // local part (UI, logging, etc.) - hk_message_out(jid, NULL, 0, msg); + gchar *hmsg; + if (subj) + hmsg = g_strdup_printf("[%s]\n%s", subj, msg); + else + hmsg = (char*)msg; + hk_message_out(jid, NULL, 0, hmsg); + if (hmsg != msg) g_free(hmsg); } // Network part - jb_send_msg(jid, msg, buddy_gettype(BUDDATA(current_buddy)), NULL); + jb_send_msg(jid, msg, buddy_gettype(BUDDATA(current_buddy)), subj); } // process_command(line) @@ -696,9 +702,10 @@ if (leave_windowbuddy) scr_ShowBuddyWindow(); } -static int send_message_to(const char *jid, const char *msg) +static int send_message_to(const char *jid, const char *msg, const char *subj) { char *bare_jid, *rp; + char *hmsg; if (!jid || !*jid) { scr_LogPrint(LPRINT_NORMAL, "You must specify a Jabber ID."); @@ -729,10 +736,16 @@ } // local part (UI, logging, etc.) - hk_message_out(bare_jid, rp, 0, msg); + if (subj) + hmsg = g_strdup_printf("[%s]\n%s", subj, msg); + else + hmsg = (char*)msg; + + hk_message_out(bare_jid, rp, 0, hmsg); + if (hmsg != msg) g_free(hmsg); // Network part - jb_send_msg(jid, msg, ROSTER_TYPE_USER, NULL); + jb_send_msg(jid, msg, ROSTER_TYPE_USER, subj); if (rp) g_free(bare_jid); return 0; @@ -759,7 +772,7 @@ buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); arg = to_utf8(arg); - send_message(arg); + send_message(arg, NULL); g_free(arg); } @@ -793,18 +806,20 @@ if (!strcasecmp(subcmd, "abort")) { if (scr_get_multimode()) scr_LogPrint(LPRINT_NORMAL, "Leaving multi-line message mode."); - scr_set_multimode(FALSE); + scr_set_multimode(FALSE, NULL); return; } else if ((!strcasecmp(subcmd, "begin")) || (!strcasecmp(subcmd, "verbatim"))) { + gchar *subj_utf8 = to_utf8(arg); if (!strcasecmp(subcmd, "verbatim")) - scr_set_multimode(2); + scr_set_multimode(2, subj_utf8); else - scr_set_multimode(1); + scr_set_multimode(1, subj_utf8); scr_LogPrint(LPRINT_NORMAL, "Entered multi-line message mode."); scr_LogPrint(LPRINT_NORMAL, "Select a buddy and use \"/msay send\" " "when your message is ready."); + g_free(subj_utf8); return; } else if (strcasecmp(subcmd, "send") && strcasecmp(subcmd, "send_to")) { scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); @@ -829,7 +844,7 @@ arg = to_utf8(arg); msg_utf8 = to_utf8(scr_get_multiline()); if (msg_utf8) { - err = send_message_to(arg, msg_utf8); + err = send_message_to(arg, msg_utf8, scr_get_multimode_subj()); g_free(msg_utf8); } g_free(arg); @@ -853,11 +868,11 @@ buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); msg_utf8 = to_utf8(scr_get_multiline()); if (msg_utf8) { - send_message(msg_utf8); + send_message(msg_utf8, scr_get_multimode_subj()); g_free(msg_utf8); } } - scr_set_multimode(FALSE); + scr_set_multimode(FALSE, NULL); scr_LogPrint(LPRINT_NORMAL, "You have left multi-line message mode."); } @@ -884,7 +899,7 @@ jid = to_utf8(jid); msg = to_utf8(msg); - send_message_to(jid, msg); + send_message_to(jid, msg, NULL); g_free(jid); g_free(msg); diff -r 3521e34f722a -r f6cda389db48 mcabber/src/screen.c --- a/mcabber/src/screen.c Fri Apr 14 20:38:35 2006 +0200 +++ b/mcabber/src/screen.c Fri Apr 14 20:43:11 2006 +0200 @@ -78,7 +78,7 @@ static int roster_hidden; static int chatmode; static int multimode; -static char *multiline; +static char *multiline, *multimode_subj; int update_roster; int utf8_mode = 0; static bool Autoaway; @@ -1560,23 +1560,36 @@ // Public function to (un)set multimode... // Convention: // 0 = disabled / 1 = multimode / 2 = multimode verbatim (commands disabled) -inline void scr_set_multimode(int enable) +inline void scr_set_multimode(int enable, char *subject) { - if (multiline) { - g_free(multiline); - multiline = NULL; - } + g_free(multiline); + multiline = NULL; + + g_free(multimode_subj); + if (enable && subject) + multimode_subj = g_strdup(subject); + else + multimode_subj = NULL; + multimode = enable; } // scr_get_multiline() // Public function to get the current multi-line. -inline const char *scr_get_multiline() +inline const char *scr_get_multiline(void) { if (multimode && multiline) return multiline; - else - return NULL; + return NULL; +} + +// scr_get_multimode_subj() +// Public function to get the multi-line subject, if any. +inline const char *scr_get_multimode_subj(void) +{ + if (multimode) + return multimode_subj; + return NULL; } // scr_append_multiline(line) diff -r 3521e34f722a -r f6cda389db48 mcabber/src/screen.h --- a/mcabber/src/screen.h Fri Apr 14 20:38:35 2006 +0200 +++ b/mcabber/src/screen.h Fri Apr 14 20:43:11 2006 +0200 @@ -66,11 +66,12 @@ void scr_ShowBuddyWindow(void); bool scr_BuddyBufferExists(const char *jid); inline void scr_set_chatmode(int enable); -inline void scr_set_multimode(int enable); +inline void scr_set_multimode(int enable, char *subject); inline int scr_get_multimode(void); void scr_setmsgflag_if_needed(const char *jid); void scr_append_multiline(const char *line); inline const char *scr_get_multiline(void); +inline const char *scr_get_multimode_subj(void); inline void scr_Beep(void);