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);
}
ProfWin*
win_create_console(void)
static ProfLayout*
_win_create_simple_layout(void)
{
ProfConsoleWin *new_win = malloc(sizeof(ProfConsoleWin));
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));
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));
layout->super.buffer = buffer_create();
layout->super.y_pos = 0;
@ -94,43 +108,37 @@ win_create_console(void)
scrollok(layout->super.win, TRUE);
layout->subwin = NULL;
layout->sub_y_pos = 0;
new_win->super.layout = (ProfLayout*)layout;
ProfWin *profwin = (ProfWin*)new_win;
profwin->from = strdup(CONS_WIN_TITLE);
profwin->unread = 0;
return &layout->super;
}
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*
win_create_chat(const char * const barejid)
{
ProfChatWin *new_win = malloc(sizeof(ProfChatWin));
int cols = getmaxx(stdscr);
new_win->super.type = WIN_CHAT;
ProfLayoutSingle *layout = malloc(sizeof(ProfLayoutSingle));
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(barejid);
profwin->unread = 0;
new_win->super.layout = _win_create_simple_layout();
new_win->super.from = strdup(barejid);
new_win->super.unread = 0;
new_win->resource = NULL;
new_win->is_otr = FALSE;
new_win->is_trusted = FALSE;
new_win->history_shown = FALSE;
return (ProfWin*)new_win;
return &new_win->super;
}
ProfWin*
@ -162,88 +170,48 @@ win_create_muc(const char * const roomjid)
scrollok(layout->super.win, TRUE);
new_win->super.layout = (ProfLayout*)layout;
ProfWin *profwin = (ProfWin*)new_win;
profwin->from = strdup(roomjid);
profwin->unread = 0;
new_win->super.from = strdup(roomjid);
new_win->super.unread = 0;
return (ProfWin*)new_win;
return &new_win->super;
}
ProfWin*
win_create_muc_config(const char * const title, DataForm *form)
{
ProfMucConfWin *new_win = malloc(sizeof(ProfMucConfWin));
int cols = getmaxx(stdscr);
new_win->super.type = WIN_MUC_CONFIG;
ProfLayoutSingle *layout = malloc(sizeof(ProfLayoutSingle));
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;
new_win->super.layout = _win_create_simple_layout();
new_win->super.from = strdup(title);
new_win->super.unread = 0;
new_win->form = form;
ProfWin *profwin = (ProfWin*)new_win;
profwin->from = strdup(title);
profwin->unread = 0;
return (ProfWin*)new_win;
return &new_win->super;
}
ProfWin*
win_create_private(const char * const fulljid)
{
ProfPrivateWin *new_win = malloc(sizeof(ProfPrivateWin));
int cols = getmaxx(stdscr);
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));
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;
return &new_win->super;
}
ProfWin*
win_create_xmlconsole(void)
{
ProfXMLWin *new_win = malloc(sizeof(ProfXMLWin));
int cols = getmaxx(stdscr);
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));
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;
return &new_win->super;
}
void

View File

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