mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Basic multiwindow chat
This commit is contained in:
parent
17a284b24b
commit
8c24a7c475
18
app.c
18
app.c
@ -87,16 +87,26 @@ static void main_event_loop(void)
|
|||||||
// null terminate the input
|
// null terminate the input
|
||||||
command[size++] = '\0';
|
command[size++] = '\0';
|
||||||
|
|
||||||
// newline was hit, check if /quit command issued
|
// deal with input
|
||||||
|
|
||||||
|
// /quit command -> exit
|
||||||
if (strcmp(command, "/quit") == 0) {
|
if (strcmp(command, "/quit") == 0) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// /help -> print help to console
|
||||||
} else if (strncmp(command, "/help", 5) == 0) {
|
} else if (strncmp(command, "/help", 5) == 0) {
|
||||||
cons_help();
|
cons_help();
|
||||||
inp_clear();
|
inp_clear();
|
||||||
|
|
||||||
|
// send message to recipient if chat window
|
||||||
} else {
|
} else {
|
||||||
jabber_send(command);
|
if (in_chat()) {
|
||||||
show_outgoing_msg("me", command);
|
char recipient[100] = "";
|
||||||
inp_clear();
|
get_recipient(recipient);
|
||||||
|
jabber_send(command, recipient);
|
||||||
|
show_outgoing_msg("me", command);
|
||||||
|
inp_clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
jabber.c
7
jabber.c
@ -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;
|
xmpp_stanza_t *reply, *body, *text;
|
||||||
|
|
||||||
reply = xmpp_stanza_new(_ctx);
|
reply = xmpp_stanza_new(_ctx);
|
||||||
xmpp_stanza_set_name(reply, "message");
|
xmpp_stanza_set_name(reply, "message");
|
||||||
xmpp_stanza_set_type(reply, "chat");
|
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);
|
body = xmpp_stanza_new(_ctx);
|
||||||
xmpp_stanza_set_name(body, "body");
|
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"));
|
message = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body"));
|
||||||
|
|
||||||
char *from = xmpp_stanza_get_attribute(stanza, "from");
|
char *from = xmpp_stanza_get_attribute(stanza, "from");
|
||||||
char *short_from = strtok(from, "@");
|
show_incomming_msg(from, message);
|
||||||
show_incomming_msg(short_from, message);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
2
jabber.h
2
jabber.h
@ -4,6 +4,6 @@
|
|||||||
void jabber_connect(char *user, char *passwd);
|
void jabber_connect(char *user, char *passwd);
|
||||||
void jabber_disconnect(void);
|
void jabber_disconnect(void);
|
||||||
void jabber_process_events(void);
|
void jabber_process_events(void);
|
||||||
void jabber_send(char *msg);
|
void jabber_send(char *msg, char *recipient);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
14
windows.c
14
windows.c
@ -60,6 +60,16 @@ void switch_to(int i)
|
|||||||
curr_win = 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)
|
void show_incomming_msg(char *from, char *message)
|
||||||
{
|
{
|
||||||
char line[100];
|
char line[100];
|
||||||
@ -117,7 +127,9 @@ void show_outgoing_msg(char *from, char* message)
|
|||||||
char line[100];
|
char line[100];
|
||||||
sprintf(line, "%s: %s\n", from, message);
|
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)
|
void inp_get_command_str(char *cmd)
|
||||||
|
@ -5,13 +5,15 @@
|
|||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
|
||||||
struct prof_win {
|
struct prof_win {
|
||||||
char from[70];
|
char from[100];
|
||||||
WINDOW *win;
|
WINDOW *win;
|
||||||
};
|
};
|
||||||
|
|
||||||
void gui_init(void);
|
void gui_init(void);
|
||||||
void gui_close(void);
|
void gui_close(void);
|
||||||
void switch_to(int i);
|
void switch_to(int i);
|
||||||
|
int in_chat(void);
|
||||||
|
void get_recipient(char *recipient);
|
||||||
void show_incomming_msg(char *from, char *message);
|
void show_incomming_msg(char *from, char *message);
|
||||||
void show_outgoing_msg(char *from, char *message);
|
void show_outgoing_msg(char *from, char *message);
|
||||||
void inp_get_command_str(char *cmd);
|
void inp_get_command_str(char *cmd);
|
||||||
|
Loading…
Reference in New Issue
Block a user