Last round of functionality changes.

"Add" and "test" now work. Be warned - without the input server addon running (and maybe even with), testing will cause the ScreenSaver to run but not to turn off. The way out of this is to alt-f# to a different workspace and kill "OpenBeOS ScreenSaver".

As far as I know, all functionality now in place and working properly. Needs a good workout.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7257 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Phipps 2004-04-20 02:05:24 +00:00
parent 730036e22e
commit 048f424d11
7 changed files with 276 additions and 209 deletions

View File

@ -33,6 +33,9 @@ const int SHOW ='SHOW';
const int POPULATE ='POPU';
const int UTILIZE ='UTIL';
const int SAVER_SEL ='SSEL';
const int TEST_BTN ='TEST';
const int ADD_BTN ='ADD ';
const int UPDATELIST ='UPDL';
const rgb_color black = {0,0,0,0};
const rgb_color darkGrey = {150,150,150,0};

View File

@ -12,7 +12,7 @@ local sources =
Preference ScreenSaver : $(sources) ;
LinkSharedOSLibs ScreenSaver : libscreensaver.so be stdc++.r4 ;
LinkSharedOSLibs ScreenSaver : tracker libscreensaver.so be stdc++.r4 ;
# Ugly hack: Prepend the dir containing Be's ScreenSaver.h to the list of
# include search dirs. Otherwise it won't be found.

View File

