1448 } else if(doc->type == DAV_RESOURCE_VIEW_IMAGE) { |
1447 } else if(doc->type == DAV_RESOURCE_VIEW_IMAGE) { |
1449 ui_image_load_file(doc->image, doc->tmp_file); |
1448 ui_image_load_file(doc->image, doc->tmp_file); |
1450 } |
1449 } |
1451 |
1450 |
1452 ui_set(doc->tabview, 1); |
1451 ui_set(doc->tabview, 1); |
|
1452 |
|
1453 doc->loaded = TRUE; |
1453 } |
1454 } |
1454 |
1455 |
1455 void dav_resourceviewer_load(UiObject *ui, DavResourceViewer *res) { |
1456 void dav_resourceviewer_load(UiObject *ui, DavResourceViewer *res) { |
1456 ui_set(res->loading, 1); |
1457 ui_set(res->loading, 1); |
1457 ui_set(res->message, "Loading..."); |
1458 ui_set(res->message, "Loading..."); |
1458 ui_set(res->tabview, 0); |
1459 ui_set(res->tabview, 0); |
1459 |
1460 |
1460 ui_job(ui, jobthr_resourceviewer_load, res, resourceviewer_load_finished, res); |
1461 ui_job(ui, jobthr_resourceviewer_load, res, resourceviewer_load_finished, res); |
1461 } |
1462 } |
1462 |
1463 |
|
1464 |
|
1465 typedef struct ResourceViewerUploadFile { |
|
1466 UiObject *ui; |
|
1467 DavSession *sn; |
|
1468 char *path; |
|
1469 cxmutstr text; |
|
1470 int error; |
|
1471 } ResourceViewerUploadFile; |
|
1472 |
|
1473 static int jobthr_upload_text(void *data) { |
|
1474 ResourceViewerUploadFile *upload = data; |
|
1475 |
|
1476 DavResource *res = dav_resource_new(upload->sn, upload->path); |
|
1477 dav_set_content_data(res, upload->text.ptr, upload->text.length); |
|
1478 upload->error = dav_store(res); |
|
1479 dav_resource_free(res); |
|
1480 |
|
1481 return 0; |
|
1482 } |
|
1483 |
|
1484 static void uithr_upload_text_finished(UiEvent *event, void *data) { |
|
1485 ResourceViewerUploadFile *upload = data; |
|
1486 |
|
1487 if(upload->error) { |
|
1488 cxmutstr errormsg = cx_asprintf("Upload failed: %d", upload->sn->error); // TODO: add full error message |
|
1489 ui_dialog(event->obj, .title = "Error", .content = errormsg.ptr, .closebutton_label = "OK"); |
|
1490 free(errormsg.ptr); |
|
1491 ui_set_group(event->obj->ctx, RESOURCEVIEWER_STATE_MODIFIED); |
|
1492 } |
|
1493 |
|
1494 dav_session_destroy(upload->sn); |
|
1495 free(upload->path); |
|
1496 free(upload->text.ptr); |
|
1497 free(upload); |
|
1498 } |
|
1499 |
|
1500 void dav_resourceviewer_save(UiObject *ui, DavResourceViewer *res) { |
|
1501 if(res->type == DAV_RESOURCE_VIEW_TEXT) { |
|
1502 DavSession *newsn = dav_session_clone(res->current->session); |
|
1503 ResourceViewerUploadFile *upload = malloc(sizeof(ResourceViewerUploadFile)); |
|
1504 upload->ui = ui; |
|
1505 upload->sn = newsn; |
|
1506 upload->path = strdup(res->current->path); |
|
1507 char *text = ui_get(res->text); |
|
1508 size_t textlen = strlen(text); |
|
1509 upload->text = cx_strdup(cx_strn(text, textlen)); |
|
1510 ui_job(ui, jobthr_upload_text, upload, uithr_upload_text_finished, upload); |
|
1511 ui_unset_group(ui->ctx, RESOURCEVIEWER_STATE_MODIFIED); |
|
1512 } |
|
1513 } |
|
1514 |
1463 void dav_resourceviewer_destroy(DavResourceViewer *res) { |
1515 void dav_resourceviewer_destroy(DavResourceViewer *res) { |
1464 |
1516 |
1465 } |
1517 } |