diff --git a/ncdc/include/ncdc/textview.h b/ncdc/include/ncdc/textview.h index 933cfb4..42eb00e 100644 --- a/ncdc/include/ncdc/textview.h +++ b/ncdc/include/ncdc/textview.h @@ -14,6 +14,9 @@ void ncdc_textview_set_account(ncdc_textview_t v, dc_account_t a); dc_channel_t ncdc_textview_channel(ncdc_textview_t v); void ncdc_textview_set_channel(ncdc_textview_t v, dc_channel_t a); +wchar_t const *ncdc_textview_title(ncdc_textview_t v); +void ncdc_textview_set_title(ncdc_textview_t v, wchar_t const *w); + void ncdc_textview_append(ncdc_textview_t v, wchar_t const *w); wchar_t const *ncdc_textview_nthline(ncdc_textview_t v, size_t i); void ncdc_textview_render(ncdc_textview_t v, WINDOW *win, int lines, int cols); diff --git a/ncdc/src/mainwindow.c b/ncdc/src/mainwindow.c index 74b9a6e..25696ca 100644 --- a/ncdc/src/mainwindow.c +++ b/ncdc/src/mainwindow.c @@ -85,6 +85,7 @@ ncdc_mainwindow_t ncdc_mainwindow_new(void) (GDestroyNotify)dc_unref ); ptr->log = ncdc_textview_new(); + ncdc_textview_set_title(ptr->log, L"status"); g_ptr_array_add(ptr->views, ptr->log); ptr->guilds = newwin(5, 5, 1, 1); @@ -190,6 +191,8 @@ static void ncdc_mainwindow_render_status(ncdc_mainwindow_t n) time_t tm = time(NULL); struct tm *t = localtime(&tm); FILE *f = open_wmemstream(&status, &statuslen); + wchar_t const *wintitle = NULL; + ncdc_textview_t view = NULL; werase(n->sep1); return_if_true(f == NULL,); @@ -203,7 +206,11 @@ static void ncdc_mainwindow_render_status(ncdc_mainwindow_t n) fwprintf(f, L" [%s]", dc_account_fullname(current_account)); } - fwprintf(f, L" [%d]", n->curview); + view = g_ptr_array_index(n->views, n->curview); + wintitle = ncdc_textview_title(view); + fwprintf(f, L" [%d: %ls]", n->curview, + (wintitle != NULL ? wintitle : L"n/a") + ); fclose(f); mvwaddwstr(n->sep1, 0, 0, status); diff --git a/ncdc/src/textview.c b/ncdc/src/textview.c index 4b5202b..b110f5c 100644 --- a/ncdc/src/textview.c +++ b/ncdc/src/textview.c @@ -6,6 +6,7 @@ struct ncdc_textview_ dc_refable_t ref; GPtrArray *par; + wchar_t *title; dc_account_t account; dc_channel_t channel; @@ -15,6 +16,9 @@ static void ncdc_textview_free(ncdc_textview_t v) { return_if_true(v == NULL,); + free(v->title); + v->title = NULL; + dc_unref(v->account); dc_unref(v->channel); @@ -38,7 +42,44 @@ ncdc_textview_t ncdc_textview_new(void) return NULL; } - return p; + return dc_ref(p); +} + +static void ncdc_textview_maketitle(ncdc_textview_t v) +{ + size_t i = 0; + wchar_t *buf = NULL; + size_t buflen = 0; + FILE *f = open_wmemstream(&buf, &buflen); + size_t rlen = dc_channel_recipients(v->channel); + + for (i = 0; i < rlen; i++) { + dc_account_t r = dc_channel_nthrecipient(v->channel, i); + fwprintf(f, L"%s", dc_account_fullname(r)); + if (i < (rlen-1)) { + fwprintf(f, L","); + } + } + + fclose(f); + + free(v->title); + v->title = buf; +} + +wchar_t const *ncdc_textview_title(ncdc_textview_t v) +{ + if (v->title == NULL && v->channel != NULL) { + ncdc_textview_maketitle(v); + } + + return v->title; +} + +void ncdc_textview_set_title(ncdc_textview_t v, wchar_t const *w) +{ + free(v->title); + v->title = wcsdup(w); } dc_account_t ncdc_textview_account(ncdc_textview_t v) @@ -98,7 +139,7 @@ void ncdc_textview_render(ncdc_textview_t v, WINDOW *win, int lines, int cols) werase(win); - if (v->par->len == 0) { + if (v->par == NULL || v->par->len == 0) { return; }