1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Further tidy up of windows.c

This commit is contained in:
James Booth 2012-11-26 00:57:41 +00:00
parent e131afdb12
commit b2f9e1ad5f
5 changed files with 420 additions and 428 deletions

View File

@ -747,7 +747,7 @@ cmd_execute(const char * const command, const char * const inp)
if (win_current_is_chat()) {
char usage[strlen(cmd->help.usage) + 8];
sprintf(usage, "Usage: %s", cmd->help.usage);
win_show(usage);
win_current_show(usage);
}
return TRUE;
} else {
@ -766,7 +766,7 @@ cmd_execute_default(const char * const inp)
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.");
win_current_show("You are not currently connected.");
} else {
char *recipient = win_current_get_recipient();
jabber_send_groupchat(inp, recipient);
@ -775,7 +775,7 @@ cmd_execute_default(const char * const inp)
} 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.");
win_current_show("You are not currently connected.");
} else {
char *recipient = win_current_get_recipient();
jabber_send(inp, recipient);
@ -1272,7 +1272,7 @@ _cmd_info(gchar **args, struct cmd_help_t help)
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
} else {
win_show_status(usr);
cons_show_status(usr);
}
return TRUE;
@ -1339,7 +1339,7 @@ _cmd_tiny(gchar **args, struct cmd_help_t help)
g_string_append(error, url);
cons_bad_show(error->str);
if (win_current_is_chat()) {
win_bad_show(error->str);
win_current_bad_show(error->str);
}
g_string_free(error, TRUE);
} else if (win_current_is_chat()) {

View File

@ -262,34 +262,34 @@ _handle_edit(const int ch, char *input, int *size)
switch (next_ch)
{
case '1':
win_switch_if_active(0);
ui_switch_win(0);
break;
case '2':
win_switch_if_active(1);
ui_switch_win(1);
break;
case '3':
win_switch_if_active(2);
ui_switch_win(2);
break;
case '4':
win_switch_if_active(3);
ui_switch_win(3);
break;
case '5':
win_switch_if_active(4);
ui_switch_win(4);
break;
case '6':
win_switch_if_active(5);
ui_switch_win(5);
break;
case '7':
win_switch_if_active(6);
ui_switch_win(6);
break;
case '8':
win_switch_if_active(7);
ui_switch_win(7);
break;
case '9':
win_switch_if_active(8);
ui_switch_win(8);
break;
case '0':
win_switch_if_active(9);
ui_switch_win(9);
break;
default:
break;

View File

@ -77,7 +77,7 @@ prof_run(const int disable_tls, char *log_level)
g_timer_start(timer);
}
win_handle_special_keys(&ch);
ui_handle_special_keys(&ch);
if (ch == KEY_RESIZE) {
ui_resize(ch, inp, size);
@ -100,14 +100,14 @@ void
prof_handle_typing(char *from)
{
ui_show_typing(from);
win_page_off();
win_current_page_off();
}
void
prof_handle_incoming_message(char *from, char *message, gboolean priv)
{
win_show_incomming_msg(from, message, NULL, priv);
win_page_off();
ui_show_incoming_msg(from, message, NULL, priv);
win_current_page_off();
if (prefs_get_chlog()) {
char from_cpy[strlen(from) + 1];
@ -123,8 +123,8 @@ void
prof_handle_delayed_message(char *from, char *message, GTimeVal tv_stamp,
gboolean priv)
{
win_show_incomming_msg(from, message, &tv_stamp, priv);
win_page_off();
ui_show_incoming_msg(from, message, &tv_stamp, priv);
win_current_page_off();
if (prefs_get_chlog()) {
char from_cpy[strlen(from) + 1];
@ -157,19 +157,19 @@ prof_handle_subscription(const char *from, jabber_subscr_t type)
cons_show("Received authorization request from %s", from);
log_info("Received authorization request from %s", from);
win_show_system_msg(from, "Authorization request, type '/sub add' to accept or '/sub del' to reject");
win_page_off();
win_current_page_off();
break;
case PRESENCE_SUBSCRIBED:
cons_show("Subscription received from %s", from);
log_info("Subscription received from %s", from);
win_show_system_msg(from, "Subscribed");
win_page_off();
win_current_page_off();
break;
case PRESENCE_UNSUBSCRIBED:
cons_show("%s deleted subscription", from);
log_info("%s deleted subscription", from);
win_show_system_msg(from, "Unsubscribed");
win_page_off();
win_current_page_off();
break;
default:
/* unknown type */
@ -184,7 +184,7 @@ prof_handle_login_success(const char *jid)
cons_show("%s %s", jid, msg);
title_bar_set_status(PRESENCE_ONLINE);
log_info("%s %s", jid, msg);
win_page_off();
win_current_page_off();
status_bar_print_message(jid);
status_bar_refresh();
prefs_add_login(jid);
@ -194,7 +194,7 @@ void
prof_handle_gone(const char * const from)
{
win_show_gone(from);
win_page_off();
win_current_page_off();
}
void
@ -203,8 +203,8 @@ prof_handle_lost_connection(void)
cons_bad_show("Lost connection.");
log_info("Lost connection");
contact_list_clear();
win_disconnected();
win_page_off();
ui_disconnected();
win_current_page_off();
log_info("disconnected");
}
@ -213,7 +213,7 @@ prof_handle_failed_login(void)
{
cons_bad_show("Login failed.");
log_info("Login failed");
win_page_off();
win_current_page_off();
log_info("disconnected");
}
@ -224,12 +224,12 @@ prof_handle_disconnect(const char * const jid)
contact_list_clear();
chat_sessions_clear();
jabber_restart();
win_disconnected();
ui_disconnected();
title_bar_set_status(PRESENCE_OFFLINE);
status_bar_clear_message();
status_bar_refresh();
cons_show("%s logged out successfully.", jid);
win_page_off();
win_current_page_off();
}
void
@ -237,7 +237,7 @@ prof_handle_room_history(const char * const room_jid, const char * const nick,
GTimeVal tv_stamp, const char * const message)
{
win_show_room_history(room_jid, nick, tv_stamp, message);
win_page_off();
win_current_page_off();
}
void
@ -245,14 +245,14 @@ prof_handle_room_message(const char * const room_jid, const char * const nick,
const char * const message)
{
win_show_room_message(room_jid, nick, message);
win_page_off();
win_current_page_off();
}
void
prof_handle_room_subject(const char * const room_jid, const char * const subject)
{
win_show_room_subject(room_jid, subject);
win_page_off();
win_current_page_off();
}
void
@ -260,7 +260,7 @@ prof_handle_room_broadcast(const char *const room_jid,
const char * const message)
{
win_show_room_broadcast(room_jid, message);
win_page_off();
win_current_page_off();
}
void
@ -268,7 +268,7 @@ prof_handle_room_roster_complete(const char * const room)
{
room_set_roster_received(room);
win_show_room_roster(room);
win_page_off();
win_current_page_off();
}
void
@ -280,7 +280,7 @@ prof_handle_room_member_presence(const char * const room,
if (updated) {
win_show_room_member_presence(room, nick, show, status);
win_page_off();
win_current_page_off();
}
}
@ -290,7 +290,7 @@ prof_handle_room_member_online(const char * const room, const char * const nick,
{
room_add_to_roster(room, nick, show, status);
win_show_room_member_online(room, nick, show, status);
win_page_off();
win_current_page_off();
}
void
@ -299,7 +299,7 @@ prof_handle_room_member_offline(const char * const room, const char * const nick
{
room_remove_from_roster(room, nick);
win_show_room_member_offline(room, nick);
win_page_off();
win_current_page_off();
}
void
@ -317,8 +317,8 @@ prof_handle_contact_online(char *contact, char *show, char *status)
PContact result = contact_list_get_contact(contact);
if (p_contact_subscription(result) != NULL) {
if (strcmp(p_contact_subscription(result), "none") != 0) {
win_contact_online(contact, show, status);
win_page_off();
ui_contact_online(contact, show, status);
win_current_page_off();
}
}
}
@ -333,8 +333,8 @@ prof_handle_contact_offline(char *contact, char *show, char *status)
PContact result = contact_list_get_contact(contact);
if (p_contact_subscription(result) != NULL) {
if (strcmp(p_contact_subscription(result), "none") != 0) {
win_contact_offline(contact, show, status);
win_page_off();
ui_contact_offline(contact, show, status);
win_current_page_off();
}
}
}
@ -345,7 +345,7 @@ prof_handle_room_member_nick_change(const char * const room,
const char * const old_nick, const char * const nick)
{
win_show_room_member_nick_change(room, old_nick, nick);
win_page_off();
win_current_page_off();
}
void
@ -353,7 +353,7 @@ prof_handle_room_nick_change(const char * const room,
const char * const nick)
{
win_show_room_nick_change(room, nick);
win_page_off();
win_current_page_off();
}
void
@ -361,7 +361,7 @@ prof_handle_idle(void)
{
jabber_conn_status_t status = jabber_get_connection_status();
if (status == JABBER_CONNECTED) {
win_no_activity();
ui_idle();
}
}
@ -370,7 +370,14 @@ prof_handle_activity(void)
{
jabber_conn_status_t status = jabber_get_connection_status();
if (status == JABBER_CONNECTED) {
win_activity();
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)) {
jabber_send_composing(recipient);
}
}
}
}
@ -422,7 +429,7 @@ _process_input(char *inp)
inp_clear();
contact_list_reset_search_attempts();
win_page_off();
win_current_page_off();
return result;
}

