module states are now saved correctly
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13851 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -39,7 +39,7 @@ public:
|
|||||||
const char *Password() { return fPassword.String(); }
|
const char *Password() { return fPassword.String(); }
|
||||||
bool IsNetworkPassword() {return fIsNetworkPassword;}
|
bool IsNetworkPassword() {return fIsNetworkPassword;}
|
||||||
const char *ModuleName() {return fModuleName.String();}
|
const char *ModuleName() {return fModuleName.String();}
|
||||||
BMessage *GetState(const char *name);
|
status_t GetState(const char *name, BMessage *stateMsg);
|
||||||
|
|
||||||
void SetWindowFrame(const BRect &fr) { fWindowFrame = fr;}
|
void SetWindowFrame(const BRect &fr) { fWindowFrame = fr;}
|
||||||
void SetWindowTab(int32 tab) { fWindowTab = tab;}
|
void SetWindowTab(int32 tab) { fWindowTab = tab;}
|
||||||
@@ -54,9 +54,9 @@ public:
|
|||||||
void SetPasswordTime(bigtime_t pt) {fPasswordTime = pt;}
|
void SetPasswordTime(bigtime_t pt) {fPasswordTime = pt;}
|
||||||
void SetPassword(char *pw) {fPassword = pw;} // Can not set network password from here.
|
void SetPassword(char *pw) {fPassword = pw;} // Can not set network password from here.
|
||||||
void SetModuleName(const char *mn) {fModuleName = mn;}
|
void SetModuleName(const char *mn) {fModuleName = mn;}
|
||||||
void SetState(const char *name,BMessage *in);
|
void SetState(const char *name, BMessage *stateMsg);
|
||||||
void SaveSettings();
|
void SaveSettings();
|
||||||
BMessage * GetSettings();
|
BMessage & GetSettings();
|
||||||
private:
|
private:
|
||||||
BRect fWindowFrame;
|
BRect fWindowFrame;
|
||||||
int32 fWindowTab;
|
int32 fWindowTab;
|
||||||
@@ -75,7 +75,7 @@ private:
|
|||||||
|
|
||||||
bool fIsNetworkPassword;
|
bool fIsNetworkPassword;
|
||||||
|
|
||||||
BMessage stateMsg, currentMessage;
|
BMessage fSettings;
|
||||||
BPath ssPath,networkPath;
|
BPath ssPath,networkPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <StorageDefs.h>
|
|
||||||
#include <FindDirectory.h>
|
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
|
#include <FindDirectory.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <string.h> // Posix string functions
|
#include <StorageDefs.h>
|
||||||
#include <String.h> // BString def
|
#include <String.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "ScreenSaverPrefs.h"
|
#include "ScreenSaverPrefs.h"
|
||||||
|
|
||||||
@@ -30,33 +30,32 @@ 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;
|
if (fSettings.Unflatten(&ssSettings)!=B_OK)
|
||||||
if (settings.Unflatten(&ssSettings)!=B_OK)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
settings.PrintToStream();
|
fSettings.PrintToStream();
|
||||||
|
|
||||||
settings.FindRect("windowframe", &fWindowFrame);
|
fSettings.FindRect("windowframe", &fWindowFrame);
|
||||||
settings.FindInt32("windowtab", &fWindowTab);
|
fSettings.FindInt32("windowtab", &fWindowTab);
|
||||||
settings.FindInt32("timeflags", &fTimeFlags);
|
fSettings.FindInt32("timeflags", &fTimeFlags);
|
||||||
|
|
||||||
int32 blank_time, standByTime, suspendTime, offTime, passwordTime;
|
int32 blank_time, standByTime, suspendTime, offTime, passwordTime;
|
||||||
if (settings.FindInt32("timefade", &blank_time) == B_OK)
|
if (fSettings.FindInt32("timefade", &blank_time) == B_OK)
|
||||||
fBlankTime = blank_time * 1000000;
|
fBlankTime = blank_time * 1000000;
|
||||||
if (settings.FindInt32("timestandby", &standByTime) == B_OK)
|
if (fSettings.FindInt32("timestandby", &standByTime) == B_OK)
|
||||||
fStandByTime = standByTime * 1000000;
|
fStandByTime = standByTime * 1000000;
|
||||||
if (settings.FindInt32("timesuspend", &suspendTime) == B_OK)
|
if (fSettings.FindInt32("timesuspend", &suspendTime) == B_OK)
|
||||||
fSuspendTime = suspendTime * 1000000;
|
fSuspendTime = suspendTime * 1000000;
|
||||||
if (settings.FindInt32("timeoff", &offTime) == B_OK)
|
if (fSettings.FindInt32("timeoff", &offTime) == B_OK)
|
||||||
fOffTime = offTime * 1000000;
|
fOffTime = offTime * 1000000;
|
||||||
settings.FindInt32("cornernow", (int32*)&fBlankCorner);
|
fSettings.FindInt32("cornernow", (int32*)&fBlankCorner);
|
||||||
settings.FindInt32("cornernever", (int32*)&fNeverBlankCorner);
|
fSettings.FindInt32("cornernever", (int32*)&fNeverBlankCorner);
|
||||||
settings.FindBool("lockenable", &fLockEnabled);
|
fSettings.FindBool("lockenable", &fLockEnabled);
|
||||||
if (settings.FindInt32("lockdelay", &passwordTime) == B_OK)
|
if (fSettings.FindInt32("lockdelay", &passwordTime) == B_OK)
|
||||||
fPasswordTime = passwordTime * 1000000;
|
fPasswordTime = passwordTime * 1000000;
|
||||||
settings.FindString("lockpassword", &fPassword);
|
fSettings.FindString("lockpassword", &fPassword);
|
||||||
settings.FindString("lockmethod", &fLockMethod);
|
fSettings.FindString("lockmethod", &fLockMethod);
|
||||||
settings.FindString("modulename", &fModuleName);
|
fSettings.FindString("modulename", &fModuleName);
|
||||||
|
|
||||||
if (IsNetworkPassword()) {
|
if (IsNetworkPassword()) {
|
||||||
FILE *networkFile=NULL;
|
FILE *networkFile=NULL;
|
||||||
@@ -95,56 +94,68 @@ ScreenSaverPrefs::Defaults()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BMessage *
|
BMessage &
|
||||||
ScreenSaverPrefs::GetSettings()
|
ScreenSaverPrefs::GetSettings()
|
||||||
{
|
{
|
||||||
BMessage *msg = new BMessage();
|
fSettings.RemoveName("windowframe");
|
||||||
msg->AddRect("windowframe", fWindowFrame);
|
fSettings.RemoveName("windowtab");
|
||||||
msg->AddInt32("windowtab", fWindowTab);
|
fSettings.RemoveName("timeflags");
|
||||||
msg->AddInt32("timeflags", fTimeFlags);
|
fSettings.RemoveName("timefade");
|
||||||
msg->AddInt32("timefade", fBlankTime/1000000);
|
fSettings.RemoveName("timestandby");
|
||||||
msg->AddInt32("timestandby", fStandByTime/1000000);
|
fSettings.RemoveName("timesuspend");
|
||||||
msg->AddInt32("timesuspend", fSuspendTime/1000000);
|
fSettings.RemoveName("timeoff");
|
||||||
msg->AddInt32("timeoff", fOffTime/1000000);
|
fSettings.RemoveName("cornernow");
|
||||||
msg->AddInt32("cornernow", fBlankCorner);
|
fSettings.RemoveName("cornernever");
|
||||||
msg->AddInt32("cornernever", fNeverBlankCorner);
|
fSettings.RemoveName("lockenable");
|
||||||
msg->AddBool("lockenable", fLockEnabled);
|
fSettings.RemoveName("lockdelay");
|
||||||
msg->AddInt32("lockdelay", fPasswordTime/1000000);
|
fSettings.RemoveName("lockpassword");
|
||||||
msg->AddString("lockpassword", fPassword);
|
fSettings.RemoveName("lockmethod");
|
||||||
msg->AddString("lockmethod", fLockMethod);
|
fSettings.RemoveName("modulename");
|
||||||
msg->AddString("modulename", fModuleName);
|
fSettings.AddRect("windowframe", fWindowFrame);
|
||||||
|
fSettings.AddInt32("windowtab", fWindowTab);
|
||||||
|
fSettings.AddInt32("timeflags", fTimeFlags);
|
||||||
|
fSettings.AddInt32("timefade", fBlankTime/1000000);
|
||||||
|
fSettings.AddInt32("timestandby", fStandByTime/1000000);
|
||||||
|
fSettings.AddInt32("timesuspend", fSuspendTime/1000000);
|
||||||
|
fSettings.AddInt32("timeoff", fOffTime/1000000);
|
||||||
|
fSettings.AddInt32("cornernow", fBlankCorner);
|
||||||
|
fSettings.AddInt32("cornernever", fNeverBlankCorner);
|
||||||
|
fSettings.AddBool("lockenable", fLockEnabled);
|
||||||
|
fSettings.AddInt32("lockdelay", fPasswordTime/1000000);
|
||||||
|
fSettings.AddString("lockpassword", fPassword);
|
||||||
|
fSettings.AddString("lockmethod", fLockMethod);
|
||||||
|
fSettings.AddString("modulename", fModuleName);
|
||||||
|
|
||||||
return msg;
|
return fSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BMessage *
|
status_t
|
||||||
ScreenSaverPrefs::GetState(const char *name)
|
ScreenSaverPrefs::GetState(const char *name, BMessage *stateMsg)
|
||||||
{
|
{
|
||||||
BString stateMsgName("modulesettings_");
|
BString stateName("modulesettings_");
|
||||||
stateMsgName+=name;
|
stateName += name;
|
||||||
currentMessage.FindMessage(stateMsgName.String(),&stateMsg);
|
return fSettings.FindMessage(stateName.String(), stateMsg);
|
||||||
return &stateMsg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScreenSaverPrefs::SetState(const char *name,BMessage *msg)
|
ScreenSaverPrefs::SetState(const char *name, BMessage *stateMsg)
|
||||||
{
|
{
|
||||||
BString stateMsgName("modulesettings_");
|
BString stateName("modulesettings_");
|
||||||
stateMsgName+=name;
|
stateName += name;
|
||||||
if (B_NAME_NOT_FOUND == currentMessage.ReplaceMessage(stateMsgName.String(),msg))
|
fSettings.RemoveName(stateName.String());
|
||||||
currentMessage.AddMessage(stateMsgName.String(),msg);
|
fSettings.AddMessage(stateName.String(), stateMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScreenSaverPrefs::SaveSettings()
|
ScreenSaverPrefs::SaveSettings()
|
||||||
{
|
{
|
||||||
BMessage *settings = GetSettings();
|
BMessage &settings = GetSettings();
|
||||||
settings->PrintToStream();
|
settings.PrintToStream();
|
||||||
BFile file(ssPath.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
|
BFile file(ssPath.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
|
||||||
if ((file.InitCheck()!=B_OK) || (settings->Flatten(&file)!=B_OK))
|
if ((file.InitCheck()!=B_OK) || (settings.Flatten(&file)!=B_OK))
|
||||||
fprintf(stderr, "Problem while saving screensaver preferences file!\n");
|
fprintf(stderr, "Problem while saving screensaver preferences file!\n");
|
||||||
delete settings;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,8 +107,11 @@ ScreenSaverThread::LoadAddOn()
|
|||||||
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 {
|
||||||
fSaver = instantiate(fPref->GetState(fPref->ModuleName()), fAddonImage);
|
BMessage state;
|
||||||
|
fPref->GetState(fPref->ModuleName(), &state);
|
||||||
|
fSaver = instantiate(&state, fAddonImage);
|
||||||
|
}
|
||||||
if (B_OK != fSaver->InitCheck()) {
|
if (B_OK != fSaver->InitCheck()) {
|
||||||
printf ("InitCheck() Failed!\n");
|
printf ("InitCheck() Failed!\n");
|
||||||
unload_add_on(fAddonImage);
|
unload_add_on(fAddonImage);
|
||||||
|
|||||||
@@ -148,9 +148,8 @@ ScreenSaverWin::MessageReceived(BMessage *msg)
|
|||||||
break;
|
break;
|
||||||
case kTest_btn:
|
case kTest_btn:
|
||||||
{
|
{
|
||||||
BMessage *settings = fPrefs.GetSettings();
|
BMessage &settings = fPrefs.GetSettings();
|
||||||
be_roster->Launch("application/x-vnd.haiku-ScreenSaverApp", settings);
|
be_roster->Launch("application/x-vnd.haiku-ScreenSaverApp", &settings);
|
||||||
delete settings;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case kAdd_btn:
|
case kAdd_btn:
|
||||||
|
|||||||
Reference in New Issue
Block a user