about summary refs log tree commit diff stats
path: root/src/tools/http_download.c
diff options
context:
space:
mode:
authorJohn Hernandez <129467592+H3rnand3zzz@users.noreply.github.com>2023-04-19 14:19:47 +0200
committerJohn Hernandez <129467592+H3rnand3zzz@users.noreply.github.com>2023-05-16 15:57:07 +0200
commit95e06ad16955f3b49c117cc6f2d53bf4da747154 (patch)
tree91738ed4485940d4d9fcb4fcd97caa391db82fda /src/tools/http_download.c
parent9a68aab01149c9781b899d482eb2c34f2cdf505c (diff)
downloadprofani-tty-95e06ad16955f3b49c117cc6f2d53bf4da747154.tar.gz
Add url support (downloading) to `/plugins install`
Additional changes include code refactoring.
Diffstat (limited to 'src/tools/http_download.c')
-rw-r--r--src/tools/http_download.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/tools/http_download.c b/src/tools/http_download.c
index 71c9a1e1..bd34a4ed 100644
--- a/src/tools/http_download.c
+++ b/src/tools/http_download.c
@@ -4,6 +4,7 @@
  *
  * Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
  * Copyright (C) 2020 William Wennerström <william@wstrm.dev>
+ * Copyright (C) 2019 - 2023 Michael Vetter <jubalh@iodoru.org>
  *
  * This file is part of Profanity.
  *
@@ -57,6 +58,7 @@
 #include "common.h"
 
 GSList* download_processes = NULL;
+gboolean silent = FALSE;
 
 static int
 _xferinfo(void* userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
@@ -82,8 +84,9 @@ _xferinfo(void* userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultot
         dlperc = (100 * dlnow) / dltotal;
     }
 
-    http_print_transfer_update(download->window, download->url,
-                               "Downloading '%s': %d%%", download->url, dlperc);
+    if (!silent)
+        http_print_transfer_update(download->window, download->url,
+                                   "Downloading '%s': %d%%", download->url, dlperc);
 
     pthread_mutex_unlock(&lock);
 
@@ -107,13 +110,16 @@ http_file_get(void* userdata)
 
     CURL* curl;
     CURLcode res;
+    silent = download->silent;
 
     download->cancel = 0;
     download->bytes_received = 0;
 
     pthread_mutex_lock(&lock);
-    http_print_transfer(download->window, download->id,
-                        "Downloading '%s': 0%%", download->url);
+    if (!silent) {
+        http_print_transfer(download->window, download->id,
+                            "Downloading '%s': 0%%", download->url);
+    }
 
     FILE* outfh = fopen(download->filename, "wb");
     if (outfh == NULL) {
@@ -188,7 +194,7 @@ http_file_get(void* userdata)
         }
         free(err);
     } else {
-        if (!download->cancel) {
+        if (!download->cancel && !silent) {
             http_print_transfer_update(download->window, download->id,
                                        "Downloading '%s': done\nSaved to '%s'",
                                        download->url, download->filename);