update toolkit / set window size

Tue, 30 Jan 2024 13:31:25 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 30 Jan 2024 13:31:25 +0100
changeset 13
5a8762fcfecc
parent 12
3eb0cbab53db
child 14
872d570ae843

update toolkit / set window size

application/davcontroller.c file | annotate | diff | comparison | revisions
application/window.c file | annotate | diff | comparison | revisions
application/window.h file | annotate | diff | comparison | revisions
ui/common/types.c file | annotate | diff | comparison | revisions
ui/ui/toolkit.h file | annotate | diff | comparison | revisions
ui/ui/tree.h file | annotate | diff | comparison | revisions
ui/ui/window.h file | annotate | diff | comparison | revisions
ui/winui/pch.h file | annotate | diff | comparison | revisions
ui/winui/table.cpp file | annotate | diff | comparison | revisions
ui/winui/text.cpp file | annotate | diff | comparison | revisions
ui/winui/window.cpp file | annotate | diff | comparison | revisions
--- a/application/davcontroller.c	Tue Jan 30 11:58:11 2024 +0100
+++ b/application/davcontroller.c	Tue Jan 30 13:31:25 2024 +0100
@@ -48,8 +48,12 @@
 
 
 void davbrowser_set_collection(UiObject *ui, DavBrowser *browser, DavResource *collection) {
+    if (browser->current) {
+        dav_resource_free_all(browser->current);
+    }
     ui_list_clear(browser->resources);
 
+    browser->current = collection;
     for (DavResource *res = collection->children; res; res = res->next) {
         ui_list_append(browser->resources, res);
     }
@@ -88,7 +92,7 @@
     DavBrowserQueryPath *query = data;
     DavSession *sn = query->browser->sn;
 
-    DavResource *res = dav_query(sn, "select `idav:crypto-name`,`idav:crypto-key`,D:lockdiscovery from %s with depth = 1 order by iscollection desc, name", query->path);
+    DavResource *res = dav_query(sn, "select `idav:crypto-name`,`idav:crypto-key`,D:lockdiscovery,D:getcontenttype from %s with depth = 1 order by iscollection desc, name", query->path);
     query->result = res;
 
     return 0;
--- 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
+			}
+		}
+	}
+}
--- a/application/window.h	Tue Jan 30 11:58:11 2024 +0100
+++ b/application/window.h	Tue Jan 30 13:31:25 2024 +0100
@@ -56,6 +56,8 @@
 
 void action_path_selected(UiEvent *event, void *data);
 
+void action_list_activate(UiEvent *event, void *data);
+
 #ifdef	__cplusplus
 }
 #endif
--- a/ui/common/types.c	Tue Jan 30 11:58:11 2024 +0100
+++ b/ui/common/types.c	Tue Jan 30 13:31:25 2024 +0100
@@ -456,3 +456,13 @@
     l->update = NULL;
     l->obj = NULL;
 }
+
+
+
+UiStr ui_str(char *cstr) {
+    return (UiStr) { cstr, NULL };
+}
+
+UiStr ui_str_free(char *str, void (*freefunc)(void *v)) {
+    return (UiStr) { str, freefunc };
+}
--- a/ui/ui/toolkit.h	Tue Jan 30 11:58:11 2024 +0100
+++ b/ui/ui/toolkit.h	Tue Jan 30 13:31:25 2024 +0100
@@ -474,6 +474,10 @@
 UIEXPORT UiIcon* ui_foldericon(size_t size);
 UIEXPORT UiIcon* ui_fileicon(size_t size);
 
+
+UiStr ui_str(char *cstr);
+UiStr ui_str_free(char *str, void (*free)(void *v));
+
 #ifdef	__cplusplus
 }
 #endif
--- a/ui/ui/tree.h	Tue Jan 30 11:58:11 2024 +0100
+++ b/ui/ui/tree.h	Tue Jan 30 13:31:25 2024 +0100
@@ -44,9 +44,11 @@
 
 typedef enum UiModelType {
     UI_STRING = 0,
+    UI_STRING_FREE,
     UI_INTEGER,
     UI_ICON,
     UI_ICON_TEXT,
+    UI_ICON_TEXT_FREE
 } UiModelType;
 
 struct UiModel {
@@ -154,6 +156,7 @@
 void ui_table_dragdest(UIWIDGET tablewidget, int actions, char *target0, ...);
 void ui_table_dragdest_a(UIWIDGET tablewidget, int actions, char **targets, int nelm);
 
+
 #ifdef	__cplusplus
 }
 #endif
--- a/ui/ui/window.h	Tue Jan 30 11:58:11 2024 +0100
+++ b/ui/ui/window.h	Tue Jan 30 13:31:25 2024 +0100
@@ -38,6 +38,8 @@
 UIEXPORT UiObject* ui_window(const char *title, void *window_data);
 UIEXPORT UiObject* ui_simplewindow(char *title, void *window_data);
 
+UIEXPORT void ui_window_size(UiObject *obj, int width, int height);
+
 char* ui_openfiledialog(UiObject *obj);
 char* ui_savefiledialog(UiObject *obj);
 
