small cleanups

password window is now font sensitiv, can be seen as part of ticket #705



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23547 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Karsten Heimrich
2008-01-16 00:07:11 +00:00
parent 3b4fa1664e
commit c0a4294edd
3 changed files with 82 additions and 47 deletions
+62 -32
View File
@@ -1,15 +1,16 @@
/* /*
* Copyright 2003-2006, Haiku. * Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Phipps * Michael Phipps
* Jérôme Duval, [email protected] * Jérôme Duval, [email protected]
* Julun <[email protected]>
*/ */
#include "PasswordWindow.h" #include "PasswordWindow.h"
#include <Alert.h> #include <Alert.h>
#include <Box.h> #include <Box.h>
#include <Button.h> #include <Button.h>
@@ -17,9 +18,6 @@
#include <Screen.h> #include <Screen.h>
#include <TextControl.h> #include <TextControl.h>
#include <stdio.h>
#include <unistd.h>
const uint32 kMsgDone = 'done'; const uint32 kMsgDone = 'done';
const uint32 kMsgPasswordTypeChanged = 'pwtp'; const uint32 kMsgPasswordTypeChanged = 'pwtp';
@@ -27,10 +25,11 @@ const uint32 kMsgPasswordTypeChanged = 'pwtp';
PasswordWindow::PasswordWindow(ScreenSaverSettings& settings) PasswordWindow::PasswordWindow(ScreenSaverSettings& settings)
: BWindow(BRect(100, 100, 380, 249), "Password Window", B_MODAL_WINDOW_LOOK, : BWindow(BRect(100, 100, 380, 249), "Password Window", B_MODAL_WINDOW_LOOK,
B_MODAL_APP_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE), B_MODAL_APP_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE),
fSettings(settings) fSettings(settings)
{ {
_Setup(); _Setup();
Update();
BRect screenFrame = BScreen(B_MAIN_SCREEN_ID).Frame(); BRect screenFrame = BScreen(B_MAIN_SCREEN_ID).Frame();
BPoint point; BPoint point;
@@ -45,41 +44,68 @@ PasswordWindow::PasswordWindow(ScreenSaverSettings& settings)
void void
PasswordWindow::_Setup() PasswordWindow::_Setup()
{ {
BView* topView = new BView(Bounds(), "mainView", B_FOLLOW_ALL, B_WILL_DRAW); BRect bounds = Bounds();
BView* topView = new BView(bounds, "topView", B_FOLLOW_ALL, B_WILL_DRAW);
topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(topView); AddChild(topView);
fUseNetwork = new BRadioButton(BRect(14,10,159,20), "useNetwork", bounds.InsetBy(10.0, 10.0);
"Use Network password", new BMessage(kMsgPasswordTypeChanged), B_FOLLOW_NONE); fUseNetwork = new BRadioButton(bounds, "useNetwork", "Use Network password",
new BMessage(kMsgPasswordTypeChanged), B_FOLLOW_NONE);
topView->AddChild(fUseNetwork); topView->AddChild(fUseNetwork);
fUseCustom = new BRadioButton(BRect(30,50,130,60), "fUseCustom",
"Use custom password", new BMessage(kMsgPasswordTypeChanged), B_FOLLOW_NONE);
fUseNetwork->ResizeToPreferred(); fUseNetwork->ResizeToPreferred();
fUseCustom->ResizeToPreferred(); fUseNetwork->MoveBy(10.0, 0.0);
BBox *customBox = new BBox(BRect(9,30,269,105), "custBeBox", B_FOLLOW_NONE); bounds.OffsetBy(0.0, fUseNetwork->Bounds().Height());
customBox->SetLabel(fUseCustom); BBox *customBox = new BBox(bounds, "customBox", B_FOLLOW_NONE);
fPasswordControl = new BTextControl(BRect(10,20,251,35), "pwdCntrl", "Password:", NULL, B_FOLLOW_NONE);
fConfirmControl = new BTextControl(BRect(10,45,251,60), "fConfirmCntrl", "Confirm password:", NULL, B_FOLLOW_NONE);
fPasswordControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
float divider = be_plain_font->StringWidth("Confirm password:") + 5.0;
fPasswordControl->SetDivider(divider);
fPasswordControl->TextView()->HideTyping(true);
fConfirmControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
fConfirmControl->SetDivider(divider);
fConfirmControl->TextView()->HideTyping(true);
customBox->AddChild(fPasswordControl);
customBox->AddChild(fConfirmControl);
topView->AddChild(customBox); topView->AddChild(customBox);
BButton* button = new BButton(BRect(194,118,269,129), "done", "Done", new BMessage(kMsgDone), B_FOLLOW_NONE); fUseCustom = new BRadioButton(BRect(), "useCustom", "Use custom password",
new BMessage(kMsgPasswordTypeChanged), B_FOLLOW_NONE);
customBox->SetLabel(fUseCustom);
fUseCustom->ResizeToPreferred();
fPasswordControl = new BTextControl(bounds, "passwordControl", "Password:",
NULL, B_FOLLOW_NONE);
customBox->AddChild(fPasswordControl);
fPasswordControl->ResizeToPreferred();
fPasswordControl->TextView()->HideTyping(true);
fPasswordControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
bounds.OffsetBy(0.0, fPasswordControl->Bounds().Height() + 5.0);
fConfirmControl = new BTextControl(bounds, "confirmControl",
"Confirm password:", "VeryLongPasswordPossible", B_FOLLOW_NONE);
customBox->AddChild(fConfirmControl);
fConfirmControl->TextView()->HideTyping(true);
fConfirmControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
float width, height;
fConfirmControl->GetPreferredSize(&width, &height);
fPasswordControl->ResizeTo(width, height);
float divider = be_plain_font->StringWidth("Confirm password:") + 5.0;
fConfirmControl->SetDivider(divider);
fPasswordControl->SetDivider(divider);
customBox->ResizeTo(fConfirmControl->Frame().right + 10.0,
fConfirmControl->Frame().bottom + 10.0);
BButton* button = new BButton(BRect(), "done", "Done", new BMessage(kMsgDone));
topView->AddChild(button); topView->AddChild(button);
button->ResizeToPreferred();
BRect frame = customBox->Frame();
button->MoveTo(frame.right - button->Bounds().Width(), frame.bottom + 10.0);
frame = button->Frame();
button->MakeDefault(true); button->MakeDefault(true);
button = new BButton(BRect(109,118,184,129), "cancel", "Cancel", new BMessage(B_CANCEL), B_FOLLOW_NONE); button = new BButton(frame, "cancel", "Cancel", new BMessage(B_CANCEL));
topView->AddChild(button); topView->AddChild(button);
button->ResizeToPreferred();
button->MoveBy(-(button->Bounds().Width() + 10.0), 0.0);
Update(); ResizeTo(customBox->Frame().right + 10.0, frame.bottom + 10.0);
} }
@@ -90,7 +116,8 @@ PasswordWindow::Update()
fUseNetwork->SetValue(B_CONTROL_ON); fUseNetwork->SetValue(B_CONTROL_ON);
else else
fUseCustom->SetValue(B_CONTROL_ON); fUseCustom->SetValue(B_CONTROL_ON);
bool useNetPassword=(fUseCustom->Value()>0);
bool useNetPassword = (fUseCustom->Value() > 0);
fConfirmControl->SetEnabled(useNetPassword); fConfirmControl->SetEnabled(useNetPassword);
fPasswordControl->SetEnabled(useNetPassword); fPasswordControl->SetEnabled(useNetPassword);
} }
@@ -103,17 +130,20 @@ PasswordWindow::MessageReceived(BMessage *message)
case kMsgDone: case kMsgDone:
fSettings.SetLockMethod(fUseCustom->Value() ? "custom" : "network"); fSettings.SetLockMethod(fUseCustom->Value() ? "custom" : "network");
if (fUseCustom->Value()) { if (fUseCustom->Value()) {
if (strcmp(fPasswordControl->Text(),fConfirmControl->Text())) { if (strcmp(fPasswordControl->Text(), fConfirmControl->Text())) {
BAlert *alert=new BAlert("noMatch","Passwords don't match. Try again.","OK"); BAlert *alert = new BAlert("noMatch",
"Passwords don't match. Try again.","OK");
alert->Go(); alert->Go();
break; break;
} }
fSettings.SetPassword(crypt(fPasswordControl->Text(), fPasswordControl->Text())); fSettings.SetPassword(crypt(fPasswordControl->Text(),
fPasswordControl->Text()));
} else { } else {
fSettings.SetPassword(""); fSettings.SetPassword("");
} }
fPasswordControl->SetText(""); fPasswordControl->SetText("");
fConfirmControl->SetText(""); fConfirmControl->SetText("");
fSettings.Save();
Hide(); Hide();
break; break;
+13 -7
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2006, Haiku. * Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -12,24 +12,30 @@
#include "ScreenSaverSettings.h" #include "ScreenSaverSettings.h"
#include <Window.h> #include <Window.h>
class BRadioButton; class BRadioButton;
class BTextControl; class BTextControl;
class PasswordWindow : public BWindow { class PasswordWindow : public BWindow {
public: public:
PasswordWindow(ScreenSaverSettings &settings); PasswordWindow(ScreenSaverSettings &settings);
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
void Update(); void Update();
private: private:
void _Setup(); void _Setup();
BRadioButton *fUseCustom;
BRadioButton *fUseNetwork;
BTextControl *fConfirmControl;
BTextControl *fPasswordControl;
BRadioButton *fUseNetwork, *fUseCustom;
BTextControl *fPasswordControl, *fConfirmControl;
ScreenSaverSettings &fSettings; ScreenSaverSettings &fSettings;
}; };
+7 -8
View File
@@ -5,28 +5,27 @@
#include <Rect.h> #include <Rect.h>
int secondsToSlider(int val);
inline BPoint inline BPoint
scale_direct(float x, float y, BRect area) scale_direct(float x, float y, BRect area)
{ {
return BPoint(area.Width()*x+area.left,area.Height()*y+area.top); return BPoint(area.Width() * x + area.left, area.Height() * y + area.top);
} }
inline BRect inline BRect
scale_direct(float x1,float x2,float y1,float y2,BRect area) scale_direct(float x1, float x2, float y1, float y2, BRect area)
{ {
return BRect(area.Width()*x1+area.left,area.Height()*y1+area.top, area.Width()*x2+area.left,area.Height()*y2+area.top); return BRect(area.Width() * x1 + area.left, area.Height() * y1 + area.top,
area.Width()* x2 + area.left, area.Height() * y2 + area.top);
} }
static const float kPositionalX[] = {0,.1,.25,.3,.7,.75,.9,1.0}; static const float kPositionalX[] = { 0, .1, .25, .3, .7, .75, .9, 1.0 };
static const float kPositionalY[] = {0,.1,.7,.8,.9,1.0}; static const float kPositionalY[] = { 0, .1, .7, .8, .9, 1.0 };
inline BPoint inline BPoint
scale(int x, int y,BRect area) scale(int x, int y,BRect area)
{ {
return scale_direct(kPositionalX[x],kPositionalY[y],area); return scale_direct(kPositionalX[x], kPositionalY[y], area);
} }