diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-12-03 10:41:15 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-12-03 10:41:15 +0200 |
commit | ad86fbe2cffa2bea07d004782e711932c5c91a79 (patch) | |
tree | 5df37073ad27b9893c4f42673e02e39ceb0a1176 /src/ui | |
parent | 6e917280380316eba77b1dfa983daf488510e70f (diff) |
Improving identity use
The URL checks for determining which identity was in use were a bit too page-specific. Now the URL prefix usage is applied more consistently.
The identity toolbar menu is now more useful in that it allows both switching identities and stopping the use of the current identity.
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/certlistwidget.c | 13 | ||||
-rw-r--r-- | src/ui/documentwidget.c | 9 | ||||
-rw-r--r-- | src/ui/root.c | 78 | ||||
-rw-r--r-- | src/ui/sidebarwidget.c | 59 |
4 files changed, 89 insertions, 70 deletions
diff --git a/src/ui/certlistwidget.c b/src/ui/certlistwidget.c index c67203e3..7c140c19 100644 --- a/src/ui/certlistwidget.c +++ b/src/ui/certlistwidget.c | |||
@@ -113,7 +113,7 @@ static void updateContextMenu_CertListWidget_(iCertListWidget *d) { | |||
113 | iBool usedOnCurrentPage = iFalse; | 113 | iBool usedOnCurrentPage = iFalse; |
114 | iConstForEach(StringSet, i, ident->useUrls) { | 114 | iConstForEach(StringSet, i, ident->useUrls) { |
115 | const iString *url = i.value; | 115 | const iString *url = i.value; |
116 | usedOnCurrentPage |= equalCase_String(docUrl, url); | 116 | usedOnCurrentPage |= startsWithCase_String(docUrl, cstr_String(url)); |
117 | iRangecc urlStr = range_String(url); | 117 | iRangecc urlStr = range_String(url); |
118 | if (startsWith_Rangecc(urlStr, "gemini://")) { | 118 | if (startsWith_Rangecc(urlStr, "gemini://")) { |
119 | urlStr.start += 9; /* omit the default scheme */ | 119 | urlStr.start += 9; /* omit the default scheme */ |
@@ -128,6 +128,9 @@ static void updateContextMenu_CertListWidget_(iCertListWidget *d) { | |||
128 | if (!usedOnCurrentPage) { | 128 | if (!usedOnCurrentPage) { |
129 | remove_Array(items, 1); | 129 | remove_Array(items, 1); |
130 | } | 130 | } |
131 | else { | ||
132 | remove_Array(items, 0); | ||
133 | } | ||
131 | } | 134 | } |
132 | destroy_Widget(d->menu); | 135 | destroy_Widget(d->menu); |
133 | d->menu = makeMenu_Widget(as_Widget(d), data_Array(items), size_Array(items)); | 136 | d->menu = makeMenu_Widget(as_Widget(d), data_Array(items), size_Array(items)); |
@@ -166,8 +169,8 @@ static iBool processEvent_CertListWidget_(iCertListWidget *d, const SDL_Event *e | |||
166 | return iTrue; | 169 | return iTrue; |
167 | } | 170 | } |
168 | else if (isCommand_Widget(w, ev, "ident.use")) { | 171 | else if (isCommand_Widget(w, ev, "ident.use")) { |
169 | iGmIdentity * ident = menuIdentity_CertListWidget_(d); | 172 | iGmIdentity *ident = menuIdentity_CertListWidget_(d); |
170 | const iString *tabUrl = url_DocumentWidget(document_App()); | 173 | const iString *tabUrl = urlQueryStripped_String(url_DocumentWidget(document_App())); |
171 | if (ident) { | 174 | if (ident) { |
172 | if (argLabel_Command(cmd, "clear")) { | 175 | if (argLabel_Command(cmd, "clear")) { |
173 | clearUse_GmIdentity(ident); | 176 | clearUse_GmIdentity(ident); |
@@ -388,7 +391,6 @@ void init_CertListWidget(iCertListWidget *d) { | |||
388 | init_ListWidget(&d->list); | 391 | init_ListWidget(&d->list); |
389 | setId_Widget(w, "certlist"); | 392 | setId_Widget(w, "certlist"); |
390 | setBackgroundColor_Widget(w, none_ColorId); | 393 | setBackgroundColor_Widget(w, none_ColorId); |
391 | setItemHeight_ListWidget(&d->list, 3.5f * lineHeight_Text(default_FontId)); | ||
392 | d->itemFonts[0] = uiContent_FontId; | 394 | d->itemFonts[0] = uiContent_FontId; |
393 | d->itemFonts[1] = uiContentBold_FontId; | 395 | d->itemFonts[1] = uiContentBold_FontId; |
394 | #if defined (iPlatformMobile) | 396 | #if defined (iPlatformMobile) |
@@ -397,6 +399,7 @@ void init_CertListWidget(iCertListWidget *d) { | |||
397 | d->itemFonts[1] = uiLabelBigBold_FontId; | 399 | d->itemFonts[1] = uiLabelBigBold_FontId; |
398 | } | 400 | } |
399 | #endif | 401 | #endif |
402 | updateItemHeight_CertListWidget(d); | ||
400 | d->menu = NULL; | 403 | d->menu = NULL; |
401 | d->contextItem = NULL; | 404 | d->contextItem = NULL; |
402 | d->contextIndex = iInvalidPos; | 405 | d->contextIndex = iInvalidPos; |
@@ -443,7 +446,7 @@ iBool updateItems_CertListWidget(iCertListWidget *d) { | |||
443 | cstr_String(&ident->notes)); | 446 | cstr_String(&ident->notes)); |
444 | } | 447 | } |
445 | item->listItem.isSelected = isActive; | 448 | item->listItem.isSelected = isActive; |
446 | if (isUsedOnDomain_GmIdentity(ident, tabHost)) { | 449 | if (!isActive && isUsedOnDomain_GmIdentity(ident, tabHost)) { |
447 | item->indent = 1; /* will be highlighted */ | 450 | item->indent = 1; /* will be highlighted */ |
448 | } | 451 | } |
449 | addItem_ListWidget(&d->list, item); | 452 | addItem_ListWidget(&d->list, item); |
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 3fb8498b..95286566 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -1289,8 +1289,13 @@ static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode | |||
1289 | if (category_GmStatusCode(code) == categoryClientCertificate_GmStatus) { | 1289 | if (category_GmStatusCode(code) == categoryClientCertificate_GmStatus) { |
1290 | makeFooterButtons_DocumentWidget_( | 1290 | makeFooterButtons_DocumentWidget_( |
1291 | d, | 1291 | d, |
1292 | (iMenuItem[]){ { leftHalf_Icon " ${menu.show.identities}", '4', KMOD_PRIMARY, "sidebar.mode arg:3 show:1" }, | 1292 | (iMenuItem[]){ |
1293 | { person_Icon " ${menu.identity.new}", newIdentity_KeyShortcut, "ident.new" } }, | 1293 | { leftHalf_Icon " ${menu.show.identities}", |
1294 | '4', | ||
1295 | KMOD_PRIMARY, | ||
1296 | deviceType_App() == desktop_AppDeviceType ? "sidebar.mode arg:3 show:1" | ||
1297 | : "preferences idents:1" }, | ||
1298 | { person_Icon " ${menu.identity.new}", newIdentity_KeyShortcut, "ident.new" } }, | ||
1294 | 2); | 1299 | 2); |
1295 | } | 1300 | } |
1296 | /* Make a new document for the error page.*/ | 1301 | /* Make a new document for the error page.*/ |
diff --git a/src/ui/root.c b/src/ui/root.c index 5df4b36f..f722df94 100644 --- a/src/ui/root.c +++ b/src/ui/root.c | |||
@@ -344,41 +344,47 @@ static iBool handleRootCommands_(iWidget *root, const char *cmd) { | |||
344 | if (ident) { | 344 | if (ident) { |
345 | str = copy_String(name_GmIdentity(ident)); | 345 | str = copy_String(name_GmIdentity(ident)); |
346 | if (!isEmpty_String(&ident->notes)) { | 346 | if (!isEmpty_String(&ident->notes)) { |
347 | appendFormat_String(str, "\n%s%s", escape_Color(uiAnnotation_ColorId), | 347 | appendFormat_String(str, "\n\x1b[0m" uiHeading_ColorEscape "%s", cstr_String(&ident->notes)); |
348 | cstr_String(&ident->notes)); | ||
349 | } | 348 | } |
350 | } | 349 | } |
351 | pushBackN_Array( | 350 | pushBack_Array( |
352 | &items, | 351 | &items, |
353 | (iMenuItem[]){ { format_CStr("///" uiHeading_ColorEscape "%s", | 352 | &(iMenuItem){ format_CStr("```" uiHeading_ColorEscape "\x1b[1m%s", |
354 | str ? cstr_String(str) : "${menu.identity.notactive}") }, | 353 | str ? cstr_String(str) : "${menu.identity.notactive}") }); |
355 | { "---" } }, | 354 | if (ident && isUsedOn_GmIdentity(ident, docUrl)) { |
356 | 2); | 355 | pushBack_Array(&items, |
356 | &(iMenuItem){ close_Icon " ${ident.stopuse}", | ||
357 | 0, | ||
358 | 0, | ||
359 | format_CStr("ident.signout ident:%s url:%s", | ||
360 | cstr_String(fp), | ||
361 | cstr_String(docUrl)) }); | ||
362 | } | ||
363 | pushBack_Array(&items, &(iMenuItem){ "---" }); | ||
357 | delete_String(str); | 364 | delete_String(str); |
358 | /* Alternate identities. */ | 365 | /* Alternate identities. */ |
359 | if (ident) { | 366 | const iString *site = collectNewRange_String(urlRoot_String(docUrl)); |
360 | const iString *site = collectNewRange_String(urlRoot_String(docUrl)); | 367 | iBool haveAlts = iFalse; |
361 | iBool haveAlts = iFalse; | 368 | iConstForEach(StringArray, i, strings_SiteSpec(site, usedIdentities_SiteSpecKey)) { |
362 | iConstForEach(StringArray, i, strings_SiteSpec(site, usedIdentities_SiteSpecKey)) { | 369 | if (!fp || !equal_String(i.value, fp)) { |
363 | if (!equal_String(i.value, fp)) { | 370 | const iBlock *otherFp = collect_Block(hexDecode_Rangecc(range_String(i.value))); |
364 | const iBlock *otherFp = collect_Block(hexDecode_Rangecc(range_String(i.value))); | 371 | const iGmIdentity *other = findIdentity_GmCerts(certs_App(), otherFp); |
365 | const iGmIdentity *other = findIdentity_GmCerts(certs_App(), otherFp); | 372 | if (other && other != ident) { |
366 | if (other) { | 373 | pushBack_Array( |
367 | pushBack_Array( | 374 | &items, |
368 | &items, | 375 | &(iMenuItem){ |
369 | &(iMenuItem){ | 376 | format_CStr(translateCStr_Lang("\U0001f816 ${ident.switch}"), |
370 | format_CStr(translateCStr_Lang("\U0001f816 ${ident.switch}"), | 377 | format_CStr("\x1b[1m%s", |
371 | cstr_String(name_GmIdentity(other))), | 378 | cstr_String(name_GmIdentity(other)))), |
372 | 0, | 379 | 0, |
373 | 0, | 380 | 0, |
374 | format_CStr("ident.switch fp:%s", cstr_String(i.value)) }); | 381 | format_CStr("ident.switch fp:%s", cstr_String(i.value)) }); |
375 | haveAlts = iTrue; | 382 | haveAlts = iTrue; |
376 | } | ||
377 | } | 383 | } |
378 | } | 384 | } |
379 | if (haveAlts) { | 385 | } |
380 | pushBack_Array(&items, &(iMenuItem){ "---" }); | 386 | if (haveAlts) { |
381 | } | 387 | pushBack_Array(&items, &(iMenuItem){ "---" }); |
382 | } | 388 | } |
383 | iSidebarWidget *sidebar = findWidget_App("sidebar"); | 389 | iSidebarWidget *sidebar = findWidget_App("sidebar"); |
384 | pushBackN_Array( | 390 | pushBackN_Array( |
@@ -388,14 +394,14 @@ static iBool handleRootCommands_(iWidget *root, const char *cmd) { | |||
388 | { "${menu.identity.import}", SDLK_i, KMOD_PRIMARY | KMOD_SHIFT, "ident.import" }, | 394 | { "${menu.identity.import}", SDLK_i, KMOD_PRIMARY | KMOD_SHIFT, "ident.import" }, |
389 | { "---" } }, 3); | 395 | { "---" } }, 3); |
390 | if (deviceType_App() == desktop_AppDeviceType) { | 396 | if (deviceType_App() == desktop_AppDeviceType) { |
391 | pushBack_Array(&items, &(iMenuItem) | 397 | pushBack_Array(&items, |
392 | { isVisible_Widget(sidebar) && mode_SidebarWidget(sidebar) == identities_SidebarMode | 398 | &(iMenuItem){ isVisible_Widget(sidebar) && mode_SidebarWidget(sidebar) == |
393 | ? leftHalf_Icon " ${menu.hide.identities}" | 399 | identities_SidebarMode |
394 | : leftHalf_Icon " ${menu.show.identities}", | 400 | ? leftHalf_Icon " ${menu.hide.identities}" |
395 | 0, | 401 | : leftHalf_Icon " ${menu.show.identities}", |
396 | 0, | 402 | 0, |
397 | //deviceType_App() == phone_AppDeviceType ? "toolbar.showident" | 403 | 0, |
398 | "sidebar.mode arg:3 toggle:1" }); | 404 | "sidebar.mode arg:3 toggle:1" }); |
399 | } | 405 | } |
400 | else { | 406 | else { |
401 | pushBack_Array(&items, &(iMenuItem){ gear_Icon " ${menu.identities}", 0, 0, | 407 | pushBack_Array(&items, &(iMenuItem){ gear_Icon " ${menu.identities}", 0, 0, |
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index 9b94f4d9..13fc33b1 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c | |||
@@ -591,6 +591,9 @@ iBool setMode_SidebarWidget(iSidebarWidget *d, enum iSidebarMode mode) { | |||
591 | if (d->mode == mode) { | 591 | if (d->mode == mode) { |
592 | return iFalse; | 592 | return iFalse; |
593 | } | 593 | } |
594 | if (mode == identities_SidebarMode && deviceType_App() != desktop_AppDeviceType) { | ||
595 | return iFalse; /* Identities are in Settings. */ | ||
596 | } | ||
594 | if (d->mode >= 0 && d->mode < max_SidebarMode) { | 597 | if (d->mode >= 0 && d->mode < max_SidebarMode) { |
595 | d->modeScroll[d->mode] = scrollPos_ListWidget(list_SidebarWidget_(d)); /* saved for later */ | 598 | d->modeScroll[d->mode] = scrollPos_ListWidget(list_SidebarWidget_(d)); /* saved for later */ |
596 | } | 599 | } |
@@ -705,33 +708,34 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { | |||
705 | d->certList = NULL; | 708 | d->certList = NULL; |
706 | d->actions = NULL; | 709 | d->actions = NULL; |
707 | d->closedFolders = new_IntSet(); | 710 | d->closedFolders = new_IntSet(); |
708 | /* On a phone, the right sidebar is used exclusively for Identities. */ | 711 | /* On a phone, the right sidebar is not used. */ |
709 | const iBool isPhone = deviceType_App() == phone_AppDeviceType; | 712 | const iBool isPhone = deviceType_App() == phone_AppDeviceType; |
710 | if (!isPhone || d->side == left_SidebarSide) { | 713 | //if (!isPhone || d->side == left_SidebarSide) { |
711 | iWidget *buttons = new_Widget(); | 714 | iWidget *buttons = new_Widget(); |
712 | setId_Widget(buttons, "buttons"); | 715 | setId_Widget(buttons, "buttons"); |
713 | setDrawBufferEnabled_Widget(buttons, iTrue); | 716 | setDrawBufferEnabled_Widget(buttons, iTrue); |
714 | for (int i = 0; i < max_SidebarMode; i++) { | 717 | for (int i = 0; i < max_SidebarMode; i++) { |
715 | if (i == identities_SidebarMode && deviceType_App() != desktop_AppDeviceType) { | 718 | if (i == identities_SidebarMode && deviceType_App() != desktop_AppDeviceType) { |
716 | /* On mobile, identities are managed via Settings. */ | 719 | /* On mobile, identities are managed via Settings. */ |
717 | continue; | 720 | continue; |
718 | } | 721 | } |
719 | d->modeButtons[i] = addChildFlags_Widget( | 722 | d->modeButtons[i] = addChildFlags_Widget( |
720 | buttons, | 723 | buttons, |
721 | iClob(new_LabelWidget( | 724 | iClob(new_LabelWidget( |
722 | tightModeLabels_[i], | 725 | tightModeLabels_[i], |
723 | format_CStr("%s.mode arg:%d", cstr_String(id_Widget(w)), i))), | 726 | format_CStr("%s.mode arg:%d", cstr_String(id_Widget(w)), i))), |
724 | frameless_WidgetFlag | noBackground_WidgetFlag); | 727 | frameless_WidgetFlag | noBackground_WidgetFlag); |
725 | } | ||
726 | setButtonFont_SidebarWidget(d, isPhone ? uiLabelBig_FontId : uiLabel_FontId); | ||
727 | addChildFlags_Widget(vdiv, | ||
728 | iClob(buttons), | ||
729 | arrangeHorizontal_WidgetFlag | | ||
730 | resizeWidthOfChildren_WidgetFlag | | ||
731 | arrangeHeight_WidgetFlag | resizeToParentWidth_WidgetFlag); // | | ||
732 | // drawBackgroundToHorizontalSafeArea_WidgetFlag); | ||
733 | setBackgroundColor_Widget(buttons, uiBackgroundSidebar_ColorId); | ||
734 | } | 728 | } |
729 | setButtonFont_SidebarWidget(d, isPhone ? uiLabelBig_FontId : uiLabel_FontId); | ||
730 | addChildFlags_Widget(vdiv, | ||
731 | iClob(buttons), | ||
732 | arrangeHorizontal_WidgetFlag | | ||
733 | resizeWidthOfChildren_WidgetFlag | | ||
734 | arrangeHeight_WidgetFlag | resizeToParentWidth_WidgetFlag); // | | ||
735 | // drawBackgroundToHorizontalSafeArea_WidgetFlag); | ||
736 | setBackgroundColor_Widget(buttons, uiBackgroundSidebar_ColorId); | ||
737 | // } | ||
738 | #if 0 | ||
735 | else { | 739 | else { |
736 | iLabelWidget *heading = new_LabelWidget(person_Icon " ${sidebar.identities}", NULL); | 740 | iLabelWidget *heading = new_LabelWidget(person_Icon " ${sidebar.identities}", NULL); |
737 | checkIcon_LabelWidget(heading); | 741 | checkIcon_LabelWidget(heading); |
@@ -742,6 +746,7 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { | |||
742 | drawBackgroundToHorizontalSafeArea_WidgetFlag), | 746 | drawBackgroundToHorizontalSafeArea_WidgetFlag), |
743 | uiLabelLargeBold_FontId); | 747 | uiLabelLargeBold_FontId); |
744 | } | 748 | } |
749 | #endif | ||
745 | iWidget *content = new_Widget(); | 750 | iWidget *content = new_Widget(); |
746 | setFlags_Widget(content, resizeChildren_WidgetFlag, iTrue); | 751 | setFlags_Widget(content, resizeChildren_WidgetFlag, iTrue); |
747 | iWidget *listAndActions = makeVDiv_Widget(); | 752 | iWidget *listAndActions = makeVDiv_Widget(); |
@@ -771,8 +776,8 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { | |||
771 | addChildFlags_Widget(content, iClob(d->blank), resizeChildren_WidgetFlag); | 776 | addChildFlags_Widget(content, iClob(d->blank), resizeChildren_WidgetFlag); |
772 | addChildFlags_Widget(vdiv, iClob(content), expand_WidgetFlag); | 777 | addChildFlags_Widget(vdiv, iClob(content), expand_WidgetFlag); |
773 | setMode_SidebarWidget(d, | 778 | setMode_SidebarWidget(d, |
774 | deviceType_App() == phone_AppDeviceType && d->side == right_SidebarSide ? | 779 | /*deviceType_App() == phone_AppDeviceType && d->side == right_SidebarSide ? |
775 | identities_SidebarMode : bookmarks_SidebarMode); | 780 | identities_SidebarMode :*/ bookmarks_SidebarMode); |
776 | d->resizer = | 781 | d->resizer = |
777 | addChildFlags_Widget(w, | 782 | addChildFlags_Widget(w, |
778 | iClob(new_Widget()), | 783 | iClob(new_Widget()), |