clean up, style change, unused files are removed

added ScreenSaver.cpp to ScreenSaver preferences to have Matrix working


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13828 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2005-07-26 16:12:05 +00:00
parent dcd14cab61
commit 66dee31a87
21 changed files with 318 additions and 457 deletions

View File

@ -7,25 +7,25 @@ class BScreenSaver;
class BView;
class ScreenSaverPrefs;
int32 threadFunc(void *data);
class ScreenSaverThread
{
public:
ScreenSaverThread(BWindow *wnd, BView *vw, ScreenSaverPrefs *p);
void thread(void);
BScreenSaver *LoadAddOn(void) ;
void quit(void);
private:
BScreenSaver *saver;
BWindow *win;
BDirectWindow *dwin;
BView *view;
ScreenSaverPrefs *pref;
void Thread();
BScreenSaver *LoadAddOn() ;
void Quit();
long frame;
int snoozeCount;
image_id addon_image;
static int32 ThreadFunc(void *data);
private:
BScreenSaver *fSaver;
BWindow *fWin;
BDirectWindow *fDWin;
BView *fView;
ScreenSaverPrefs *fPref;
long fFrame;
int fSnoozeCount;
image_id fAddonImage;
};
#endif //SCREEN_SAVER_THREAD_H

View File

@ -1,13 +1,14 @@
#include "ScreenSaverPrefs.h"
#include "StorageDefs.h"
#include "FindDirectory.h"
#include "File.h"
#include "Path.h"
#include "string.h" // Posix string functions
#include "String.h" // BString def
#include <StorageDefs.h>
#include <FindDirectory.h>
#include <File.h>
#include <Path.h>
#include <string.h> // Posix string functions
#include <String.h> // BString def
#include <stdio.h>
ScreenSaverPrefs::ScreenSaverPrefs(void)
#include "ScreenSaverPrefs.h"
ScreenSaverPrefs::ScreenSaverPrefs()
{
find_directory(B_USER_SETTINGS_DIRECTORY,&ssPath);
find_directory(B_USER_SETTINGS_DIRECTORY,&networkPath);
@ -15,21 +16,22 @@ ScreenSaverPrefs::ScreenSaverPrefs(void)
networkPath.Append("network",true);
}
// Load the flattened settings BMessage from disk and parse it.
bool
ScreenSaverPrefs::LoadSettings(void)
ScreenSaverPrefs::LoadSettings()
{
BFile ssSettings(ssPath.Path(),B_READ_ONLY);
if (B_OK==ssSettings.InitCheck()) { // File exists. Unflatten the message and call the settings parser.
BMessage settings;
settings.Unflatten(&ssSettings);
return true;
}
}
return false;
}
const char *
ScreenSaverPrefs::Password(void) {
ScreenSaverPrefs::Password() {
if (IsNetworkPassword()) {
FILE *networkFile=NULL;
char buffer[512],*start;
@ -39,10 +41,9 @@ ScreenSaverPrefs::Password(void) {
if ((start=strstr(buffer,"PASSWORD ="))) {
strncpy(password, start+10,strlen(start-11));
return password;
}
}
}
else
return getString("lockpassword");
return getString("lockpassword");
}
BMessage *

View File

@ -1,60 +1,64 @@
#ifndef SCREEN_SAVER_THREAD_H
#include "ScreenSaverThread.h"
#endif
#include "Screen.h"
#include "ScreenSaver.h"
#include "ScreenSaverPrefs.h"
#include "FindDirectory.h"
#include <Screen.h>
#include <ScreenSaver.h>
#include <FindDirectory.h>
#include <stdio.h>
#include "ScreenSaverThread.h"
#include "ScreenSaverPrefs.h"
int32
threadFunc(void *data)
ScreenSaverThread::ThreadFunc(void *data)
{
ScreenSaverThread *ss=(ScreenSaverThread *)data;
ss->thread();
ss->Thread();
return B_OK;
}
ScreenSaverThread::ScreenSaverThread(BWindow *wnd, BView *vw, ScreenSaverPrefs *p) :
saver(NULL),win(wnd),view(vw), pref(p), frame(0),snoozeCount(0),addon_image(0)
ScreenSaverThread::ScreenSaverThread(BWindow *wnd, BView *vw, ScreenSaverPrefs *p)
: fSaver(NULL),
fWin(wnd),
fView(vw),
fPref(p),
fFrame(0),
fSnoozeCount(0),
fAddonImage(0)
{
dwin=reinterpret_cast<BDirectWindow *>(wnd);
fDWin = dynamic_cast<BDirectWindow *>(wnd);
}
void
ScreenSaverThread::quit(void)
ScreenSaverThread::Quit()
{
saver->StopSaver();
if (win)
win->Hide();
fSaver->StopSaver();
if (fWin)
fWin->Hide();
}
void
ScreenSaverThread::thread()
ScreenSaverThread::Thread()
{
win->Lock();
view->SetViewColor(0,0,0);
view->SetLowColor(0,0,0);
saver->StartSaver(view,false);
win->Unlock();
fWin->Lock();
fView->SetViewColor(0,0,0);
fView->SetLowColor(0,0,0);
fSaver->StartSaver(fView,false);
fWin->Unlock();
while (1) {
snooze(saver->TickSize());
if (snoozeCount) { // If we are sleeping, do nothing
snoozeCount--;
snooze(fSaver->TickSize());
if (fSnoozeCount) { // If we are sleeping, do nothing
fSnoozeCount--;
return;
} else if (saver->LoopOnCount() && (frame>=saver->LoopOnCount())) { // Time to nap
frame=0;
snoozeCount=saver->LoopOffCount();
} else if (fSaver->LoopOnCount() && (fFrame >= fSaver->LoopOnCount())) { // Time to nap
fFrame = 0;
fSnoozeCount = fSaver->LoopOffCount();
} else {
win->Lock();
if (dwin)
saver->DirectDraw(frame);
saver->Draw(view,frame);
win->Unlock();
frame++;
fWin->Lock();
if (fDWin)
fSaver->DirectDraw(fFrame);
fSaver->Draw(fView,fFrame);
fWin->Unlock();
fFrame++;
}
}
}
@ -64,50 +68,50 @@ BScreenSaver *
ScreenSaverThread::LoadAddOn()
{
BScreenSaver *(*instantiate)(BMessage *, image_id );
if (addon_image) { // This is a new set of preferences. Free up what we did have
unload_add_on(addon_image);
if (fAddonImage) { // This is a new set of preferences. Free up what we did have
unload_add_on(fAddonImage);
}
char temp[B_PATH_NAME_LENGTH];
if (B_OK==find_directory(B_BEOS_ADDONS_DIRECTORY,NULL,false,temp,B_PATH_NAME_LENGTH)) {
sprintf (temp,"%s/Screen Savers/%s",temp,pref->ModuleName());
addon_image = load_add_on(temp);
sprintf (temp,"%s/Screen Savers/%s", temp, fPref->ModuleName());
fAddonImage = load_add_on(temp);
}
if (addon_image<0) {
if (fAddonImage<0) {
//printf ("Unable to open add-on: %s\n",temp);
sprintf (temp,"%s/Screen Savers/%s",temp,pref->ModuleName());
sprintf (temp,"%s/Screen Savers/%s", temp, fPref->ModuleName());
if (B_OK==find_directory(B_COMMON_ADDONS_DIRECTORY,NULL,false,temp,B_PATH_NAME_LENGTH)) {
sprintf (temp,"%s/Screen Savers/%s",temp,pref->ModuleName());
addon_image = load_add_on(temp);
sprintf (temp,"%s/Screen Savers/%s", temp, fPref->ModuleName());
fAddonImage = load_add_on(temp);
}
}
if (addon_image<0) {
if (fAddonImage<0) {
//printf ("Unable to open add-on: %s\n",temp);
if (B_OK==find_directory(B_USER_ADDONS_DIRECTORY,NULL,false,temp,B_PATH_NAME_LENGTH)) {
sprintf (temp,"%s/Screen Savers/%s",temp,pref->ModuleName());
addon_image = load_add_on(temp);
sprintf (temp,"%s/Screen Savers/%s", temp, fPref->ModuleName());
fAddonImage = load_add_on(temp);
}
}
if (addon_image<0) {
if (fAddonImage<0) {
printf ("Unable to open add-on: %s\n",temp);
printf ("add on image = %ld!\n",addon_image);
printf ("add on image = %ld!\n", fAddonImage);
return NULL;
} else {
// Look for the one C function that should exist.
status_t retVal;
if (B_OK != (retVal=get_image_symbol(addon_image, "instantiate_screen_saver", B_SYMBOL_TYPE_TEXT,(void **) &instantiate))) {
if (B_OK != (retVal=get_image_symbol(fAddonImage, "instantiate_screen_saver", B_SYMBOL_TYPE_TEXT,(void **) &instantiate))) {
printf ("Unable to find the instantiator\n");
printf ("Error = %ld\n",retVal);
return NULL;
} else
saver=instantiate(pref->GetState(pref->ModuleName()),addon_image);
if (B_OK!=saver->InitCheck()) {
fSaver = instantiate(fPref->GetState(fPref->ModuleName()), fAddonImage);
if (B_OK != fSaver->InitCheck()) {
printf ("InitCheck() Failed!\n");
unload_add_on(addon_image);
delete saver;
saver=NULL;
unload_add_on(fAddonImage);
delete fSaver;
fSaver = NULL;
return NULL;
}
}
return saver;
return fSaver;
}

View File

@ -1,44 +0,0 @@
#ifndef __CONSTANTS__
#define __CONSTANTS__
static const char *times[]={"30 seconds", "1 minute", "1 minute 30 seconds",
"2 minutes", "2 minutes 30 seconds", "3 minutes",
"4 minutes", "5 minutes", "6 minutes",
"7 minutes", "8 minutes", "9 minutes",
"10 minutes", "15 minutes", "20 minutes",
"25 minutes", "30 minutes", "40 minutes",
"50 minutes", "1 hour", "1 hour 30 minutes",
"2 hours", "2 hours 30 minutes", "3 hours",
"4 hours", "5 hours"};
static const int timeInSeconds[]={ 30, 60, 90,
120, 150, 180,
240, 300, 360,
420, 480, 540,
600, 900, 1200,
1500, 1800, 2400,
3000, 3600, 5400,
7200, 9000, 10800,
14400, 18000};
int secondsToSlider(int);
const int TAB1_CHG='TAB1';
const int TAB2_CHG='TAB2';
const int PWBUTTON='PWBT';
const int DONE_CLICKED='DONE';
const int CANCEL_CLICKED='CNCL';
const int BUTTON_CHANGED='BTNC';
const int SHOW='SHOW';
const int POPULATE='POPU';
const int UTILIZE='UTIL';
const int SAVER_SEL='SSEL';
rgb_color black = {0,0,0,0};
rgb_color darkGrey = {150,150,150,0};
rgb_color grey = {200,200,200,0};
rgb_color lightBlue = {200,200,255,0};
rgb_color lightGreen = {255,200,200,0};
rgb_color red = {255,100,100,0};
#endif

View File

@ -3,26 +3,6 @@
int secondsToSlider(int val);
static const char *kTimes[]={"30 seconds", "1 minute", "1 minute 30 seconds",
"2 minutes", "2 minutes 30 seconds", "3 minutes",
"4 minutes", "5 minutes", "6 minutes",
"7 minutes", "8 minutes", "9 minutes",
"10 minutes", "15 minutes", "20 minutes",
"25 minutes", "30 minutes", "40 minutes",
"50 minutes", "1 hour", "1 hour 30 minutes",
"2 hours", "2 hours 30 minutes", "3 hours",
"4 hours", "5 hours"};
static const int kTimeInSeconds[]={ 30, 60, 90,
120, 150, 180,
240, 300, 360,
420, 480, 540,
600, 900, 1200,
1500, 1800, 2400,
3000, 3600, 5400,
7200, 9000, 10800,
14400, 18000};
inline BPoint
scaleDirect(float x, float y,BRect area)
{

View File

@ -5,10 +5,14 @@ UsePrivateHeaders screen_saver ;
Preference ScreenSaver :
ScreenSaverPrefsApp.cpp
ScreenSaverWindow.cpp
passwordWindow.cpp
PasswordWindow.cpp
PreviewView.cpp
MouseAreaView.cpp
ScreenSaver.cpp
: libtracker.so libscreensaver.so libbe.so libstdc++.r4.so
: ScreenSaver.rdef
;
SEARCH on [ FGristFiles
ScreenSaver.cpp
] = [ FDirName $(OBOS_TOP) src kits screensaver ] ;

View File

@ -1,3 +1,8 @@
/*
* Copyright 2003, Michael Phipps. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include "MouseAreaView.h"
#include "Constants.h"
#include <Rect.h>
@ -5,6 +10,14 @@
#include <Shape.h>
#include <stdio.h>
MouseAreaView::MouseAreaView(BRect frame, const char *name)
: BView (frame,name,B_FOLLOW_NONE,B_WILL_DRAW)
{
SetViewColor(216,216,216);
fCurrentDirection = NONE;
}
void
MouseAreaView::Draw(BRect update)
{
@ -72,11 +85,13 @@ MouseAreaView::DrawArrow(void)
SetHighColor(kBlack);
FillShape(&arrow,B_SOLID_HIGH);
} else {
PushState();
BRect area(getArrowSize(fScreenArea,true));
SetHighColor(kRed);
SetPenSize(2);
StrokeEllipse(area);
StrokeLine(BPoint(area.right,area.top),BPoint(area.left,area.bottom));
PopState();
}
}

View File

@ -1,19 +1,26 @@
/*
* Copyright 2003, Michael Phipps. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef MOUSEAREAVIEW_H
#define MOUSEAREAVIEW_H
#include <View.h>
#include "ScreenSaverPrefs.h"
class MouseAreaView : public BView
{
public:
MouseAreaView(BRect frame, const char *name) : BView (frame,name,B_FOLLOW_NONE,B_WILL_DRAW)
{ SetViewColor(216,216,216);
fCurrentDirection=NONE;}
public:
MouseAreaView(BRect frame, const char *name);
virtual void Draw(BRect update);
virtual void MouseUp(BPoint point);
void DrawArrow(void);
inline arrowDirection getDirection(void) {return fCurrentDirection;}
void setDirection(arrowDirection direction) {fCurrentDirection=direction;Draw(BRect (0,0,100,100));}
private:
void DrawArrow();
inline arrowDirection getDirection(void) { return fCurrentDirection;}
void setDirection(arrowDirection direction) { fCurrentDirection = direction; Invalidate(); }
private:
BRect fScreenArea;
arrowDirection fCurrentDirection;
};
#endif // MOUSEAREAVIEW_H

View File

@ -1,36 +0,0 @@
#include <Application.h>
#include "OBOSScreenSaverPreferences.h"
#include "ScreenSaver.h"
const char *APP_SIG = "application/x-vnd.SSPreferences";
OBOSScreenSaverPreferences::OBOSScreenSaverPreferences(void) : BApplication(APP_SIG)
{
m_MainForm = new ScreenSaver();
m_MainForm->Show();
}
OBOSScreenSaverPreferences::~OBOSScreenSaverPreferences(void)
{
}
void OBOSScreenSaverPreferences::MessageReceived(BMessage *message)
{
switch(message->what)
{
case B_READY_TO_RUN:
break;
default:
{
BApplication::MessageReceived(message);
}
}
}
int main(void)
{
OBOSScreenSaverPreferences app;
app.Run();
return 0;
}

View File

@ -1,16 +0,0 @@
#ifndef _OBOSScreenSaverPreferences_H
#define _OBOSScreenSaverPreferences_H
extern const char *APP_SIG;
class OBOSScreenSaverPreferences: public BApplication {
BWindow *m_MainForm;
public:
OBOSScreenSaverPreferences(void);
virtual ~OBOSScreenSaverPreferences(void);
virtual void MessageReceived(BMessage *);
};
#endif // _OBOSScreenSaverPreferences_H

View File

@ -1,10 +1,23 @@
#include "passwordWindow.h"
/*
* Copyright 2003, Michael Phipps. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include "PasswordWindow.h"
#include <stdio.h>
#include "RadioButton.h"
#include "Alert.h"
#include <RadioButton.h>
#include <Alert.h>
PasswordWindow::PasswordWindow()
: BWindow(BRect(100,100,380,250),"",B_MODAL_WINDOW_LOOK,B_MODAL_APP_WINDOW_FEEL,B_NOT_RESIZABLE)
{
Setup();
}
void
pwWindow::setup(void)
PasswordWindow::Setup()
{
BView *owner=new BView(Bounds(),"ownerView",B_FOLLOW_NONE,B_WILL_DRAW);
owner->SetViewColor(216,216,216);
@ -33,11 +46,12 @@ pwWindow::setup(void)
owner->AddChild(fDone);
owner->AddChild(fCancel);
fDone->MakeDefault(true);
update();
Update();
}
void
pwWindow::update(void)
PasswordWindow::Update()
{
fUseNetPassword=(fUseCustom->Value()>0);
fConfirm->SetEnabled(fUseNetPassword);
@ -46,10 +60,10 @@ pwWindow::update(void)
void
pwWindow::MessageReceived(BMessage *message)
PasswordWindow::MessageReceived(BMessage *message)
{
switch(message->what) {
case kDone_clicked:
switch(message->what) {
case kDone_clicked:
if (fUseCustom->Value())
if (strcmp(fPassword->Text(),fConfirm->Text())) {
BAlert *alert=new BAlert("noMatch","Passwords don't match. Try again.","OK");
@ -64,13 +78,13 @@ pwWindow::MessageReceived(BMessage *message)
Hide();
}
break;
case kCancel_clicked:
case kCancel_clicked:
fPassword->SetText("");
fConfirm->SetText("");
Hide();
break;
case kButton_changed:
update();
Update();
break;
case kShow:
Show();
@ -90,8 +104,8 @@ pwWindow::MessageReceived(BMessage *message)
}
break;
}
default:
BWindow::MessageReceived(message);
break;
default:
BWindow::MessageReceived(message);
break;
}
}

View File

@ -1,3 +1,10 @@
/*
* Copyright 2003, Michael Phipps. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef PASSWORDWINDOW_H
#define PASSWORDWINDOW_H
#include "Window.h"
#include "CheckBox.h"
#include "String.h"
@ -6,12 +13,12 @@
#include "Button.h"
#include "Constants.h"
class pwWindow : public BWindow
class PasswordWindow : public BWindow
{
public:
pwWindow (void) : BWindow(BRect(100,100,380,250),"",B_MODAL_WINDOW_LOOK,B_MODAL_APP_WINDOW_FEEL,B_NOT_RESIZABLE) {setup();}
void setup(void);
void update(void);
PasswordWindow();
void Setup();
void Update();
virtual void MessageReceived(BMessage *message);
private:
@ -24,3 +31,5 @@ class pwWindow : public BWindow
};
#endif // PASSWORDWINDOW_H

View File

@ -1,3 +1,8 @@
/*
* Copyright 2003, Michael Phipps. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include "PreviewView.h"
#include "Constants.h"
#include <Rect.h>
@ -26,8 +31,12 @@ scale2(int x1, int x2, int y1, int y2,BRect area)
PreviewView::PreviewView(BRect frame, const char *name,ScreenSaverPrefs *prefp)
: BView (frame,name,B_FOLLOW_NONE,B_WILL_DRAW),
fSaver (NULL),fConfigView(NULL),fSst(NULL),fThreadID(-1),fPrefPtr(prefp)
: BView (frame,name,B_FOLLOW_NONE,B_WILL_DRAW),
fSaver(NULL),
fConfigView(NULL),
fSst(NULL),
fThreadID(-1),
fPrefPtr(prefp)
{
SetViewColor(216,216,216);
}
@ -45,7 +54,7 @@ PreviewView::SetScreenSaver(BString name)
{
if (fThreadID>=0) {
kill_thread(fThreadID);
fThreadID=-1;
fThreadID = -1;
}
if (fSst)
delete fSst;
@ -54,14 +63,14 @@ PreviewView::SetScreenSaver(BString name)
delete fConfigView;
}
fConfigView=new BView(scale2(1,8,1,2,Bounds()),"previewArea",B_FOLLOW_NONE,B_WILL_DRAW);
fConfigView = new BView(scale2(1,8,1,2,Bounds()),"previewArea",B_FOLLOW_NONE,B_WILL_DRAW);
fConfigView->SetViewColor(0,0,0);
AddChild(fConfigView);
fSst=new ScreenSaverThread(Window(),fConfigView,fPrefPtr);
fSaver=fSst->LoadAddOn();
fSst = new ScreenSaverThread(Window(),fConfigView,fPrefPtr);
fSaver = fSst->LoadAddOn();
if (fSaver) {
fThreadID=spawn_thread(threadFunc,"ScreenSaverRenderer",0,fSst);
fThreadID = spawn_thread(ScreenSaverThread::ThreadFunc, "ScreenSaverRenderer", B_LOW_PRIORITY, fSst);
resume_thread(fThreadID);
}
@ -82,7 +91,7 @@ PreviewView::Draw(BRect update)
SetHighColor(kBlack);
SetHighColor(184,184,184);
BRect outerShape=scale2(2,7,2,6,Bounds());
BRect outerShape = scale2(2,7,2,6,Bounds());
outerShape.InsetBy(1,1);
FillRoundRect(outerShape,4,4);// Outer shape

View File

@ -1,3 +1,11 @@
/*
* Copyright 2003, Michael Phipps. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef PREVIEWVIEW_H
#define PREVIEWVIEW_H
#include <View.h>
#include <Box.h>
#include <ScreenSaverThread.h>
@ -12,7 +20,7 @@ public:
~PreviewView();
void Draw(BRect update);
void SetScreenSaver(BString name);
BScreenSaver *ScreenSaver(void) {return fSaver;}
BScreenSaver *ScreenSaver() {return fSaver;}
private:
BScreenSaver* fSaver;
BView *fConfigView;
@ -22,3 +30,4 @@ private:
}; // end class PreviewView
#endif // PREVIEWVIEW_H

View File

@ -1,5 +1,5 @@
resource(1, "BEOS:APP_SIG") #'MIMS' "application/x-vnd.OBOS.ScreenSaver";
resource app_signature "application/x-vnd.haiku.ScreenSaver";
resource(1, "BEOS:FILE_TYPES") message;

View File

@ -1,3 +1,8 @@
/*
* Copyright 2003, Michael Phipps. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include <Application.h>
#include <unistd.h>
#include <stdio.h>
@ -6,17 +11,12 @@
#include "ScreenSaverPrefsApp.h"
const char *APP_SIG = "application/x-vnd.OBOS.ScreenSaver";
const char *APP_SIG = "application/x-vnd.haiku.ScreenSaver";
ScreenSaverPrefsApp::~ScreenSaverPrefsApp(void)
ScreenSaverPrefsApp::ScreenSaverPrefsApp() : BApplication(APP_SIG)
{
}
ScreenSaverPrefsApp::ScreenSaverPrefsApp(void) : BApplication(APP_SIG)
{
m_MainForm = new ScreenSaverWin();
m_MainForm->Show();
fScreenSaverWin = new ScreenSaverWin();
fScreenSaverWin->Show();
}
@ -33,19 +33,7 @@ ScreenSaverPrefsApp::RefsReceived(BMessage *msg)
char temp[2*B_PATH_NAME_LENGTH];
sprintf (temp,"cp %s '/boot/home/config/add-ons/Screen Savers/'\n",p.Path());
system(temp);
m_MainForm->PostMessage(new BMessage(kUpdatelist));
}
void ScreenSaverPrefsApp::MessageReceived(BMessage *message)
{
switch(message->what) {
case B_READY_TO_RUN:
break;
default: {
BApplication::MessageReceived(message);
}
}
fScreenSaverWin->PostMessage(kUpdatelist);
}

View File

@ -1,18 +1,19 @@
/*
* Copyright 2003, Michael Phipps. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _ScreenSaverPrefsApp_H
#define _ScreenSaverPrefsApp_H
#include "ScreenSaverWindow.h"
extern const char *APP_SIG;
class ScreenSaverPrefsApp: public BApplication {
private:
ScreenSaverWin *m_MainForm;
class ScreenSaverPrefsApp : public BApplication
{
public:
ScreenSaverPrefsApp(void);
virtual ~ScreenSaverPrefsApp(void);
virtual void MessageReceived(BMessage *);
virtual void RefsReceived(BMessage *);
ScreenSaverPrefsApp();
virtual void RefsReceived(BMessage *);
private:
ScreenSaverWin *fScreenSaverWin;
};
#endif // _ScreenSaverPrefsApp_H

View File

@ -1,4 +1,8 @@
#include "ScreenSaverWindow.h"
/*
* Copyright 2003, Michael Phipps. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include <ListView.h>
#include <Application.h>
#include <Button.h>
@ -14,11 +18,33 @@
#include <Slider.h>
#include <StringView.h>
#include <ScreenSaver.h>
#include "MouseAreaView.h"
#include "PreviewView.h"
#include <Roster.h>
#include <stdio.h>
#include "ScreenSaverWindow.h"
#include "MouseAreaView.h"
#include "PreviewView.h"
static const char *kTimes[]={"30 seconds", "1 minute", "1 minute 30 seconds",
"2 minutes", "2 minutes 30 seconds", "3 minutes",
"4 minutes", "5 minutes", "6 minutes",
"7 minutes", "8 minutes", "9 minutes",
"10 minutes", "15 minutes", "20 minutes",
"25 minutes", "30 minutes", "40 minutes",
"50 minutes", "1 hour", "1 hour 30 minutes",
"2 hours", "2 hours 30 minutes", "3 hours",
"4 hours", "5 hours"};
static const int kTimeInSeconds[]={ 30, 60, 90,
120, 150, 180,
240, 300, 360,
420, 480, 540,
600, 900, 1200,
1500, 1800, 2400,
3000, 3600, 5400,
7200, 9000, 10800,
14400, 18000};
const int32 zero=0;
void drawPositionalMonitor(BView *view,BRect areaToDrawIn,int state);
@ -42,6 +68,41 @@ struct SSListItem {
BString displayName;
};
ScreenSaverWin::ScreenSaverWin()
: BWindow(BRect(50,50,500,385),"OBOS Screen Saver Preferences",
B_TITLED_WINDOW,B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE) ,
fFadeState(0),fNoFadeState(0),
fSampleView(NULL),
fTab1(NULL),fTab2(NULL),
fTabView(NULL), fModuleSettingsBox(NULL),
fPreviewDisplay(NULL), fListView1(NULL),
fAddonList(NULL), fSelectedAddonFileName(NULL),
fCurrentAddon(NULL), fTestButton(NULL),
fAddButton(NULL), fEnableScreenSaverBox(NULL),
fPasswordSlider(NULL), fTurnOffSlider(NULL),
fRunSlider(NULL), fStringView1(NULL),
fEnableCheckbox(NULL), fPasswordCheckbox(NULL),
fTurnOffScreenCheckBox(NULL),
fTurnOffMinutes(NULL), fRunMinutes(NULL),
fPasswordMinutes(NULL), fPasswordButton(NULL),
fFadeNowString(NULL),
fFadeNowString2(NULL),
fDontFadeString(NULL), fDontFadeString2(NULL),
fFadeNow(NULL),fFadeNever(NULL),
fPwWin(NULL),
fPwMessenger(NULL), fFilePanel(NULL) ,
fSettingsArea(NULL)
{
SetupForm();
}
ScreenSaverWin::~ScreenSaverWin()
{
}
void
ScreenSaverWin::SaverSelected(void)
{
@ -88,10 +149,10 @@ ScreenSaverWin::MessageReceived(BMessage *msg)
fFilePanel->Show();
break;
case kUpdatelist:
populateScreenSaverList();
PopulateScreenSaverList();
break;
}
updateStatus(); // This could get called sometimes when it doesn't need to. Shouldn't hurt
UpdateStatus(); // This could get called sometimes when it doesn't need to. Shouldn't hurt
BWindow::MessageReceived(msg);
}
@ -99,14 +160,14 @@ ScreenSaverWin::MessageReceived(BMessage *msg)
bool
ScreenSaverWin::QuitRequested()
{
updateStatus();
UpdateStatus();
be_app->PostMessage(B_QUIT_REQUESTED);
return(true);
}
void
ScreenSaverWin::updateStatus(void)
ScreenSaverWin::UpdateStatus(void)
{
DisableUpdates();
// Policy - enable and disable controls as per checkboxes, etc
@ -141,23 +202,21 @@ ScreenSaverWin::updateStatus(void)
// TODO - Tell the password window to update its stuff
BMessage ssState;
if ((fPreviewDisplay->ScreenSaver()) && (fPreviewDisplay->ScreenSaver()->SaveState(&ssState)==B_OK))
fPrefs.SetState(&ssState);
fPrefs.SetState(fPrefs.ModuleName(), &ssState);
fPrefs.SaveSettings();
};
void
ScreenSaverWin::SetupForm(void)
ScreenSaverWin::SetupForm()
{
fFilePanel=new BFilePanel();
BRect r;
BView *background;
BRect r = Bounds();
BTab *tab;
r = Bounds();
// Create a background view
background=new BView(r,"background",B_FOLLOW_NONE,0);
BView *background = new BView(r,"background",B_FOLLOW_NONE,0);
background->SetViewColor(216,216,216,0);
AddChild(background);
@ -182,16 +241,16 @@ ScreenSaverWin::SetupForm(void)
background->AddChild(fTabView);
// Create the controls inside the tabs
setupTab2();
setupTab1();
SetupTab2();
SetupTab1();
// Create the password editing window
fPwWin=new pwWindow;
fPwMessenger=new BMessenger (NULL,fPwWin);
fPwWin = new PasswordWindow();
fPwMessenger = new BMessenger(NULL,fPwWin);
fPwWin->Run();
MoveTo(fPrefs.WindowFrame().left,fPrefs.WindowFrame().top);
ResizeTo(fPrefs.WindowFrame().right-fPrefs.WindowFrame().left,fPrefs.WindowFrame().bottom-fPrefs.WindowFrame().top);
//ResizeTo(fPrefs.WindowFrame().right-fPrefs.WindowFrame().left,fPrefs.WindowFrame().bottom-fPrefs.WindowFrame().top);
fTabView->Select(fPrefs.WindowTab());
fEnableCheckbox->SetValue(fPrefs.TimeFlags());
fRunSlider->SetValue(secondsToSlider(fPrefs.BlankTime()));
@ -210,7 +269,7 @@ ScreenSaverWin::SetupForm(void)
fListView1->ScrollToSelection();
}
}
updateStatus();
UpdateStatus();
}
@ -272,7 +331,7 @@ addScreenSaversToList (directory_which dir, BList *list)
// sorting function for SSListItems
int
compareSSListItems(const void* left, const void* right)
ScreenSaverWin::CompareSSListItems(const void* left, const void* right)
{
SSListItem* leftItem = *(SSListItem **)left;
SSListItem* rightItem = *(SSListItem **)right;
@ -282,7 +341,7 @@ compareSSListItems(const void* left, const void* right)
void
ScreenSaverWin::populateScreenSaverList(void)
ScreenSaverWin::PopulateScreenSaverList(void)
{
if (!fAddonList)
fAddonList = new BList;
@ -296,7 +355,7 @@ ScreenSaverWin::populateScreenSaverList(void)
fAddonList->AddItem(tempListItem);
addScreenSaversToList( B_BEOS_ADDONS_DIRECTORY, fAddonList );
addScreenSaversToList( B_USER_ADDONS_DIRECTORY, fAddonList );
fAddonList->SortItems(compareSSListItems);
fAddonList->SortItems(CompareSSListItems);
// Add the strings in the BList to a BListView
fListView1->DeselectAll();
@ -313,7 +372,7 @@ ScreenSaverWin::populateScreenSaverList(void)
// Create the controls for the first tab
void
ScreenSaverWin::setupTab1(void)
ScreenSaverWin::SetupTab1()
{
int columns[4]={15,150,180,430};
int rows[6]={15,120,135,255,263,280};
@ -341,13 +400,13 @@ ScreenSaverWin::setupTab1(void)
fAddButton->SetLabel("Add...");
fTab1->AddChild(fPreviewDisplay = new PreviewView(BRect(columns[0]+5,rows[0],columns[1],rows[1]),"preview",&fPrefs));
populateScreenSaverList();
PopulateScreenSaverList();
}
// Create the controls for the second tab
void
ScreenSaverWin::setupTab2(void)
ScreenSaverWin::SetupTab2()
{
font_height stdFontHt;
be_plain_font->GetHeight(&stdFontHt);

View File

@ -1,9 +1,13 @@
#ifndef _ScreenSaver_H
#define _ScreenSaver_H
/*
* Copyright 2003, Michael Phipps. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _ScreenSaverWindow_H
#define _ScreenSaverWindow_H
#include <FilePanel.h>
#include <Picture.h>
#include "Constants.h"
#include "passwordWindow.h"
#include "PasswordWindow.h"
#include "ScreenSaverPrefs.h"
class MouseAreaView;
@ -11,42 +15,21 @@ class PreviewView;
class ScreenSaverWin: public BWindow {
public:
ScreenSaverWin(void) : BWindow(BRect(50,50,500,385),"OBOS Screen Saver Preferences",B_TITLED_WINDOW,B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE) ,
fFadeState(0),fNoFadeState(0),
fSampleView(NULL),
fTab1(NULL),fTab2(NULL),
fTabView(NULL), fModuleSettingsBox(NULL),
fPreviewDisplay(NULL), fListView1(NULL),
fAddonList(NULL), fSelectedAddonFileName(NULL),
fCurrentAddon(NULL), fTestButton(NULL),
fAddButton(NULL), fEnableScreenSaverBox(NULL),
fPasswordSlider(NULL), fTurnOffSlider(NULL),
fRunSlider(NULL), fStringView1(NULL),
fEnableCheckbox(NULL), fPasswordCheckbox(NULL),
fTurnOffScreenCheckBox(NULL),
fTurnOffMinutes(NULL), fRunMinutes(NULL),
fPasswordMinutes(NULL), fPasswordButton(NULL),
fFadeNowString(NULL),
fFadeNowString2(NULL),
fDontFadeString(NULL), fDontFadeString2(NULL),
fFadeNow(NULL),fFadeNever(NULL),
fPwWin(NULL),
fPwMessenger(NULL), fFilePanel(NULL) ,
fSettingsArea(NULL) {
SetupForm();
}
ScreenSaverWin();
virtual void MessageReceived(BMessage *message);
virtual bool QuitRequested(void);
void populateScreenSaverList(void);
void LoadSettings(void);
virtual ~ScreenSaverWin(void) {};
virtual bool QuitRequested();
void PopulateScreenSaverList();
void LoadSettings();
virtual ~ScreenSaverWin();
private:
void SetupForm(void);
void setupTab1(void);
void setupTab2(void);
void updateStatus(void);
void SaverSelected(void);
void SetupForm();
void SetupTab1();
void SetupTab2();
void UpdateStatus();
void SaverSelected();
static int CompareSSListItems(const void* left, const void* right);
ScreenSaverPrefs fPrefs;
int fFadeState,fNoFadeState;
@ -82,7 +65,7 @@ private:
BStringView *fDontFadeString2;
BPicture fSamplePicture;
MouseAreaView *fFadeNow,*fFadeNever;
pwWindow *fPwWin;
PasswordWindow *fPwWin;
BMessenger *fPwMessenger;
BMessage fSettings;
@ -90,4 +73,4 @@ private:
BView *fSettingsArea;
};
#endif // _ScreenSaver_H
#endif // _ScreenSaverWindow_H

View File

@ -1,100 +0,0 @@
#include "pwWindow.h"
#include <stdio.h>
#include "RadioButton.h"
#include "Alert.h"
void pwWindow::setup(void)
{
BView *owner=new BView(Bounds(),"ownerView",B_FOLLOW_NONE,B_WILL_DRAW);
owner->SetViewColor(216,216,216);
AddChild(owner);
useNetwork=new BRadioButton(BRect(15,10,160,20),"useNetwork","Use Network password",new BMessage(BUTTON_CHANGED),B_FOLLOW_NONE);
useNetwork->SetValue(1);
owner->AddChild(useNetwork);
useCustom=new BRadioButton(BRect(30,50,130,60),"useCustom","Use custom password",new BMessage(BUTTON_CHANGED),B_FOLLOW_NONE);
customBox=new BBox(BRect(10,30,270,105),"custBeBox",B_FOLLOW_NONE);
customBox->SetLabel(useCustom);
password=new BTextControl(BRect(10,20,250,35),"pwdCntrl","Password:",NULL,B_FOLLOW_NONE);
confirm=new BTextControl(BRect(10,45,250,60),"confirmCntrl","Confirm password:",NULL,B_FOLLOW_NONE);
password->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT);
password->SetDivider(90);
password->TextView()->HideTyping(true);
confirm->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT);
confirm->SetDivider(90);
confirm->TextView()->HideTyping(true);
customBox->AddChild(password);
customBox->AddChild(confirm);
owner->AddChild(customBox);
done=new BButton(BRect(200,120,275,130),"done","Done",new BMessage (DONE_CLICKED),B_FOLLOW_NONE);
cancel=new BButton(BRect(115,120,190,130),"cancel","Cancel",new BMessage (CANCEL_CLICKED),B_FOLLOW_NONE);
owner->AddChild(done);
owner->AddChild(cancel);
done->MakeDefault(true);
update();
}
void pwWindow::update(void)
{
useNetPassword=(useCustom->Value()>0);
confirm->SetEnabled(useNetPassword);
password->SetEnabled(useNetPassword);
}
void pwWindow::MessageReceived(BMessage *message)
{
switch(message->what)
{
case DONE_CLICKED:
if (useCustom->Value())
if (strcmp(password->Text(),confirm->Text()))
{
BAlert *alert=new BAlert("noMatch","Passwords don't match. Try again.","OK");
alert->Go();
}
else
{
thePassword=password->Text();
Hide();
}
else
{
password->SetText("");
confirm->SetText("");
Hide();
}
break;
case CANCEL_CLICKED:
password->SetText("");
confirm->SetText("");
Hide();
break;
case BUTTON_CHANGED:
update();
break;
case SHOW:
Show();
break;
case POPULATE:
message->ReplaceString("lockpassword", ((useNetPassword)?"":thePassword));
message->ReplaceString("lockmethod", (useNetPassword?"network":"custom"));
message->SendReply(message);
break;
case UTILIZE:
{
BString temp;
message->FindString("lockmethod",&temp);
useNetPassword=(temp=="custom");
if (!useNetPassword)
{
message->FindString("lockpassword",&temp);
thePassword=temp;
}
break;
}
default:
BWindow::MessageReceived(message);
break;
}
}

View File

@ -1,26 +0,0 @@
#include "Window.h"
#include "CheckBox.h"
#include "String.h"
#include "Box.h"
#include "TextControl.h"
#include "Button.h"
#include "Constants.h"
class pwWindow : public BWindow
{
public:
pwWindow (void) : BWindow(BRect(100,100,380,250),"",B_MODAL_WINDOW_LOOK,B_MODAL_APP_WINDOW_FEEL,B_NOT_RESIZABLE) {setup();}
void setup(void);
void update(void);
virtual void MessageReceived(BMessage *message);
private:
BRadioButton *useNetwork,*useCustom;
BBox *customBox;
BTextControl *password,*confirm;
BButton *cancel,*done;
BString thePassword;
bool useNetPassword;
};