application/window.c

changeset 13
5a8762fcfecc
parent 11
26acbfa75c1f
child 15
78684a24dc52
--- a/application/window.c	Tue Jan 30 11:58:11 2024 +0100
+++ b/application/window.c	Tue Jan 30 13:31:25 2024 +0100
@@ -32,6 +32,8 @@
 
 #include <ui/stock.h>
 
+#include <libidav/utils.h>
+
 static UiIcon* folder_icon;
 static UiIcon* file_icon;
 
@@ -44,6 +46,7 @@
 
 UiObject* window_create(void) {
 	UiObject* obj = ui_window("iDAV", NULL);
+	ui_window_size(obj, 900, 700);
 
 	MainWindow* wdata = ui_malloc(obj->ctx, sizeof(MainWindow));
 	memset(wdata, 0, sizeof(MainWindow));
@@ -62,9 +65,9 @@
 	}
 
 	// main content
-	UiModel* model = ui_model(obj->ctx, UI_ICON_TEXT, "Name", UI_STRING, "Type", UI_STRING, "Last Modified", UI_STRING, "Size", -1);
+	UiModel* model = ui_model(obj->ctx, UI_ICON_TEXT, "Name", UI_STRING, "Type", UI_STRING_FREE, "Last Modified", UI_STRING_FREE, "Size", -1);
 	model->getvalue = (ui_getvaluefunc)window_resource_table_getvalue;
-	ui_table(obj, .fill = UI_ON, .model = model, .varname = "reslist");
+	ui_table(obj, .fill = UI_ON, .model = model, .onactivate = action_list_activate, .varname = "reslist");
 
 	// status bar
 	ui_hbox(obj, .fill = UI_OFF) {
@@ -85,13 +88,13 @@
 			return res->name;
 		}
 		case 2: { // type
-			return ""; // TODO
+			return res->iscollection ? "Collection" : (res->contenttype ? res->contenttype : "Resource");
 		}
 		case 3: { // last modified
-			return ""; // TODO
+			return util_date_str(res->lastmodified);
 		}
 		case 4: { // size
-			return ""; // TODO
+			return util_size_str(res->iscollection, res->contentlength);
 		}
 	}
 	return NULL;
@@ -185,3 +188,19 @@
 	char *path = event->eventdata;
 	davbrowser_query_url(event->obj, browser, path);
 }
+
+void action_list_activate(UiEvent *event, void *data) {
+	UiListSelection *selection = event->eventdata;
+	DavBrowser *browser = event->document;
+
+	if (selection->count == 1) {
+		DavResource *res = ui_list_get(browser->resources, selection->rows[0]);
+		if (res) {
+			if (res->iscollection) {
+				davbrowser_query_path(event->obj, browser, res->path);
+			} else {
+				// TODO
+			}
+		}
+	}
+}

mercurial