1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-22 19:45:54 -04:00

Added window specific creation functions

This commit is contained in:
James Booth 2014-12-15 00:28:28 +00:00
parent 3cef4e1db4
commit 070547a7ff
6 changed files with 136 additions and 63 deletions

View File

@ -931,11 +931,11 @@ _ui_next_win(void)
}
static void
_ui_gone_secure(const char * const recipient, gboolean trusted)
_ui_gone_secure(const char * const barejid, gboolean trusted)
{
ProfWin *window = wins_get_by_recipient(recipient);
ProfWin *window = wins_get_by_recipient(barejid);
if (window == NULL) {
window = wins_new(recipient, WIN_CHAT);
window = wins_new_chat(barejid);
}
if (window->type != WIN_CHAT) {
@ -964,7 +964,7 @@ _ui_gone_secure(const char * const recipient, gboolean trusted)
if (ui_index == 10) {
ui_index = 0;
}
cons_show("%s started an OTR session (%d).", recipient, ui_index);
cons_show("%s started an OTR session (%d).", barejid, ui_index);
cons_alert();
}
}
@ -1380,9 +1380,9 @@ _ui_new_chat_win(const char * const to)
Jid *jid = jid_create(to);
if (muc_active(jid->barejid)) {
window = wins_new(to, WIN_PRIVATE);
window = wins_new_private(to);
} else {
window = wins_new(to, WIN_CHAT);
window = wins_new_chat(to);
}
jid_destroy(jid);
@ -1409,7 +1409,7 @@ _ui_new_chat_win(const char * const to)
static void
_ui_create_xmlconsole_win(void)
{
ProfWin *window = wins_new("XML Console", WIN_XML);
ProfWin *window = wins_new_xmlconsole();
int num = wins_get_num(window);
ui_switch_win(num);
}
@ -1437,9 +1437,9 @@ _ui_outgoing_msg(const char * const from, const char * const to,
Jid *jid = jid_create(to);
if (muc_active(jid->barejid)) {
window = wins_new(to, WIN_PRIVATE);
window = wins_new_private(to);
} else {
window = wins_new(to, WIN_CHAT);
window = wins_new_chat(to);
#ifdef HAVE_LIBOTR
if (otr_is_secure(to)) {
window->wins.chat.is_otr = TRUE;
@ -1479,7 +1479,7 @@ _ui_room_join(const char * const room, gboolean focus)
// create new window
if (window == NULL) {
window = wins_new(room, WIN_MUC);
window = wins_new_muc(room);
}
char *nick = muc_nick(room);
@ -2715,11 +2715,9 @@ _ui_handle_room_configuration(const char * const room, DataForm *form)
{
GString *title = g_string_new(room);
g_string_append(title, " config");
ProfWin *window = wins_new(title->str, WIN_MUC_CONFIG);
ProfWin *window = wins_new_muc_config(title->str, form);
g_string_free(title, TRUE);
window->wins.conf.form = form;
int num = wins_get_num(window);
ui_switch_win(num);

View File

@ -70,7 +70,7 @@ gboolean (*ui_switch_win)(const int i);
void (*ui_next_win)(void);
void (*ui_previous_win)(void);
void (*ui_gone_secure)(const char * const recipient, gboolean trusted);
void (*ui_gone_secure)(const char * const barejid, gboolean trusted);
void (*ui_gone_insecure)(const char * const recipient);
void (*ui_trust)(const char * const recipient);
void (*ui_untrust)(const char * const recipient);

View File

@ -51,6 +51,9 @@
#include "ui/window.h"
#include "xmpp/xmpp.h"
#define CONS_WIN_TITLE "_cons"
#define XML_WIN_TITLE "XML Console"
#define CEILING(X) (X-(int)(X) > 0 ? (int)(X+1) : (int)(X))
static void _win_print(ProfWin *window, const char show_char, GDateTime *time,
@ -73,6 +76,30 @@ win_occpuants_cols(void)
return CEILING( (((double)cols) / 100) * occupants_win_percent);
}
ProfWin*
win_create_console(void)
{
ProfWin *new_win = malloc(sizeof(ProfWin));
int cols = getmaxx(stdscr);
new_win->type = WIN_CONSOLE;
new_win->win = newpad(PAD_SIZE, (cols));
wbkgd(new_win->win, theme_attrs(THEME_TEXT));
new_win->wins.cons.subwin = NULL;
new_win->wins.cons.sub_y_pos = 0;
new_win->from = strdup(CONS_WIN_TITLE);
new_win->buffer = buffer_create();
new_win->y_pos = 0;
new_win->paged = 0;
new_win->unread = 0;
scrollok(new_win->win, TRUE);
return new_win;
}
ProfWin*
win_create_chat(const char * const barejid)
{
@ -100,6 +127,62 @@ win_create_chat(const char * const barejid)
return new_win;
}
ProfWin*
win_create_muc(const char * const roomjid)
{
ProfWin *new_win = malloc(sizeof(ProfWin));
int cols = getmaxx(stdscr);
new_win->type = WIN_MUC;
if (prefs_get_boolean(PREF_OCCUPANTS)) {
int subwin_cols = win_occpuants_cols();
new_win->win = newpad(PAD_SIZE, cols - subwin_cols);
wbkgd(new_win->win, theme_attrs(THEME_TEXT));
new_win->wins.muc.subwin = newpad(PAD_SIZE, subwin_cols);;
wbkgd(new_win->wins.muc.subwin, theme_attrs(THEME_TEXT));
} else {
new_win->win = newpad(PAD_SIZE, (cols));
wbkgd(new_win->win, theme_attrs(THEME_TEXT));
new_win->wins.muc.subwin = NULL;
}
new_win->wins.muc.sub_y_pos = 0;
new_win->from = strdup(roomjid);
new_win->buffer = buffer_create();
new_win->y_pos = 0;
new_win->paged = 0;
new_win->unread = 0;
scrollok(new_win->win, TRUE);
return new_win;
}
ProfWin*
win_create_muc_config(const char * const title, DataForm *form)
{
ProfWin *new_win = malloc(sizeof(ProfWin));
int cols = getmaxx(stdscr);
new_win->type = WIN_MUC_CONFIG;
new_win->win = newpad(PAD_SIZE, (cols));
wbkgd(new_win->win, theme_attrs(THEME_TEXT));
new_win->wins.conf.form = form;
new_win->from = strdup(title);
new_win->buffer = buffer_create();
new_win->y_pos = 0;
new_win->paged = 0;
new_win->unread = 0;
scrollok(new_win->win, TRUE);
return new_win;
}
ProfWin*
win_create_private(const char * const fulljid)
{
@ -124,57 +207,22 @@ win_create_private(const char * const fulljid)
}
ProfWin*
win_create(const char * const title, win_type_t type)
win_create_xmlconsole(void)
{
ProfWin *new_win = malloc(sizeof(ProfWin));
int cols = getmaxx(stdscr);
new_win->type = type;
new_win->type = WIN_XML;
switch (new_win->type) {
case WIN_CONSOLE:
new_win->win = newpad(PAD_SIZE, (cols));
wbkgd(new_win->win, theme_attrs(THEME_TEXT));
new_win->wins.cons.subwin = NULL;
new_win->wins.cons.sub_y_pos = 0;
break;
case WIN_MUC:
if (prefs_get_boolean(PREF_OCCUPANTS)) {
int subwin_cols = win_occpuants_cols();
new_win->win = newpad(PAD_SIZE, cols - subwin_cols);
wbkgd(new_win->win, theme_attrs(THEME_TEXT));
new_win->wins.muc.subwin = newpad(PAD_SIZE, subwin_cols);;
wbkgd(new_win->wins.muc.subwin, theme_attrs(THEME_TEXT));
} else {
new_win->win = newpad(PAD_SIZE, (cols));
wbkgd(new_win->win, theme_attrs(THEME_TEXT));
new_win->wins.muc.subwin = NULL;
}
new_win->wins.muc.sub_y_pos = 0;
break;
default:
new_win->win = newpad(PAD_SIZE, (cols));
wbkgd(new_win->win, theme_attrs(THEME_TEXT));
break;
}
new_win->win = newpad(PAD_SIZE, (cols));
wbkgd(new_win->win, theme_attrs(THEME_TEXT));
if (new_win->type == WIN_MUC_CONFIG) {
new_win->wins.conf.form = NULL;
}
new_win->from = strdup(title);
new_win->from = strdup(XML_WIN_TITLE);
new_win->buffer = buffer_create();
new_win->y_pos = 0;
new_win->paged = 0;
new_win->unread = 0;
if (new_win->type == WIN_CHAT) {
new_win->wins.chat.resource = NULL;
new_win->wins.chat.is_otr = FALSE;
new_win->wins.chat.is_trusted = FALSE;
new_win->wins.chat.history_shown = FALSE;
}
scrollok(new_win->win, TRUE);
return new_win;

View File

@ -110,9 +110,12 @@ typedef struct prof_win_t {
} wins;
} ProfWin;
ProfWin* win_create(const char * const title, win_type_t type);
ProfWin* win_create_console(void);
ProfWin* win_create_chat(const char * const barejid);
ProfWin* win_create_muc(const char * const roomjid);
ProfWin* win_create_muc_config(const char * const title, DataForm *form);
ProfWin* win_create_private(const char * const fulljid);
ProfWin* win_create_xmlconsole(void);
void win_free(ProfWin *window);
void win_update_virtual(ProfWin *window);

View File

@ -52,8 +52,6 @@
#include "ui/window.h"
#include "ui/windows.h"
#define CONS_WIN_TITLE "_cons"
static GHashTable *windows;
static int current;
static int max_cols;
@ -65,7 +63,7 @@ wins_init(void)
(GDestroyNotify)win_free);
max_cols = getmaxx(stdscr);
ProfWin *console = win_create(CONS_WIN_TITLE, WIN_CONSOLE);
ProfWin *console = win_create_console();
g_hash_table_insert(windows, GINT_TO_POINTER(1), console);
current = 1;
@ -256,11 +254,11 @@ wins_is_current(ProfWin *window)
}
ProfWin *
wins_new(const char * const from, win_type_t type)
wins_new_xmlconsole(void)
{
GList *keys = g_hash_table_get_keys(windows);
int result = get_next_available_win_num(keys);
ProfWin *new = win_create(from, type);
ProfWin *new = win_create_xmlconsole();
g_hash_table_insert(windows, GINT_TO_POINTER(result), new);
g_list_free(keys);
return new;
@ -277,6 +275,28 @@ wins_new_chat(const char * const barejid)
return new;
}
ProfWin *
wins_new_muc(const char * const roomjid)
{
GList *keys = g_hash_table_get_keys(windows);
int result = get_next_available_win_num(keys);
ProfWin *new = win_create_muc(roomjid);
g_hash_table_insert(windows, GINT_TO_POINTER(result), new);
g_list_free(keys);
return new;
}
ProfWin *
wins_new_muc_config(const char * const title, DataForm *form)
{
GList *keys = g_hash_table_get_keys(windows);
int result = get_next_available_win_num(keys);
ProfWin *new = win_create_muc_config(title, form);
g_hash_table_insert(windows, GINT_TO_POINTER(result), new);
g_list_free(keys);
return new;
}
ProfWin *
wins_new_private(const char * const fulljid)
{

View File

@ -36,6 +36,13 @@
#define UI_WINDOWS_H
void wins_init(void);
ProfWin * wins_new_xmlconsole(void);
ProfWin * wins_new_chat(const char * const barejid);
ProfWin * wins_new_muc(const char * const roomjid);
ProfWin * wins_new_muc_config(const char * const title, DataForm *form);
ProfWin * wins_new_private(const char * const fulljid);
ProfWin * wins_get_console(void);
ProfWin * wins_get_current(void);
void wins_set_current_by_num(int i);
@ -49,9 +56,6 @@ void wins_close_current(void);
void wins_close_by_num(int i);
void wins_clear_current(void);
gboolean wins_is_current(ProfWin *window);
ProfWin * wins_new(const char * const from, win_type_t type);
ProfWin * wins_new_chat(const char * const barejid);
ProfWin * wins_new_private(const char * const fulljid);
int wins_get_total_unread(void);
void wins_resize_all(void);
GSList * wins_get_chat_recipients(void);