Skip to content

Commit

Permalink
on #377, #323 - many things
Browse files Browse the repository at this point in the history
* rename shoes_queue_download to shoes_native_download
* refactor to get rid of the goto. It was was more annoying
  than duplicating code. Separate code paths for cache, no-cache.
* weird tmp bug with osx for http no cache - more to do
* undo a lot of the last commit
* clear cache in bugs/bug377.rb requests a restart. Yes, you do want that.
* move extern shoes_cache_setting to app.h
  • Loading branch information
Cecil committed Oct 26, 2017
1 parent 996d23f commit b894619
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 156 deletions.
20 changes: 10 additions & 10 deletions bugs/bug377.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
Shoes.app do
require 'shoes/data'
require 'shoes/image'
app.cache = false
stack do
flow do
#@el = edit_line "#{DIR}/static/shoes-icon-walkabout.png"
@el = edit_line "https://shoes.mvmanila.com/public/images/dino.jpg"
@el = edit_line "#{DIR}/static/shoes-icon-walkabout.png"
#@el = edit_line "https://shoes.mvmanila.com/public/images/dino.jpg"
@cb = check; para "Cached?"
button "(Re)load" do
@img.clear
@img.append do
if @cb.checked?
image @el.text, cache: false
else
image @el.text
end
image @el.text, cache: @cb.checked
end
end
button "Show cache" do
@cview.clear
@cview.append do
eb = edit_box width: 400
DATABASE.open if DATABASE.closed?
DATABASE.each do |key, value|
eb.append "#{key} -> #{value}"
end
end
end
button "clear caches" do
DATABASE.open if DATABASE.closed?
DATABASE.each do |k, val|
v = val.split('|')
path = Shoes::image_cache_path v[1], File.extname(k)
Expand All @@ -37,12 +30,19 @@
end
DATABASE.clear
DATABASE.close
quit if confirm "Please restart Shoes"
end
para "Global cache: "
@sw = switch width: 80 do |n|
app.cache = n.active?
@cb.checked = n.active?
end
end
@img = flow {}
@cview = flow {}
end
start do
@sw.active = app.cache
@cb.checked = app.cache
end
end
2 changes: 1 addition & 1 deletion make/darwin/xmavericks/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
DLEXT = "dylib"
#LINUX_CFLAGS << " -DSHOES_QUARTZ -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -fpascal-strings #{RbConfig::CONFIG["CFLAGS"]} -x objective-c -fobjc-exceptions"
LINUX_CFLAGS << " -DVIDEO -DSHOES_QUARTZ -Wall -fpascal-strings -x objective-c -fobjc-exceptions"
LINUX_LDFLAGS = "-framework Cocoa -framework Carbon -dynamiclib -Wl,-single_module INSTALL_NAME"
LINUX_LDFLAGS = "-framework Cocoa -framework QuartzCore -framework Carbon -dynamiclib -Wl,-single_module INSTALL_NAME"
LINUX_LIB_NAMES << 'pixman-1' << 'jpeg.8'


Expand Down
7 changes: 3 additions & 4 deletions shoes/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,9 @@ VALUE shoes_app_get_decoration(VALUE app) {
return (shoes_native_app_get_decoration(app_t) ? Qtrue : Qfalse);
}

