Merge pull request #2041 from profanity-im/some-improvements
All checks were successful
CI / Linux (debian) (pull_request) Successful in 13m45s
CI / Linux (arch) (pull_request) Successful in 16m48s
CI / Linux (fedora) (pull_request) Successful in 15m11s
CI / Check coding style (pull_request) Successful in 29s
CI / Check spelling (pull_request) Successful in 15s
CI / Linux (ubuntu) (pull_request) Successful in 13m50s
CI / Linux (debian) (push) Successful in 11m36s
CI / Linux (arch) (push) Successful in 14m0s
CI / Linux (fedora) (push) Successful in 12m25s
CI / Check coding style (push) Successful in 30s
CI / Check spelling (push) Successful in 16s
CI / Linux (ubuntu) (push) Successful in 11m55s
All checks were successful
CI / Linux (debian) (pull_request) Successful in 13m45s
CI / Linux (arch) (pull_request) Successful in 16m48s
CI / Linux (fedora) (pull_request) Successful in 15m11s
CI / Check coding style (pull_request) Successful in 29s
CI / Check spelling (pull_request) Successful in 15s
CI / Linux (ubuntu) (pull_request) Successful in 13m50s
CI / Linux (debian) (push) Successful in 11m36s
CI / Linux (arch) (push) Successful in 14m0s
CI / Linux (fedora) (push) Successful in 12m25s
CI / Check coding style (push) Successful in 30s
CI / Check spelling (push) Successful in 16s
CI / Linux (ubuntu) (push) Successful in 11m55s
Summary:
- Print the final storage location when successfully decrypting a file with `aesgcm://` source.
- Less GString
- Re-factor cmd_presence()
- Improve const correctness
- Use correct free function. Fixes: 75d7663 ("Free wins summary list")
Pull Request Source: https://github.com/profanity-im/profanity/pull/2041
Author: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
@@ -5233,54 +5233,43 @@ cmd_console(ProfWin* window, const char* const command, gchar** args)
|
||||
gboolean
|
||||
cmd_presence(ProfWin* window, const char* const command, gchar** args)
|
||||
{
|
||||
if (strcmp(args[0], "console") != 0 && strcmp(args[0], "chat") != 0 && strcmp(args[0], "room") != 0 && strcmp(args[0], "titlebar") != 0) {
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (strcmp(args[0], "titlebar") == 0) {
|
||||
_cmd_set_boolean_preference(args[1], "Contact presence", PREF_PRESENCE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (strcmp(args[1], "all") != 0 && strcmp(args[1], "online") != 0 && strcmp(args[1], "none") != 0) {
|
||||
const struct presence_preferences
|
||||
{
|
||||
preference_t pref;
|
||||
const char *name, *description;
|
||||
} presence_prefs[] = {
|
||||
{ .pref = PREF_STATUSES_CONSOLE, .name = "console", .description = "the console" },
|
||||
{ .pref = PREF_STATUSES_CHAT, .name = "chat", .description = "chat windows" },
|
||||
{ .pref = PREF_STATUSES_MUC, .name = "room", .description = "chat room windows" },
|
||||
};
|
||||
size_t n = 0;
|
||||
for (; n < ARRAY_SIZE(presence_prefs); ++n) {
|
||||
const struct presence_preferences* pp = &presence_prefs[n];
|
||||
if (g_strcmp0(args[0], pp->name) != 0)
|
||||
continue;
|
||||
if (strcmp(args[1], "all") == 0) {
|
||||
cons_show("All presence updates will appear in %s.", pp->description);
|
||||
} else if (strcmp(args[1], "online") == 0) {
|
||||
cons_show("Only %s presence updates will appear in %s.",
|
||||
pp->pref == PREF_STATUSES_MUC ? "join/leave" : "online/offline",
|
||||
pp->description);
|
||||
} else if (strcmp(args[1], "none") == 0) {
|
||||
cons_show("Presence updates will not appear in %s.", pp->description);
|
||||
} else {
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
}
|
||||
prefs_set_string(pp->pref, args[1]);
|
||||
break;
|
||||
}
|
||||
if (n == ARRAY_SIZE(presence_prefs)) {
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (strcmp(args[0], "console") == 0) {
|
||||
prefs_set_string(PREF_STATUSES_CONSOLE, args[1]);
|
||||
if (strcmp(args[1], "all") == 0) {
|
||||
cons_show("All presence updates will appear in the console.");
|
||||
} else if (strcmp(args[1], "online") == 0) {
|
||||
cons_show("Only online/offline presence updates will appear in the console.");
|
||||
} else {
|
||||
cons_show("Presence updates will not appear in the console.");
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(args[0], "chat") == 0) {
|
||||
prefs_set_string(PREF_STATUSES_CHAT, args[1]);
|
||||
if (strcmp(args[1], "all") == 0) {
|
||||
cons_show("All presence updates will appear in chat windows.");
|
||||
} else if (strcmp(args[1], "online") == 0) {
|
||||
cons_show("Only online/offline presence updates will appear in chat windows.");
|
||||
} else {
|
||||
cons_show("Presence updates will not appear in chat windows.");
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(args[0], "room") == 0) {
|
||||
prefs_set_string(PREF_STATUSES_MUC, args[1]);
|
||||
if (strcmp(args[1], "all") == 0) {
|
||||
cons_show("All presence updates will appear in chat room windows.");
|
||||
} else if (strcmp(args[1], "online") == 0) {
|
||||
cons_show("Only join/leave presence updates will appear in chat room windows.");
|
||||
} else {
|
||||
cons_show("Presence updates will not appear in chat room windows.");
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -5314,7 +5303,8 @@ cmd_time(ProfWin* window, const char* const command, gchar** args)
|
||||
};
|
||||
gboolean redraw = FALSE;
|
||||
gboolean set_all = g_strcmp0(args[0], "all") == 0;
|
||||
for (size_t n = 0; n < ARRAY_SIZE(time_prefs); ++n) {
|
||||
size_t n = 0;
|
||||
for (; n < ARRAY_SIZE(time_prefs); ++n) {
|
||||
if (!set_all && g_strcmp0(args[0], time_prefs[n].name) != 0)
|
||||
continue;
|
||||
const struct time_preferences* tp = &time_prefs[n];
|
||||
@@ -5355,6 +5345,9 @@ cmd_time(ProfWin* window, const char* const command, gchar** args)
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
if (!set_all && n == ARRAY_SIZE(time_prefs)) {
|
||||
cons_bad_cmd_usage(command);
|
||||
}
|
||||
if (redraw)
|
||||
ui_redraw();
|
||||
return TRUE;
|
||||
|
||||
@@ -140,6 +140,9 @@ aesgcm_file_get(void* userdata)
|
||||
"Downloading '%s' failed: Failed to decrypt "
|
||||
"file (%s).",
|
||||
https_url, gcry_strerror(crypt_res));
|
||||
} else {
|
||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
||||
"Decrypted file saved to '%s'", aesgcm_dl->filename);
|
||||
}
|
||||
|
||||
if (aesgcm_dl->cmd_template != NULL) {
|
||||
|
||||
@@ -258,22 +258,20 @@ GList*
|
||||
wins_get_private_chats(const char* const roomjid)
|
||||
{
|
||||
GList* result = NULL;
|
||||
GString* prefix = g_string_new(roomjid);
|
||||
g_string_append(prefix, "/");
|
||||
auto_gchar gchar* prefix = g_strdup_printf("%s/", roomjid);
|
||||
GList* curr = values;
|
||||
|
||||
while (curr) {
|
||||
ProfWin* window = curr->data;
|
||||
if (window->type == WIN_PRIVATE) {
|
||||
ProfPrivateWin* privatewin = (ProfPrivateWin*)window;
|
||||
if (roomjid == NULL || g_str_has_prefix(privatewin->fulljid, prefix->str)) {
|
||||
if (roomjid == NULL || g_str_has_prefix(privatewin->fulljid, prefix)) {
|
||||
result = g_list_append(result, privatewin);
|
||||
}
|
||||
}
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
|
||||
g_string_free(prefix, TRUE);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1067,19 +1065,13 @@ wins_create_summary(gboolean unread)
|
||||
while (curr) {
|
||||
ProfWin* window = g_hash_table_lookup(windows, curr->data);
|
||||
if (!unread || (unread && win_unread(window) > 0)) {
|
||||
GString* line = g_string_new("");
|
||||
|
||||
int ui_index = GPOINTER_TO_INT(curr->data);
|
||||
auto_gchar gchar* winstring = win_to_string(window);
|
||||
if (!winstring) {
|
||||
g_string_free(line, TRUE);
|
||||
continue;
|
||||
}
|
||||
|
||||
g_string_append_printf(line, "%d: %s", ui_index, winstring);
|
||||
|
||||
result = g_slist_append(result, strdup(line->str));
|
||||
g_string_free(line, TRUE);
|
||||
gchar* line = g_strdup_printf("%d: %s", ui_index, winstring);
|
||||
result = g_slist_append(result, line);
|
||||
}
|
||||
|
||||
curr = g_list_next(curr);
|
||||
@@ -1108,19 +1100,13 @@ wins_create_summary_attention()
|
||||
has_attention = mucwin->has_attention;
|
||||
}
|
||||
if (has_attention) {
|
||||
GString* line = g_string_new("");
|
||||
|
||||
int ui_index = GPOINTER_TO_INT(curr->data);
|
||||
auto_gchar gchar* winstring = win_to_string(window);
|
||||
if (!winstring) {
|
||||
g_string_free(line, TRUE);
|
||||
continue;
|
||||
}
|
||||
|
||||
g_string_append_printf(line, "%d: %s", ui_index, winstring);
|
||||
|
||||
result = g_slist_append(result, strdup(line->str));
|
||||
g_string_free(line, TRUE);
|
||||
gchar* line = g_strdup_printf("%d: %s", ui_index, winstring);
|
||||
result = g_slist_append(result, line);
|
||||
}
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ get_nick_from_full_jid(const char* const full_room_jid)
|
||||
/*
|
||||
* get the fulljid, fall back to the barejid
|
||||
*/
|
||||
char*
|
||||
const char*
|
||||
jid_fulljid_or_barejid(Jid* jid)
|
||||
{
|
||||
if (jid->fulljid) {
|
||||
|
||||
@@ -63,7 +63,7 @@ gboolean jid_is_valid_room_form(Jid* jid);
|
||||
char* create_fulljid(const char* const barejid, const char* const resource);
|
||||
char* get_nick_from_full_jid(const char* const full_room_jid);
|
||||
|
||||
char* jid_fulljid_or_barejid(Jid* jid);
|
||||
const char* jid_fulljid_or_barejid(Jid* jid);
|
||||
gchar* jid_random_resource(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -621,7 +621,7 @@ _available_handler(xmpp_stanza_t* const stanza)
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
char* jid = jid_fulljid_or_barejid(xmpp_presence->jid);
|
||||
const char* jid = jid_fulljid_or_barejid(xmpp_presence->jid);
|
||||
log_debug("Presence available handler fired for: %s", jid);
|
||||
}
|
||||
|
||||
@@ -632,7 +632,7 @@ _available_handler(xmpp_stanza_t* const stanza)
|
||||
XMPPCaps* caps = stanza_parse_caps(stanza);
|
||||
if ((g_strcmp0(my_jid->fulljid, xmpp_presence->jid->fulljid) != 0) && caps) {
|
||||
log_debug("Presence contains capabilities.");
|
||||
char* jid = jid_fulljid_or_barejid(xmpp_presence->jid);
|
||||
const char* jid = jid_fulljid_or_barejid(xmpp_presence->jid);
|
||||
_handle_caps(jid, caps);
|
||||
}
|
||||
stanza_free_caps(caps);
|
||||
|
||||
@@ -275,11 +275,8 @@ roster_remove(const char* const name, const char* const barejid)
|
||||
if (contact) {
|
||||
GList* resources = p_contact_get_available_resources(contact);
|
||||
while (resources) {
|
||||
GString* fulljid = g_string_new(barejid);
|
||||
g_string_append(fulljid, "/");
|
||||
g_string_append(fulljid, resources->data);
|
||||
autocomplete_remove(roster->fulljid_ac, fulljid->str);
|
||||
g_string_free(fulljid, TRUE);
|
||||
auto_gchar gchar* fulljid = g_strdup_printf("%s/%s", barejid, (char*)resources->data);
|
||||
autocomplete_remove(roster->fulljid_ac, fulljid);
|
||||
resources = g_list_next(resources);
|
||||
}
|
||||
g_list_free(resources);
|
||||
|
||||
@@ -219,7 +219,7 @@ returns_fulljid_when_exists(void** state)
|
||||
{
|
||||
Jid* jid = jid_create("localpart@domainpart/resourcepart");
|
||||
|
||||
char* result = jid_fulljid_or_barejid(jid);
|
||||
const char* result = jid_fulljid_or_barejid(jid);
|
||||
|
||||
assert_string_equal("localpart@domainpart/resourcepart", result);
|
||||
|
||||
@@ -231,7 +231,7 @@ returns_barejid_when_fulljid_not_exists(void** state)
|
||||
{
|
||||
Jid* jid = jid_create("localpart@domainpart");
|
||||
|
||||
char* result = jid_fulljid_or_barejid(jid);
|
||||
const char* result = jid_fulljid_or_barejid(jid);
|
||||
|
||||
assert_string_equal("localpart@domainpart", result);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user