application/window.c

Mon, 11 Nov 2024 20:45:34 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 11 Nov 2024 20:45:34 +0100
changeset 77
5de33c2d94c6
parent 68
79a9aadf1c70
child 78
ad7ced6cf00b
permissions
-rw-r--r--

fix text/image preview loading

2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2024 Olaf Wintermann. All rights reserved.
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "window.h"
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
31 #include "davcontroller.h"
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
32
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <ui/stock.h>
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
34 #include <ui/dnd.h>
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
13
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
36 #include <libidav/utils.h>
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
37
56
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
38 #include <cx/printf.h>
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
39
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
40 static UiIcon* folder_icon;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
41 static UiIcon* file_icon;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
42
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
43 static UiPathElm* dav_get_pathelm(const char *full_path, size_t len, size_t *ret_nelm, void* data);
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
44
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
45 void window_init(void) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
46 folder_icon = ui_foldericon(16);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
47 file_icon = ui_fileicon(16);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
48 }
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 UiObject* window_create(void) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
51 UiObject* obj = ui_window("iDAV", NULL);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
52 ui_window_size(obj, 900, 700);
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
54 MainWindow* wdata = ui_malloc(obj->ctx, sizeof (MainWindow));
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
55 memset(wdata, 0, sizeof (MainWindow));
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
56 obj->window = wdata;
7
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
57
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
58 wdata->progress = ui_int_new(obj->ctx, "progress");
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
59
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
60 // navigation bar
7
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
61
45
ab71409644b0 update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
62 ui_hbox(obj, .fill = UI_OFF, .margin = 8, .spacing = 8) {
ab71409644b0 update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
63 ui_hbox(obj, .fill = UI_OFF, .style_class="linked") {
ab71409644b0 update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
64 ui_button(obj, .icon = UI_ICON_GO_BACK, .onclick = action_go_back);
ab71409644b0 update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
65 ui_button(obj, .icon = UI_ICON_GO_FORWARD, .onclick = action_go_forward);
ab71409644b0 update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
66 }
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
68 ui_path_textfield(obj, .fill = UI_ON, .getpathelm = dav_get_pathelm, .onactivate = action_path_selected, .varname = "path");
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
69
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
70 ui_progressspinner(obj, .value = wdata->progress);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
71 }
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
73 // main content
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
74 UiModel* model = ui_model(obj->ctx, UI_ICON_TEXT, "Name", UI_STRING, "Type", UI_STRING_FREE, "Last Modified", UI_STRING_FREE, "Size", -1);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
75 model->getvalue = (ui_getvaluefunc) window_resource_table_getvalue;
68
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
76 ui_table(obj, .fill = UI_ON, .model = model, .onselection = action_list_selection, .onactivate = action_list_activate, .ondrop = action_dnd_drop, .varname = "reslist", .multiselection = TRUE);
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
78 // status bar
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
80 ui_hbox(obj, .fill = UI_OFF) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
81 ui_label(obj, .label = "");
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
82 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
83
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
84 return obj;
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 }
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
86
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
87 void* window_resource_table_getvalue(DavResource *res, int col) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
88 switch (col) {
38
acd8c4a9d3fe fix path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
89 case 0: { // icon
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
90 return res->iscollection ? folder_icon : file_icon;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
91 }
38
acd8c4a9d3fe fix path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
92 case 1: { // resource name
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
93 return res->name;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
94 }
38
acd8c4a9d3fe fix path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
95 case 2: { // type
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
96 return res->iscollection ? "Collection" : (res->contenttype ? res->contenttype : "Resource");
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
97 }
38
acd8c4a9d3fe fix path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
98 case 3: { // last modified
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
99 return util_date_str(res->lastmodified);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
100 }
38
acd8c4a9d3fe fix path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
101 case 4: { // size
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
102 return util_size_str(res->iscollection, res->contentlength);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
103 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
104 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
105 return NULL;
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
106 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
107
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
108 void window_progress(MainWindow *win, int on) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
109 ui_set(win->progress, on);
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
110 }
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
111
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
112
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
113
54
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
114 static void resourceviewer_close(UiEvent *event, void *data) {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
115 DavResourceViewer *doc = data;
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
116 doc->window_closed = TRUE;
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
117 if(doc->loaded) {
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
118 dav_resourceviewer_destroy(doc);
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
119 }
77
5de33c2d94c6 fix text/image preview loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
120
5de33c2d94c6 fix text/image preview loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
121 if (doc->tmp_file) {
5de33c2d94c6 fix text/image preview loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
122 unlink(doc->tmp_file);
5de33c2d94c6 fix text/image preview loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
123 free(doc->tmp_file);
5de33c2d94c6 fix text/image preview loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
124 }
54
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
125 }
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
126
52
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
127 void resourceviewer_new(DavBrowser *browser, const char *path, DavResourceViewType type) {
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
128 const char *name = util_resource_name(path);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
129 UiObject *win = ui_simple_window(name, NULL);
77
5de33c2d94c6 fix text/image preview loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
130 ui_window_size(win, 600, 600);
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
131
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
132 DavResourceViewer *doc = dav_resourceviewer_create(browser->sn, path, type);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
133 ui_attach_document(win->ctx, doc);
54
3ca3acefc66a add resourceviewer cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
134 ui_context_closefunc(win->ctx, resourceviewer_close, doc);
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
135
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
136 ui_tabview(win, .tabview = UI_TABVIEW_INVISIBLE, .varname = "tabview") {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
137 /* loading / message tab */
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
138 ui_tab(win, NULL) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
139 ui_hbox(win, .margin = 16, .spacing = 10, .fill = UI_OFF) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
140 ui_progressspinner(win, .varname = "loading");
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
141 ui_label(win, .varname = "message");
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
142 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
143 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
144
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
145 /* preview tab */
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
146 ui_tab(win, NULL) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
147 ui_tabview0(win) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
148 if(type == DAV_RESOURCE_VIEW_TEXT) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
149 ui_tab(win, "Content") {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
150 ui_textarea(win, .varname = "text");
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
151 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
152 } else if(type == DAV_RESOURCE_VIEW_IMAGE) {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
153 ui_tab(win, "Preview") {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
154 ui_imageviewer(win, .varname = "image");
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
155 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
156 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
157
52
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
158 ui_tab(win, "Info") {
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
159 ui_grid(win, .margin = 16, .columnspacing = 30, .rowspacing = 6) {
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
160 ui_llabel(win, .label = "URL");
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
161 ui_llabel(win, .varname = "info_url");
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
162 ui_newline(win);
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
163
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
164 ui_llabel(win, .label = "Name");
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
165 ui_llabel(win, .varname = "info_name");
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
166 ui_newline(win);
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
167
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
168 ui_llabel(win, .label = "Type");
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
169 ui_llabel(win, .varname = "info_type");
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
170 ui_newline(win);
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
171
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
172 ui_llabel(win, .label = "Encrypted");
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
173 ui_llabel(win, .varname = "info_encrypted");
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
174 ui_newline(win);
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
175
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
176 ui_llabel(win, .label = "ETag");
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
177 ui_llabel(win, .varname = "info_etag");
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
178 ui_newline(win);
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
179
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
180 ui_llabel(win, .label = "Size");
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
181 ui_llabel(win, .varname = "info_size");
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
182 ui_newline(win);
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
183 }
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
184 }
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
185
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
186 ui_tab(win, "Properties") {
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
187 UiModel* model = ui_model(win->ctx, UI_STRING, "Namespace", UI_STRING, "Name", UI_STRING, "Value", -1);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
188 model->getvalue = (ui_getvaluefunc) resourceviewer_proplist_getvalue;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
189 ui_table(win, .fill = UI_ON, .model = model, .varname = "properties");
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
190 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
191 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
192 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
193 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
194
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
195 dav_resourceviewer_load(win, doc);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
196
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
197 ui_show(win);
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
198 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
199
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
200 void* resourceviewer_proplist_getvalue(DavPropertyList *property, int col) {
52
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
201 switch(col) {
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
202 case 0: {
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
203 return property->ns;
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
204 }
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
205 case 1: {
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
206 return property->name;
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
207 }
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
208 case 2: {
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
209 return property->value_simplified ? property->value_simplified : property->value_full;
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
210 }
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
211 }
0c881944fa10 add resourceviewer info and properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
212
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
213 return NULL;
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
214 }
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
215
56
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
216
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
217 typedef struct AuthDialogWindow {
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
218 UiString *user;
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
219 UiString *password;
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
220 } AuthDialogWindow;
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
221
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
222 static void auth_dialog_action(UiEvent *event, void *data) {
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
223 SessionAuthData *auth = data;
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
224 AuthDialogWindow *wdata = event->window;
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
225 int result = 0;
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
226 if(event->intval == 4) {
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
227 char *user = ui_get(wdata->user);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
228 char *password = ui_get(wdata->password);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
229 davbrowser_auth_set_user_pwd(auth, user, password);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
230 result = 1;
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
231 }
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
232 ui_condvar_signal(auth->cond, NULL, result);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
233 ui_close(event->obj);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
234 }
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
235
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
236 void auth_dialog(SessionAuthData *auth) {
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
237 UiObject *obj = ui_dialog_window(auth->obj,
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
238 .title = "Authentication",
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
239 .lbutton1 = "Cancel",
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
240 .rbutton4 = "Connect",
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
241 .default_button = 4,
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
242 .show_closebutton = UI_OFF,
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
243 .onclick = auth_dialog_action,
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
244 .onclickdata = auth);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
245
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
246 AuthDialogWindow *wdata = ui_malloc(obj->ctx, sizeof(AuthDialogWindow));
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
247 wdata->user = ui_string_new(obj->ctx, NULL);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
248 wdata->password = ui_string_new(obj->ctx, NULL);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
249 obj->window = wdata;
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
250
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
251 ui_grid(obj, .margin = 20, .columnspacing = 12, .rowspacing = 12) {
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
252 cxmutstr heading = cx_asprintf("Authentication required for: %s", auth->sn->base_url);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
253 ui_llabel(obj, .label = heading.ptr, .colspan = 2);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
254 free(heading.ptr);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
255 ui_newline(obj);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
256
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
257 ui_llabel(obj, .label = "User");
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
258 ui_textfield(obj, .value = wdata->user, .hexpand = TRUE);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
259 ui_newline(obj);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
260
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
261 ui_llabel(obj, .label = "Password");
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
262 ui_passwordfield(obj, .value = wdata->password, .hexpand = TRUE);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
263 }
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
264
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
265 if(auth->user) {
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
266 ui_set(wdata->user, auth->user);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
267 }
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
268
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
269 ui_show(obj);
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
270 }
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
271
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
272
294d5515583a add authentication dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
273
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
274 static UiPathElm* dav_get_pathelm(const char *full_path, size_t len, size_t *ret_nelm, void* data) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
275 cxstring fpath = cx_strn(full_path, len);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
276 int protocol = 0;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
277 if (cx_strcaseprefix(fpath, CX_STR("http://"))) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
278 protocol = 7;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
279 } else if (cx_strcaseprefix(fpath, CX_STR("https://"))) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
280 protocol = 8;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
281 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
282
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
283 size_t start = 0;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
284 size_t end = 0;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
285 for (size_t i = protocol; i < len; i++) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
286 if (full_path[i] == '/') {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
287 end = i;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
288 break;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
289 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
290 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
291
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
292 int skip = 0;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
293 if (end == 0) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
294 // no '/' found or first char is '/'
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
295 end = len > 0 && full_path[0] == '/' ? 1 : len;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
296 } else if (end + 1 <= len) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
297 skip++; // skip first '/'
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
298 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
299
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
300
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
301 cxmutstr base = cx_strdup(cx_strn(full_path, end));
57
d5a7dbc945ef store elm path with trailing path separator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
302 cxmutstr base_path = cx_strcat(2, cx_strcast(base), CX_STR("/"));
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
303 cxstring path = cx_strsubs(fpath, end + skip);
59
6bd37fe6d905 allow regular resource url input in the path bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
304
6bd37fe6d905 allow regular resource url input in the path bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
305 cxstring trail = cx_str(len > 0 && full_path[len-1] == '/' ? "/" : "");
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
306
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
307 cxstring *pathelms;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
308 size_t nelm = 0;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
309
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
310 if (path.length > 0) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
311 nelm = cx_strsplit_a(cxDefaultAllocator, path, CX_STR("/"), 4096, &pathelms);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
312 if (nelm == 0) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
313 *ret_nelm = 0;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
314 return NULL;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
315 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
316 }
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
317
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
318 UiPathElm* elms = (UiPathElm*) calloc(nelm + 1, sizeof (UiPathElm));
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
319 size_t n = nelm + 1;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
320 elms[0].name = base.ptr;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
321 elms[0].name_len = base.length;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
322 elms[0].path = base_path.ptr;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
323 elms[0].path_len = base_path.length;
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
324
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
325 int j = 1;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
326 for (int i = 0; i < nelm; i++) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
327 cxstring c = pathelms[i];
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
328 if (c.length == 0) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
329 if (i == 0) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
330 c.length = 1;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
331 } else {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
332 n--;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
333 continue;
34
98e041f2f9a2 fix dav path separator function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
334 }
98e041f2f9a2 fix dav path separator function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
335 }
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
336
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
337 cxmutstr m = cx_strdup(c);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
338 elms[j].name = m.ptr;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
339 elms[j].name_len = m.length;
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
340
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
341 size_t elm_path_len = c.ptr + c.length - full_path;
59
6bd37fe6d905 allow regular resource url input in the path bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
342 cxmutstr elm_path = cx_strcat(2, cx_strn(full_path, elm_path_len), i+1 < nelm ? CX_STR("/") : trail);
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
343 elms[j].path = elm_path.ptr;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
344 elms[j].path_len = elm_path.length;
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
345
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
346 j++;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
347 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
348 *ret_nelm = n;
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
349
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
350 return elms;
9
0676408f50ad add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
351 }
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
352
68
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
353 void action_go_parent(UiEvent *event, void *data) {
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
354 DavBrowser *browser = event->document;
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
355 davbrowser_navigation_parent(event->obj, browser);
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
356 }
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
357
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
358 void action_go_back(UiEvent *event, void *data) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
359 DavBrowser *browser = event->document;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
360 davbrowser_navigation_back(event->obj, browser);
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
361 }
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
362
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
363 void action_go_forward(UiEvent *event, void *data) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
364 DavBrowser *browser = event->document;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
365 davbrowser_navigation_forward(event->obj, browser);
15
78684a24dc52 implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
366 }
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
367
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
368 void action_path_selected(UiEvent *event, void *data) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
369 DavBrowser *browser = event->document;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
370 char *path = event->eventdata;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
371 if (path && strlen(path) > 0) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
372 davbrowser_query_url(event->obj, browser, path);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
373 }
11
26acbfa75c1f add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
374 }
13
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
375
68
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
376 void action_list_selection(UiEvent *event, void *data) {
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
377 UiListSelection *selection = event->eventdata;
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
378 if (selection->count > 0) {
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
379 ui_set_group(event->obj->ctx, APP_STATE_BROWSER_SELECTION);
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
380 } else {
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
381 ui_unset_group(event->obj->ctx, APP_STATE_BROWSER_SELECTION);
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
382 }
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
383 }
79a9aadf1c70 add main menu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
384
13
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
385 void action_list_activate(UiEvent *event, void *data) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
386 UiListSelection *selection = event->eventdata;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
387 DavBrowser *browser = event->document;
13
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
388
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
389 if (selection->count == 1) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
390 DavResource *res = ui_list_get(browser->resources, selection->rows[0]);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
391 if (res) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
392 if (res->iscollection) {
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
393 davbrowser_query_path(event->obj, browser, res->path);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
394 } else {
53
da05df77652e add menu items to open resource properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
395 davbrowser_open_resource(event->obj, browser, res, NULL);
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
396 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
397 }
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
398 }
13
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
399 }
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
400
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
401 void action_dnd_drop(UiEvent *event, void *data) {
37
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
402 UiListDnd *listdnd = event->eventdata;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
403 UiDnD *dnd = listdnd->dnd;
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
404 UiFileList files = ui_selection_geturis(dnd);
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
405
9b754f1b7e16 fix formatting
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
406 davbrowser_upload_files(event->obj, event->document, files);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
407 }

mercurial