extern int shoes_cache_setting;
VALUE shoes_app_set_cache(VALUE app, VALUE bool) {
shoes_cache_setting = (bool == Qtrue) ? 1 : 0;
return bool;
VALUE shoes_app_set_cache(VALUE app, VALUE boolv) {
shoes_cache_setting = (boolv == Qtrue) ? 1 : 0;
return boolv;
}

VALUE shoes_app_get_cache(VALUE app) {
Expand Down
3 changes: 2 additions & 1 deletion shoes/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ VALUE shoes_app_get_resizable(VALUE);
VALUE shoes_app_set_resizable(VALUE, VALUE);
VALUE shoes_app_set_cache(VALUE app, VALUE decorated);
VALUE shoes_app_get_cache(VALUE app);

// global var for image cache - declared in types/image.c
extern int shoes_cache_setting;
// global var for console up and running
extern int shoes_global_terminal;
#ifdef SHOES_QUARTZ
Expand Down
5 changes: 3 additions & 2 deletions shoes/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ typedef struct {
} shoes_http_request;

void shoes_download(shoes_http_request *req);
void shoes_queue_download(shoes_http_request *req);
shoes_cached_image* shoes_no_cache_queue_download(shoes_http_request *req);
void shoes_native_download(shoes_http_request *req);
//void shoes_queue_download(shoes_http_request *req);
//shoes_cached_image* shoes_no_cache_queue_download(shoes_http_request *req);
VALUE shoes_http_err(SHOES_DOWNLOAD_ERROR error);
SHOES_DOWNLOAD_HEADERS shoes_http_headers(VALUE hsh);
void shoes_http_request_free(shoes_http_request *);
Expand Down
6 changes: 6 additions & 0 deletions shoes/http/nsurl.m
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ - (void)downloadDidFinish: (NSURLDownload *)download
shoes_download(req);
}

void
shoes_native_download(shoes_http_request *req)
{
shoes_download(req);
}

VALUE
shoes_http_err(SHOES_DOWNLOAD_ERROR code)
{
Expand Down
48 changes: 3 additions & 45 deletions shoes/http/rbload.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
#include "shoes/types/download.h"
#include "shoes/canvas.h"

extern int shoes_cache_setting;

void shoes_download(shoes_http_request *req) {
/* monkey patched out in download.rb - need function for linking */
printf("monkey patch failed\n");
}

void shoes_queue_download(shoes_http_request *req) {
//printf("shoes_queue_download called: %s -> %s\n",req->url,req->filepath);
void shoes_native_download(shoes_http_request *req) {
//printf("shoes_native_download called: %s -> %s\n",req->url,req->filepath);
VALUE path, url, opts, svsym, dnobj, stvar;
path = rb_str_new2(req->filepath);
url = rb_str_new2(req->url);
Expand Down Expand Up @@ -60,50 +58,10 @@ void shoes_queue_download(shoes_http_request *req) {
shoes_catch_message(SHOES_IMAGE_DOWNLOAD, Qnil, side);
shoes_http_request_free(req);
free(req);
// assume Ruby will garbage collect all the VALUE var's.
// TODO : assume Ruby will garbage collect all the VALUE var's.
// after this stack frame pops there's nothing holding them.
}

shoes_cached_image* shoes_no_cache_queue_download(shoes_http_request *req) {
VALUE path, url, opts, svsym, dnobj, stvar;
path = rb_str_new2(req->filepath);
url = rb_str_new2(req->url);
opts = rb_hash_new();
shoes_cached_image *cached;
// make a :save symbol
svsym = ID2SYM(rb_intern("save"));
// add :save and filepath to hash
rb_hash_aset(opts, svsym, path);
// Call Shoes::image_download_sync - defined in image.rb
dnobj = rb_funcall(cShoes,
rb_intern("image_download_sync"), 2, url, opts);
// convert the status var of dnobj to a C int and save it in req->idat
stvar = rb_funcall(dnobj, rb_intern("status"), 0);
int st = NUM2INT(stvar);
// dig the etag field out of headers.
VALUE hdrs = rb_funcall(dnobj, rb_intern("headers"), 0);
shoes_image_download_event *side = req->data;
side->status = st;
VALUE etag = Qnil;
VALUE keys = rb_funcall(hdrs, s_keys, 0);
int i;
for (i = 0; i < RARRAY_LEN(keys); i++ ) {
VALUE key = rb_ary_entry(keys, i);
if (strcmp("etag", RSTRING_PTR(key)) == 0) {
etag = key;
break;
}
}
if (! NIL_P(etag))
side->etag = RSTRING_PTR(rb_hash_aref(hdrs, etag));
// may draw the image into side->slot
cached = shoes_no_cache_download(side);
shoes_http_request_free(req);
free(req);
return cached;
}


VALUE shoes_http_err(SHOES_DOWNLOAD_ERROR code) {
/* a little unclear what this does or what it returns
I think it converts the platform 'code' to a Shoes string
Expand Down
Loading

0 comments on commit b894619

Please sign in to comment.