keystore: Clean up the code add an icon.
* Need more work see #13812 and #11315
This commit is contained in:
parent
ef854aff3a
commit
3004f55c5c
@ -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)
|
||||
|
||||
BBitmap icon = GetIcon(32 * icon_layout_scale());
|
||||
fStripeView = new StripeView(icon);
|
||||
|
||||
float inset = ceilf(be_plain_font->Size() * 0.7);
|
||||
|
||||
BTextView* message = new(std::nothrow) BTextView("Message");
|
||||
if (message == NULL)
|
||||
return;
|
||||
|
||||
SetLayout(layout);
|
||||
BString details;
|
||||
details << B_TRANSLATE("The application:\n"
|
||||
"%signature% (%path%)\n\n");
|
||||
details.ReplaceFirst("%signature%", signature);
|
||||
details.ReplaceFirst("%path%", path);
|
||||
|
||||
fRequestView = new(std::nothrow) AppAccessRequestView(keyringName,
|
||||
signature, path, accessString, appIsNew, appWasUpdated);
|
||||
if (fRequestView == NULL)
|
||||
return;
|
||||
if (keyringName != NULL) {
|
||||
details << B_TRANSLATE("requests access to keyring:\n"
|
||||
"%keyringName%\n\n");
|
||||
details.ReplaceFirst("%keyringName%", keyringName);
|
||||
}
|
||||
|
||||
layout->AddView(fRequestView);
|
||||
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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -7,7 +7,7 @@ Server keystore_server :
|
||||
KeyRequestWindow.cpp
|
||||
Keyring.cpp
|
||||
KeyStoreServer.cpp
|
||||
|
||||
StripeView.cpp
|
||||
: be localestub [ TargetLibstdc++ ]
|
||||
: keystore_server.rdef
|
||||
;
|
||||
|
87
src/servers/keystore/StripeView.cpp
Normal file
87
src/servers/keystore/StripeView.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2007-2016 Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Ryan Leavengood <leavengood@gmail.com>
|
||||
* John Scipione <jscipione@gmail.com>
|
||||
* Joseph Groover <looncraz@looncraz.net>
|
||||
* 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));
|
||||
}
|
43
src/servers/keystore/StripeView.h
Normal file
43
src/servers/keystore/StripeView.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2007-2016 Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Ryan Leavengood <leavengood@gmail.com>
|
||||
* John Scipione <jscipione@gmail.com>
|
||||
* Joseph Groover <looncraz@looncraz.net>
|
||||
* 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 */
|
Loading…
x
Reference in New Issue
Block a user