2 * Copyright 2012, Michael Lotz, mmlr@mlotz.ch. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
7 #include "AppAccessRequestWindow.h"
10 #include <LayoutBuilder.h>
11 #include <LayoutUtils.h>
14 #include <SpaceLayoutItem.h>
19 #undef B_TRANSLATION_CONTEXT
20 #define B_TRANSLATION_CONTEXT "AppAccessRequestWindow"
23 static const uint32 kMessageDisallow
= 'btda';
24 static const uint32 kMessageOnce
= 'btao';
25 static const uint32 kMessageAlways
= 'btaa';
28 AppAccessRequestWindow::AppAccessRequestWindow(const char* keyringName
,
29 const char* signature
, const char* path
, const char* accessString
,
30 bool appIsNew
, bool appWasUpdated
)
32 BWindow(BRect(50, 50, 100, 100), B_TRANSLATE("Application keyring access"),
33 B_TITLED_WINDOW
, B_NOT_RESIZABLE
| B_ASYNCHRONOUS_CONTROLS
34 | B_NOT_ZOOMABLE
| B_NOT_MINIMIZABLE
| B_AUTO_UPDATE_SIZE_LIMITS
37 fResult(kMessageDisallow
)
39 fDoneSem
= create_sem(0, "application keyring access dialog");
44 BBitmap icon
= GetIcon(32 * icon_layout_scale());
45 fStripeView
= new StripeView(icon
);
47 float inset
= ceilf(be_plain_font
->Size() * 0.7);
49 BTextView
* message
= new(std::nothrow
) BTextView("Message");
54 details
<< B_TRANSLATE("The application:\n"
55 "%signature% (%path%)\n\n");
56 details
.ReplaceFirst("%signature%", signature
);
57 details
.ReplaceFirst("%path%", path
);
59 if (keyringName
!= NULL
) {
60 details
<< B_TRANSLATE("requests access to keyring:\n"
62 details
.ReplaceFirst("%keyringName%", keyringName
);
65 if (accessString
!= NULL
) {
66 details
<< B_TRANSLATE("to perform the following action:\n"
67 "%accessString%\n\n");
68 details
.ReplaceFirst("%accessString%", accessString
);
72 details
<< B_TRANSLATE("This application hasn't been granted "
74 else if (appWasUpdated
) {
75 details
<< B_TRANSLATE("This application has been updated since "
76 "it was last granted access.");
78 details
<< B_TRANSLATE("This application doesn't yet have the "
79 "required privileges.");
82 message
->SetText(details
);
83 message
->SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
84 rgb_color textColor
= ui_color(B_PANEL_TEXT_COLOR
);
85 message
->SetFontAndColor(be_plain_font
, B_FONT_ALL
, &textColor
);
86 message
->MakeEditable(false);
87 message
->MakeSelectable(false);
88 message
->SetWordWrap(true);
90 message
->SetExplicitMinSize(BSize(message
->StringWidth(
91 "01234567890123456789012345678901234567890123456789") + inset
,
94 fDisallowButton
= new(std::nothrow
) BButton(B_TRANSLATE("Disallow"),
95 new BMessage(kMessageDisallow
));
96 fOnceButton
= new(std::nothrow
) BButton(B_TRANSLATE("Allow once"),
97 new BMessage(kMessageOnce
));
98 fAlwaysButton
= new(std::nothrow
) BButton(B_TRANSLATE("Allow always"),
99 new BMessage(kMessageAlways
));
101 BLayoutBuilder::Group
<>(this, B_HORIZONTAL
, B_USE_ITEM_SPACING
)
103 .AddGroup(B_VERTICAL
, 0)
104 .SetInsets(0, B_USE_WINDOW_SPACING
,
105 B_USE_WINDOW_SPACING
, B_USE_WINDOW_SPACING
)
106 .AddGroup(new BGroupView(B_VERTICAL
, B_USE_ITEM_SPACING
))
109 .AddStrut(B_USE_SMALL_SPACING
)
110 .AddGroup(new BGroupView(B_HORIZONTAL
))
111 .Add(fDisallowButton
)
121 AppAccessRequestWindow::~AppAccessRequestWindow()
124 delete_sem(fDoneSem
);
129 AppAccessRequestWindow::QuitRequested()
131 fResult
= kMessageDisallow
;
132 release_sem(fDoneSem
);
138 AppAccessRequestWindow::MessageReceived(BMessage
* message
)
140 switch (message
->what
) {
141 case kMessageDisallow
:
144 fResult
= message
->what
;
145 release_sem(fDoneSem
);
149 BWindow::MessageReceived(message
);
154 AppAccessRequestWindow::RequestAppAccess(bool& allowAlways
)
160 while (acquire_sem(fDoneSem
) == B_INTERRUPTED
)
166 case kMessageDisallow
:
167 result
= B_NOT_ALLOWED
;
187 AppAccessRequestWindow::GetIcon(int32 iconSize
)
189 BBitmap
icon(BRect(0, 0, iconSize
- 1, iconSize
- 1), 0, B_RGBA32
);
191 get_team_info(B_CURRENT_TEAM
, &teamInfo
);
193 be_roster
->GetRunningAppInfo(teamInfo
.team
, &appInfo
);
194 BNodeInfo::GetTrackerIcon(&appInfo
.ref
, &icon
, icon_size(iconSize
));