2011-01-06 00:02:22 +03: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>
|
2011-02-02 00:26:29 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2011-01-06 00:02:22 +03:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
2013-01-07 23:04:44 +04:00
|
|
|
#include <stdbool.h>
|
2011-01-06 00:02:22 +03:00
|
|
|
|
|
|
|
#include "content/urldb.h"
|
|
|
|
#include "content/fetch.h"
|
|
|
|
#include "desktop/gui.h"
|
2013-07-10 14:55:42 +04:00
|
|
|
#include "desktop/local_history.h"
|
2011-01-06 00:02:22 +03:00
|
|
|
#include "desktop/netsurf.h"
|
2013-05-26 01:46:27 +04:00
|
|
|
#include "utils/nsoption.h"
|
2011-01-06 00:02:22 +03:00
|
|
|
#include "desktop/save_complete.h"
|
|
|
|
#include "desktop/textinput.h"
|
2011-02-02 00:26:29 +03:00
|
|
|
#include "desktop/download.h"
|
2011-01-06 00:02:22 +03:00
|
|
|
#include "render/html.h"
|
|
|
|
#include "utils/url.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "atari/gui.h"
|
2011-02-02 00:26:29 +03:00
|
|
|
#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
|
|
|
static void toolbar_redraw_cb(GUIWIN *win, uint16_t msg, GRECT *clip);
|
|
|
|
|
|
|
|
static void toolbar_redraw_cb(GUIWIN *win, uint16_t msg, GRECT *clip)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2012-12-17 03:36:17 +04:00
|
|
|
if (dw->size_total > 0 ) {
|
2012-12-12 04:51:18 +04:00
|
|
|
p = ((double)dw->size_downloaded / (double)dw->size_total * 100);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2011-02-02 00:26:29 +03:00
|
|
|
|
2012-12-12 04:51:18 +04:00
|
|
|
static void on_abort_click(struct gui_download_window *dw)
|
2011-02-02 00:26:29 +03:00
|
|
|
{
|
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);
|
2012-03-11 19:42:41 +04:00
|
|
|
}
|
|
|
|
else if( dw->status != NSATARI_DOWNLOAD_CANCELED ){
|
2011-02-02 00:26:29 +03:00
|
|
|
dw->abort = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-12 04:51:18 +04:00
|
|
|
static void on_cbrdy_click(struct gui_download_window *dw)
|
2012-12-17 03:36:17 +04:00
|
|
|
{
|
2012-12-18 02:32:06 +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);
|
2012-12-18 02:32:06 +04:00
|
|
|
evnt_timer(250);
|
2011-02-02 00:26:29 +03:00
|
|
|
}
|
|
|
|
|
2012-12-12 04:51:18 +04:00
|
|
|
static void on_close(struct gui_download_window * dw)
|
2011-02-02 00:26:29 +03:00
|
|
|
{
|
2012-12-12 04:51:18 +04:00
|
|
|
gui_download_window_destroy(dw);
|
2011-02-02 00:26:29 +03:00
|
|
|
}
|
|
|
|
|
2012-12-12 04:51:18 +04:00
|
|
|
static void gui_download_window_destroy( struct gui_download_window * gdw)
|
2011-02-02 00:26:29 +03:00
|
|
|
{
|
2012-12-12 04:51:18 +04:00
|
|
|
|
|
|
|
|
|
|
|
LOG((""));
|
|
|
|
if (gdw->status == NSATARI_DOWNLOAD_WORKING) {
|
|
|
|
download_context_abort(gdw->ctx);
|
2011-02-02 00:26:29 +03:00
|
|
|
}
|
2012-12-12 04:51:18 +04:00
|
|
|
|
|
|
|
download_context_destroy(gdw->ctx);
|
|
|
|
|
|
|
|
if (gdw->destination) {
|
2011-02-02 00:26:29 +03:00
|
|
|
free( gdw->destination );
|
|
|
|
}
|
2012-12-12 04:51:18 +04:00
|
|
|
if (gdw->fd != NULL) {
|
2011-02-02 00:26:29 +03:00
|
|
|
fclose(gdw->fd);
|
|
|
|
gdw->fd = NULL;
|
|
|
|
}
|
2012-12-12 04:51:18 +04:00
|
|
|
if (gdw->fbuf != NULL) {
|
2011-11-24 00:01:47 +04:00
|
|
|
free( gdw->fbuf );
|
2012-12-21 03:56:50 +04:00
|
|
|
}
|
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);
|
|
|
|
wind_delete(gdw->aes_handle);
|
2012-12-17 03:36:17 +04:00
|
|
|
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);
|
2011-02-02 00:26:29 +03:00
|
|
|
}
|
2012-12-17 03:36:17 +04:00
|
|
|
|
|
|
|
struct gui_download_window * gui_download_window_create(download_context *ctx,
|
|
|
|
struct gui_window *parent)
|
|
|
|
{
|
2013-01-15 04:31:35 +04:00
|
|
|
const char *filename;
|
2012-03-22 13:34:34 +04:00
|
|
|
char *destination;
|
2012-03-22 01:12:06 +04:00
|
|
|
char gdos_path[PATH_MAX];
|
2011-02-02 00:26:29 +03:00
|
|
|
const char * url;
|
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
|
|
|
|
2012-12-12 04:51:18 +04:00
|
|
|
LOG(("Creating download window for gui window: %p", parent));
|
|
|
|
|
2011-02-02 00:26:29 +03: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);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
dlgres = form_alert(2, alert);
|
2012-03-22 01:12:06 +04:00
|
|
|
if( dlgres == 3){
|
2011-02-02 00:26:29 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-12-18 02:32:06 +04:00
|
|
|
gdw = calloc(1, sizeof(struct gui_download_window));
|
2012-03-22 01:12:06 +04:00
|
|
|
if( gdw == NULL ){
|
2012-12-12 04:51:18 +04:00
|
|
|
warn_user(NULL, "Out of memory!");
|
2012-03-22 01:12:06 +04:00
|
|
|
free( destination );
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
2011-02-02 00:26:29 +03:00
|
|
|
gdw->ctx = ctx;
|
|
|
|
gdw->abort = false;
|
2011-02-02 22:48:13 +03:00
|
|
|
gdw->start = clock() / CLOCKS_PER_SEC;
|
2011-11-24 00:01:47 +04:00
|
|
|
gdw->lastrdw = 0;
|
2011-02-02 00:26:29 +03:00
|
|
|
gdw->status = NSATARI_DOWNLOAD_WORKING;
|
|
|
|
gdw->parent = parent;
|
2011-02-02 22:48:13 +03:00
|
|
|
gdw->fbufsize = MAX(BUFSIZ, 48000);
|
2011-02-02 00:26:29 +03:00
|
|
|
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;
|
|
|
|
gdw->tree = tree;
|
2011-02-02 00:26:29 +03:00
|
|
|
url = download_context_get_url(ctx);
|
|
|
|
|
2012-12-18 02:32:06 +04:00
|
|
|
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);
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_msg_box_show(GEMTK_MSG_BOX_ALERT, spare);
|
2011-02-02 00:26:29 +03:00
|
|
|
gui_download_window_destroy(gdw);
|
|
|
|
return( NULL );
|
2012-03-22 01:12:06 +04:00
|
|
|
}
|
|
|
|
|
2011-02-02 22:48:13 +03:00
|
|
|
gdw->fbuf = malloc( gdw->fbufsize+1 );
|
|
|
|
if( gdw->fbuf != NULL ){
|
2011-11-24 00:01:47 +04:00
|
|
|
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 ){
|
|
|
|
die("could not create guiwin");
|
2011-02-02 00:26:29 +03:00
|
|
|
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);
|
|
|
|
gemtk_wm_set_toolbar_redraw_func(gdw->guiwin, toolbar_redraw_cb);
|
2011-02-02 00:26:29 +03:00
|
|
|
|
2012-12-18 02:32:06 +04:00
|
|
|
strncpy((char*)&gdw->lbl_file, filename, MAX_SLEN_LBL_FILE-1);
|
2011-02-02 22:48:13 +03:00
|
|
|
LOG(("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);
|
|
|
|
}
|
2011-02-02 00:26:29 +03:00
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
|
2011-11-24 00:01:47 +04:00
|
|
|
nserror gui_download_window_data(struct gui_download_window *dw,
|
2011-01-06 00:02:22 +03:00
|
|
|
const char *data, unsigned int size)
|
|
|
|
{
|
2012-12-18 02:32:06 +04:00
|
|
|
|
|
|
|
uint32_t clck = clock();
|
|
|
|
uint32_t tnow = clck / (CLOCKS_PER_SEC>>3);
|
|
|
|
uint32_t sdiff = (clck / (CLOCKS_PER_SEC)) - dw->start;
|
2012-12-12 04:51:18 +04:00
|
|
|
uint32_t p = 0;
|
2011-02-02 00:26:29 +03:00
|
|
|
float speed;
|
2012-12-12 04:51:18 +04:00
|
|
|
float pf = 0;
|
|
|
|
|
|
|
|
LOG((""));
|
2012-12-17 03:36:17 +04:00
|
|
|
|
2012-12-12 04:51:18 +04:00
|
|
|
OBJECT * tree = dw->tree;
|
|
|
|
|
|
|
|
if(dw->abort == true){
|
2011-02-02 00:26:29 +03:00
|
|
|
dw->status = NSATARI_DOWNLOAD_CANCELED;
|
|
|
|
dw->abort = false;
|
2012-12-12 04:51:18 +04:00
|
|
|
download_context_abort(dw->ctx);
|
2013-04-12 00:56:48 +04:00
|
|
|
gemtk_wm_exec_redraw(dw->guiwin, NULL);
|
2012-12-12 04:51:18 +04:00
|
|
|
return(NSERROR_OK);
|
2011-02-02 00:26:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* save data */
|
2011-02-02 22:48:13 +03:00
|
|
|
fwrite( data , size, sizeof(unsigned char),dw->fd );
|
2012-12-12 04:51:18 +04:00
|
|
|
dw->size_downloaded += size;
|
|
|
|
|
2012-12-18 02:32:06 +04:00
|
|
|
/* Update GUI */
|
|
|
|
if ((tnow - dw->lastrdw) > 1) {
|
2012-12-12 04:51:18 +04:00
|
|
|
|
2011-02-02 22:48:13 +03:00
|
|
|
dw->lastrdw = tnow;
|
|
|
|
speed = dw->size_downloaded / sdiff;
|
2012-12-12 04:51:18 +04:00
|
|
|
|
|
|
|
if( dw->size_total > 0 ){
|
|
|
|
p = ((double)dw->size_downloaded / (double)dw->size_total * 100);
|
2011-11-24 00:01:47 +04:00
|
|
|
snprintf( (char*)&dw->lbl_percent, MAX_SLEN_LBL_PERCENT,
|
|
|
|
"%lu%s", p, "%"
|
2011-02-02 22:48:13 +03:00
|
|
|
);
|
|
|
|
} else {
|
2011-11-24 00:01:47 +04:00
|
|
|
snprintf( (char*)&dw->lbl_percent, MAX_SLEN_LBL_PERCENT,
|
2011-02-02 22:48:13 +03:00
|
|
|
"%s", "?%"
|
|
|
|
);
|
|
|
|
}
|
2011-11-24 00:01:47 +04:00
|
|
|
snprintf( (char*)&dw->lbl_speed, MAX_SLEN_LBL_SPEED, "%s/s",
|
2011-02-02 22:48:13 +03:00
|
|
|
human_friendly_bytesize(speed)
|
|
|
|
);
|
2011-11-24 00:01:47 +04:00
|
|
|
snprintf( (char*)&dw->lbl_done, MAX_SLEN_LBL_DONE, "%s / %s",
|
2011-02-02 22:48:13 +03:00
|
|
|
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
|
|
|
|
2013-04-12 00:56:48 +04:00
|
|
|
gemtk_wm_exec_redraw(dw->guiwin, NULL);
|
2011-02-02 00:26:29 +03:00
|
|
|
}
|
2011-01-06 00:02:22 +03:00
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gui_download_window_error(struct gui_download_window *dw,
|
|
|
|
const char *error_msg)
|
|
|
|
{
|
2011-02-02 00:26:29 +03:00
|
|
|
LOG(("%s", error_msg));
|
|
|
|
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);
|
2012-12-18 02:32:06 +04:00
|
|
|
gui_window_set_status(input_window, messages_get("Done") );
|
|
|
|
// TODO: change abort to close
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void gui_download_window_done(struct gui_download_window *dw)
|
2012-03-11 19:42:41 +04:00
|
|
|
{
|
|
|
|
OBJECT * tree;
|
|
|
|
LOG((""));
|
2012-12-18 02:32:06 +04:00
|
|
|
|
|
|
|
// TODO: change abort to close
|
2012-03-11 19:42:41 +04:00
|
|
|
dw->status = NSATARI_DOWNLOAD_COMPLETE;
|
|
|
|
|
2011-02-02 00:26:29 +03:00
|
|
|
if( dw->fd != NULL ) {
|
|
|
|
fclose( dw->fd );
|
|
|
|
dw->fd = NULL;
|
|
|
|
}
|
2012-03-11 19:42:41 +04:00
|
|
|
|
2012-12-12 04:51:18 +04:00
|
|
|
tree = dw->tree;
|
2012-12-17 03:36:17 +04:00
|
|
|
if (dw->close_on_finish) {
|
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
|
|
|
} else {
|
2012-03-11 19:42:41 +04:00
|
|
|
snprintf( (char*)&dw->lbl_percent, MAX_SLEN_LBL_PERCENT,
|
|
|
|
"%lu%s", 100, "%"
|
|
|
|
);
|
|
|
|
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)
|
2012-12-12 04:51:18 +04:00
|
|
|
);
|
2013-04-12 00:56:48 +04:00
|
|
|
gemtk_wm_exec_redraw(dw->guiwin, NULL);
|
2011-12-28 03:30:39 +04:00
|
|
|
}
|
|
|
|
gui_window_set_status(input_window, messages_get("Done") );
|
2011-09-21 04:25:09 +04:00
|
|
|
}
|