[/trunk] Changeset 63 by mikael
* Add commands.[ch] files, to deal with command lines.
Move sendmessage() to commands.c
* Update Makefile accordingly.
* Create a scr_WriteMessage() function, layer between UI and the
scr_WriteIncomingMessage() / scr_WriteOutgoingMessage().
(The last one is a new function)
--- a/mcabber/src/Makefile Wed Apr 06 09:49:39 2005 +0000
+++ b/mcabber/src/Makefile Wed Apr 06 10:07:59 2005 +0000
@@ -50,6 +50,7 @@
SOURCES = \
main.c \
+ commands.c \
screen.c \
utils.c \
buddies.c \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mcabber/src/commands.c Wed Apr 06 10:07:59 2005 +0000
@@ -0,0 +1,67 @@
+/*
+ * commands.c -- user commands handling
+ *
+ * Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include "commands.h"
+#include "jabglue.h"
+#include "screen.h"
+#include "utils.h"
+#include "buddies.h"
+#include "utf8.h"
+
+
+// send_message(msg)
+// Write the message in the buddy's window and send the message on
+// the network.
+void send_message(char *msg)
+{
+ char *buffer;
+ buddy_entry_t *tmp = bud_SelectedInfo();
+
+ // UI part
+ scr_WriteOutgoingMessage(tmp->jid, msg);
+
+ // Network part
+ buffer = utf8_encode(msg);
+ jb_send_msg(tmp->jid, buffer);
+ free(buffer);
+}
+
+// process_line(line)
+// Process a command/message line.
+// If this isn't a command, this is a message and it is sent to the
+// currently selected buddy.
+int process_line(char *line)
+{
+ if (*line != '/') {
+ send_message(line);
+ return 0;
+ }
+ if (!strcasecmp(line, "/quit")) {
+ return 255;
+ }
+ // Commands handling
+ // TODO
+ // say, send_raw...
+
+ scr_LogPrint("Unrecognised command, sorry.");
+ return 0;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mcabber/src/commands.h Wed Apr 06 10:07:59 2005 +0000
@@ -0,0 +1,7 @@
+#ifndef __COMMANDS_H__
+#define __COMMANDS_H__ 1
+
+int process_line(char *line);
+
+#endif /* __COMMANDS_H__ */
+
--- a/mcabber/src/screen.c Wed Apr 06 09:49:39 2005 +0000
+++ b/mcabber/src/screen.c Wed Apr 06 10:07:59 2005 +0000
@@ -9,10 +9,12 @@
#include "screen.h"
#include "utils.h"
+#include "commands.h"
#include "buddies.h"
#include "parsecfg.h"
#include "lang.h"
#include "list.h"
+#include "utf8.h"
#define window_entry(n) list_entry(n, window_entry_t, list)
@@ -383,36 +385,53 @@
return;
}
-void scr_WriteIncomingMessage(char *jidfrom, char *text)
+void scr_WriteMessage(char *jid, char *text, char *prefix)
{
char **submsgs;
int n, i;
- char *buffer = (char *) malloc(5 + strlen(text));
+ char *buffer = (char *) malloc(strlen(text) + strlen(text));
- sprintf(buffer, "<== %s", utf8_decode(text));
+ if (prefix)
+ strcpy(buffer, prefix);
+ else
+ *buffer = 0;
+
+ strcat(buffer, text);
submsgs =
ut_SplitMessage(buffer, &n, maxX - scr_WindowHeight(rosterWnd) - 14);
for (i = 0; i < n; i++) {
if (i == 0)
- scr_WriteInWindow(jidfrom, submsgs[i], TRUE, FALSE);
+ scr_WriteInWindow(jid, submsgs[i], TRUE, FALSE);
else
- scr_WriteInWindow(jidfrom, submsgs[i], FALSE, FALSE);
+ scr_WriteInWindow(jid, submsgs[i], FALSE, FALSE);
}
for (i = 0; i < n; i++)
free(submsgs[i]);
-
free(submsgs);
free(buffer);
top_panel(inputPanel);
- //wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine);
+}
+
+void scr_WriteIncomingMessage(char *jidfrom, char *text)
+{
+ char *buffer = utf8_decode(text);
+ scr_WriteMessage(jidfrom, buffer, "<== ");
+ free(buffer);
update_panels();
doupdate();
}
+void scr_WriteOutgoingMessage(char *jidto, char *text)
+{
+ scr_ShowWindow(jidto);
+ scr_WriteMessage(jidto, text, "--> ");
+ //refresh(); // XXX ?
+}
+
int scr_Getch(void)
{
int ch;
@@ -474,65 +493,6 @@
return FALSE;
}
-// send_message(msg)
-// Write the message in the buddy's window and send the message on
-// the network.
-void send_message(char *msg)
-{
- char **submsgs;
- char *buffer = (char *) calloc(1, 24+strlen(msg));
- char *buffer2 = (char *) calloc(1, 1024);
- int n, i;
- buddy_entry_t *tmp = bud_SelectedInfo();
-
- scr_ShowWindow(tmp->jid);
-
- sprintf(buffer, "--> %s", msg);
-
- submsgs =
- ut_SplitMessage(buffer, &n,
- maxX - scr_WindowHeight(rosterWnd) - 14);
- for (i = 0; i < n; i++) {
- if (i == 0)
- scr_WriteInWindow(tmp->jid, submsgs[i], TRUE, TRUE);
- else
- scr_WriteInWindow(tmp->jid, submsgs[i], FALSE, TRUE);
- }
-
- for (i = 0; i < n; i++)
- free(submsgs[i]);
- free(submsgs);
-
- refresh();
- sprintf(buffer2, "%s@%s/%s", cfg_read("username"),
- cfg_read("server"), cfg_read("resource"));
- jb_send_msg(tmp->jid, utf8_encode(msg));
- free(buffer);
- free(buffer2);
-
- top_panel(inputPanel);
-}
-
-// process_line(line)
-// Process the line *line. Note: if this isn't a command, this is a message
-// and it is sent to the current buddy.
-int process_line(char *line)
-{
- if (*line != '/') {
- send_message(line);
- return 0;
- }
- if (!strcasecmp(line, "/quit")) {
- return 255;
- }
- // Commands handling
- // TODO
- // say, send_raw...
-
- scr_LogPrint("Unrecognised command, sorry.");
- return 0;
-}
-
// check_offset(int direction)
// Check inputline_offset value, and make sure the cursor is inside the
// screen.
--- a/mcabber/src/screen.h Wed Apr 06 09:49:39 2005 +0000
+++ b/mcabber/src/screen.h Wed Apr 06 10:07:59 2005 +0000
@@ -21,9 +21,10 @@
void scr_InitCurses(void);
void scr_DrawMainWindow(void);
void scr_TerminateCurses(void);
-void scr_WriteInWindow(char *nombreVentana, char *texto, int TimeStamp,
- int force_show);
+// void scr_WriteInWindow(char *nombreVentana, char *texto, int TimeStamp,
+// int force_show);
void scr_WriteIncomingMessage(char *jidfrom, char *text);
+void scr_WriteOutgoingMessage(char *jidto, char *text);
void scr_RoolWindow(void);
void scr_ShowBuddyWindow(void);
void scr_LogPrint(const char *fmt, ...);