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

View File

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

View File

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

View File

@ -5,10 +5,14 @@ UsePrivateHeaders screen_saver ;
Preference ScreenSaver : Preference ScreenSaver :
ScreenSaverPrefsApp.cpp ScreenSaverPrefsApp.cpp
ScreenSaverWindow.cpp ScreenSaverWindow.cpp
passwordWindow.cpp PasswordWindow.cpp
PreviewView.cpp PreviewView.cpp
MouseAreaView.cpp MouseAreaView.cpp
ScreenSaver.cpp
: libtracker.so libscreensaver.so libbe.so libstdc++.r4.so : libtracker.so libscreensaver.so libbe.so libstdc++.r4.so
: ScreenSaver.rdef : 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 "MouseAreaView.h"
#include "Constants.h" #include "Constants.h"
#include <Rect.h> #include <Rect.h>
@ -5,6 +10,14 @@
#include <Shape.h> #include <Shape.h>
#include <stdio.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 void
MouseAreaView::Draw(BRect update) MouseAreaView::Draw(BRect update)
{ {
@ -72,11 +85,13 @@ MouseAreaView::DrawArrow(void)
SetHighColor(kBlack); SetHighColor(kBlack);
FillShape(&arrow,B_SOLID_HIGH); FillShape(&arrow,B_SOLID_HIGH);
} else { } else {
PushState();
BRect area(getArrowSize(fScreenArea,true)); BRect area(getArrowSize(fScreenArea,true));
SetHighColor(kRed); SetHighColor(kRed);
SetPenSize(2); SetPenSize(2);
StrokeEllipse(area); StrokeEllipse(area);
StrokeLine(BPoint(area.right,area.top),BPoint(area.left,area.bottom)); 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 <View.h>
#include "ScreenSaverPrefs.h" #include "ScreenSaverPrefs.h"
class MouseAreaView : public BView class MouseAreaView : public BView
{ {
public: public:
MouseAreaView(BRect frame, const char *name) : BView (frame,name,B_FOLLOW_NONE,B_WILL_DRAW) MouseAreaView(BRect frame, const char *name);
{ SetViewColor(216,216,216);
fCurrentDirection=NONE;}
virtual void Draw(BRect update); virtual void Draw(BRect update);
virtual void MouseUp(BPoint point); virtual void MouseUp(BPoint point);
void DrawArrow(void); void DrawArrow();
inline arrowDirection getDirection(void) {return fCurrentDirection;} inline arrowDirection getDirection(void) { return fCurrentDirection;}
void setDirection(arrowDirection direction) {fCurrentDirection=direction;Draw(BRect (0,0,100,100));} void setDirection(arrowDirection direction) { fCurrentDirection = direction; Invalidate(); }
private: private:
BRect fScreenArea; BRect fScreenArea;
arrowDirection fCurrentDirection; 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 <stdio.h>
#include "RadioButton.h" #include <RadioButton.h>
#include "Alert.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 void
pwWindow::setup(void) PasswordWindow::Setup()
{ {
BView *owner=new BView(Bounds(),"ownerView",B_FOLLOW_NONE,B_WILL_DRAW); BView *owner=new BView(Bounds(),"ownerView",B_FOLLOW_NONE,B_WILL_DRAW);
owner->SetViewColor(216,216,216); owner->SetViewColor(216,216,216);
@ -33,11 +46,12 @@ pwWindow::setup(void)
owner->AddChild(fDone); owner->AddChild(fDone);
owner->AddChild(fCancel); owner->AddChild(fCancel);
fDone->MakeDefault(true); fDone->MakeDefault(true);
update(); Update();
} }
void void
pwWindow::update(void) PasswordWindow::Update()
{ {
fUseNetPassword=(fUseCustom->Value()>0); fUseNetPassword=(fUseCustom->Value()>0);
fConfirm->SetEnabled(fUseNetPassword); fConfirm->SetEnabled(fUseNetPassword);
@ -46,10 +60,10 @@ pwWindow::update(void)
void void
pwWindow::MessageReceived(BMessage *message) PasswordWindow::MessageReceived(BMessage *message)
{ {
switch(message->what) { switch(message->what) {
case kDone_clicked: case kDone_clicked:
if (fUseCustom->Value()) if (fUseCustom->Value())
if (strcmp(fPassword->Text(),fConfirm->Text())) { if (strcmp(fPassword->Text(),fConfirm->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");
@ -64,13 +78,13 @@ pwWindow::MessageReceived(BMessage *message)
Hide(); Hide();
} }
break; break;
case kCancel_clicked: case kCancel_clicked:
fPassword->SetText(""); fPassword->SetText("");
fConfirm->SetText(""); fConfirm->SetText("");
Hide(); Hide();
break; break;
case kButton_changed: case kButton_changed:
update(); Update();
break; break;
case kShow: case kShow:
Show(); Show();
@ -90,8 +104,8 @@ pwWindow::MessageReceived(BMessage *message)
} }
break; break;
} }
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
break; 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 "Window.h"
#include "CheckBox.h" #include "CheckBox.h"
#include "String.h" #include "String.h"
@ -6,12 +13,12 @@
#include "Button.h" #include "Button.h"
#include "Constants.h" #include "Constants.h"
class pwWindow : public BWindow class PasswordWindow : public BWindow
{ {
public: public:
pwWindow (void) : BWindow(BRect(100,100,380,250),"",B_MODAL_WINDOW_LOOK,B_MODAL_APP_WINDOW_FEEL,B_NOT_RESIZABLE) {setup();} PasswordWindow();
void setup(void); void Setup();
void update(void); void Update();
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
private: 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 "PreviewView.h"
#include "Constants.h" #include "Constants.h"
#include <Rect.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) PreviewView::PreviewView(BRect frame, const char *name,ScreenSaverPrefs *prefp)
: BView (frame,name,B_FOLLOW_NONE,B_WILL_DRAW), : BView (frame,name,B_FOLLOW_NONE,B_WILL_DRAW),
fSaver (NULL),fConfigView(NULL),fSst(NULL),fThreadID(-1),fPrefPtr(prefp) fSaver(NULL),
fConfigView(NULL),
fSst(NULL),
fThreadID(-1),
fPrefPtr(prefp)
{ {
SetViewColor(216,216,216); SetViewColor(216,216,216);
} }
@ -45,7 +54,7 @@ PreviewView::SetScreenSaver(BString name)
{ {
if (fThreadID>=0) { if (fThreadID>=0) {
kill_thread(fThreadID); kill_thread(fThreadID);
fThreadID=-1; fThreadID = -1;
} }
if (fSst) if (fSst)
delete fSst; delete fSst;
@ -54,14 +63,14 @@ PreviewView::SetScreenSaver(BString name)
delete fConfigView; 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); fConfigView->SetViewColor(0,0,0);
AddChild(fConfigView); AddChild(fConfigView);
fSst=new ScreenSaverThread(Window(),fConfigView,fPrefPtr); fSst = new ScreenSaverThread(Window(),fConfigView,fPrefPtr);
fSaver=fSst->LoadAddOn(); fSaver = fSst->LoadAddOn();
if (fSaver) { if (fSaver) {
fThreadID=spawn_thread(threadFunc,"ScreenSaverRenderer",0,fSst); fThreadID = spawn_thread(ScreenSaverThread::ThreadFunc, "ScreenSaverRenderer", B_LOW_PRIORITY, fSst);
resume_thread(fThreadID); resume_thread(fThreadID);
} }
@ -82,7 +91,7 @@ PreviewView::Draw(BRect update)
SetHighColor(kBlack); SetHighColor(kBlack);
SetHighColor(184,184,184); SetHighColor(184,184,184);
BRect outerShape=scale2(2,7,2,6,Bounds()); BRect outerShape = scale2(2,7,2,6,Bounds());
outerShape.InsetBy(1,1); outerShape.InsetBy(1,1);
FillRoundRect(outerShape,4,4);// Outer shape 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 <View.h>
#include <Box.h> #include <Box.h>
#include <ScreenSaverThread.h> #include <ScreenSaverThread.h>
@ -12,7 +20,7 @@ public:
~PreviewView(); ~PreviewView();
void Draw(BRect update); void Draw(BRect update);
void SetScreenSaver(BString name); void SetScreenSaver(BString name);
BScreenSaver *ScreenSaver(void) {return fSaver;} BScreenSaver *ScreenSaver() {return fSaver;}
private: private:
BScreenSaver* fSaver; BScreenSaver* fSaver;
BView *fConfigView; BView *fConfigView;
@ -22,3 +30,4 @@ private:
}; // end class PreviewView }; // 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; 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 <Application.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
@ -6,17 +11,12 @@
#include "ScreenSaverPrefsApp.h" #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)
{ {
} fScreenSaverWin = new ScreenSaverWin();
fScreenSaverWin->Show();
ScreenSaverPrefsApp::ScreenSaverPrefsApp(void) : BApplication(APP_SIG)
{
m_MainForm = new ScreenSaverWin();
m_MainForm->Show();
} }
@ -33,19 +33,7 @@ ScreenSaverPrefsApp::RefsReceived(BMessage *msg)
char temp[2*B_PATH_NAME_LENGTH]; char temp[2*B_PATH_NAME_LENGTH];
sprintf (temp,"cp %s '/boot/home/config/add-ons/Screen Savers/'\n",p.Path()); sprintf (temp,"cp %s '/boot/home/config/add-ons/Screen Savers/'\n",p.Path());
system(temp); system(temp);
m_MainForm->PostMessage(new BMessage(kUpdatelist)); fScreenSaverWin->PostMessage(kUpdatelist);
}
void ScreenSaverPrefsApp::MessageReceived(BMessage *message)
{
switch(message->what) {
case B_READY_TO_RUN:
break;
default: {
BApplication::MessageReceived(message);
}
}
} }

View File

@ -1,18 +1,19 @@
/*
* Copyright 2003, Michael Phipps. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _ScreenSaverPrefsApp_H #ifndef _ScreenSaverPrefsApp_H
#define _ScreenSaverPrefsApp_H #define _ScreenSaverPrefsApp_H
#include "ScreenSaverWindow.h" #include "ScreenSaverWindow.h"
extern const char *APP_SIG; class ScreenSaverPrefsApp : public BApplication
{
class ScreenSaverPrefsApp: public BApplication {
private:
ScreenSaverWin *m_MainForm;
public: public:
ScreenSaverPrefsApp(void); ScreenSaverPrefsApp();
virtual ~ScreenSaverPrefsApp(void); virtual void RefsReceived(BMessage *);
virtual void MessageReceived(BMessage *); private:
virtual void RefsReceived(BMessage *); ScreenSaverWin *fScreenSaverWin;
}; };
#endif // _ScreenSaverPrefsApp_H #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 <ListView.h>
#include <Application.h> #include <Application.h>
#include <Button.h> #include <Button.h>
@ -14,11 +18,33 @@
#include <Slider.h> #include <Slider.h>
#include <StringView.h> #include <StringView.h>
#include <ScreenSaver.h> #include <ScreenSaver.h>
#include "MouseAreaView.h"
#include "PreviewView.h"
#include <Roster.h> #include <Roster.h>
#include <stdio.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; const int32 zero=0;
void drawPositionalMonitor(BView *view,BRect areaToDrawIn,int state); void drawPositionalMonitor(BView *view,BRect areaToDrawIn,int state);
@ -42,6 +68,41 @@ struct SSListItem {
BString displayName; 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 void
ScreenSaverWin::SaverSelected(void) ScreenSaverWin::SaverSelected(void)
{ {
@ -88,10 +149,10 @@ ScreenSaverWin::MessageReceived(BMessage *msg)
fFilePanel->Show(); fFilePanel->Show();
break; break;
case kUpdatelist: case kUpdatelist:
populateScreenSaverList(); PopulateScreenSaverList();
break; 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); BWindow::MessageReceived(msg);
} }
@ -99,14 +160,14 @@ ScreenSaverWin::MessageReceived(BMessage *msg)
bool bool
ScreenSaverWin::QuitRequested() ScreenSaverWin::QuitRequested()
{ {
updateStatus(); UpdateStatus();
be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED);
return(true); return(true);
} }
void void
ScreenSaverWin::updateStatus(void) ScreenSaverWin::UpdateStatus(void)
{ {
DisableUpdates(); DisableUpdates();
// Policy - enable and disable controls as per checkboxes, etc // 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 // TODO - Tell the password window to update its stuff
BMessage ssState; BMessage ssState;
if ((fPreviewDisplay->ScreenSaver()) && (fPreviewDisplay->ScreenSaver()->SaveState(&ssState)==B_OK)) if ((fPreviewDisplay->ScreenSaver()) && (fPreviewDisplay->ScreenSaver()->SaveState(&ssState)==B_OK))
fPrefs.SetState(&ssState); fPrefs.SetState(fPrefs.ModuleName(), &ssState);
fPrefs.SaveSettings(); fPrefs.SaveSettings();
}; };
void void
ScreenSaverWin::SetupForm(void) ScreenSaverWin::SetupForm()
{ {
fFilePanel=new BFilePanel(); fFilePanel=new BFilePanel();
BRect r; BRect r = Bounds();
BView *background;
BTab *tab; BTab *tab;
r = Bounds();
// Create a background view // 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); background->SetViewColor(216,216,216,0);
AddChild(background); AddChild(background);
@ -182,16 +241,16 @@ ScreenSaverWin::SetupForm(void)
background->AddChild(fTabView); background->AddChild(fTabView);
// Create the controls inside the tabs // Create the controls inside the tabs
setupTab2(); SetupTab2();
setupTab1(); SetupTab1();
// Create the password editing window // Create the password editing window
fPwWin=new pwWindow; fPwWin = new PasswordWindow();
fPwMessenger=new BMessenger (NULL,fPwWin); fPwMessenger = new BMessenger(NULL,fPwWin);
fPwWin->Run(); fPwWin->Run();
MoveTo(fPrefs.WindowFrame().left,fPrefs.WindowFrame().top); 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()); fTabView->Select(fPrefs.WindowTab());
fEnableCheckbox->SetValue(fPrefs.TimeFlags()); fEnableCheckbox->SetValue(fPrefs.TimeFlags());
fRunSlider->SetValue(secondsToSlider(fPrefs.BlankTime())); fRunSlider->SetValue(secondsToSlider(fPrefs.BlankTime()));
@ -210,7 +269,7 @@ ScreenSaverWin::SetupForm(void)
fListView1->ScrollToSelection(); fListView1->ScrollToSelection();
} }
} }
updateStatus(); UpdateStatus();
} }
@ -272,7 +331,7 @@ addScreenSaversToList (directory_which dir, BList *list)
// sorting function for SSListItems // sorting function for SSListItems
int int
compareSSListItems(const void* left, const void* right) ScreenSaverWin::CompareSSListItems(const void* left, const void* right)
{ {
SSListItem* leftItem = *(SSListItem **)left; SSListItem* leftItem = *(SSListItem **)left;
SSListItem* rightItem = *(SSListItem **)right; SSListItem* rightItem = *(SSListItem **)right;
@ -282,7 +341,7 @@ compareSSListItems(const void* left, const void* right)
void void
ScreenSaverWin::populateScreenSaverList(void) ScreenSaverWin::PopulateScreenSaverList(void)
{ {
if (!fAddonList) if (!fAddonList)
fAddonList = new BList; fAddonList = new BList;
@ -296,7 +355,7 @@ ScreenSaverWin::populateScreenSaverList(void)
fAddonList->AddItem(tempListItem); fAddonList->AddItem(tempListItem);
addScreenSaversToList( B_BEOS_ADDONS_DIRECTORY, fAddonList ); addScreenSaversToList( B_BEOS_ADDONS_DIRECTORY, fAddonList );
addScreenSaversToList( B_USER_ADDONS_DIRECTORY, fAddonList ); addScreenSaversToList( B_USER_ADDONS_DIRECTORY, fAddonList );
fAddonList->SortItems(compareSSListItems); fAddonList->SortItems(CompareSSListItems);
// Add the strings in the BList to a BListView // Add the strings in the BList to a BListView
fListView1->DeselectAll(); fListView1->DeselectAll();
@ -313,7 +372,7 @@ ScreenSaverWin::populateScreenSaverList(void)
// Create the controls for the first tab // Create the controls for the first tab
void void
ScreenSaverWin::setupTab1(void) ScreenSaverWin::SetupTab1()
{ {
int columns[4]={15,150,180,430}; int columns[4]={15,150,180,430};
int rows[6]={15,120,135,255,263,280}; int rows[6]={15,120,135,255,263,280};
@ -341,13 +400,13 @@ ScreenSaverWin::setupTab1(void)
fAddButton->SetLabel("Add..."); fAddButton->SetLabel("Add...");
fTab1->AddChild(fPreviewDisplay = new PreviewView(BRect(columns[0]+5,rows[0],columns[1],rows[1]),"preview",&fPrefs)); 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 // Create the controls for the second tab
void void
ScreenSaverWin::setupTab2(void) ScreenSaverWin::SetupTab2()
{ {
font_height stdFontHt; font_height stdFontHt;
be_plain_font->GetHeight(&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 <FilePanel.h>
#include <Picture.h> #include <Picture.h>
#include "Constants.h" #include "PasswordWindow.h"
#include "passwordWindow.h"
#include "ScreenSaverPrefs.h" #include "ScreenSaverPrefs.h"
class MouseAreaView; class MouseAreaView;
@ -11,42 +15,21 @@ class PreviewView;
class ScreenSaverWin: public BWindow { class ScreenSaverWin: public BWindow {
public: 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) , ScreenSaverWin();
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();
}
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
virtual bool QuitRequested(void); virtual bool QuitRequested();
void populateScreenSaverList(void); void PopulateScreenSaverList();
void LoadSettings(void); void LoadSettings();
virtual ~ScreenSaverWin(void) {}; virtual ~ScreenSaverWin();
private: private:
void SetupForm(void); void SetupForm();
void setupTab1(void); void SetupTab1();
void setupTab2(void); void SetupTab2();
void updateStatus(void); void UpdateStatus();
void SaverSelected(void); void SaverSelected();
static int CompareSSListItems(const void* left, const void* right);
ScreenSaverPrefs fPrefs; ScreenSaverPrefs fPrefs;
int fFadeState,fNoFadeState; int fFadeState,fNoFadeState;
@ -82,7 +65,7 @@ private:
BStringView *fDontFadeString2; BStringView *fDontFadeString2;
BPicture fSamplePicture; BPicture fSamplePicture;
MouseAreaView *fFadeNow,*fFadeNever; MouseAreaView *fFadeNow,*fFadeNever;
pwWindow *fPwWin; PasswordWindow *fPwWin;
BMessenger *fPwMessenger; BMessenger *fPwMessenger;
BMessage fSettings; BMessage fSettings;
@ -90,4 +73,4 @@ private:
BView *fSettingsArea; 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;
};