1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-22 19:45:54 -04:00

Basic multiwindow chat

This commit is contained in:
James Booth 2012-02-08 22:46:35 +00:00
parent 17a284b24b
commit 8c24a7c475
5 changed files with 34 additions and 11 deletions

18
app.c
View File

@ -87,16 +87,26 @@ static void main_event_loop(void)
// null terminate the input
command[size++] = '\0';
// newline was hit, check if /quit command issued
// deal with input
// /quit command -> exit
if (strcmp(command, "/quit") == 0) {
break;
// /help -> print help to console
} else if (strncmp(command, "/help", 5) == 0) {
cons_help();
inp_clear();
// send message to recipient if chat window
} else {
jabber_send(command);
show_outgoing_msg("me", command);
inp_clear();
if (in_chat()) {
char recipient[100] = "";
get_recipient(recipient);
jabber_send(command, recipient);
show_outgoing_msg("me", command);
inp_clear();
}
}
}

View File

@ -46,14 +46,14 @@ void jabber_process_events(void)
}
void jabber_send(char *msg)
void jabber_send(char *msg, char *recipient)
{
xmpp_stanza_t *reply, *body, *text;
reply = xmpp_stanza_new(_ctx);
xmpp_stanza_set_name(reply, "message");
xmpp_stanza_set_type(reply, "chat");
xmpp_stanza_set_attribute(reply, "to", "boothj5@localhost");
xmpp_stanza_set_attribute(reply, "to", recipient);
body = xmpp_stanza_new(_ctx);
xmpp_stanza_set_name(body, "body");
@ -80,8 +80,7 @@ static int _jabber_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * con
message = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body"));
char *from = xmpp_stanza_get_attribute(stanza, "from");
char *short_from = strtok(from, "@");
show_incomming_msg(short_from, message);
show_incomming_msg(from, message);
return 1;
}

View File

@ -4,6 +4,6 @@
void jabber_connect(char *user, char *passwd);
void jabber_disconnect(void);
void jabber_process_events(void);
void jabber_send(char *msg);
void jabber_send(char *msg, char *recipient);
#endif

View File

@ -60,6 +60,16 @@ void switch_to(int i)
curr_win = i;
}
int in_chat(void)
{
return (curr_win != 0);
}
void get_recipient(char *recipient)
{
strcpy(recipient, wins[curr_win].from);
}
void show_incomming_msg(char *from, char *message)
{
char line[100];
@ -117,7 +127,9 @@ void show_outgoing_msg(char *from, char* message)
char line[100];
sprintf(line, "%s: %s\n", from, message);
// wprintw(chat_win, line);
wprintw(wins[curr_win].win, line);
touchwin(wins[curr_win].win);
wrefresh(wins[curr_win].win);
}
void inp_get_command_str(char *cmd)

View File

@ -5,13 +5,15 @@
#include <ncurses.h>
struct prof_win {
char from[70];
char from[100];
WINDOW *win;
};
void gui_init(void);
void gui_close(void);
void switch_to(int i);
int in_chat(void);
void get_recipient(char *recipient);
void show_incomming_msg(char *from, char *message);
void show_outgoing_msg(char *from, char *message);
void inp_get_command_str(char *cmd);