Wed, 27 Nov 2024 16:48:59 +0100
use repo encryption and SSL settings, resolves #516
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2024 Olaf Wintermann. All rights reserved. |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
ee4e4742391e
add settings window and implement repository editing
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 |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include "settings.h" |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include <cx/list.h> |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
32 | #include <cx/array_list.h> |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
33 | #include <cx/printf.h> |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include <libidav/utils.h> |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
37 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | #define SETTINGS_STATE_REPOLIST_SELECTED 1 |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #define SETTINGS_STATE_REPO_ENCRYPTION 20 |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
40 | #define SETTINGS_STATE_CREDENTIALS_SELECTED 30 |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
41 | #define SETTINGS_STATE_CREDENTIALS_LOCATION_SELECTED 31 |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
42 | #define SETTINGS_STATE_KEYS_SELECTED 40 |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
43 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
44 | #define SETTINGS_STATE_DISABLED 9999 |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | static void repolist_activate(UiEvent *event, void *userdata) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | UiListSelection *selection = event->eventdata; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | SettingsWindow *settings = event->window; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | settings_edit_repository(settings, selection->rows[0]); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | static void repolist_selection(UiEvent *event, void *userdata) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | UiListSelection *selection = event->eventdata; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | SettingsWindow *settings = event->window; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | if(selection->count > 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | ui_set_group(event->obj->ctx, SETTINGS_STATE_REPOLIST_SELECTED); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | settings->selected_repo = selection->rows[0]; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | } else { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | ui_unset_group(event->obj->ctx, SETTINGS_STATE_REPOLIST_SELECTED); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | static void repolist_edit(UiEvent *event, void *userdata) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | SettingsWindow *settings = event->window; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | if(settings->selected_repo >= 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | settings_edit_repository(settings, settings->selected_repo); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | |
62
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
71 | static void repolist_add(UiEvent *event, void *userdata) { |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
72 | SettingsWindow *settings = event->window; |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
73 | settings->repo_new = TRUE; |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
74 | settings->selected_repo = -1; |
63
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
75 | settings_clear_repository(settings); |
62
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
76 | // switch to editing tab |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
77 | ui_set(settings->repo_tabview, 1); |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
78 | } |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
79 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | static void repolist_remove(UiEvent *event, void *userdata) { |
62
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
81 | SettingsWindow *settings = event->window; |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
82 | DavCfgRepository *repo = ui_list_get(settings->repos, settings->selected_repo); |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
83 | if(!repo) { |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
84 | fprintf(stderr, "Error: cannot get repository at index %d\n", settings->selected_repo); |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
85 | return; |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
86 | } |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
87 | dav_repository_remove_and_free(settings->config, repo); |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
88 | settings_update_repolist(settings); |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
89 | settings->selected_repo = -1; |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
90 | ui_unset_group(event->obj->ctx, SETTINGS_STATE_REPOLIST_SELECTED); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | static void editrepo_go_back(UiEvent *event, void *userdata) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | SettingsWindow *settings = event->window; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | settings_store_repository(settings); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | ui_set(settings->repo_tabview, 0); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
99 | static void credentials_add(UiEvent *event, void *userdata) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
100 | SettingsWindow *settings = event->window; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
101 | if(settings_credentials_save(settings)) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
102 | return; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
103 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
104 | if(settings->credentials_list_needs_update) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
105 | settings->credentials_ignore_selectionevent = TRUE; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
106 | ui_list_update(settings->credentials_users); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
107 | settings_reload_repo_credentials(settings); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
108 | settings->credentials_ignore_selectionevent = FALSE; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
109 | settings->credentials_list_needs_update = FALSE; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
110 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
111 | settings_credentials_clear(settings); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
112 | settings->credentials_new = TRUE; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
113 | PwdStore *pwd = settings->pwdstore; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
114 | if(!pwd->isdecrypted) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
115 | settings_credentials_decrypt(settings); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
116 | return; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
117 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
118 | settings_credentials_select(settings, NULL); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
119 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
120 | |
74
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
121 | static void addcred_onclick(UiEvent *event, void *userdata) { |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
122 | SettingsNewCredentialsDialog *wdata = event->window; |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
123 | if(event->intval == 4) { |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
124 | char *id = ui_get(wdata->id); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
125 | char *user = ui_get(wdata->user); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
126 | char *password = ui_get(wdata->password); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
127 | int addlocation = ui_get(wdata->addlocation); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
128 | |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
129 | if(strlen(id) == 0) { |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
130 | ui_set(wdata->message, "Missing identifier!"); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
131 | return; |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
132 | } |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
133 | if(strlen(user) == 0) { |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
134 | ui_set(wdata->message, "Missing user!"); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
135 | return; |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
136 | } |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
137 | if(strlen(password) == 0) { |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
138 | ui_set(wdata->message, "Missing password!"); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
139 | return; |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
140 | } |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
141 | |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
142 | if(pwdstore_has_id(wdata->settings->pwdstore, id)) { |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
143 | ui_set(wdata->message, "Identifier already in use!"); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
144 | return; |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
145 | } |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
146 | |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
147 | CxList *locations = NULL; |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
148 | if(addlocation) { |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
149 | locations = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
150 | cxListAdd(locations, strdup(wdata->url)); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
151 | } |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
152 | pwdstore_put(wdata->settings->pwdstore, id, user, password); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
153 | pwdstore_put_index(wdata->settings->pwdstore, strdup(id), locations); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
154 | |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
155 | settings_reload_credentials(wdata->settings); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
156 | settings_reload_repo_credentials(wdata->settings); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
157 | |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
158 | CxList *list = wdata->settings->repo_credentials->data; |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
159 | ssize_t index = cxListFind(list, id); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
160 | if(index >= 0) { |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
161 | ui_list_setselection(wdata->settings->repo_credentials, index); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
162 | } |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
163 | } |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
164 | |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
165 | ui_close(event->obj); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
166 | } |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
167 | |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
168 | // called by repo_edit |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
169 | // create new credentials in dialog |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
170 | static void credentials_new(UiEvent *event, void *userdata) { |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
171 | SettingsWindow *settings = event->window; |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
172 | |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
173 | UiObject *dialog = ui_dialog_window(event->obj, |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
174 | .modal = UI_ON, |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
175 | .title = "New Credentials", |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
176 | .show_closebutton = UI_OFF, |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
177 | .lbutton1 = "Cancel", |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
178 | .rbutton4 = "Add", |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
179 | .onclick = addcred_onclick); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
180 | |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
181 | SettingsNewCredentialsDialog *wdata = ui_malloc(dialog->ctx, sizeof(SettingsNewCredentialsDialog)); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
182 | wdata->settings = settings; |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
183 | wdata->id = ui_string_new(dialog->ctx, NULL); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
184 | wdata->user = ui_string_new(dialog->ctx, NULL); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
185 | wdata->password = ui_string_new(dialog->ctx, NULL); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
186 | wdata->addlocation = ui_int_new(dialog->ctx, NULL); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
187 | wdata->message = ui_string_new(dialog->ctx, NULL); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
188 | dialog->window = wdata; |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
189 | |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
190 | char *url = ui_get(settings->repo_url); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
191 | if(strlen(url) > 0) { |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
192 | wdata->url = ui_strdup(dialog->ctx, url); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
193 | } else { |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
194 | wdata->url = NULL; |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
195 | } |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
196 | |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
197 | ui_grid(dialog, .margin = 16, .columnspacing = 40, .rowspacing = 10) { |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
198 | ui_llabel(dialog, .label = "Identifier"); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
199 | ui_textfield(dialog, .value = wdata->id, .hexpand = TRUE); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
200 | ui_newline(dialog); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
201 | |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
202 | ui_llabel(dialog, .label = "User"); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
203 | ui_textfield(dialog, .value = wdata->user, .hexpand = TRUE); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
204 | ui_newline(dialog); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
205 | |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
206 | ui_llabel(dialog, .label = "Password"); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
207 | ui_passwordfield(dialog, .value = wdata->password, .hexpand = TRUE); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
208 | ui_newline(dialog); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
209 | |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
210 | if(wdata->url) { |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
211 | cxmutstr msg = cx_asprintf("Add URL %s to Credential Locations", url); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
212 | ui_checkbox(dialog, .label = msg.ptr, .value = wdata->addlocation, .colspan = 2); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
213 | ui_newline(dialog); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
214 | free(msg.ptr); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
215 | } |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
216 | |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
217 | ui_llabel(dialog, .value = wdata->message, .colspan = 2); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
218 | } |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
219 | |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
220 | ui_show(dialog); |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
221 | } |
4466ebbd9fd5
implement repo New Credentials button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
222 | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
223 | static void credentials_remove(UiEvent *event, void *userdata) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
224 | SettingsWindow *settings = event->window; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
225 | if(settings->credentials_selected_id) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
226 | pwdstore_remove_entry(settings->pwdstore, settings->credentials_selected_id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
227 | ui_list_remove(settings->credentials_users, settings->credentials_selected_index); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
228 | ui_list_update(settings->credentials_users); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
229 | settings_reload_repo_credentials(settings); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
230 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
231 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
232 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
233 | static void credentials_onselect(UiEvent *event, void *userdata) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
234 | SettingsWindow *settings = event->window; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
235 | if(settings->credentials_ignore_selectionevent) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
236 | return; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
237 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
238 | UiListSelection *sel = event->eventdata; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
239 | if(settings_credentials_save(settings)) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
240 | return; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
241 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
242 | if(sel->count > 0) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
243 | const char *id = ui_list_get(settings->credentials_users, sel->rows[0]); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
244 | settings->credentials_selected_index = sel->rows[0]; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
245 | settings_credentials_select(settings, id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
246 | if(settings->credentials_list_needs_update) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
247 | settings->credentials_ignore_selectionevent = TRUE; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
248 | ui_list_update(settings->credentials_users); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
249 | settings_reload_repo_credentials(settings); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
250 | ui_list_setselection(settings->credentials_users, sel->rows[0]); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
251 | settings->credentials_ignore_selectionevent = FALSE; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
252 | settings->credentials_list_needs_update = FALSE; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
253 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
254 | } else { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
255 | settings_credentials_clear(settings); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
256 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
257 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
258 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
259 | static void c_add_location(UiEvent *event, void *userdata) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
260 | SettingsWindow *settings = event->window; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
261 | if(event->intval == 1) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
262 | ui_list_append(settings->credentials_locations, ui_strdup(event->obj->ctx, event->eventdata)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
263 | ui_list_update(settings->credentials_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
264 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
265 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
266 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
267 | static void credentials_location_add(UiEvent *event, void *userdata) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
268 | SettingsWindow *settings = event->window; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
269 | ui_dialog(event->obj, |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
270 | .title = "Add Location", |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
271 | .content = "New Location URL", |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
272 | .input = TRUE, |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
273 | .result = c_add_location, |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
274 | .button1_label = "Add Location", |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
275 | .closebutton_label = "Cancel"); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
276 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
277 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
278 | static void c_edit_location(UiEvent *event, void *userdata) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
279 | SettingsWindow *settings = event->window; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
280 | if(event->intval == 1) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
281 | CxList *list = settings->credentials_locations->data; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
282 | ssize_t i = cxListFind(list, userdata); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
283 | if(i >= 0) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
284 | cxListRemove(list, i); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
285 | cxListInsert(list, i, ui_strdup(event->obj->ctx, event->eventdata)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
286 | ui_list_update(settings->credentials_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
287 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
288 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
289 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
290 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
291 | static void credentials_location_edit(UiEvent *event, void *userdata) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
292 | SettingsWindow *settings = event->window; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
293 | char *location = ui_list_get(settings->credentials_locations, settings->credentials_location_selected_index); |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
294 | if(!location) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
295 | return; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
296 | } |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
297 | ui_dialog(event->obj, |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
298 | .title = "Edit Location", |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
299 | .content = "Location URL", |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
300 | .input_value = location, |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
301 | .input = TRUE, |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
302 | .result = c_edit_location, |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
303 | .resultdata = location, |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
304 | .button1_label = "Edit Location", |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
305 | .closebutton_label = "Cancel"); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
306 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
307 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
308 | static void credentials_location_remove(UiEvent *event, void *userdata) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
309 | SettingsWindow *settings = event->window; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
310 | if(settings->credentials_location_selected_index >= 0) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
311 | CxList *list = settings->credentials_locations->data; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
312 | cxListRemove(list, settings->credentials_location_selected_index); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
313 | ui_list_update(settings->credentials_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
314 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
315 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
316 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
317 | static void credentials_location_up(UiEvent *event, void *userdata) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
318 | SettingsWindow *settings = event->window; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
319 | int index = settings->credentials_location_selected_index; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
320 | if(index >= 1) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
321 | CxList *list = settings->credentials_locations->data; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
322 | cxListSwap(list, index, index-1); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
323 | ui_list_update(settings->credentials_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
324 | ui_list_setselection(settings->credentials_locations, index-1); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
325 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
326 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
327 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
328 | static void credentials_location_down(UiEvent *event, void *userdata) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
329 | SettingsWindow *settings = event->window; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
330 | int index = settings->credentials_location_selected_index; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
331 | if(index >= 0 && index + 1 < ui_list_count(settings->credentials_locations)) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
332 | CxList *list = settings->credentials_locations->data; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
333 | cxListSwap(list, index, index+1); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
334 | ui_list_update(settings->credentials_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
335 | ui_list_setselection(settings->credentials_locations, index+1); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
336 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
337 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
338 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
339 | static void credentials_location_onselect(UiEvent *event, void *userdata) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
340 | SettingsWindow *settings = event->window; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
341 | UiListSelection *sel = event->eventdata; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
342 | if(sel->count > 0) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
343 | settings->credentials_location_selected_index = sel->rows[0]; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
344 | ui_set_group(event->obj->ctx, SETTINGS_STATE_CREDENTIALS_LOCATION_SELECTED); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
345 | } else { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
346 | settings->credentials_location_selected_index = -1; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
347 | ui_unset_group(event->obj->ctx, SETTINGS_STATE_CREDENTIALS_LOCATION_SELECTED); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
348 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
349 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
350 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
351 | static void credentials_setmasterpw(UiEvent *event, void *userdata) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
352 | if(event->intval == 1) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
353 | SettingsWindow *settings = event->window; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
354 | char *pw = event->eventdata; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
355 | size_t pwlen = strlen(pw); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
356 | if(pwlen > 0) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
357 | pwdstore_setpassword(settings->pwdstore, event->eventdata); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
358 | memset(pw, 0, pwlen); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
359 | if(!pwdstore_decrypt(settings->pwdstore)) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
360 | settings_credentials_select(settings, NULL); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
361 | } else { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
362 | ui_dialog(event->obj, .title = "Error", .content = "Cannot decrypt Secret Store", .closebutton_label = "OK"); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
363 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
364 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
365 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
366 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
367 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
368 | void settings_credentials_decrypt(SettingsWindow *settings) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
369 | ui_dialog(settings->obj, |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
370 | .title = "Secret Store", |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
371 | .content = "Master password", |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
372 | .password = TRUE, |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
373 | .result = credentials_setmasterpw, |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
374 | .button1_label = "Decrypt Secret Store", |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
375 | .closebutton_label = "Cancel"); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
376 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
377 | |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
378 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
379 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
380 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
381 | #define ADDKEY_DIALOG_STATE_NO_IMPORT 10 |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
382 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
383 | static void addkey_onclick(UiEvent *event, void *userdata) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
384 | SettingsNewKeyDialog *wdata = event->window; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
385 | if(event->intval == 4) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
386 | ui_set(wdata->message, ""); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
387 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
388 | // validate form |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
389 | char *name = ui_get(wdata->name); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
390 | if(strlen(name) == 0) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
391 | ui_set(wdata->message, "A name must be specified!"); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
392 | return; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
393 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
394 | char *file = ui_get(wdata->file); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
395 | if(strlen(file) == 0) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
396 | ui_set(wdata->message, "A file path must be specified!"); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
397 | return; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
398 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
399 | UiListSelection sel = ui_list_getselection(wdata->type); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
400 | if(sel.count == 0) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
401 | ui_set(wdata->message, "No type selected!"); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
402 | return; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
403 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
404 | DavCfgKeyType type = sel.rows[0]; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
405 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
406 | // generate key file |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
407 | char *path = NULL; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
408 | char *cfg_path = NULL; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
409 | if(file[0] == '/') { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
410 | path = file; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
411 | } else { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
412 | cfg_path = config_file_path(file); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
413 | path = cfg_path; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
414 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
415 | FILE *f = fopen(path, "w"); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
416 | if(!f) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
417 | cxmutstr msg = cx_asprintf("Error: cannot write file '%s': %s", path, strerror(errno)); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
418 | ui_set(wdata->message, msg.ptr); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
419 | free(msg.ptr); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
420 | free(cfg_path); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
421 | return; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
422 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
423 | free(cfg_path); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
424 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
425 | unsigned char key[32]; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
426 | dav_rand_bytes(key, 32); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
427 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
428 | size_t len; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
429 | switch(type) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
430 | default: |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
431 | case DAV_KEY_TYPE_AES256: len = 32; break; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
432 | case DAV_KEY_TYPE_AES128: len = 16; break; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
433 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
434 | size_t w = fwrite(key, 1, len, f); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
435 | fclose(f); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
436 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
437 | if(w != len) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
438 | cxmutstr msg = cx_asprintf("Could not write key data: %s", strerror(errno)); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
439 | ui_set(wdata->message, msg.ptr); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
440 | free(msg.ptr); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
441 | return; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
442 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
443 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
444 | // add key to config |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
445 | DavCfgKey *newkey = dav_key_new(wdata->settings->config); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
446 | const CxAllocator *a = wdata->settings->config->mp->allocator; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
447 | newkey->name.value = cx_strdup_a(a, cx_str(name)); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
448 | newkey->file.value = cx_strdup_a(a, cx_str(file)); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
449 | newkey->type = type; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
450 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
451 | dav_config_add_key(wdata->settings->config, newkey); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
452 | settings_reload_repo_keys(wdata->settings); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
453 | settings_reload_keys(wdata->settings); |
73
ede7885491b1
implement repo Generate Key button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
454 | |
ede7885491b1
implement repo Generate Key button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
455 | if(wdata->add_to_repo && (wdata->settings->selected_repo >= 0 || wdata->settings->repo_new)) { |
ede7885491b1
implement repo Generate Key button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
456 | CxList *repo_keys = wdata->settings->repo_keys->data; |
ede7885491b1
implement repo Generate Key button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
457 | ssize_t index = cxListFind(repo_keys, name); |
ede7885491b1
implement repo Generate Key button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
458 | if(index >= 0) { |
ede7885491b1
implement repo Generate Key button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
459 | ui_list_setselection(wdata->settings->repo_keys, index); |
ede7885491b1
implement repo Generate Key button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
460 | } |
ede7885491b1
implement repo Generate Key button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
461 | } |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
462 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
463 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
464 | ui_close(event->obj); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
465 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
466 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
467 | static void addkey_name_changed(UiEvent *event, void *userdata) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
468 | SettingsNewKeyDialog *wdata = event->window; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
469 | char *name = ui_get(wdata->name); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
470 | cxmutstr file = cx_asprintf("keys/%s", name); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
471 | ui_set(wdata->file, file.ptr); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
472 | free(file.ptr); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
473 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
474 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
475 | static void keys_add(UiEvent *event, void *userdata) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
476 | SettingsWindow *settings = event->window; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
477 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
478 | UiObject *dialog = ui_dialog_window(event->obj, |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
479 | .modal = UI_ON, |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
480 | .title = "Add Key", |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
481 | .show_closebutton = UI_OFF, |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
482 | .lbutton1 = "Cancel", |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
483 | .rbutton4 = "Add", |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
484 | .default_button = 4, |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
485 | .onclick = addkey_onclick); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
486 | SettingsNewKeyDialog *wdata = ui_malloc(dialog->ctx, sizeof(SettingsNewKeyDialog)); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
487 | wdata->settings = settings; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
488 | wdata->name = ui_string_new(dialog->ctx, NULL); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
489 | wdata->file = ui_string_new(dialog->ctx, NULL); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
490 | wdata->import_path = ui_string_new(dialog->ctx, NULL); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
491 | wdata->message = ui_string_new(dialog->ctx, NULL); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
492 | wdata->secretstore = ui_int_new(dialog->ctx, NULL); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
493 | wdata->type = ui_list_new(dialog->ctx, NULL); |
73
ede7885491b1
implement repo Generate Key button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
494 | wdata->add_to_repo = userdata ? TRUE : FALSE; |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
495 | dialog->window = wdata; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
496 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
497 | ui_list_append(wdata->type, "AES256"); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
498 | ui_list_append(wdata->type, "AES128"); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
499 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
500 | ui_grid(dialog, .margin = 16, .columnspacing = 40, .rowspacing = 10) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
501 | /* |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
502 | ui_hbox(dialog, .colspan = 2) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
503 | ui_button(dialog, .label = "Import Key..."); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
504 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
505 | ui_newline(dialog); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
506 | ui_llabel(dialog, .value = wdata->import_path); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
507 | ui_newline(dialog); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
508 | */ |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
509 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
510 | ui_llabel(dialog, .label = "Name"); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
511 | ui_textfield(dialog, .value = wdata->name, .onchange = addkey_name_changed, .hexpand = TRUE); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
512 | ui_newline(dialog); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
513 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
514 | ui_llabel(dialog, .label = "File"); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
515 | ui_textfield(dialog, .value = wdata->file); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
516 | ui_newline(dialog); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
517 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
518 | ui_llabel(dialog, .label = "Type"); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
519 | ui_combobox(dialog, .list = wdata->type, .groups = UI_GROUPS(ADDKEY_DIALOG_STATE_NO_IMPORT)); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
520 | ui_newline(dialog); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
521 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
522 | ui_llabel(dialog, .value = wdata->message, .colspan = 2); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
523 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
524 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
525 | ui_set_group(dialog->ctx, ADDKEY_DIALOG_STATE_NO_IMPORT); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
526 | ui_list_setselection(wdata->type, 0); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
527 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
528 | ui_show(dialog); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
529 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
530 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
531 | static void keys_remove(UiEvent *event, void *userdata) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
532 | SettingsWindow *settings = event->window; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
533 | DavCfgKey *key = ui_list_get(settings->keys_list, settings->keys_selected_index); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
534 | if(key) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
535 | dav_key_remove_and_free(settings->config, key); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
536 | ui_list_remove(settings->keys_list, settings->keys_selected_index); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
537 | ui_list_update(settings->keys_list); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
538 | settings_reload_repo_keys(settings); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
539 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
540 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
541 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
542 | static void keys_onselect(UiEvent *event, void *userdata) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
543 | SettingsWindow *settings = event->window; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
544 | UiListSelection *sel = event->eventdata; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
545 | if(sel->count > 0) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
546 | settings->keys_selected_index = sel->rows[0]; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
547 | DavCfgKey *key = ui_list_get(settings->keys_list, sel->rows[0]); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
548 | if(key) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
549 | settings_edit_key(settings, key); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
550 | ui_set_group(event->obj->ctx, SETTINGS_STATE_KEYS_SELECTED); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
551 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
552 | } else { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
553 | settings->keys_selected_index = -1; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
554 | settings_clear_key(settings); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
555 | ui_unset_group(event->obj->ctx, SETTINGS_STATE_KEYS_SELECTED); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
556 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
557 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
558 | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
559 | static void list_str_destructor(void *data, void *ptr) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
560 | UiContext *ctx = data; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
561 | char *s = ptr; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
562 | ui_free(ctx, ptr); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
563 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
564 | |
67
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
565 | static void secretstore_newmasterpw(UiEvent *event, void *userdata) { |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
566 | SettingsWindow *settings = event->window; |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
567 | if(event->intval == 1) { |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
568 | pwdstore_setpassword(settings->pwdstore, event->eventdata); |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
569 | set_pwdstore(settings->pwdstore); |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
570 | pwdstore_save(settings->pwdstore); |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
571 | settings->pwdstore = NULL; |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
572 | } |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
573 | ui_close(event->obj); |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
574 | } |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
575 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
576 | void settings_ok(UiEvent *event, void *userdata) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
577 | SettingsWindow *settings = event->window; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
578 | // save any changed settings |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
579 | settings_store_repository(settings); |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
580 | settings_credentials_save(settings); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
581 | |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
582 | set_config(settings->config); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
583 | if(store_config()) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
584 | ui_dialog(event->obj, .title = "Error", .content = "Cannot store settings", .closebutton_label = "OK"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
585 | } |
67
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
586 | application_update_repolist(get_application()); settings->config = NULL; |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
587 | if(settings->credentials_modified) { |
67
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
588 | if(settings->pwdstore->key) { |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
589 | set_pwdstore(settings->pwdstore); |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
590 | pwdstore_save(settings->pwdstore); |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
591 | } else { |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
592 | ui_dialog(event->obj, |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
593 | .title = "Secret Store", |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
594 | .content = "Master password", |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
595 | .password = TRUE, |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
596 | .result = secretstore_newmasterpw, |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
597 | .button1_label = "Create Secret Store", |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
598 | .closebutton_label = "Cancel", |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
599 | .result = secretstore_newmasterpw); |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
600 | return; |
3f987dde3be2
implement creation of new secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
601 | } |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
602 | settings->pwdstore = NULL; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
603 | } |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
604 | ui_close(event->obj); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
605 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
606 | |
61
eb63af2f2bdd
fix crash when closing the settings window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
607 | void settings_close(UiEvent *event, void *userdata) { |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
608 | SettingsWindow *settings = event->window; |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
609 | if(settings->config) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
610 | dav_config_free(settings->config); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
611 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
612 | if(settings->pwdstore) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
613 | pwdstore_free(settings->pwdstore); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
614 | } |
61
eb63af2f2bdd
fix crash when closing the settings window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
615 | } |
eb63af2f2bdd
fix crash when closing the settings window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
616 | |
eb63af2f2bdd
fix crash when closing the settings window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
617 | void settings_cancel(UiEvent *event, void *userdata) { |
eb63af2f2bdd
fix crash when closing the settings window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
618 | ui_close(event->obj); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
619 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
620 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
621 | void settings_window_open() { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
622 | DavConfig *config = load_config_file(); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
623 | if(!config) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
624 | return; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
625 | } |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
626 | PwdStore *pwdstore = get_pwdstore(); |
66
eee1f3092844
fix missing settings_reload_repo_credentials call
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
627 | pwdstore = pwdstore ? pwdstore_clone(pwdstore) : pwdstore_new(); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
628 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
629 | UiObject *obj = ui_simple_window("Settings", NULL); |
61
eb63af2f2bdd
fix crash when closing the settings window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
630 | ui_context_closefunc(obj->ctx, settings_close, NULL); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
631 | SettingsWindow *wdata = ui_malloc(obj->ctx, sizeof(SettingsWindow)); |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
632 | memset(wdata, 0, sizeof(SettingsWindow)); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
633 | wdata->config = config; |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
634 | wdata->pwdstore = pwdstore; |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
635 | obj->window = wdata; |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
636 | wdata->obj = obj; |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
637 | settings_init(obj, wdata); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
638 | |
76 | 639 | ui_tabview(obj, .tabview = UI_TABVIEW_NAVIGATION_TOP) { |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
640 | ui_tab(obj, "General") { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
641 | ui_grid(obj, .margin = 10) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
642 | ui_label(obj, .label = "TODO"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
643 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
644 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
645 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
646 | ui_tab(obj, "Repositories") { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
647 | |
68 | 648 | ui_tabview(obj, .value = wdata->repo_tabview, .tabview = UI_TABVIEW_INVISIBLE) { |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
649 | ui_tab(obj, "list") { |
68 | 650 | ui_grid(obj, .margin = 16, .columnspacing = 10, .rowspacing = 10) { |
651 | ui_hbox(obj, .spacing = 4) { | |
62
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
652 | ui_button(obj, .label = "Add", .onclick = repolist_add); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
653 | ui_button(obj, .label = "Edit", .onclick = repolist_edit, .groups = UI_GROUPS(SETTINGS_STATE_REPOLIST_SELECTED)); |
62
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
654 | ui_button(obj, .label = "Remove", .onclick = repolist_remove, .groups = UI_GROUPS(SETTINGS_STATE_REPOLIST_SELECTED)); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
655 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
656 | ui_newline(obj); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
657 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
658 | UiModel* model = ui_model(obj->ctx, UI_STRING, "Name", UI_STRING, "URL", UI_STRING, "User", UI_STRING, "Encrypted", -1); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
659 | model->getvalue = (ui_getvaluefunc) settings_repolist_getvalue; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
660 | ui_table(obj, |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
661 | .model = model, |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
662 | .list = wdata->repos, |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
663 | .multiselection = FALSE, |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
664 | .onactivate = repolist_activate, |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
665 | .onselection = repolist_selection, |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
666 | .vexpand = TRUE, .hexpand = TRUE, .colspan = 3); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
667 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
668 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
669 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
670 | ui_tab(obj, "repo") { |
68 | 671 | ui_vbox(obj, .margin = 16, .spacing = 10) { |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
672 | ui_hbox(obj, .fill = UI_OFF, .spacing = 4) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
673 | ui_button(obj, .icon = UI_ICON_GO_BACK, .onclick = editrepo_go_back); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
674 | ui_label(obj, .label = "Repository List"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
675 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
676 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
677 | ui_scrolledwindow(obj, .hexpand = TRUE, .vexpand = TRUE, .subcontainer = UI_CONTAINER_NO_SUB) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
678 | ui_grid(obj, .margin = 10, .columnspacing = 10, .rowspacing = 10) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
679 | ui_llabel(obj, .label = "Name"); |
75
73c8a3780c72
toolkit update, small UI adjustments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
74
diff
changeset
|
680 | ui_textfield(obj, .value = wdata->repo_name, .width = 15); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
681 | ui_newline(obj); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
682 | ui_llabel(obj, .label = "URL"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
683 | ui_textfield(obj, .value = wdata->repo_url, .hexpand = TRUE); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
684 | ui_newline(obj); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
685 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
686 | ui_llabel(obj, .label = "Credentials", .style = UI_LABEL_STYLE_TITLE, .colspan = 2); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
687 | ui_newline(obj); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
688 | ui_hbox(obj, .spacing = 4, .colspan = 2) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
689 | ui_combobox(obj, .list = wdata->repo_credentials); |
75
73c8a3780c72
toolkit update, small UI adjustments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
74
diff
changeset
|
690 | ui_button(obj, .label = "New Credentials", .onclick = credentials_new); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
691 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
692 | ui_newline(obj); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
693 | ui_expander(obj, .spacing = 10, .colspan = 2, .label = "Unencrypted User/Password", .margin = 10) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
694 | ui_llabel(obj, .label = "Store the credentials unencrypted in the repository and not in the secret store", .style = UI_LABEL_STYLE_DIM); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
695 | ui_grid(obj, .rowspacing = 10, .columnspacing = 10, .fill = UI_OFF) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
696 | ui_llabel(obj, .label = "User"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
697 | ui_textfield(obj, .value = wdata->repo_user, .width = 15); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
698 | ui_newline(obj); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
699 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
700 | ui_llabel(obj, .label = "Password"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
701 | ui_passwordfield(obj, .value = wdata->repo_password, .width = 15); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
702 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
703 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
704 | ui_newline(obj); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
705 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
706 | ui_llabel(obj, .label = "Encryption", .style = UI_LABEL_STYLE_TITLE, .colspan = 2); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
707 | ui_newline(obj); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
708 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
709 | ui_checkbox(obj, .label = "Enable client-side encryption", .value = wdata->repo_encryption, .colspan = 2, .enable_group = SETTINGS_STATE_REPO_ENCRYPTION); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
710 | ui_newline(obj); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
711 | ui_llabel(obj, .label = "Default key"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
712 | ui_hbox(obj, .spacing = 4) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
713 | ui_combobox(obj, .list = wdata->repo_keys, .groups = UI_GROUPS(SETTINGS_STATE_REPO_ENCRYPTION)); |
73
ede7885491b1
implement repo Generate Key button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
714 | ui_button(obj, .label = "Generate Key", .onclick = keys_add, .onclickdata = "repo", .groups = UI_GROUPS(SETTINGS_STATE_REPO_ENCRYPTION)); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
715 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
716 | ui_newline(obj); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
717 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
718 | ui_llabel(obj, .label = "TLS", .style = UI_LABEL_STYLE_TITLE, .colspan = 2); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
719 | ui_newline(obj); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
720 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
721 | ui_llabel(obj, .label = "Cert Path"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
722 | ui_hbox0(obj) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
723 | ui_textfield(obj, .value = wdata->repo_cacert, .width = 15); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
724 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
725 | ui_newline(obj); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
726 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
727 | ui_llabel(obj, .label = "TLS Version"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
728 | ui_hbox0(obj) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
729 | ui_combobox(obj, .list = wdata->repo_tls_versions); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
730 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
731 | ui_newline(obj); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
732 | ui_checkbox(obj, .label = "Disable TLS verification", .value = wdata->repo_disable_verification, .colspan = 2); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
733 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
734 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
735 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
736 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
737 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
738 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
739 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
740 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
741 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
742 | ui_tab(obj, "Sync Directories") { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
743 | ui_grid(obj, .margin = 10) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
744 | ui_label(obj, .label = "TODO"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
745 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
746 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
747 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
748 | ui_tab(obj, "Credentials") { |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
749 | ui_hbox(obj, .margin = 16, .spacing = 30) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
750 | ui_vbox(obj, .fill = UI_OFF, .spacing = 4) { |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
751 | ui_hbox(obj, .fill = UI_OFF, .spacing = 4) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
752 | ui_button(obj, .label = "Add", .onclick = credentials_add); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
753 | ui_button(obj, .label = "Remove", .onclick = credentials_remove, .groups = UI_GROUPS(SETTINGS_STATE_CREDENTIALS_SELECTED)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
754 | } |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
755 | ui_listview(obj, .list = wdata->credentials_users, .fill = UI_ON, .onselection = credentials_onselect); |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
756 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
757 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
758 | ui_grid(obj, .columnspacing = 30, .rowspacing = 10) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
759 | ui_llabel(obj, .label = "Identifier"); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
760 | ui_textfield(obj, .value = wdata->credentials_id, .hexpand = TRUE, .groups = UI_GROUPS(SETTINGS_STATE_CREDENTIALS_SELECTED)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
761 | ui_newline(obj); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
762 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
763 | ui_llabel(obj, .label = "User"); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
764 | ui_textfield(obj, .value = wdata->credentials_user, .hexpand = TRUE, .groups = UI_GROUPS(SETTINGS_STATE_CREDENTIALS_SELECTED)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
765 | ui_newline(obj); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
766 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
767 | ui_llabel(obj, .label = "Password"); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
768 | ui_passwordfield(obj, .value = wdata->credentials_password, .hexpand = TRUE, .groups = UI_GROUPS(SETTINGS_STATE_CREDENTIALS_SELECTED)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
769 | ui_newline(obj); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
770 | |
76 | 771 | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
772 | ui_label(obj, .label = " "); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
773 | ui_newline(obj); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
774 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
775 | ui_llabel(obj, .style = UI_LABEL_STYLE_TITLE, .label = "Locations", .colspan = 2); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
776 | ui_newline(obj); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
777 | ui_llabel(obj, .style = UI_LABEL_STYLE_DIM, .label = "List of URLs for which these credentials should be used (optional)", .colspan = 2); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
778 | ui_newline(obj); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
779 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
780 | ui_hbox(obj, .colspan = 2, .vexpand = TRUE, .hexpand = TRUE, .spacing = 10) { |
76 | 781 | #ifndef UI_WINUI |
782 | ui_callback credentials_activate_callback = credentials_location_edit; | |
783 | #else | |
784 | ui_callback credentials_activate_callback = NULL; | |
785 | #endif | |
786 | ui_listview(obj, .list = wdata->credentials_locations, .onactivate = credentials_activate_callback, .onselection = credentials_location_onselect, .colspan = 2, .fill = UI_ON, .groups = UI_GROUPS(SETTINGS_STATE_CREDENTIALS_SELECTED)); | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
787 | ui_vbox(obj, .fill = UI_OFF, .spacing = 4) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
788 | ui_button(obj, .label = "Add", .onclick = credentials_location_add, .groups = UI_GROUPS(SETTINGS_STATE_CREDENTIALS_SELECTED)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
789 | ui_button(obj, .label = "Edit", .onclick = credentials_location_edit, .groups = UI_GROUPS(SETTINGS_STATE_CREDENTIALS_SELECTED, SETTINGS_STATE_CREDENTIALS_LOCATION_SELECTED)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
790 | ui_button(obj, .label = "Remove", .onclick = credentials_location_remove, .groups = UI_GROUPS(SETTINGS_STATE_CREDENTIALS_SELECTED, SETTINGS_STATE_CREDENTIALS_LOCATION_SELECTED)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
791 | ui_button(obj, .label = "Move Up", .onclick = credentials_location_up, .groups = UI_GROUPS(SETTINGS_STATE_CREDENTIALS_SELECTED, SETTINGS_STATE_CREDENTIALS_LOCATION_SELECTED)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
792 | ui_button(obj, .label = "Move Down", .onclick = credentials_location_down, .groups = UI_GROUPS(SETTINGS_STATE_CREDENTIALS_SELECTED, SETTINGS_STATE_CREDENTIALS_LOCATION_SELECTED)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
793 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
794 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
795 | } |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
796 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
797 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
798 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
799 | ui_tab(obj, "Keys") { |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
800 | ui_hbox(obj, .margin = 16, .spacing = 30) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
801 | ui_vbox(obj, .fill = UI_OFF, .spacing = 4) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
802 | ui_hbox(obj, .fill = UI_OFF, .spacing = 4) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
803 | ui_button(obj, .label = "Add", .onclick = keys_add); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
804 | ui_button(obj, .label = "Remove", .onclick = keys_remove, .groups = UI_GROUPS(SETTINGS_STATE_KEYS_SELECTED)); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
805 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
806 | ui_listview(obj, .list = wdata->keys_list, .fill = UI_ON, .onselection = keys_onselect, .getvalue = keylist_getvalue); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
807 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
808 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
809 | ui_grid(obj, .columnspacing = 30, .rowspacing = 10) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
810 | ui_llabel(obj, .label = "Identifier"); |
75
73c8a3780c72
toolkit update, small UI adjustments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
74
diff
changeset
|
811 | ui_textfield(obj, .value = wdata->key_name, .groups = UI_GROUPS(SETTINGS_STATE_KEYS_SELECTED)); |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
812 | ui_newline(obj); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
813 | ui_llabel(obj, .label = "Type"); |
75
73c8a3780c72
toolkit update, small UI adjustments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
74
diff
changeset
|
814 | ui_textfield(obj, .value = wdata->key_type, .groups = UI_GROUPS(SETTINGS_STATE_DISABLED)); |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
815 | ui_newline(obj); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
816 | ui_llabel(obj, .label = "File"); |
75
73c8a3780c72
toolkit update, small UI adjustments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
74
diff
changeset
|
817 | ui_textfield(obj, .value = wdata->key_file, .groups = UI_GROUPS(SETTINGS_STATE_KEYS_SELECTED)); |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
818 | } |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
819 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
820 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
821 | |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
822 | /* |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
823 | ui_tab(obj, "Properties") { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
824 | ui_grid(obj, .margin = 10) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
825 | ui_label(obj, .label = "TODO"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
826 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
827 | } |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
828 | */ |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
829 | } |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
830 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
831 | ui_hbox(obj, .fill = UI_OFF, .margin = 10) { |
61
eb63af2f2bdd
fix crash when closing the settings window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
832 | ui_button(obj, .label = "Cancel", .onclick = settings_cancel); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
833 | ui_label(obj, .fill = UI_ON); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
834 | ui_button(obj, .label = "Save", .onclick = settings_ok); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
835 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
836 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
837 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
838 | ui_show(obj); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
839 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
840 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
841 | void settings_init(UiObject *obj, SettingsWindow *settings) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
842 | settings->repos = ui_list_new(obj->ctx, NULL); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
843 | settings->repo_tabview = ui_int_new(obj->ctx, NULL); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
844 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
845 | settings->repo_name = ui_string_new(obj->ctx, NULL); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
846 | settings->repo_url = ui_string_new(obj->ctx, NULL); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
847 | settings->repo_user = ui_string_new(obj->ctx, NULL); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
848 | settings->repo_password = ui_string_new(obj->ctx, NULL); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
849 | settings->repo_cacert = ui_string_new(obj->ctx, NULL); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
850 | settings->repo_credentials = ui_list_new(obj->ctx, NULL); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
851 | settings->repo_keys = ui_list_new(obj->ctx, NULL); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
852 | settings->repo_tls_versions = ui_list_new(obj->ctx, NULL); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
853 | settings->repo_encryption = ui_int_new(obj->ctx, NULL); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
854 | settings->repo_disable_verification = ui_int_new(obj->ctx, NULL); |
73
ede7885491b1
implement repo Generate Key button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
855 | CxList *repo_keys = settings->repo_keys->data; |
ede7885491b1
implement repo Generate Key button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
856 | repo_keys->collection.cmpfunc = (cx_compare_func)strcmp; |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
857 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
858 | ui_list_append(settings->repo_tls_versions, "Default"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
859 | ui_list_append(settings->repo_tls_versions, "TLSv1.3"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
860 | ui_list_append(settings->repo_tls_versions, "TLSv1.2"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
861 | ui_list_append(settings->repo_tls_versions, "TLSv1.1"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
862 | ui_list_append(settings->repo_tls_versions, "TLSv1.0"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
863 | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
864 | settings->credentials_selected_index = -1; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
865 | settings->credentials_users = ui_list_new(obj->ctx, NULL); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
866 | settings->credentials_locations = ui_list_new(obj->ctx, NULL); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
867 | settings->credentials_id = ui_string_new(obj->ctx, NULL); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
868 | settings->credentials_user = ui_string_new(obj->ctx, NULL); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
869 | settings->credentials_password = ui_string_new(obj->ctx, NULL); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
870 | CxList *credentials_users = settings->credentials_users->data; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
871 | CxList *credentials_locations = settings->credentials_locations->data; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
872 | credentials_users->collection.advanced_destructor = list_str_destructor; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
873 | credentials_users->collection.destructor_data = settings->obj->ctx; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
874 | credentials_users->collection.cmpfunc = (cx_compare_func)strcmp; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
875 | credentials_locations->collection.advanced_destructor = list_str_destructor; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
876 | credentials_locations->collection.destructor_data = settings->obj->ctx; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
877 | credentials_locations->collection.cmpfunc = (cx_compare_func)strcmp; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
878 | |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
879 | settings->keys_list = ui_list_new(obj->ctx, NULL); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
880 | settings->key_name = ui_string_new(obj->ctx, NULL); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
881 | settings->key_type = ui_string_new(obj->ctx, NULL); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
882 | settings->key_file = ui_string_new(obj->ctx, NULL); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
883 | settings->keys_selected_index = -1; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
884 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
885 | // load some list values, that can be reused |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
886 | settings_update_repolist(settings); |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
887 | settings_reload_repo_keys(settings); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
888 | settings_reload_credentials(settings); |
66
eee1f3092844
fix missing settings_reload_repo_credentials call
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
889 | settings_reload_repo_credentials(settings); |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
890 | settings_reload_keys(settings); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
891 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
892 | settings->selected_repo = -1; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
893 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
894 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
895 | #define SETTINGS_SET_STRING(str, setting) if(setting.value.ptr) ui_set(str, setting.value.ptr); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
896 | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
897 | /* ----------------------------- Repository ----------------------------- */ |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
898 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
899 | void settings_edit_repository(SettingsWindow *settings, int repo_index) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
900 | DavCfgRepository *repo = ui_list_get(settings->repos, repo_index); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
901 | if(!repo) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
902 | fprintf(stderr, "Error: cannot get repository at index %d\n", repo_index); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
903 | return; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
904 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
905 | settings->selected_repo = repo_index; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
906 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
907 | // load plain string values |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
908 | SETTINGS_SET_STRING(settings->repo_name, repo->name); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
909 | SETTINGS_SET_STRING(settings->repo_url, repo->url); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
910 | SETTINGS_SET_STRING(settings->repo_cacert, repo->cert); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
911 | SETTINGS_SET_STRING(settings->repo_user, repo->user); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
912 | // load decrypted password |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
913 | if(repo->password.value.ptr) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
914 | char *decoded_pw = util_base64decode(repo->password.value.ptr); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
915 | ui_set(settings->repo_password, decoded_pw); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
916 | size_t decoded_pw_len = strlen(decoded_pw); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
917 | memset(decoded_pw, 0, decoded_pw_len); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
918 | free(decoded_pw); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
919 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
920 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
921 | // select credentials dropdown value |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
922 | CxList *cred = settings->repo_credentials->data; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
923 | cred->collection.cmpfunc = (cx_compare_func)strcmp; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
924 | ssize_t cred_index = repo->stored_user.value.ptr ? cxListFind(cred, repo->stored_user.value.ptr) : 0; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
925 | if(cred_index > 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
926 | ui_list_setselection(settings->repo_credentials, cred_index); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
927 | } else { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
928 | ui_list_setselection(settings->repo_credentials, 0); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
929 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
930 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
931 | // load encryption value and default key value |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
932 | ui_set(settings->repo_encryption, repo->full_encryption.value); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
933 | CxList *keys = settings->repo_keys->data; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
934 | keys->collection.cmpfunc = (cx_compare_func)strcmp; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
935 | ssize_t key_index = repo->default_key.value.ptr ? cxListFind(keys, repo->default_key.value.ptr) : 0; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
936 | if(key_index > 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
937 | ui_list_setselection(settings->repo_keys, key_index); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
938 | } else { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
939 | ui_list_setselection(settings->repo_keys, 0); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
940 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
941 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
942 | // select tls version from dropdown menu |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
943 | CxList *tlsVersions = settings->repo_tls_versions->data; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
944 | tlsVersions->collection.cmpfunc = (cx_compare_func)strcmp; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
945 | const char *tls_str = dav_tlsversion2str(repo->ssl_version.value); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
946 | if(!tls_str) tls_str = ""; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
947 | ssize_t tlsv_index = cxListFind(tlsVersions, tls_str); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
948 | if(tlsv_index > 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
949 | ui_list_setselection(settings->repo_tls_versions, tlsv_index); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
950 | } else { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
951 | ui_list_setselection(settings->repo_tls_versions, 0); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
952 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
953 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
954 | if(!repo->verification.value) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
955 | ui_set(settings->repo_disable_verification, TRUE); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
956 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
957 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
958 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
959 | // switch to editing tab |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
960 | ui_set(settings->repo_tabview, 1); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
961 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
962 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
963 | /* |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
964 | * sets a config value |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
965 | * if new_value is null, the xml node is removed |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
966 | */ |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
967 | static void cfg_string_set_value_or_remove(DavConfig *config, CfgString *str, xmlNode *parent, cxstring new_value, const char *nodename) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
968 | if(new_value.length == 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
969 | new_value.ptr = NULL; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
970 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
971 | dav_cfg_string_set_value(config, str, parent, new_value, nodename); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
972 | if(!new_value.ptr) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
973 | dav_cfg_string_remove(str); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
974 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
975 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
976 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
977 | /* |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
978 | * return the selected list value, if it is not the default value at index 0 |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
979 | */ |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
980 | static cxstring default_list_get_value(UiList *list) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
981 | cxstring ret = { NULL, 0 }; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
982 | UiListSelection sel = ui_list_getselection(list); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
983 | if(sel.count > 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
984 | int index = sel.rows[0]; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
985 | if(index > 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
986 | ret = cx_str(ui_list_get(list, index)); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
987 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
988 | free(sel.rows); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
989 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
990 | return ret; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
991 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
992 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
993 | void settings_store_repository(SettingsWindow *settings) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
994 | DavConfig *config = settings->config; |
62
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
995 | DavCfgRepository *repo; |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
996 | if(settings->repo_new) { |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
997 | settings->repo_new = FALSE; |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
998 | char *name = ui_get(settings->repo_name); |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
999 | if(strlen(name) == 0) { |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1000 | return; |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1001 | } |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1002 | repo = dav_repository_new(config); |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1003 | dav_config_add_repository(config, repo); |
63
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1004 | } else if(settings->selected_repo >= 0) { |
62
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1005 | repo = ui_list_get(settings->repos, settings->selected_repo); |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1006 | if(!repo) { |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1007 | fprintf(stderr, "Error: cannot get repository at index %d\n", settings->selected_repo); |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1008 | return; |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1009 | } |
63
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1010 | } else { |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1011 | return; |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1012 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1013 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1014 | // always store name/url nodes |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1015 | dav_cfg_string_set_value(config, &repo->name, repo->node, cx_str(ui_get(settings->repo_name)), "name"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1016 | dav_cfg_string_set_value(config, &repo->url, repo->node, cx_str(ui_get(settings->repo_url)), "url"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1017 | // store user of remove node, if no user is configured |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1018 | cfg_string_set_value_or_remove(config, &repo->user, repo->node, cx_str(ui_get(settings->repo_user)), "user"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1019 | // store cert or remove node |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1020 | cfg_string_set_value_or_remove(config, &repo->cert, repo->node, cx_str(ui_get(settings->repo_cacert)), "cert"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1021 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1022 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1023 | // store password or remove node, if no password is configured |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1024 | char *pw = ui_get(settings->repo_password); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1025 | size_t pwlen = strlen(pw); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1026 | if(pwlen > 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1027 | char *pwenc = util_base64encode(pw, pwlen); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1028 | memset(pw, 0, pwlen); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1029 | dav_cfg_string_set_value(config, &repo->password, repo->node, cx_str(pwenc), "password"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1030 | free(pwenc); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1031 | } else { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1032 | // set password 0 NULL and remove password config node |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1033 | cfg_string_set_value_or_remove(config, &repo->password, repo->node, cx_strn(NULL, 0), "password"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1034 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1035 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1036 | // get the selected credentials and set "stored-user" |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1037 | // remove node if not needed |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1038 | cxstring stored_user = default_list_get_value(settings->repo_credentials); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1039 | cfg_string_set_value_or_remove(config, &repo->stored_user, repo->node, stored_user, "stored-user"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1040 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1041 | // adjust full-encryption node if necessary |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1042 | int encryption = ui_get(settings->repo_encryption); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1043 | if(encryption || repo->full_encryption.node) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1044 | dav_cfg_bool_set_value(config, &repo->full_encryption, repo->node, encryption, "full-encryption"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1045 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1046 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1047 | // set default-key |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1048 | cxstring key = default_list_get_value(settings->repo_keys); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1049 | cfg_string_set_value_or_remove(config, &repo->default_key, repo->node, key, "default-key"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1050 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1051 | // if disable_verification is enabled, set repo verification to false |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1052 | // otherwise remove the node, because verification is enabled by default |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1053 | int disable_verification = ui_get(settings->repo_disable_verification); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1054 | if(disable_verification) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1055 | dav_cfg_bool_set_value(config, &repo->verification, repo->node, !disable_verification, "verification"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1056 | } else { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1057 | dav_cfg_bool_remove(&repo->verification); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1058 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1059 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1060 | // set tls version if configured |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1061 | cxstring tlsversion_str = default_list_get_value(settings->repo_tls_versions); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1062 | int tlsversion = dav_str2ssl_version(tlsversion_str.ptr); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1063 | if(tlsversion >= 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1064 | dav_cfg_int_set_value(config, &repo->ssl_version, repo->node, tlsversion, "ssl-version"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1065 | } else { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1066 | dav_cfg_int_remove(&repo->ssl_version); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1067 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1068 | |
62
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1069 | settings_update_repolist(settings); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1070 | settings->selected_repo = -1; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1071 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1072 | |
63
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1073 | void settings_clear_repository(SettingsWindow *settings) { |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1074 | ui_set(settings->repo_name, ""); |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1075 | ui_set(settings->repo_url, ""); |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1076 | ui_set(settings->repo_user, ""); |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1077 | ui_set(settings->repo_password, ""); |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1078 | ui_set(settings->repo_cacert, ""); |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1079 | ui_list_setselection(settings->repo_credentials, 0); |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1080 | ui_list_setselection(settings->repo_keys, 0); |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1081 | ui_list_setselection(settings->repo_tls_versions, 0); |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1082 | ui_set(settings->repo_encryption, 0); |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1083 | ui_set(settings->repo_disable_verification, 0); |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1084 | } |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1085 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1086 | void settings_update_repolist(SettingsWindow *settings) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1087 | DavConfig *config = settings->config; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1088 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1089 | ui_list_clear(settings->repos); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1090 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1091 | for (DavCfgRepository *repo = config->repositories; repo; repo = repo->next) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1092 | ui_list_append(settings->repos, repo); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1093 | } |
62
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1094 | |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1095 | if(settings->repos->update) { |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1096 | ui_list_update(settings->repos); |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1097 | } |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1098 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1099 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1100 | void* settings_repolist_getvalue(DavCfgRepository *repo, int col) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1101 | switch(col) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1102 | case 0: { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1103 | return repo->name.value.ptr; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1104 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1105 | case 1: { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1106 | return repo->url.value.ptr; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1107 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1108 | case 2: { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1109 | return repo->user.value.ptr; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1110 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1111 | case 3: { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1112 | return repo->full_encryption.value ? "yes" : "no"; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1113 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1114 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1115 | return NULL; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1116 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1117 | |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1118 | void settings_reload_repo_keys(SettingsWindow *settings) { |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1119 | DavConfig *config = settings->config; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1120 | DavCfgKey *key = config->keys; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1121 | ui_list_clear(settings->repo_keys); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1122 | ui_list_append(settings->repo_keys, "-"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1123 | while(key) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1124 | if(key->name.value.ptr) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1125 | ui_list_append(settings->repo_keys, key->name.value.ptr); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1126 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1127 | key = key->next; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1128 | } |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1129 | ui_list_update(settings->repo_keys); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1130 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1131 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1132 | void settings_reload_keys(SettingsWindow *settings) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1133 | DavConfig *config = settings->config; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1134 | DavCfgKey *key = config->keys; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1135 | ui_list_clear(settings->keys_list); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1136 | while(key) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1137 | if(key->name.value.ptr) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1138 | ui_list_append(settings->keys_list, key); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1139 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1140 | key = key->next; |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1141 | } |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1142 | ui_list_update(settings->keys_list); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1143 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1144 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1145 | const char* dav_tlsversion2str(int value) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1146 | if(value == CURL_SSLVERSION_TLSv1) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1147 | return "TLSv1"; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1148 | } else if(value == CURL_SSLVERSION_SSLv2) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1149 | return "SSLv2"; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1150 | } else if(value == CURL_SSLVERSION_SSLv3) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1151 | return "SSLv3"; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1152 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1153 | #if LIBCURL_VERSION_MAJOR * 1000 + LIBCURL_VERSION_MINOR >= 7034 |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1154 | else if(value == CURL_SSLVERSION_TLSv1_0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1155 | return "TLSv1.0"; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1156 | } else if(value == CURL_SSLVERSION_TLSv1_1) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1157 | return "TLSv1.1"; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1158 | } else if(value == CURL_SSLVERSION_TLSv1_2) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1159 | return "TLSv1.2"; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1160 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1161 | #endif |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1162 | #if LIBCURL_VERSION_MAJOR * 1000 + LIBCURL_VERSION_MINOR >= 7052 |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1163 | else if(value == CURL_SSLVERSION_TLSv1_3) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1164 | return "TLSv1.3"; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1165 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1166 | #endif |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1167 | return NULL; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1168 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1169 | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1170 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1171 | /* ----------------------------- Credentials ----------------------------- */ |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1172 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1173 | void settings_reload_credentials(SettingsWindow *settings) { |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1174 | PwdStore *pwd = settings->pwdstore; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1175 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1176 | ui_list_clear(settings->credentials_users); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1177 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1178 | CxIterator i = cxListIterator(pwd->noloc); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1179 | cx_foreach(PwdIndexEntry*, entry, i) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1180 | char *id = ui_strdup(settings->obj->ctx, entry->id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1181 | ui_list_append(settings->credentials_users, id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1182 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1183 | i = cxListIterator(pwd->locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1184 | cx_foreach(PwdIndexEntry*, entry, i) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1185 | char *id = ui_strdup(settings->obj->ctx, entry->id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1186 | ui_list_append(settings->credentials_users, id); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1187 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1188 | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1189 | ui_list_update(settings->credentials_users); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1190 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1191 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1192 | void settings_reload_repo_credentials(SettingsWindow *settings) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1193 | PwdStore *pwd = settings->pwdstore; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1194 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1195 | ui_list_clear(settings->repo_credentials); |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1196 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1197 | // repo_credentials needs an entry for selecting no credentials |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1198 | ui_list_append(settings->repo_credentials, "-"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1199 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1200 | CxIterator i = cxListIterator(pwd->noloc); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1201 | cx_foreach(PwdIndexEntry*, entry, i) { |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1202 | char *id = ui_strdup(settings->obj->ctx, entry->id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1203 | ui_list_append(settings->repo_credentials, id); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1204 | } |
64
98d0e2516f4e
fix missing credentials in repository settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
1205 | i = cxListIterator(pwd->locations); |
98d0e2516f4e
fix missing credentials in repository settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
1206 | cx_foreach(PwdIndexEntry*, entry, i) { |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1207 | char *id = ui_strdup(settings->obj->ctx, entry->id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1208 | ui_list_append(settings->repo_credentials, id); |
64
98d0e2516f4e
fix missing credentials in repository settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
1209 | } |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1210 | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1211 | ui_list_update(settings->repo_credentials); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1212 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1213 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1214 | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1215 | void settings_credentials_select(SettingsWindow *settings, const char *id) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1216 | if(!id && !settings->credentials_selected_id && !settings->credentials_new) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1217 | fprintf(stderr, "Error: no credentials id selected\n"); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1218 | return; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1219 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1220 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1221 | PwdStore *pwd = settings->pwdstore; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1222 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1223 | if(id) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1224 | ui_free(settings->obj->ctx, settings->credentials_selected_id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1225 | settings->credentials_selected_id = ui_strdup(settings->obj->ctx, id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1226 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1227 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1228 | if(!pwd->isdecrypted) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1229 | settings_credentials_decrypt(settings); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1230 | return; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1231 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1232 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1233 | if(settings->credentials_new) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1234 | ui_free(settings->obj->ctx, settings->credentials_selected_id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1235 | settings->credentials_selected_id = NULL; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1236 | settings->credentials_selected_index = ui_list_count(settings->credentials_users); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1237 | ui_list_append(settings->credentials_users, ui_strdup(settings->obj->ctx, "new")); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1238 | settings->credentials_ignore_selectionevent = TRUE; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1239 | ui_list_update(settings->credentials_users); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1240 | ui_list_setselection(settings->credentials_users, settings->credentials_selected_index); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1241 | settings->credentials_ignore_selectionevent = FALSE; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1242 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1243 | ui_set(settings->credentials_id, "new"); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1244 | ui_set(settings->credentials_user, ""); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1245 | ui_set(settings->credentials_password, ""); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1246 | ui_list_clear(settings->credentials_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1247 | ui_list_update(settings->credentials_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1248 | } else { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1249 | PwdEntry *entry = cxMapGet(pwd->ids, settings->credentials_selected_id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1250 | PwdIndexEntry *index = cxMapGet(pwd->index, settings->credentials_selected_id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1251 | if(!entry) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1252 | fprintf(stderr, "Error: cannot get pwd entry %s\n", settings->credentials_selected_id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1253 | return; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1254 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1255 | if(!index) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1256 | fprintf(stderr, "Error: missing PwdIndexEntry. PwdStore may be broken.\n"); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1257 | return; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1258 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1259 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1260 | ui_set(settings->credentials_id, entry->id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1261 | ui_set(settings->credentials_user, entry->user); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1262 | ui_set(settings->credentials_password, entry->password); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1263 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1264 | ui_list_clear(settings->credentials_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1265 | if(index->locations) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1266 | CxIterator i = cxListIterator(index->locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1267 | cx_foreach(char *, loc, i) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1268 | ui_list_append(settings->credentials_locations, ui_strdup(settings->obj->ctx, loc)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1269 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1270 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1271 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1272 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1273 | ui_list_update(settings->credentials_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1274 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1275 | ui_set_group(settings->obj->ctx, SETTINGS_STATE_CREDENTIALS_SELECTED); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1276 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1277 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1278 | void settings_credentials_clear(SettingsWindow *settings) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1279 | ui_free(settings->obj->ctx, settings->credentials_selected_id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1280 | settings->credentials_selected_id = NULL; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1281 | settings->credentials_new = FALSE; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1282 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1283 | ui_set(settings->credentials_id, ""); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1284 | ui_set(settings->credentials_user, ""); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1285 | ui_set(settings->credentials_password, ""); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1286 | ui_list_clear(settings->credentials_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1287 | ui_list_update(settings->credentials_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1288 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1289 | ui_unset_group(settings->obj->ctx, SETTINGS_STATE_CREDENTIALS_SELECTED); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1290 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1291 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1292 | int settings_credentials_save(SettingsWindow *settings) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1293 | if(settings->credentials_selected_index == -1) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1294 | return 0; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1295 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1296 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1297 | // check if the credentials list contains an element with the same id |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1298 | // if an index is found, it must match the selected index, otherwise |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1299 | // we have a duplicate identifier |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1300 | char *newid = ui_get(settings->credentials_id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1301 | if(strlen(newid) == 0) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1302 | return 0; // TODO: check if other fields are set |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1303 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1304 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1305 | ssize_t index = cxListFind(settings->credentials_users->data, newid); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1306 | if(index >=0 && index != settings->credentials_selected_index) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1307 | cxmutstr s = cx_asprintf("Identifier %s already in use", newid); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1308 | ui_dialog(settings->obj, .title = "Error", .content = s.ptr, .closebutton_label = "OK"); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1309 | free(s.ptr); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1310 | return 1; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1311 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1312 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1313 | char *user = ui_get(settings->credentials_user); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1314 | char *password = ui_get(settings->credentials_password); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1315 | CxList *ui_locations = settings->credentials_locations->data; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1316 | size_t numlocations = cxListSize(ui_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1317 | CxList *locations = NULL; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1318 | if(numlocations > 0) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1319 | locations = cxArrayListCreateSimple(CX_STORE_POINTERS, numlocations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1320 | CxIterator i = cxListIterator(ui_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1321 | cx_foreach(char*, loc, i) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1322 | cxListAdd(locations, strdup(loc)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1323 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1324 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1325 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1326 | // if the user id changed, mark the list as changed to update it later |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1327 | settings->credentials_list_needs_update = settings->credentials_new || strcmp(newid, settings->credentials_selected_id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1328 | if(settings->credentials_new || strcmp(newid, settings->credentials_selected_id ? settings->credentials_selected_id : "")) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1329 | settings->credentials_list_needs_update = TRUE; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1330 | cxListRemove(settings->credentials_users->data, settings->credentials_selected_index); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1331 | cxListInsert(settings->credentials_users->data, settings->credentials_selected_index, ui_strdup(settings->obj->ctx, newid)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1332 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1333 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1334 | // if the pwdstore already contains this id, remove it first |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1335 | if(settings->credentials_selected_id) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1336 | pwdstore_remove_entry(settings->pwdstore, settings->credentials_selected_id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1337 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1338 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1339 | pwdstore_put(settings->pwdstore, newid, user, password); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1340 | pwdstore_put_index(settings->pwdstore, strdup(newid), locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1341 | settings->credentials_modified = TRUE; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1342 | settings->credentials_new = FALSE; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1343 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1344 | return 0; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1345 | } |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1346 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1347 | void *keylist_getvalue(void *data, int col) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1348 | DavCfgKey *key = data; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1349 | return key->name.value.ptr; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1350 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1351 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1352 | void settings_edit_key(SettingsWindow *settings, DavCfgKey *key) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1353 | if(key->name.value.ptr) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1354 | ui_set(settings->key_name, key->name.value.ptr); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1355 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1356 | const char *key_type; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1357 | switch(key->type) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1358 | default: key_type = ""; break; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1359 | case DAV_KEY_TYPE_AES256: { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1360 | key_type = "AES256"; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1361 | break; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1362 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1363 | case DAV_KEY_TYPE_AES128: { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1364 | key_type = "AES128"; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1365 | break; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1366 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1367 | case DAV_KEY_TYPE_UNKNOWN: { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1368 | key_type = "unknown"; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1369 | break; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1370 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1371 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1372 | ui_set(settings->key_type, key_type); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1373 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1374 | if(key->file.value.ptr) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1375 | ui_set(settings->key_file, key->file.value.ptr); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1376 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1377 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1378 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1379 | void settings_clear_key(SettingsWindow *settings) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1380 | ui_set(settings->key_name, ""); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1381 | ui_set(settings->key_type, ""); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1382 | ui_set(settings->key_file, ""); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1383 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1384 | |
92
43aee6c8c166
add encryption and lock indicator, resolves #501
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
1385 | |
43aee6c8c166
add encryption and lock indicator, resolves #501
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
1386 | |
43aee6c8c166
add encryption and lock indicator, resolves #501
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
1387 | |
43aee6c8c166
add encryption and lock indicator, resolves #501
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
1388 | const char* settings_get_cryptoflag(UiBool encrypted) { |
93
5ee236155955
use repo encryption and SSL settings, resolves #516
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
1389 | return encrypted ? "c" : ""; |
92
43aee6c8c166
add encryption and lock indicator, resolves #501
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
1390 | } |
43aee6c8c166
add encryption and lock indicator, resolves #501
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
1391 | |
43aee6c8c166
add encryption and lock indicator, resolves #501
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
1392 | const char* settings_get_lockflag(UiBool locked) { |
43aee6c8c166
add encryption and lock indicator, resolves #501
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
1393 | return locked ? "L" : ""; |
43aee6c8c166
add encryption and lock indicator, resolves #501
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
1394 | } |
43aee6c8c166
add encryption and lock indicator, resolves #501
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
1395 | |
43aee6c8c166
add encryption and lock indicator, resolves #501
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
1396 | const char* settings_get_execflag(UiBool executable) { |
43aee6c8c166
add encryption and lock indicator, resolves #501
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
1397 | return ""; // executable flag disabled |
43aee6c8c166
add encryption and lock indicator, resolves #501
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
76
diff
changeset
|
1398 | } |