mirror of
https://github.com/profanity-im/profanity.git
synced 2024-09-22 19:45:54 -04:00
Refactor buffer updates
This commit is contained in:
parent
186b53680e
commit
de938536ce
@ -92,7 +92,7 @@ _xferinfo(void *userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultot
|
||||
if (asprintf(&msg, "Uploading '%s': %d%%", upload->filename, ulperc) == -1) {
|
||||
msg = strdup(FALLBACK_MSG);
|
||||
}
|
||||
win_update_entry_message(upload->window, upload->put_url, msg);
|
||||
win_update_message(upload->window, upload->put_url, msg);
|
||||
free(msg);
|
||||
|
||||
pthread_mutex_unlock(&lock);
|
||||
@ -245,7 +245,7 @@ end:
|
||||
if (asprintf(&msg, "Uploading '%s' failed: %s", upload->filename, err) == -1) {
|
||||
msg = strdup(FALLBACK_MSG);
|
||||
}
|
||||
win_update_entry_message(upload->window, upload->put_url, msg);
|
||||
win_update_message(upload->window, upload->put_url, msg);
|
||||
}
|
||||
cons_show_error(msg);
|
||||
free(msg);
|
||||
@ -255,7 +255,7 @@ end:
|
||||
if (asprintf(&msg, "Uploading '%s': 100%%", upload->filename) == -1) {
|
||||
msg = strdup(FALLBACK_MSG);
|
||||
}
|
||||
win_update_entry_message(upload->window, upload->put_url, msg);
|
||||
win_update_message(upload->window, upload->put_url, msg);
|
||||
win_mark_received(upload->window, upload->put_url);
|
||||
free(msg);
|
||||
|
||||
|
@ -100,31 +100,6 @@ buffer_append(ProfBuff buffer, const char show_char, int pad_indent, GDateTime *
|
||||
buffer->entries = g_slist_append(buffer->entries, e);
|
||||
}
|
||||
|
||||
gboolean
|
||||
buffer_mark_received(ProfBuff buffer, const char *const id)
|
||||
{
|
||||
GSList *entries = buffer->entries;
|
||||
while (entries) {
|
||||
ProfBuffEntry *entry = entries->data;
|
||||
if (entry->receipt && g_strcmp0(entry->receipt->id, id) == 0) {
|
||||
if (!entry->receipt->received) {
|
||||
entry->receipt->received = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
entries = g_slist_next(entries);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ProfBuffEntry*
|
||||
buffer_get_entry(ProfBuff buffer, int entry)
|
||||
{
|
||||
GSList *node = g_slist_nth(buffer->entries, entry);
|
||||
return node->data;
|
||||
}
|
||||
|
||||
ProfBuffEntry*
|
||||
buffer_get_entry_by_id(ProfBuff buffer, const char *const id)
|
||||
{
|
||||
@ -140,6 +115,13 @@ buffer_get_entry_by_id(ProfBuff buffer, const char *const id)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ProfBuffEntry*
|
||||
buffer_get_entry(ProfBuff buffer, int entry)
|
||||
{
|
||||
GSList *node = g_slist_nth(buffer->entries, entry);
|
||||
return node->data;
|
||||
}
|
||||
|
||||
static void
|
||||
_free_entry(ProfBuffEntry *entry)
|
||||
{
|
||||
|
@ -1266,21 +1266,30 @@ win_print_with_receipt(ProfWin *window, const char show_char, const char *const
|
||||
void
|
||||
win_mark_received(ProfWin *window, const char *const id)
|
||||
{
|
||||
gboolean received = buffer_mark_received(window->layout->buffer, id);
|
||||
if (received) {
|
||||
win_redraw(window);
|
||||
ProfBuffEntry *entry = buffer_get_entry_by_id(window->layout->buffer, id);
|
||||
if (!entry) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (entry->receipt->received) {
|
||||
return;
|
||||
}
|
||||
|
||||
entry->receipt->received = TRUE;
|
||||
win_redraw(window);
|
||||
}
|
||||
|
||||
void
|
||||
win_update_entry_message(ProfWin *window, const char *const id, const char *const message)
|
||||
win_update_message(ProfWin *window, const char *const id, const char *const message)
|
||||
{
|
||||
ProfBuffEntry *entry = buffer_get_entry_by_id(window->layout->buffer, id);
|
||||
if (entry) {
|
||||
free(entry->message);
|
||||
entry->message = strdup(message);
|
||||
win_redraw(window);
|
||||
if (!entry) {
|
||||
return;
|
||||
}
|
||||
|
||||
free(entry->message);
|
||||
entry->message = strdup(message);
|
||||
win_redraw(window);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -80,8 +80,9 @@ int win_roster_cols(void);
|
||||
int win_occpuants_cols(void);
|
||||
void win_sub_print(WINDOW *win, char *msg, gboolean newline, gboolean wrap, int indent);
|
||||
void win_sub_newline_lazy(WINDOW *win);
|
||||
|
||||
void win_mark_received(ProfWin *window, const char *const id);
|
||||
void win_update_entry_message(ProfWin *window, const char *const id, const char *const message);
|
||||
void win_update_message(ProfWin *window, const char *const id, const char *const message);
|
||||
|
||||
gboolean win_has_active_subwin(ProfWin *window);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user