From 83baf4eae5ea3b6c378acdfa07b9e9eeaf5de85b Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sat, 29 Aug 2020 08:28:22 +0300 Subject: Visualize identity in nav bar --- src/ui/sidebarwidget.c | 2 +- src/ui/window.c | 34 ++++++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index 25fa3f6a..325e8e2b 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c @@ -245,7 +245,7 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) { { "Use on This Page", 0, 0, "ident.use arg:1" }, { "Stop Using This Page", 0, 0, "ident.use arg:0" }, { "Stop Using Everywhere", 0, 0, "ident.use arg:0 clear:1" }, - { "View Use URLs", 0, 0, "ident.showuse" }, + { "Show Usage", 0, 0, "ident.showuse" }, { "---", 0, 0, NULL }, { "Edit Notes...", 0, 0, "ident.edit" }, { "Pick Icon...", 0, 0, "ident.pickicon" }, diff --git a/src/ui/window.c b/src/ui/window.c index bdf80e52..19fe02ed 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -22,18 +22,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "window.h" +#include "labelwidget.h" +#include "inputwidget.h" +#include "documentwidget.h" +#include "sidebarwidget.h" #include "embedded.h" -#include "app.h" #include "command.h" #include "paint.h" -#include "text.h" #include "util.h" +#include "../app.h" #include "../visited.h" -#include "labelwidget.h" -#include "inputwidget.h" -#include "documentwidget.h" -#include "sidebarwidget.h" -#include "gmutil.h" +#include "../gmcerts.h" +#include "../gmutil.h" #if defined (iPlatformMsys) # include "../win32.h" #endif @@ -150,7 +150,7 @@ static const iMenuItem helpMenuItems[] = { #endif static const iMenuItem identityButtonMenuItems[] = { - { "No Active Identity", 0, 0, NULL }, + { "No Active Identity", 0, 0, "ident.showactive" }, { "---", 0, 0, NULL }, #if !defined (iHaveNativeMenus) { "New Identity...", SDLK_n, KMOD_PRIMARY | KMOD_SHIFT, "ident.new" }, @@ -166,6 +166,21 @@ static const iMenuItem identityButtonMenuItems[] = { static const char *reloadCStr_ = "\U0001f503"; static const char *stopCStr_ = uiTextCaution_ColorEscape "\U0001f310"; +static void updateNavBarIdentity_(iWidget *navBar) { + const iGmIdentity *ident = + identityForUrl_GmCerts(certs_App(), url_DocumentWidget(document_App())); + iWidget *button = findChild_Widget(navBar, "navbar.ident"); + setFlags_Widget(button, selected_WidgetFlag, ident != NULL); + /* Update menu. */ + iLabelWidget *idItem = child_Widget(findChild_Widget(button, "menu"), 0); + setTextCStr_LabelWidget( + idItem, + ident ? format_CStr(uiTextAction_ColorEscape "%s", + cstrCollect_String(subject_TlsCertificate(ident->cert))) + : "No Active Identity"); + setFlags_Widget(as_Widget(idItem), disabled_WidgetFlag, !ident); +} + static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) { if (equal_Command(cmd, "window.resized")) { const iBool isNarrow = width_Rect(bounds_Widget(navBar)) / gap_UI < 140; @@ -203,6 +218,7 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) { const iString *urlStr = collect_String(suffix_Command(cmd, "url")); setText_InputWidget(url, urlStr); updateTextCStr_LabelWidget(reloadButton, reloadCStr_); + updateNavBarIdentity_(navBar); return iFalse; } else if (equal_Command(cmd, "document.request.cancelled")) { @@ -227,6 +243,7 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) { setText_InputWidget(findChild_Widget(navBar, "url"), url_DocumentWidget(doc)); updateTextCStr_LabelWidget(findChild_Widget(navBar, "reload"), isRequestOngoing_DocumentWidget(doc) ? stopCStr_ : reloadCStr_); + updateNavBarIdentity_(navBar); } } else if (equal_Command(cmd, "mouse.clicked") && arg_Command(cmd)) { @@ -317,6 +334,7 @@ static void setupUserInterface_Window(iWindow *d) { makeMenuButton_LabelWidget("\U0001f464", identityButtonMenuItems, iElemCount(identityButtonMenuItems)); setAlignVisually_LabelWidget(idMenu, iTrue); addChild_Widget(navBar, iClob(idMenu)); + setId_Widget(as_Widget(idMenu), "navbar.ident"); iLabelWidget *lock = addChildFlags_Widget(navBar, iClob(newIcon_LabelWidget("\U0001f513", 0, 0, "server.showcert")), -- cgit v1.2.3