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

Rename http upload functions

This commit is contained in:
James Booth 2016-12-01 22:06:43 +00:00
parent 29124da110
commit 98870646d8
6 changed files with 79 additions and 33 deletions

View File

@ -92,7 +92,8 @@ _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_message(upload->window, upload->put_url, msg);
win_update_upload(upload->window, upload->put_url, msg);
sleep(2);
free(msg);
pthread_mutex_unlock(&lock);
@ -146,7 +147,7 @@ http_file_put(void *userdata)
if (asprintf(&msg, "Uploading '%s': 0%%", upload->filename) == -1) {
msg = strdup(FALLBACK_MSG);
}
win_print_http_upload(upload->window, msg, upload->put_url);
win_print_upload(upload->window, msg, upload->put_url);
free(msg);
char *cert_path = prefs_get_string(PREF_TLS_CERTPATH);
@ -245,7 +246,7 @@ end:
if (asprintf(&msg, "Uploading '%s' failed: %s", upload->filename, err) == -1) {
msg = strdup(FALLBACK_MSG);
}
win_update_message(upload->window, upload->put_url, msg);
win_update_upload(upload->window, upload->put_url, msg);
}
cons_show_error(msg);
free(msg);
@ -255,8 +256,8 @@ end:
if (asprintf(&msg, "Uploading '%s': 100%%", upload->filename) == -1) {
msg = strdup(FALLBACK_MSG);
}
win_update_message(upload->window, upload->put_url, msg);
win_http_upload_complete(upload->window, upload->put_url);
win_update_upload(upload->window, upload->put_url, msg);
win_complete_upload(upload->window, upload->put_url);
free(msg);
switch (upload->window->type) {

View File

@ -71,6 +71,16 @@ buffer_date_new_now(void)
return date;
}
ProfBuffUpload*
buffer_upload_new(char *url)
{
ProfBuffUpload *upload = malloc(sizeof(ProfBuffUpload));
upload->url = strdup(url);
upload->complete = FALSE;
return upload;
}
ProfBuffReceipt*
buffer_receipt_new(char *id)
{
@ -100,7 +110,8 @@ buffer_entry_create(
const char *const message,
int pad_indent,
gboolean newline,
ProfBuffReceipt *receipt)
ProfBuffReceipt *receipt,
ProfBuffUpload *upload)
{
ProfBuffEntry *entry = malloc(sizeof(struct prof_buff_entry_t));
entry->show_char = show_char;
@ -110,6 +121,7 @@ buffer_entry_create(
entry->date = date;
entry->from = from;
entry->receipt = receipt;
entry->upload = upload;
entry->message = strdup(message);
return entry;
@ -129,6 +141,21 @@ buffer_append(ProfWin *window, ProfBuffEntry *entry)
inp_nonblocking(TRUE);
}
ProfBuffEntry*
buffer_get_upload_entry(GSList *entries, const char *const url)
{
GSList *curr = entries;
while (curr) {
ProfBuffEntry *entry = curr->data;
if (entry->upload && g_strcmp0(entry->upload->url, url) == 0) {
return entry;
}
curr = g_slist_next(curr);
}
return NULL;
}
ProfBuffEntry*
buffer_get_entry_by_id(GSList *entries, const char *const id)
{

View File

@ -44,6 +44,7 @@
ProfBuffDate* buffer_date_new_now(void);
ProfBuffDate* buffer_date_new(GDateTime *timestamp, gboolean colour);
ProfBuffReceipt* buffer_receipt_new(char *id);
ProfBuffUpload* buffer_upload_new(char *url);
ProfBuffFrom* buffer_from_new(prof_buff_from_type_t type, const char *const from);
ProfBuffEntry* buffer_entry_create(
@ -54,11 +55,13 @@ ProfBuffEntry* buffer_entry_create(
const char *const message,
int pad_indent,
gboolean newline,
ProfBuffReceipt *receipt);
ProfBuffReceipt *receipt,
ProfBuffUpload *upload);
void buffer_append(ProfWin *window, ProfBuffEntry *entry);
ProfBuffEntry* buffer_get_entry_by_id(GSList *entries, const char *const id);
ProfBuffEntry* buffer_get_upload_entry(GSList *entries, const char *const url);
void buffer_free_entry(ProfBuffEntry *entry);
#endif

View File

@ -204,6 +204,11 @@ typedef struct prof_buff_receipt_t {
gboolean received;
} ProfBuffReceipt;
typedef struct prof_buff_upload_t {
char *url;
gboolean complete;
} ProfBuffUpload;
typedef struct prof_buff_date_t {
GDateTime *timestamp;
gboolean colour_date;
@ -228,6 +233,7 @@ typedef struct prof_buff_entry_t {
int pad_indent;
gboolean newline;
ProfBuffReceipt *receipt;
ProfBuffUpload *upload;
} ProfBuffEntry;
#endif

View File

@ -693,7 +693,7 @@ win_print(ProfWin *window, theme_item_t theme_item, const char ch, const char *c
va_end(args);
ProfBuffDate *date = buffer_date_new_now();
ProfBuffEntry *entry = buffer_entry_create(theme_item, date, ch, NULL, fmt_msg->str, 0, FALSE, NULL);
ProfBuffEntry *entry = buffer_entry_create(theme_item, date, ch, NULL, fmt_msg->str, 0, FALSE, NULL, NULL);
g_string_free(fmt_msg, TRUE);
buffer_append(window, entry);
@ -709,7 +709,7 @@ win_println(ProfWin *window, theme_item_t theme_item, const char ch, const char
va_end(args);
ProfBuffDate *date = buffer_date_new_now();
ProfBuffEntry *entry = buffer_entry_create(theme_item, date, ch, NULL, fmt_msg->str, 0, TRUE, NULL);
ProfBuffEntry *entry = buffer_entry_create(theme_item, date, ch, NULL, fmt_msg->str, 0, TRUE, NULL, NULL);
g_string_free(fmt_msg, TRUE);
buffer_append(window, entry);
@ -725,7 +725,7 @@ win_println_indent(ProfWin *window, int pad, const char *const message, ...)
va_end(args);
ProfBuffDate *date = buffer_date_new_now();
ProfBuffEntry *entry = buffer_entry_create(THEME_DEFAULT, date, '-', NULL, fmt_msg->str, pad, TRUE, NULL);
ProfBuffEntry *entry = buffer_entry_create(THEME_DEFAULT, date, '-', NULL, fmt_msg->str, pad, TRUE, NULL, NULL);
g_string_free(fmt_msg, TRUE);
buffer_append(window, entry);
@ -740,7 +740,7 @@ win_append(ProfWin *window, theme_item_t theme_item, const char *const message,
g_string_vprintf(fmt_msg, message, args);
va_end(args);
ProfBuffEntry *entry = buffer_entry_create(theme_item, NULL, '-', NULL, fmt_msg->str, 0, FALSE, NULL);
ProfBuffEntry *entry = buffer_entry_create(theme_item, NULL, '-', NULL, fmt_msg->str, 0, FALSE, NULL, NULL);
g_string_free(fmt_msg, TRUE);
buffer_append(window, entry);
@ -755,7 +755,7 @@ win_appendln(ProfWin *window, theme_item_t theme_item, const char *const message
g_string_vprintf(fmt_msg, message, args);
va_end(args);
ProfBuffEntry *entry = buffer_entry_create(theme_item, NULL, '-', NULL, fmt_msg->str, 0, TRUE, NULL);
ProfBuffEntry *entry = buffer_entry_create(theme_item, NULL, '-', NULL, fmt_msg->str, 0, TRUE, NULL, NULL);
g_string_free(fmt_msg, TRUE);
buffer_append(window, entry);
@ -770,7 +770,7 @@ win_append_highlight(ProfWin *window, theme_item_t theme_item, const char *const
g_string_vprintf(fmt_msg, message, args);
va_end(args);
ProfBuffEntry *entry = buffer_entry_create(theme_item, NULL, '-', NULL, fmt_msg->str, 0, FALSE, NULL);
ProfBuffEntry *entry = buffer_entry_create(theme_item, NULL, '-', NULL, fmt_msg->str, 0, FALSE, NULL, NULL);
g_string_free(fmt_msg, TRUE);
buffer_append(window, entry);
@ -785,7 +785,7 @@ win_appendln_highlight(ProfWin *window, theme_item_t theme_item, const char *con
g_string_vprintf(fmt_msg, message, args);
va_end(args);
ProfBuffEntry *entry = buffer_entry_create(theme_item, NULL, '-', NULL, fmt_msg->str, 0, TRUE, NULL);
ProfBuffEntry *entry = buffer_entry_create(theme_item, NULL, '-', NULL, fmt_msg->str, 0, TRUE, NULL, NULL);
g_string_free(fmt_msg, TRUE);
buffer_append(window, entry);
@ -1108,7 +1108,7 @@ win_print_muc_occupant(ProfWin *window, theme_item_t theme_item, const char *con
{
ProfBuffDate *date = buffer_date_new_now();
ProfBuffFrom *from = them ? buffer_from_new(FROM_THEM, them) : NULL;
ProfBuffEntry *entry = buffer_entry_create(theme_item, date, '-', from, "", 0, FALSE, NULL);
ProfBuffEntry *entry = buffer_entry_create(theme_item, date, '-', from, "", 0, FALSE, NULL, NULL);
buffer_append(window, entry);
}
@ -1124,7 +1124,7 @@ win_print_muc_occupant_message(ProfWin *window, const char *const them, const ch
ProfBuffDate *date = buffer_date_new_now();
ProfBuffFrom *from = them ? buffer_from_new(FROM_THEM, them) : NULL;
ProfBuffEntry *entry = buffer_entry_create(THEME_TEXT_THEM, date, '-', from, fmt_msg->str, 0, TRUE, NULL);
ProfBuffEntry *entry = buffer_entry_create(THEME_TEXT_THEM, date, '-', from, fmt_msg->str, 0, TRUE, NULL, NULL);
g_string_free(fmt_msg, TRUE);
buffer_append(window, entry);
@ -1141,7 +1141,7 @@ win_print_muc_self_message(ProfWin *window, const char *const me, const char *co
ProfBuffDate *date = buffer_date_new_now();
ProfBuffFrom *from = me ? buffer_from_new(FROM_ME, me) : NULL;
ProfBuffEntry *entry = buffer_entry_create(THEME_TEXT_ME, date, '-', from, fmt_msg->str, 0, TRUE, NULL);
ProfBuffEntry *entry = buffer_entry_create(THEME_TEXT_ME, date, '-', from, fmt_msg->str, 0, TRUE, NULL, NULL);
g_string_free(fmt_msg, TRUE);
buffer_append(window, entry);
@ -1166,7 +1166,7 @@ win_print_incoming(ProfWin *window, GDateTime *timestamp, const char *const them
ProfBuffDate *date = buffer_date_new(timestamp, TRUE);
ProfBuffFrom *from = them ? buffer_from_new(FROM_THEM, them) : NULL;
ProfBuffEntry *entry = buffer_entry_create(THEME_TEXT_THEM, date, ch, from, message, 0, TRUE, NULL);
ProfBuffEntry *entry = buffer_entry_create(THEME_TEXT_THEM, date, ch, from, message, 0, TRUE, NULL, NULL);
buffer_append(window, entry);
}
@ -1182,7 +1182,7 @@ win_print_outgoing(ProfWin *window, const char ch, const char *const message, ..
ProfBuffDate *date = buffer_date_new_now();
ProfBuffFrom *from = buffer_from_new(FROM_ME, "me");
ProfBuffEntry *entry = buffer_entry_create(THEME_TEXT_ME, date, ch, from, fmt_msg->str, 0, TRUE, NULL);
ProfBuffEntry *entry = buffer_entry_create(THEME_TEXT_ME, date, ch, from, fmt_msg->str, 0, TRUE, NULL, NULL);
g_string_free(fmt_msg, TRUE);
buffer_append(window, entry);
@ -1198,18 +1198,18 @@ win_print_history(ProfWin *window, GDateTime *timestamp, const char *const messa
va_end(args);
ProfBuffDate *date = buffer_date_new(timestamp, FALSE);
ProfBuffEntry *entry = buffer_entry_create(THEME_DEFAULT, date, '-', NULL, fmt_msg->str, 0, TRUE, NULL);
ProfBuffEntry *entry = buffer_entry_create(THEME_DEFAULT, date, '-', NULL, fmt_msg->str, 0, TRUE, NULL, NULL);
g_string_free(fmt_msg, TRUE);
buffer_append(window, entry);
}
void
win_print_http_upload(ProfWin *window, const char *const message, char *url)
win_print_upload(ProfWin *window, const char *const message, char *url)
{
ProfBuffReceipt *receipt = buffer_receipt_new(url);
ProfBuffUpload *upload = buffer_upload_new(url);
ProfBuffDate *date = buffer_date_new_now();
ProfBuffEntry *entry = buffer_entry_create(THEME_TEXT_ME, date, '!', NULL, message, 0, TRUE, receipt);
ProfBuffEntry *entry = buffer_entry_create(THEME_TEXT_ME, date, '!', NULL, message, 0, TRUE, NULL, upload);
buffer_append(window, entry);
}
@ -1220,24 +1220,24 @@ win_print_with_receipt(ProfWin *window, const char show_char, const char *const
ProfBuffReceipt *receipt = buffer_receipt_new(id);
ProfBuffDate *date = buffer_date_new_now();
ProfBuffFrom *from = me ? buffer_from_new(FROM_ME, me) : NULL;
ProfBuffEntry *entry = buffer_entry_create(THEME_TEXT_ME, date, show_char, from, message, 0, TRUE, receipt);
ProfBuffEntry *entry = buffer_entry_create(THEME_TEXT_ME, date, show_char, from, message, 0, TRUE, receipt, NULL);
buffer_append(window, entry);
}
void
win_http_upload_complete(ProfWin *window, const char *const url)
win_complete_upload(ProfWin *window, const char *const url)
{
ProfBuffEntry *entry = buffer_get_entry_by_id(window->layout->entries, url);
ProfBuffEntry *entry = buffer_get_upload_entry(window->layout->entries, url);
if (!entry) {
return;
}
if (entry->receipt->received) {
if (entry->upload->complete) {
return;
}
entry->receipt->received = TRUE;
entry->upload->complete = TRUE;
win_redraw(window);
}
@ -1258,9 +1258,9 @@ win_mark_received(ProfWin *window, const char *const id)
}
void
win_update_message(ProfWin *window, const char *const id, const char *const message)
win_update_upload(ProfWin *window, const char *const url, const char *const message)
{
ProfBuffEntry *entry = buffer_get_entry_by_id(window->layout->entries, id);
ProfBuffEntry *entry = buffer_get_upload_entry(window->layout->entries, url);
if (!entry) {
return;
}
@ -1331,6 +1331,10 @@ win_print_entry(ProfWin *window, ProfBuffEntry *entry)
colour = theme_attrs(THEME_RECEIPT_SENT);
}
if (entry->upload && !entry->upload->complete) {
colour = theme_attrs(THEME_RECEIPT_SENT);
}
wbkgdset(window->layout->win, colour);
wattron(window->layout->win, colour);
if (strncmp(entry->message, "/me ", 4) == 0) {
@ -1347,6 +1351,9 @@ win_print_entry(ProfWin *window, ProfBuffEntry *entry)
if (entry->receipt && !entry->receipt->received) {
wbkgdset(window->layout->win, theme_attrs(THEME_RECEIPT_SENT));
wattron(window->layout->win, theme_attrs(THEME_RECEIPT_SENT));
} else if (entry->upload && !entry->upload->complete) {
wbkgdset(window->layout->win, theme_attrs(THEME_RECEIPT_SENT));
wattron(window->layout->win, theme_attrs(THEME_RECEIPT_SENT));
} else {
wbkgdset(window->layout->win, theme_attrs(entry->theme_item));
wattron(window->layout->win, theme_attrs(entry->theme_item));
@ -1371,6 +1378,8 @@ win_print_entry(ProfWin *window, ProfBuffEntry *entry)
} else {
if (entry->receipt && !entry->receipt->received) {
wattroff(window->layout->win, theme_attrs(THEME_RECEIPT_SENT));
} else if (entry->upload && !entry->upload->complete) {
wattroff(window->layout->win, theme_attrs(THEME_RECEIPT_SENT));
} else {
wattroff(window->layout->win, theme_attrs(entry->theme_item));
}

View File

@ -69,8 +69,9 @@ void win_print_incoming(ProfWin *window, GDateTime *timestamp,
const char *const them, const char *const message, prof_enc_t enc_mode);
void win_print_history(ProfWin *window, GDateTime *timestamp, const char *const message, ...);
void win_print_http_upload(ProfWin *window, const char *const message, char *url);
void win_http_upload_complete(ProfWin *window, const char *const url);
void win_print_upload(ProfWin *window, const char *const message, char *url);
void win_update_upload(ProfWin *window, const char *const url, const char *const message);
void win_complete_upload(ProfWin *window, const char *const url);
void win_print_with_receipt(ProfWin *window, const char show_char, const char *const me, const char *const message,
char *id);
@ -83,7 +84,6 @@ void win_sub_print(WINDOW *win, char *msg, gboolean newline, gboolean wrap, int
void win_sub_newline_lazy(WINDOW *win);
void win_mark_received(ProfWin *window, const char *const id);
void win_update_message(ProfWin *window, const char *const id, const char *const message);
void win_print_entry(ProfWin *window, ProfBuffEntry *entry);
gboolean win_has_active_subwin(ProfWin *window);