Mercurial > hg
comparison mcabber/src/commands.c @ 807:f6cda389db48
Allow messages with a subject (/msay)
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 14 Apr 2006 20:43:11 +0200 |
parents | 5eb701c1bc1f |
children | 80bd7f49075f |
comparison
equal
deleted
inserted
replaced
806:3521e34f722a | 807:f6cda389db48 |
---|---|
267 } | 267 } |
268 | 268 |
269 // send_message(msg) | 269 // send_message(msg) |
270 // Write the message in the buddy's window and send the message on | 270 // Write the message in the buddy's window and send the message on |
271 // the network. | 271 // the network. |
272 static void send_message(const char *msg) | 272 static void send_message(const char *msg, const char *subj) |
273 { | 273 { |
274 const char *jid; | 274 const char *jid; |
275 | 275 |
276 if (!jb_getonline()) { | 276 if (!jb_getonline()) { |
277 scr_LogPrint(LPRINT_NORMAL, "You are not connected."); | 277 scr_LogPrint(LPRINT_NORMAL, "You are not connected."); |
289 return; | 289 return; |
290 } | 290 } |
291 | 291 |
292 if (buddy_gettype(BUDDATA(current_buddy)) != ROSTER_TYPE_ROOM) { | 292 if (buddy_gettype(BUDDATA(current_buddy)) != ROSTER_TYPE_ROOM) { |
293 // local part (UI, logging, etc.) | 293 // local part (UI, logging, etc.) |
294 hk_message_out(jid, NULL, 0, msg); | 294 gchar *hmsg; |
295 if (subj) | |
296 hmsg = g_strdup_printf("[%s]\n%s", subj, msg); | |
297 else | |
298 hmsg = (char*)msg; | |
299 hk_message_out(jid, NULL, 0, hmsg); | |
300 if (hmsg != msg) g_free(hmsg); | |
295 } | 301 } |
296 | 302 |
297 // Network part | 303 // Network part |
298 jb_send_msg(jid, msg, buddy_gettype(BUDDATA(current_buddy)), NULL); | 304 jb_send_msg(jid, msg, buddy_gettype(BUDDATA(current_buddy)), subj); |
299 } | 305 } |
300 | 306 |
301 // process_command(line) | 307 // process_command(line) |
302 // Process a command line. | 308 // Process a command line. |
303 // Return 255 if this is the /quit command, and 0 for the other commands. | 309 // Return 255 if this is the /quit command, and 0 for the other commands. |
694 buddylist_build(); | 700 buddylist_build(); |
695 update_roster = TRUE; | 701 update_roster = TRUE; |
696 if (leave_windowbuddy) scr_ShowBuddyWindow(); | 702 if (leave_windowbuddy) scr_ShowBuddyWindow(); |
697 } | 703 } |
698 | 704 |
699 static int send_message_to(const char *jid, const char *msg) | 705 static int send_message_to(const char *jid, const char *msg, const char *subj) |
700 { | 706 { |
701 char *bare_jid, *rp; | 707 char *bare_jid, *rp; |
708 char *hmsg; | |
702 | 709 |
703 if (!jid || !*jid) { | 710 if (!jid || !*jid) { |
704 scr_LogPrint(LPRINT_NORMAL, "You must specify a Jabber ID."); | 711 scr_LogPrint(LPRINT_NORMAL, "You must specify a Jabber ID."); |
705 return 1; | 712 return 1; |
706 } | 713 } |
727 if (roster_find(bare_jid, jidsearch, ROSTER_TYPE_ROOM)) rp++; | 734 if (roster_find(bare_jid, jidsearch, ROSTER_TYPE_ROOM)) rp++; |
728 else rp = NULL; | 735 else rp = NULL; |
729 } | 736 } |
730 | 737 |
731 // local part (UI, logging, etc.) | 738 // local part (UI, logging, etc.) |
732 hk_message_out(bare_jid, rp, 0, msg); | 739 if (subj) |
740 hmsg = g_strdup_printf("[%s]\n%s", subj, msg); | |
741 else | |
742 hmsg = (char*)msg; | |
743 | |
744 hk_message_out(bare_jid, rp, 0, hmsg); | |
745 if (hmsg != msg) g_free(hmsg); | |
733 | 746 |
734 // Network part | 747 // Network part |
735 jb_send_msg(jid, msg, ROSTER_TYPE_USER, NULL); | 748 jb_send_msg(jid, msg, ROSTER_TYPE_USER, subj); |
736 | 749 |
737 if (rp) g_free(bare_jid); | 750 if (rp) g_free(bare_jid); |
738 return 0; | 751 return 0; |
739 } | 752 } |
740 | 753 |
757 return; | 770 return; |
758 } | 771 } |
759 | 772 |
760 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); | 773 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); |
761 arg = to_utf8(arg); | 774 arg = to_utf8(arg); |
762 send_message(arg); | 775 send_message(arg, NULL); |
763 g_free(arg); | 776 g_free(arg); |
764 } | 777 } |
765 | 778 |
766 static void do_msay(char *arg) | 779 static void do_msay(char *arg) |
767 { | 780 { |
791 } | 804 } |
792 | 805 |
793 if (!strcasecmp(subcmd, "abort")) { | 806 if (!strcasecmp(subcmd, "abort")) { |
794 if (scr_get_multimode()) | 807 if (scr_get_multimode()) |
795 scr_LogPrint(LPRINT_NORMAL, "Leaving multi-line message mode."); | 808 scr_LogPrint(LPRINT_NORMAL, "Leaving multi-line message mode."); |
796 scr_set_multimode(FALSE); | 809 scr_set_multimode(FALSE, NULL); |
797 return; | 810 return; |
798 } else if ((!strcasecmp(subcmd, "begin")) || | 811 } else if ((!strcasecmp(subcmd, "begin")) || |
799 (!strcasecmp(subcmd, "verbatim"))) { | 812 (!strcasecmp(subcmd, "verbatim"))) { |
813 gchar *subj_utf8 = to_utf8(arg); | |
800 if (!strcasecmp(subcmd, "verbatim")) | 814 if (!strcasecmp(subcmd, "verbatim")) |
801 scr_set_multimode(2); | 815 scr_set_multimode(2, subj_utf8); |
802 else | 816 else |
803 scr_set_multimode(1); | 817 scr_set_multimode(1, subj_utf8); |
804 | 818 |
805 scr_LogPrint(LPRINT_NORMAL, "Entered multi-line message mode."); | 819 scr_LogPrint(LPRINT_NORMAL, "Entered multi-line message mode."); |
806 scr_LogPrint(LPRINT_NORMAL, "Select a buddy and use \"/msay send\" " | 820 scr_LogPrint(LPRINT_NORMAL, "Select a buddy and use \"/msay send\" " |
807 "when your message is ready."); | 821 "when your message is ready."); |
822 g_free(subj_utf8); | |
808 return; | 823 return; |
809 } else if (strcasecmp(subcmd, "send") && strcasecmp(subcmd, "send_to")) { | 824 } else if (strcasecmp(subcmd, "send") && strcasecmp(subcmd, "send_to")) { |
810 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); | 825 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
811 return; | 826 return; |
812 } | 827 } |
827 // Let's send to the specified JID. We leave now if there | 842 // Let's send to the specified JID. We leave now if there |
828 // has been an error (so we don't leave multi-line mode). | 843 // has been an error (so we don't leave multi-line mode). |
829 arg = to_utf8(arg); | 844 arg = to_utf8(arg); |
830 msg_utf8 = to_utf8(scr_get_multiline()); | 845 msg_utf8 = to_utf8(scr_get_multiline()); |
831 if (msg_utf8) { | 846 if (msg_utf8) { |
832 err = send_message_to(arg, msg_utf8); | 847 err = send_message_to(arg, msg_utf8, scr_get_multimode_subj()); |
833 g_free(msg_utf8); | 848 g_free(msg_utf8); |
834 } | 849 } |
835 g_free(arg); | 850 g_free(arg); |
836 if (err) | 851 if (err) |
837 return; | 852 return; |
851 } | 866 } |
852 | 867 |
853 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); | 868 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); |
854 msg_utf8 = to_utf8(scr_get_multiline()); | 869 msg_utf8 = to_utf8(scr_get_multiline()); |
855 if (msg_utf8) { | 870 if (msg_utf8) { |
856 send_message(msg_utf8); | 871 send_message(msg_utf8, scr_get_multimode_subj()); |
857 g_free(msg_utf8); | 872 g_free(msg_utf8); |
858 } | 873 } |
859 } | 874 } |
860 scr_set_multimode(FALSE); | 875 scr_set_multimode(FALSE, NULL); |
861 scr_LogPrint(LPRINT_NORMAL, "You have left multi-line message mode."); | 876 scr_LogPrint(LPRINT_NORMAL, "You have left multi-line message mode."); |
862 } | 877 } |
863 | 878 |
864 static void do_say_to(char *arg) | 879 static void do_say_to(char *arg) |
865 { | 880 { |
882 } | 897 } |
883 | 898 |
884 jid = to_utf8(jid); | 899 jid = to_utf8(jid); |
885 msg = to_utf8(msg); | 900 msg = to_utf8(msg); |
886 | 901 |
887 send_message_to(jid, msg); | 902 send_message_to(jid, msg, NULL); |
888 | 903 |
889 g_free(jid); | 904 g_free(jid); |
890 g_free(msg); | 905 g_free(msg); |
891 free_arg_lst(paramlst); | 906 free_arg_lst(paramlst); |
892 } | 907 } |