application/application.c

Sun, 09 Jun 2024 16:43:40 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 09 Jun 2024 16:43:40 +0200
changeset 34
98e041f2f9a2
parent 33
cdeb0dc47ef5
child 35
834d9c15a69f
permissions
-rw-r--r--

fix dav path separator function

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 "application.h"
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <stdbool.h>
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
6
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
34 #include <libidav/webdav.h>
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
35
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "window.h"
6
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
37 #include "config.h"
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
38 #include "davcontroller.h"
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
6
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
40 static DavContext* davctx;
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
3
f154867f54dc add nav buttons, update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
42 void application_init(void) {
6
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
43 davctx = dav_context_new();
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
44 dav_context_set_mtsafe(davctx, true);
6
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
45
3
f154867f54dc add nav buttons, update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
46 application_create_menu();
f154867f54dc add nav buttons, update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
47 }
f154867f54dc add nav buttons, update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
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 void application_startup(UiEvent* event, void* data) {
6
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
51 if (load_config(davctx)) {
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
52 // TODO: error
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
53 exit(-1);
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
54 }
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
55
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
56 window_init();
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
57
14
872d570ae843 implement window new button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
58 // create document for global settings (repolist, ...)
872d570ae843 implement window new button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
59 DavApp *app = application_create_app_document();
872d570ae843 implement window new button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
60 UiContext *global = ui_global_context();
872d570ae843 implement window new button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
61 ui_attach_document(global, app);
872d570ae843 implement window new button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
62
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
63 // create new window
7
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
64 UiObject *win = window_create();
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
65 // create new browser document and attach it to the main window
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
66 DavBrowser *doc = davbrowser_create(win);
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
67 ui_attach_document(win->ctx, doc);
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 ui_show(win);
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 }
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
72 static void* davrepo_getname(void *elm, int unused) {
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
73 DavCfgRepository *repo = elm;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
74 return repo->name.value.ptr;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
75 }
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
76
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 void application_create_menu(void) {
33
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
78 // menu
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79
3
f154867f54dc add nav buttons, update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
80
33
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
81 // toolbar
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
82 ui_toolbar_item("Home", .icon = UI_ICON_HOME);
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
83 ui_toolbar_item("NewWindow", .icon = UI_ICON_NEW_WINDOW, .onclick = action_window_new);
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
84 ui_toolbar_item("Refresh", .icon = UI_ICON_REFRESH, .onclick = action_refresh);
3
f154867f54dc add nav buttons, update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
85 ui_toolbar_menu("Repo", .label = "Repository") {
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
86 ui_menu_itemlist(.varname = "repolist", .getvalue = davrepo_getname, .onselect = action_repo_selected);
3
f154867f54dc add nav buttons, update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
87 }
33
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
88 ui_toolbar_item("NewFolder", .icon = UI_ICON_NEW_FOLDER, .onclick = action_mkcol);
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
89 ui_toolbar_item("NewFile", .icon = UI_ICON_ADD, .onclick = action_newfile);
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
90 ui_toolbar_item("Upload", .label = "Upload", .icon = UI_ICON_UPLOAD, .onclick = action_upload_file);
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
91 ui_toolbar_item("Download", .icon = UI_ICON_SAVE_LOCAL, .onclick = action_download);
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
92 ui_toolbar_item("Remove", .icon = UI_ICON_DELETE, .onclick = action_delete );
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
93 ui_toolbar_toggleitem("LocalBrowser", .icon = UI_ICON_DOCK_LEFT, .label = "Local Browser");
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
94 ui_toolbar_toggleitem("PreviewPane", .icon = UI_ICON_DOCK_RIGHT);
4
31137432bea8 add more toolbar items
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
95
33
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
96 ui_toolbar_appmenu() {
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
97 ui_menuitem("TODO", NULL);
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
98 }
3
f154867f54dc add nav buttons, update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
99
33
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
100 ui_toolbar_add_default("Home", UI_TOOLBAR_LEFT);
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
101 ui_toolbar_add_default("NewWindow", UI_TOOLBAR_LEFT);
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
102 ui_toolbar_add_default("Refresh", UI_TOOLBAR_LEFT);
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
103 ui_toolbar_add_default("Repo", UI_TOOLBAR_LEFT);
4
31137432bea8 add more toolbar items
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
104
33
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
105 ui_toolbar_add_default("NewFolder", UI_TOOLBAR_CENTER);
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
106 ui_toolbar_add_default("NewFile", UI_TOOLBAR_CENTER);
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
107 ui_toolbar_add_default("Remove", UI_TOOLBAR_CENTER);
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
108 ui_toolbar_add_default("Download", UI_TOOLBAR_CENTER);
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
109 ui_toolbar_add_default("Upload", UI_TOOLBAR_CENTER);
4
31137432bea8 add more toolbar items
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
110
33
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
111 ui_toolbar_add_default("LocalBrowser", UI_TOOLBAR_RIGHT);
cdeb0dc47ef5 replace hard coded icon names with macros
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
112 ui_toolbar_add_default("PreviewPane", UI_TOOLBAR_RIGHT);
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 }
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115
6
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
116
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 DavApp* application_create_app_document(void) {
7
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
118 DavApp *doc = ui_document_new(sizeof(DavApp));
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
119 UiContext *ctx = ui_document_context(doc);
3
f154867f54dc add nav buttons, update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
120 doc->repos = ui_list_new(ctx, "repolist");
f154867f54dc add nav buttons, update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
121
6
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
122 // create repo list
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
123 application_update_repolist(doc);
3
f154867f54dc add nav buttons, update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
124
2
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 return doc;
fbdfaacc4182 update ucx, libidav and add first gui code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 }
6
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
127
7
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
128 void application_update_repolist(DavApp *app) {
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
129 DavConfig *config = get_config();
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
130 DavCfgRepository *repo = config->repositories;
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
131
6
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
132 ui_list_clear(app->repos);
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
133
7
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
134 for (DavCfgRepository *repo = config->repositories; repo; repo = repo->next) {
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
135 ui_list_append(app->repos, repo);
6
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
136 }
09ac07345656 add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
137 }
7
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
138
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
139
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
140 DavContext* application_dav_context(void) {
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
141 return davctx;
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
142 }
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
143
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
144
14
872d570ae843 implement window new button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
145 void action_window_new(UiEvent *event, void *data) {
872d570ae843 implement window new button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
146 UiObject *win = window_create();
872d570ae843 implement window new button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
147 // create new browser document and attach it to the main window
872d570ae843 implement window new button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
148 DavBrowser *doc = davbrowser_create(win);
872d570ae843 implement window new button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
149 ui_attach_document(win->ctx, doc);
872d570ae843 implement window new button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
150
872d570ae843 implement window new button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
151 ui_show(win);
872d570ae843 implement window new button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
152 }
872d570ae843 implement window new button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
153
17
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
154 void action_refresh(UiEvent *event, void *data) {
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
155 DavBrowser *browser = event->document;
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
156 if (browser->current) {
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
157 davbrowser_query_path(event->obj, browser, browser->current->path);
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
158 }
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
159 }
7cfd36aa005b add refresh button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
160
7
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
161 void action_repo_selected(UiEvent *event, void *data) {
8
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
162 DavCfgRepository *repo = event->eventdata;
726b24766437 implement connecting to repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
163 DavBrowser *browser = event->document;
16
f2e79b69d233 switch DavSession in davbrowser_query_url when a different server is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
164 davbrowser_connect2repo(event->obj, browser, repo, "");
7
905ac52c910f port more dav config code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
165 }
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
166
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
167 static void file_selected(UiEvent *event, void *data) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
168 UiFileList *files = event->eventdata;
23
cdcb20412dd4 implement upload via file dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
169 if (files && files->nfiles > 0) {
cdcb20412dd4 implement upload via file dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
170 // files will be freed by the filedialog handler, therefore we need a copy
cdcb20412dd4 implement upload via file dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
171 UiFileList uploadList = ui_filelist_copy(*files); // uploadList will be freed by davbrowser_upload_files
cdcb20412dd4 implement upload via file dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
172 davbrowser_upload_files(event->obj, event->document, uploadList);
cdcb20412dd4 implement upload via file dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
173 }
cdcb20412dd4 implement upload via file dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
174
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
175 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
176
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
177
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
178
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
179 static void download_location_selected(UiEvent *event, void *data) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
180 DavBrowser *browser = event->document;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
181 DavResource *reslist = data;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
182 UiFileList *flist = event->eventdata;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
183
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
184 if (flist && flist->nfiles > 0) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
185 davbrowser_download(event->obj, browser, reslist, flist->files[0]);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
186 } else {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
187 dav_session_destroy(reslist->session);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
188 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
189 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
190
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
191 void action_download(UiEvent *event, void *data) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
192 DavBrowser *browser = event->document;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
193 UiListSelection sel = ui_list_getselection(browser->resources);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
194 if (sel.count > 0) {;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
195 const char *initialFileName = NULL;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
196 if (sel.count == 1) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
197 DavResource *res = ui_list_get(browser->resources, sel.rows[0]);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
198 if (res && !res->iscollection) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
199 initialFileName = res->name;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
200 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
201 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
202
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
203 // create a copy of the current session and all selected resources
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
204 DavSession *sn = dav_session_clone(browser->sn);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
205 DavResource *first = NULL;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
206 DavResource *last = NULL;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
207 for (int i = 0; i < sel.count; i++) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
208 // get selected resource
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
209 DavResource *res = ui_list_get(browser->resources, sel.rows[i]);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
210 // copy resource
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
211 DavResource *res_copy = dav_resource_new(sn, res->path);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
212 res_copy->iscollection = res->iscollection;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
213 res_copy->contentlength = res->contentlength;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
214 res_copy->lastmodified = res->lastmodified;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
215 res_copy->creationdate = res->creationdate;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
216
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
217 // link resources
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
218 if (!first) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
219 first = res_copy;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
220 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
221 if (last) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
222 res_copy->prev = last;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
223 last->next = res_copy;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
224 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
225 last = res_copy;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
226 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
227
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
228 if (initialFileName) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
229 ui_savefiledialog(event->obj, initialFileName, download_location_selected, first);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
230 } else {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
231 ui_openfiledialog(event->obj, UI_FILEDIALOG_SELECT_FOLDER, download_location_selected, first);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
232 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
233 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
234 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
235
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
236 void action_upload_file(UiEvent *event, void *data) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
237 ui_openfiledialog(event->obj, UI_FILEDIALOG_SELECT_MULTI, file_selected, NULL);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
238 }
26
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
239
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
240 void action_delete(UiEvent *event, void *data) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
241 DavBrowser *browser = event->document;
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
242 UiListSelection sel = ui_list_getselection(browser->resources);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
243 if (sel.count > 0) {
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
244 davbrowser_delete(event->obj, browser, sel);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
245 }
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
246 ui_listselection_free(sel);
40d6af793c1a implement resource deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
247 }
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
248
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
249 void action_newfile(UiEvent *event, void *data) {
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
250
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
251 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
252
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
253
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
254 static void newfolderdialog_result(UiEvent *event, void *data) {
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
255 DavBrowser *browser = event->document;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
256 char *path = event->eventdata;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
257 if (event->intval == 1) {
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
258 davbrowser_mkcol(event->obj, browser, path);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
259 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
260 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
261
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
262 void action_mkcol(UiEvent *event, void *data) {
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
263 ui_dialog(event->obj, .content = "New Folder", .input = TRUE, .button1_label = "Create Folder", .button2_label = "Close", .result = newfolderdialog_result);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
264 }

mercurial