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

Refactor layout creation

This commit is contained in:
James Booth 2014-12-16 20:53:23 +00:00
parent 630fef015d
commit 8f6167b45e
2 changed files with 53 additions and 85 deletions

View File

@ -76,17 +76,31 @@ win_occpuants_cols(void)
return CEILING( (((double)cols) / 100) * occupants_win_percent); return CEILING( (((double)cols) / 100) * occupants_win_percent);
} }
ProfWin* static ProfLayout*
win_create_console(void) _win_create_simple_layout(void)
{ {
ProfConsoleWin *new_win = malloc(sizeof(ProfConsoleWin));
int cols = getmaxx(stdscr); int cols = getmaxx(stdscr);
new_win->super.type = WIN_CONSOLE; ProfLayoutSimple *layout = malloc(sizeof(ProfLayoutSimple));
layout->super.type = LAYOUT_SIMPLE;
layout->super.win = newpad(PAD_SIZE, cols);
wbkgd(layout->super.win, theme_attrs(THEME_TEXT));
layout->super.buffer = buffer_create();
layout->super.y_pos = 0;
layout->super.paged = 0;
scrollok(layout->super.win, TRUE);
return &layout->super;
}
static ProfLayout*
_win_create_split_layout(void)
{
int cols = getmaxx(stdscr);
ProfLayoutSplit *layout = malloc(sizeof(ProfLayoutSplit)); ProfLayoutSplit *layout = malloc(sizeof(ProfLayoutSplit));
layout->super.type = LAYOUT_SPLIT; layout->super.type = LAYOUT_SPLIT;
layout->super.win = newpad(PAD_SIZE, (cols)); layout->super.win = newpad(PAD_SIZE, cols);
wbkgd(layout->super.win, theme_attrs(THEME_TEXT)); wbkgd(layout->super.win, theme_attrs(THEME_TEXT));
layout->super.buffer = buffer_create(); layout->super.buffer = buffer_create();
layout->super.y_pos = 0; layout->super.y_pos = 0;
@ -94,43 +108,37 @@ win_create_console(void)
scrollok(layout->super.win, TRUE); scrollok(layout->super.win, TRUE);
layout->subwin = NULL; layout->subwin = NULL;
layout->sub_y_pos = 0; layout->sub_y_pos = 0;
new_win->super.layout = (ProfLayout*)layout;
ProfWin *profwin = (ProfWin*)new_win; return &layout->super;
profwin->from = strdup(CONS_WIN_TITLE); }
profwin->unread = 0;
return (ProfWin*)new_win; ProfWin*
win_create_console(void)
{
ProfConsoleWin *new_win = malloc(sizeof(ProfConsoleWin));
new_win->super.type = WIN_CONSOLE;
new_win->super.layout = _win_create_split_layout();
new_win->super.from = strdup(CONS_WIN_TITLE);
new_win->super.unread = 0;
return &new_win->super;
} }
ProfWin* ProfWin*
win_create_chat(const char * const barejid) win_create_chat(const char * const barejid)
{ {
ProfChatWin *new_win = malloc(sizeof(ProfChatWin)); ProfChatWin *new_win = malloc(sizeof(ProfChatWin));
int cols = getmaxx(stdscr);
new_win->super.type = WIN_CHAT; new_win->super.type = WIN_CHAT;
new_win->super.layout = _win_create_simple_layout();
ProfLayoutSingle *layout = malloc(sizeof(ProfLayoutSingle)); new_win->super.from = strdup(barejid);
layout->super.type = LAYOUT_SINGLE; new_win->super.unread = 0;
layout->super.win = newpad(PAD_SIZE, (cols));
wbkgd(layout->super.win, theme_attrs(THEME_TEXT));
layout->super.buffer = buffer_create();
layout->super.y_pos = 0;
layout->super.paged = 0;
scrollok(layout->super.win, TRUE);
new_win->super.layout = (ProfLayout*)layout;
ProfWin *profwin = (ProfWin*)new_win;
profwin->from = strdup(barejid);
profwin->unread = 0;
new_win->resource = NULL; new_win->resource = NULL;
new_win->is_otr = FALSE; new_win->is_otr = FALSE;
new_win->is_trusted = FALSE; new_win->is_trusted = FALSE;
new_win->history_shown = FALSE; new_win->history_shown = FALSE;
return (ProfWin*)new_win; return &new_win->super;
} }
ProfWin* ProfWin*
@ -162,88 +170,48 @@ win_create_muc(const char * const roomjid)
scrollok(layout->super.win, TRUE); scrollok(layout->super.win, TRUE);
new_win->super.layout = (ProfLayout*)layout; new_win->super.layout = (ProfLayout*)layout;
ProfWin *profwin = (ProfWin*)new_win; new_win->super.from = strdup(roomjid);
profwin->from = strdup(roomjid); new_win->super.unread = 0;
profwin->unread = 0;
return (ProfWin*)new_win; return &new_win->super;
} }
ProfWin* ProfWin*
win_create_muc_config(const char * const title, DataForm *form) win_create_muc_config(const char * const title, DataForm *form)
{ {
ProfMucConfWin *new_win = malloc(sizeof(ProfMucConfWin)); ProfMucConfWin *new_win = malloc(sizeof(ProfMucConfWin));
int cols = getmaxx(stdscr);
new_win->super.type = WIN_MUC_CONFIG; new_win->super.type = WIN_MUC_CONFIG;
new_win->super.layout = _win_create_simple_layout();
ProfLayoutSingle *layout = malloc(sizeof(ProfLayoutSingle)); new_win->super.from = strdup(title);
layout->super.type = LAYOUT_SINGLE; new_win->super.unread = 0;
layout->super.win = newpad(PAD_SIZE, (cols));
wbkgd(layout->super.win, theme_attrs(THEME_TEXT));
layout->super.buffer = buffer_create();
layout->super.y_pos = 0;
layout->super.paged = 0;
scrollok(layout->super.win, TRUE);
new_win->super.layout = (ProfLayout*)layout;
new_win->form = form; new_win->form = form;
ProfWin *profwin = (ProfWin*)new_win; return &new_win->super;
profwin->from = strdup(title);
profwin->unread = 0;
return (ProfWin*)new_win;
} }
ProfWin* ProfWin*
win_create_private(const char * const fulljid) win_create_private(const char * const fulljid)
{ {
ProfPrivateWin *new_win = malloc(sizeof(ProfPrivateWin)); ProfPrivateWin *new_win = malloc(sizeof(ProfPrivateWin));
int cols = getmaxx(stdscr);
new_win->super.type = WIN_PRIVATE; new_win->super.type = WIN_PRIVATE;
new_win->super.layout = _win_create_simple_layout();
new_win->super.from = strdup(fulljid);
new_win->super.unread = 0;
ProfLayoutSingle *layout = malloc(sizeof(ProfLayoutSingle)); return &new_win->super;
layout->super.type = LAYOUT_SINGLE;
layout->super.win = newpad(PAD_SIZE, (cols));
wbkgd(layout->super.win, theme_attrs(THEME_TEXT));
layout->super.buffer = buffer_create();
layout->super.y_pos = 0;
layout->super.paged = 0;
scrollok(layout->super.win, TRUE);
new_win->super.layout = (ProfLayout*)layout;
ProfWin *profwin = (ProfWin*)new_win;
profwin->from = strdup(fulljid);
profwin->unread = 0;
return (ProfWin*)new_win;
} }
ProfWin* ProfWin*
win_create_xmlconsole(void) win_create_xmlconsole(void)
{ {
ProfXMLWin *new_win = malloc(sizeof(ProfXMLWin)); ProfXMLWin *new_win = malloc(sizeof(ProfXMLWin));
int cols = getmaxx(stdscr);
new_win->super.type = WIN_XML; new_win->super.type = WIN_XML;
new_win->super.layout = _win_create_simple_layout();
new_win->super.from = strdup(XML_WIN_TITLE);
new_win->super.unread = 0;
ProfLayoutSingle *layout = malloc(sizeof(ProfLayoutSingle)); return &new_win->super;
layout->super.type = LAYOUT_SINGLE;
layout->super.win = newpad(PAD_SIZE, (cols));
wbkgd(layout->super.win, theme_attrs(THEME_TEXT));
layout->super.buffer = buffer_create();
layout->super.y_pos = 0;
layout->super.paged = 0;
scrollok(layout->super.win, TRUE);
new_win->super.layout = (ProfLayout*)layout;
ProfWin *profwin = (ProfWin*)new_win;
profwin->from = strdup(XML_WIN_TITLE);
profwin->unread = 0;
return (ProfWin*)new_win;
} }
void void

View File

@ -57,7 +57,7 @@
#define PAD_SIZE 1000 #define PAD_SIZE 1000
typedef enum { typedef enum {
LAYOUT_SINGLE, LAYOUT_SIMPLE,
LAYOUT_SPLIT LAYOUT_SPLIT
} layout_type_t; } layout_type_t;
@ -69,9 +69,9 @@ typedef struct prof_layout_t {
int paged; int paged;
} ProfLayout; } ProfLayout;
typedef struct prof_layout_single_t { typedef struct prof_layout_simple_t {
ProfLayout super; ProfLayout super;
} ProfLayoutSingle; } ProfLayoutSimple;
typedef struct prof_layout_split_t { typedef struct prof_layout_split_t {
ProfLayout super; ProfLayout super;