1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

ui: make it easier to find non covered window types

Rewrite `win_get_title()` to using switch without a default case. So the compiler warns us
(`enumeration value ‘WIN_XXX’ not handled in switch`)
in case we add a new window type (WIN_CHAT, WIN_PRIV etc) and forget to
adapt this function.

Add assert() in the end to make compiler happy when he realizes there
the function might have no return value (`control reaches end of
non-void function`). This should ever be reached.

Replace the default value of `win_to_string()`, `win_get_tab_identifier()` as
well, and replace it with an assert.

See discussion started at https://github.com/profanity-im/profanity/pull/1799#discussion_r1142444684
This commit is contained in:
Michael Vetter 2023-03-23 07:41:25 +01:00
parent b393363bd5
commit 12b997c5f3

View File

@ -302,10 +302,14 @@ win_get_title(ProfWin* window)
if (window == NULL) {
return strdup(CONS_WIN_TITLE);
}
if (window->type == WIN_CONSOLE) {
switch (window->type) {
case WIN_CONSOLE:
{
return strdup(CONS_WIN_TITLE);
}
if (window->type == WIN_CHAT) {
case WIN_CHAT:
{
ProfChatWin* chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
jabber_conn_status_t conn_status = connection_get_status();
@ -321,7 +325,8 @@ win_get_title(ProfWin* window)
return strdup(chatwin->barejid);
}
}
if (window->type == WIN_MUC) {
case WIN_MUC:
{
ProfMucWin* mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
@ -339,30 +344,37 @@ win_get_title(ProfWin* window)
return g_string_free(title, FALSE);
}
if (window->type == WIN_CONFIG) {
ProfConfWin* confwin = (ProfConfWin*)window;
assert(confwin->memcheck == PROFCONFWIN_MEMCHECK);
GString* title = g_string_new(confwin->roomjid);
g_string_append(title, " config");
if (confwin->form->modified) {
g_string_append(title, " *");
case WIN_CONFIG:
{
if (window->type == WIN_CONFIG) {
ProfConfWin* confwin = (ProfConfWin*)window;
assert(confwin->memcheck == PROFCONFWIN_MEMCHECK);
GString* title = g_string_new(confwin->roomjid);
g_string_append(title, " config");
if (confwin->form->modified) {
g_string_append(title, " *");
}
return g_string_free(title, FALSE);
}
return g_string_free(title, FALSE);
}
if (window->type == WIN_PRIVATE) {
case WIN_PRIVATE:
{
ProfPrivateWin* privatewin = (ProfPrivateWin*)window;
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
return strdup(privatewin->fulljid);
}
if (window->type == WIN_XML) {
case WIN_XML:
{
return strdup(XML_WIN_TITLE);
}
if (window->type == WIN_PLUGIN) {
case WIN_PLUGIN:
{
ProfPluginWin* pluginwin = (ProfPluginWin*)window;
assert(pluginwin->memcheck == PROFPLUGINWIN_MEMCHECK);
return strdup(pluginwin->tag);
}
if (window->type == WIN_VCARD) {
case WIN_VCARD:
{
ProfVcardWin* vcardwin = (ProfVcardWin*)window;
assert(vcardwin->memcheck == PROFVCARDWIN_MEMCHECK);
@ -378,7 +390,8 @@ win_get_title(ProfWin* window)
free(jid);
return g_string_free(title, FALSE);
}
return NULL;
}
assert(FALSE);
}
char*
@ -420,9 +433,8 @@ win_get_tab_identifier(ProfWin* window)
{
return strdup("xmlconsole");
}
default:
return strdup("UNKNOWN");
}
assert(FALSE);
}
char*
@ -503,9 +515,8 @@ win_to_string(ProfWin* window)
ProfVcardWin* vcardwin = (ProfVcardWin*)window;
return vcardwin_get_string(vcardwin);
}
default:
return NULL;
}
assert(FALSE);
}
void