2009-03-28 15:50:19 +03:00
|
|
|
/*
|
2010-02-13 20:31:10 +03:00
|
|
|
* Copyright 2008-2010 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
2009-03-28 15:50:19 +03:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-03-24 01:27:33 +03:00
|
|
|
#include <string.h>
|
|
|
|
|
2009-03-28 15:50:19 +03:00
|
|
|
#include <proto/wb.h>
|
|
|
|
#include <proto/asl.h>
|
|
|
|
#include <proto/exec.h>
|
|
|
|
#include <proto/dos.h>
|
|
|
|
#include <proto/intuition.h>
|
2009-03-28 18:43:12 +03:00
|
|
|
#include <proto/utility.h>
|
|
|
|
#include <proto/icon.h>
|
2011-01-07 02:17:17 +03:00
|
|
|
#ifdef __amigaos4__
|
2010-02-13 20:31:10 +03:00
|
|
|
#include <proto/application.h>
|
2011-01-07 02:17:17 +03:00
|
|
|
#endif
|
2009-03-28 18:43:12 +03:00
|
|
|
|
|
|
|
#include <workbench/icon.h>
|
2009-03-28 15:50:19 +03:00
|
|
|
|
|
|
|
#include <proto/window.h>
|
|
|
|
#include <proto/layout.h>
|
|
|
|
|
|
|
|
#include <proto/fuelgauge.h>
|
|
|
|
#include <classes/window.h>
|
|
|
|
#include <gadgets/fuelgauge.h>
|
|
|
|
#include <gadgets/layout.h>
|
|
|
|
|
|
|
|
#include <reaction/reaction_macros.h>
|
|
|
|
|
2014-10-16 12:55:01 +04:00
|
|
|
#include "utils/errors.h"
|
2016-04-20 17:54:18 +03:00
|
|
|
#include "utils/nsurl.h"
|
2014-10-16 12:55:01 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "utils/nsoption.h"
|
2016-04-22 00:36:21 +03:00
|
|
|
#include "utils/string.h"
|
2016-05-30 19:32:57 +03:00
|
|
|
#include "netsurf/browser_window.h"
|
2016-05-30 14:07:16 +03:00
|
|
|
#include "netsurf/mouse.h"
|
2016-05-30 13:01:40 +03:00
|
|
|
#include "netsurf/window.h"
|
2016-05-30 13:15:58 +03:00
|
|
|
#include "netsurf/download.h"
|
2016-05-24 01:32:16 +03:00
|
|
|
#include "content/handlers/image/ico.h"
|
2016-06-06 10:59:23 +03:00
|
|
|
#include "desktop/download.h"
|
|
|
|
#include "desktop/save_complete.h"
|
2014-10-16 12:55:01 +04:00
|
|
|
|
|
|
|
#include "amiga/gui.h"
|
|
|
|
#include "amiga/download.h"
|
|
|
|
#include "amiga/object.h"
|
|
|
|
#include "amiga/bitmap.h"
|
|
|
|
#include "amiga/icon.h"
|
|
|
|
#include "amiga/file.h"
|
|
|
|
#include "amiga/iff_dr2d.h"
|
2015-01-26 03:05:01 +03:00
|
|
|
#include "amiga/libs.h"
|
2014-10-16 12:55:01 +04:00
|
|
|
#include "amiga/misc.h"
|
2014-11-09 04:00:08 +03:00
|
|
|
#include "amiga/theme.h"
|
2014-10-16 12:55:01 +04:00
|
|
|
#include "amiga/utf8.h"
|
|
|
|
|
2017-03-20 23:35:40 +03:00
|
|
|
#ifndef APPNOTIFY_DisplayTime
|
|
|
|
#define APPNOTIFY_DisplayTime ( TAG_USER + 13 )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef APPNOTIFY_Percentage
|
|
|
|
#define APPNOTIFY_Percentage ( TAG_USER + 14 )
|
|
|
|
#endif
|
|
|
|
|
2017-03-21 21:42:41 +03:00
|
|
|
#ifndef APPNOTIFY_StopBackMsg
|
|
|
|
#define APPNOTIFY_StopBackMsg ( TAG_USER + 17 )
|
|
|
|
#endif
|
|
|
|
|
2018-09-27 01:53:49 +03:00
|
|
|
enum {
|
|
|
|
OID_D_MAIN = 0,
|
|
|
|
GID_D_MAIN,
|
|
|
|
GID_D_STATUS,
|
|
|
|
GID_D_CANCEL,
|
|
|
|
GID_D_LAST
|
|
|
|
};
|
|
|
|
|
2011-03-26 13:33:58 +03:00
|
|
|
struct gui_download_window {
|
2016-12-31 03:11:06 +03:00
|
|
|
struct ami_generic_window w;
|
2011-03-26 13:33:58 +03:00
|
|
|
struct Window *win;
|
2018-09-27 01:53:49 +03:00
|
|
|
Object *objects[GID_D_LAST];
|
2011-03-26 13:33:58 +03:00
|
|
|
BPTR fh;
|
|
|
|
uint32 size;
|
|
|
|
uint32 downloaded;
|
2017-03-20 23:53:39 +03:00
|
|
|
uint32 progress;
|
2011-03-26 13:33:58 +03:00
|
|
|
struct dlnode *dln;
|
|
|
|
struct browser_window *bw;
|
|
|
|
struct download_context *ctx;
|
2014-05-24 15:02:41 +04:00
|
|
|
const char *url;
|
2011-03-26 13:33:58 +03:00
|
|
|
char fname[1024];
|
2012-06-04 19:10:13 +04:00
|
|
|
int result;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2017-03-21 21:42:41 +03:00
|
|
|
AMINS_DLOAD_PROGRESS = 0,
|
|
|
|
AMINS_DLOAD_OK,
|
2012-06-04 19:10:13 +04:00
|
|
|
AMINS_DLOAD_ERROR,
|
|
|
|
AMINS_DLOAD_ABORT,
|
2011-03-26 13:33:58 +03:00
|
|
|
};
|
|
|
|
|
2016-12-31 03:11:06 +03:00
|
|
|
static void ami_download_window_abort(void *w);
|
|
|
|
static BOOL ami_download_window_event(void *w);
|
|
|
|
|
|
|
|
static const struct ami_win_event_table ami_download_table = {
|
|
|
|
ami_download_window_event,
|
|
|
|
ami_download_window_abort,
|
|
|
|
};
|
|
|
|
|
2016-06-02 02:44:20 +03:00
|
|
|
static int downloads_in_progress = 0;
|
2012-06-04 20:15:12 +04:00
|
|
|
|
2014-01-14 20:04:02 +04:00
|
|
|
static struct gui_download_window *gui_download_window_create(download_context *ctx,
|
2010-04-06 01:35:38 +04:00
|
|
|
struct gui_window *gui)
|
2009-03-28 15:50:19 +03:00
|
|
|
{
|
2014-05-24 15:02:41 +04:00
|
|
|
const char *url = nsurl_access(download_context_get_url(ctx));
|
2010-04-06 01:35:38 +04:00
|
|
|
unsigned long total_size = download_context_get_total_length(ctx);
|
2009-03-28 15:50:19 +03:00
|
|
|
struct gui_download_window *dw;
|
2014-01-02 22:50:59 +04:00
|
|
|
char *dl_filename = ami_utf8_easy(download_context_get_filename(ctx));
|
2009-03-28 15:50:19 +03:00
|
|
|
APTR va[3];
|
|
|
|
|
2016-11-19 23:44:17 +03:00
|
|
|
dw = calloc(1, sizeof(struct gui_download_window));
|
2009-03-28 15:50:19 +03:00
|
|
|
|
2019-05-07 23:45:40 +03:00
|
|
|
if(gui && (!IsListEmpty(ami_gui_get_download_list(gui)) &&
|
|
|
|
(dw->dln = (struct dlnode *)FindName(ami_gui_get_download_list(gui), url)))) {
|
2010-02-13 20:31:10 +03:00
|
|
|
strcpy(dw->fname, dw->dln->filename);
|
2009-03-28 15:50:19 +03:00
|
|
|
free(dw->dln->node.ln_Name);
|
|
|
|
dw->dln->node.ln_Name = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(AslRequestTags(savereq,
|
2019-05-07 23:45:40 +03:00
|
|
|
ASLFR_Window, ami_gui_get_gui_window_2(gui)->win,
|
2013-05-25 16:59:42 +04:00
|
|
|
ASLFR_SleepWindow, TRUE,
|
2014-01-02 22:50:59 +04:00
|
|
|
ASLFR_TitleText, messages_get("NetSurf"),
|
|
|
|
ASLFR_Screen, scrn,
|
|
|
|
ASLFR_InitialFile, dl_filename,
|
2009-03-28 15:50:19 +03:00
|
|
|
TAG_DONE))
|
|
|
|
{
|
2011-07-23 18:10:01 +04:00
|
|
|
strlcpy(dw->fname, savereq->fr_Drawer, 1024);
|
2010-02-13 20:31:10 +03:00
|
|
|
AddPart((STRPTR)&dw->fname,savereq->fr_File,1024);
|
2019-05-07 23:45:40 +03:00
|
|
|
if(!ami_download_check_overwrite(dw->fname, ami_gui_get_gui_window_2(gui)->win, total_size))
|
2011-03-26 13:33:58 +03:00
|
|
|
{
|
2016-11-19 20:02:18 +03:00
|
|
|
free(dw);
|
2011-03-26 13:33:58 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-19 20:02:18 +03:00
|
|
|
free(dw);
|
2011-07-23 18:10:01 +04:00
|
|
|
return NULL;
|
2009-03-28 15:50:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-02 22:50:59 +04:00
|
|
|
if(dl_filename) ami_utf8_free(dl_filename);
|
2009-03-28 15:50:19 +03:00
|
|
|
dw->size = total_size;
|
|
|
|
dw->downloaded = 0;
|
2019-05-07 23:45:40 +03:00
|
|
|
if(gui) dw->bw = ami_gui_get_browser_window(gui);
|
2014-05-24 15:02:41 +04:00
|
|
|
dw->url = url;
|
2009-03-28 15:50:19 +03:00
|
|
|
|
|
|
|
va[0] = (APTR)dw->downloaded;
|
|
|
|
va[1] = (APTR)dw->size;
|
|
|
|
va[2] = 0;
|
|
|
|
|
2010-02-13 20:31:10 +03:00
|
|
|
if(!(dw->fh = FOpen((STRPTR)&dw->fname,MODE_NEWFILE,0)))
|
2009-03-28 15:50:19 +03:00
|
|
|
{
|
2016-11-19 20:02:18 +03:00
|
|
|
free(dw);
|
2009-03-28 15:50:19 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-20 23:35:40 +03:00
|
|
|
if((nsoption_bool(download_notify_progress) == true)) {
|
2017-03-21 21:42:41 +03:00
|
|
|
char bkm[1030];
|
|
|
|
snprintf(bkm, 1030, "STOP %p", dw);
|
|
|
|
|
2017-03-20 23:53:39 +03:00
|
|
|
Notify(ami_gui_get_app_id(), APPNOTIFY_Title, messages_get("amiDownloading"),
|
2017-03-20 23:35:40 +03:00
|
|
|
APPNOTIFY_PubScreenName, "FRONT",
|
|
|
|
APPNOTIFY_Text, dw->fname,
|
|
|
|
APPNOTIFY_DisplayTime, TRUE,
|
|
|
|
APPNOTIFY_Percentage, 0,
|
2017-03-21 21:42:41 +03:00
|
|
|
APPNOTIFY_StopBackMsg, bkm,
|
2017-03-20 23:35:40 +03:00
|
|
|
TAG_DONE);
|
|
|
|
} else {
|
2018-09-27 01:53:49 +03:00
|
|
|
dw->objects[OID_D_MAIN] = WindowObj,
|
2014-11-16 19:40:41 +03:00
|
|
|
WA_ScreenTitle, ami_gui_get_screen_title(),
|
2009-10-15 20:49:52 +04:00
|
|
|
WA_Title, dw->url,
|
2009-03-28 15:50:19 +03:00
|
|
|
WA_Activate, TRUE,
|
|
|
|
WA_DepthGadget, TRUE,
|
|
|
|
WA_DragBar, TRUE,
|
|
|
|
WA_CloseGadget, FALSE,
|
|
|
|
WA_SizeGadget, TRUE,
|
2013-03-20 12:22:03 +04:00
|
|
|
WA_PubScreen,scrn,
|
2009-04-30 22:40:26 +04:00
|
|
|
WINDOW_SharedPort,sport,
|
|
|
|
WINDOW_UserData,dw,
|
2010-02-13 20:31:10 +03:00
|
|
|
WINDOW_IconifyGadget, FALSE,
|
2009-03-28 15:50:19 +03:00
|
|
|
WINDOW_LockHeight,TRUE,
|
|
|
|
WINDOW_Position, WPOS_CENTERSCREEN,
|
2018-09-27 01:53:49 +03:00
|
|
|
WINDOW_ParentGroup, dw->objects[GID_D_MAIN] = LayoutVObj,
|
|
|
|
LAYOUT_AddChild, dw->objects[GID_D_STATUS] = FuelGaugeObj,
|
|
|
|
GA_ID,GID_D_STATUS,
|
2009-03-28 15:50:19 +03:00
|
|
|
GA_Text,messages_get("amiDownload"),
|
|
|
|
FUELGAUGE_Min,0,
|
|
|
|
FUELGAUGE_Max,total_size,
|
|
|
|
FUELGAUGE_Level,0,
|
|
|
|
FUELGAUGE_Ticks,11,
|
|
|
|
FUELGAUGE_ShortTicks,TRUE,
|
|
|
|
FUELGAUGE_VarArgs,va,
|
|
|
|
FUELGAUGE_Percent,FALSE,
|
|
|
|
FUELGAUGE_Justification,FGJ_CENTER,
|
2009-04-30 22:40:26 +04:00
|
|
|
FuelGaugeEnd,
|
2009-03-28 15:50:19 +03:00
|
|
|
CHILD_NominalSize,TRUE,
|
|
|
|
CHILD_WeightedHeight,0,
|
2018-09-27 01:53:49 +03:00
|
|
|
LAYOUT_AddChild, dw->objects[GID_D_CANCEL] = ButtonObj,
|
|
|
|
GA_ID,GID_D_CANCEL,
|
2009-04-30 22:40:26 +04:00
|
|
|
GA_RelVerify,TRUE,
|
|
|
|
GA_Text,messages_get("Abort"),
|
|
|
|
GA_TabCycle,TRUE,
|
|
|
|
ButtonEnd,
|
2009-03-28 15:50:19 +03:00
|
|
|
EndGroup,
|
|
|
|
EndWindow;
|
|
|
|
|
2018-09-27 01:53:49 +03:00
|
|
|
dw->win = (struct Window *)RA_OpenWindow(dw->objects[OID_D_MAIN]);
|
2017-03-20 23:35:40 +03:00
|
|
|
}
|
|
|
|
|
2010-04-06 01:35:38 +04:00
|
|
|
dw->ctx = ctx;
|
2017-03-21 21:42:41 +03:00
|
|
|
dw->result = AMINS_DLOAD_PROGRESS;
|
2009-03-28 15:50:19 +03:00
|
|
|
|
2016-12-31 03:11:06 +03:00
|
|
|
ami_gui_win_list_add(dw, AMINS_DLWINDOW, &ami_download_table);
|
2012-06-04 20:15:12 +04:00
|
|
|
|
|
|
|
downloads_in_progress++;
|
|
|
|
|
2009-03-28 15:50:19 +03:00
|
|
|
return dw;
|
|
|
|
}
|
|
|
|
|
2014-01-14 20:04:02 +04:00
|
|
|
static nserror gui_download_window_data(struct gui_download_window *dw,
|
2010-04-06 01:35:38 +04:00
|
|
|
const char *data, unsigned int size)
|
2009-03-28 15:50:19 +03:00
|
|
|
{
|
|
|
|
APTR va[3];
|
2010-04-06 01:35:38 +04:00
|
|
|
if(!dw) return NSERROR_SAVE_FAILED;
|
2009-03-28 15:50:19 +03:00
|
|
|
|
|
|
|
FWrite(dw->fh,data,1,size);
|
|
|
|
|
|
|
|
dw->downloaded = dw->downloaded + size;
|
|
|
|
|
|
|
|
va[0] = (APTR)dw->downloaded;
|
|
|
|
va[1] = (APTR)dw->size;
|
|
|
|
va[2] = 0;
|
|
|
|
|
2017-03-20 23:35:40 +03:00
|
|
|
if(dw->size) {
|
2017-03-20 23:53:39 +03:00
|
|
|
if((nsoption_bool(download_notify_progress) == true) &&
|
|
|
|
(((dw->downloaded * 100) / dw->size) > dw->progress)) {
|
|
|
|
dw->progress = (uint32)((dw->downloaded * 100) / dw->size);
|
2017-03-20 23:35:40 +03:00
|
|
|
Notify(ami_gui_get_app_id(),
|
2017-03-20 23:53:39 +03:00
|
|
|
APPNOTIFY_Percentage, dw->progress,
|
2017-03-20 23:35:40 +03:00
|
|
|
TAG_DONE);
|
|
|
|
} else {
|
2018-09-27 01:53:49 +03:00
|
|
|
RefreshSetGadgetAttrs((struct Gadget *)dw->objects[GID_D_STATUS], dw->win, NULL,
|
2011-07-23 18:10:01 +04:00
|
|
|
FUELGAUGE_Level, dw->downloaded,
|
|
|
|
GA_Text, messages_get("amiDownload"),
|
|
|
|
FUELGAUGE_VarArgs, va,
|
2009-03-28 15:50:19 +03:00
|
|
|
TAG_DONE);
|
2017-03-20 23:35:40 +03:00
|
|
|
}
|
2009-03-28 15:50:19 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-20 23:35:40 +03:00
|
|
|
if((nsoption_bool(download_notify_progress) == true)) {
|
|
|
|
/* unknown size, not entirely sure how to deal with this atm... */
|
|
|
|
Notify(ami_gui_get_app_id(),
|
2017-03-20 23:53:39 +03:00
|
|
|
APPNOTIFY_Percentage, 100,
|
2017-03-20 23:35:40 +03:00
|
|
|
TAG_DONE);
|
|
|
|
} else {
|
2018-09-27 01:53:49 +03:00
|
|
|
RefreshSetGadgetAttrs((struct Gadget *)dw->objects[GID_D_STATUS], dw->win, NULL,
|
2011-07-23 18:10:01 +04:00
|
|
|
FUELGAUGE_Level, dw->downloaded,
|
|
|
|
GA_Text, messages_get("amiDownloadU"),
|
|
|
|
FUELGAUGE_VarArgs, va,
|
2009-03-28 15:50:19 +03:00
|
|
|
TAG_DONE);
|
2017-03-20 23:35:40 +03:00
|
|
|
}
|
2009-03-28 15:50:19 +03:00
|
|
|
}
|
2010-04-06 01:35:38 +04:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
2009-03-28 15:50:19 +03:00
|
|
|
}
|
|
|
|
|
2014-01-14 20:04:02 +04:00
|
|
|
static void gui_download_window_done(struct gui_download_window *dw)
|
2009-03-28 15:50:19 +03:00
|
|
|
{
|
2012-03-22 13:34:34 +04:00
|
|
|
struct dlnode *dln,*dln2 = NULL;
|
2014-04-03 22:12:47 +04:00
|
|
|
struct browser_window *bw;
|
2009-03-28 15:50:19 +03:00
|
|
|
bool queuedl = false;
|
|
|
|
|
|
|
|
if(!dw) return;
|
2014-04-03 22:12:47 +04:00
|
|
|
bw = dw->bw;
|
2009-03-28 15:50:19 +03:00
|
|
|
|
2017-03-21 21:42:41 +03:00
|
|
|
if(dw->result == AMINS_DLOAD_PROGRESS)
|
|
|
|
dw->result = AMINS_DLOAD_OK;
|
|
|
|
|
2017-03-20 23:35:40 +03:00
|
|
|
if((nsoption_bool(download_notify_progress) == true)) {
|
|
|
|
Notify(ami_gui_get_app_id(),
|
|
|
|
APPNOTIFY_Update, TRUE,
|
|
|
|
TAG_DONE);
|
|
|
|
}
|
|
|
|
|
2012-06-04 19:10:13 +04:00
|
|
|
if((nsoption_bool(download_notify)) && (dw->result == AMINS_DLOAD_OK))
|
2010-01-25 15:41:05 +03:00
|
|
|
{
|
2017-03-21 21:42:41 +03:00
|
|
|
char bkm[1030];
|
|
|
|
snprintf(bkm, 1030, "OPEN %s", dw->fname);
|
|
|
|
|
2014-11-16 17:06:12 +03:00
|
|
|
Notify(ami_gui_get_app_id(), APPNOTIFY_Title, messages_get("amiDownloadComplete"),
|
2010-02-13 20:31:10 +03:00
|
|
|
APPNOTIFY_PubScreenName, "FRONT",
|
2017-03-21 21:42:41 +03:00
|
|
|
APPNOTIFY_BackMsg, bkm,
|
2010-02-13 20:31:10 +03:00
|
|
|
APPNOTIFY_CloseOnDC, TRUE,
|
|
|
|
APPNOTIFY_Text, dw->fname,
|
|
|
|
TAG_DONE);
|
2010-01-25 15:41:05 +03:00
|
|
|
}
|
|
|
|
|
2010-04-10 02:38:51 +04:00
|
|
|
download_context_destroy(dw->ctx);
|
2009-03-28 15:50:19 +03:00
|
|
|
|
2014-11-09 04:00:08 +03:00
|
|
|
if((dln = dw->dln))
|
2009-03-28 15:50:19 +03:00
|
|
|
{
|
2009-03-28 18:43:12 +03:00
|
|
|
dln2 = (struct dlnode *)GetSucc((struct Node *)dln);
|
2009-04-14 22:51:10 +04:00
|
|
|
if((dln!=dln2) && (dln2)) queuedl = true;
|
2009-03-28 15:50:19 +03:00
|
|
|
|
|
|
|
free(dln->filename);
|
2009-03-28 18:43:12 +03:00
|
|
|
Remove((struct Node *)dln);
|
2016-11-19 20:02:18 +03:00
|
|
|
free(dln);
|
2009-03-28 15:50:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
FClose(dw->fh);
|
2010-03-06 20:06:52 +03:00
|
|
|
SetComment(dw->fname, dw->url);
|
|
|
|
|
2012-06-04 20:15:12 +04:00
|
|
|
downloads_in_progress--;
|
|
|
|
|
2018-09-27 01:53:49 +03:00
|
|
|
if(dw->objects[OID_D_MAIN] != NULL) {
|
|
|
|
DisposeObject(dw->objects[OID_D_MAIN]);
|
2017-03-20 23:35:40 +03:00
|
|
|
}
|
|
|
|
|
2016-12-31 03:11:06 +03:00
|
|
|
ami_gui_win_list_remove(dw);
|
2013-02-14 19:09:28 +04:00
|
|
|
if(queuedl) {
|
|
|
|
nsurl *url;
|
|
|
|
if (nsurl_create(dln2->node.ln_Name, &url) != NSERROR_OK) {
|
2016-05-01 16:00:47 +03:00
|
|
|
amiga_warn_user("NoMemory", 0);
|
2013-02-14 19:09:28 +04:00
|
|
|
} else {
|
|
|
|
browser_window_navigate(bw,
|
|
|
|
url,
|
|
|
|
NULL,
|
2014-02-11 02:40:04 +04:00
|
|
|
BW_NAVIGATE_DOWNLOAD,
|
2013-02-14 19:09:28 +04:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
|
|
|
}
|
2014-02-11 00:40:08 +04:00
|
|
|
ami_try_quit(); /* In case the only window open was this download */
|
2009-03-28 15:50:19 +03:00
|
|
|
}
|
|
|
|
|
2014-01-16 18:43:48 +04:00
|
|
|
static void gui_download_window_error(struct gui_download_window *dw,
|
|
|
|
const char *error_msg)
|
|
|
|
{
|
2016-05-01 16:00:47 +03:00
|
|
|
amiga_warn_user("Unwritten","");
|
2014-01-16 18:43:48 +04:00
|
|
|
dw->result = AMINS_DLOAD_ERROR;
|
|
|
|
gui_download_window_done(dw);
|
|
|
|
}
|
|
|
|
|
2016-12-31 03:11:06 +03:00
|
|
|
static void ami_download_window_abort(void *w)
|
2014-01-16 18:43:48 +04:00
|
|
|
{
|
2017-03-03 22:34:11 +03:00
|
|
|
struct gui_download_window *dw = (struct gui_download_window *)w;
|
2014-01-16 18:43:48 +04:00
|
|
|
download_context_abort(dw->ctx);
|
|
|
|
dw->result = AMINS_DLOAD_ABORT;
|
|
|
|
gui_download_window_done(dw);
|
|
|
|
}
|
|
|
|
|
2016-12-31 03:11:06 +03:00
|
|
|
static BOOL ami_download_window_event(void *w)
|
2010-04-10 02:38:51 +04:00
|
|
|
{
|
|
|
|
/* return TRUE if window destroyed */
|
2016-12-31 03:11:06 +03:00
|
|
|
struct gui_download_window *dw = (struct gui_download_window *)w;
|
2014-11-09 04:00:08 +03:00
|
|
|
ULONG result;
|
2010-04-10 02:38:51 +04:00
|
|
|
uint16 code;
|
|
|
|
|
2017-03-21 21:42:41 +03:00
|
|
|
if(dw == NULL) return FALSE; /* We may not have a real window */
|
|
|
|
|
2018-09-27 01:53:49 +03:00
|
|
|
while((result = RA_HandleInput(dw->objects[OID_D_MAIN], &code)) != WMHI_LASTMSG)
|
2010-04-10 02:38:51 +04:00
|
|
|
{
|
|
|
|
switch(result & WMHI_CLASSMASK) // class
|
|
|
|
{
|
|
|
|
case WMHI_GADGETUP:
|
|
|
|
switch(result & WMHI_GADGETMASK)
|
|
|
|
{
|
2018-09-27 01:53:49 +03:00
|
|
|
case GID_D_CANCEL:
|
2010-04-10 02:38:51 +04:00
|
|
|
ami_download_window_abort(dw);
|
|
|
|
return TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-03-28 15:50:19 +03:00
|
|
|
void ami_free_download_list(struct List *dllist)
|
|
|
|
{
|
|
|
|
struct dlnode *node;
|
|
|
|
struct dlnode *nnode;
|
|
|
|
|
2009-11-16 02:11:41 +03:00
|
|
|
if(!dllist) return;
|
|
|
|
if(IsListEmpty(dllist)) return;
|
|
|
|
|
2009-03-28 15:50:19 +03:00
|
|
|
node = (struct dlnode *)GetHead((struct List *)dllist);
|
|
|
|
|
2009-11-16 02:11:41 +03:00
|
|
|
do
|
2009-03-28 15:50:19 +03:00
|
|
|
{
|
2009-11-16 02:11:41 +03:00
|
|
|
nnode=(struct dlnode *)GetSucc((struct Node *)node);
|
2009-03-28 15:50:19 +03:00
|
|
|
free(node->node.ln_Name);
|
|
|
|
free(node->filename);
|
2009-03-28 18:43:12 +03:00
|
|
|
Remove((struct Node *)node);
|
2016-11-19 20:02:18 +03:00
|
|
|
free((struct Node *)node);
|
2014-11-09 04:00:08 +03:00
|
|
|
}while((node=nnode));
|
2009-03-28 15:50:19 +03:00
|
|
|
}
|
|
|
|
|
2014-11-04 02:05:59 +03:00
|
|
|
nserror
|
|
|
|
gui_window_save_link(struct gui_window *g, nsurl *url, const char *title)
|
2009-03-28 18:43:12 +03:00
|
|
|
{
|
|
|
|
char fname[1024];
|
|
|
|
STRPTR openurlstring,linkname;
|
|
|
|
struct DiskObject *dobj = NULL;
|
|
|
|
|
2014-11-04 02:05:59 +03:00
|
|
|
linkname = ASPrintf("Link_to_%s",FilePart(nsurl_access(url)));
|
2009-03-28 18:43:12 +03:00
|
|
|
|
|
|
|
if(AslRequestTags(savereq,
|
2019-05-07 23:45:40 +03:00
|
|
|
ASLFR_Window, ami_gui_get_gui_window_2(g)->win,
|
2013-05-25 16:59:42 +04:00
|
|
|
ASLFR_SleepWindow, TRUE,
|
2009-03-28 18:43:12 +03:00
|
|
|
ASLFR_TitleText,messages_get("NetSurf"),
|
|
|
|
ASLFR_Screen,scrn,
|
|
|
|
ASLFR_InitialFile,linkname,
|
|
|
|
TAG_DONE))
|
|
|
|
{
|
2011-07-23 18:10:01 +04:00
|
|
|
strlcpy(fname, savereq->fr_Drawer, 1024);
|
2009-03-28 18:43:12 +03:00
|
|
|
AddPart(fname,savereq->fr_File,1024);
|
2013-01-03 23:53:20 +04:00
|
|
|
|
2019-05-07 23:45:40 +03:00
|
|
|
ami_set_pointer(ami_gui_get_gui_window_2(g), GUI_POINTER_WAIT, false);
|
2011-03-26 13:33:58 +03:00
|
|
|
|
2019-05-07 23:45:40 +03:00
|
|
|
if(ami_download_check_overwrite(fname, ami_gui_get_gui_window_2(g)->win, 0))
|
2009-03-28 18:43:12 +03:00
|
|
|
{
|
2014-04-05 22:56:28 +04:00
|
|
|
BPTR fh;
|
|
|
|
|
2014-11-09 04:00:08 +03:00
|
|
|
if((fh = FOpen(fname,MODE_NEWFILE,0)))
|
2011-03-26 13:33:58 +03:00
|
|
|
{
|
2014-11-09 04:00:08 +03:00
|
|
|
/* \todo Should be URLOpen on OS4.1 */
|
2014-11-04 02:05:59 +03:00
|
|
|
openurlstring = ASPrintf("openurl \"%s\"\n",nsurl_access(url));
|
2011-03-26 13:33:58 +03:00
|
|
|
FWrite(fh,openurlstring,1,strlen(openurlstring));
|
|
|
|
FClose(fh);
|
|
|
|
FreeVec(openurlstring);
|
2014-11-04 02:05:59 +03:00
|
|
|
SetComment(fname, nsurl_access(url));
|
2011-03-26 13:33:58 +03:00
|
|
|
|
|
|
|
dobj = GetIconTags(NULL,ICONGETA_GetDefaultName,"url",
|
|
|
|
ICONGETA_GetDefaultType,WBPROJECT,
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
dobj->do_DefaultTool = "IconX";
|
|
|
|
|
|
|
|
PutIconTags(fname,dobj,
|
|
|
|
ICONPUTA_NotifyWorkbench,TRUE,
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
FreeDiskObject(dobj);
|
|
|
|
}
|
|
|
|
FreeVec(linkname);
|
|
|
|
}
|
2019-05-07 23:45:40 +03:00
|
|
|
ami_reset_pointer(ami_gui_get_gui_window_2(g));
|
2011-03-26 13:33:58 +03:00
|
|
|
}
|
2014-11-04 02:05:59 +03:00
|
|
|
return NSERROR_OK;
|
2011-03-26 13:33:58 +03:00
|
|
|
}
|
2009-03-28 18:43:12 +03:00
|
|
|
|
2011-07-23 19:19:27 +04:00
|
|
|
BOOL ami_download_check_overwrite(const char *file, struct Window *win, ULONG size)
|
2011-03-26 13:33:58 +03:00
|
|
|
{
|
|
|
|
/* Return TRUE if file can be (over-)written */
|
2012-12-08 21:47:57 +04:00
|
|
|
int32 res = 0;
|
2011-03-26 13:33:58 +03:00
|
|
|
BPTR lock = 0;
|
2011-07-23 19:19:27 +04:00
|
|
|
char *overwritetext;
|
2009-03-28 18:43:12 +03:00
|
|
|
|
2012-03-22 13:34:34 +04:00
|
|
|
if(nsoption_bool(ask_overwrite) == false) return TRUE;
|
2009-03-28 18:43:12 +03:00
|
|
|
|
2011-03-26 13:33:58 +03:00
|
|
|
lock = Lock(file, ACCESS_READ);
|
2009-03-28 18:43:12 +03:00
|
|
|
|
2011-03-26 13:33:58 +03:00
|
|
|
if(lock)
|
|
|
|
{
|
2011-07-23 19:19:27 +04:00
|
|
|
if(size) {
|
2014-04-05 22:56:28 +04:00
|
|
|
BPTR fh;
|
|
|
|
int64 oldsize = 0;
|
|
|
|
|
2014-11-09 04:00:08 +03:00
|
|
|
if((fh = OpenFromLock(lock))) {
|
2011-07-23 19:19:27 +04:00
|
|
|
oldsize = GetFileSize(fh);
|
|
|
|
Close(fh);
|
|
|
|
}
|
2011-07-23 19:34:52 +04:00
|
|
|
overwritetext = ASPrintf("%s\n\n%s %s\n%s %s",
|
2011-07-23 19:19:27 +04:00
|
|
|
messages_get("OverwriteFile"),
|
2011-07-23 19:34:52 +04:00
|
|
|
messages_get("amiSizeExisting"), human_friendly_bytesize((ULONG)oldsize),
|
|
|
|
messages_get("amiSizeNew"), human_friendly_bytesize(size));
|
2011-07-23 19:19:27 +04:00
|
|
|
} else {
|
|
|
|
UnLock(lock);
|
|
|
|
overwritetext = ASPrintf(messages_get("OverwriteFile"));
|
|
|
|
}
|
|
|
|
|
2016-05-01 16:00:47 +03:00
|
|
|
res = amiga_warn_user_multi(overwritetext, "Replace", "DontReplace", win);
|
2011-07-23 19:19:27 +04:00
|
|
|
FreeVec(overwritetext);
|
2009-03-28 18:43:12 +03:00
|
|
|
}
|
2011-03-26 13:33:58 +03:00
|
|
|
else return TRUE;
|
|
|
|
|
2012-12-10 00:00:59 +04:00
|
|
|
if(res == 1) return TRUE;
|
2011-03-26 13:33:58 +03:00
|
|
|
else return FALSE;
|
2009-03-28 18:43:12 +03:00
|
|
|
}
|
2014-01-14 20:04:02 +04:00
|
|
|
|
2017-03-21 21:42:41 +03:00
|
|
|
void ami_download_parse_backmsg(const char *backmsg)
|
|
|
|
{
|
|
|
|
if((backmsg[0] == 'O') && (backmsg[1] == 'P') && (backmsg[2] == 'E') && (backmsg[3] == 'N')) {
|
|
|
|
OpenWorkbenchObjectA((backmsg + 5), NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-15 23:37:05 +04:00
|
|
|
static struct gui_download_table download_table = {
|
2014-01-14 20:04:02 +04:00
|
|
|
.create = gui_download_window_create,
|
|
|
|
.data = gui_download_window_data,
|
|
|
|
.error = gui_download_window_error,
|
|
|
|
.done = gui_download_window_done,
|
|
|
|
};
|
|
|
|
|
2014-01-15 23:37:05 +04:00
|
|
|
struct gui_download_table *amiga_download_table = &download_table;
|