1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Moved cons_show_login_success() to console module

This commit is contained in:
James Booth 2013-04-21 00:21:30 +01:00
parent c7100203e4
commit a234ba0cd6
7 changed files with 90 additions and 132 deletions

View File

@ -10,7 +10,7 @@ profanity_SOURCES = src/contact.c src/contact.h src/log.c src/common.c \
src/xmpp/capabilities.h src/xmpp/connection.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/windows.c \
src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \
src/ui/console.h src/ui/console.c \ src/ui/console.c \
src/command/command.h src/command/command.c src/command/history.c \ src/command/command.h src/command/command.c src/command/history.c \
src/command/history.h src/command/parser.c \ src/command/history.h src/command/parser.c \
src/command/parser.h \ src/command/parser.h \

View File

@ -33,6 +33,7 @@
#include "config/preferences.h" #include "config/preferences.h"
#include "config/theme.h" #include "config/theme.h"
#include "ui/window.h" #include "ui/window.h"
#include "ui/ui.h"
#define CONS_WIN_TITLE "_cons" #define CONS_WIN_TITLE "_cons"
@ -149,6 +150,24 @@ cons_check_version(gboolean not_available_msg)
} }
} }
void
cons_show_login_success(ProfAccount *account)
{
window_show_time(console, '-');
wprintw(console->win, "%s logged in successfully, ", account->jid);
resource_presence_t presence = accounts_get_login_presence(account->name);
const char *presence_str = string_from_resource_presence(presence);
window_presence_colour_on(console, presence_str);
wprintw(console->win, "%s", presence_str);
window_presence_colour_off(console, presence_str);
wprintw(console->win, " (priority %d)",
accounts_get_priority_for_presence_type(account->name, presence));
wprintw(console->win, ".\n");
}
static void static void
_cons_splash_logo(void) _cons_splash_logo(void)
{ {

View File

@ -1,35 +0,0 @@
/*
* console.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/>.
*
*/
#ifndef CONSOLE_H
#define CONSOLE_H
#include "ui/window.h"
ProfWin* cons_create(void);
void cons_refresh(void);
void cons_show(const char * const msg, ...);
void cons_about(void);
void cons_check_version(gboolean not_available_msg);
#endif

View File

@ -36,28 +36,10 @@
#include "contact.h" #include "contact.h"
#include "jid.h" #include "jid.h"
#include "ui/window.h"
#include "xmpp/xmpp.h" #include "xmpp/xmpp.h"
#define INP_WIN_MAX 1000 #define INP_WIN_MAX 1000
#define PAD_SIZE 1000
typedef enum {
WIN_UNUSED,
WIN_CONSOLE,
WIN_CHAT,
WIN_MUC,
WIN_PRIVATE
} win_type_t;
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 // gui startup and shutdown, resize
void ui_init(void); void ui_init(void);
@ -140,6 +122,9 @@ void win_show_status(void);
void win_private_show_status(void); void win_private_show_status(void);
// console window actions // console window actions
ProfWin* cons_create(void);
void cons_refresh(void);
void cons_show(const char * const msg, ...);
void cons_about(void); void cons_about(void);
void cons_help(void); void cons_help(void);
void cons_basic_help(void); void cons_basic_help(void);
@ -155,14 +140,12 @@ void cons_show_presence_prefs(void);
void cons_show_connection_prefs(void); void cons_show_connection_prefs(void);
void cons_show_account(ProfAccount *account); void cons_show_account(ProfAccount *account);
void cons_bad_command(const char * const cmd); void cons_bad_command(const char * const cmd);
void cons_show(const char * const cmd, ...);
void cons_debug(const char * const msg, ...); void cons_debug(const char * const msg, ...);
void cons_show_time(void); void cons_show_time(void);
void cons_show_word(const char * const word); void cons_show_word(const char * const word);
void cons_bad_show(const char * const cmd, ...); void cons_bad_show(const char * const cmd, ...);
void cons_highlight_show(const char * const cmd); void cons_highlight_show(const char * const cmd);
void cons_show_contacts(GSList * list); void cons_show_contacts(GSList * list);
void cons_check_version(gboolean not_available_msg);
void cons_show_wins(void); void cons_show_wins(void);
void cons_show_status(const char * const contact); void cons_show_status(const char * const contact);
void cons_show_info(PContact pcontact); void cons_show_info(PContact pcontact);
@ -178,6 +161,7 @@ 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_disco_info(const char *from, GSList *identities, GSList *features);
void cons_show_room_invite(const char * const invitor, const char * const room, void cons_show_room_invite(const char * const invitor, const char * const room,
const char * const reason); const char * const reason);
void cons_check_version(gboolean not_available_msg);
// status bar actions // status bar actions
void status_bar_refresh(void); void status_bar_refresh(void);

View File

@ -76,3 +76,40 @@ window_show_time(ProfWin* window, char show_char)
g_date_time_unref(time); g_date_time_unref(time);
g_free(date_fmt); g_free(date_fmt);
} }
void
window_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
window_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);
}
}

