From ee88653dc0a7ee3077cedefedf51ca196f4ad006 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Mon, 20 Mar 2017 20:35:40 +0000 Subject: [PATCH] Enable displaying download progress within a notification. Requires Enhancer Pack (Ringhio 53.65+) Defaults to 0 (off) as there is currently no check to see if this version is installed. This is currently potentially dangerous to toggle whilst a download is in progress, so cannot be changed through the GUI. --- frontends/amiga/dist/NetSurf.guide | 1 + frontends/amiga/download.c | 53 ++++++++++++++++++++++++++---- frontends/amiga/options.h | 1 + resources/FatMessages | 5 +++ 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/frontends/amiga/dist/NetSurf.guide b/frontends/amiga/dist/NetSurf.guide index 512a264e6..d628a1c3b 100755 --- a/frontends/amiga/dist/NetSurf.guide +++ b/frontends/amiga/dist/NetSurf.guide @@ -146,6 +146,7 @@ There are a couple of Amiga-specific options which can only be changed directly @{b}mask_alpha@{ub} Threshold to use when determining which alpha values to convert to full transparency (0 - 255, where 255 will convert even opaque pixels to transparent). Defaults to 0. This is only used in palette-mapped modes where alpha blending is not currently supported. @{b}tab_new_session{ub} If NetSurf is already running, this will cause any passed URLs to open in a new tab rather than a new window. @{b}use_extmem@{ub} Defaults to 1 (enabled). Setting to 0 will prevent NetSurf using Extended Memory to store uncompressed images - this may have a performance benefit and no disadvantage for <2GB configurations. OS4.1FEU1 only. +@{b}download_notify_progress@{ub} Defaults to 0 (disabled). Display download progress in a Ringhio notification. Requires Enhancer Pack (Ringhio 53.65+), behaviour without it is undefined. @{b}url_file@{ub} Path to URL database file @{b}hotlist_file@{ub} Path to Hotlist file @{b}arexx_dir@{ub} Path to ARexx scripts dir diff --git a/frontends/amiga/download.c b/frontends/amiga/download.c index 18d3a59bc..3f3d96a33 100644 --- a/frontends/amiga/download.c +++ b/frontends/amiga/download.c @@ -68,6 +68,14 @@ #include "amiga/theme.h" #include "amiga/utf8.h" +#ifndef APPNOTIFY_DisplayTime +#define APPNOTIFY_DisplayTime ( TAG_USER + 13 ) +#endif + +#ifndef APPNOTIFY_Percentage +#define APPNOTIFY_Percentage ( TAG_USER + 14 ) +#endif + struct gui_download_window { struct ami_generic_window w; struct Window *win; @@ -157,7 +165,15 @@ static struct gui_download_window *gui_download_window_create(download_context * return NULL; } - dw->objects[OID_MAIN] = WindowObj, + if((nsoption_bool(download_notify_progress) == true)) { + Notify(ami_gui_get_app_id(), APPNOTIFY_Title, messages_get("NetSurf"), + APPNOTIFY_PubScreenName, "FRONT", + APPNOTIFY_Text, dw->fname, + APPNOTIFY_DisplayTime, TRUE, + APPNOTIFY_Percentage, 0, + TAG_DONE); + } else { + dw->objects[OID_MAIN] = WindowObj, WA_ScreenTitle, ami_gui_get_screen_title(), WA_Title, dw->url, WA_Activate, TRUE, @@ -195,7 +211,9 @@ static struct gui_download_window *gui_download_window_create(download_context * EndGroup, EndWindow; - dw->win = (struct Window *)RA_OpenWindow(dw->objects[OID_MAIN]); + dw->win = (struct Window *)RA_OpenWindow(dw->objects[OID_MAIN]); + } + dw->ctx = ctx; ami_gui_win_list_add(dw, AMINS_DLWINDOW, &ami_download_table); @@ -219,21 +237,33 @@ static nserror gui_download_window_data(struct gui_download_window *dw, va[1] = (APTR)dw->size; va[2] = 0; - if(dw->size) - { - RefreshSetGadgetAttrs((struct Gadget *)dw->objects[GID_STATUS], dw->win, NULL, + if(dw->size) { + if((nsoption_bool(download_notify_progress) == true)) { + Notify(ami_gui_get_app_id(), + APPNOTIFY_Percentage, (dw->downloaded * 100) / dw->size, + TAG_DONE); + } else { + RefreshSetGadgetAttrs((struct Gadget *)dw->objects[GID_STATUS], dw->win, NULL, FUELGAUGE_Level, dw->downloaded, GA_Text, messages_get("amiDownload"), FUELGAUGE_VarArgs, va, TAG_DONE); + } } else { - RefreshSetGadgetAttrs((struct Gadget *)dw->objects[GID_STATUS], dw->win, NULL, + if((nsoption_bool(download_notify_progress) == true)) { + /* unknown size, not entirely sure how to deal with this atm... */ + Notify(ami_gui_get_app_id(), + APPNOTIFY_Percentage, 0, + TAG_DONE); + } else { + RefreshSetGadgetAttrs((struct Gadget *)dw->objects[GID_STATUS], dw->win, NULL, FUELGAUGE_Level, dw->downloaded, GA_Text, messages_get("amiDownloadU"), FUELGAUGE_VarArgs, va, TAG_DONE); + } } return NSERROR_OK; @@ -248,6 +278,12 @@ static void gui_download_window_done(struct gui_download_window *dw) if(!dw) return; bw = dw->bw; + if((nsoption_bool(download_notify_progress) == true)) { + Notify(ami_gui_get_app_id(), + APPNOTIFY_Update, TRUE, + TAG_DONE); + } + if((nsoption_bool(download_notify)) && (dw->result == AMINS_DLOAD_OK)) { Notify(ami_gui_get_app_id(), APPNOTIFY_Title, messages_get("amiDownloadComplete"), @@ -275,7 +311,10 @@ static void gui_download_window_done(struct gui_download_window *dw) downloads_in_progress--; - DisposeObject(dw->objects[OID_MAIN]); + if(dw->objects[OID_MAIN] != NULL) { + DisposeObject(dw->objects[OID_MAIN]); + } + ami_gui_win_list_remove(dw); if(queuedl) { nsurl *url; diff --git a/frontends/amiga/options.h b/frontends/amiga/options.h index a2cc92e11..a23435ca6 100644 --- a/frontends/amiga/options.h +++ b/frontends/amiga/options.h @@ -49,6 +49,7 @@ NSOPTION_STRING(arexx_startup, "Startup.nsrx") NSOPTION_STRING(arexx_shutdown, "Shutdown.nsrx") NSOPTION_STRING(download_dir, NULL) NSOPTION_BOOL(download_notify, true) +NSOPTION_BOOL(download_notify_progress, false) NSOPTION_BOOL(faster_scroll, true) NSOPTION_BOOL(scale_quality, false) NSOPTION_INTEGER(dither_quality, 0) diff --git a/resources/FatMessages b/resources/FatMessages index ead95fc06..8f3c64af5 100644 --- a/resources/FatMessages +++ b/resources/FatMessages @@ -1564,6 +1564,11 @@ nl.all.Abort:Breek af # This section contains tokens which are used in the Amiga # download window. # +en.ami.amiDownloading:NetSurf: Downloading... +de.ami.amiDownloading:NetSurf: Downloading... +fr.ami.amiDownloading:NetSurf: Downloading... +it.ami.amiDownloading:NetSurf: Downloading... +nl.ami.amiDownloading:NetSurf: Downloading... en.ami.amiDownload:%ld of %ld bytes downloaded de.ami.amiDownload:%ld von %ld Bytes heruntergeladen fr.ami.amiDownload:%ld of %ld bytes downloaded