diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-11-21 14:35:32 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-11-21 14:35:32 +0200 |
commit | c58985ed3105ff7fc29fc0d53ba81ba55882e05e (patch) | |
tree | 0dd4e254645ce7478a8fc6e01d7f7fa1e51784e4 /src/ui | |
parent | 67f1a5b152ca90fd8346bd39957905edaf3fb1cc (diff) |
Site-specific Titan upload identity
The identity to be used for uploads is now in sitespec.ini, so it applies to an entire site root. This should match actual use cases better than having URL-specific identities.
Also fixed an issue with native menus. Replacing the items with new ones was not implemented.
IssueID #379
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/uploadwidget.c | 45 | ||||
-rw-r--r-- | src/ui/util.c | 50 | ||||
-rw-r--r-- | src/ui/util.h | 1 |
3 files changed, 65 insertions, 31 deletions
diff --git a/src/ui/uploadwidget.c b/src/ui/uploadwidget.c index 90df1958..bad00071 100644 --- a/src/ui/uploadwidget.c +++ b/src/ui/uploadwidget.c | |||
@@ -45,7 +45,7 @@ iDefineObjectConstruction(UploadWidget) | |||
45 | 45 | ||
46 | enum iUploadIdentity { | 46 | enum iUploadIdentity { |
47 | none_UploadIdentity, | 47 | none_UploadIdentity, |
48 | defaultForUrl_UploadIdentity, | 48 | defaultForSite_UploadIdentity, |
49 | dropdown_UploadIdentity, | 49 | dropdown_UploadIdentity, |
50 | }; | 50 | }; |
51 | 51 | ||
@@ -104,9 +104,16 @@ static void updateInputMaxHeight_UploadWidget_(iUploadWidget *d) { | |||
104 | (avail - inputPos.y) / lineHeight_Text(font_InputWidget(d->input)))); | 104 | (avail - inputPos.y) / lineHeight_Text(font_InputWidget(d->input)))); |
105 | } | 105 | } |
106 | 106 | ||
107 | static const iGmIdentity *titanIdentityForUrl_(const iString *url) { | ||
108 | return findIdentity_GmCerts( | ||
109 | certs_App(), | ||
110 | collect_Block(hexDecode_Rangecc(range_String(valueString_SiteSpec( | ||
111 | collectNewRange_String(urlRoot_String(url)), titanIdentity_SiteSpecKey))))); | ||
112 | } | ||
113 | |||
107 | static const iArray *makeIdentityItems_UploadWidget_(const iUploadWidget *d) { | 114 | static const iArray *makeIdentityItems_UploadWidget_(const iUploadWidget *d) { |
108 | iArray *items = collectNew_Array(sizeof(iMenuItem)); | 115 | iArray *items = collectNew_Array(sizeof(iMenuItem)); |
109 | const iGmIdentity *urlId = identityForUrl_GmCerts(certs_App(), &d->url); | 116 | const iGmIdentity *urlId = titanIdentityForUrl_(&d->url); |
110 | pushBack_Array(items, | 117 | pushBack_Array(items, |
111 | &(iMenuItem){ format_CStr("${dlg.upload.id.default} (%s)", | 118 | &(iMenuItem){ format_CStr("${dlg.upload.id.default} (%s)", |
112 | urlId ? cstr_String(name_GmIdentity(urlId)) | 119 | urlId ? cstr_String(name_GmIdentity(urlId)) |
@@ -147,7 +154,7 @@ void init_UploadWidget(iUploadWidget *d) { | |||
147 | d->request = NULL; | 154 | d->request = NULL; |
148 | init_String(&d->filePath); | 155 | init_String(&d->filePath); |
149 | d->fileSize = 0; | 156 | d->fileSize = 0; |
150 | d->idMode = defaultForUrl_UploadIdentity; | 157 | d->idMode = defaultForSite_UploadIdentity; |
151 | init_Block(&d->idFingerprint, 0); | 158 | init_Block(&d->idFingerprint, 0); |
152 | const iMenuItem actions[] = { | 159 | const iMenuItem actions[] = { |
153 | { "${upload.port}", 0, 0, "upload.setport" }, | 160 | { "${upload.port}", 0, 0, "upload.setport" }, |
@@ -289,16 +296,22 @@ void deinit_UploadWidget(iUploadWidget *d) { | |||
289 | 296 | ||
290 | static void remakeIdentityItems_UploadWidget_(iUploadWidget *d) { | 297 | static void remakeIdentityItems_UploadWidget_(iUploadWidget *d) { |
291 | iWidget *dropMenu = findChild_Widget(findChild_Widget(as_Widget(d), "upload.id"), "menu"); | 298 | iWidget *dropMenu = findChild_Widget(findChild_Widget(as_Widget(d), "upload.id"), "menu"); |
292 | releaseChildren_Widget(dropMenu); | ||
293 | const iArray *items = makeIdentityItems_UploadWidget_(d); | 299 | const iArray *items = makeIdentityItems_UploadWidget_(d); |
294 | makeMenuItems_Widget(dropMenu, constData_Array(items), size_Array(items)); | 300 | /* TODO: Make the following a utility method. */ |
301 | if (flags_Widget(dropMenu) & nativeMenu_WidgetFlag) { | ||
302 | setNativeMenuItems_Widget(dropMenu, constData_Array(items), size_Array(items)); | ||
303 | } | ||
304 | else { | ||
305 | releaseChildren_Widget(dropMenu); | ||
306 | makeMenuItems_Widget(dropMenu, constData_Array(items), size_Array(items)); | ||
307 | } | ||
295 | } | 308 | } |
296 | 309 | ||
297 | static void updateIdentityDropdown_UploadWidget_(iUploadWidget *d) { | 310 | static void updateIdentityDropdown_UploadWidget_(iUploadWidget *d) { |
298 | updateDropdownSelection_LabelWidget( | 311 | updateDropdownSelection_LabelWidget( |
299 | findChild_Widget(as_Widget(d), "upload.id"), | 312 | findChild_Widget(as_Widget(d), "upload.id"), |
300 | d->idMode == none_UploadIdentity ? " arg:0" | 313 | d->idMode == none_UploadIdentity ? " arg:0" |
301 | : d->idMode == defaultForUrl_UploadIdentity | 314 | : d->idMode == defaultForSite_UploadIdentity |
302 | ? " arg:1" | 315 | ? " arg:1" |
303 | : format_CStr(" fp:%s", cstrCollect_String(hexEncode_Block(&d->idFingerprint)))); | 316 | : format_CStr(" fp:%s", cstrCollect_String(hexEncode_Block(&d->idFingerprint)))); |
304 | } | 317 | } |
@@ -422,7 +435,7 @@ static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) { | |||
422 | } | 435 | } |
423 | else if (arg_Command(cmd)) { | 436 | else if (arg_Command(cmd)) { |
424 | clear_Block(&d->idFingerprint); | 437 | clear_Block(&d->idFingerprint); |
425 | d->idMode = defaultForUrl_UploadIdentity; | 438 | d->idMode = defaultForSite_UploadIdentity; |
426 | } | 439 | } |
427 | else { | 440 | else { |
428 | clear_Block(&d->idFingerprint); | 441 | clear_Block(&d->idFingerprint); |
@@ -452,19 +465,27 @@ static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) { | |||
452 | setSendProgressFunc_GmRequest(d->request, updateProgress_UploadWidget_); | 465 | setSendProgressFunc_GmRequest(d->request, updateProgress_UploadWidget_); |
453 | setUserData_Object(d->request, d); | 466 | setUserData_Object(d->request, d); |
454 | setUrl_GmRequest(d->request, &d->url); | 467 | setUrl_GmRequest(d->request, &d->url); |
468 | const iString *site = collectNewRange_String(urlRoot_String(&d->url)); | ||
455 | switch (d->idMode) { | 469 | switch (d->idMode) { |
456 | case defaultForUrl_UploadIdentity: | ||
457 | break; /* GmRequest handles it */ | ||
458 | case none_UploadIdentity: | 470 | case none_UploadIdentity: |
459 | setIdentity_GmRequest(d->request, NULL); | 471 | /* Ensure no identity will be used for this specific URL. */ |
460 | signOut_GmCerts(certs_App(), url_GmRequest(d->request)); | 472 | signOut_GmCerts(certs_App(), url_GmRequest(d->request)); |
473 | setValueString_SiteSpec(site, titanIdentity_SiteSpecKey, collectNew_String()); | ||
461 | break; | 474 | break; |
462 | case dropdown_UploadIdentity: { | 475 | case dropdown_UploadIdentity: { |
463 | iGmIdentity *ident = findIdentity_GmCerts(certs_App(), &d->idFingerprint); | 476 | iGmIdentity *ident = findIdentity_GmCerts(certs_App(), &d->idFingerprint); |
464 | setIdentity_GmRequest(d->request, ident); | 477 | if (ident) { |
465 | signIn_GmCerts(certs_App(), ident, url_GmRequest(d->request)); | 478 | setValueString_SiteSpec(site, |
479 | titanIdentity_SiteSpecKey, | ||
480 | collect_String(hexEncode_Block(&ident->fingerprint))); | ||
481 | } | ||
466 | break; | 482 | break; |
467 | } | 483 | } |
484 | default: | ||
485 | break; | ||
486 | } | ||
487 | if (d->idMode != none_UploadIdentity) { | ||
488 | setIdentity_GmRequest(d->request, titanIdentityForUrl_(&d->url)); | ||
468 | } | 489 | } |
469 | if (isText) { | 490 | if (isText) { |
470 | /* Uploading text. */ | 491 | /* Uploading text. */ |
diff --git a/src/ui/util.c b/src/ui/util.c index 2624bf2b..0a9dde0c 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -809,14 +809,27 @@ static void deleteMenuItems_(iArray *items) { | |||
809 | delete_Array(items); | 809 | delete_Array(items); |
810 | } | 810 | } |
811 | 811 | ||
812 | iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) { | 812 | void releaseNativeMenu_Widget(iWidget *d) { |
813 | iWidget *menu = new_Widget(); | ||
814 | #if defined (iHaveNativeContextMenus) | 813 | #if defined (iHaveNativeContextMenus) |
815 | setFlags_Widget(menu, hidden_WidgetFlag | nativeMenu_WidgetFlag, iTrue); | 814 | iArray *items = userData_Object(d); |
815 | if (items) { | ||
816 | iAssert(flags_Widget(d) & nativeMenu_WidgetFlag); | ||
817 | iAssert(items); | ||
818 | deleteMenuItems_(items); | ||
819 | setUserData_Object(d, NULL); | ||
820 | } | ||
821 | #else | ||
822 | iUnused(d); | ||
823 | #endif | ||
824 | } | ||
825 | |||
826 | void setNativeMenuItems_Widget(iWidget *menu, const iMenuItem *items, size_t n) { | ||
827 | #if defined (iHaveNativeContextMenus) | ||
828 | iAssert(flags_Widget(menu) & nativeMenu_WidgetFlag); | ||
829 | releaseNativeMenu_Widget(menu); | ||
816 | setUserData_Object(menu, deepCopyMenuItems_(menu, items, n)); | 830 | setUserData_Object(menu, deepCopyMenuItems_(menu, items, n)); |
817 | addChild_Widget(parent, menu); | ||
818 | iRelease(menu); /* owned by parent now */ | ||
819 | /* Keyboard shortcuts still need to triggerable via the menu, although the items don't exist. */ { | 831 | /* Keyboard shortcuts still need to triggerable via the menu, although the items don't exist. */ { |
832 | releaseChildren_Widget(menu); | ||
820 | for (size_t i = 0; i < n; i++) { | 833 | for (size_t i = 0; i < n; i++) { |
821 | const iMenuItem *item = &items[i]; | 834 | const iMenuItem *item = &items[i]; |
822 | if (item->key) { | 835 | if (item->key) { |
@@ -824,6 +837,17 @@ iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) { | |||
824 | } | 837 | } |
825 | } | 838 | } |
826 | } | 839 | } |
840 | #endif | ||
841 | } | ||
842 | |||
843 | iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) { | ||
844 | iWidget *menu = new_Widget(); | ||
845 | #if defined (iHaveNativeContextMenus) | ||
846 | setFlags_Widget(menu, hidden_WidgetFlag | nativeMenu_WidgetFlag, iTrue); | ||
847 | addChild_Widget(parent, menu); | ||
848 | iRelease(menu); /* owned by parent now */ | ||
849 | setUserData_Object(menu, NULL); | ||
850 | setNativeMenuItems_Widget(menu, items, n); | ||
827 | #else | 851 | #else |
828 | /* Non-native custom popup menu. This may still be displayed inside a separate window. */ | 852 | /* Non-native custom popup menu. This may still be displayed inside a separate window. */ |
829 | setDrawBufferEnabled_Widget(menu, iTrue); | 853 | setDrawBufferEnabled_Widget(menu, iTrue); |
@@ -990,18 +1014,6 @@ iLocalDef iBool isUsingMenuPopupWindows_(void) { | |||
990 | #endif | 1014 | #endif |
991 | } | 1015 | } |
992 | 1016 | ||
993 | void releaseNativeMenu_Widget(iWidget *d) { | ||
994 | #if defined (iHaveNativeContextMenus) | ||
995 | iArray *items = userData_Object(d); | ||
996 | iAssert(flags_Widget(d) & nativeMenu_WidgetFlag); | ||
997 | iAssert(items); | ||
998 | deleteMenuItems_(items); | ||
999 | setUserData_Object(d, NULL); | ||
1000 | #else | ||
1001 | iUnused(d); | ||
1002 | #endif | ||
1003 | } | ||
1004 | |||
1005 | void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { | 1017 | void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { |
1006 | const iBool postCommands = (menuOpenFlags & postCommands_MenuOpenFlags) != 0; | 1018 | const iBool postCommands = (menuOpenFlags & postCommands_MenuOpenFlags) != 0; |
1007 | #if defined (iHaveNativeContextMenus) | 1019 | #if defined (iHaveNativeContextMenus) |
@@ -1263,8 +1275,8 @@ void updateDropdownSelection_LabelWidget(iLabelWidget *dropButton, const char *s | |||
1263 | iMenuItem *item = findNativeMenuItem_Widget(menu, selectedCommand); | 1275 | iMenuItem *item = findNativeMenuItem_Widget(menu, selectedCommand); |
1264 | if (item) { | 1276 | if (item) { |
1265 | setSelected_NativeMenuItem(item, iTrue); | 1277 | setSelected_NativeMenuItem(item, iTrue); |
1266 | updateText_LabelWidget(dropButton, | 1278 | updateText_LabelWidget( |
1267 | removeMenuItemLabelPrefixes_String(collectNewCStr_String(item->label))); | 1279 | dropButton, removeMenuItemLabelPrefixes_String(collectNewCStr_String(item->label))); |
1268 | } | 1280 | } |
1269 | return; | 1281 | return; |
1270 | } | 1282 | } |
diff --git a/src/ui/util.h b/src/ui/util.h index cf96dfe4..52b3a692 100644 --- a/src/ui/util.h +++ b/src/ui/util.h | |||
@@ -249,6 +249,7 @@ void setMenuItemDisabled_Widget (iWidget *menu, const char *comm | |||
249 | void setMenuItemDisabledByIndex_Widget(iWidget *menu, size_t index, iBool disable); | 249 | void setMenuItemDisabledByIndex_Widget(iWidget *menu, size_t index, iBool disable); |
250 | void setMenuItemLabel_Widget (iWidget *menu, const char *command, const char *newLabel); | 250 | void setMenuItemLabel_Widget (iWidget *menu, const char *command, const char *newLabel); |
251 | void setMenuItemLabelByIndex_Widget (iWidget *menu, size_t index, const char *newLabel); | 251 | void setMenuItemLabelByIndex_Widget (iWidget *menu, size_t index, const char *newLabel); |
252 | void setNativeMenuItems_Widget (iWidget *, const iMenuItem *items, size_t n); | ||
252 | 253 | ||
253 | int checkContextMenu_Widget (iWidget *, const SDL_Event *ev); /* see macro below */ | 254 | int checkContextMenu_Widget (iWidget *, const SDL_Event *ev); /* see macro below */ |
254 | 255 | ||