Sun, 20 Oct 2024 21:24:13 +0200
add resource preview window
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 | |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
38 | static UiIcon* folder_icon; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
39 | static UiIcon* file_icon; |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
40 | |
9
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
41 | 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
|
42 | |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
43 | void window_init(void) { |
37 | 44 | folder_icon = ui_foldericon(16); |
45 | file_icon = ui_fileicon(16); | |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
46 | } |
2
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | |
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | UiObject* window_create(void) { |
37 | 49 | UiObject* obj = ui_window("iDAV", NULL); |
50 | 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
|
51 | |
37 | 52 | MainWindow* wdata = ui_malloc(obj->ctx, sizeof (MainWindow)); |
53 | memset(wdata, 0, sizeof (MainWindow)); | |
54 | obj->window = wdata; | |
7
905ac52c910f
port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
55 | |
37 | 56 | wdata->progress = ui_int_new(obj->ctx, "progress"); |
57 | ||
58 | // navigation bar | |
7
905ac52c910f
port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
59 | |
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
60 | 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
|
61 | 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
|
62 | 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
|
63 | 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
|
64 | } |
2
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | |
37 | 66 | 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
|
67 | |
37 | 68 | ui_progressspinner(obj, .value = wdata->progress); |
69 | } | |
2
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | |
37 | 71 | // main content |
72 | UiModel* model = ui_model(obj->ctx, UI_ICON_TEXT, "Name", UI_STRING, "Type", UI_STRING_FREE, "Last Modified", UI_STRING_FREE, "Size", -1); | |
73 | model->getvalue = (ui_getvaluefunc) window_resource_table_getvalue; | |
74 | ui_table(obj, .fill = UI_ON, .model = model, .onactivate = action_list_activate, .ondrop = action_dnd_drop, .varname = "reslist"); | |
2
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | |
37 | 76 | // status bar |
2
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | |
37 | 78 | ui_hbox(obj, .fill = UI_OFF) { |
79 | ui_label(obj, .label = ""); | |
80 | } | |
81 | ||
82 | return obj; | |
2
fbdfaacc4182
update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | } |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
84 | |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
85 | void* window_resource_table_getvalue(DavResource *res, int col) { |
37 | 86 | switch (col) { |
38
acd8c4a9d3fe
fix path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
87 | case 0: { // icon |
37 | 88 | return res->iscollection ? folder_icon : file_icon; |
89 | } | |
38
acd8c4a9d3fe
fix path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
90 | case 1: { // resource name |
37 | 91 | return res->name; |
92 | } | |
38
acd8c4a9d3fe
fix path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
93 | case 2: { // type |
37 | 94 | return res->iscollection ? "Collection" : (res->contenttype ? res->contenttype : "Resource"); |
95 | } | |
38
acd8c4a9d3fe
fix path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
96 | case 3: { // last modified |
37 | 97 | return util_date_str(res->lastmodified); |
98 | } | |
38
acd8c4a9d3fe
fix path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
99 | case 4: { // size |
37 | 100 | return util_size_str(res->iscollection, res->contentlength); |
101 | } | |
102 | } | |
103 | return NULL; | |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
104 | } |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
105 | |
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
106 | void window_progress(MainWindow *win, int on) { |
37 | 107 | ui_set(win->progress, on); |
8
726b24766437
implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
108 | } |
9
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
109 | |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
110 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
111 | |
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 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
114 | void dav_resourceviewer_new(DavBrowser *browser, const char *path, DavResourceViewType type) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
115 | const char *name = util_resource_name(path); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
116 | UiObject *win = ui_simple_window(name, NULL); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
117 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
118 | DavResourceViewer *doc = dav_resourceviewer_create(browser->sn, path, type); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
119 | ui_attach_document(win->ctx, doc); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
120 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
121 | ui_tabview(win, .tabview = UI_TABVIEW_INVISIBLE, .varname = "tabview") { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
122 | /* loading / message tab */ |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
123 | ui_tab(win, NULL) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
124 | 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
|
125 | ui_progressspinner(win, .varname = "loading"); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
126 | ui_label(win, .varname = "message"); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
127 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
128 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
129 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
130 | /* preview tab */ |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
131 | ui_tab(win, NULL) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
132 | ui_tabview0(win) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
133 | if(type == DAV_RESOURCE_VIEW_TEXT) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
134 | ui_tab(win, "Content") { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
135 | ui_textarea(win, .varname = "text"); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
136 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
137 | } else if(type == DAV_RESOURCE_VIEW_IMAGE) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
138 | ui_tab(win, "Preview") { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
139 | ui_imageviewer(win, .varname = "image"); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
140 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
141 | } |
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 | ui_tab(win, "Properties") { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
144 | 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
|
145 | model->getvalue = (ui_getvaluefunc) resourceviewer_proplist_getvalue; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
146 | 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
|
147 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
148 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
149 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
150 | } |
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 | dav_resourceviewer_load(win, doc); |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
153 | |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
154 | ui_show(win); |
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 | void* resourceviewer_proplist_getvalue(DavPropertyList *property, int col) { |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
158 | return NULL; |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
159 | } |
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
160 | |
9
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
161 | static UiPathElm* dav_get_pathelm(const char *full_path, size_t len, size_t *ret_nelm, void* data) { |
37 | 162 | cxstring fpath = cx_strn(full_path, len); |
163 | int protocol = 0; | |
164 | if (cx_strcaseprefix(fpath, CX_STR("http://"))) { | |
165 | protocol = 7; | |
166 | } else if (cx_strcaseprefix(fpath, CX_STR("https://"))) { | |
167 | protocol = 8; | |
168 | } | |
169 | ||
170 | size_t start = 0; | |
171 | size_t end = 0; | |
172 | for (size_t i = protocol; i < len; i++) { | |
173 | if (full_path[i] == '/') { | |
174 | end = i; | |
175 | break; | |
176 | } | |
177 | } | |
178 | ||
179 | int skip = 0; | |
180 | if (end == 0) { | |
181 | // no '/' found or first char is '/' | |
182 | end = len > 0 && full_path[0] == '/' ? 1 : len; | |
183 | } else if (end + 1 <= len) { | |
184 | skip++; // skip first '/' | |
185 | } | |
186 | ||
9
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
187 | |
37 | 188 | cxmutstr base = cx_strdup(cx_strn(full_path, end)); |
189 | cxmutstr base_path = cx_strdup(cx_strcast(base)); | |
190 | cxstring path = cx_strsubs(fpath, end + skip); | |
191 | ||
192 | cxstring *pathelms; | |
193 | size_t nelm = 0; | |
194 | ||
195 | if (path.length > 0) { | |
196 | nelm = cx_strsplit_a(cxDefaultAllocator, path, CX_STR("/"), 4096, &pathelms); | |
197 | if (nelm == 0) { | |
198 | *ret_nelm = 0; | |
199 | return NULL; | |
200 | } | |
201 | } | |
9
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
202 | |
37 | 203 | UiPathElm* elms = (UiPathElm*) calloc(nelm + 1, sizeof (UiPathElm)); |
204 | size_t n = nelm + 1; | |
205 | elms[0].name = base.ptr; | |
206 | elms[0].name_len = base.length; | |
207 | elms[0].path = base_path.ptr; | |
208 | 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
|
209 | |
37 | 210 | int j = 1; |
211 | for (int i = 0; i < nelm; i++) { | |
212 | cxstring c = pathelms[i]; | |
213 | if (c.length == 0) { | |
214 | if (i == 0) { | |
215 | c.length = 1; | |
216 | } else { | |
217 | n--; | |
218 | continue; | |
34
98e041f2f9a2
fix dav path separator function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
219 | } |
98e041f2f9a2
fix dav path separator function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
220 | } |
9
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
221 | |
37 | 222 | cxmutstr m = cx_strdup(c); |
223 | elms[j].name = m.ptr; | |
224 | 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
|
225 | |
37 | 226 | size_t elm_path_len = c.ptr + c.length - full_path; |
227 | cxmutstr elm_path = cx_strdup(cx_strn(full_path, elm_path_len)); | |
228 | elms[j].path = elm_path.ptr; | |
229 | 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
|
230 | |
37 | 231 | j++; |
232 | } | |
233 | *ret_nelm = n; | |
9
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
234 | |
37 | 235 | return elms; |
9
0676408f50ad
add path-textfield getelm function, that supports urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
236 | } |
11
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
237 | |
15
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
238 | void action_go_back(UiEvent *event, void *data) { |
37 | 239 | DavBrowser *browser = event->document; |
240 | davbrowser_navigation_back(event->obj, browser); | |
15
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
241 | } |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
242 | |
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
243 | void action_go_forward(UiEvent *event, void *data) { |
37 | 244 | DavBrowser *browser = event->document; |
245 | davbrowser_navigation_forward(event->obj, browser); | |
15
78684a24dc52
implement navigation back/forward buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
246 | } |
11
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
247 | |
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
248 | void action_path_selected(UiEvent *event, void *data) { |
37 | 249 | DavBrowser *browser = event->document; |
250 | char *path = event->eventdata; | |
251 | if (path && strlen(path) > 0) { | |
252 | davbrowser_query_url(event->obj, browser, path); | |
253 | } | |
11
26acbfa75c1f
add handler for the path bar activate events
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
254 | } |
13
5a8762fcfecc
update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
255 | |
5a8762fcfecc
update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
256 | void action_list_activate(UiEvent *event, void *data) { |
37 | 257 | UiListSelection *selection = event->eventdata; |
258 | DavBrowser *browser = event->document; | |
13
5a8762fcfecc
update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
259 | |
37 | 260 | if (selection->count == 1) { |
261 | DavResource *res = ui_list_get(browser->resources, selection->rows[0]); | |
262 | if (res) { | |
263 | if (res->iscollection) { | |
264 | davbrowser_query_path(event->obj, browser, res->path); | |
265 | } else { | |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
266 | davbrowser_open_resource(event->obj, browser, res); |
37 | 267 | } |
268 | } | |
269 | } | |
13
5a8762fcfecc
update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
270 | } |
18
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
271 | |
af411868ab9b
implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
272 | void action_dnd_drop(UiEvent *event, void *data) { |
37 | 273 | UiListDnd *listdnd = event->eventdata; |
274 | UiDnD *dnd = listdnd->dnd; | |
275 | UiFileList files = ui_selection_geturis(dnd); | |
276 | ||
277 | 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
|
278 | } |