View File

@ -23,7 +23,15 @@
#ifndef WINDOW_H #ifndef WINDOW_H
#define WINDOW_H #define WINDOW_H
#include "ui/ui.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 { typedef struct prof_win_t {
char *from; char *from;
@ -35,10 +43,11 @@ typedef struct prof_win_t {
int history_shown; int history_shown;
} ProfWin; } ProfWin;
ProfWin* window_create(const char * const title, int cols, win_type_t type); ProfWin* window_create(const char * const title, int cols, win_type_t type);
void window_free(ProfWin *window); void window_free(ProfWin *window);
void window_show_time(ProfWin* window, char show_char); void window_show_time(ProfWin *window, char show_char);
void window_presence_colour_on(ProfWin *window, const char * const presence);
void window_presence_colour_off(ProfWin *window, const char * const presence);
#endif #endif

View File

@ -50,7 +50,6 @@
#include "jid.h" #include "jid.h"
#include "log.h" #include "log.h"
#include "muc.h" #include "muc.h"
#include "ui/console.h"
#include "ui/ui.h" #include "ui/ui.h"
#include "ui/window.h" #include "ui/window.h"
@ -102,8 +101,6 @@ static void _win_show_history(WINDOW *win, int win_index,
const char * const contact); const char * const contact);
static void _win_show_info(ProfWin *window, PContact pcontact); static void _win_show_info(ProfWin *window, PContact pcontact);
static void _ui_draw_win_title(void); static void _ui_draw_win_title(void);
static void _presence_colour_on(WINDOW *win, const char * const presence);
static void _presence_colour_off(WINDOW *win, const char * const presence);
static void _notify(const char * const message, int timeout, static void _notify(const char * const message, int timeout,
const char * const category); const char * const category);
@ -883,9 +880,9 @@ win_show_room_roster(const char * const room, GList *roster, const char * const
const char const *nick = p_contact_barejid(member); const char const *nick = p_contact_barejid(member);
const char const *show = p_contact_presence(member); const char const *show = p_contact_presence(member);
_presence_colour_on(window->win, show); window_presence_colour_on(window, show);
wprintw(window->win, "%s", nick); wprintw(window->win, "%s", nick);
_presence_colour_off(window->win, show); window_presence_colour_off(window, show);
if (roster->next != NULL) { if (roster->next != NULL) {
wprintw(window->win, ", "); wprintw(window->win, ", ");
@ -1115,23 +1112,6 @@ win_show_room_broadcast(const char * const room_jid, const char * const message)
} }
} }
void
cons_show_login_success(ProfAccount *account)
{
window_show_time(console, '-');
wprintw(console->win, "%s logged in successfully, ", account->jid);
resource_presence_t presence = accounts_get_login_presence(account->name);
const char *presence_str = string_from_resource_presence(presence);
_presence_colour_on(console->win, presence_str);
wprintw(console->win, "%s", presence_str);
_presence_colour_off(console->win, presence_str);
wprintw(console->win, " (priority %d)",
accounts_get_priority_for_presence_type(account->name, presence));
wprintw(console->win, ".\n");
}
void void
cons_show_wins(void) cons_show_wins(void)
@ -1222,9 +1202,9 @@ cons_show_caps(const char * const contact, Resource *resource)
cons_show(""); cons_show("");
const char *resource_presence = string_from_resource_presence(resource->presence); const char *resource_presence = string_from_resource_presence(resource->presence);
window_show_time(console, '-'); window_show_time(console, '-');
_presence_colour_on(win, resource_presence); window_presence_colour_on(console, resource_presence);
wprintw(console->win, "%s", contact); wprintw(console->win, "%s", contact);
_presence_colour_off(win, resource_presence); window_presence_colour_off(console, resource_presence);
wprintw(win, ":\n"); wprintw(win, ":\n");
if (resource->caps_str != NULL) { if (resource->caps_str != NULL) {
@ -1302,9 +1282,9 @@ cons_show_software_version(const char * const jid, const char * const presence,
if ((name != NULL) || (version != NULL) || (os != NULL)) { if ((name != NULL) || (version != NULL) || (os != NULL)) {
cons_show(""); cons_show("");
window_show_time(console, '-'); window_show_time(console, '-');
_presence_colour_on(console->win, presence); window_presence_colour_on(console, presence);
wprintw(console->win, "%s", jid); wprintw(console->win, "%s", jid);
_presence_colour_off(console->win, presence); window_presence_colour_off(console, presence);
wprintw(console->win, ":\n"); wprintw(console->win, ":\n");
} }
if (name != NULL) { if (name != NULL) {
@ -1455,9 +1435,9 @@ cons_show_account_list(gchar **accounts)
(g_strcmp0(jabber_get_account_name(), accounts[i]) == 0)) { (g_strcmp0(jabber_get_account_name(), accounts[i]) == 0)) {
resource_presence_t presence = accounts_get_last_presence(accounts[i]); resource_presence_t presence = accounts_get_last_presence(accounts[i]);
window_show_time(console, '-'); window_show_time(console, '-');
_presence_colour_on(console->win, string_from_resource_presence(presence)); window_presence_colour_on(console, string_from_resource_presence(presence));
wprintw(console->win, "%s\n", accounts[i]); wprintw(console->win, "%s\n", accounts[i]);
_presence_colour_off(console->win, string_from_resource_presence(presence)); window_presence_colour_off(console, string_from_resource_presence(presence));
} else { } else {
cons_show(accounts[i]); cons_show(accounts[i]);
} }
@ -1519,13 +1499,13 @@ cons_show_account(ProfAccount *account)
Resource *resource = ordered_resources->data; Resource *resource = ordered_resources->data;
const char *resource_presence = string_from_resource_presence(resource->presence); const char *resource_presence = string_from_resource_presence(resource->presence);
window_show_time(console, '-'); window_show_time(console, '-');
_presence_colour_on(win, resource_presence); window_presence_colour_on(console, resource_presence);
wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence); wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence);
if (resource->status != NULL) { if (resource->status != NULL) {
wprintw(win, ", \"%s\"", resource->status); wprintw(win, ", \"%s\"", resource->status);
} }
wprintw(win, "\n"); wprintw(win, "\n");
_presence_colour_off(win, resource_presence); window_presence_colour_off(console, resource_presence);
if (resource->caps_str != NULL) { if (resource->caps_str != NULL) {
Capabilities *caps = caps_get(resource->caps_str); Capabilities *caps = caps_get(resource->caps_str);
@ -2226,42 +2206,6 @@ _win_resize_all(void)
prefresh(current->win, current->y_pos, 0, 1, 0, rows-3, cols-1); prefresh(current->win, current->y_pos, 0, 1, 0, rows-3, cols-1);
} }
static void
_presence_colour_on(WINDOW *win, const char * const presence)
{
if (g_strcmp0(presence, "online") == 0) {
wattron(win, COLOUR_ONLINE);
} else if (g_strcmp0(presence, "away") == 0) {
wattron(win, COLOUR_AWAY);
} else if (g_strcmp0(presence, "chat") == 0) {
wattron(win, COLOUR_CHAT);
} else if (g_strcmp0(presence, "dnd") == 0) {
wattron(win, COLOUR_DND);
} else if (g_strcmp0(presence, "xa") == 0) {
wattron(win, COLOUR_XA);
} else {
wattron(win, COLOUR_OFFLINE);
}
}
static void
_presence_colour_off(WINDOW *win, const char * const presence)
{
if (g_strcmp0(presence, "online") == 0) {
wattroff(win, COLOUR_ONLINE);
} else if (g_strcmp0(presence, "away") == 0) {
wattroff(win, COLOUR_AWAY);
} else if (g_strcmp0(presence, "chat") == 0) {
wattroff(win, COLOUR_CHAT);
} else if (g_strcmp0(presence, "dnd") == 0) {
wattroff(win, COLOUR_DND);
} else if (g_strcmp0(presence, "xa") == 0) {
wattroff(win, COLOUR_XA);
} else {
wattroff(win, COLOUR_OFFLINE);
}
}
static void static void
_show_status_string(ProfWin *window, const char * const from, _show_status_string(ProfWin *window, const char * const from,
const char * const show, const char * const status, const char * const show, const char * const status,
@ -2376,7 +2320,7 @@ _win_show_contact(ProfWin *window, PContact contact)
GDateTime *last_activity = p_contact_last_activity(contact); GDateTime *last_activity = p_contact_last_activity(contact);
window_show_time(window, '-'); window_show_time(window, '-');
_presence_colour_on(window->win, presence); window_presence_colour_on(window, presence);
wprintw(window->win, "%s", barejid); wprintw(window->win, "%s", barejid);
if (name != NULL) { if (name != NULL) {
@ -2410,7 +2354,7 @@ _win_show_contact(ProfWin *window, PContact contact)
} }
wprintw(window->win, "\n"); wprintw(window->win, "\n");
_presence_colour_off(window->win, presence); window_presence_colour_off(window, presence);
} }
static void static void
@ -2559,12 +2503,12 @@ _win_show_info(ProfWin *window, PContact pcontact)
window_show_time(window, '-'); window_show_time(window, '-');
wprintw(win, "\n"); wprintw(win, "\n");
window_show_time(window, '-'); window_show_time(window, '-');
_presence_colour_on(win, presence); window_presence_colour_on(window, presence);
wprintw(win, "%s", barejid); wprintw(win, "%s", barejid);
if (name != NULL) { if (name != NULL) {
wprintw(win, " (%s)", name); wprintw(win, " (%s)", name);
} }
_presence_colour_off(win, presence); window_presence_colour_off(window, presence);
wprintw(win, ":\n"); wprintw(win, ":\n");
if (sub != NULL) { if (sub != NULL) {
@ -2614,13 +2558,13 @@ _win_show_info(ProfWin *window, PContact pcontact)
Resource *resource = ordered_resources->data; Resource *resource = ordered_resources->data;
const char *resource_presence = string_from_resource_presence(resource->presence); const char *resource_presence = string_from_resource_presence(resource->presence);
window_show_time(window, '-'); window_show_time(window, '-');
_presence_colour_on(win, resource_presence); window_presence_colour_on(window, resource_presence);
wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence); wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence);
if (resource->status != NULL) { if (resource->status != NULL) {
wprintw(win, ", \"%s\"", resource->status); wprintw(win, ", \"%s\"", resource->status);
} }
wprintw(win, "\n"); wprintw(win, "\n");
_presence_colour_off(win, resource_presence); window_presence_colour_off(window, resource_presence);
if (resource->caps_str != NULL) { if (resource->caps_str != NULL) {
Capabilities *caps = caps_get(resource->caps_str); Capabilities *caps = caps_get(resource->caps_str);