mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Merge branch 'ui'
Conflicts: src/ui/windows.c
This commit is contained in:
commit
e418705b7f
@ -8,8 +8,9 @@ profanity_SOURCES = src/contact.c src/contact.h src/log.c src/common.c \
|
||||
src/xmpp/iq.c src/xmpp/message.c src/xmpp/presence.c src/xmpp/stanza.c \
|
||||
src/xmpp/stanza.h src/xmpp/message.h src/xmpp/iq.h src/xmpp/presence.h \
|
||||
src/xmpp/capabilities.h src/xmpp/connection.h \
|
||||
src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/windows.c \
|
||||
src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/core.c \
|
||||
src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \
|
||||
src/ui/console.c src/ui/notifier.c src/ui/notifier.h \
|
||||
src/command/command.h src/command/command.c src/command/history.c \
|
||||
src/command/history.h src/command/parser.c \
|
||||
src/command/parser.h \
|
||||
|
@ -499,11 +499,14 @@ static struct cmd_t setting_commands[] =
|
||||
" : use 0 to disable.",
|
||||
"typing : Notifications when contacts are typing.",
|
||||
" : on|off",
|
||||
"invite : Notifications for chat room invites.",
|
||||
" : on|off",
|
||||
"",
|
||||
"Example : /notify message on (enable message notifications)",
|
||||
"Example : /notify remind 10 (remind every 10 seconds)",
|
||||
"Example : /notify remind 0 (switch off reminders)",
|
||||
"Example : /notify typing on (enable typing notifications)",
|
||||
"Example : /notify invite on (enable chat room invite notifications)",
|
||||
NULL } } },
|
||||
|
||||
{ "/flash",
|
||||
@ -783,6 +786,7 @@ cmd_init(void)
|
||||
autocomplete_add(notify_ac, strdup("message"));
|
||||
autocomplete_add(notify_ac, strdup("typing"));
|
||||
autocomplete_add(notify_ac, strdup("remind"));
|
||||
autocomplete_add(notify_ac, strdup("invite"));
|
||||
autocomplete_add(notify_ac, strdup("status"));
|
||||
|
||||
sub_ac = autocomplete_new();
|
||||
@ -917,8 +921,8 @@ cmd_reset_autocomplete()
|
||||
autocomplete_reset(notify_ac);
|
||||
autocomplete_reset(sub_ac);
|
||||
|
||||
if (win_current_is_groupchat()) {
|
||||
Autocomplete nick_ac = muc_get_roster_ac(win_current_get_recipient());
|
||||
if (ui_current_win_type() == WIN_MUC) {
|
||||
Autocomplete nick_ac = muc_get_roster_ac(ui_current_recipient());
|
||||
if (nick_ac != NULL) {
|
||||
autocomplete_reset(nick_ac);
|
||||
}
|
||||
@ -989,10 +993,10 @@ 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_current_is_chat()) {
|
||||
if (ui_current_win_type() == WIN_CHAT) {
|
||||
char usage[strlen(cmd->help.usage) + 8];
|
||||
sprintf(usage, "Usage: %s", cmd->help.usage);
|
||||
win_current_show(usage);
|
||||
ui_current_print_line(usage);
|
||||
}
|
||||
return TRUE;
|
||||
} else {
|
||||
@ -1008,35 +1012,54 @@ cmd_execute(const char * const command, const char * const inp)
|
||||
gboolean
|
||||
cmd_execute_default(const char * const inp)
|
||||
{
|
||||
if (win_current_is_groupchat()) {
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
jabber_conn_status_t status = jabber_get_connection_status();
|
||||
char *recipient = ui_current_recipient();
|
||||
|
||||
switch (win_type)
|
||||
{
|
||||
case WIN_MUC:
|
||||
if (status != JABBER_CONNECTED) {
|
||||
win_current_show("You are not currently connected.");
|
||||
ui_current_print_line("You are not currently connected.");
|
||||
} else {
|
||||
char *recipient = win_current_get_recipient();
|
||||
message_send_groupchat(inp, recipient);
|
||||
free(recipient);
|
||||
}
|
||||
} else if (win_current_is_chat() || win_current_is_private()) {
|
||||
jabber_conn_status_t status = jabber_get_connection_status();
|
||||
break;
|
||||
|
||||
case WIN_CHAT:
|
||||
if (status != JABBER_CONNECTED) {
|
||||
win_current_show("You are not currently connected.");
|
||||
ui_current_print_line("You are not currently connected.");
|
||||
} else {
|
||||
char *recipient = win_current_get_recipient();
|
||||
message_send(inp, recipient);
|
||||
|
||||
if (win_current_is_chat() && prefs_get_boolean(PREF_CHLOG)) {
|
||||
if (prefs_get_boolean(PREF_CHLOG)) {
|
||||
const char *jid = jabber_get_jid();
|
||||
Jid *jidp = jid_create(jid);
|
||||
chat_log_chat(jidp->barejid, recipient, inp, PROF_OUT_LOG, NULL);
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
|
||||
win_show_outgoing_msg("me", recipient, inp);
|
||||
ui_outgoing_msg("me", recipient, inp);
|
||||
free(recipient);
|
||||
}
|
||||
break;
|
||||
|
||||
case WIN_PRIVATE:
|
||||
if (status != JABBER_CONNECTED) {
|
||||
ui_current_print_line("You are not currently connected.");
|
||||
} else {
|
||||
cons_bad_command(inp);
|
||||
message_send(inp, recipient);
|
||||
ui_outgoing_msg("me", recipient, inp);
|
||||
free(recipient);
|
||||
}
|
||||
break;
|
||||
|
||||
case WIN_CONSOLE:
|
||||
cons_show("Unknown command: %s", inp);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@ -1068,8 +1091,8 @@ _cmd_complete_parameters(char *input, int *size)
|
||||
_parameter_autocomplete(input, size, "/statuses",
|
||||
prefs_autocomplete_boolean_choice);
|
||||
|
||||
if (win_current_is_groupchat()) {
|
||||
Autocomplete nick_ac = muc_get_roster_ac(win_current_get_recipient());
|
||||
if (ui_current_win_type() == WIN_MUC) {
|
||||
Autocomplete nick_ac = muc_get_roster_ac(ui_current_recipient());
|
||||
if (nick_ac != NULL) {
|
||||
_parameter_autocomplete_with_ac(input, size, "/msg", nick_ac);
|
||||
_parameter_autocomplete_with_ac(input, size, "/info", nick_ac);
|
||||
@ -1149,7 +1172,7 @@ _cmd_connect(gchar **args, struct cmd_help_t help)
|
||||
}
|
||||
|
||||
if (conn_status == JABBER_DISCONNECTED) {
|
||||
cons_bad_show("Connection attempt for %s failed.", jid);
|
||||
cons_show_error("Connection attempt for %s failed.", jid);
|
||||
log_debug("Connection attempt for %s failed", jid);
|
||||
}
|
||||
|
||||
@ -1333,6 +1356,7 @@ static gboolean
|
||||
_cmd_sub(gchar **args, struct cmd_help_t help)
|
||||
{
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
cons_show("You are currently not connected.");
|
||||
@ -1383,7 +1407,7 @@ _cmd_sub(gchar **args, struct cmd_help_t help)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!win_current_is_chat() && (jid == NULL)) {
|
||||
if ((win_type != WIN_CHAT) && (jid == NULL)) {
|
||||
cons_show("You must specify a contact.");
|
||||
return TRUE;
|
||||
}
|
||||
@ -1391,7 +1415,7 @@ _cmd_sub(gchar **args, struct cmd_help_t help)
|
||||
if (jid != NULL) {
|
||||
jid = strdup(jid);
|
||||
} else {
|
||||
jid = win_current_get_recipient();
|
||||
jid = ui_current_recipient();
|
||||
}
|
||||
|
||||
bare_jid = strtok(jid, "/");
|
||||
@ -1411,18 +1435,18 @@ _cmd_sub(gchar **args, struct cmd_help_t help)
|
||||
} else if (strcmp(subcmd, "show") == 0) {
|
||||
PContact contact = contact_list_get_contact(bare_jid);
|
||||
if ((contact == NULL) || (p_contact_subscription(contact) == NULL)) {
|
||||
if (win_current_is_chat()) {
|
||||
win_current_show("No subscription information for %s.", bare_jid);
|
||||
if (win_type == WIN_CHAT) {
|
||||
ui_current_print_line("No subscription information for %s.", bare_jid);
|
||||
} else {
|
||||
cons_show("No subscription information for %s.", bare_jid);
|
||||
}
|
||||
} else {
|
||||
if (win_current_is_chat()) {
|
||||
if (win_type == WIN_CHAT) {
|
||||
if (p_contact_pending_out(contact)) {
|
||||
win_current_show("%s subscription status: %s, request pending.",
|
||||
ui_current_print_line("%s subscription status: %s, request pending.",
|
||||
bare_jid, p_contact_subscription(contact));
|
||||
} else {
|
||||
win_current_show("%s subscription status: %s.", bare_jid,
|
||||
ui_current_print_line("%s subscription status: %s.", bare_jid,
|
||||
p_contact_subscription(contact));
|
||||
}
|
||||
} else {
|
||||
@ -1550,6 +1574,9 @@ _cmd_about(gchar **args, struct cmd_help_t help)
|
||||
{
|
||||
cons_show("");
|
||||
cons_about();
|
||||
if (ui_current_win_type() != WIN_CONSOLE) {
|
||||
status_bar_new(0);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -1620,6 +1647,7 @@ static gboolean
|
||||
_cmd_who(gchar **args, struct cmd_help_t help)
|
||||
{
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
cons_show("You are not currently connected.");
|
||||
@ -1640,13 +1668,13 @@ _cmd_who(gchar **args, struct cmd_help_t help)
|
||||
|
||||
// valid arg
|
||||
} else {
|
||||
if (win_current_is_groupchat()) {
|
||||
char *room = win_current_get_recipient();
|
||||
if (win_type == WIN_MUC) {
|
||||
char *room = ui_current_recipient();
|
||||
GList *list = muc_get_roster(room);
|
||||
|
||||
// no arg, show all contacts
|
||||
if (presence == NULL) {
|
||||
win_show_room_roster(room, list, NULL);
|
||||
ui_room_roster(room, list, NULL);
|
||||
|
||||
// available
|
||||
} else if (strcmp("available", presence) == 0) {
|
||||
@ -1660,7 +1688,7 @@ _cmd_who(gchar **args, struct cmd_help_t help)
|
||||
list = g_list_next(list);
|
||||
}
|
||||
|
||||
win_show_room_roster(room, filtered, "available");
|
||||
ui_room_roster(room, filtered, "available");
|
||||
|
||||
// unavailable
|
||||
} else if (strcmp("unavailable", presence) == 0) {
|
||||
@ -1674,7 +1702,7 @@ _cmd_who(gchar **args, struct cmd_help_t help)
|
||||
list = g_list_next(list);
|
||||
}
|
||||
|
||||
win_show_room_roster(room, filtered, "unavailable");
|
||||
ui_room_roster(room, filtered, "unavailable");
|
||||
|
||||
// online, available resources
|
||||
} else if (strcmp("online", presence) == 0) {
|
||||
@ -1688,7 +1716,7 @@ _cmd_who(gchar **args, struct cmd_help_t help)
|
||||
list = g_list_next(list);
|
||||
}
|
||||
|
||||
win_show_room_roster(room, filtered, "online");
|
||||
ui_room_roster(room, filtered, "online");
|
||||
|
||||
// offline, no available resources
|
||||
} else if (strcmp("offline", presence) == 0) {
|
||||
@ -1702,7 +1730,7 @@ _cmd_who(gchar **args, struct cmd_help_t help)
|
||||
list = g_list_next(list);
|
||||
}
|
||||
|
||||
win_show_room_roster(room, filtered, "offline");
|
||||
ui_room_roster(room, filtered, "offline");
|
||||
|
||||
// show specific status
|
||||
} else {
|
||||
@ -1716,7 +1744,7 @@ _cmd_who(gchar **args, struct cmd_help_t help)
|
||||
list = g_list_next(list);
|
||||
}
|
||||
|
||||
win_show_room_roster(room, filtered, presence);
|
||||
ui_room_roster(room, filtered, presence);
|
||||
}
|
||||
|
||||
// not in groupchat window
|
||||
@ -1808,6 +1836,10 @@ _cmd_who(gchar **args, struct cmd_help_t help)
|
||||
}
|
||||
}
|
||||
|
||||
if (win_type != WIN_CONSOLE) {
|
||||
status_bar_new(0);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -1818,6 +1850,7 @@ _cmd_msg(gchar **args, struct cmd_help_t help)
|
||||
char *msg = args[1];
|
||||
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
cons_show("You are not currently connected.");
|
||||
@ -1825,12 +1858,12 @@ _cmd_msg(gchar **args, struct cmd_help_t help)
|
||||
}
|
||||
|
||||
if (ui_windows_full()) {
|
||||
cons_bad_show("Windows all used, close a window and try again.");
|
||||
cons_show_error("Windows all used, close a window and try again.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (win_current_is_groupchat()) {
|
||||
char *room_name = win_current_get_recipient();
|
||||
if (win_type == WIN_MUC) {
|
||||
char *room_name = ui_current_recipient();
|
||||
if (muc_nick_in_roster(room_name, usr)) {
|
||||
GString *full_jid = g_string_new(room_name);
|
||||
g_string_append(full_jid, "/");
|
||||
@ -1838,15 +1871,15 @@ _cmd_msg(gchar **args, struct cmd_help_t help)
|
||||
|
||||
if (msg != NULL) {
|
||||
message_send(msg, full_jid->str);
|
||||
win_show_outgoing_msg("me", full_jid->str, msg);
|
||||
ui_outgoing_msg("me", full_jid->str, msg);
|
||||
} else {
|
||||
win_new_chat_win(full_jid->str);
|
||||
ui_new_chat_win(full_jid->str);
|
||||
}
|
||||
|
||||
g_string_free(full_jid, TRUE);
|
||||
|
||||
} else {
|
||||
win_current_show("No such participant \"%s\" in room.", usr);
|
||||
ui_current_print_line("No such participant \"%s\" in room.", usr);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@ -1854,9 +1887,9 @@ _cmd_msg(gchar **args, struct cmd_help_t help)
|
||||
} else {
|
||||
if (msg != NULL) {
|
||||
message_send(msg, usr);
|
||||
win_show_outgoing_msg("me", usr, msg);
|
||||
ui_outgoing_msg("me", usr, msg);
|
||||
|
||||
if (win_current_is_chat() && prefs_get_boolean(PREF_CHLOG)) {
|
||||
if ((win_type == WIN_CHAT) && prefs_get_boolean(PREF_CHLOG)) {
|
||||
const char *jid = jabber_get_jid();
|
||||
Jid *jidp = jid_create(jid);
|
||||
chat_log_chat(jidp->barejid, usr, msg, PROF_OUT_LOG, NULL);
|
||||
@ -1865,7 +1898,7 @@ _cmd_msg(gchar **args, struct cmd_help_t help)
|
||||
|
||||
return TRUE;
|
||||
} else {
|
||||
win_new_chat_win(usr);
|
||||
ui_new_chat_win(usr);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
@ -1877,35 +1910,45 @@ _cmd_status(gchar **args, struct cmd_help_t help)
|
||||
char *usr = args[0];
|
||||
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
cons_show("You are not currently connected.");
|
||||
} else {
|
||||
if (win_current_is_groupchat()) {
|
||||
if (usr != NULL) {
|
||||
win_room_show_status(usr);
|
||||
} else {
|
||||
win_current_show("You must specify a nickname.");
|
||||
return TRUE;
|
||||
}
|
||||
} else if (win_current_is_chat()) {
|
||||
|
||||
switch (win_type)
|
||||
{
|
||||
case WIN_MUC:
|
||||
if (usr != NULL) {
|
||||
win_current_show("No parameter required when in chat.");
|
||||
ui_status_room(usr);
|
||||
} else {
|
||||
win_show_status();
|
||||
ui_current_print_line("You must specify a nickname.");
|
||||
}
|
||||
} else if (win_current_is_private()) {
|
||||
break;
|
||||
case WIN_CHAT:
|
||||
if (usr != NULL) {
|
||||
win_current_show("No parameter required when in chat.");
|
||||
ui_current_print_line("No parameter required when in chat.");
|
||||
} else {
|
||||
win_private_show_status();
|
||||
ui_status();
|
||||
}
|
||||
break;
|
||||
case WIN_PRIVATE:
|
||||
if (usr != NULL) {
|
||||
ui_current_print_line("No parameter required when in chat.");
|
||||
} else {
|
||||
ui_status_private();
|
||||
}
|
||||
break;
|
||||
case WIN_CONSOLE:
|
||||
if (usr != NULL) {
|
||||
cons_show_status(usr);
|
||||
} else {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@ -1917,13 +1960,19 @@ _cmd_info(gchar **args, struct cmd_help_t help)
|
||||
char *usr = args[0];
|
||||
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
PContact pcontact = NULL;
|
||||
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
cons_show("You are not currently connected.");
|
||||
} else {
|
||||
if (win_current_is_groupchat()) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
switch (win_type)
|
||||
{
|
||||
case WIN_MUC:
|
||||
if (usr != NULL) {
|
||||
PContact pcontact = muc_get_participant(win_current_get_recipient(), usr);
|
||||
pcontact = muc_get_participant(ui_current_recipient(), usr);
|
||||
if (pcontact != NULL) {
|
||||
cons_show_info(pcontact);
|
||||
} else {
|
||||
@ -1932,25 +1981,25 @@ _cmd_info(gchar **args, struct cmd_help_t help)
|
||||
} else {
|
||||
cons_show("No nickname supplied to /info in chat room.");
|
||||
}
|
||||
|
||||
} else if (win_current_is_chat()) {
|
||||
break;
|
||||
case WIN_CHAT:
|
||||
if (usr != NULL) {
|
||||
cons_show("No parameter required for /info in chat.");
|
||||
} else {
|
||||
PContact pcontact = contact_list_get_contact(win_current_get_recipient());
|
||||
pcontact = contact_list_get_contact(ui_current_recipient());
|
||||
if (pcontact != NULL) {
|
||||
cons_show_info(pcontact);
|
||||
} else {
|
||||
cons_show("No such contact \"%s\" in roster.", win_current_get_recipient());
|
||||
cons_show("No such contact \"%s\" in roster.", ui_current_recipient());
|
||||
}
|
||||
}
|
||||
|
||||
} else if (win_current_is_private()) {
|
||||
break;
|
||||
case WIN_PRIVATE:
|
||||
if (usr != NULL) {
|
||||
win_current_show("No parameter required when in chat.");
|
||||
ui_current_print_line("No parameter required when in chat.");
|
||||
} else {
|
||||
Jid *jid = jid_create(win_current_get_recipient());
|
||||
PContact pcontact = muc_get_participant(jid->barejid, jid->resourcepart);
|
||||
Jid *jid = jid_create(ui_current_recipient());
|
||||
pcontact = muc_get_participant(jid->barejid, jid->resourcepart);
|
||||
if (pcontact != NULL) {
|
||||
cons_show_info(pcontact);
|
||||
} else {
|
||||
@ -1958,9 +2007,10 @@ _cmd_info(gchar **args, struct cmd_help_t help)
|
||||
}
|
||||
jid_destroy(jid);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
case WIN_CONSOLE:
|
||||
if (usr != NULL) {
|
||||
PContact pcontact = contact_list_get_contact(usr);
|
||||
pcontact = contact_list_get_contact(usr);
|
||||
if (pcontact != NULL) {
|
||||
cons_show_info(pcontact);
|
||||
} else {
|
||||
@ -1969,7 +2019,9 @@ _cmd_info(gchar **args, struct cmd_help_t help)
|
||||
} else {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@ -1979,13 +2031,19 @@ static gboolean
|
||||
_cmd_caps(gchar **args, struct cmd_help_t help)
|
||||
{
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
PContact pcontact = NULL;
|
||||
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
cons_show("You are not currently connected.");
|
||||
} else {
|
||||
if (win_current_is_groupchat()) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
switch (win_type)
|
||||
{
|
||||
case WIN_MUC:
|
||||
if (args[0] != NULL) {
|
||||
PContact pcontact = muc_get_participant(win_current_get_recipient(), args[0]);
|
||||
pcontact = muc_get_participant(ui_current_recipient(), args[0]);
|
||||
if (pcontact != NULL) {
|
||||
Resource *resource = p_contact_get_resource(pcontact, args[0]);
|
||||
cons_show_caps(args[0], resource);
|
||||
@ -1995,14 +2053,16 @@ _cmd_caps(gchar **args, struct cmd_help_t help)
|
||||
} else {
|
||||
cons_show("No nickname supplied to /caps in chat room.");
|
||||
}
|
||||
} else if (win_current_is_chat() || win_current_is_console()) {
|
||||
break;
|
||||
case WIN_CHAT:
|
||||
case WIN_CONSOLE:
|
||||
if (args[0] != NULL) {
|
||||
Jid *jid = jid_create(args[0]);
|
||||
|
||||
if (jid->fulljid == NULL) {
|
||||
cons_show("You must provide a full jid to the /caps command.");
|
||||
} else {
|
||||
PContact pcontact = contact_list_get_contact(jid->barejid);
|
||||
pcontact = contact_list_get_contact(jid->barejid);
|
||||
if (pcontact == NULL) {
|
||||
cons_show("Contact not found in roster: %s", jid->barejid);
|
||||
} else {
|
||||
@ -2017,16 +2077,19 @@ _cmd_caps(gchar **args, struct cmd_help_t help)
|
||||
} else {
|
||||
cons_show("You must provide a jid to the /caps command.");
|
||||
}
|
||||
} else { // private chat
|
||||
break;
|
||||
case WIN_PRIVATE:
|
||||
if (args[0] != NULL) {
|
||||
cons_show("No parameter needed to /caps when in private chat.");
|
||||
} else {
|
||||
Jid *jid = jid_create(win_current_get_recipient());
|
||||
PContact pcontact = muc_get_participant(jid->barejid, jid->resourcepart);
|
||||
Jid *jid = jid_create(ui_current_recipient());
|
||||
pcontact = muc_get_participant(jid->barejid, jid->resourcepart);
|
||||
Resource *resource = p_contact_get_resource(pcontact, jid->resourcepart);
|
||||
cons_show_caps(jid->resourcepart, resource);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@ -2037,15 +2100,21 @@ static gboolean
|
||||
_cmd_software(gchar **args, struct cmd_help_t help)
|
||||
{
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
PContact pcontact = NULL;
|
||||
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
cons_show("You are not currently connected.");
|
||||
} else {
|
||||
if (win_current_is_groupchat()) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
switch (win_type)
|
||||
{
|
||||
case WIN_MUC:
|
||||
if (args[0] != NULL) {
|
||||
PContact pcontact = muc_get_participant(win_current_get_recipient(), args[0]);
|
||||
pcontact = muc_get_participant(ui_current_recipient(), args[0]);
|
||||
if (pcontact != NULL) {
|
||||
Jid *jid = jid_create_from_bare_and_resource(win_current_get_recipient(), args[0]);
|
||||
Jid *jid = jid_create_from_bare_and_resource(ui_current_recipient(), args[0]);
|
||||
iq_send_software_version(jid->fulljid);
|
||||
jid_destroy(jid);
|
||||
} else {
|
||||
@ -2054,7 +2123,9 @@ _cmd_software(gchar **args, struct cmd_help_t help)
|
||||
} else {
|
||||
cons_show("No nickname supplied to /software in chat room.");
|
||||
}
|
||||
} else if (win_current_is_chat() || win_current_is_console()) {
|
||||
break;
|
||||
case WIN_CHAT:
|
||||
case WIN_CONSOLE:
|
||||
if (args[0] != NULL) {
|
||||
Jid *jid = jid_create(args[0]);
|
||||
|
||||
@ -2066,13 +2137,16 @@ _cmd_software(gchar **args, struct cmd_help_t help)
|
||||
} else {
|
||||
cons_show("You must provide a jid to the /software command.");
|
||||
}
|
||||
} else { // private chat
|
||||
break;
|
||||
case WIN_PRIVATE:
|
||||
if (args[0] != NULL) {
|
||||
cons_show("No parameter needed to /software when in private chat.");
|
||||
} else {
|
||||
iq_send_software_version(win_current_get_recipient());
|
||||
}
|
||||
iq_send_software_version(ui_current_recipient());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@ -2089,7 +2163,7 @@ _cmd_join(gchar **args, struct cmd_help_t help)
|
||||
}
|
||||
|
||||
if (ui_windows_full()) {
|
||||
cons_bad_show("Windows all used, close a window and try again.");
|
||||
cons_show_error("Windows all used, close a window and try again.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -2126,7 +2200,7 @@ _cmd_join(gchar **args, struct cmd_help_t help)
|
||||
if (!muc_room_is_active(room_jid)) {
|
||||
presence_join_room(room_jid);
|
||||
}
|
||||
win_join_chat(room_jid);
|
||||
ui_room_join(room_jid);
|
||||
|
||||
jid_destroy(room_jid);
|
||||
jid_destroy(my_jid);
|
||||
@ -2148,12 +2222,12 @@ _cmd_invite(gchar **args, struct cmd_help_t help)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!win_current_is_groupchat()) {
|
||||
if (ui_current_win_type() != WIN_MUC) {
|
||||
cons_show("You must be in a chat room to send an invite.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
room = win_current_get_recipient();
|
||||
room = ui_current_recipient();
|
||||
message_send_invite(room, contact, reason);
|
||||
if (reason != NULL) {
|
||||
cons_show("Room invite sent, contact: %s, room: %s, reason: \"%s\".",
|
||||
@ -2229,12 +2303,12 @@ _cmd_nick(gchar **args, struct cmd_help_t help)
|
||||
cons_show("You are not currently connected.");
|
||||
return TRUE;
|
||||
}
|
||||
if (!win_current_is_groupchat()) {
|
||||
if (ui_current_win_type() != WIN_MUC) {
|
||||
cons_show("You can only change your nickname in a chat room window.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char *room = win_current_get_recipient();
|
||||
char *room = ui_current_recipient();
|
||||
char *nick = args[0];
|
||||
presence_change_room_nick(room, nick);
|
||||
|
||||
@ -2245,21 +2319,22 @@ static gboolean
|
||||
_cmd_tiny(gchar **args, struct cmd_help_t help)
|
||||
{
|
||||
char *url = args[0];
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
|
||||
if (!tinyurl_valid(url)) {
|
||||
GString *error = g_string_new("/tiny, badly formed URL: ");
|
||||
g_string_append(error, url);
|
||||
cons_bad_show(error->str);
|
||||
if (!win_current_is_console()) {
|
||||
win_current_bad_show(error->str);
|
||||
cons_show_error(error->str);
|
||||
if (win_type != WIN_CONSOLE) {
|
||||
ui_current_error_line(error->str);
|
||||
}
|
||||
g_string_free(error, TRUE);
|
||||
} else if (!win_current_is_console()) {
|
||||
} else if (win_type != WIN_CONSOLE) {
|
||||
char *tiny = tinyurl_get(url);
|
||||
|
||||
if (tiny != NULL) {
|
||||
if (win_current_is_chat()) {
|
||||
char *recipient = win_current_get_recipient();
|
||||
if (win_type == WIN_CHAT) {
|
||||
char *recipient = ui_current_recipient();
|
||||
message_send(tiny, recipient);
|
||||
|
||||
if (prefs_get_boolean(PREF_CHLOG)) {
|
||||
@ -2269,21 +2344,21 @@ _cmd_tiny(gchar **args, struct cmd_help_t help)
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
|
||||
win_show_outgoing_msg("me", recipient, tiny);
|
||||
ui_outgoing_msg("me", recipient, tiny);
|
||||
free(recipient);
|
||||
} else if (win_current_is_private()) {
|
||||
char *recipient = win_current_get_recipient();
|
||||
} else if (win_type == WIN_PRIVATE) {
|
||||
char *recipient = ui_current_recipient();
|
||||
message_send(tiny, recipient);
|
||||
win_show_outgoing_msg("me", recipient, tiny);
|
||||
ui_outgoing_msg("me", recipient, tiny);
|
||||
free(recipient);
|
||||
} else { // groupchat
|
||||
char *recipient = win_current_get_recipient();
|
||||
char *recipient = ui_current_recipient();
|
||||
message_send_groupchat(tiny, recipient);
|
||||
free(recipient);
|
||||
}
|
||||
free(tiny);
|
||||
} else {
|
||||
cons_bad_show("Couldn't get tinyurl.");
|
||||
cons_show_error("Couldn't get tinyurl.");
|
||||
}
|
||||
} else {
|
||||
cons_show("/tiny can only be used in chat windows");
|
||||
@ -2295,7 +2370,7 @@ _cmd_tiny(gchar **args, struct cmd_help_t help)
|
||||
static gboolean
|
||||
_cmd_clear(gchar **args, struct cmd_help_t help)
|
||||
{
|
||||
win_current_clear();
|
||||
ui_clear_current();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -2303,22 +2378,23 @@ static gboolean
|
||||
_cmd_close(gchar **args, struct cmd_help_t help)
|
||||
{
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
|
||||
// cannot close console window
|
||||
if (win_current_is_console()) {
|
||||
if (win_type == WIN_CONSOLE) {
|
||||
cons_show("Cannot close console window.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// handle leaving rooms, or chat
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
if (win_current_is_groupchat()) {
|
||||
char *room_jid = win_current_get_recipient();
|
||||
if (win_type == WIN_MUC) {
|
||||
char *room_jid = ui_current_recipient();
|
||||
presence_leave_chat_room(room_jid);
|
||||
} else if (win_current_is_chat() || win_current_is_private()) {
|
||||
} else if ((win_type == WIN_CHAT) || (win_type == WIN_PRIVATE)) {
|
||||
|
||||
if (prefs_get_boolean(PREF_STATES)) {
|
||||
char *recipient = win_current_get_recipient();
|
||||
char *recipient = ui_current_recipient();
|
||||
|
||||
// send <gone/> chat state before closing
|
||||
if (chat_session_get_recipient_supports(recipient)) {
|
||||
@ -2331,7 +2407,7 @@ _cmd_close(gchar **args, struct cmd_help_t help)
|
||||
}
|
||||
|
||||
// close the window
|
||||
win_current_close();
|
||||
ui_close_current();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -2415,7 +2491,7 @@ _cmd_set_notify(gchar **args, struct cmd_help_t help)
|
||||
|
||||
// bad kind
|
||||
if ((strcmp(kind, "message") != 0) && (strcmp(kind, "typing") != 0) &&
|
||||
(strcmp(kind, "remind") != 0)) {
|
||||
(strcmp(kind, "remind") != 0) && (strcmp(kind, "invite") != 0)) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
|
||||
// set message setting
|
||||
@ -2442,6 +2518,18 @@ _cmd_set_notify(gchar **args, struct cmd_help_t help)
|
||||
cons_show("Usage: /notify typing on|off");
|
||||
}
|
||||
|
||||
// set invite setting
|
||||
} else if (strcmp(kind, "invite") == 0) {
|
||||
if (strcmp(value, "on") == 0) {
|
||||
cons_show("Chat room invite notifications enabled.");
|
||||
prefs_set_boolean(PREF_NOTIFY_INVITE, TRUE);
|
||||
} else if (strcmp(value, "off") == 0) {
|
||||
cons_show("Chat room invite notifications disabled.");
|
||||
prefs_set_boolean(PREF_NOTIFY_INVITE, FALSE);
|
||||
} else {
|
||||
cons_show("Usage: /notify invite on|off");
|
||||
}
|
||||
|
||||
// set remind setting
|
||||
} else if (strcmp(kind, "remind") == 0) {
|
||||
gint period = atoi(value);
|
||||
|
27
src/common.c
27
src/common.c
@ -19,6 +19,7 @@
|
||||
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
@ -260,6 +261,32 @@ release_get_latest()
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
release_is_new(char *found_version)
|
||||
{
|
||||
int curr_maj, curr_min, curr_patch, found_maj, found_min, found_patch;
|
||||
|
||||
int parse_curr = sscanf(PACKAGE_VERSION, "%d.%d.%d", &curr_maj, &curr_min,
|
||||
&curr_patch);
|
||||
int parse_found = sscanf(found_version, "%d.%d.%d", &found_maj, &found_min,
|
||||
&found_patch);
|
||||
|
||||
if (parse_found == 3 && parse_curr == 3) {
|
||||
if (found_maj > curr_maj) {
|
||||
return TRUE;
|
||||
} else if (found_maj == curr_maj && found_min > curr_min) {
|
||||
return TRUE;
|
||||
} else if (found_maj == curr_maj && found_min == curr_min
|
||||
&& found_patch > curr_patch) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
valid_resource_presence_string(const char * const str)
|
||||
{
|
||||
|
@ -83,6 +83,7 @@ char* encode_xml(const char * const xml);
|
||||
char * prof_getline(FILE *stream);
|
||||
int octet_compare(unsigned char *str1, unsigned char *str2);
|
||||
char* release_get_latest(void);
|
||||
gboolean release_is_new(char *found_version);
|
||||
gchar * xdg_get_config_home(void);
|
||||
gchar * xdg_get_data_home(void);
|
||||
|
||||
|
@ -299,6 +299,7 @@ _get_group(preference_t pref)
|
||||
return "chatstates";
|
||||
case PREF_NOTIFY_TYPING:
|
||||
case PREF_NOTIFY_MESSAGE:
|
||||
case PREF_NOTIFY_INVITE:
|
||||
return "notifications";
|
||||
case PREF_CHLOG:
|
||||
return "logging";
|
||||
@ -344,6 +345,8 @@ _get_key(preference_t pref)
|
||||
return "typing";
|
||||
case PREF_NOTIFY_MESSAGE:
|
||||
return "message";
|
||||
case PREF_NOTIFY_INVITE:
|
||||
return "invite";
|
||||
case PREF_CHLOG:
|
||||
return "chlog";
|
||||
case PREF_AUTOAWAY_CHECK:
|
||||
|
@ -50,6 +50,7 @@ typedef enum {
|
||||
PREF_OUTTYPE,
|
||||
PREF_NOTIFY_TYPING,
|
||||
PREF_NOTIFY_MESSAGE,
|
||||
PREF_NOTIFY_INVITE,
|
||||
PREF_CHLOG,
|
||||
PREF_AUTOAWAY_CHECK,
|
||||
PREF_AUTOAWAY_MODE,
|
||||
|
124
src/profanity.c
124
src/profanity.c
@ -42,6 +42,7 @@
|
||||
#include "log.h"
|
||||
#include "muc.h"
|
||||
#include "resource.h"
|
||||
#include "ui/notifier.h"
|
||||
#include "ui/ui.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
|
||||
@ -102,15 +103,15 @@ prof_run(const int disable_tls, char *log_level)
|
||||
void
|
||||
prof_handle_typing(char *from)
|
||||
{
|
||||
ui_show_typing(from);
|
||||
win_current_page_off();
|
||||
ui_contact_typing(from);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_incoming_message(char *from, char *message, gboolean priv)
|
||||
{
|
||||
ui_show_incoming_msg(from, message, NULL, priv);
|
||||
win_current_page_off();
|
||||
ui_incoming_msg(from, message, NULL, priv);
|
||||
ui_current_page_off();
|
||||
|
||||
if (prefs_get_boolean(PREF_CHLOG) && !priv) {
|
||||
Jid *from_jid = jid_create(from);
|
||||
@ -126,8 +127,8 @@ void
|
||||
prof_handle_delayed_message(char *from, char *message, GTimeVal tv_stamp,
|
||||
gboolean priv)
|
||||
{
|
||||
ui_show_incoming_msg(from, message, &tv_stamp, priv);
|
||||
win_current_page_off();
|
||||
ui_incoming_msg(from, message, &tv_stamp, priv);
|
||||
ui_current_page_off();
|
||||
|
||||
if (prefs_get_boolean(PREF_CHLOG) && !priv) {
|
||||
Jid *from_jid = jid_create(from);
|
||||
@ -142,19 +143,20 @@ prof_handle_delayed_message(char *from, char *message, GTimeVal tv_stamp,
|
||||
void
|
||||
prof_handle_error_message(const char *from, const char *err_msg)
|
||||
{
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
if (err_msg == NULL) {
|
||||
cons_bad_show("Unknown error received from service.");
|
||||
cons_show_error("Unknown error received from service.");
|
||||
} else if (strcmp(err_msg, "conflict") == 0) {
|
||||
if (win_current_is_groupchat()) {
|
||||
win_current_show("Nickname already in use.");
|
||||
if (win_type == WIN_MUC) {
|
||||
ui_current_print_line("Nickname already in use.");
|
||||
} else {
|
||||
cons_bad_show("Error received from server: %s", err_msg);
|
||||
cons_show_error("Error received from server: %s", err_msg);
|
||||
}
|
||||
} else {
|
||||
cons_bad_show("Error received from server: %s", err_msg);
|
||||
cons_show_error("Error received from server: %s", err_msg);
|
||||
}
|
||||
|
||||
win_show_error_msg(from, err_msg);
|
||||
ui_print_error_from_recipient(from, err_msg);
|
||||
}
|
||||
|
||||
void
|
||||
@ -165,20 +167,20 @@ prof_handle_subscription(const char *from, jabber_subscr_t type)
|
||||
/* TODO: auto-subscribe if needed */
|
||||
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 allow' to accept or '/sub deny' to reject");
|
||||
win_current_page_off();
|
||||
ui_print_system_msg_from_recipient(from, "Authorization request, type '/sub allow' to accept or '/sub deny' to reject");
|
||||
ui_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_current_page_off();
|
||||
ui_print_system_msg_from_recipient(from, "Subscribed");
|
||||
ui_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_current_page_off();
|
||||
ui_print_system_msg_from_recipient(from, "Unsubscribed");
|
||||
ui_current_page_off();
|
||||
break;
|
||||
default:
|
||||
/* unknown type */
|
||||
@ -195,7 +197,7 @@ prof_handle_login_account_success(char *account_name)
|
||||
cons_show_login_success(account);
|
||||
title_bar_set_status(contact_presence);
|
||||
log_info("%s logged in successfully", account->jid);
|
||||
win_current_page_off();
|
||||
ui_current_page_off();
|
||||
status_bar_print_message(account->jid);
|
||||
status_bar_refresh();
|
||||
|
||||
@ -205,26 +207,26 @@ prof_handle_login_account_success(char *account_name)
|
||||
void
|
||||
prof_handle_gone(const char * const from)
|
||||
{
|
||||
win_show_gone(from);
|
||||
win_current_page_off();
|
||||
ui_recipient_gone(from);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_failed_login(void)
|
||||
{
|
||||
cons_bad_show("Login failed.");
|
||||
cons_show_error("Login failed.");
|
||||
log_info("Login failed");
|
||||
win_current_page_off();
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_lost_connection(void)
|
||||
{
|
||||
cons_bad_show("Lost connection.");
|
||||
cons_show_error("Lost connection.");
|
||||
contact_list_clear();
|
||||
chat_sessions_clear();
|
||||
ui_disconnected();
|
||||
win_current_page_off();
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
@ -235,38 +237,38 @@ prof_handle_disconnect(const char * const jid)
|
||||
contact_list_clear();
|
||||
chat_sessions_clear();
|
||||
ui_disconnected();
|
||||
win_current_page_off();
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
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_current_page_off();
|
||||
ui_room_history(room_jid, nick, tv_stamp, message);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
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_current_page_off();
|
||||
ui_room_message(room_jid, nick, message);
|
||||
ui_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_current_page_off();
|
||||
ui_room_subject(room_jid, subject);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_room_broadcast(const char *const room_jid,
|
||||
const char * const message)
|
||||
{
|
||||
win_show_room_broadcast(room_jid, message);
|
||||
win_current_page_off();
|
||||
ui_room_broadcast(room_jid, message);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
@ -274,8 +276,8 @@ prof_handle_room_roster_complete(const char * const room)
|
||||
{
|
||||
muc_set_roster_received(room);
|
||||
GList *roster = muc_get_roster(room);
|
||||
win_show_room_roster(room, roster, NULL);
|
||||
win_current_page_off();
|
||||
ui_room_roster(room, roster, NULL);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
@ -286,8 +288,8 @@ prof_handle_room_member_presence(const char * const room,
|
||||
gboolean updated = muc_add_to_roster(room, nick, show, status, caps_str);
|
||||
|
||||
if (updated) {
|
||||
win_show_room_member_presence(room, nick, show, status);
|
||||
win_current_page_off();
|
||||
ui_room_member_presence(room, nick, show, status);
|
||||
ui_current_page_off();
|
||||
}
|
||||
}
|
||||
|
||||
@ -297,8 +299,8 @@ prof_handle_room_member_online(const char * const room, const char * const nick,
|
||||
const char * const caps_str)
|
||||
{
|
||||
muc_add_to_roster(room, nick, show, status, caps_str);
|
||||
win_show_room_member_online(room, nick, show, status);
|
||||
win_current_page_off();
|
||||
ui_room_member_online(room, nick, show, status);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
@ -306,8 +308,8 @@ prof_handle_room_member_offline(const char * const room, const char * const nick
|
||||
const char * const show, const char * const status)
|
||||
{
|
||||
muc_remove_from_roster(room, nick);
|
||||
win_show_room_member_offline(room, nick);
|
||||
win_current_page_off();
|
||||
ui_room_member_offline(room, nick);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
@ -321,7 +323,7 @@ void prof_handle_room_invite(jabber_invite_t invite_type,
|
||||
const char * const reason)
|
||||
{
|
||||
cons_show_room_invite(invitor, room, reason);
|
||||
win_current_page_off();
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
@ -336,7 +338,7 @@ prof_handle_contact_online(char *contact, Resource *resource,
|
||||
if (strcmp(p_contact_subscription(result), "none") != 0) {
|
||||
const char *show = string_from_resource_presence(resource->presence);
|
||||
ui_contact_online(contact, resource->name, show, resource->status, last_activity);
|
||||
win_current_page_off();
|
||||
ui_current_page_off();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -353,7 +355,7 @@ prof_handle_contact_offline(char *contact, char *resource, char *status)
|
||||
if (p_contact_subscription(result) != NULL) {
|
||||
if (strcmp(p_contact_subscription(result), "none") != 0) {
|
||||
ui_contact_offline(jid->fulljid, "offline", status);
|
||||
win_current_page_off();
|
||||
ui_current_page_off();
|
||||
}
|
||||
}
|
||||
jid_destroy(jid);
|
||||
@ -364,16 +366,16 @@ void
|
||||
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_current_page_off();
|
||||
ui_room_member_nick_change(room, old_nick, nick);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_room_nick_change(const char * const room,
|
||||
const char * const nick)
|
||||
{
|
||||
win_show_room_nick_change(room, nick);
|
||||
win_current_page_off();
|
||||
ui_room_nick_change(room, nick);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
@ -388,10 +390,11 @@ prof_handle_idle(void)
|
||||
void
|
||||
prof_handle_activity(void)
|
||||
{
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
jabber_conn_status_t status = jabber_get_connection_status();
|
||||
if (status == JABBER_CONNECTED) {
|
||||
if (win_current_is_chat()) {
|
||||
char *recipient = win_current_get_recipient();
|
||||
|
||||
if ((status == JABBER_CONNECTED) && (win_type == WIN_CHAT)) {
|
||||
char *recipient = ui_current_recipient();
|
||||
chat_session_set_composing(recipient);
|
||||
if (!chat_session_get_sent(recipient) ||
|
||||
chat_session_is_paused(recipient)) {
|
||||
@ -399,35 +402,34 @@ prof_handle_activity(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_version_result(const char * const jid, const char * const presence,
|
||||
const char * const name, const char * const version, const char * const os)
|
||||
{
|
||||
cons_show_software_version(jid, presence, name, version, os);
|
||||
win_current_page_off();
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_room_list(GSList *rooms, const char *conference_node)
|
||||
{
|
||||
cons_show_room_list(rooms, conference_node);
|
||||
win_current_page_off();
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_disco_items(GSList *items, const char *jid)
|
||||
{
|
||||
cons_show_disco_items(items, jid);
|
||||
win_current_page_off();
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_disco_info(const char *from, GSList *identities, GSList *features)
|
||||
{
|
||||
cons_show_disco_info(from, identities, features);
|
||||
win_current_page_off();
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -464,7 +466,7 @@ _process_input(char *inp)
|
||||
|
||||
inp_win_reset();
|
||||
contact_list_reset_search_attempts();
|
||||
win_current_page_off();
|
||||
ui_current_page_off();
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -489,7 +491,7 @@ _handle_idle_time()
|
||||
cons_show("Idle for %d minutes, status set to away (priority %d), \"%s\".",
|
||||
prefs_get_autoaway_time(), pri, prefs_get_string(PREF_AUTOAWAY_MESSAGE));
|
||||
title_bar_set_status(CONTACT_AWAY);
|
||||
win_current_page_off();
|
||||
ui_current_page_off();
|
||||
} else {
|
||||
int pri =
|
||||
accounts_get_priority_for_presence_type(jabber_get_account_name(),
|
||||
@ -497,7 +499,7 @@ _handle_idle_time()
|
||||
cons_show("Idle for %d minutes, status set to away (priority %d).",
|
||||
prefs_get_autoaway_time(), pri);
|
||||
title_bar_set_status(CONTACT_AWAY);
|
||||
win_current_page_off();
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
// handle idle mode
|
||||
@ -520,7 +522,7 @@ _handle_idle_time()
|
||||
RESOURCE_ONLINE);
|
||||
cons_show("No longer idle, status set to online (priority %d).", pri);
|
||||
title_bar_set_status(CONTACT_ONLINE);
|
||||
win_current_page_off();
|
||||
ui_current_page_off();
|
||||
} else if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "idle") == 0) {
|
||||
presence_update(RESOURCE_ONLINE, NULL, 0);
|
||||
title_bar_set_status(CONTACT_ONLINE);
|
||||
|
1250
src/ui/console.c
Normal file
1250
src/ui/console.c
Normal file
File diff suppressed because it is too large
Load Diff
1432
src/ui/core.c
Normal file
1432
src/ui/core.c
Normal file
File diff suppressed because it is too large
Load Diff
152
src/ui/notifier.c
Normal file
152
src/ui/notifier.c
Normal file
@ -0,0 +1,152 @@
|
||||
/*
|
||||
* notifier.c
|
||||
*
|
||||
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* This file is part of Profanity.
|
||||
*
|
||||
* Profanity is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Profanity is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <glib.h>
|
||||
#ifdef HAVE_LIBNOTIFY
|
||||
#include <libnotify/notify.h>
|
||||
#endif
|
||||
#ifdef PLATFORM_CYGWIN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "log.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
static void _notify(const char * const message, int timeout,
|
||||
const char * const category);
|
||||
|
||||
void
|
||||
notifier_init(void)
|
||||
{
|
||||
#ifdef HAVE_LIBNOTIFY
|
||||
notify_init("Profanity");
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
notifier_uninit(void)
|
||||
{
|
||||
#ifdef HAVE_LIBNOTIFY
|
||||
if (notify_is_initted()) {
|
||||
notify_uninit();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
notify_typing(const char * const from)
|
||||
{
|
||||
char message[strlen(from) + 1 + 11];
|
||||
sprintf(message, "%s: typing...", from);
|
||||
|
||||
_notify(message, 10000, "Incoming message");
|
||||
}
|
||||
|
||||
void
|
||||
notify_invite(const char * const from, const char * const room)
|
||||
{
|
||||
GString *message = g_string_new("Room invite\nfrom: ");
|
||||
g_string_append(message, from);
|
||||
g_string_append(message, "\nto: ");
|
||||
g_string_append(message, room);
|
||||
|
||||
_notify(message->str, 10000, "Incoming message");
|
||||
|
||||
g_string_free(message, FALSE);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
void
|
||||
notify_remind(void)
|
||||
{
|
||||
gint unread = ui_unread();
|
||||
if (unread > 0) {
|
||||
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(const char * const message, int timeout,
|
||||
const char * const category)
|
||||
{
|
||||
#ifdef HAVE_LIBNOTIFY
|
||||
|
||||
if (notify_is_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.");
|
||||
}
|
||||
#endif
|
||||
#ifdef PLATFORM_CYGWIN
|
||||
NOTIFYICONDATA nid;
|
||||
nid.cbSize = sizeof(NOTIFYICONDATA);
|
||||
//nid.hWnd = hWnd;
|
||||
nid.uID = 100;
|
||||
nid.uVersion = NOTIFYICON_VERSION;
|
||||
//nid.uCallbackMessage = WM_MYMESSAGE;
|
||||
nid.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
strcpy(nid.szTip, "Tray Icon");
|
||||
nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
|
||||
Shell_NotifyIcon(NIM_ADD, &nid);
|
||||
|
||||
// For a Ballon Tip
|
||||
nid.uFlags = NIF_INFO;
|
||||
strcpy(nid.szInfoTitle, "Profanity"); // Title
|
||||
strcpy(nid.szInfo, message); // Copy Tip
|
||||
nid.uTimeout = timeout; // 3 Seconds
|
||||
nid.dwInfoFlags = NIIF_INFO;
|
||||
|
||||
Shell_NotifyIcon(NIM_MODIFY, &nid);
|
||||
#endif
|
||||
}
|
29
src/ui/notifier.h
Normal file
29
src/ui/notifier.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* notifier.h
|
||||
*
|
||||
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* This file is part of Profanity.
|
||||
*
|
||||
* Profanity is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Profanity is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
void notifier_init(void);
|
||||
void notifier_uninit(void);
|
||||
|
||||
void notify_typing(const char * const from);
|
||||
void notify_message(const char * const short_from);
|
||||
void notify_remind(void);
|
||||
void notify_invite(const char * const from, const char * const room);
|
135
src/ui/ui.h
135
src/ui/ui.h
@ -36,51 +36,79 @@
|
||||
|
||||
#include "contact.h"
|
||||
#include "jid.h"
|
||||
#include "ui/window.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
|
||||
#define INP_WIN_MAX 1000
|
||||
#define PAD_SIZE 1000
|
||||
#define NUM_WINS 10
|
||||
|
||||
typedef enum {
|
||||
WIN_UNUSED,
|
||||
WIN_CONSOLE,
|
||||
WIN_CHAT,
|
||||
WIN_MUC,
|
||||
WIN_PRIVATE
|
||||
} win_type_t;
|
||||
// holds console at index 0 and chat wins 1 through to 9
|
||||
ProfWin* windows[NUM_WINS];
|
||||
|
||||
struct prof_win {
|
||||
char from[100];
|
||||
WINDOW *win;
|
||||
win_type_t type;
|
||||
int y_pos;
|
||||
int paged;
|
||||
int unread;
|
||||
int history_shown;
|
||||
};
|
||||
|
||||
// gui startup and shutdown, resize
|
||||
// ui startup and control
|
||||
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);
|
||||
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 barejid, const char * const resource,
|
||||
const char * const show, const char * const status, GDateTime *last_activity);
|
||||
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 wint_t * const ch, const char * const inp,
|
||||
const int size);
|
||||
void ui_switch_win(const int i);
|
||||
gboolean ui_windows_full(void);
|
||||
unsigned long ui_get_idle_time(void);
|
||||
void ui_reset_idle_time(void);
|
||||
void ui_new_chat_win(const char * const to);
|
||||
void ui_print_error_from_recipient(const char * const from, const char *err_msg);
|
||||
void ui_print_system_msg_from_recipient(const char * const from, const char *message);
|
||||
gint ui_unread(void);
|
||||
void ui_console_dirty(void);
|
||||
|
||||
// current window actions
|
||||
void ui_close_current(void);
|
||||
void ui_clear_current(void);
|
||||
win_type_t ui_current_win_type(void);
|
||||
char* ui_current_recipient(void);
|
||||
void ui_current_print_line(const char * const msg, ...);
|
||||
void ui_current_error_line(const char * const msg);
|
||||
void ui_current_page_off(void);
|
||||
|
||||
// ui events
|
||||
void ui_contact_typing(const char * const from);
|
||||
void ui_incoming_msg(const char * const from, const char * const message,
|
||||
GTimeVal *tv_stamp, gboolean priv);
|
||||
void ui_contact_online(const char * const barejid, const char * const resource,
|
||||
const char * const show, const char * const status, GDateTime *last_activity);
|
||||
void ui_contact_offline(const char * const from, const char * const show,
|
||||
const char * const status);
|
||||
void ui_disconnected(void);
|
||||
void ui_recipient_gone(const char * const from);
|
||||
void ui_outgoing_msg(const char * const from, const char * const to,
|
||||
const char * const message);
|
||||
void ui_room_join(Jid *jid);
|
||||
void ui_room_roster(const char * const room, GList *roster, const char * const presence);
|
||||
void ui_room_history(const char * const room_jid, const char * const nick,
|
||||
GTimeVal tv_stamp, const char * const message);
|
||||
void ui_room_message(const char * const room_jid, const char * const nick,
|
||||
const char * const message);
|
||||
void ui_room_subject(const char * const room_jid,
|
||||
const char * const subject);
|
||||
void ui_room_broadcast(const char * const room_jid,
|
||||
const char * const message);
|
||||
void ui_room_member_offline(const char * const room, const char * const nick);
|
||||
void ui_room_member_online(const char * const room,
|
||||
const char * const nick, const char * const show, const char * const status);
|
||||
void ui_room_member_nick_change(const char * const room,
|
||||
const char * const old_nick, const char * const nick);
|
||||
void ui_room_nick_change(const char * const room, const char * const nick);
|
||||
void ui_room_member_presence(const char * const room,
|
||||
const char * const nick, const char * const show, const char * const status);
|
||||
|
||||
// contact status functions
|
||||
void ui_status_room(const char * const contact);
|
||||
void ui_status(void);
|
||||
void ui_status_private(void);
|
||||
|
||||
// create windows
|
||||
void create_title_bar(void);
|
||||
@ -97,49 +125,9 @@ void title_bar_set_recipient(char *from);
|
||||
void title_bar_set_typing(gboolean is_typing);
|
||||
void title_bar_draw(void);
|
||||
|
||||
// current window actions
|
||||
void win_current_close(void);
|
||||
void win_current_clear(void);
|
||||
int win_current_is_console(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_current_show(const char * const msg, ...);
|
||||
void win_current_bad_show(const char * const msg);
|
||||
void win_current_page_off(void);
|
||||
|
||||
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_new_chat_win(const char * const to);
|
||||
|
||||
void win_join_chat(Jid *jid);
|
||||
void win_show_room_roster(const char * const room, GList *roster, const char * const presence);
|
||||
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,
|
||||
const char * const message);
|
||||
void win_show_room_subject(const char * const room_jid,
|
||||
const char * const subject);
|
||||
void win_show_room_broadcast(const char * const room_jid,
|
||||
const char * const message);
|
||||
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_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_room_show_status(const char * const contact);
|
||||
void win_room_show_info(const char * const contact);
|
||||
void win_show_status(void);
|
||||
void win_private_show_status(void);
|
||||
|
||||
// console window actions
|
||||
ProfWin* cons_create(void);
|
||||
void cons_show(const char * const msg, ...);
|
||||
void cons_about(void);
|
||||
void cons_help(void);
|
||||
void cons_basic_help(void);
|
||||
@ -154,15 +142,12 @@ void cons_show_log_prefs(void);
|
||||
void cons_show_presence_prefs(void);
|
||||
void cons_show_connection_prefs(void);
|
||||
void cons_show_account(ProfAccount *account);
|
||||
void cons_bad_command(const char * const cmd);
|
||||
void cons_show(const char * const cmd, ...);
|
||||
void cons_debug(const char * const msg, ...);
|
||||
void cons_show_time(void);
|
||||
void cons_show_word(const char * const word);
|
||||
void cons_bad_show(const char * const cmd, ...);
|
||||
void cons_show_error(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);
|
||||
void cons_show_status(const char * const contact);
|
||||
void cons_show_info(PContact pcontact);
|
||||
@ -178,6 +163,9 @@ void cons_show_disco_items(GSList *items, const char * const jid);
|
||||
void cons_show_disco_info(const char *from, GSList *identities, GSList *features);
|
||||
void cons_show_room_invite(const char * const invitor, const char * const room,
|
||||
const char * const reason);
|
||||
void cons_check_version(gboolean not_available_msg);
|
||||
void cons_show_typing(const char * const short_from);
|
||||
void cons_show_incoming_message(const char * const short_from, const int win_index);
|
||||
|
||||
// status bar actions
|
||||
void status_bar_refresh(void);
|
||||
@ -201,5 +189,4 @@ void inp_block(void);
|
||||
void inp_get_password(char *passwd);
|
||||
void inp_replace_input(char *input, const char * const new_input, int *size);
|
||||
|
||||
void notify_remind(void);
|
||||
#endif
|
||||
|
@ -38,7 +38,7 @@
|
||||
#define CONS_WIN_TITLE "_cons"
|
||||
|
||||
ProfWin*
|
||||
window_create(const char * const title, int cols, win_type_t type)
|
||||
win_create(const char * const title, int cols, win_type_t type)
|
||||
{
|
||||
ProfWin *new_win = malloc(sizeof(struct prof_win_t));
|
||||
new_win->from = strdup(title);
|
||||
@ -55,7 +55,7 @@ window_create(const char * const title, int cols, win_type_t type)
|
||||
}
|
||||
|
||||
void
|
||||
window_free(ProfWin* window)
|
||||
win_free(ProfWin* window)
|
||||
{
|
||||
delwin(window->win);
|
||||
free(window->from);
|
||||
@ -64,3 +64,98 @@ window_free(ProfWin* window)
|
||||
free(window);
|
||||
window = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
win_print_time(ProfWin* window, char show_char)
|
||||
{
|
||||
GDateTime *time = g_date_time_new_now_local();
|
||||
gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
|
||||
wattron(window->win, COLOUR_TIME);
|
||||
wprintw(window->win, "%s %c ", date_fmt, show_char);
|
||||
wattroff(window->win, COLOUR_TIME);
|
||||
g_date_time_unref(time);
|
||||
g_free(date_fmt);
|
||||
}
|
||||
|
||||
void
|
||||
win_presence_colour_on(ProfWin *window, const char * const presence)
|
||||
{
|
||||
if (g_strcmp0(presence, "online") == 0) {
|
||||
wattron(window->win, COLOUR_ONLINE);
|
||||
} else if (g_strcmp0(presence, "away") == 0) {
|
||||
wattron(window->win, COLOUR_AWAY);
|
||||
} else if (g_strcmp0(presence, "chat") == 0) {
|
||||
wattron(window->win, COLOUR_CHAT);
|
||||
} else if (g_strcmp0(presence, "dnd") == 0) {
|
||||
wattron(window->win, COLOUR_DND);
|
||||
} else if (g_strcmp0(presence, "xa") == 0) {
|
||||
wattron(window->win, COLOUR_XA);
|
||||
} else {
|
||||
wattron(window->win, COLOUR_OFFLINE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
win_presence_colour_off(ProfWin *window, const char * const presence)
|
||||
{
|
||||
if (g_strcmp0(presence, "online") == 0) {
|
||||
wattroff(window->win, COLOUR_ONLINE);
|
||||
} else if (g_strcmp0(presence, "away") == 0) {
|
||||
wattroff(window->win, COLOUR_AWAY);
|
||||
} else if (g_strcmp0(presence, "chat") == 0) {
|
||||
wattroff(window->win, COLOUR_CHAT);
|
||||
} else if (g_strcmp0(presence, "dnd") == 0) {
|
||||
wattroff(window->win, COLOUR_DND);
|
||||
} else if (g_strcmp0(presence, "xa") == 0) {
|
||||
wattroff(window->win, COLOUR_XA);
|
||||
} else {
|
||||
wattroff(window->win, COLOUR_OFFLINE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
win_show_contact(ProfWin *window, PContact contact)
|
||||
{
|
||||
const char *barejid = p_contact_barejid(contact);
|
||||
const char *name = p_contact_name(contact);
|
||||
const char *presence = p_contact_presence(contact);
|
||||
const char *status = p_contact_status(contact);
|
||||
GDateTime *last_activity = p_contact_last_activity(contact);
|
||||
|
||||
win_print_time(window, '-');
|
||||
win_presence_colour_on(window, presence);
|
||||
wprintw(window->win, "%s", barejid);
|
||||
|
||||
if (name != NULL) {
|
||||
wprintw(window->win, " (%s)", name);
|
||||
}
|
||||
|
||||
wprintw(window->win, " is %s", presence);
|
||||
|
||||
if (last_activity != NULL) {
|
||||
GDateTime *now = g_date_time_new_now_local();
|
||||
GTimeSpan span = g_date_time_difference(now, last_activity);
|
||||
|
||||
wprintw(window->win, ", idle ");
|
||||
|
||||
int hours = span / G_TIME_SPAN_HOUR;
|
||||
span = span - hours * G_TIME_SPAN_HOUR;
|
||||
if (hours > 0) {
|
||||
wprintw(window->win, "%dh", hours);
|
||||
}
|
||||
|
||||
int minutes = span / G_TIME_SPAN_MINUTE;
|
||||
span = span - minutes * G_TIME_SPAN_MINUTE;
|
||||
wprintw(window->win, "%dm", minutes);
|
||||
|
||||
int seconds = span / G_TIME_SPAN_SECOND;
|
||||
wprintw(window->win, "%ds", seconds);
|
||||
}
|
||||
|
||||
if (status != NULL) {
|
||||
wprintw(window->win, ", \"%s\"", p_contact_status(contact));
|
||||
}
|
||||
|
||||
wprintw(window->win, "\n");
|
||||
win_presence_colour_off(window, presence);
|
||||
}
|
||||
|
@ -23,7 +23,17 @@
|
||||
#ifndef WINDOW_H
|
||||
#define WINDOW_H
|
||||
|
||||
#include "ui/ui.h"
|
||||
#include "contact.h"
|
||||
|
||||
#define PAD_SIZE 1000
|
||||
|
||||
typedef enum {
|
||||
WIN_UNUSED,
|
||||
WIN_CONSOLE,
|
||||
WIN_CHAT,
|
||||
WIN_MUC,
|
||||
WIN_PRIVATE
|
||||
} win_type_t;
|
||||
|
||||
typedef struct prof_win_t {
|
||||
char *from;
|
||||
@ -35,8 +45,12 @@ typedef struct prof_win_t {
|
||||
int history_shown;
|
||||
} ProfWin;
|
||||
|
||||
ProfWin* win_create(const char * const title, int cols, win_type_t type);
|
||||
void win_free(ProfWin *window);
|
||||
|
||||
ProfWin* window_create(const char * const title, int cols, win_type_t type);
|
||||
void window_free(ProfWin *window);
|
||||
void win_print_time(ProfWin *window, char show_char);
|
||||
void win_presence_colour_on(ProfWin *window, const char * const presence);
|
||||
void win_presence_colour_off(ProfWin *window, const char * const presence);
|
||||
void win_show_contact(ProfWin *window, PContact contact);
|
||||
|
||||
#endif
|
||||
|
2881
src/ui/windows.c
2881
src/ui/windows.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user