View File

@ -65,6 +65,16 @@ 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);
void ui_idle(void);
void ui_show_incoming_msg(const char * const from, const char * const message,
GTimeVal *tv_stamp, gboolean priv);
void ui_contact_online(const char * const from, const char * const show,
const char * const status);
void ui_contact_offline(const char * const from, const char * const show,
const char * const status);
void ui_disconnected(void);
void ui_handle_special_keys(const int * const ch);
void ui_switch_win(const int i);
// create windows
void create_title_bar(void);
@ -87,26 +97,15 @@ 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_current_show(const char * const msg);
void win_current_bad_show(const char * const msg);
void win_current_page_off(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);
void win_show_error_msg(const char * const from, const char *err_msg);
void win_show_gone(const char * const from);
void win_show_system_msg(const char * const from, const char *message);
void win_show_outgoing_msg(const char * const from, const char * const to,
const char * const message);
void win_handle_special_keys(const int * const ch);
void win_page_off(void);
void win_contact_online(const char * const from, const char * const show,
const char * const status);
void win_contact_offline(const char * const from, const char * const show,
const char * const status);
void win_disconnected(void);
void win_show(const char * const msg);
void win_bad_show(const char * const msg);
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);
@ -121,7 +120,6 @@ void win_show_room_broadcast(const char * const room_jid,
void win_show_room_member_offline(const char * const room, const char * const nick);
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_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);
@ -145,6 +143,7 @@ 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);
void cons_show_status(const char * const contact);
// status bar actions
void status_bar_refresh(void);

