1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Use null check convention in window.c

This commit is contained in:
James Booth 2015-05-04 23:11:32 +01:00
parent dd386b4a4e
commit c19a05ca09

View File

@ -573,7 +573,7 @@ win_show_contact(ProfWin *window, PContact contact)
theme_item_t presence_colour = theme_main_presence_attrs(presence); theme_item_t presence_colour = theme_main_presence_attrs(presence);
if (name != NULL) { if (name) {
win_print(window, '-', NULL, NO_EOL, presence_colour, "", name); win_print(window, '-', NULL, NO_EOL, presence_colour, "", name);
} else { } else {
win_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid); win_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid);
@ -581,7 +581,7 @@ win_show_contact(ProfWin *window, PContact contact)
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence); win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence);
if (last_activity != NULL) { if (last_activity) {
GDateTime *now = g_date_time_new_now_local(); GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity); GTimeSpan span = g_date_time_difference(now, last_activity);
@ -599,7 +599,7 @@ win_show_contact(ProfWin *window, PContact contact)
} }
} }
if (status != NULL) { if (status) {
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", p_contact_status(contact)); win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", p_contact_status(contact));
} }
@ -637,41 +637,41 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup
if (caps) { if (caps) {
// show identity // show identity
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { if (caps->category || caps->type || caps->name) {
win_print(window, '!', NULL, NO_EOL, 0, "", " Identity: "); win_print(window, '!', NULL, NO_EOL, 0, "", " Identity: ");
if (caps->name != NULL) { if (caps->name) {
win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->name); win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->name);
if ((caps->category != NULL) || (caps->type != NULL)) { if (caps->category || caps->type) {
win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
} }
} }
if (caps->type != NULL) { if (caps->type) {
win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->type); win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->type);
if (caps->category != NULL) { if (caps->category) {
win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", " "); win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", " ");
} }
} }
if (caps->category != NULL) { if (caps->category) {
win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->category); win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->category);
} }
win_newline(window); win_newline(window);
} }
if (caps->software != NULL) { if (caps->software) {
win_vprint(window, '!', NULL, NO_EOL, 0, "", " Software: %s", caps->software); win_vprint(window, '!', NULL, NO_EOL, 0, "", " Software: %s", caps->software);
} }
if (caps->software_version != NULL) { if (caps->software_version) {
win_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); win_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version);
} }
if ((caps->software != NULL) || (caps->software_version != NULL)) { if (caps->software || caps->software_version) {
win_newline(window); win_newline(window);
} }
if (caps->os != NULL) { if (caps->os) {
win_vprint(window, '!', NULL, NO_EOL, 0, "", " OS: %s", caps->os); win_vprint(window, '!', NULL, NO_EOL, 0, "", " OS: %s", caps->os);
} }
if (caps->os_version != NULL) { if (caps->os_version) {
win_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); win_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version);
} }
if ((caps->os != NULL) || (caps->os_version != NULL)) { if (caps->os || caps->os_version) {
win_newline(window); win_newline(window);
} }
caps_destroy(caps); caps_destroy(caps);
@ -693,16 +693,16 @@ win_show_info(ProfWin *window, PContact contact)
win_print(window, '-', NULL, 0, 0, "", ""); win_print(window, '-', NULL, 0, 0, "", "");
win_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid); win_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid);
if (name != NULL) { if (name) {
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%s)", name); win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%s)", name);
} }
win_print(window, '-', NULL, NO_DATE, 0, "", ":"); win_print(window, '-', NULL, NO_DATE, 0, "", ":");
if (sub != NULL) { if (sub) {
win_vprint(window, '-', NULL, 0, 0, "", "Subscription: %s", sub); win_vprint(window, '-', NULL, 0, 0, "", "Subscription: %s", sub);
} }
if (last_activity != NULL) { if (last_activity) {
GDateTime *now = g_date_time_new_now_local(); GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity); GTimeSpan span = g_date_time_difference(now, last_activity);
@ -724,12 +724,12 @@ win_show_info(ProfWin *window, PContact contact)
GList *resources = p_contact_get_available_resources(contact); GList *resources = p_contact_get_available_resources(contact);
GList *ordered_resources = NULL; GList *ordered_resources = NULL;
if (resources != NULL) { if (resources) {
win_print(window, '-', NULL, 0, 0, "", "Resources:"); win_print(window, '-', NULL, 0, 0, "", "Resources:");
// sort in order of availability // sort in order of availability
GList *curr = resources; GList *curr = resources;
while (curr != NULL) { while (curr) {
Resource *resource = curr->data; Resource *resource = curr->data;
ordered_resources = g_list_insert_sorted(ordered_resources, ordered_resources = g_list_insert_sorted(ordered_resources,
resource, (GCompareFunc)resource_compare_availability); resource, (GCompareFunc)resource_compare_availability);
@ -739,12 +739,12 @@ win_show_info(ProfWin *window, PContact contact)
g_list_free(resources); g_list_free(resources);
GList *curr = ordered_resources; GList *curr = ordered_resources;
while (curr != NULL) { while (curr) {
Resource *resource = curr->data; Resource *resource = curr->data;
const char *resource_presence = string_from_resource_presence(resource->presence); const char *resource_presence = string_from_resource_presence(resource->presence);
theme_item_t presence_colour = theme_main_presence_attrs(resource_presence); theme_item_t presence_colour = theme_main_presence_attrs(resource_presence);
win_vprint(window, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence); win_vprint(window, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence);
if (resource->status != NULL) { if (resource->status) {
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status); win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status);
} }
win_newline(window); win_newline(window);
@ -755,41 +755,41 @@ win_show_info(ProfWin *window, PContact contact)
if (caps) { if (caps) {
// show identity // show identity
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { if (caps->category || caps->type || caps->name) {
win_print(window, '-', NULL, NO_EOL, 0, "", " Identity: "); win_print(window, '-', NULL, NO_EOL, 0, "", " Identity: ");
if (caps->name != NULL) { if (caps->name) {
win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name); win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name);
if ((caps->category != NULL) || (caps->type != NULL)) { if (caps->category || caps->type) {
win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
} }
} }
if (caps->type != NULL) { if (caps->type) {
win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type); win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type);
if (caps->category != NULL) { if (caps->category) {
win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
} }
} }
if (caps->category != NULL) { if (caps->category) {
win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category);
} }
win_newline(window); win_newline(window);
} }
if (caps->software != NULL) { if (caps->software) {
win_vprint(window, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software); win_vprint(window, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software);
} }
if (caps->software_version != NULL) { if (caps->software_version) {
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); win_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version);
} }
if ((caps->software != NULL) || (caps->software_version != NULL)) { if (caps->software || caps->software_version) {
win_newline(window); win_newline(window);
} }
if (caps->os != NULL) { if (caps->os) {
win_vprint(window, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os); win_vprint(window, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os);
} }
if (caps->os_version != NULL) { if (caps->os_version) {
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); win_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version);
} }
if ((caps->os != NULL) || (caps->os_version != NULL)) { if (caps->os || caps->os_version) {
win_newline(window); win_newline(window);
} }
caps_destroy(caps); caps_destroy(caps);
@ -808,7 +808,7 @@ win_show_status_string(ProfWin *window, const char * const from,
{ {
theme_item_t presence_colour; theme_item_t presence_colour;
if (show != NULL) { if (show) {
presence_colour = theme_main_presence_attrs(show); presence_colour = theme_main_presence_attrs(show);
} else if (strcmp(default_show, "online") == 0) { } else if (strcmp(default_show, "online") == 0) {
presence_colour = THEME_ONLINE; presence_colour = THEME_ONLINE;
@ -819,12 +819,12 @@ win_show_status_string(ProfWin *window, const char * const from,
win_vprint(window, '-', NULL, NO_EOL, presence_colour, "", "%s %s", pre, from); win_vprint(window, '-', NULL, NO_EOL, presence_colour, "", "%s %s", pre, from);
if (show != NULL) if (show)
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", show); win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", show);
else else
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", default_show); win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", default_show);
if (last_activity != NULL) { if (last_activity) {
GDateTime *now = g_date_time_new_now_local(); GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity); GTimeSpan span = g_date_time_difference(now, last_activity);
g_date_time_unref(now); g_date_time_unref(now);
@ -843,7 +843,7 @@ win_show_status_string(ProfWin *window, const char * const from,
} }
} }
if (status != NULL) if (status)
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", status); win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", status);
win_print(window, '-', NULL, NO_DATE, presence_colour, "", ""); win_print(window, '-', NULL, NO_DATE, presence_colour, "", "");