2008-01-11 14:33:31 +00:00
|
|
|
#include <ScrollView.h>
|
2008-04-20 02:42:25 +00:00
|
|
|
#include <Window.h>
|
2008-01-11 14:33:31 +00:00
|
|
|
|
|
|
|
|
#include <pwd.h>
|
|
|
|
|
|
2008-04-20 02:42:25 +00:00
|
|
|
#include "LoginApp.h"
|
2008-01-11 14:33:31 +00:00
|
|
|
#include "LoginView.h"
|
|
|
|
|
|
|
|
|
|
#define CSEP 15
|
2008-04-20 02:42:25 +00:00
|
|
|
#define BH 20
|
|
|
|
|
#define BW 60
|
2008-01-11 14:33:31 +00:00
|
|
|
|
|
|
|
|
LoginView::LoginView(BRect frame)
|
|
|
|
|
: BView(frame, "LoginView", B_FOLLOW_ALL, 0)
|
|
|
|
|
{
|
2008-04-20 02:42:25 +00:00
|
|
|
// TODO: when I don't need to test in BeOS anymore,
|
|
|
|
|
// rewrite to use layout engine.
|
2008-01-11 14:33:31 +00:00
|
|
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
|
|
|
|
SetLowColor(ViewColor());
|
|
|
|
|
BRect r;
|
2008-04-20 02:42:25 +00:00
|
|
|
r.Set(CSEP, CSEP, 80, Bounds().Height() - 3 * CSEP - BH);
|
2008-01-11 14:33:31 +00:00
|
|
|
fUserList = new BListView(r, "users");
|
2008-04-20 02:42:25 +00:00
|
|
|
BScrollView *sv = new BScrollView("userssv", fUserList,
|
|
|
|
|
B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true);
|
2008-01-11 14:33:31 +00:00
|
|
|
AddChild(sv);
|
2008-04-20 02:42:25 +00:00
|
|
|
fUserList->SetSelectionMessage(new BMessage(kUserSelected));
|
|
|
|
|
fUserList->SetInvocationMessage(new BMessage(kUserInvoked));
|
2008-01-11 14:33:31 +00:00
|
|
|
|
2008-04-20 02:42:25 +00:00
|
|
|
r.Set(140, Bounds().top + CSEP,
|
|
|
|
|
Bounds().right - CSEP, Bounds().top + CSEP + CSEP);
|
|
|
|
|
fLoginControl = new BTextControl(r, "login", "login:", "",
|
|
|
|
|
new BMessage(kLoginEdited));
|
2008-01-11 14:33:31 +00:00
|
|
|
AddChild(fLoginControl);
|
2008-04-20 02:42:25 +00:00
|
|
|
|
2008-01-11 14:33:31 +00:00
|
|
|
r.OffsetBySelf(0, CSEP + CSEP);
|
2008-04-20 02:42:25 +00:00
|
|
|
fPasswordControl = new BTextControl(r, "password", "password:", "",
|
|
|
|
|
new BMessage(kPasswordEdited));
|
2008-04-20 00:14:58 +00:00
|
|
|
fPasswordControl->TextView()->HideTyping(true);
|
2008-01-11 14:33:31 +00:00
|
|
|
AddChild(fPasswordControl);
|
2008-04-20 02:42:25 +00:00
|
|
|
|
|
|
|
|
r.OffsetBySelf(0, CSEP + CSEP);
|
|
|
|
|
fHidePasswordCheckBox = new BCheckBox(r, "hidepw", "Hide Password",
|
|
|
|
|
new BMessage(kHidePassword));
|
|
|
|
|
fHidePasswordCheckBox->SetValue(1);
|
|
|
|
|
AddChild(fHidePasswordCheckBox);
|
|
|
|
|
|
|
|
|
|
// buttons
|
|
|
|
|
float buttonWidth = BW; //(Bounds().Width() - 4 * CSEP) / 3;
|
|
|
|
|
BRect buttonRect(0, Bounds().bottom - BH,
|
|
|
|
|
buttonWidth, Bounds().bottom);
|
|
|
|
|
buttonRect.OffsetBySelf(CSEP, -CSEP);
|
|
|
|
|
|
|
|
|
|
fHaltButton = new BButton(buttonRect, "halt", "Halt",
|
|
|
|
|
new BMessage(kHaltAction));
|
|
|
|
|
AddChild(fHaltButton);
|
|
|
|
|
|
|
|
|
|
buttonRect.OffsetBySelf(CSEP + buttonWidth, 0);
|
|
|
|
|
fRebootButton = new BButton(buttonRect, "reboot", "Reboot",
|
|
|
|
|
new BMessage(kRebootAction));
|
|
|
|
|
AddChild(fRebootButton);
|
|
|
|
|
|
|
|
|
|
buttonRect.OffsetToSelf(Bounds().Width() - CSEP - buttonWidth,
|
|
|
|
|
Bounds().Height() - CSEP - BH);
|
|
|
|
|
fLoginButton = new BButton(buttonRect, "ok", "Ok",
|
|
|
|
|
new BMessage(kAttemptLogin));
|
|
|
|
|
AddChild(fLoginButton);
|
|
|
|
|
|
2008-01-11 14:33:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LoginView::~LoginView()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
LoginView::AttachedToWindow()
|
|
|
|
|
{
|
2008-04-20 02:42:25 +00:00
|
|
|
fUserList->SetTarget(this);
|
|
|
|
|
fLoginControl->SetTarget(this);
|
|
|
|
|
fPasswordControl->SetTarget(this);
|
|
|
|
|
fHidePasswordCheckBox->SetTarget(this);
|
|
|
|
|
fHaltButton->SetTarget(be_app_messenger);
|
|
|
|
|
fRebootButton->SetTarget(be_app_messenger);
|
|
|
|
|
fLoginButton->SetTarget(this);
|
|
|
|
|
Window()->SetDefaultButton(fLoginButton);
|
|
|
|
|
//fLoginControl->MakeFocus();
|
|
|
|
|
fUserList->MakeFocus();
|
2008-01-11 14:33:31 +00:00
|
|
|
// populate user list
|
|
|
|
|
BMessenger(this).SendMessage(kAddNextUser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
LoginView::MessageReceived(BMessage *message)
|
|
|
|
|
{
|
|
|
|
|
switch (message->what) {
|
2008-04-20 02:42:25 +00:00
|
|
|
case kSetProgress:
|
|
|
|
|
break;
|
|
|
|
|
case kAddNextUser:
|
|
|
|
|
AddNextUser();
|
|
|
|
|
break;
|
|
|
|
|
case kUserSelected:
|
|
|
|
|
{
|
|
|
|
|
int32 selection = fUserList->CurrentSelection();
|
|
|
|
|
if (selection > -1) {
|
|
|
|
|
BStringItem *item = dynamic_cast<BStringItem *>(
|
|
|
|
|
fUserList->ItemAt(selection));
|
|
|
|
|
if (item)
|
|
|
|
|
fLoginControl->SetText(item->Text());
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case kUserInvoked:
|
|
|
|
|
fPasswordControl->MakeFocus();
|
|
|
|
|
break;
|
|
|
|
|
case kLoginEdited:
|
|
|
|
|
break;
|
|
|
|
|
case kHidePassword:
|
|
|
|
|
fPasswordControl->TextView()->HideTyping(
|
2008-04-20 02:44:27 +00:00
|
|
|
fHidePasswordCheckBox->Value());
|
2008-04-20 02:42:25 +00:00
|
|
|
break;
|
|
|
|
|
case kAttemptLogin:
|
|
|
|
|
{
|
|
|
|
|
BMessage *m = new BMessage(kAttemptLogin);
|
|
|
|
|
m->AddString("login", fLoginControl->Text());
|
|
|
|
|
m->AddString("password", fPasswordControl->Text());
|
|
|
|
|
be_app->PostMessage(m, NULL, this);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case kLoginBad:
|
|
|
|
|
fPasswordControl->SetText("");
|
|
|
|
|
EnableControls(false);
|
|
|
|
|
if (Window()) {
|
|
|
|
|
BPoint savedPos = Window()->Frame().LeftTop();
|
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
|
BPoint p(savedPos);
|
|
|
|
|
p.x += (i%2) ? 10 : -10;
|
|
|
|
|
Window()->MoveTo(p);
|
|
|
|
|
Window()->UpdateIfNeeded();
|
|
|
|
|
snooze(30000);
|
|
|
|
|
}
|
|
|
|
|
Window()->MoveTo(savedPos);
|
|
|
|
|
}
|
|
|
|
|
EnableControls(true);
|
|
|
|
|
break;
|
|
|
|
|
case kLoginOk:
|
|
|
|
|
// XXX: quit ?
|
|
|
|
|
if (Window()) {
|
|
|
|
|
Window()->Hide();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
message->PrintToStream();
|
|
|
|
|
BView::MessageReceived(message);
|
2008-01-11 14:33:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
LoginView::AddNextUser()
|
|
|
|
|
{
|
|
|
|
|
struct passwd *pwd;
|
|
|
|
|
if (fUserList->CountItems() < 1)
|
|
|
|
|
setpwent();
|
|
|
|
|
|
|
|
|
|
pwd = getpwent();
|
|
|
|
|
|
|
|
|
|
if (pwd && pwd->pw_shell &&
|
|
|
|
|
strcmp(pwd->pw_shell, "false") &&
|
|
|
|
|
strcmp(pwd->pw_shell, "true") &&
|
|
|
|
|
strcmp(pwd->pw_shell, "/bin/false") &&
|
|
|
|
|
strcmp(pwd->pw_shell, "/bin/true")) {
|
|
|
|
|
// not disabled
|
|
|
|
|
BStringItem *item = new BStringItem(pwd->pw_name);
|
|
|
|
|
fUserList->AddItem(item);
|
|
|
|
|
}
|
|
|
|
|
if (pwd)
|
|
|
|
|
BMessenger(this).SendMessage(kAddNextUser);
|
|
|
|
|
else
|
|
|
|
|
endpwent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-04-20 02:42:25 +00:00
|
|
|
void
|
|
|
|
|
LoginView::EnableControls(bool enable)
|
|
|
|
|
{
|
|
|
|
|
fLoginControl->SetEnabled(enable);
|
|
|
|
|
fPasswordControl->SetEnabled(enable);
|
|
|
|
|
fHidePasswordCheckBox->SetEnabled(enable);
|
|
|
|
|
fHaltButton->SetEnabled(enable);
|
|
|
|
|
fRebootButton->SetEnabled(enable);
|
|
|
|
|
fLoginButton->SetEnabled(enable);
|
|
|
|
|
}
|
|
|
|
|
|