@ -29,6 +29,8 @@ PreviewView::PreviewView(BRect frame, const char *name,ScreenSaverPrefs *prefp)
}
PreviewView::~PreviewView() {
if (threadID)
kill_thread(threadID);
}
void PreviewView::SetScreenSaver(BString name) {
@ -47,9 +49,11 @@ void PreviewView::SetScreenSaver(BString name) {
sst=new ScreenSaverThread(Window(),configView,prefPtr);
saver=sst->LoadAddOn();
if (saver) {
threadID=spawn_thread(threadFunc,"ScreenSaverRenderer",0,sst);
resume_thread(threadID);
}
}
void PreviewView::Draw(BRect update) {
SetViewColor(216,216,216);

View File

@ -1,4 +1,7 @@
#include <Application.h>
#include <unistd.h>
#include <stdio.h>
#include <Path.h>
#include "ScreenSaverPrefsApp.h"
@ -12,6 +15,20 @@ ScreenSaverPrefsApp::ScreenSaverPrefsApp(void) : BApplication(APP_SIG) {
m_MainForm->Show();
}
void ScreenSaverPrefsApp::RefsReceived(BMessage *msg) {
entry_ref ref;
BEntry e;
BPath p;
msg->FindRef("refs", &ref);
e.SetTo(&ref, true);
e.GetPath(&p);
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(UPDATELIST));
}
void ScreenSaverPrefsApp::MessageReceived(BMessage *message) {
switch(message->what) {
case B_READY_TO_RUN:

View File

@ -11,6 +11,7 @@ public:
ScreenSaverPrefsApp(void);
virtual ~ScreenSaverPrefsApp(void);
virtual void MessageReceived(BMessage *);
virtual void RefsReceived(BMessage *);
};

View File

@ -16,8 +16,11 @@
#include <ScreenSaver.h>
#include "MouseAreaView.h"
#include "PreviewView.h"
#include <Roster.h>
#include <stdio.h>
const int32 zero=0;
void drawPositionalMonitor(BView *view,BRect areaToDrawIn,int state);
BView *drawSampleMonitor(BView *view, BRect area);
@ -26,16 +29,9 @@ struct SSListItem {
BString displayName;
};
void ScreenSaverWin::MessageReceived(BMessage *msg) {
void ScreenSaverWin::SaverSelected(void) {
if (ListView1->CurrentSelection()>=0) {
SSListItem* listItem;
switch(msg->what) {
case PWBUTTON:
pwMessenger->SendMessage(SHOW);
break;
case B_QUIT_REQUESTED:
be_app->PostMessage(B_QUIT_REQUESTED);
break;
case SAVER_SEL:
if (previewDisplay->ScreenSaver())
previewDisplay->ScreenSaver()->StopConfig();
listItem = reinterpret_cast<SSListItem*>(AddonList->ItemAt(ListView1->CurrentSelection()));
@ -53,6 +49,28 @@ void ScreenSaverWin::MessageReceived(BMessage *msg) {
if (previewDisplay->ScreenSaver())
previewDisplay->ScreenSaver()->StartConfig(settingsArea);
}
}
void ScreenSaverWin::MessageReceived(BMessage *msg) {
switch(msg->what) {
case PWBUTTON:
pwMessenger->SendMessage(SHOW);
break;
case B_QUIT_REQUESTED:
be_app->PostMessage(B_QUIT_REQUESTED);
break;
case SAVER_SEL:
SaverSelected();
break;
case TEST_BTN:
be_roster->Launch("application/x-vnd.OBOS-ScreenSaverApp",prefs.GetSettings());
break;
case ADD_BTN:
filePanel->Show();
break;
case UPDATELIST:
populateScreenSaverList();
break;
}
updateStatus(); // This could get called sometimes when it doesn't need to. Shouldn't hurt
@ -98,10 +116,16 @@ void ScreenSaverWin::updateStatus(void) {
if (selection>=0)
prefs.SetModuleName(((BStringItem *)(ListView1->ItemAt(selection)))->Text());
// TODO - Tell the password window to update its stuff
BMessage ssState;
if ((previewDisplay->ScreenSaver()) && (previewDisplay->ScreenSaver()->SaveState(&ssState)==B_OK))
prefs.SetState(&ssState);
prefs.SaveSettings();
};
void ScreenSaverWin::SetupForm(void) {
filePanel=new BFilePanel();
BRect r;
BView *background;
BTab *tab;
@ -120,6 +144,10 @@ void ScreenSaverWin::SetupForm(void) {
r.InsetBy(0,4);
r.bottom -= tabView->TabHeight();
// Time to load the settings into a message and implement them...
prefs.LoadSettings();
prefs.WindowFrame().PrintToStream();
tab = new BTab();
tabView->AddTab(tab2=new BView(r,"Fade",B_FOLLOW_NONE,0), tab);
tab->SetLabel("Fade");
@ -137,9 +165,7 @@ void ScreenSaverWin::SetupForm(void) {
pwWin=new pwWindow;
pwMessenger=new BMessenger (NULL,pwWin);
pwWin->Run();
// Time to load the settings into a message and implement them...
prefs.LoadSettings();
prefs.WindowFrame().PrintToStream();
MoveTo(prefs.WindowFrame().left,prefs.WindowFrame().top);
ResizeTo(prefs.WindowFrame().right-prefs.WindowFrame().left,prefs.WindowFrame().bottom-prefs.WindowFrame().top);
tabView->Select(prefs.WindowTab());
@ -152,10 +178,13 @@ void ScreenSaverWin::SetupForm(void) {
PasswordSlider->SetValue(secondsToSlider(prefs.PasswordTime()));
const BStringItem **ptr = (const BStringItem **)(ListView1->Items());
long count=ListView1->CountItems();
if (prefs.Password() && ptr)
if (prefs.ModuleName() && ptr)
for ( long i = 0; i < count; i++ ) {
if (BString(prefs.Password())==((*ptr++)->Text()))
if (BString(prefs.ModuleName())==((*ptr++)->Text())) {
ListView1->Select(count=i); // Clever bit here - intentional assignment.
SaverSelected();
ListView1->ScrollToSelection();
}
}
updateStatus();
}
@ -218,21 +247,37 @@ int compareSSListItems(const void* left, const void* right) {
return leftItem->displayName.Compare(rightItem->displayName);
}
// Add the strings in the BList to a BListView
void displayScreenSaversList(BList* list, BListView* view) {
list->SortItems(compareSSListItems);
void ScreenSaverWin::populateScreenSaverList(void) {
if (!AddonList)
AddonList = new BList;
else
for (void *i=AddonList->RemoveItem(zero);i;i=AddonList->RemoveItem(zero))
delete ((SSListItem *)i);
int numItems = list->CountItems();
SSListItem* tempListItem = new SSListItem;
tempListItem->fileName = "";
tempListItem->displayName = "Blackness";
AddonList->AddItem(tempListItem);
addScreenSaversToList( B_BEOS_ADDONS_DIRECTORY, AddonList );
addScreenSaversToList( B_USER_ADDONS_DIRECTORY, AddonList );
AddonList->SortItems(compareSSListItems);
// Add the strings in the BList to a BListView
ListView1->DeselectAll();
for (void *i=ListView1->RemoveItem(zero);i;i=ListView1->RemoveItem(zero))
delete ((BStringItem *)i);
int numItems = AddonList->CountItems();
for( int i = 0; i < numItems; ++i ) {
SSListItem* item = (SSListItem*)(list->ItemAt(i));
view->AddItem( new BStringItem(item->displayName.String()) );
SSListItem* item = (SSListItem*)(AddonList->ItemAt(i));
ListView1->AddItem( new BStringItem(item->displayName.String()) );
}
}
// Create the controls for the first tab
void ScreenSaverWin::setupTab1(void) {
int columns[4]={15,150,180,430};
int rows[6]={15,125,135,255,263,276};
int rows[6]={15,120,135,255,263,280};
{rgb_color clr = {216,216,216,255}; tab1->SetViewColor(clr);}
tab1->AddChild( ModuleSettingsBox = new BBox(BRect(columns[2],rows[0],columns[3],rows[5]),"ModuleSettingsBox",B_FOLLOW_NONE,B_WILL_DRAW));
@ -248,25 +293,18 @@ void ScreenSaverWin::setupTab1(void) {
// selection message for screensaver list
ListView1->SetSelectionMessage( new BMessage( SAVER_SEL ) );
tab1->AddChild( TestButton = new BButton(BRect(columns[0],rows[4],91,rows[5]),"TestButton","Test", new BMessage (TAB1_CHG)));
tab1->AddChild( TestButton = new BButton(BRect(columns[0],rows[4],91,rows[5]),"TestButton","Test", new BMessage (TEST_BTN)));
commonLookAndFeel(TestButton,false,true);
TestButton->SetLabel("Test");
tab1->AddChild( AddButton = new BButton(BRect(97,rows[4],columns[2]-10,rows[5]),"AddButton","Add...", new BMessage (TAB1_CHG)));
tab1->AddChild( AddButton = new BButton(BRect(97,rows[4],columns[2]-10,rows[5]),"AddButton","Add...", new BMessage (ADD_BTN)));
commonLookAndFeel(AddButton,false,true);
AddButton->SetLabel("Add...");
tab1->AddChild(previewDisplay = new PreviewView(BRect(columns[0]+5,rows[0],columns[1],rows[1]),"preview",&prefs));
AddonList = new BList;
addScreenSaversToList( B_BEOS_ADDONS_DIRECTORY, AddonList );
addScreenSaversToList( B_USER_ADDONS_DIRECTORY, AddonList );
displayScreenSaversList( AddonList, ListView1 );
populateScreenSaverList();
}
// Create the controls for the second tab
void ScreenSaverWin::setupTab2(void) {
font_height stdFontHt;

View File

@ -1,5 +1,6 @@
#ifndef _ScreenSaver_H
#define _ScreenSaver_H
#include <FilePanel.h>
#include <Picture.h>
#include "Constants.h"
#include "passwordWindow.h"
@ -30,12 +31,13 @@ FadeNowString2(NULL),
DontFadeString(NULL), DontFadeString2(NULL),
fadeNow(NULL),fadeNever(NULL),
pwWin(NULL),
pwMessenger(NULL),
pwMessenger(NULL), filePanel(NULL) ,
settingsArea(NULL) {
SetupForm();
}
virtual void MessageReceived(BMessage *message);
virtual bool QuitRequested(void);
void populateScreenSaverList(void);
void LoadSettings(void);
virtual ~ScreenSaverWin(void) {};
@ -44,6 +46,7 @@ private:
void setupTab1(void);
void setupTab2(void);
void updateStatus(void);
void SaverSelected(void);
ScreenSaverPrefs prefs;
int fadeState,noFadeState;
@ -83,6 +86,7 @@ private:
BMessenger *pwMessenger;
BMessage settings;
BFilePanel *filePanel;
BView *settingsArea;
};