summaryrefslogtreecommitdiff
path: root/src/ui/sidebarwidget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/sidebarwidget.c')
-rw-r--r--src/ui/sidebarwidget.c62
1 files changed, 57 insertions, 5 deletions
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index 82efb04e..aa2e185d 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -22,11 +22,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
22 22
23#include "sidebarwidget.h" 23#include "sidebarwidget.h"
24 24
25#include "../gmdocument.h"
26#include "app.h" 25#include "app.h"
27#include "bookmarks.h" 26#include "bookmarks.h"
28#include "command.h" 27#include "command.h"
29#include "documentwidget.h" 28#include "documentwidget.h"
29#include "gmcerts.h"
30#include "gmdocument.h"
30#include "inputwidget.h" 31#include "inputwidget.h"
31#include "labelwidget.h" 32#include "labelwidget.h"
32#include "paint.h" 33#include "paint.h"
@@ -216,6 +217,33 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
216 }, 6); 217 }, 6);
217 break; 218 break;
218 } 219 }
220 case identities_SidebarMode: {
221 iConstForEach(PtrArray, i, identities_GmCerts(certs_App())) {
222 const iGmIdentity *ident = i.ptr;
223 /* icon, common name, used URLs, expiration, isTemp, free-form notes */
224 iSidebarItem item;
225 init_SidebarItem(&item);
226 item.icon = ident->icon;
227 set_String(&item.label, collect_String(subject_TlsCertificate(ident->cert)));
228 iDate until;
229 validUntil_TlsCertificate(ident->cert, &until);
230 set_String(
231 &item.meta,
232 collectNewFormat_String(
233 "%s \u2014 %s\n%s",
234 isEmpty_SortedArray(&ident->useUrls)
235 ? "Not used"
236 : format_CStr("Used on %zu URLs", size_SortedArray(&ident->useUrls)),
237 ident->flags & temporary_GmIdentityFlag
238 ? "Temporary"
239 : cstrCollect_String(format_Date(&until, "Expires %b %d, %Y")),
240 cstr_String(&ident->notes)));
241 pushBack_Array(&d->items, &item);
242 }
243 /* menu: set icon, edit notes, view urls, reveal files, delete, activate on this page,
244 * deactivate on this page, deactivate everywhere */
245 break;
246 }
219 default: 247 default:
220 break; 248 break;
221 } 249 }
@@ -247,7 +275,7 @@ void setMode_SidebarWidget(iSidebarWidget *d, enum iSidebarMode mode) {
247 for (enum iSidebarMode i = 0; i < max_SidebarMode; i++) { 275 for (enum iSidebarMode i = 0; i < max_SidebarMode; i++) {
248 setFlags_Widget(as_Widget(d->modeButtons[i]), selected_WidgetFlag, i == d->mode); 276 setFlags_Widget(as_Widget(d->modeButtons[i]), selected_WidgetFlag, i == d->mode);
249 } 277 }
250 const float heights[max_SidebarMode] = { 1.333f, 1.333f, 2.5f, 1.2f }; 278 const float heights[max_SidebarMode] = { 1.333f, 1.333f, 3.0f, 1.2f };
251 d->itemHeight = heights[mode] * lineHeight_Text(uiContent_FontId); 279 d->itemHeight = heights[mode] * lineHeight_Text(uiContent_FontId);
252 invalidate_SidebarWidget_(d); 280 invalidate_SidebarWidget_(d);
253 /* Restore previous scroll position. */ 281 /* Restore previous scroll position. */
@@ -529,7 +557,10 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
529 } 557 }
530 return iTrue; 558 return iTrue;
531 } 559 }
532 else if (equal_Command(cmd, "bookmarks.changed")) { 560 else if (equal_Command(cmd, "bookmarks.changed") && d->mode == bookmarks_SidebarMode) {
561 updateItems_SidebarWidget_(d);
562 }
563 else if (equal_Command(cmd, "idents.changed") && d->mode == identities_SidebarMode) {
533 updateItems_SidebarWidget_(d); 564 updateItems_SidebarWidget_(d);
534 } 565 }
535 else if (equal_Command(cmd, "history.delete")) { 566 else if (equal_Command(cmd, "history.delete")) {
@@ -661,6 +692,9 @@ static void draw_SidebarWidget_(const iSidebarWidget *d) {
661 const iSidebarItem *item = constAt_Array(&d->items, i); 692 const iSidebarItem *item = constAt_Array(&d->items, i);
662 const iRect itemRect = { pos, init_I2(width_Rect(bufBounds), d->itemHeight) }; 693 const iRect itemRect = { pos, init_I2(width_Rect(bufBounds), d->itemHeight) };
663 const iBool isHover = (d->hoverItem == i); 694 const iBool isHover = (d->hoverItem == i);
695 const int iconColor =
696 isHover ? (isPressing ? uiTextPressed_ColorId : uiIconHover_ColorId)
697 : uiIcon_ColorId;
664 setClip_Paint(&p, intersect_Rect(itemRect, bufBounds)); 698 setClip_Paint(&p, intersect_Rect(itemRect, bufBounds));
665 if (isHover && !item->isSeparator) { 699 if (isHover && !item->isSeparator) {
666 fillRect_Paint(&p, 700 fillRect_Paint(&p,
@@ -691,8 +725,7 @@ static void draw_SidebarWidget_(const iSidebarWidget *d) {
691 font, 725 font,
692 iconArea, 726 iconArea,
693 iTrue, 727 iTrue,
694 isHover ? (isPressing ? uiTextPressed_ColorId : uiIconHover_ColorId) 728 iconColor,
695 : uiIcon_ColorId,
696 "%s", 729 "%s",
697 cstr_String(&str)); 730 cstr_String(&str));
698 deinit_String(&str); 731 deinit_String(&str);
@@ -737,6 +770,25 @@ static void draw_SidebarWidget_(const iSidebarWidget *d) {
737 } 770 }
738 iEndCollect(); 771 iEndCollect();
739 } 772 }
773 else if (d->mode == identities_SidebarMode) {
774 const int fg = isHover ? (isPressing ? uiTextPressed_ColorId
775 : uiTextFramelessHover_ColorId)
776 : uiText_ColorId;
777 iString icon;
778 initUnicodeN_String(&icon, &item->icon, 1);
779 drawRange_Text(font, add_I2(topLeft_Rect(itemRect), init_I2(3 * gap_UI, 0)),
780 iconColor, range_String(&icon));
781 deinit_String(&icon);
782 drawRange_Text(font, add_I2(topLeft_Rect(itemRect), init_I2(10 * gap_UI, 0)),
783 fg, range_String(&item->label));
784 drawRange_Text(
785 font,
786 add_I2(topLeft_Rect(itemRect), init_I2(3 * gap_UI, lineHeight_Text(font))),
787 isHover
788 ? (isPressing ? uiTextPressed_ColorId : uiTextFramelessHover_ColorId)
789 : uiAnnotation_ColorId,
790 range_String(&item->meta));
791 }
740 unsetClip_Paint(&p); 792 unsetClip_Paint(&p);
741 pos.y += d->itemHeight; 793 pos.y += d->itemHeight;
742 } 794 }