2014-05-19 20:08:42 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Ole Loots <ole@monochrom.net>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
2013-01-07 23:04:44 +04:00
|
|
|
#include <stdbool.h>
|
2016-06-08 17:30:25 +03:00
|
|
|
#include <time.h>
|
2014-05-19 20:08:42 +04:00
|
|
|
|
2014-10-17 00:23:51 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/nsoption.h"
|
2016-04-22 00:36:21 +03:00
|
|
|
#include "utils/string.h"
|
2017-01-21 19:49:14 +03:00
|
|
|
#include "netsurf/inttypes.h"
|
2016-05-30 19:32:57 +03:00
|
|
|
#include "netsurf/browser_window.h"
|
2016-05-30 13:15:58 +03:00
|
|
|
#include "netsurf/download.h"
|
2016-07-01 16:27:04 +03:00
|
|
|
#include "desktop/save_complete.h"
|
|
|
|
#include "desktop/download.h"
|
2014-10-17 00:23:51 +04:00
|
|
|
|
2014-05-19 20:08:42 +04:00
|
|
|
#include "atari/gui.h"
|
|
|
|
#include "atari/misc.h"
|
|
|
|
#include "atari/res/netsurf.rsh"
|
|
|
|
#include "atari/download.h"
|
|
|
|
#include "atari/osspec.h"
|
2011-12-28 03:30:39 +04:00
|
|
|
|
2012-12-12 04:51:18 +04:00
|
|
|
extern struct gui_window * input_window;
|
|
|
|
extern GRECT desk_area;
|
|
|
|
|
|
|
|
static void gui_download_window_destroy( struct gui_download_window * gdw );
|
|
|
|
static void on_abort_click(struct gui_download_window *dw);
|
2012-12-18 02:32:06 +04:00
|
|
|
static void on_cbrdy_click(struct gui_download_window *dw);
|
2012-12-12 04:51:18 +04:00
|
|
|
static void on_close(struct gui_download_window * dw);
|
|
|
|
static void on_redraw(struct gui_download_window *dw, GRECT *clip);
|
2013-01-15 04:31:35 +04:00
|
|
|
|
2014-10-17 00:23:51 +04:00
|
|
|
static void toolbar_redraw_cb(GUIWIN *win, uint16_t msg, GRECT *clip)
|
2013-01-15 04:31:35 +04:00
|
|
|
{
|
|
|
|
struct gui_download_window *data;
|
|
|
|
|
|
|
|
if (msg != WM_REDRAW) {
|
2013-01-22 05:33:27 +04:00
|
|
|
data = gemtk_wm_get_user_data(win);
|
2013-01-15 04:31:35 +04:00
|
|
|
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
on_redraw(data, clip);
|
|
|
|
}
|
|
|
|
}
|
2012-12-12 04:51:18 +04:00
|
|
|
|
|
|
|
static short on_aes_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
|
|
|
|
{
|
|
|
|
short retval = 0;
|
2012-12-17 03:36:17 +04:00
|
|
|
struct gui_download_window *data;
|
|
|
|
|
2012-12-12 04:51:18 +04:00
|
|
|
GRECT clip;
|
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
data = gemtk_wm_get_user_data(win);
|
2012-12-12 04:51:18 +04:00
|
|
|
|
|
|
|
if ((ev_out->emo_events & MU_MESAG) != 0) {
|
|
|
|
// handle message
|
2012-12-18 02:32:06 +04:00
|
|
|
//printf("download win msg: %d\n", msg[0]);
|
2012-12-12 04:51:18 +04:00
|
|
|
switch (msg[0]) {
|
|
|
|
|
|
|
|
case WM_REDRAW:
|
|
|
|
clip.g_x = msg[4];
|
|
|
|
clip.g_y = msg[5];
|
|
|
|
clip.g_w = msg[6];
|
|
|
|
clip.g_h = msg[7];
|
2012-12-17 03:36:17 +04:00
|
|
|
on_redraw(data, &clip);
|
2012-12-12 04:51:18 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_CLOSED:
|
|
|
|
// TODO: this needs to iterate through all gui windows and
|
|
|
|
// check if the rootwin is this window...
|
2012-12-18 04:10:20 +04:00
|
|
|
on_close(data);
|
2012-12-12 04:51:18 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_TOOLBAR:
|
|
|
|
switch(msg[4]){
|
|
|
|
|
|
|
|
case DOWNLOAD_BT_ABORT:
|
2012-12-17 03:36:17 +04:00
|
|
|
on_abort_click(data);
|
2012-12-12 04:51:18 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DOWNLOAD_CB_CLOSE_RDY:
|
2012-12-18 02:32:06 +04:00
|
|
|
on_cbrdy_click(data);
|
2012-12-12 04:51:18 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((ev_out->emo_events & MU_KEYBD) != 0) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
if ((ev_out->emo_events & MU_BUTTON) != 0) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return(retval);
|
2014-05-19 20:08:42 +04:00
|
|
|
}
|
2012-12-12 04:51:18 +04:00
|
|
|
|
|
|
|
static void on_redraw(struct gui_download_window *dw, GRECT *clip)
|
|
|
|
{
|
|
|
|
OBJECT *tree = dw->tree;
|
|
|
|
GRECT work, visible;
|
|
|
|
uint32_t p = 0;
|
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_get_grect(dw->guiwin, GEMTK_WM_AREA_TOOLBAR, &work);
|
2012-12-12 04:51:18 +04:00
|
|
|
tree->ob_x = work.g_x;
|
|
|
|
tree->ob_y = work.g_y;
|
|
|
|
|
|
|
|
if(!rc_intersect(clip, &work)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Update the AES Object to reflect current state of download:
|
|
|
|
*/
|
2012-12-31 06:37:43 +04:00
|
|
|
((TEDINFO *)get_obspec(tree, DOWNLOAD_FILENAME))->te_ptext = dw->lbl_file;
|
|
|
|
((TEDINFO *)get_obspec(tree, DOWNLOAD_LBL_BYTES))->te_ptext = dw->lbl_done;
|
|
|
|
((TEDINFO *)get_obspec(tree, DOWNLOAD_LBL_PERCENT))->te_ptext = dw->lbl_percent;
|
|
|
|
((TEDINFO *)get_obspec(tree, DOWNLOAD_LBL_SPEED))->te_ptext = dw->lbl_speed;
|
2012-12-12 04:51:18 +04:00
|
|
|
|
2014-05-19 20:08:42 +04:00
|
|
|
if (dw->size_total > 0 ) {
|
|
|
|
p = ((double)dw->size_downloaded / (double)dw->size_total * 100);
|
2012-12-12 04:51:18 +04:00
|
|
|
}
|
|
|
|
tree[DOWNLOAD_PROGRESS_DONE].ob_width = MAX( MIN( p*(DOWNLOAD_BAR_MAX/100),
|
|
|
|
DOWNLOAD_BAR_MAX ), 1);
|
2012-12-17 03:36:17 +04:00
|
|
|
if (dw->close_on_finish) {
|
2013-01-07 23:04:44 +04:00
|
|
|
tree[DOWNLOAD_CB_CLOSE_RDY].ob_state |= (OS_SELECTED | OS_CROSSED);
|
2012-12-17 03:36:17 +04:00
|
|
|
} else {
|
2013-01-07 23:04:44 +04:00
|
|
|
tree[DOWNLOAD_CB_CLOSE_RDY].ob_state &= ~(OS_SELECTED | OS_CROSSED);
|
2012-12-17 03:36:17 +04:00
|
|
|
}
|
2013-01-07 23:04:44 +04:00
|
|
|
tree[DOWNLOAD_BT_ABORT].ob_state &= ~OS_SELECTED;
|
2012-12-12 04:51:18 +04:00
|
|
|
|
|
|
|
/*Walk the AES rectangle list and redraw the visible areas of the window: */
|
|
|
|
wind_get_grect(dw->aes_handle, WF_FIRSTXYWH, &visible);
|
|
|
|
while (visible.g_x && visible.g_y) {
|
|
|
|
if (rc_intersect(&work, &visible)) {
|
|
|
|
objc_draw_grect(tree, 0, 8, &visible);
|
|
|
|
}
|
|
|
|
wind_get_grect(dw->aes_handle, WF_NEXTXYWH, &visible);
|
|
|
|
}
|
|
|
|
}
|
2014-05-19 20:08:42 +04:00
|
|
|
|
|
|
|
static void on_abort_click(struct gui_download_window *dw)
|
|
|
|
{
|
2012-03-11 19:42:41 +04:00
|
|
|
if( dw->status == NSATARI_DOWNLOAD_COMPLETE
|
|
|
|
|| dw->status == NSATARI_DOWNLOAD_ERROR ) {
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_send_msg(dw->guiwin, WM_CLOSED, 0,0,0,0);
|
2014-05-19 20:08:42 +04:00
|
|
|
}
|
|
|
|
else if( dw->status != NSATARI_DOWNLOAD_CANCELED ){
|
|
|
|
dw->abort = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void on_cbrdy_click(struct gui_download_window *dw)
|
2012-12-17 03:36:17 +04:00
|
|
|
{
|
2014-05-19 20:08:42 +04:00
|
|
|
dw->close_on_finish = !dw->close_on_finish;
|
2012-12-17 03:36:17 +04:00
|
|
|
if (dw->close_on_finish && dw->status == NSATARI_DOWNLOAD_COMPLETE) {
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_send_msg(dw->guiwin, WM_CLOSED, 0,0,0,0);
|
2012-12-17 03:36:17 +04:00
|
|
|
}
|
2013-04-12 00:56:48 +04:00
|
|
|
gemtk_wm_exec_redraw(dw->guiwin, NULL);
|
2014-05-19 20:08:42 +04:00
|
|
|
evnt_timer(250);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void on_close(struct gui_download_window * dw)
|
|
|
|
{
|
|
|
|
gui_download_window_destroy(dw);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gui_download_window_destroy( struct gui_download_window * gdw)
|
|
|
|
{
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "gdw %p", gdw);
|
2014-05-19 20:08:42 +04:00
|
|
|
|
|
|
|
if (gdw->status == NSATARI_DOWNLOAD_WORKING) {
|
|
|
|
download_context_abort(gdw->ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
download_context_destroy(gdw->ctx);
|
|
|
|
|
|
|
|
if (gdw->destination) {
|
|
|
|
free( gdw->destination );
|
|
|
|
}
|
|
|
|
if (gdw->fd != NULL) {
|
|
|
|
fclose(gdw->fd);
|
|
|
|
gdw->fd = NULL;
|
|
|
|
}
|
|
|
|
if (gdw->fbuf != NULL) {
|
|
|
|
free( gdw->fbuf );
|
|
|
|
}
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_remove(gdw->guiwin);
|
2012-12-21 03:56:50 +04:00
|
|
|
wind_close(gdw->aes_handle);
|
2014-05-19 20:08:42 +04:00
|
|
|
wind_delete(gdw->aes_handle);
|
|
|
|
free(gdw);
|
2012-03-22 01:12:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static char * select_filepath( const char * path, const char * filename )
|
|
|
|
{
|
|
|
|
char tmp[PATH_MAX];
|
|
|
|
char res_path[PATH_MAX];
|
|
|
|
char res_file[PATH_MAX];
|
|
|
|
char * ret = NULL;
|
|
|
|
|
2013-01-07 23:04:44 +04:00
|
|
|
strncpy(res_path, path, PATH_MAX);
|
|
|
|
strncpy(res_file, filename, PATH_MAX);
|
2012-03-22 01:12:06 +04:00
|
|
|
res_file[PATH_MAX-1] = 0;
|
|
|
|
res_path[PATH_MAX-1] = 0;
|
2013-01-07 23:04:44 +04:00
|
|
|
|
|
|
|
if(select_file(res_path, res_file, (char*)"*",
|
|
|
|
(char*)messages_get("SaveAsNS"), NULL)) {
|
|
|
|
snprintf(tmp, PATH_MAX, "%s%s", res_path, res_file);
|
|
|
|
ret = malloc(strlen(tmp)+1);
|
|
|
|
strcpy(ret, tmp);
|
2012-03-22 01:12:06 +04:00
|
|
|
}
|
2013-01-07 23:04:44 +04:00
|
|
|
|
|
|
|
printf("download file: %s\n", ret);
|
|
|
|
return(ret);
|
2014-05-19 20:08:42 +04:00
|
|
|
}
|
2012-12-17 03:36:17 +04:00
|
|
|
|
2014-01-14 20:04:02 +04:00
|
|
|
static struct gui_download_window *
|
|
|
|
gui_download_window_create(download_context *ctx, struct gui_window *parent)
|
2012-12-17 03:36:17 +04:00
|
|
|
{
|
2014-05-19 20:08:42 +04:00
|
|
|
const char *filename;
|
|
|
|
char *destination;
|
|
|
|
char gdos_path[PATH_MAX];
|
2012-03-22 01:12:06 +04:00
|
|
|
struct gui_download_window * gdw;
|
|
|
|
int dlgres = 0;
|
2013-01-22 05:33:27 +04:00
|
|
|
OBJECT * tree = gemtk_obj_get_tree(DOWNLOAD);
|
2013-01-17 05:04:43 +04:00
|
|
|
char alert[200];
|
2012-03-22 01:12:06 +04:00
|
|
|
|
2012-12-17 03:36:17 +04:00
|
|
|
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Creating download window for gui window: %p",
|
|
|
|
parent);
|
2012-12-12 04:51:18 +04:00
|
|
|
|
2014-05-19 20:08:42 +04:00
|
|
|
/* TODO: Implement real form and use messages file strings! */
|
|
|
|
|
2012-12-17 03:36:17 +04:00
|
|
|
if (tree == NULL){
|
|
|
|
die("Couldn't find AES Object tree for download window!");
|
|
|
|
return(NULL);
|
|
|
|
}
|
2014-05-19 20:08:42 +04:00
|
|
|
|
2013-01-15 04:31:35 +04:00
|
|
|
filename = download_context_get_filename((const download_context*)ctx);
|
2013-01-17 05:04:43 +04:00
|
|
|
snprintf(alert, 200, "[2][Accept download?|%.*s][Yes|Save as...|No]",
|
|
|
|
40,filename);
|
2014-05-19 20:08:42 +04:00
|
|
|
dlgres = form_alert(2, alert);
|
|
|
|
if( dlgres == 3){
|
|
|
|
return( NULL );
|
2012-03-22 01:12:06 +04:00
|
|
|
}
|
|
|
|
else if( dlgres == 2 ){
|
2012-03-22 13:34:34 +04:00
|
|
|
gemdos_realpath(nsoption_charp(downloads_path), gdos_path);
|
2012-03-22 01:12:06 +04:00
|
|
|
char * tmp = select_filepath( gdos_path, filename );
|
|
|
|
if( tmp == NULL )
|
|
|
|
return( NULL );
|
|
|
|
destination = tmp;
|
|
|
|
} else {
|
2012-05-13 19:31:30 +04:00
|
|
|
int dstsize=0;
|
2012-03-22 13:34:34 +04:00
|
|
|
gemdos_realpath(nsoption_charp(downloads_path), gdos_path);
|
2012-05-13 19:31:30 +04:00
|
|
|
dstsize = strlen(gdos_path) + strlen(filename) + 2;
|
|
|
|
destination = malloc( dstsize );
|
2012-12-21 03:56:50 +04:00
|
|
|
snprintf(destination, dstsize, "%s/%s", gdos_path, filename);
|
2012-03-22 01:12:06 +04:00
|
|
|
}
|
2014-05-19 20:08:42 +04:00
|
|
|
|
|
|
|
gdw = calloc(1, sizeof(struct gui_download_window));
|
2012-03-22 01:12:06 +04:00
|
|
|
if( gdw == NULL ){
|
2016-04-30 13:34:45 +03:00
|
|
|
atari_warn_user(NULL, "Out of memory!");
|
2014-05-19 20:08:42 +04:00
|
|
|
free( destination );
|
2012-03-22 01:12:06 +04:00
|
|
|
return( NULL );
|
|
|
|
}
|
2014-05-19 20:08:42 +04:00
|
|
|
|
|
|
|
gdw->ctx = ctx;
|
|
|
|
gdw->abort = false;
|
|
|
|
gdw->start = clock() / CLOCKS_PER_SEC;
|
|
|
|
gdw->lastrdw = 0;
|
|
|
|
gdw->status = NSATARI_DOWNLOAD_WORKING;
|
|
|
|
gdw->parent = parent;
|
|
|
|
gdw->fbufsize = MAX(BUFSIZ, 48000);
|
|
|
|
gdw->size_downloaded = 0;
|
2012-03-22 01:12:06 +04:00
|
|
|
gdw->size_total = download_context_get_total_length(ctx);
|
2012-12-17 03:36:17 +04:00
|
|
|
gdw->destination = destination;
|
2014-05-19 20:08:42 +04:00
|
|
|
gdw->tree = tree;
|
|
|
|
|
|
|
|
gdw->fd = fopen(gdw->destination, "wb");
|
2012-12-12 04:51:18 +04:00
|
|
|
if( gdw->fd == NULL ){
|
|
|
|
char spare[200];
|
|
|
|
snprintf(spare, 200, "Couldn't open %s for writing!", gdw->destination);
|
2014-05-19 20:08:42 +04:00
|
|
|
gemtk_msg_box_show(GEMTK_MSG_BOX_ALERT, spare);
|
|
|
|
gui_download_window_destroy(gdw);
|
|
|
|
return( NULL );
|
2012-03-22 01:12:06 +04:00
|
|
|
}
|
2014-05-19 20:08:42 +04:00
|
|
|
|
|
|
|
gdw->fbuf = malloc( gdw->fbufsize+1 );
|
|
|
|
if( gdw->fbuf != NULL ){
|
|
|
|
setvbuf( gdw->fd, gdw->fbuf, _IOFBF, gdw->fbufsize );
|
2012-12-12 04:51:18 +04:00
|
|
|
}
|
|
|
|
|
2012-12-18 02:32:06 +04:00
|
|
|
gdw->aes_handle = wind_create_grect(CLOSER | NAME | MOVER, &desk_area);
|
2012-12-12 04:51:18 +04:00
|
|
|
wind_set_str(gdw->aes_handle, WF_NAME, "Download");
|
2013-01-22 05:33:27 +04:00
|
|
|
unsigned long gwflags = GEMTK_WM_FLAG_DEFAULTS;
|
|
|
|
gdw->guiwin = gemtk_wm_add(gdw->aes_handle, gwflags, on_aes_event);
|
2012-12-12 04:51:18 +04:00
|
|
|
if( gdw->guiwin == NULL || gdw->fd == NULL ){
|
2014-05-19 20:08:42 +04:00
|
|
|
die("could not create guiwin");
|
|
|
|
gui_download_window_destroy(gdw);
|
|
|
|
return( NULL );
|
2012-12-17 03:36:17 +04:00
|
|
|
}
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_set_user_data(gdw->guiwin, gdw);
|
|
|
|
gemtk_wm_set_toolbar(gdw->guiwin, tree, 0, 0);
|
2014-05-19 20:08:42 +04:00
|
|
|
gemtk_wm_set_toolbar_redraw_func(gdw->guiwin, toolbar_redraw_cb);
|
|
|
|
|
|
|
|
strncpy((char*)&gdw->lbl_file, filename, MAX_SLEN_LBL_FILE-1);
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "created download: %s (total size: %d)",
|
|
|
|
gdw->destination, gdw->size_total);
|
2012-12-12 04:51:18 +04:00
|
|
|
|
|
|
|
GRECT work, curr;
|
|
|
|
work.g_x = 0;
|
|
|
|
work.g_y = 0;
|
|
|
|
work.g_w = tree->ob_width;
|
|
|
|
work.g_h = tree->ob_height;
|
|
|
|
|
2012-12-17 03:36:17 +04:00
|
|
|
wind_calc_grect(WC_BORDER, CLOSER | MOVER | NAME, &work, &curr);
|
2012-12-12 04:51:18 +04:00
|
|
|
|
|
|
|
curr.g_x = (desk_area.g_w / 2) - (curr.g_w / 2);
|
|
|
|
curr.g_y = (desk_area.g_h / 2) - (curr.g_h / 2);
|
|
|
|
|
2012-12-17 03:36:17 +04:00
|
|
|
wind_open_grect(gdw->aes_handle, &curr);
|
2012-12-18 02:32:06 +04:00
|
|
|
gdw->lastrdw = clock() / (CLOCKS_PER_SEC >> 3);
|
2012-12-17 03:36:17 +04:00
|
|
|
|
|
|
|
return(gdw);
|
|
|
|
}
|
2014-05-19 20:08:42 +04:00
|
|
|
|
|
|
|
|
|
|
|
static nserror gui_download_window_data(struct gui_download_window *dw,
|
|
|
|
const char *data, unsigned int size)
|
|
|
|
{
|
|
|
|
uint32_t clck = clock();
|
|
|
|
uint32_t tnow = clck / (CLOCKS_PER_SEC>>3);
|
2012-12-18 02:32:06 +04:00
|
|
|
uint32_t sdiff = (clck / (CLOCKS_PER_SEC)) - dw->start;
|
2012-12-12 04:51:18 +04:00
|
|
|
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "dw %p", dw);
|
2012-12-17 03:36:17 +04:00
|
|
|
|
2016-04-20 12:43:58 +03:00
|
|
|
if (dw->abort == true){
|
2014-05-19 20:08:42 +04:00
|
|
|
dw->status = NSATARI_DOWNLOAD_CANCELED;
|
|
|
|
dw->abort = false;
|
2012-12-12 04:51:18 +04:00
|
|
|
download_context_abort(dw->ctx);
|
2014-05-19 20:08:42 +04:00
|
|
|
gemtk_wm_exec_redraw(dw->guiwin, NULL);
|
|
|
|
return(NSERROR_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save data */
|
|
|
|
fwrite( data , size, sizeof(unsigned char),dw->fd );
|
2012-12-12 04:51:18 +04:00
|
|
|
dw->size_downloaded += size;
|
|
|
|
|
2014-05-19 20:08:42 +04:00
|
|
|
/* Update GUI */
|
2012-12-18 02:32:06 +04:00
|
|
|
if ((tnow - dw->lastrdw) > 1) {
|
2014-05-19 20:12:18 +04:00
|
|
|
float speed;
|
2012-12-12 04:51:18 +04:00
|
|
|
|
2014-05-19 20:08:42 +04:00
|
|
|
dw->lastrdw = tnow;
|
|
|
|
speed = dw->size_downloaded / sdiff;
|
|
|
|
|
2012-12-12 04:51:18 +04:00
|
|
|
if( dw->size_total > 0 ){
|
2014-05-19 20:12:18 +04:00
|
|
|
uint32_t p = 0;
|
2014-05-19 20:08:42 +04:00
|
|
|
p = ((double)dw->size_downloaded / (double)dw->size_total * 100);
|
|
|
|
snprintf( (char*)&dw->lbl_percent, MAX_SLEN_LBL_PERCENT,
|
2014-10-17 00:23:51 +04:00
|
|
|
"%"PRIu32"%s", p, "%"
|
2014-05-19 20:08:42 +04:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
snprintf( (char*)&dw->lbl_percent, MAX_SLEN_LBL_PERCENT,
|
|
|
|
"%s", "?%"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
snprintf( (char*)&dw->lbl_speed, MAX_SLEN_LBL_SPEED, "%s/s",
|
|
|
|
human_friendly_bytesize(speed)
|
|
|
|
);
|
|
|
|
snprintf( (char*)&dw->lbl_done, MAX_SLEN_LBL_DONE, "%s / %s",
|
|
|
|
human_friendly_bytesize(dw->size_downloaded),
|
|
|
|
(dw->size_total>0) ? human_friendly_bytesize(dw->size_total) : "?"
|
2012-12-12 04:51:18 +04:00
|
|
|
);
|
2012-12-17 03:36:17 +04:00
|
|
|
|
2014-05-19 20:08:42 +04:00
|
|
|
gemtk_wm_exec_redraw(dw->guiwin, NULL);
|
|
|
|
}
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gui_download_window_error(struct gui_download_window *dw,
|
|
|
|
const char *error_msg)
|
|
|
|
{
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "%s", error_msg);
|
2016-04-20 12:43:58 +03:00
|
|
|
|
2014-05-19 20:08:42 +04:00
|
|
|
strncpy((char*)&dw->lbl_file, error_msg, MAX_SLEN_LBL_FILE-1);
|
|
|
|
dw->status = NSATARI_DOWNLOAD_ERROR;
|
2013-04-12 00:56:48 +04:00
|
|
|
gemtk_wm_exec_redraw(dw->guiwin, NULL);
|
2014-11-10 23:15:14 +03:00
|
|
|
atari_window_set_status(input_window, messages_get("Done") );
|
2014-05-19 20:08:42 +04:00
|
|
|
// TODO: change abort to close
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gui_download_window_done(struct gui_download_window *dw)
|
2012-03-11 19:42:41 +04:00
|
|
|
{
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "dw %p", dw);
|
2012-12-18 02:32:06 +04:00
|
|
|
|
2014-05-19 20:08:42 +04:00
|
|
|
// TODO: change abort to close
|
2012-03-11 19:42:41 +04:00
|
|
|
dw->status = NSATARI_DOWNLOAD_COMPLETE;
|
2014-05-19 20:08:42 +04:00
|
|
|
|
|
|
|
if( dw->fd != NULL ) {
|
|
|
|
fclose( dw->fd );
|
|
|
|
dw->fd = NULL;
|
|
|
|
}
|
2012-03-11 19:42:41 +04:00
|
|
|
|
2012-12-17 03:36:17 +04:00
|
|
|
if (dw->close_on_finish) {
|
2014-05-19 20:08:42 +04:00
|
|
|
gemtk_wm_send_msg(dw->guiwin, WM_CLOSED, 0, 0, 0, 0);
|
2012-12-17 03:36:17 +04:00
|
|
|
} else {
|
2014-05-19 20:08:42 +04:00
|
|
|
snprintf( (char*)&dw->lbl_percent, MAX_SLEN_LBL_PERCENT,
|
2014-10-17 00:23:51 +04:00
|
|
|
"%u%s", 100, "%"
|
2014-05-19 20:08:42 +04:00
|
|
|
);
|
|
|
|
snprintf( (char*)&dw->lbl_done, MAX_SLEN_LBL_DONE, "%s / %s",
|
|
|
|
human_friendly_bytesize(dw->size_downloaded),
|
|
|
|
(dw->size_total>0) ? human_friendly_bytesize(dw->size_total) : human_friendly_bytesize(dw->size_downloaded)
|
|
|
|
);
|
2013-04-12 00:56:48 +04:00
|
|
|
gemtk_wm_exec_redraw(dw->guiwin, NULL);
|
2011-12-28 03:30:39 +04:00
|
|
|
}
|
2014-11-10 23:15:14 +03:00
|
|
|
atari_window_set_status(input_window, messages_get("Done") );
|
2014-05-19 20:08:42 +04:00
|
|
|
}
|
2014-01-14 20:04:02 +04:00
|
|
|
|
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 *atari_download_table = &download_table;
|