application/application.c

changeset 35
834d9c15a69f
parent 33
cdeb0dc47ef5
child 43
ef01d2c90128
--- a/application/application.c	Sun Jun 09 16:43:40 2024 +0200
+++ b/application/application.c	Sun Jun 09 17:00:22 2024 +0200
@@ -40,38 +40,38 @@
 static DavContext* davctx;
 
 void application_init(void) {
-	davctx = dav_context_new();
-	dav_context_set_mtsafe(davctx, true);
+    davctx = dav_context_new();
+    dav_context_set_mtsafe(davctx, true);
 
-	application_create_menu();
+    application_create_menu();
 }
 
 
 void application_startup(UiEvent* event, void* data) {
-	if (load_config(davctx)) {
-		// TODO: error
-		exit(-1);
-	}
+    if (load_config(davctx)) {
+        // TODO: error
+        exit(-1);
+    }
 
-	window_init();
+    window_init();
 
-	// create document for global settings (repolist, ...)
-	DavApp *app = application_create_app_document();
-	UiContext *global = ui_global_context();
-	ui_attach_document(global, app);
+    // create document for global settings (repolist, ...)
+    DavApp *app = application_create_app_document();
+    UiContext *global = ui_global_context();
+    ui_attach_document(global, app);
 
-	// create new window
-	UiObject *win = window_create();
-	// create new browser document and attach it to the main window
-	DavBrowser *doc = davbrowser_create(win);
-	ui_attach_document(win->ctx, doc);
+    // create new window
+    UiObject *win = window_create();
+    // create new browser document and attach it to the main window
+    DavBrowser *doc = davbrowser_create(win);
+    ui_attach_document(win->ctx, doc);
 
-	ui_show(win);
+    ui_show(win);
 }
 
 static void* davrepo_getname(void *elm, int unused) {
-	DavCfgRepository *repo = elm;
-	return repo->name.value.ptr;
+    DavCfgRepository *repo = elm;
+    return repo->name.value.ptr;
 }
 
 void application_create_menu(void) {
@@ -115,135 +115,135 @@
 
 
 DavApp* application_create_app_document(void) {
-	DavApp *doc = ui_document_new(sizeof(DavApp));
-	UiContext *ctx = ui_document_context(doc);
-	doc->repos = ui_list_new(ctx, "repolist");
+    DavApp *doc = ui_document_new(sizeof(DavApp));
+    UiContext *ctx = ui_document_context(doc);
+    doc->repos = ui_list_new(ctx, "repolist");
 
-	// create repo list
-	application_update_repolist(doc);
+    // create repo list
+    application_update_repolist(doc);
 
-	return doc;
+    return doc;
 }
 
 void application_update_repolist(DavApp *app) {
-	DavConfig *config = get_config();
-	DavCfgRepository *repo = config->repositories;
+    DavConfig *config = get_config();
+    DavCfgRepository *repo = config->repositories;
 
-	ui_list_clear(app->repos);
+    ui_list_clear(app->repos);
 
-	for (DavCfgRepository *repo = config->repositories; repo; repo = repo->next) {
-		ui_list_append(app->repos, repo);
-	}
+    for (DavCfgRepository *repo = config->repositories; repo; repo = repo->next) {
+        ui_list_append(app->repos, repo);
+    }
 }
 
 
 DavContext* application_dav_context(void) {
-	return davctx;
+    return davctx;
 }
 
 
 void action_window_new(UiEvent *event, void *data) {
-	UiObject *win = window_create();
-	// create new browser document and attach it to the main window
-	DavBrowser *doc = davbrowser_create(win);
-	ui_attach_document(win->ctx, doc);
+    UiObject *win = window_create();
+    // create new browser document and attach it to the main window
+    DavBrowser *doc = davbrowser_create(win);
+    ui_attach_document(win->ctx, doc);
 
-	ui_show(win);
+    ui_show(win);
 }
 
 void action_refresh(UiEvent *event, void *data) {
-	DavBrowser *browser = event->document;
-	if (browser->current) {
-		davbrowser_query_path(event->obj, browser, browser->current->path);
-	}
+    DavBrowser *browser = event->document;
+    if (browser->current) {
+        davbrowser_query_path(event->obj, browser, browser->current->path);
+    }
 }
 
 void action_repo_selected(UiEvent *event, void *data) {
-	DavCfgRepository *repo = event->eventdata;
-	DavBrowser *browser = event->document;
-	davbrowser_connect2repo(event->obj, browser, repo, "");
+    DavCfgRepository *repo = event->eventdata;
+    DavBrowser *browser = event->document;
+    davbrowser_connect2repo(event->obj, browser, repo, "");
 }
 
 static void file_selected(UiEvent *event, void *data) {
-	UiFileList *files = event->eventdata;
-	if (files && files->nfiles > 0) {
-		// files will be freed by the filedialog handler, therefore we need a copy
-		UiFileList uploadList = ui_filelist_copy(*files); // uploadList will be freed by davbrowser_upload_files
-		davbrowser_upload_files(event->obj, event->document, uploadList);
-	}
-	
+    UiFileList *files = event->eventdata;
+    if (files && files->nfiles > 0) {
+        // files will be freed by the filedialog handler, therefore we need a copy
+        UiFileList uploadList = ui_filelist_copy(*files); // uploadList will be freed by davbrowser_upload_files
+        davbrowser_upload_files(event->obj, event->document, uploadList);
+    }
+    
 }
 
 
 
 static void download_location_selected(UiEvent *event, void *data) {
-	DavBrowser *browser = event->document;
-	DavResource *reslist = data;
-	UiFileList *flist = event->eventdata;
+    DavBrowser *browser = event->document;
+    DavResource *reslist = data;
+    UiFileList *flist = event->eventdata;
 
-	if (flist && flist->nfiles > 0) {
-		davbrowser_download(event->obj, browser, reslist, flist->files[0]);
-	} else {
-		dav_session_destroy(reslist->session);
-	}
+    if (flist && flist->nfiles > 0) {
+        davbrowser_download(event->obj, browser, reslist, flist->files[0]);
+    } else {
+        dav_session_destroy(reslist->session);
+    }
 }
 
 void action_download(UiEvent *event, void *data) {
-	DavBrowser *browser = event->document;
-	UiListSelection sel = ui_list_getselection(browser->resources);
-	if (sel.count > 0) {;
-		const char *initialFileName = NULL;
-		if (sel.count == 1) {
-			DavResource *res = ui_list_get(browser->resources, sel.rows[0]);
-			if (res && !res->iscollection) {
-				initialFileName = res->name;
-			}
-		}
+    DavBrowser *browser = event->document;
+    UiListSelection sel = ui_list_getselection(browser->resources);
+    if (sel.count > 0) {;
+        const char *initialFileName = NULL;
+        if (sel.count == 1) {
+            DavResource *res = ui_list_get(browser->resources, sel.rows[0]);
+            if (res && !res->iscollection) {
+                initialFileName = res->name;
+            }
+        }
 
-		// create a copy of the current session and all selected resources
-		DavSession *sn = dav_session_clone(browser->sn);
-		DavResource *first = NULL;
-		DavResource *last = NULL;
-		for (int i = 0; i < sel.count; i++) {
-			// get selected resource
-			DavResource *res = ui_list_get(browser->resources, sel.rows[i]);
-			// copy resource
-			DavResource *res_copy = dav_resource_new(sn, res->path);
-			res_copy->iscollection = res->iscollection;
-			res_copy->contentlength = res->contentlength;
-			res_copy->lastmodified = res->lastmodified;
-			res_copy->creationdate = res->creationdate;
+        // create a copy of the current session and all selected resources
+        DavSession *sn = dav_session_clone(browser->sn);
+        DavResource *first = NULL;
+        DavResource *last = NULL;
+        for (int i = 0; i < sel.count; i++) {
+            // get selected resource
+            DavResource *res = ui_list_get(browser->resources, sel.rows[i]);
+            // copy resource
+            DavResource *res_copy = dav_resource_new(sn, res->path);
+            res_copy->iscollection = res->iscollection;
+            res_copy->contentlength = res->contentlength;
+            res_copy->lastmodified = res->lastmodified;
+            res_copy->creationdate = res->creationdate;
 
-			// link resources
-			if (!first) {
-				first = res_copy;
-			}
-			if (last) {
-				res_copy->prev = last;
-				last->next = res_copy;
-			}
-			last = res_copy;
-		}
+            // link resources
+            if (!first) {
+                first = res_copy;
+            }
+            if (last) {
+                res_copy->prev = last;
+                last->next = res_copy;
+            }
+            last = res_copy;
+        }
 
-		if (initialFileName) {
-			ui_savefiledialog(event->obj, initialFileName, download_location_selected, first);
-		} else {
-			ui_openfiledialog(event->obj, UI_FILEDIALOG_SELECT_FOLDER, download_location_selected, first);
-		}
-	}
+        if (initialFileName) {
+            ui_savefiledialog(event->obj, initialFileName, download_location_selected, first);
+        } else {
+            ui_openfiledialog(event->obj, UI_FILEDIALOG_SELECT_FOLDER, download_location_selected, first);
+        }
+    }
 }
 
 void action_upload_file(UiEvent *event, void *data) {
-	ui_openfiledialog(event->obj, UI_FILEDIALOG_SELECT_MULTI, file_selected, NULL);
+    ui_openfiledialog(event->obj, UI_FILEDIALOG_SELECT_MULTI, file_selected, NULL);
 }
 
 void action_delete(UiEvent *event, void *data) {
-	DavBrowser *browser = event->document;
-	UiListSelection sel = ui_list_getselection(browser->resources);
-	if (sel.count > 0) {
-		davbrowser_delete(event->obj, browser, sel);
-	}
-	ui_listselection_free(sel);
+    DavBrowser *browser = event->document;
+    UiListSelection sel = ui_list_getselection(browser->resources);
+    if (sel.count > 0) {
+        davbrowser_delete(event->obj, browser, sel);
+    }
+    ui_listselection_free(sel);
 }
 
 void action_newfile(UiEvent *event, void *data) {
@@ -252,13 +252,13 @@
 
 
 static void newfolderdialog_result(UiEvent *event, void *data) {
-	DavBrowser *browser = event->document;
-	char *path = event->eventdata;
-	if (event->intval == 1) {
-		davbrowser_mkcol(event->obj, browser, path);
-	}
+    DavBrowser *browser = event->document;
+    char *path = event->eventdata;
+    if (event->intval == 1) {
+        davbrowser_mkcol(event->obj, browser, path);
+    }
 }
 
 void action_mkcol(UiEvent *event, void *data) {
-	ui_dialog(event->obj, .content = "New Folder", .input =  TRUE, .button1_label = "Create Folder", .button2_label = "Close", .result = newfolderdialog_result);
+    ui_dialog(event->obj, .content = "New Folder", .input =  TRUE, .button1_label = "Create Folder", .button2_label = "Close", .result = newfolderdialog_result);
 }

mercurial