1
0
Fork 0

Compare commits

...

4 Commits

Author SHA1 Message Date
John Hernandez beae9f461b
Merge 0f361e6b52 into e5eb0f41f3 2024-03-01 12:59:57 +01:00
Michael Vetter e5eb0f41f3
Merge pull request #1958 from ike08/fix/no-download-twice
Fix unable to download item twice
2024-03-01 12:57:54 +01:00
ike08 23fa4750ff Fix unable to download item twice
## Summary

Partial fix for https://github.com/profanity-im/profanity/issues/1939  

> When doing the same in an unencrypted (no e2ee) chat there is no Downloading… message at all but the file is downloaded.  

Download a file twice with `/url save`, the second download will not print download progress to the window.  

The cause is `HTTPDownload`'s `silent` variable is not initialized; so, `silent` points to a second-hand stack memory address with old data. `silent` references data, so the `if` statement will fail in **src/tools/http_download.c:206** and download progress will not print to the window.  

The fix is to initialize `silent` in both encrypted and unencrypted file download scenarios.  

## Testing

Valgrind: Yes  

- `/url save` without OMEMO  
  **SUCCESS**: Try three times with the same URL and download status will display every time.  

- `/url save` with OMEMO  
  **SUCCESS**: Try three times with the same URL and download status will display every time.  

- `/plugins install https://raw.githubusercontent.com/profanity-im/profanity-plugins/master/stable/sounds.py`  
  **SUCCESS**: Try once and download progress is hidden.
2024-02-28 07:23:59 -07:00
John Hernandez 0f361e6b52
Remove maxtabs limitation for statusbar 2024-01-19 16:25:27 +01:00
4 changed files with 19 additions and 11 deletions

View File

@ -1298,7 +1298,7 @@ static const struct cmd_t command_defs[] = {
CMD_DESC(
"Manage statusbar display preferences.")
CMD_ARGS(
{ "maxtabs <value>", "Set the maximum number of tabs to display, <value> must be between 0 and 10." },
{ "maxtabs <value>", "Set the maximum number of tabs to display, <value> must be more than or equal to 0." },
{ "tablen <value>", "Set the maximum number of characters to show as the tab name, 0 sets to unlimited." },
{ "tabmode default|dynamic|actlist", "Set the mode tabs are shown. `dynamic` is a mode that displays tabs conveniently around current tab, thus providing proper pagination. `actlist` setting shows only active tabs. `default` setting always shows tabs in 1 to max_tabs range." },
{ "show|hide name", "Show or hide names in tabs." },

View File

@ -6182,11 +6182,6 @@ cmd_statusbar(ProfWin* window, const char* const command, gchar** args)
auto_char char* err_msg = NULL;
gboolean res = strtoi_range(value, &intval, 0, INT_MAX, &err_msg);
if (res) {
if (intval < 0 || intval > 10) {
cons_bad_cmd_usage(command);
return TRUE;
}
prefs_set_statusbartabs(intval);
if (intval == 0) {
cons_show("Status bar tabs disabled.");
@ -9447,6 +9442,7 @@ _url_http_method(ProfWin* window, const char* cmd_template, gchar* url, gchar* p
download->filename = strdup(filename);
download->id = strdup(id);
download->cmd_template = cmd_template ? strdup(cmd_template) : NULL;
download->silent = FALSE;
pthread_create(&(download->worker), NULL, &http_file_get, download);
http_download_add_download(download);

View File

@ -110,6 +110,7 @@ aesgcm_file_get(void* userdata)
http_dl->url = strdup(https_url);
http_dl->filename = strdup(tmpname);
http_dl->cmd_template = NULL;
http_dl->silent = FALSE;
aesgcm_dl->http_dl = http_dl;
http_file_get(http_dl); // TODO(wstrm): Verify result.

View File

@ -77,8 +77,10 @@ typedef struct _status_bar_t
static GTimeZone* tz;
static StatusBar* statusbar;
static WINDOW* statusbar_win;
static int left_part_size;
void _get_range_bounds(int* start, int* end, gboolean is_static);
static int _get_max_tabs();
static int _status_bar_draw_time(int pos);
static int _status_bar_draw_maintext(int pos);
static int _status_bar_draw_bracket(gboolean current, int pos, const char* ch);
@ -285,11 +287,14 @@ status_bar_draw(void)
werase(statusbar_win);
wbkgd(statusbar_win, theme_attrs(THEME_STATUS_TEXT));
gint max_tabs = prefs_get_statusbartabs();
gint max_tabs = _get_max_tabs();
int pos = 1;
pos = _status_bar_draw_time(pos);
pos = _status_bar_draw_maintext(pos);
left_part_size = pos;
if (max_tabs != 0)
pos = _status_bar_draw_tabs(pos);
@ -367,7 +372,7 @@ _status_bar_draw_tabs(int pos)
static gboolean
_has_new_msgs_beyond_range_on_side(gboolean left_side, int display_tabs_start, int display_tabs_end)
{
gint max_tabs = prefs_get_statusbartabs();
gint max_tabs = _get_max_tabs();
int tabs_count = g_hash_table_size(statusbar->tabs);
if (tabs_count <= max_tabs) {
return FALSE;
@ -389,7 +394,7 @@ _has_new_msgs_beyond_range_on_side(gboolean left_side, int display_tabs_start, i
static int
_status_bar_draw_extended_tabs(int pos, gboolean prefix, int start, int end, gboolean is_static)
{
gint max_tabs = prefs_get_statusbartabs();
gint max_tabs = _get_max_tabs();
if (max_tabs == 0) {
return pos;
}
@ -620,7 +625,7 @@ _tabs_width(int start, int end)
gboolean show_number = prefs_get_boolean(PREF_STATUSBAR_SHOW_NUMBER);
gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME);
gboolean show_read = prefs_get_boolean(PREF_STATUSBAR_SHOW_READ);
gint max_tabs = prefs_get_statusbartabs();
gint max_tabs = _get_max_tabs();
guint opened_tabs = g_hash_table_size(statusbar->tabs);
int width = start < 2 ? 1 : 4;
@ -718,7 +723,7 @@ void
_get_range_bounds(int* start, int* end, gboolean is_static)
{
int current_tab = statusbar->current_tab;
gint display_range = prefs_get_statusbartabs();
gint display_range = _get_max_tabs();
int total_tabs = g_hash_table_size(statusbar->tabs);
int side_range = display_range / 2;
@ -766,3 +771,9 @@ _count_digits_in_range(int start, int end)
return total_digits;
}
static int
_get_max_tabs()
{
return MIN(prefs_get_statusbartabs(), (getmaxx(stdscr) - left_part_size) / 3);
}