mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Window per chat and incoming notifications
This commit is contained in:
parent
ab50d324c4
commit
17a284b24b
42
app.c
42
app.c
@ -7,9 +7,6 @@
|
|||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
#include "jabber.h"
|
#include "jabber.h"
|
||||||
|
|
||||||
#define CHAT 0
|
|
||||||
#define CONS 1
|
|
||||||
|
|
||||||
static void main_event_loop(void);
|
static void main_event_loop(void);
|
||||||
|
|
||||||
void start_profanity(void)
|
void start_profanity(void)
|
||||||
@ -34,7 +31,6 @@ void start_profanity(void)
|
|||||||
|
|
||||||
bar_print_message(user);
|
bar_print_message(user);
|
||||||
jabber_connect(user, passwd);
|
jabber_connect(user, passwd);
|
||||||
chat_show();
|
|
||||||
main_event_loop();
|
main_event_loop();
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@ -47,8 +43,6 @@ void start_profanity(void)
|
|||||||
|
|
||||||
static void main_event_loop(void)
|
static void main_event_loop(void)
|
||||||
{
|
{
|
||||||
int showing = CHAT;
|
|
||||||
|
|
||||||
inp_non_block();
|
inp_non_block();
|
||||||
|
|
||||||
while(TRUE) {
|
while(TRUE) {
|
||||||
@ -62,18 +56,30 @@ static void main_event_loop(void)
|
|||||||
|
|
||||||
// handle incoming messages
|
// handle incoming messages
|
||||||
jabber_process_events();
|
jabber_process_events();
|
||||||
if (showing == CHAT) {
|
|
||||||
chat_show();
|
|
||||||
}
|
|
||||||
|
|
||||||
// determine if they changed windows
|
// determine if they changed windows
|
||||||
if (ch == KEY_F(1)) {
|
if (ch == KEY_F(1)) {
|
||||||
cons_show();
|
switch_to(0);
|
||||||
showing = CONS;
|
|
||||||
} else if (ch == KEY_F(2)) {
|
} else if (ch == KEY_F(2)) {
|
||||||
chat_show();
|
switch_to(1);
|
||||||
showing = CHAT;
|
} else if (ch == KEY_F(3)) {
|
||||||
|
switch_to(2);
|
||||||
|
} else if (ch == KEY_F(4)) {
|
||||||
|
switch_to(3);
|
||||||
|
} else if (ch == KEY_F(5)) {
|
||||||
|
switch_to(4);
|
||||||
|
} else if (ch == KEY_F(6)) {
|
||||||
|
switch_to(5);
|
||||||
|
} else if (ch == KEY_F(7)) {
|
||||||
|
switch_to(6);
|
||||||
|
} else if (ch == KEY_F(8)) {
|
||||||
|
switch_to(7);
|
||||||
|
} else if (ch == KEY_F(9)) {
|
||||||
|
switch_to(8);
|
||||||
|
} else if (ch == KEY_F(10)) {
|
||||||
|
switch_to(9);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get another character from the command box
|
// get another character from the command box
|
||||||
inp_poll_char(&ch, command, &size);
|
inp_poll_char(&ch, command, &size);
|
||||||
}
|
}
|
||||||
@ -86,20 +92,10 @@ static void main_event_loop(void)
|
|||||||
break;
|
break;
|
||||||
} else if (strncmp(command, "/help", 5) == 0) {
|
} else if (strncmp(command, "/help", 5) == 0) {
|
||||||
cons_help();
|
cons_help();
|
||||||
if (showing == CONS) {
|
|
||||||
cons_show();
|
|
||||||
}
|
|
||||||
inp_clear();
|
inp_clear();
|
||||||
} else {
|
} else {
|
||||||
if (showing == CONS) {
|
|
||||||
cons_bad_command(command);
|
|
||||||
cons_show();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
jabber_send(command);
|
jabber_send(command);
|
||||||
show_outgoing_msg("me", command);
|
show_outgoing_msg("me", command);
|
||||||
chat_show();
|
|
||||||
}
|
|
||||||
inp_clear();
|
inp_clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
138
windows.c
138
windows.c
@ -1,5 +1,5 @@
|
|||||||
|
#include <string.h>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
|
|
||||||
// common window references
|
// common window references
|
||||||
@ -7,16 +7,15 @@ static WINDOW *title_bar;
|
|||||||
static WINDOW *inp_bar;
|
static WINDOW *inp_bar;
|
||||||
static WINDOW *inp_win;
|
static WINDOW *inp_win;
|
||||||
|
|
||||||
// main windows
|
static struct prof_win wins[10];
|
||||||
static WINDOW *chat_win;
|
static int curr_win = 0;
|
||||||
static WINDOW *cons_win;
|
|
||||||
|
|
||||||
|
// main windows
|
||||||
static void create_title_bar(void);
|
static void create_title_bar(void);
|
||||||
static void create_input_bar(void);
|
static void create_input_bar(void);
|
||||||
static void create_input_window(void);
|
static void create_input_window(void);
|
||||||
|
|
||||||
static void create_chat_window(void);
|
static void create_windows(void);
|
||||||
static void create_console_window(void);
|
|
||||||
|
|
||||||
void gui_init(void)
|
void gui_init(void)
|
||||||
{
|
{
|
||||||
@ -44,8 +43,7 @@ void gui_init(void)
|
|||||||
create_input_window();
|
create_input_window();
|
||||||
wrefresh(inp_win);
|
wrefresh(inp_win);
|
||||||
|
|
||||||
create_chat_window();
|
create_windows();
|
||||||
create_console_window();
|
|
||||||
|
|
||||||
wmove(inp_win, 0, 0);
|
wmove(inp_win, 0, 0);
|
||||||
}
|
}
|
||||||
@ -55,12 +53,63 @@ void gui_close(void)
|
|||||||
endwin();
|
endwin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void switch_to(int i)
|
||||||
|
{
|
||||||
|
touchwin(wins[i].win);
|
||||||
|
wrefresh(wins[i].win);
|
||||||
|
curr_win = i;
|
||||||
|
}
|
||||||
|
|
||||||
void show_incomming_msg(char *from, char *message)
|
void show_incomming_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);
|
// find the chat window for sender
|
||||||
|
int i;
|
||||||
|
for (i = 1; i < 10; i++)
|
||||||
|
if (strcmp(wins[i].from, from) == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// if we didn't find a window
|
||||||
|
if (i == 10) {
|
||||||
|
// find the first unused one
|
||||||
|
for (i = 1; i < 10; i++)
|
||||||
|
if (strcmp(wins[i].from, "") == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// set it up and print the message to it
|
||||||
|
strcpy(wins[i].from, from);
|
||||||
|
wclear(wins[i].win);
|
||||||
|
wprintw(wins[i].win, line);
|
||||||
|
|
||||||
|
// signify active window in status bar
|
||||||
|
mvwprintw(inp_bar, 0, 30 + i, "%d", i+1);
|
||||||
|
touchwin(inp_bar);
|
||||||
|
wrefresh(inp_bar);
|
||||||
|
|
||||||
|
// if its the current window, draw it
|
||||||
|
if (curr_win == i) {
|
||||||
|
touchwin(wins[i].win);
|
||||||
|
wrefresh(wins[i].win);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// otherwise
|
||||||
|
else {
|
||||||
|
// add the line to the senders window
|
||||||
|
wprintw(wins[i].win, line);
|
||||||
|
|
||||||
|
// signify active window in status bar
|
||||||
|
mvwprintw(inp_bar, 0, 30 + i, "%d", i+1);
|
||||||
|
touchwin(inp_bar);
|
||||||
|
wrefresh(inp_bar);
|
||||||
|
|
||||||
|
// if its the current window, draw it
|
||||||
|
if (curr_win == i) {
|
||||||
|
touchwin(wins[i].win);
|
||||||
|
wrefresh(wins[i].win);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void show_outgoing_msg(char *from, char* message)
|
void show_outgoing_msg(char *from, char* message)
|
||||||
@ -68,7 +117,7 @@ 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(chat_win, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
void inp_get_command_str(char *cmd)
|
void inp_get_command_str(char *cmd)
|
||||||
@ -113,7 +162,18 @@ void inp_poll_char(int *ch, char command[], int *size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// else if not error or newline, show it and store it
|
// else if not error or newline, show it and store it
|
||||||
else if (*ch != ERR && *ch != '\n' && *ch != KEY_F(1) && *ch != KEY_F(2)) {
|
else if (*ch != ERR &&
|
||||||
|
*ch != '\n' &&
|
||||||
|
*ch != KEY_F(1) &&
|
||||||
|
*ch != KEY_F(2) &&
|
||||||
|
*ch != KEY_F(3) &&
|
||||||
|
*ch != KEY_F(4) &&
|
||||||
|
*ch != KEY_F(5) &&
|
||||||
|
*ch != KEY_F(6) &&
|
||||||
|
*ch != KEY_F(7) &&
|
||||||
|
*ch != KEY_F(8) &&
|
||||||
|
*ch != KEY_F(9) &&
|
||||||
|
*ch != KEY_F(10)) {
|
||||||
waddch(inp_win, *ch);
|
waddch(inp_win, *ch);
|
||||||
command[(*size)++] = *ch;
|
command[(*size)++] = *ch;
|
||||||
}
|
}
|
||||||
@ -137,27 +197,21 @@ void bar_print_message(char *msg)
|
|||||||
|
|
||||||
void cons_help(void)
|
void cons_help(void)
|
||||||
{
|
{
|
||||||
waddstr(cons_win, "Help\n");
|
waddstr(wins[9].win, "Help\n");
|
||||||
waddstr(cons_win, "----\n");
|
waddstr(wins[0].win, "----\n");
|
||||||
waddstr(cons_win, "/quit - Quits Profanity.\n");
|
waddstr(wins[0].win, "/quit - Quits Profanity.\n");
|
||||||
waddstr(cons_win, "/connect <username@host> - Login to jabber.\n");
|
waddstr(wins[0].win, "/connect <username@host> - Login to jabber.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void cons_bad_command(char *cmd)
|
void cons_bad_command(char *cmd)
|
||||||
{
|
{
|
||||||
wprintw(cons_win, "Unknown command: %s\n", cmd);
|
wprintw(wins[0].win, "Unknown command: %s\n", cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cons_show(void)
|
void cons_show(void)
|
||||||
{
|
{
|
||||||
touchwin(cons_win);
|
touchwin(wins[0].win);
|
||||||
wrefresh(cons_win);
|
wrefresh(wins[0].win);
|
||||||
}
|
|
||||||
|
|
||||||
void chat_show(void)
|
|
||||||
{
|
|
||||||
touchwin(chat_win);
|
|
||||||
wrefresh(chat_win);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void create_title_bar(void)
|
static void create_title_bar(void)
|
||||||
@ -190,25 +244,29 @@ static void create_input_window(void)
|
|||||||
keypad(inp_win, TRUE);
|
keypad(inp_win, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void create_chat_window(void)
|
static void create_windows(void)
|
||||||
{
|
{
|
||||||
int rows, cols;
|
int rows, cols;
|
||||||
getmaxyx(stdscr, rows, cols);
|
getmaxyx(stdscr, rows, cols);
|
||||||
|
|
||||||
chat_win = newwin(rows-3, cols, 1, 0);
|
// create the console window in 0
|
||||||
scrollok(chat_win, TRUE);
|
struct prof_win cons;
|
||||||
|
strcpy(cons.from, "_cons");
|
||||||
|
cons.win = newwin(rows-3, cols, 1, 0);
|
||||||
|
scrollok(cons.win, TRUE);
|
||||||
|
|
||||||
|
waddstr(cons.win, "Welcome to Profanity.\n");
|
||||||
|
touchwin(cons.win);
|
||||||
|
wrefresh(cons.win);
|
||||||
|
wins[0] = cons;
|
||||||
|
|
||||||
|
// create the chat windows
|
||||||
|
int i;
|
||||||
|
for (i = 1; i < 10; i++) {
|
||||||
|
struct prof_win chat;
|
||||||
|
strcpy(chat.from, "");
|
||||||
|
chat.win = newwin(rows-3, cols, 1, 0);
|
||||||
|
scrollok(chat.win, TRUE);
|
||||||
|
wins[i] = chat;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void create_console_window(void)
|
|
||||||
{
|
|
||||||
int rows, cols;
|
|
||||||
getmaxyx(stdscr, rows, cols);
|
|
||||||
|
|
||||||
cons_win = newwin(rows-3, cols, 1, 0);
|
|
||||||
scrollok(cons_win, TRUE);
|
|
||||||
|
|
||||||
waddstr(cons_win, "Welcome to Profanity.\n");
|
|
||||||
touchwin(cons_win);
|
|
||||||
wrefresh(cons_win);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,14 @@
|
|||||||
#include <strophe/strophe.h>
|
#include <strophe/strophe.h>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
|
||||||
|
struct prof_win {
|
||||||
|
char from[70];
|
||||||
|
WINDOW *win;
|
||||||
|
};
|
||||||
|
|
||||||
void gui_init(void);
|
void gui_init(void);
|
||||||
void gui_close(void);
|
void gui_close(void);
|
||||||
|
void switch_to(int i);
|
||||||
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