Sun, 10 Nov 2024 09:12:30 +0100
toolkit update, small UI adjustments
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 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
639 | ui_tabview(obj) { |
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 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
771 | ui_label(obj, .label = " "); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
772 | ui_newline(obj); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
773 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
774 | 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
|
775 | ui_newline(obj); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
776 | 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
|
777 | ui_newline(obj); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
778 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
779 | ui_hbox(obj, .colspan = 2, .vexpand = TRUE, .hexpand = TRUE, .spacing = 10) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
780 | ui_listview(obj, .list = wdata->credentials_locations, .onactivate = credentials_location_edit, .onselection = credentials_location_onselect, .colspan = 2, .fill = UI_ON, .groups = UI_GROUPS(SETTINGS_STATE_CREDENTIALS_SELECTED)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
781 | ui_vbox(obj, .fill = UI_OFF, .spacing = 4) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
782 | 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
|
783 | 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
|
784 | 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
|
785 | 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
|
786 | 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
|
787 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
788 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
789 | } |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
790 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
791 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
792 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
793 | ui_tab(obj, "Keys") { |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
794 | ui_hbox(obj, .margin = 16, .spacing = 30) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
795 | ui_vbox(obj, .fill = UI_OFF, .spacing = 4) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
796 | ui_hbox(obj, .fill = UI_OFF, .spacing = 4) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
797 | ui_button(obj, .label = "Add", .onclick = keys_add); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
798 | 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
|
799 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
800 | 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
|
801 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
802 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
803 | ui_grid(obj, .columnspacing = 30, .rowspacing = 10) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
804 | ui_llabel(obj, .label = "Identifier"); |
75
73c8a3780c72
toolkit update, small UI adjustments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
74
diff
changeset
|
805 | 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
|
806 | ui_newline(obj); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
807 | ui_llabel(obj, .label = "Type"); |
75
73c8a3780c72
toolkit update, small UI adjustments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
74
diff
changeset
|
808 | 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
|
809 | ui_newline(obj); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
810 | ui_llabel(obj, .label = "File"); |
75
73c8a3780c72
toolkit update, small UI adjustments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
74
diff
changeset
|
811 | 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
|
812 | } |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
813 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
814 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
815 | |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
816 | /* |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
817 | ui_tab(obj, "Properties") { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
818 | ui_grid(obj, .margin = 10) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
819 | ui_label(obj, .label = "TODO"); |
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 | } |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
824 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
825 | 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
|
826 | 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
|
827 | ui_label(obj, .fill = UI_ON); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
828 | 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
|
829 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
830 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
831 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
832 | ui_show(obj); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
833 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
834 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
835 | void settings_init(UiObject *obj, SettingsWindow *settings) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
836 | 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
|
837 | 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
|
838 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
839 | 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
|
840 | 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
|
841 | 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
|
842 | 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
|
843 | 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
|
844 | 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
|
845 | 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
|
846 | 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
|
847 | 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
|
848 | 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
|
849 | CxList *repo_keys = settings->repo_keys->data; |
ede7885491b1
implement repo Generate Key button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
850 | 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
|
851 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
852 | 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
|
853 | 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
|
854 | 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
|
855 | 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
|
856 | 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
|
857 | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
858 | settings->credentials_selected_index = -1; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
859 | 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
|
860 | 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
|
861 | 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
|
862 | 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
|
863 | 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
|
864 | CxList *credentials_users = settings->credentials_users->data; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
865 | CxList *credentials_locations = settings->credentials_locations->data; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
866 | credentials_users->collection.advanced_destructor = list_str_destructor; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
867 | credentials_users->collection.destructor_data = settings->obj->ctx; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
868 | credentials_users->collection.cmpfunc = (cx_compare_func)strcmp; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
869 | credentials_locations->collection.advanced_destructor = list_str_destructor; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
870 | credentials_locations->collection.destructor_data = settings->obj->ctx; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
871 | credentials_locations->collection.cmpfunc = (cx_compare_func)strcmp; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
872 | |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
873 | settings->keys_list = ui_list_new(obj->ctx, NULL); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
874 | settings->key_name = ui_string_new(obj->ctx, NULL); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
875 | settings->key_type = ui_string_new(obj->ctx, NULL); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
876 | settings->key_file = ui_string_new(obj->ctx, NULL); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
877 | settings->keys_selected_index = -1; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
878 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
879 | // 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
|
880 | settings_update_repolist(settings); |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
881 | settings_reload_repo_keys(settings); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
882 | settings_reload_credentials(settings); |
66
eee1f3092844
fix missing settings_reload_repo_credentials call
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
883 | settings_reload_repo_credentials(settings); |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
884 | settings_reload_keys(settings); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
885 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
886 | settings->selected_repo = -1; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
887 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
888 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
889 | #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
|
890 | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
891 | /* ----------------------------- Repository ----------------------------- */ |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
892 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
893 | 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
|
894 | 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
|
895 | if(!repo) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
896 | 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
|
897 | return; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
898 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
899 | settings->selected_repo = repo_index; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
900 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
901 | // load plain string values |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
902 | 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
|
903 | 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
|
904 | 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
|
905 | 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
|
906 | // load decrypted password |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
907 | if(repo->password.value.ptr) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
908 | 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
|
909 | ui_set(settings->repo_password, decoded_pw); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
910 | 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
|
911 | memset(decoded_pw, 0, decoded_pw_len); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
912 | free(decoded_pw); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
913 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
914 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
915 | // select credentials dropdown value |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
916 | CxList *cred = settings->repo_credentials->data; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
917 | cred->collection.cmpfunc = (cx_compare_func)strcmp; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
918 | 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
|
919 | if(cred_index > 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
920 | 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
|
921 | } else { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
922 | ui_list_setselection(settings->repo_credentials, 0); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
923 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
924 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
925 | // load encryption value and default key value |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
926 | 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
|
927 | CxList *keys = settings->repo_keys->data; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
928 | keys->collection.cmpfunc = (cx_compare_func)strcmp; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
929 | 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
|
930 | if(key_index > 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
931 | 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
|
932 | } else { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
933 | ui_list_setselection(settings->repo_keys, 0); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
934 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
935 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
936 | // select tls version from dropdown menu |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
937 | CxList *tlsVersions = settings->repo_tls_versions->data; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
938 | tlsVersions->collection.cmpfunc = (cx_compare_func)strcmp; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
939 | 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
|
940 | if(!tls_str) tls_str = ""; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
941 | 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
|
942 | if(tlsv_index > 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
943 | 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
|
944 | } else { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
945 | 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
|
946 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
947 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
948 | if(!repo->verification.value) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
949 | ui_set(settings->repo_disable_verification, TRUE); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
950 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
951 | |
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 | // switch to editing tab |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
954 | ui_set(settings->repo_tabview, 1); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
955 | } |
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 | * sets a config value |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
959 | * 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
|
960 | */ |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
961 | 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
|
962 | if(new_value.length == 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
963 | new_value.ptr = NULL; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
964 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
965 | 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
|
966 | if(!new_value.ptr) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
967 | dav_cfg_string_remove(str); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
968 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
969 | } |
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 | /* |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
972 | * 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
|
973 | */ |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
974 | 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
|
975 | cxstring ret = { NULL, 0 }; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
976 | UiListSelection sel = ui_list_getselection(list); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
977 | if(sel.count > 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
978 | int index = sel.rows[0]; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
979 | if(index > 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
980 | 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
|
981 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
982 | free(sel.rows); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
983 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
984 | return ret; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
985 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
986 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
987 | void settings_store_repository(SettingsWindow *settings) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
988 | DavConfig *config = settings->config; |
62
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
989 | DavCfgRepository *repo; |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
990 | if(settings->repo_new) { |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
991 | settings->repo_new = FALSE; |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
992 | char *name = ui_get(settings->repo_name); |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
993 | if(strlen(name) == 0) { |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
994 | return; |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
995 | } |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
996 | repo = dav_repository_new(config); |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
997 | 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
|
998 | } else if(settings->selected_repo >= 0) { |
62
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
999 | repo = ui_list_get(settings->repos, settings->selected_repo); |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1000 | if(!repo) { |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1001 | 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
|
1002 | return; |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1003 | } |
63
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1004 | } else { |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1005 | return; |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1006 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1007 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1008 | // always store name/url nodes |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1009 | 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
|
1010 | 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
|
1011 | // 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
|
1012 | 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
|
1013 | // store cert or remove node |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1014 | 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
|
1015 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1016 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1017 | // 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
|
1018 | char *pw = ui_get(settings->repo_password); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1019 | size_t pwlen = strlen(pw); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1020 | if(pwlen > 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1021 | char *pwenc = util_base64encode(pw, pwlen); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1022 | memset(pw, 0, pwlen); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1023 | 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
|
1024 | free(pwenc); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1025 | } else { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1026 | // 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
|
1027 | 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
|
1028 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1029 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1030 | // 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
|
1031 | // remove node if not needed |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1032 | 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
|
1033 | 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
|
1034 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1035 | // adjust full-encryption node if necessary |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1036 | int encryption = ui_get(settings->repo_encryption); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1037 | if(encryption || repo->full_encryption.node) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1038 | 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
|
1039 | } |
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 | // set default-key |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1042 | 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
|
1043 | 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
|
1044 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1045 | // 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
|
1046 | // 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
|
1047 | 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
|
1048 | if(disable_verification) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1049 | 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
|
1050 | } else { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1051 | dav_cfg_bool_remove(&repo->verification); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1052 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1053 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1054 | // set tls version if configured |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1055 | 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
|
1056 | 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
|
1057 | if(tlsversion >= 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1058 | 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
|
1059 | } else { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1060 | dav_cfg_int_remove(&repo->ssl_version); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1061 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1062 | |
62
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1063 | settings_update_repolist(settings); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1064 | settings->selected_repo = -1; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1065 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1066 | |
63
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1067 | void settings_clear_repository(SettingsWindow *settings) { |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1068 | ui_set(settings->repo_name, ""); |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1069 | ui_set(settings->repo_url, ""); |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1070 | ui_set(settings->repo_user, ""); |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1071 | ui_set(settings->repo_password, ""); |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1072 | ui_set(settings->repo_cacert, ""); |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1073 | 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
|
1074 | 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
|
1075 | 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
|
1076 | ui_set(settings->repo_encryption, 0); |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1077 | 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
|
1078 | } |
d0eeb2b98dae
repo add should clear the form first
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1079 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1080 | void settings_update_repolist(SettingsWindow *settings) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1081 | DavConfig *config = settings->config; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1082 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1083 | ui_list_clear(settings->repos); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1084 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1085 | 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
|
1086 | ui_list_append(settings->repos, repo); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1087 | } |
62
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1088 | |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1089 | if(settings->repos->update) { |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1090 | ui_list_update(settings->repos); |
dbde5e038ea9
implement repo add/remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1091 | } |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1092 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1093 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1094 | 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
|
1095 | switch(col) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1096 | case 0: { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1097 | return repo->name.value.ptr; |
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 | case 1: { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1100 | return repo->url.value.ptr; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1101 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1102 | case 2: { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1103 | return repo->user.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 3: { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1106 | return repo->full_encryption.value ? "yes" : "no"; |
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 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1109 | return NULL; |
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 | |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1112 | 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
|
1113 | DavConfig *config = settings->config; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1114 | DavCfgKey *key = config->keys; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1115 | ui_list_clear(settings->repo_keys); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1116 | ui_list_append(settings->repo_keys, "-"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1117 | while(key) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1118 | if(key->name.value.ptr) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1119 | 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
|
1120 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1121 | key = key->next; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1122 | } |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1123 | ui_list_update(settings->repo_keys); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1124 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1125 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1126 | void settings_reload_keys(SettingsWindow *settings) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1127 | DavConfig *config = settings->config; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1128 | DavCfgKey *key = config->keys; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1129 | ui_list_clear(settings->keys_list); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1130 | while(key) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1131 | if(key->name.value.ptr) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1132 | ui_list_append(settings->keys_list, key); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1133 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1134 | key = key->next; |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1135 | } |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1136 | ui_list_update(settings->keys_list); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1137 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1138 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1139 | const char* dav_tlsversion2str(int value) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1140 | if(value == CURL_SSLVERSION_TLSv1) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1141 | return "TLSv1"; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1142 | } else if(value == CURL_SSLVERSION_SSLv2) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1143 | return "SSLv2"; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1144 | } else if(value == CURL_SSLVERSION_SSLv3) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1145 | return "SSLv3"; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1146 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1147 | #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
|
1148 | else if(value == CURL_SSLVERSION_TLSv1_0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1149 | return "TLSv1.0"; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1150 | } else if(value == CURL_SSLVERSION_TLSv1_1) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1151 | return "TLSv1.1"; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1152 | } else if(value == CURL_SSLVERSION_TLSv1_2) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1153 | return "TLSv1.2"; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1154 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1155 | #endif |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1156 | #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
|
1157 | else if(value == CURL_SSLVERSION_TLSv1_3) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1158 | return "TLSv1.3"; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1159 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1160 | #endif |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1161 | return NULL; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1162 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1163 | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1164 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1165 | /* ----------------------------- Credentials ----------------------------- */ |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1166 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1167 | void settings_reload_credentials(SettingsWindow *settings) { |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1168 | PwdStore *pwd = settings->pwdstore; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1169 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1170 | ui_list_clear(settings->credentials_users); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1171 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1172 | CxIterator i = cxListIterator(pwd->noloc); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1173 | cx_foreach(PwdIndexEntry*, entry, i) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1174 | 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
|
1175 | ui_list_append(settings->credentials_users, id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1176 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1177 | i = cxListIterator(pwd->locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1178 | cx_foreach(PwdIndexEntry*, entry, i) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1179 | 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
|
1180 | 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
|
1181 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1182 | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1183 | ui_list_update(settings->credentials_users); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1184 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1185 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1186 | void settings_reload_repo_credentials(SettingsWindow *settings) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1187 | PwdStore *pwd = settings->pwdstore; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1188 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1189 | ui_list_clear(settings->repo_credentials); |
65
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 | // 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
|
1192 | ui_list_append(settings->repo_credentials, "-"); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1193 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1194 | CxIterator i = cxListIterator(pwd->noloc); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1195 | cx_foreach(PwdIndexEntry*, entry, i) { |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1196 | 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
|
1197 | 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
|
1198 | } |
64
98d0e2516f4e
fix missing credentials in repository settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
1199 | i = cxListIterator(pwd->locations); |
98d0e2516f4e
fix missing credentials in repository settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
1200 | cx_foreach(PwdIndexEntry*, entry, i) { |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1201 | 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
|
1202 | 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
|
1203 | } |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1204 | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1205 | ui_list_update(settings->repo_credentials); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1206 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1207 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1208 | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1209 | 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
|
1210 | 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
|
1211 | fprintf(stderr, "Error: no credentials id selected\n"); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1212 | return; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1213 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1214 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1215 | PwdStore *pwd = settings->pwdstore; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1216 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1217 | if(id) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1218 | 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
|
1219 | 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
|
1220 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1221 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1222 | if(!pwd->isdecrypted) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1223 | settings_credentials_decrypt(settings); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1224 | return; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1225 | } |
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 | if(settings->credentials_new) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1228 | 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
|
1229 | settings->credentials_selected_id = NULL; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1230 | 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
|
1231 | 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
|
1232 | settings->credentials_ignore_selectionevent = TRUE; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1233 | ui_list_update(settings->credentials_users); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1234 | 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
|
1235 | settings->credentials_ignore_selectionevent = FALSE; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1236 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1237 | ui_set(settings->credentials_id, "new"); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1238 | ui_set(settings->credentials_user, ""); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1239 | ui_set(settings->credentials_password, ""); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1240 | ui_list_clear(settings->credentials_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1241 | ui_list_update(settings->credentials_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1242 | } else { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1243 | 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
|
1244 | 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
|
1245 | if(!entry) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1246 | 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
|
1247 | return; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1248 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1249 | if(!index) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1250 | 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
|
1251 | return; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1252 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1253 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1254 | ui_set(settings->credentials_id, entry->id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1255 | ui_set(settings->credentials_user, entry->user); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1256 | ui_set(settings->credentials_password, entry->password); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1257 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1258 | ui_list_clear(settings->credentials_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1259 | if(index->locations) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1260 | CxIterator i = cxListIterator(index->locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1261 | cx_foreach(char *, loc, i) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1262 | 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
|
1263 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1264 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1265 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1266 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1267 | ui_list_update(settings->credentials_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1268 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1269 | 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
|
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 | void settings_credentials_clear(SettingsWindow *settings) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1273 | 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
|
1274 | settings->credentials_selected_id = NULL; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1275 | settings->credentials_new = FALSE; |
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 | ui_set(settings->credentials_id, ""); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1278 | ui_set(settings->credentials_user, ""); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1279 | ui_set(settings->credentials_password, ""); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1280 | ui_list_clear(settings->credentials_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1281 | ui_list_update(settings->credentials_locations); |
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_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
|
1284 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1285 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1286 | int settings_credentials_save(SettingsWindow *settings) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1287 | if(settings->credentials_selected_index == -1) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1288 | return 0; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1289 | } |
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 | // 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
|
1292 | // 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
|
1293 | // we have a duplicate identifier |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1294 | char *newid = ui_get(settings->credentials_id); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1295 | if(strlen(newid) == 0) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1296 | 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
|
1297 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1298 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1299 | 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
|
1300 | if(index >=0 && index != settings->credentials_selected_index) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1301 | 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
|
1302 | 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
|
1303 | free(s.ptr); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1304 | return 1; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1305 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1306 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1307 | char *user = ui_get(settings->credentials_user); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1308 | char *password = ui_get(settings->credentials_password); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1309 | CxList *ui_locations = settings->credentials_locations->data; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1310 | size_t numlocations = cxListSize(ui_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1311 | CxList *locations = NULL; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1312 | if(numlocations > 0) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1313 | locations = cxArrayListCreateSimple(CX_STORE_POINTERS, numlocations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1314 | CxIterator i = cxListIterator(ui_locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1315 | cx_foreach(char*, loc, i) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1316 | cxListAdd(locations, strdup(loc)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1317 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1318 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1319 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1320 | // 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
|
1321 | 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
|
1322 | 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
|
1323 | settings->credentials_list_needs_update = TRUE; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1324 | 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
|
1325 | 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
|
1326 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1327 | |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1328 | // 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
|
1329 | if(settings->credentials_selected_id) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1330 | 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
|
1331 | } |
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 | pwdstore_put(settings->pwdstore, newid, user, password); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1334 | pwdstore_put_index(settings->pwdstore, strdup(newid), locations); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1335 | settings->credentials_modified = TRUE; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1336 | settings->credentials_new = FALSE; |
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 | return 0; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1339 | } |
72
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1340 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1341 | void *keylist_getvalue(void *data, int col) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1342 | DavCfgKey *key = data; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1343 | return key->name.value.ptr; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1344 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1345 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1346 | void settings_edit_key(SettingsWindow *settings, DavCfgKey *key) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1347 | if(key->name.value.ptr) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1348 | ui_set(settings->key_name, key->name.value.ptr); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1349 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1350 | const char *key_type; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1351 | switch(key->type) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1352 | default: key_type = ""; break; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1353 | case DAV_KEY_TYPE_AES256: { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1354 | key_type = "AES256"; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1355 | break; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1356 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1357 | case DAV_KEY_TYPE_AES128: { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1358 | key_type = "AES128"; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1359 | break; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1360 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1361 | case DAV_KEY_TYPE_UNKNOWN: { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1362 | key_type = "unknown"; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1363 | break; |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1364 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1365 | } |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1366 | ui_set(settings->key_type, key_type); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1367 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1368 | if(key->file.value.ptr) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1369 | ui_set(settings->key_file, key->file.value.ptr); |
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 | |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1373 | void settings_clear_key(SettingsWindow *settings) { |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1374 | ui_set(settings->key_name, ""); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1375 | ui_set(settings->key_type, ""); |
d5307e9ee384
implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
68
diff
changeset
|
1376 | ui_set(settings->key_file, ""); |
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 |