application/davcontroller.c

changeset 117
b174e721663e
parent 115
e57ca2747782
equal deleted inserted replaced
116:376ef91111f6 117:b174e721663e
46 UiContext *ctx = ui_document_context(doc); 46 UiContext *ctx = ui_document_context(doc);
47 CxMempool *mp = ui_cx_mempool(ctx); 47 CxMempool *mp = ui_cx_mempool(ctx);
48 doc->window = toplevel; 48 doc->window = toplevel;
49 doc->ctx = ctx; 49 doc->ctx = ctx;
50 50
51 doc->navigation_stack = cxLinkedListCreateSimple(CX_STORE_POINTERS); 51 doc->navigation_stack = cxLinkedListCreate(NULL, CX_STORE_POINTERS);
52 doc->navstack_enabled = true; 52 doc->navstack_enabled = true;
53 doc->navstack_pos = 0; 53 doc->navstack_pos = 0;
54 54
55 doc->dav_queue = ui_threadpool_create(1); 55 doc->dav_queue = ui_threadpool_create(1);
56 cxMempoolRegister(mp, doc->dav_queue, (cx_destructor_func)ui_threadpool_destroy); 56 cxMempoolRegister(mp, doc->dav_queue, (cx_destructor_func)ui_threadpool_destroy);
359 359
360 if(res->iscollection) { 360 if(res->iscollection) {
361 // default type 361 // default type
362 } else if(contenttype) { 362 } else if(contenttype) {
363 cxstring ctype = cx_str(contenttype); 363 cxstring ctype = cx_str(contenttype);
364 if(cx_strprefix(ctype, CX_STR("text/"))) { 364 if(cx_strprefix(ctype, "text/")) {
365 type = DAV_RESOURCE_VIEW_TEXT; 365 type = DAV_RESOURCE_VIEW_TEXT;
366 } else if(cx_strprefix(ctype, CX_STR("image/"))) { 366 } else if(cx_strprefix(ctype, "image/")) {
367 type = DAV_RESOURCE_VIEW_IMAGE; 367 type = DAV_RESOURCE_VIEW_IMAGE;
368 } else if(cx_strprefix(ctype, CX_STR("application/"))) { 368 } else if(cx_strprefix(ctype, "application/")) {
369 if(cx_strsuffix(ctype, CX_STR("json"))) { 369 if(cx_strsuffix(ctype, "json")) {
370 type = DAV_RESOURCE_VIEW_TEXT; 370 type = DAV_RESOURCE_VIEW_TEXT;
371 } else if(cx_strsuffix(ctype, CX_STR("/xml"))) { 371 } else if(cx_strsuffix(ctype, "/xml")) {
372 type = DAV_RESOURCE_VIEW_TEXT; 372 type = DAV_RESOURCE_VIEW_TEXT;
373 } else if(cx_strsuffix(ctype, CX_STR("+xml"))) { 373 } else if(cx_strsuffix(ctype, "+xml")) {
374 type = DAV_RESOURCE_VIEW_TEXT; 374 type = DAV_RESOURCE_VIEW_TEXT;
375 } else if(cx_strsuffix(ctype, CX_STR("/xml"))) { 375 } else if(cx_strsuffix(ctype, "/xml")) {
376 type = DAV_RESOURCE_VIEW_TEXT; 376 type = DAV_RESOURCE_VIEW_TEXT;
377 } 377 }
378 } 378 }
379 } else { 379 } else {
380 cxstring path = cx_str(res->path); 380 cxstring path = cx_str(res->path);
381 if(cx_strsuffix(path, CX_STR(".png"))) { 381 if(cx_strsuffix(path, ".png")) {
382 type = DAV_RESOURCE_VIEW_IMAGE; 382 type = DAV_RESOURCE_VIEW_IMAGE;
383 } else if(cx_strsuffix(path, CX_STR(".jpg"))) { 383 } else if(cx_strsuffix(path, ".jpg")) {
384 type = DAV_RESOURCE_VIEW_IMAGE; 384 type = DAV_RESOURCE_VIEW_IMAGE;
385 } else if(cx_strsuffix(path, CX_STR(".jpeg"))) { 385 } else if(cx_strsuffix(path, ".jpeg")) {
386 type = DAV_RESOURCE_VIEW_IMAGE; 386 type = DAV_RESOURCE_VIEW_IMAGE;
387 } else if(cx_strsuffix(path, CX_STR(".tif"))) { 387 } else if(cx_strsuffix(path, ".tif")) {
388 type = DAV_RESOURCE_VIEW_IMAGE; 388 type = DAV_RESOURCE_VIEW_IMAGE;
389 } else if(cx_strsuffix(path, CX_STR(".tiff"))) { 389 } else if(cx_strsuffix(path, ".tiff")) {
390 type = DAV_RESOURCE_VIEW_IMAGE; 390 type = DAV_RESOURCE_VIEW_IMAGE;
391 } else if(cx_strsuffix(path, CX_STR(".webp"))) { 391 } else if(cx_strsuffix(path, ".webp")) {
392 type = DAV_RESOURCE_VIEW_IMAGE; 392 type = DAV_RESOURCE_VIEW_IMAGE;
393 } else if(cx_strsuffix(path, CX_STR(".bmp"))) { 393 } else if(cx_strsuffix(path, ".bmp")) {
394 type = DAV_RESOURCE_VIEW_IMAGE; 394 type = DAV_RESOURCE_VIEW_IMAGE;
395 } else if(cx_strsuffix(path, CX_STR(".gif"))) { 395 } else if(cx_strsuffix(path, ".gif")) {
396 type = DAV_RESOURCE_VIEW_IMAGE; 396 type = DAV_RESOURCE_VIEW_IMAGE;
397 } else if(cx_strsuffix(path, CX_STR(".txt"))) { 397 } else if(cx_strsuffix(path, ".txt")) {
398 type = DAV_RESOURCE_VIEW_TEXT; 398 type = DAV_RESOURCE_VIEW_TEXT;
399 } else if(cx_strsuffix(path, CX_STR(".md"))) { 399 } else if(cx_strsuffix(path, ".md")) {
400 type = DAV_RESOURCE_VIEW_TEXT; 400 type = DAV_RESOURCE_VIEW_TEXT;
401 } else if(cx_strsuffix(path, CX_STR(".xml"))) { 401 } else if(cx_strsuffix(path, ".xml")) {
402 type = DAV_RESOURCE_VIEW_TEXT; 402 type = DAV_RESOURCE_VIEW_TEXT;
403 } 403 }
404 } 404 }
405 405
406 resourceviewer_new(browser, res->path, type); 406 resourceviewer_new(browser, res->path, type);
931 if(!doc->error) { 931 if(!doc->error) {
932 doc->current = res; 932 doc->current = res;
933 933
934 if(res->contentlength < DAV_RESOURCEVIEWER_PREVIEW_MAX_SIZE) { 934 if(res->contentlength < DAV_RESOURCEVIEWER_PREVIEW_MAX_SIZE) {
935 if(doc->type == DAV_RESOURCE_VIEW_TEXT) { 935 if(doc->type == DAV_RESOURCE_VIEW_TEXT) {
936 doc->text_content = cxBufferCreate(NULL, res->contentlength, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS); 936 doc->text_content = cxBufferCreate(cxDefaultAllocator, NULL, res->contentlength, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS);
937 int err = dav_get_content(res, doc->text_content, (dav_write_func)cxBufferWrite); 937 int err = dav_get_content(res, doc->text_content, (dav_write_func)cxBufferWrite);
938 cxBufferPut(doc->text_content, 0); 938 cxBufferPut(doc->text_content, 0);
939 if(err) { 939 if(err) {
940 doc->error = err; 940 doc->error = err;
941 doc->message_str = "Cannot load content"; // TODO: better message 941 doc->message_str = "Cannot load content"; // TODO: better message

mercurial