View File

@ -93,11 +93,11 @@ static void _win_show_history(WINDOW *win, int win_index,
static gboolean _new_release(char *found_version);
#ifdef HAVE_LIBNOTIFY
static void _win_notify(const char * const message, int timeout,
static void _notify(const char * const message, int timeout,
const char * const category);
static void _win_notify_remind(gint unread);
static void _win_notify_message(const char * const short_from);
static void _win_notify_typing(const char * const from);
static void _notify_remind(gint unread);
static void _notify_message(const char * const short_from);
static void _notify_typing(const char * const from);
#endif
void
@ -197,147 +197,12 @@ ui_show_typing(const char * const from)
#ifdef HAVE_LIBNOTIFY
if (prefs_get_notify_typing())
_win_notify_typing(from);
_notify_typing(from);
#endif
}
void
win_current_close(void)
{
window_free(current);
windows[current_index] = NULL;
// set it as inactive in the status bar
status_bar_inactive(current_index);
// go back to console window
_set_current(0);
status_bar_active(0);
title_bar_title();
dirty = TRUE;
}
int
win_current_is_chat(void)
{
return (current->type == WIN_CHAT);
}
int
win_current_is_groupchat(void)
{
return (current->type == WIN_MUC);
}
int
win_current_is_private(void)
{
return (current->type == WIN_PRIVATE);
}
char *
win_current_get_recipient(void)
{
return strdup(current->from);
}
void
cons_show_wins(void)
{
int i = 0;
int count = 0;
cons_show("");
cons_show("Active windows:");
_win_show_time(console->win);
wprintw(console->win, "1: Console\n");
for (i = 1; i < NUM_WINS; i++) {
if (windows[i] != NULL) {
count++;
}
}
if (count != 0) {
for (i = 1; i < NUM_WINS; i++) {
if (windows[i] != NULL) {
ProfWin *window = windows[i];
_win_show_time(console->win);
switch (window->type)
{
case WIN_CHAT:
wprintw(console->win, "%d: chat %s", i + 1, window->from);
PContact contact = contact_list_get_contact(window->from);
if (contact != NULL) {
if (p_contact_name(contact) != NULL) {
wprintw(console->win, " (%s)", p_contact_name(contact));
}
wprintw(console->win, " - %s", p_contact_presence(contact));
}
if (window->unread > 0) {
wprintw(console->win, ", %d unread", window->unread);
}
break;
case WIN_PRIVATE:
wprintw(console->win, "%d: private %s", i + 1, window->from);
if (window->unread > 0) {
wprintw(console->win, ", %d unread", window->unread);
}
break;
case WIN_MUC:
wprintw(console->win, "%d: room %s", i + 1, window->from);
if (window->unread > 0) {
wprintw(console->win, ", %d unread", window->unread);
}
break;
default:
break;
}
wprintw(console->win, "\n");
}
}
}
}
void
notify_remind(void)
{
#ifdef HAVE_LIBNOTIFY
gint unread = _win_get_unread();
if (unread > 0) {
_win_notify_remind(unread);
}
#endif
}
void
win_activity(void)
{
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)) {
jabber_send_composing(recipient);
}
}
}
void
win_no_activity(void)
ui_idle(void)
{
int i;
@ -360,11 +225,10 @@ win_no_activity(void)
}
}
}
}
void
win_show_incomming_msg(const char * const from, const char * const message,
ui_show_incoming_msg(const char * const from, const char * const message,
GTimeVal *tv_stamp, gboolean priv)
{
win_type_t win_type;
@ -485,10 +349,176 @@ win_show_incomming_msg(const char * const from, const char * const message,
beep();
#ifdef HAVE_LIBNOTIFY
if (prefs_get_notify_message())
_win_notify_message(from);
_notify_message(from);
#endif
}
void
ui_contact_online(const char * const from, const char * const show,
const char * const status)
{
_show_status_string(console->win, from, show, status, "++", "online");
int win_index = _find_prof_win_index(from);
if (win_index != NUM_WINS) {
WINDOW *win = windows[win_index]->win;
_show_status_string(win, from, show, status, "++", "online");
}
if (win_index == current_index)
dirty = TRUE;
}
void
ui_contact_offline(const char * const from, const char * const show,
const char * const status)
{
_show_status_string(console->win, from, show, status, "--", "offline");
int win_index = _find_prof_win_index(from);
if (win_index != NUM_WINS) {
WINDOW *win = windows[win_index]->win;
_show_status_string(win, from, show, status, "--", "offline");
}
if (win_index == current_index)
dirty = TRUE;
}
void
ui_disconnected(void)
{
int i;
// show message in all active chats
for (i = 1; i < NUM_WINS; i++) {
if (windows[i] != NULL) {
WINDOW *win = windows[i]->win;
_win_show_time(win);
wattron(win, COLOUR_ERROR);
wprintw(win, "%s\n", "Lost connection.");
wattroff(win, COLOUR_ERROR);
// if current win, set dirty
if (i == current_index) {
dirty = TRUE;
}
}
}
}
void
ui_handle_special_keys(const int * const ch)
{
_win_handle_switch(ch);
_win_handle_page(ch);
}
void
ui_switch_win(const int i)
{
win_current_page_off();
if (windows[i] != NULL) {
current_index = i;
current = windows[current_index];
win_current_page_off();
current->unread = 0;
if (i == 0) {
title_bar_title();
status_bar_active(0);
} else {
title_bar_set_recipient(current->from);
title_bar_draw();;
status_bar_active(i);
}
}
dirty = TRUE;
}
void
win_current_close(void)
{
window_free(current);
windows[current_index] = NULL;
// set it as inactive in the status bar
status_bar_inactive(current_index);
// go back to console window
_set_current(0);
status_bar_active(0);
title_bar_title();
dirty = TRUE;
}
int
win_current_is_chat(void)
{
return (current->type == WIN_CHAT);
}
int
win_current_is_groupchat(void)
{
return (current->type == WIN_MUC);
}
int
win_current_is_private(void)
{
return (current->type == WIN_PRIVATE);
}
char *
win_current_get_recipient(void)
{
return strdup(current->from);
}
void
win_current_show(const char * const msg)
{
WINDOW *win = current->win;
_win_show_time(win);
wprintw(win, "%s\n", msg);
dirty = TRUE;
}
void
win_current_bad_show(const char * const msg)
{
WINDOW *win = current->win;
_win_show_time(win);
wattron(win, COLOUR_ERROR);
wprintw(win, "%s\n", msg);
wattroff(win, COLOUR_ERROR);
dirty = TRUE;
}
void
win_current_page_off(void)
{
int rows = getmaxy(stdscr);
ProfWin *window = windows[current_index];
window->paged = 0;
int y = getcury(window->win);
int size = rows - 3;
window->y_pos = y - (size - 1);
if (window->y_pos < 0)
window->y_pos = 0;
dirty = TRUE;
}
void
win_show_error_msg(const char * const from, const char *err_msg)
{
@ -510,31 +540,6 @@ win_show_error_msg(const char * const from, const char *err_msg)
}
}
void
win_show_gone(const char * const from)
{
int win_index;
WINDOW *win;
if (from == NULL)
return;
win_index = _find_prof_win_index(from);
// chat window exists
if (win_index < NUM_WINS) {
win = windows[win_index]->win;
_win_show_time(win);
wattron(win, COLOUR_GONE);
wprintw(win, "*%s ", from);
wprintw(win, "has left the conversation.");
wprintw(win, "\n");
wattroff(win, COLOUR_GONE);
if (win_index == current_index) {
dirty = TRUE;
}
}
}
void
win_show_system_msg(const char * const from, const char *message)
{
@ -566,69 +571,31 @@ win_show_system_msg(const char * const from, const char *message)
}
}
#ifdef HAVE_LIBNOTIFY
static void
_win_notify(const char * const message, int timeout,
const char * const category)
void
win_show_gone(const char * const from)
{
gboolean notify_initted = notify_is_initted();
int win_index;
WINDOW *win;
if (!notify_initted) {
notify_initted = notify_init("Profanity");
}
if (from == NULL)
return;
if (notify_initted) {
NotifyNotification *notification;
notification = notify_notification_new("Profanity", message, NULL);
notify_notification_set_timeout(notification, timeout);
notify_notification_set_category(notification, category);
notify_notification_set_urgency(notification, NOTIFY_URGENCY_NORMAL);
GError *error = NULL;
gboolean notify_success = notify_notification_show(notification, &error);
if (!notify_success) {
log_error("Error sending desktop notification:");
log_error(" -> Message : %s", message);
log_error(" -> Error : %s", error->message);
win_index = _find_prof_win_index(from);
// chat window exists
if (win_index < NUM_WINS) {
win = windows[win_index]->win;
_win_show_time(win);
wattron(win, COLOUR_GONE);
wprintw(win, "*%s ", from);
wprintw(win, "has left the conversation.");
wprintw(win, "\n");
wattroff(win, COLOUR_GONE);
if (win_index == current_index) {
dirty = TRUE;
}
} else {
log_error("Libnotify initialisation error.");
}
}
static void
_win_notify_remind(gint unread)
{
char message[20];
if (unread == 1) {
sprintf(message, "1 unread message");
} else {
snprintf(message, sizeof(message), "%d unread messages", unread);
}
_win_notify(message, 5000, "Incoming message");
}
static void
_win_notify_message(const char * const short_from)
{
char message[strlen(short_from) + 1 + 10];
sprintf(message, "%s: message.", short_from);
_win_notify(message, 10000, "Incoming message");
}
static void
_win_notify_typing(const char * const from)
{
char message[strlen(from) + 1 + 11];
sprintf(message, "%s: typing...", from);
_win_notify(message, 10000, "Incoming message");
}
#endif
void
win_show_outgoing_msg(const char * const from, const char * const to,
const char * const message)
@ -677,7 +644,7 @@ win_show_outgoing_msg(const char * const from, const char * const to,
_win_show_user(win, from, 0);
_win_show_message(win, message);
}
win_switch_if_active(win_index);
ui_switch_win(win_index);
}
void
@ -690,7 +657,7 @@ win_join_chat(const char * const room, const char * const nick)
win_index = _new_prof_win(room, WIN_MUC);
}
win_switch_if_active(win_index);
ui_switch_win(win_index);
}
void
@ -890,7 +857,7 @@ win_show_room_message(const char * const room_jid, const char * const nick,
}
#ifdef HAVE_LIBNOTIFY
if (prefs_get_notify_message()) {
_win_notify_message(nick);
_notify_message(nick);
}
#endif
}
@ -941,61 +908,77 @@ win_show_room_broadcast(const char * const room_jid, const char * const message)
}
void
win_show(const char * const msg)
cons_show_wins(void)
{
WINDOW *win = current->win;
_win_show_time(win);
wprintw(win, "%s\n", msg);
int i = 0;
int count = 0;
dirty = TRUE;
}
cons_show("");
cons_show("Active windows:");
_win_show_time(console->win);
wprintw(console->win, "1: Console\n");
void
win_bad_show(const char * const msg)
{
WINDOW *win = current->win;
_win_show_time(win);
wattron(win, COLOUR_ERROR);
wprintw(win, "%s\n", msg);
wattroff(win, COLOUR_ERROR);
dirty = TRUE;
}
void
win_contact_online(const char * const from, const char * const show,
const char * const status)
{
_show_status_string(console->win, from, show, status, "++", "online");
int win_index = _find_prof_win_index(from);
if (win_index != NUM_WINS) {
WINDOW *win = windows[win_index]->win;
_show_status_string(win, from, show, status, "++", "online");
for (i = 1; i < NUM_WINS; i++) {
if (windows[i] != NULL) {
count++;
}
}
if (win_index == current_index)
dirty = TRUE;
}
if (count != 0) {
for (i = 1; i < NUM_WINS; i++) {
if (windows[i] != NULL) {
ProfWin *window = windows[i];
_win_show_time(console->win);
void
win_contact_offline(const char * const from, const char * const show,
const char * const status)
{
_show_status_string(console->win, from, show, status, "--", "offline");
switch (window->type)
{
case WIN_CHAT:
wprintw(console->win, "%d: chat %s", i + 1, window->from);
PContact contact = contact_list_get_contact(window->from);
int win_index = _find_prof_win_index(from);
if (win_index != NUM_WINS) {
WINDOW *win = windows[win_index]->win;
_show_status_string(win, from, show, status, "--", "offline");
if (contact != NULL) {
if (p_contact_name(contact) != NULL) {
wprintw(console->win, " (%s)", p_contact_name(contact));
}
wprintw(console->win, " - %s", p_contact_presence(contact));
}
if (window->unread > 0) {
wprintw(console->win, ", %d unread", window->unread);
}
break;
case WIN_PRIVATE:
wprintw(console->win, "%d: private %s", i + 1, window->from);
if (window->unread > 0) {
wprintw(console->win, ", %d unread", window->unread);
}
break;
case WIN_MUC:
wprintw(console->win, "%d: room %s", i + 1, window->from);
if (window->unread > 0) {
wprintw(console->win, ", %d unread", window->unread);
}
break;
default:
break;
}
wprintw(console->win, "\n");
}
}
}
if (win_index == current_index)
dirty = TRUE;
}
void
win_show_status(const char * const contact)
cons_show_status(const char * const contact)
{
PContact pcontact = contact_list_get_contact(contact);
@ -1006,27 +989,6 @@ win_show_status(const char * const contact)
}
}
void
win_disconnected(void)
{
int i;
// show message in all active chats
for (i = 1; i < NUM_WINS; i++) {
if (windows[i] != NULL) {
WINDOW *win = windows[i]->win;
_win_show_time(win);
wattron(win, COLOUR_ERROR);
wprintw(win, "%s\n", "Lost connection.");
wattroff(win, COLOUR_ERROR);
// if current win, set dirty
if (i == current_index) {
dirty = TRUE;
}
}
}
}
void
cons_prefs(void)
{
@ -1330,43 +1292,6 @@ cons_bad_command(const char * const cmd)
}
}
void
win_handle_special_keys(const int * const ch)
{
_win_handle_switch(ch);
_win_handle_page(ch);
}
void
win_page_off(void)
{
int rows = getmaxy(stdscr);
ProfWin *window = windows[current_index];
window->paged = 0;
int y = getcury(window->win);
int size = rows - 3;
window->y_pos = y - (size - 1);
if (window->y_pos < 0)
window->y_pos = 0;
dirty = TRUE;
}
static void
_create_windows(void)
{
int cols = getmaxx(stdscr);
max_cols = cols;
windows[0] = window_create(CONS_WIN_TITLE, cols, WIN_CONSOLE);
console = windows[0];
current = console;
cons_about();
}
void
cons_about(void)
{
@ -1448,6 +1373,91 @@ cons_check_version(gboolean not_available_msg)
}
}
void
notify_remind(void)
{
#ifdef HAVE_LIBNOTIFY
gint unread = _win_get_unread();
if (unread > 0) {
_notify_remind(unread);
}
#endif
}
#ifdef HAVE_LIBNOTIFY
static void
_notify(const char * const message, int timeout,
const char * const category)
{
gboolean notify_initted = notify_is_initted();
if (!notify_initted) {
notify_initted = notify_init("Profanity");
}
if (notify_initted) {
NotifyNotification *notification;
notification = notify_notification_new("Profanity", message, NULL);
notify_notification_set_timeout(notification, timeout);
notify_notification_set_category(notification, category);
notify_notification_set_urgency(notification, NOTIFY_URGENCY_NORMAL);
GError *error = NULL;
gboolean notify_success = notify_notification_show(notification, &error);
if (!notify_success) {
log_error("Error sending desktop notification:");
log_error(" -> Message : %s", message);
log_error(" -> Error : %s", error->message);
}
} else {
log_error("Libnotify initialisation error.");
}
}
static void
_notify_remind(gint unread)
{
char message[20];
if (unread == 1) {
sprintf(message, "1 unread message");
} else {
snprintf(message, sizeof(message), "%d unread messages", unread);
}
_notify(message, 5000, "Incoming message");
}
static void
_notify_message(const char * const short_from)
{
char message[strlen(short_from) + 1 + 10];
sprintf(message, "%s: message.", short_from);
_notify(message, 10000, "Incoming message");
}
static void
_notify_typing(const char * const from)
{
char message[strlen(from) + 1 + 11];
sprintf(message, "%s: typing...", from);
_notify(message, 10000, "Incoming message");
}
#endif
static void
_create_windows(void)
{
int cols = getmaxx(stdscr);
max_cols = cols;
windows[0] = window_create(CONS_WIN_TITLE, cols, WIN_CONSOLE);
console = windows[0];
current = console;
cons_about();
}
static gboolean
_new_release(char *found_version)
{
@ -1557,30 +1567,6 @@ _new_prof_win(const char * const contact, win_type_t type)
}
}
void
win_switch_if_active(const int i)
{
win_page_off();
if (windows[i] != NULL) {
current_index = i;
current = windows[current_index];
win_page_off();
current->unread = 0;
if (i == 0) {
title_bar_title();
status_bar_active(0);
} else {
title_bar_set_recipient(current->from);
title_bar_draw();;
status_bar_active(i);
}
}
dirty = TRUE;
}
static void
_win_show_time(WINDOW *win)
{
@ -1786,25 +1772,25 @@ static void
_win_handle_switch(const int * const ch)
{
if (*ch == KEY_F(1)) {
win_switch_if_active(0);
ui_switch_win(0);
} else if (*ch == KEY_F(2)) {
win_switch_if_active(1);
ui_switch_win(1);
} else if (*ch == KEY_F(3)) {
win_switch_if_active(2);
ui_switch_win(2);
} else if (*ch == KEY_F(4)) {
win_switch_if_active(3);
ui_switch_win(3);
} else if (*ch == KEY_F(5)) {
win_switch_if_active(4);
ui_switch_win(4);
} else if (*ch == KEY_F(6)) {
win_switch_if_active(5);
ui_switch_win(5);
} else if (*ch == KEY_F(7)) {
win_switch_if_active(6);
ui_switch_win(6);
} else if (*ch == KEY_F(8)) {
win_switch_if_active(7);
ui_switch_win(7);
} else if (*ch == KEY_F(9)) {
win_switch_if_active(8);
ui_switch_win(8);
} else if (*ch == KEY_F(10)) {
win_switch_if_active(9);
ui_switch_win(9);
}
}