mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
windows tidy up
This commit is contained in:
parent
4aee534725
commit
e131afdb12
@ -57,7 +57,7 @@ PKG_CHECK_MODULES([DEPS], [openssl glib-2.0 libcurl])
|
||||
PKG_CHECK_MODULES([NOTIFY], [libnotify], [],
|
||||
[AC_MSG_NOTICE([libnotify module not found])])
|
||||
|
||||
AM_CFLAGS="-Wall "
|
||||
AM_CFLAGS="-Wall -Werror"
|
||||
LIBS="$LIBS $DEPS_LIBS $NOTIFY_LIBS"
|
||||
|
||||
AM_CPPFLAGS="$DEPS_CFLAGS $NOTIFY_CFLAGS"
|
||||
|
@ -744,7 +744,7 @@ cmd_execute(const char * const command, const char * const inp)
|
||||
gchar **args = cmd->parser(inp, cmd->min_args, cmd->max_args);
|
||||
if (args == NULL) {
|
||||
cons_show("Usage: %s", cmd->help.usage);
|
||||
if (win_in_chat()) {
|
||||
if (win_current_is_chat()) {
|
||||
char usage[strlen(cmd->help.usage) + 8];
|
||||
sprintf(usage, "Usage: %s", cmd->help.usage);
|
||||
win_show(usage);
|
||||
@ -763,21 +763,21 @@ cmd_execute(const char * const command, const char * const inp)
|
||||
gboolean
|
||||
cmd_execute_default(const char * const inp)
|
||||
{
|
||||
if (win_in_groupchat()) {
|
||||
if (win_current_is_groupchat()) {
|
||||
jabber_conn_status_t status = jabber_get_connection_status();
|
||||
if (status != JABBER_CONNECTED) {
|
||||
win_show("You are not currently connected.");
|
||||
} else {
|
||||
char *recipient = win_get_recipient();
|
||||
char *recipient = win_current_get_recipient();
|
||||
jabber_send_groupchat(inp, recipient);
|
||||
free(recipient);
|
||||
}
|
||||
} else if (win_in_chat() || win_in_private_chat()) {
|
||||
} else if (win_current_is_chat() || win_current_is_private()) {
|
||||
jabber_conn_status_t status = jabber_get_connection_status();
|
||||
if (status != JABBER_CONNECTED) {
|
||||
win_show("You are not currently connected.");
|
||||
} else {
|
||||
char *recipient = win_get_recipient();
|
||||
char *recipient = win_current_get_recipient();
|
||||
jabber_send(inp, recipient);
|
||||
|
||||
if (prefs_get_chlog()) {
|
||||
@ -966,7 +966,7 @@ _cmd_sub(gchar **args, struct cmd_help_t help)
|
||||
if (jid != NULL) {
|
||||
jid = strdup(jid);
|
||||
} else {
|
||||
jid = win_get_recipient();
|
||||
jid = win_current_get_recipient();
|
||||
}
|
||||
|
||||
bare_jid = strtok(jid, "/");
|
||||
@ -1019,7 +1019,7 @@ _cmd_quit(gchar **args, struct cmd_help_t help)
|
||||
static gboolean
|
||||
_cmd_wins(gchar **args, struct cmd_help_t help)
|
||||
{
|
||||
win_show_wins();
|
||||
cons_show_wins();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -1116,7 +1116,7 @@ static gboolean
|
||||
_cmd_theme(gchar **args, struct cmd_help_t help)
|
||||
{
|
||||
if (theme_change(args[0])) {
|
||||
win_load_colours();
|
||||
ui_load_colours();
|
||||
prefs_set_theme(args[0]);
|
||||
cons_show("Loaded theme: %s", args[0]);
|
||||
} else {
|
||||
@ -1150,8 +1150,8 @@ _cmd_who(gchar **args, struct cmd_help_t help)
|
||||
|
||||
// valid arg
|
||||
} else {
|
||||
if (win_in_groupchat()) {
|
||||
char *room = win_get_recipient();
|
||||
if (win_current_is_groupchat()) {
|
||||
char *room = win_current_get_recipient();
|
||||
win_show_room_roster(room);
|
||||
} else {
|
||||
GSList *list = get_contact_list();
|
||||
@ -1317,12 +1317,12 @@ _cmd_nick(gchar **args, struct cmd_help_t help)
|
||||
cons_show("You are not currently connected.");
|
||||
return TRUE;
|
||||
}
|
||||
if (!win_in_groupchat()) {
|
||||
if (!win_current_is_groupchat()) {
|
||||
cons_show("You can only change your nickname in a chat room window.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char *room = win_get_recipient();
|
||||
char *room = win_current_get_recipient();
|
||||
char *nick = args[0];
|
||||
jabber_change_room_nick(room, nick);
|
||||
|
||||
@ -1338,15 +1338,15 @@ _cmd_tiny(gchar **args, struct cmd_help_t help)
|
||||
GString *error = g_string_new("/tiny, badly formed URL: ");
|
||||
g_string_append(error, url);
|
||||
cons_bad_show(error->str);
|
||||
if (win_in_chat()) {
|
||||
if (win_current_is_chat()) {
|
||||
win_bad_show(error->str);
|
||||
}
|
||||
g_string_free(error, TRUE);
|
||||
} else if (win_in_chat()) {
|
||||
} else if (win_current_is_chat()) {
|
||||
char *tiny = tinyurl_get(url);
|
||||
|
||||
if (tiny != NULL) {
|
||||
char *recipient = win_get_recipient();
|
||||
char *recipient = win_current_get_recipient();
|
||||
jabber_send(tiny, recipient);
|
||||
|
||||
if (prefs_get_chlog()) {
|
||||
@ -1370,14 +1370,14 @@ _cmd_tiny(gchar **args, struct cmd_help_t help)
|
||||
static gboolean
|
||||
_cmd_close(gchar **args, struct cmd_help_t help)
|
||||
{
|
||||
if (win_in_groupchat()) {
|
||||
char *room_jid = win_get_recipient();
|
||||
if (win_current_is_groupchat()) {
|
||||
char *room_jid = win_current_get_recipient();
|
||||
jabber_leave_chat_room(room_jid);
|
||||
win_close_win();
|
||||
} else if (win_in_chat() || win_in_private_chat()) {
|
||||
win_current_close();
|
||||
} else if (win_current_is_chat() || win_current_is_private()) {
|
||||
|
||||
if (prefs_get_states()) {
|
||||
char *recipient = win_get_recipient();
|
||||
char *recipient = win_current_get_recipient();
|
||||
|
||||
// send <gone/> chat state before closing
|
||||
if (chat_session_get_recipient_supports(recipient)) {
|
||||
@ -1387,7 +1387,7 @@ _cmd_close(gchar **args, struct cmd_help_t help)
|
||||
}
|
||||
}
|
||||
|
||||
win_close_win();
|
||||
win_current_close();
|
||||
|
||||
} else {
|
||||
cons_show("Cannot close console window.");
|
||||
|
@ -73,17 +73,17 @@ prof_run(const int disable_tls, char *log_level)
|
||||
|
||||
// 0 means to not remind
|
||||
if (remind_period > 0 && elapsed >= remind_period) {
|
||||
win_remind();
|
||||
notify_remind();
|
||||
g_timer_start(timer);
|
||||
}
|
||||
|
||||
win_handle_special_keys(&ch);
|
||||
|
||||
if (ch == KEY_RESIZE) {
|
||||
gui_resize(ch, inp, size);
|
||||
ui_resize(ch, inp, size);
|
||||
}
|
||||
|
||||
gui_refresh();
|
||||
ui_refresh();
|
||||
jabber_process_events();
|
||||
|
||||
inp_get_char(&ch, inp, &size);
|
||||
@ -99,7 +99,7 @@ prof_run(const int disable_tls, char *log_level)
|
||||
void
|
||||
prof_handle_typing(char *from)
|
||||
{
|
||||
win_show_typing(from);
|
||||
ui_show_typing(from);
|
||||
win_page_off();
|
||||
}
|
||||
|
||||
@ -442,7 +442,7 @@ _init(const int disable_tls, char *log_level)
|
||||
chat_log_init();
|
||||
prefs_load();
|
||||
theme_load(prefs_get_theme());
|
||||
gui_init();
|
||||
ui_init();
|
||||
jabber_init(disable_tls);
|
||||
cmd_init();
|
||||
log_info("Initialising contact list");
|
||||
@ -455,7 +455,7 @@ _shutdown(void)
|
||||
{
|
||||
jabber_disconnect();
|
||||
contact_list_clear();
|
||||
gui_close();
|
||||
ui_close();
|
||||
chat_log_close();
|
||||
prefs_close();
|
||||
theme_close();
|
||||
|
29
src/ui.h
29
src/ui.h
@ -58,11 +58,13 @@ struct prof_win {
|
||||
};
|
||||
|
||||
// gui startup and shutdown, resize
|
||||
void gui_init(void);
|
||||
void gui_refresh(void);
|
||||
void gui_close(void);
|
||||
void gui_resize(const int ch, const char * const input,
|
||||
void ui_init(void);
|
||||
void ui_load_colours(void);
|
||||
void ui_refresh(void);
|
||||
void ui_close(void);
|
||||
void ui_resize(const int ch, const char * const input,
|
||||
const int size);
|
||||
void ui_show_typing(const char * const from);
|
||||
|
||||
// create windows
|
||||
void create_title_bar(void);
|
||||
@ -79,11 +81,13 @@ void title_bar_set_recipient(char *from);
|
||||
void title_bar_set_typing(gboolean is_typing);
|
||||
void title_bar_draw(void);
|
||||
|
||||
// main window actions
|
||||
void win_close_win(void);
|
||||
int win_in_chat(void);
|
||||
char *win_get_recipient(void);
|
||||
void win_show_typing(const char * const from);
|
||||
// current window actions
|
||||
void win_current_close(void);
|
||||
int win_current_is_chat(void);
|
||||
int win_current_is_groupchat(void);
|
||||
int win_current_is_private(void);
|
||||
char* win_current_get_recipient(void);
|
||||
|
||||
void win_show_gone(const char * const from);
|
||||
void win_show_incomming_msg(const char * const from, const char * const message,
|
||||
GTimeVal *tv_stamp, gboolean priv);
|
||||
@ -100,14 +104,12 @@ void win_contact_offline(const char * const from, const char * const show,
|
||||
void win_disconnected(void);
|
||||
void win_show(const char * const msg);
|
||||
void win_bad_show(const char * const msg);
|
||||
void win_remind(void);
|
||||
void win_activity(void);
|
||||
void win_no_activity(void);
|
||||
void win_switch_if_active(const int i);
|
||||
|
||||
void win_join_chat(const char * const room, const char * const nick);
|
||||
void win_show_room_roster(const char * const room);
|
||||
int win_in_groupchat(void);
|
||||
void win_show_room_history(const char * const room_jid, const char * const nick,
|
||||
GTimeVal tv_stamp, const char * const message);
|
||||
void win_show_room_message(const char * const room_jid, const char * const nick,
|
||||
@ -120,14 +122,11 @@ void win_show_room_member_offline(const char * const room, const char * const ni
|
||||
void win_show_room_member_online(const char * const room,
|
||||
const char * const nick, const char * const show, const char * const status);
|
||||
void win_show_status(const char * const contact);
|
||||
void win_show_wins(void);
|
||||
int win_in_private_chat(void);
|
||||
void win_show_room_member_nick_change(const char * const room,
|
||||
const char * const old_nick, const char * const nick);
|
||||
void win_show_room_nick_change(const char * const room, const char * const nick);
|
||||
void win_show_room_member_presence(const char * const room,
|
||||
const char * const nick, const char * const show, const char * const status);
|
||||
void win_load_colours(void);
|
||||
|
||||
// console window actions
|
||||
void cons_about(void);
|
||||
@ -145,6 +144,7 @@ void cons_bad_show(const char * const cmd, ...);
|
||||
void cons_highlight_show(const char * const cmd);
|
||||
void cons_show_contacts(GSList * list);
|
||||
void cons_check_version(gboolean not_available_msg);
|
||||
void cons_show_wins(void);
|
||||
|
||||
// status bar actions
|
||||
void status_bar_refresh(void);
|
||||
@ -169,4 +169,5 @@ void inp_get_password(char *passwd);
|
||||
void inp_replace_input(char *input, const char * const new_input, int *size);
|
||||
int inp_get_next_char(void);
|
||||
|
||||
void notify_remind(void);
|
||||
#endif
|
||||
|
126
src/windows.c
126
src/windows.c
@ -101,24 +101,20 @@ static void _win_notify_typing(const char * const from);
|
||||
#endif
|
||||
|
||||
void
|
||||
gui_init(void)
|
||||
ui_init(void)
|
||||
{
|
||||
log_info("Initialising UI");
|
||||
initscr();
|
||||
raw();
|
||||
keypad(stdscr, TRUE);
|
||||
|
||||
#ifdef PLATFORM_CYGWIN
|
||||
mousemask(BUTTON5_PRESSED | BUTTON4_PRESSED, NULL);
|
||||
#else
|
||||
mousemask(BUTTON2_PRESSED | BUTTON4_PRESSED, NULL);
|
||||
#endif
|
||||
mouseinterval(5);
|
||||
|
||||
win_load_colours();
|
||||
|
||||
ui_load_colours();
|
||||
refresh();
|
||||
|
||||
create_title_bar();
|
||||
create_status_bar();
|
||||
status_bar_active(0);
|
||||
@ -129,17 +125,7 @@ gui_init(void)
|
||||
}
|
||||
|
||||
void
|
||||
win_load_colours(void)
|
||||
{
|
||||
if (has_colors()) {
|
||||
use_default_colors();
|
||||
start_color();
|
||||
theme_init_colours();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gui_refresh(void)
|
||||
ui_refresh(void)
|
||||
{
|
||||
title_bar_refresh();
|
||||
status_bar_refresh();
|
||||
@ -153,7 +139,7 @@ gui_refresh(void)
|
||||
}
|
||||
|
||||
void
|
||||
gui_close(void)
|
||||
ui_close(void)
|
||||
{
|
||||
#ifdef HAVE_LIBNOTIFY
|
||||
if (notify_is_initted()) {
|
||||
@ -164,7 +150,7 @@ gui_close(void)
|
||||
}
|
||||
|
||||
void
|
||||
gui_resize(const int ch, const char * const input, const int size)
|
||||
ui_resize(const int ch, const char * const input, const int size)
|
||||
{
|
||||
log_info("Resizing UI");
|
||||
title_bar_resize();
|
||||
@ -175,7 +161,48 @@ gui_resize(const int ch, const char * const input, const int size)
|
||||
}
|
||||
|
||||
void
|
||||
win_close_win(void)
|
||||
ui_load_colours(void)
|
||||
{
|
||||
if (has_colors()) {
|
||||
use_default_colors();
|
||||
start_color();
|
||||
theme_init_colours();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ui_show_typing(const char * const from)
|
||||
{
|
||||
int win_index = _find_prof_win_index(from);
|
||||
|
||||
if (prefs_get_intype()) {
|
||||
// no chat window for user
|
||||
if (win_index == NUM_WINS) {
|
||||
_cons_show_typing(from);
|
||||
|
||||
// have chat window but not currently in it
|
||||
} else if (win_index != current_index) {
|
||||
_cons_show_typing(from);
|
||||
dirty = TRUE;
|
||||
|
||||
// in chat window with user
|
||||
} else {
|
||||
title_bar_set_typing(TRUE);
|
||||
title_bar_draw();
|
||||
|
||||
status_bar_active(win_index);
|
||||
dirty = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBNOTIFY
|
||||
if (prefs_get_notify_typing())
|
||||
_win_notify_typing(from);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
win_current_close(void)
|
||||
{
|
||||
window_free(current);
|
||||
windows[current_index] = NULL;
|
||||
@ -192,25 +219,31 @@ win_close_win(void)
|
||||
}
|
||||
|
||||
int
|
||||
win_in_chat(void)
|
||||
win_current_is_chat(void)
|
||||
{
|
||||
return (current->type == WIN_CHAT);
|
||||
}
|
||||
|
||||
int
|
||||
win_in_groupchat(void)
|
||||
win_current_is_groupchat(void)
|
||||
{
|
||||
return (current->type == WIN_MUC);
|
||||
}
|
||||
|
||||
int
|
||||
win_in_private_chat(void)
|
||||
win_current_is_private(void)
|
||||
{
|
||||
return (current->type == WIN_PRIVATE);
|
||||
}
|
||||
|
||||
char *
|
||||
win_current_get_recipient(void)
|
||||
{
|
||||
return strdup(current->from);
|
||||
}
|
||||
|
||||
void
|
||||
win_show_wins(void)
|
||||
cons_show_wins(void)
|
||||
{
|
||||
int i = 0;
|
||||
int count = 0;
|
||||
@ -279,47 +312,8 @@ win_show_wins(void)
|
||||
}
|
||||
}
|
||||
|
||||
char *
|
||||
win_get_recipient(void)
|
||||
{
|
||||
char *recipient = (char *) malloc(sizeof(char) * (strlen(current->from) + 1));
|
||||
strcpy(recipient, current->from);
|
||||
return recipient;
|
||||
}
|
||||
|
||||
void
|
||||
win_show_typing(const char * const from)
|
||||
{
|
||||
int win_index = _find_prof_win_index(from);
|
||||
|
||||
if (prefs_get_intype()) {
|
||||
// no chat window for user
|
||||
if (win_index == NUM_WINS) {
|
||||
_cons_show_typing(from);
|
||||
|
||||
// have chat window but not currently in it
|
||||
} else if (win_index != current_index) {
|
||||
_cons_show_typing(from);
|
||||
dirty = TRUE;
|
||||
|
||||
// in chat window with user
|
||||
} else {
|
||||
title_bar_set_typing(TRUE);
|
||||
title_bar_draw();
|
||||
|
||||
status_bar_active(win_index);
|
||||
dirty = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBNOTIFY
|
||||
if (prefs_get_notify_typing())
|
||||
_win_notify_typing(from);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
win_remind(void)
|
||||
notify_remind(void)
|
||||
{
|
||||
#ifdef HAVE_LIBNOTIFY
|
||||
gint unread = _win_get_unread();
|
||||
@ -332,8 +326,8 @@ win_remind(void)
|
||||
void
|
||||
win_activity(void)
|
||||
{
|
||||
if (win_in_chat()) {
|
||||
char *recipient = win_get_recipient();
|
||||
if (win_current_is_chat()) {
|
||||
char *recipient = win_current_get_recipient();
|
||||
chat_session_set_composing(recipient);
|
||||
if (!chat_session_get_sent(recipient) ||
|
||||
chat_session_is_paused(recipient)) {
|
||||
|
Loading…
Reference in New Issue
Block a user