29 #include "davcontroller.h" |
29 #include "davcontroller.h" |
30 #include "window.h" |
30 #include "window.h" |
31 |
31 |
32 #include <cx/printf.h> |
32 #include <cx/printf.h> |
33 |
33 |
|
34 #include "config.h" |
|
35 |
|
36 #include <libidav/config.h> |
34 #include <libidav/utils.h> |
37 #include <libidav/utils.h> |
35 |
38 |
36 DavBrowser* davbrowser_create(UiObject *toplevel) { |
39 DavBrowser* davbrowser_create(UiObject *toplevel) { |
37 DavBrowser *doc = ui_document_new(sizeof(DavBrowser)); |
40 DavBrowser *doc = ui_document_new(sizeof(DavBrowser)); |
38 UiContext *ctx = ui_document_context(doc); |
41 UiContext *ctx = ui_document_context(doc); |
65 browser->resources->update(browser->resources, 0); |
68 browser->resources->update(browser->resources, 0); |
66 } |
69 } |
67 |
70 |
68 // ------------------------------ davbrowser_connect2repo ------------------------------ |
71 // ------------------------------ davbrowser_connect2repo ------------------------------ |
69 |
72 |
70 void davbrowser_connect2repo(UiObject *ui, DavBrowser *browser, DavCfgRepository *repo) { |
73 void davbrowser_connect2repo(UiObject *ui, DavBrowser *browser, DavCfgRepository *repo, const char *path) { |
71 DavSession *sn = dav_session_new(application_dav_context(), repo->url.value.ptr); |
74 DavSession *sn = dav_session_new(application_dav_context(), repo->url.value.ptr); |
72 if (repo->user.value.ptr && repo->password.value.ptr) { |
75 if (repo->user.value.ptr && repo->password.value.ptr) { |
73 cxmutstr decodedpw = dav_repository_get_decodedpassword(repo); |
76 cxmutstr decodedpw = dav_repository_get_decodedpassword(repo); |
74 dav_session_set_auth(sn, repo->user.value.ptr, decodedpw.ptr); |
77 dav_session_set_auth(sn, repo->user.value.ptr, decodedpw.ptr); |
75 free(decodedpw.ptr); |
78 free(decodedpw.ptr); |
76 } |
79 } |
77 browser->sn = sn; |
80 browser->sn = sn; |
78 browser->repo_base = cx_strdup(cx_strn(repo->name.value.ptr, repo->name.value.length)).ptr; |
81 if (repo->name.value.length > 0) { |
79 |
82 browser->repo_base = cx_strdup(cx_strn(repo->name.value.ptr, repo->name.value.length)).ptr; |
80 ui_set(browser->path, repo->name.value.ptr); |
83 } else { |
81 |
84 browser->repo_base = cx_strdup(cx_strn(repo->url.value.ptr, repo->url.value.length)).ptr; |
82 davbrowser_query_path(ui, browser, ""); |
85 } |
|
86 |
|
87 char *dav_path = util_concat_path(browser->repo_base, path); |
|
88 ui_set(browser->path, dav_path); |
|
89 free(dav_path); |
|
90 |
|
91 davbrowser_query_path(ui, browser, path); |
83 } |
92 } |
84 |
93 |
85 |
94 |
86 // ------------------------------ davbrowser_query_path ------------------------------ |
95 // ------------------------------ davbrowser_query_path ------------------------------ |
87 |
96 |
94 |
103 |
95 static int browser_query_path(void *data) { |
104 static int browser_query_path(void *data) { |
96 DavBrowserQueryPath *query = data; |
105 DavBrowserQueryPath *query = data; |
97 DavSession *sn = query->browser->sn; |
106 DavSession *sn = query->browser->sn; |
98 |
107 |
99 DavResource *res = dav_query(sn, "select `idav:crypto-name`,`idav:crypto-key`,D:lockdiscovery,D:getcontenttype from %s with depth = 1 order by iscollection desc, name", query->path); |
108 DavResource *res = dav_query(sn, "select `idav:crypto-name`,`idav:crypto-key`,D:lockdiscovery from %s with depth = 1 order by iscollection desc, name", query->path); |
100 query->result = res; |
109 query->result = res; |
101 |
110 |
102 return 0; |
111 return 0; |
103 } |
112 } |
104 |
113 |
167 davbrowser_query_path(ui, browser, path); |
176 davbrowser_query_path(ui, browser, path); |
168 return; |
177 return; |
169 } |
178 } |
170 } |
179 } |
171 |
180 |
172 // TODO: |
181 char *path = NULL; |
|
182 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
|
183 davbrowser_connect2repo(ui, browser, repo, path); |
|
184 |
|
185 if (path) { |
|
186 free(path); |
|
187 } |
|
188 if (!repo->node) { |
|
189 dav_repository_free(get_config(), repo); |
|
190 } |
173 } |
191 } |
174 |
192 |
175 void davbrowser_add2navstack(DavBrowser *browser, const char *base, const char *path) { |
193 void davbrowser_add2navstack(DavBrowser *browser, const char *base, const char *path) { |
176 if (browser->navstack_enabled) { |
194 if (browser->navstack_enabled) { |
177 for (int i = 0; i < browser->navstack_pos; i++) { |
195 for (int i = 0; i < browser->navstack_pos; i++) { |