[haiku-commits] haiku: hrev51630 - src/servers/keystore

  • From: "" <dmarc-noreply@xxxxxxxxxxxxx> (Redacted sender "janus2" for DMARC)
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 28 Nov 2017 21:21:39 +0100 (CET)

hrev51630 adds 1 changeset to branch 'master'
old head: ef854aff3a5d27191a6dfafc8c248d95fe67a33d
new head: 3004f55c5cf554ac59ea8e5174e4c43f3ba6caf1
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=3004f55c5cf5+%5Eef854aff3a5d

----------------------------------------------------------------------------

3004f55c5cf5: keystore: Clean up the code add an icon.
  
  * Need more work see #13812 and #11315

                                                [ Janus <janus2@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev51630
Commit:      3004f55c5cf554ac59ea8e5174e4c43f3ba6caf1
URL:         http://cgit.haiku-os.org/haiku/commit/?id=3004f55c5cf5
Author:      Janus <janus2@xxxxxxxxx>
Date:        Tue Nov 28 20:15:55 2017 UTC

Ticket:      https://dev.haiku-os.org/ticket/11315
Ticket:      https://dev.haiku-os.org/ticket/13812

----------------------------------------------------------------------------

5 files changed, 228 insertions(+), 129 deletions(-)
src/servers/keystore/AppAccessRequestWindow.cpp | 214 ++++++++------------
src/servers/keystore/AppAccessRequestWindow.h   |  11 +-
src/servers/keystore/Jamfile                    |   2 +-
src/servers/keystore/StripeView.cpp             |  87 ++++++++
src/servers/keystore/StripeView.h               |  43 ++++

----------------------------------------------------------------------------

diff --git a/src/servers/keystore/AppAccessRequestWindow.cpp 
b/src/servers/keystore/AppAccessRequestWindow.cpp
index c25ba58..1d57522 100644
--- a/src/servers/keystore/AppAccessRequestWindow.cpp
+++ b/src/servers/keystore/AppAccessRequestWindow.cpp
@@ -6,24 +6,16 @@
 
 #include "AppAccessRequestWindow.h"
 
-#include <Button.h>
 #include <Catalog.h>
-#include <CheckBox.h>
-#include <GridLayout.h>
-#include <GridView.h>
-#include <GroupLayout.h>
-#include <GroupView.h>
-#include <MenuField.h>
-#include <MenuItem.h>
-#include <NetworkDevice.h>
-#include <PopUpMenu.h>
+#include <LayoutBuilder.h>
+#include <LayoutUtils.h>
+#include <NodeInfo.h>
+#include <Roster.h>
 #include <SpaceLayoutItem.h>
 #include <TextView.h>
-#include <View.h>
 
 #include <new>
 
-
 #undef B_TRANSLATION_CONTEXT
 #define B_TRANSLATION_CONTEXT "AppAccessRequestWindow"
 
@@ -33,111 +25,6 @@ static const uint32 kMessageOnce = 'btao';
 static const uint32 kMessageAlways = 'btaa';
 
 
-class AppAccessRequestView : public BView {
-public:
-       AppAccessRequestView(const char* keyringName, const char* signature,
-               const char* path, const char* accessString, bool appIsNew,
-               bool appWasUpdated)
-               :
-               BView("AppAccessRequestView", B_WILL_DRAW)
-       {
-               SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
-
-               BGroupLayout* rootLayout = new(std::nothrow) 
BGroupLayout(B_VERTICAL);
-               if (rootLayout == NULL)
-                       return;
-
-               SetLayout(rootLayout);
-
-               float inset = ceilf(be_plain_font->Size() * 0.7);
-               rootLayout->SetInsets(inset, inset, inset, inset);
-               rootLayout->SetSpacing(inset);
-
-               BTextView* message = new(std::nothrow) BTextView("Message");
-               if (message == NULL)
-                       return;
-
-               BString details;
-               details <<  B_TRANSLATE("The application:\n"
-                       "%signature% (%path%)\n\n");
-               details.ReplaceFirst("%signature%", signature);
-               details.ReplaceFirst("%path%", path);
-
-               if (keyringName != NULL) {
-                       details <<  B_TRANSLATE("requests access to keyring:\n"
-                               "%keyringName%\n\n");
-                       details.ReplaceFirst("%keyringName%", keyringName);
-               }
-
-               if (accessString != NULL) {
-                       details <<  B_TRANSLATE("to perform the following 
action:\n"
-                               "%accessString%\n\n");
-                       details.ReplaceFirst("%accessString%", accessString);
-               }
-
-               if (appIsNew)
-                       details <<  B_TRANSLATE("This application hasn't been 
granted "
-                       "access before.");
-               else if (appWasUpdated) {
-                       details <<  B_TRANSLATE("This application has been 
updated since "
-                       "it was last granted access.");
-               } else {
-                       details <<  B_TRANSLATE("This application doesn't yet 
have the "
-                       "required privileges.");
-               }
-
-               message->SetText(details);
-               message->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
-               rgb_color textColor = ui_color(B_PANEL_TEXT_COLOR);
-               message->SetFontAndColor(be_plain_font, B_FONT_ALL, &textColor);
-               message->MakeEditable(false);
-               message->MakeSelectable(false);
-               message->SetWordWrap(true);
-
-               message->SetExplicitMinSize(BSize(message->StringWidth(
-                               
"01234567890123456789012345678901234567890123456789") + inset,
-                       B_SIZE_UNSET));
-
-               BGroupView* buttons = new(std::nothrow) 
BGroupView(B_HORIZONTAL);
-               if (buttons == NULL)
-                       return;
-
-               fDisallowButton = new(std::nothrow) 
BButton(B_TRANSLATE("Disallow"),
-                       new BMessage(kMessageDisallow));
-               buttons->GroupLayout()->AddView(fDisallowButton);
-
-               buttons->GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue());
-
-               fOnceButton = new(std::nothrow) BButton(B_TRANSLATE("Allow 
once"),
-                       new BMessage(kMessageOnce));
-               buttons->GroupLayout()->AddView(fOnceButton);
-
-               fAlwaysButton = new(std::nothrow) BButton(B_TRANSLATE("Allow 
always"),
-                       new BMessage(kMessageAlways));
-               buttons->GroupLayout()->AddView(fAlwaysButton);
-
-               rootLayout->AddView(message);
-               rootLayout->AddView(buttons);
-       }
-
-       virtual void
-       AttachedToWindow()
-       {
-               fDisallowButton->SetTarget(Window());
-               fOnceButton->SetTarget(Window());
-               fAlwaysButton->SetTarget(Window());
-
-               // TODO: Decide for a sane default button (or none at all).
-               //fButton->MakeDefault(true);
-       }
-
-private:
-       BButton* fDisallowButton;
-       BButton* fOnceButton;
-       BButton* fAlwaysButton;
-};
-
-
 AppAccessRequestWindow::AppAccessRequestWindow(const char* keyringName,
        const char* signature, const char* path, const char* accessString,
        bool appIsNew, bool appWasUpdated)
@@ -146,7 +33,6 @@ AppAccessRequestWindow::AppAccessRequestWindow(const char* 
keyringName,
                B_TITLED_WINDOW, B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS
                        | B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | 
B_AUTO_UPDATE_SIZE_LIMITS
                        | B_CLOSE_ON_ESCAPE),
-       fRequestView(NULL),
        fDoneSem(-1),
        fResult(kMessageDisallow)
 {
@@ -154,18 +40,81 @@ AppAccessRequestWindow::AppAccessRequestWindow(const char* 
keyringName,
        if (fDoneSem < 0)
                return;
 
-       BLayout* layout = new(std::nothrow) BGroupLayout(B_HORIZONTAL);
-       if (layout == NULL)
-               return;
 
-       SetLayout(layout);
+       BBitmap icon = GetIcon(32 * icon_layout_scale());
+       fStripeView = new StripeView(icon);
 
-       fRequestView = new(std::nothrow) AppAccessRequestView(keyringName,
-               signature, path, accessString, appIsNew, appWasUpdated);
-       if (fRequestView == NULL)
+       float inset = ceilf(be_plain_font->Size() * 0.7);
+
+       BTextView* message = new(std::nothrow) BTextView("Message");
+       if (message == NULL)
                return;
 
-       layout->AddView(fRequestView);
+       BString details;
+       details <<  B_TRANSLATE("The application:\n"
+               "%signature% (%path%)\n\n");
+       details.ReplaceFirst("%signature%", signature);
+       details.ReplaceFirst("%path%", path);
+
+       if (keyringName != NULL) {
+               details <<  B_TRANSLATE("requests access to keyring:\n"
+                       "%keyringName%\n\n");
+               details.ReplaceFirst("%keyringName%", keyringName);
+       }
+
+       if (accessString != NULL) {
+               details <<  B_TRANSLATE("to perform the following action:\n"
+                       "%accessString%\n\n");
+               details.ReplaceFirst("%accessString%", accessString);
+       }
+
+       if (appIsNew)
+               details <<  B_TRANSLATE("This application hasn't been granted "
+               "access before.");
+       else if (appWasUpdated) {
+               details <<  B_TRANSLATE("This application has been updated 
since "
+               "it was last granted access.");
+       } else {
+               details <<  B_TRANSLATE("This application doesn't yet have the "
+               "required privileges.");
+       }
+
+       message->SetText(details);
+       message->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
+       rgb_color textColor = ui_color(B_PANEL_TEXT_COLOR);
+       message->SetFontAndColor(be_plain_font, B_FONT_ALL, &textColor);
+       message->MakeEditable(false);
+       message->MakeSelectable(false);
+       message->SetWordWrap(true);
+
+       message->SetExplicitMinSize(BSize(message->StringWidth(
+               "01234567890123456789012345678901234567890123456789") + inset,
+               B_SIZE_UNSET));
+
+       fDisallowButton = new(std::nothrow) BButton(B_TRANSLATE("Disallow"),
+               new BMessage(kMessageDisallow));
+       fOnceButton = new(std::nothrow) BButton(B_TRANSLATE("Allow once"),
+               new BMessage(kMessageOnce));
+       fAlwaysButton = new(std::nothrow) BButton(B_TRANSLATE("Allow always"),
+               new BMessage(kMessageAlways));
+
+       BLayoutBuilder::Group<>(this, B_HORIZONTAL, B_USE_ITEM_SPACING)
+               .Add(fStripeView)
+               .AddGroup(B_VERTICAL, 0)
+                       .SetInsets(0, B_USE_WINDOW_SPACING,
+                               B_USE_WINDOW_SPACING, B_USE_WINDOW_SPACING)
+                       .AddGroup(new BGroupView(B_VERTICAL, 
B_USE_ITEM_SPACING))
+                               .Add(message)
+                       .End()
+                       .AddStrut(B_USE_SMALL_SPACING)
+                       .AddGroup(new BGroupView(B_HORIZONTAL))
+                               .Add(fDisallowButton)
+                               .AddGlue()
+                               .Add(fOnceButton)
+                               .Add(fAlwaysButton)
+                       .End()
+               .End()
+       .End();
 }
 
 
@@ -232,3 +181,16 @@ AppAccessRequestWindow::RequestAppAccess(bool& allowAlways)
        Quit();
        return result;
 }
+
+
+BBitmap
+AppAccessRequestWindow::GetIcon(int32 iconSize)
+{
+       BBitmap icon(BRect(0, 0, iconSize - 1, iconSize - 1), 0, B_RGBA32);
+       team_info teamInfo;
+       get_team_info(B_CURRENT_TEAM, &teamInfo);
+       app_info appInfo;
+       be_roster->GetRunningAppInfo(teamInfo.team, &appInfo);
+       BNodeInfo::GetTrackerIcon(&appInfo.ref, &icon, icon_size(iconSize));
+       return icon;
+}
diff --git a/src/servers/keystore/AppAccessRequestWindow.h 
b/src/servers/keystore/AppAccessRequestWindow.h
index b1b8b1a..0d70c1f 100644
--- a/src/servers/keystore/AppAccessRequestWindow.h
+++ b/src/servers/keystore/AppAccessRequestWindow.h
@@ -5,10 +5,12 @@
 #ifndef _APP_ACCESS_REQUEST_WINDOW_H
 #define _APP_ACCESS_REQUEST_WINDOW_H
 
-
+#include <Bitmap.h>
+#include <Button.h>
 #include <Message.h>
 #include <Window.h>
 
+#include "StripeView.h"
 
 class AppAccessRequestView;
 
@@ -27,11 +29,16 @@ virtual     bool                                            
QuitRequested();
 virtual        void                                            
MessageReceived(BMessage* message);
 
                status_t                                        
RequestAppAccess(bool& allowAlways);
-
+               BBitmap                                         GetIcon(int32 
iconSize);
 private:
                AppAccessRequestView*           fRequestView;
                sem_id                                          fDoneSem;
                uint32                                          fResult;
+               BButton*                                        fDisallowButton;
+               BButton*                                        fOnceButton;
+               BButton*                                        fAlwaysButton;
+               StripeView*                                     fStripeView;
+
 };
 
 
diff --git a/src/servers/keystore/Jamfile b/src/servers/keystore/Jamfile
index bcad91a..e9eefe8 100644
--- a/src/servers/keystore/Jamfile
+++ b/src/servers/keystore/Jamfile
@@ -7,7 +7,7 @@ Server keystore_server :
        KeyRequestWindow.cpp
        Keyring.cpp
        KeyStoreServer.cpp
-
+       StripeView.cpp
        : be localestub [ TargetLibstdc++ ]
        : keystore_server.rdef
 ;
diff --git a/src/servers/keystore/StripeView.cpp 
b/src/servers/keystore/StripeView.cpp
new file mode 100644
index 0000000..6256e66
--- /dev/null
+++ b/src/servers/keystore/StripeView.cpp
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2007-2016 Haiku, Inc.
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ *             Ryan Leavengood <leavengood@xxxxxxxxx>
+ *             John Scipione <jscipione@xxxxxxxxx>
+ *             Joseph Groover <looncraz@xxxxxxxxxxxx>
+ *             Brian Hill <supernova@tycho.email>
+ */
+
+
+#include "StripeView.h"
+
+#include <LayoutUtils.h>
+
+
+static const float kTopOffset = 10.0f;
+static const int kIconStripeWidth = 30;
+
+
+StripeView::StripeView(BBitmap& icon)
+       :
+       BView("StripeView", B_WILL_DRAW),
+       fIcon(icon),
+       fIconSize(0.0),
+       fPreferredWidth(0.0),
+       fPreferredHeight(0.0)
+{
+       SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
+
+       if (fIcon.IsValid()) {
+               fIconSize = fIcon.Bounds().Width();
+               // Use the same scaling as a BAlert
+               int32 scale = icon_layout_scale();
+               fPreferredWidth = 18 * scale + fIcon.Bounds().Width();
+               fPreferredHeight = 6 * scale + fIcon.Bounds().Height();
+       }
+}
+
+
+void
+StripeView::Draw(BRect updateRect)
+{
+       if (fIconSize == 0)
+               return;
+
+       SetHighColor(ViewColor());
+       FillRect(updateRect);
+
+       BRect stripeRect = Bounds();
+       int32 iconLayoutScale = icon_layout_scale();
+       stripeRect.right = kIconStripeWidth * iconLayoutScale;
+       SetHighColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
+       FillRect(stripeRect);
+
+       SetDrawingMode(B_OP_ALPHA);
+       SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
+       DrawBitmapAsync(&fIcon, BPoint(stripeRect.right - (fIconSize / 2.0),
+               6 * iconLayoutScale));
+}
+
+
+BSize
+StripeView::PreferredSize()
+{
+       return BSize(fPreferredWidth, B_SIZE_UNSET);
+}
+
+
+void
+StripeView::GetPreferredSize(float* _width, float* _height)
+{
+       if (_width != NULL)
+               *_width = fPreferredWidth;
+
+       if (_height != NULL)
+               *_height = fPreferredHeight;
+}
+
+
+BSize
+StripeView::MaxSize()
+{
+       return BLayoutUtils::ComposeSize(ExplicitMaxSize(),
+               BSize(fPreferredWidth, B_SIZE_UNLIMITED));
+}
diff --git a/src/servers/keystore/StripeView.h 
b/src/servers/keystore/StripeView.h
new file mode 100644
index 0000000..d2a6ebb
--- /dev/null
+++ b/src/servers/keystore/StripeView.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2007-2016 Haiku, Inc.
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ *             Ryan Leavengood <leavengood@xxxxxxxxx>
+ *             John Scipione <jscipione@xxxxxxxxx>
+ *             Joseph Groover <looncraz@xxxxxxxxxxxx>
+ *             Brian Hill <supernova@tycho.email>
+ */
+#ifndef _STRIPE_VIEW_H
+#define _STRIPE_VIEW_H
+
+
+#include <Bitmap.h>
+#include <View.h>
+
+
+class StripeView : public BView {
+public:
+                                                       StripeView(BBitmap& 
icon);
+
+       virtual void                    Draw(BRect updateRect);
+       virtual BSize                   PreferredSize();
+       virtual void                    GetPreferredSize(float* _width, float* 
_height);
+       virtual BSize                   MaxSize();
+
+private:
+                       BBitmap                 fIcon;
+                       float                   fIconSize;
+                       float                   fPreferredWidth;
+                       float                   fPreferredHeight;
+};
+
+
+static inline int32
+icon_layout_scale()
+{
+       return max_c(1, ((int32)be_plain_font->Size() + 15) / 16);
+}
+
+
+#endif /* _STRIPE_VIEW_H */


Other related posts:

  • » [haiku-commits] haiku: hrev51630 - src/servers/keystore