--- a/ui/winui/pch.h	Tue Jan 30 11:58:11 2024 +0100
+++ b/ui/winui/pch.h	Tue Jan 30 13:31:25 2024 +0100
@@ -15,6 +15,7 @@
 #include <winrt/Windows.Foundation.Collections.h>
 #include <winrt/Windows.ApplicationModel.Activation.h>
 #include <winrt/Microsoft.UI.Composition.h>
+#include <winrt/Microsoft.UI.Windowing.h>
 #include <winrt/Microsoft.UI.Xaml.h>
 #include <winrt/Microsoft.UI.Xaml.Controls.h>
 #include <winrt/Microsoft.UI.Xaml.Controls.Primitives.h>
@@ -35,5 +36,4 @@
 #include <winrt/Windows.ApplicationModel.h>
 #include <winrt\Microsoft.UI.Dispatching.h>
 
-
 #include <winrt/Windows.Storage.Streams.h>
--- a/ui/winui/table.cpp	Tue Jan 30 11:58:11 2024 +0100
+++ b/ui/winui/table.cpp	Tue Jan 30 13:31:25 2024 +0100
@@ -410,12 +410,17 @@
 			// depending on the type, we create different cell controls
 			UiModelType type = model->types[col];
 			switch (type) {
+				case UI_STRING_FREE:
 				case UI_STRING: {
 					TextBlock cell = TextBlock();
 					cell.Padding(cellpadding);
 					cell.VerticalAlignment(VerticalAlignment::Stretch);
-					textblock_set_str(cell, (char*)getvalue(elm, model_col));
+					char *val = (char*)getvalue(elm, model_col);
+					textblock_set_str(cell, val);
 					cellBorder.Child(cell);
+					if (type == UI_STRING_FREE && val) {
+						free(val);
+					}
 
 					break;
 				}
@@ -438,6 +443,7 @@
 					}
 					break;
 				}
+				case UI_ICON_TEXT_FREE:
 				case UI_ICON_TEXT: {
 					StackPanel cellPanel = StackPanel();
 					cellPanel.Spacing(2);
@@ -455,6 +461,9 @@
 					textblock_set_str(cell, str);
 					cellPanel.Children().Append(cell);
 					cellBorder.Child(cellPanel);
+					if (type == UI_ICON_TEXT_FREE && str) {
+						free(str);
+					}
 					break;
 				}
 			}
--- a/ui/winui/text.cpp	Tue Jan 30 11:58:11 2024 +0100
+++ b/ui/winui/text.cpp	Tue Jan 30 13:31:25 2024 +0100
@@ -242,23 +242,27 @@
     return elms;
 }
 
-void ui_pathtextfield_update(UiPathTextField* pb, const char *full_path) {
+int ui_pathtextfield_update(UiPathTextField* pb, const char *full_path) {
     Grid grid = pb->grid;
 
     ui_pathelm_func getpathelm = pb->getpathelm;
     void* getpathelmdata = pb->getpathelmdata;
 
+    size_t full_path_len = full_path ? strlen(full_path) : 0;
+
+    size_t nelm = 0;
+    UiPathElm* path_elm = getpathelm(full_path, full_path_len, &nelm, getpathelmdata);
+    if (!path_elm) {
+        return 1;
+    }
+
     // hide textbox, show button panel
     pb->textbox.Visibility(Visibility::Collapsed);
     pb->buttons.Visibility(Visibility::Visible);
 
     // clear old buttons
-    ui_pathtextfield_clear(pb->buttons);
+    ui_pathtextfield_clear(pb->buttons); 
 
-    size_t full_path_len = full_path ? strlen(full_path) : 0;
-    
-    size_t nelm = 0;
-    UiPathElm* path_elm = getpathelm(full_path, full_path_len, &nelm, getpathelmdata);
     ui_pathfield_free_pathelms(pb->current_path, pb->current_path_nelms);
     pb->current_path = path_elm;
     pb->current_path_nelms = nelm;
@@ -298,6 +302,8 @@
 
         j++;
     }
+
+    return 0;
 }
 
 char* ui_path_textfield_get(UiString * str) {
@@ -436,7 +442,17 @@
                     if (update) {
                         std::wstring value(pathTextBox.Text());
                         char* full_path = wchar2utf8(value.c_str(), value.length());
-                        ui_pathtextfield_update(uipathbar, full_path);
+
+                        if (!ui_pathtextfield_update(uipathbar, full_path)) {
+                            UiEvent evt;
+                            evt.obj = obj;
+                            evt.window = obj->window;
+                            evt.document = obj->ctx->document;
+                            evt.eventdata = full_path;
+                            evt.intval = -1;
+                            args.onactivate(&evt, args.onactivatedata);
+                        } 
+
                         free(full_path);
                     }
 
--- a/ui/winui/window.cpp	Tue Jan 30 11:58:11 2024 +0100
+++ b/ui/winui/window.cpp	Tue Jan 30 13:31:25 2024 +0100
@@ -175,3 +175,13 @@
 
 	return obj;
 }
+
+void ui_window_size(UiObject *obj, int width, int height) {
+	UIWINDOW win = obj->wobj;
+	if (win) {
+		winrt::Windows::Graphics::SizeInt32 wsize;
+		wsize.Width = width;
+		wsize.Height = height;
+		win->window.AppWindow().Resize(wsize);
+	}
+}

mercurial