From e651d2636724cd6c5a55f3847d275f9be620db47 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Sat, 28 Jan 2023 18:11:42 +0100 Subject: add download capability --- config.hpp | 5 +++++ sb.cpp | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/config.hpp b/config.hpp index e5e0551..3afaa99 100644 --- a/config.hpp +++ b/config.hpp @@ -3,6 +3,11 @@ const char search_engine[] = "https://search.nathanreiner.xyz/search? const char dmenu_args[] = "-s 0 -b"; const unsigned scroll_speed = 100; +/* DOWNLOAD(URI) */ +#define DOWNLOAD(u) \ + const char *a[] = { "st", "-e", "curl", "-g", "-L", "-J", "-O", u, NULL }; \ + execvp(a[0], (char*const*)a); + #define MODIFIER Qt::ALT void register_shortcuts(QWidget *view) { diff --git a/sb.cpp b/sb.cpp index e35f987..0823c4c 100644 --- a/sb.cpp +++ b/sb.cpp @@ -166,6 +166,7 @@ void help(char *arg0) { exit(-1); } + int main(int argc, char **argv) { QApplication app(argc, argv); @@ -238,6 +239,13 @@ main(int argc, char **argv) { url_label.setText(url.toString()); }); + profile.connect(&profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *download) { + if (fork() == 0) { + std::string url = download->url().toString().toStdString(); + DOWNLOAD(url.c_str()); + } + }); + register_shortcuts(view); return app.exec(); -- cgit v1.2.3-70-g09d2