2005-07-29 11:41:58 +04:00
|
|
|
|
/*
|
|
|
|
|
* Copyright 2003, Michael Phipps. All rights reserved.
|
2005-08-18 19:30:25 +04:00
|
|
|
|
* Copyright 2005, J<EFBFBD>r<EFBFBD>me Duval. All rights reserved.
|
2005-07-29 11:41:58 +04:00
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
|
*/
|
|
|
|
|
|
2005-08-18 19:30:25 +04:00
|
|
|
|
#include <Debug.h>
|
2005-07-26 20:12:05 +04:00
|
|
|
|
#include <File.h>
|
2005-07-29 16:05:22 +04:00
|
|
|
|
#include <FindDirectory.h>
|
2005-07-26 20:12:05 +04:00
|
|
|
|
#include <Path.h>
|
2005-07-29 16:05:22 +04:00
|
|
|
|
#include <StorageDefs.h>
|
|
|
|
|
#include <String.h>
|
2004-03-20 21:53:33 +03:00
|
|
|
|
#include <stdio.h>
|
2005-07-29 16:05:22 +04:00
|
|
|
|
#include <string.h>
|
2004-03-20 21:53:33 +03:00
|
|
|
|
|
2005-07-26 20:12:05 +04:00
|
|
|
|
#include "ScreenSaverPrefs.h"
|
|
|
|
|
|
2005-07-29 11:41:58 +04:00
|
|
|
|
ScreenSaverPrefs::ScreenSaverPrefs()
|
2004-05-04 02:41:30 +04:00
|
|
|
|
{
|
2005-08-01 16:53:23 +04:00
|
|
|
|
find_directory(B_USER_SETTINGS_DIRECTORY,&fSSPath);
|
|
|
|
|
find_directory(B_USER_SETTINGS_DIRECTORY,&fNetworkPath);
|
|
|
|
|
fSSPath.Append("ScreenSaver_settings",true);
|
|
|
|
|
fNetworkPath.Append("network",true);
|
2005-07-29 11:41:58 +04:00
|
|
|
|
|
|
|
|
|
Defaults();
|
2004-03-20 21:53:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-26 20:12:05 +04:00
|
|
|
|
|
2004-03-20 21:53:33 +03:00
|
|
|
|
// Load the flattened settings BMessage from disk and parse it.
|
2004-05-04 02:41:30 +04:00
|
|
|
|
bool
|
2005-07-26 20:12:05 +04:00
|
|
|
|
ScreenSaverPrefs::LoadSettings()
|
2004-05-04 02:41:30 +04:00
|
|
|
|
{
|
2005-08-01 16:53:23 +04:00
|
|
|
|
BFile ssSettings(fSSPath.Path(),B_READ_ONLY);
|
2004-10-10 03:17:47 +04:00
|
|
|
|
if (B_OK==ssSettings.InitCheck()) { // File exists. Unflatten the message and call the settings parser.
|
2005-07-29 16:05:22 +04:00
|
|
|
|
if (fSettings.Unflatten(&ssSettings)!=B_OK)
|
2005-07-29 11:41:58 +04:00
|
|
|
|
return false;
|
|
|
|
|
|
2005-08-18 19:30:25 +04:00
|
|
|
|
PRINT_OBJECT(fSettings);
|
2005-07-29 11:41:58 +04:00
|
|
|
|
|
2005-07-29 16:05:22 +04:00
|
|
|
|
fSettings.FindRect("windowframe", &fWindowFrame);
|
|
|
|
|
fSettings.FindInt32("windowtab", &fWindowTab);
|
|
|
|
|
fSettings.FindInt32("timeflags", &fTimeFlags);
|
2004-03-20 21:53:33 +03:00
|
|
|
|
|
2005-07-29 11:41:58 +04:00
|
|
|
|
int32 blank_time, standByTime, suspendTime, offTime, passwordTime;
|
2005-07-29 16:05:22 +04:00
|
|
|
|
if (fSettings.FindInt32("timefade", &blank_time) == B_OK)
|
2005-08-18 19:30:25 +04:00
|
|
|
|
fBlankTime = blank_time * 1000000LL;
|
2005-07-29 16:05:22 +04:00
|
|
|
|
if (fSettings.FindInt32("timestandby", &standByTime) == B_OK)
|
2005-08-18 19:30:25 +04:00
|
|
|
|
fStandByTime = standByTime * 1000000LL;
|
2005-07-29 16:05:22 +04:00
|
|
|
|
if (fSettings.FindInt32("timesuspend", &suspendTime) == B_OK)
|
2005-08-18 19:30:25 +04:00
|
|
|
|
fSuspendTime = suspendTime * 1000000LL;
|
2005-07-29 16:05:22 +04:00
|
|
|
|
if (fSettings.FindInt32("timeoff", &offTime) == B_OK)
|
2005-08-18 19:30:25 +04:00
|
|
|
|
fOffTime = offTime * 1000000LL;
|
2005-07-29 16:05:22 +04:00
|
|
|
|
fSettings.FindInt32("cornernow", (int32*)&fBlankCorner);
|
|
|
|
|
fSettings.FindInt32("cornernever", (int32*)&fNeverBlankCorner);
|
|
|
|
|
fSettings.FindBool("lockenable", &fLockEnabled);
|
|
|
|
|
if (fSettings.FindInt32("lockdelay", &passwordTime) == B_OK)
|
2005-08-18 19:30:25 +04:00
|
|
|
|
fPasswordTime = passwordTime * 1000000LL;
|
2005-07-29 16:05:22 +04:00
|
|
|
|
fSettings.FindString("lockpassword", &fPassword);
|
|
|
|
|
fSettings.FindString("lockmethod", &fLockMethod);
|
|
|
|
|
fSettings.FindString("modulename", &fModuleName);
|
2005-07-29 11:41:58 +04:00
|
|
|
|
|
|
|
|
|
if (IsNetworkPassword()) {
|
|
|
|
|
FILE *networkFile=NULL;
|
|
|
|
|
char buffer[512],*start;
|
|
|
|
|
// This ugly piece opens the networking file and reads the password, if it exists.
|
2005-08-01 16:53:23 +04:00
|
|
|
|
if ((networkFile=fopen(fNetworkPath.Path(),"r")))
|
2004-10-10 03:17:47 +04:00
|
|
|
|
while (buffer==fgets(buffer,512,networkFile))
|
|
|
|
|
if ((start=strstr(buffer,"PASSWORD ="))) {
|
2005-07-29 11:41:58 +04:00
|
|
|
|
char password[12];
|
2004-10-10 03:17:47 +04:00
|
|
|
|
strncpy(password, start+10,strlen(start-11));
|
2005-07-29 11:41:58 +04:00
|
|
|
|
fPassword = password;
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-08-02 13:57:45 +04:00
|
|
|
|
return true;
|
|
|
|
|
} else
|
|
|
|
|
return false;
|
2005-07-29 11:41:58 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ScreenSaverPrefs::Defaults()
|
|
|
|
|
{
|
|
|
|
|
fWindowFrame = BRect(96.5, 77.0, 542.5, 402);
|
|
|
|
|
fWindowTab = 0;
|
|
|
|
|
fTimeFlags = 0;
|
2005-08-18 19:30:25 +04:00
|
|
|
|
fBlankTime = 120*1000000LL;
|
|
|
|
|
fStandByTime = 120*1000000LL;
|
|
|
|
|
fSuspendTime = 120*1000000LL;
|
|
|
|
|
fOffTime = 120*1000000LL;
|
2005-07-29 11:41:58 +04:00
|
|
|
|
fBlankCorner = NONE;
|
|
|
|
|
fNeverBlankCorner = NONE;
|
|
|
|
|
fLockEnabled = false;
|
2005-08-18 19:30:25 +04:00
|
|
|
|
fPasswordTime = 120*1000000LL;
|
2005-07-29 11:41:58 +04:00
|
|
|
|
fPassword = "";
|
|
|
|
|
fLockMethod = "custom";
|
|
|
|
|
fModuleName = "";
|
2004-03-20 21:53:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-29 11:41:58 +04:00
|
|
|
|
|
2005-07-29 16:05:22 +04:00
|
|
|
|
BMessage &
|
2005-07-29 11:41:58 +04:00
|
|
|
|
ScreenSaverPrefs::GetSettings()
|
|
|
|
|
{
|
2005-07-29 16:05:22 +04:00
|
|
|
|
fSettings.RemoveName("windowframe");
|
|
|
|
|
fSettings.RemoveName("windowtab");
|
|
|
|
|
fSettings.RemoveName("timeflags");
|
|
|
|
|
fSettings.RemoveName("timefade");
|
|
|
|
|
fSettings.RemoveName("timestandby");
|
|
|
|
|
fSettings.RemoveName("timesuspend");
|
|
|
|
|
fSettings.RemoveName("timeoff");
|
|
|
|
|
fSettings.RemoveName("cornernow");
|
|
|
|
|
fSettings.RemoveName("cornernever");
|
|
|
|
|
fSettings.RemoveName("lockenable");
|
|
|
|
|
fSettings.RemoveName("lockdelay");
|
|
|
|
|
fSettings.RemoveName("lockpassword");
|
|
|
|
|
fSettings.RemoveName("lockmethod");
|
|
|
|
|
fSettings.RemoveName("modulename");
|
|
|
|
|
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);
|
2005-07-29 11:41:58 +04:00
|
|
|
|
|
2005-07-29 16:05:22 +04:00
|
|
|
|
return fSettings;
|
2005-07-29 11:41:58 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-07-29 16:05:22 +04:00
|
|
|
|
status_t
|
|
|
|
|
ScreenSaverPrefs::GetState(const char *name, BMessage *stateMsg)
|
2005-07-29 11:41:58 +04:00
|
|
|
|
{
|
2005-07-29 16:05:22 +04:00
|
|
|
|
BString stateName("modulesettings_");
|
|
|
|
|
stateName += name;
|
|
|
|
|
return fSettings.FindMessage(stateName.String(), stateMsg);
|
2004-03-20 21:53:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-29 11:41:58 +04:00
|
|
|
|
|
2004-10-10 03:17:47 +04:00
|
|
|
|
void
|
2005-07-29 16:05:22 +04:00
|
|
|
|
ScreenSaverPrefs::SetState(const char *name, BMessage *stateMsg)
|
2005-07-29 11:41:58 +04:00
|
|
|
|
{
|
2005-07-29 16:05:22 +04:00
|
|
|
|
BString stateName("modulesettings_");
|
|
|
|
|
stateName += name;
|
|
|
|
|
fSettings.RemoveName(stateName.String());
|
|
|
|
|
fSettings.AddMessage(stateName.String(), stateMsg);
|
2004-04-20 06:06:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-29 11:41:58 +04:00
|
|
|
|
|
2004-05-04 02:41:30 +04:00
|
|
|
|
void
|
2005-07-29 11:41:58 +04:00
|
|
|
|
ScreenSaverPrefs::SaveSettings()
|
|
|
|
|
{
|
2005-07-29 16:05:22 +04:00
|
|
|
|
BMessage &settings = GetSettings();
|
|
|
|
|
settings.PrintToStream();
|
2005-08-01 16:53:23 +04:00
|
|
|
|
BFile file(fSSPath.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
|
2005-07-29 16:05:22 +04:00
|
|
|
|
if ((file.InitCheck()!=B_OK) || (settings.Flatten(&file)!=B_OK))
|
2005-07-29 11:41:58 +04:00
|
|
|
|
fprintf(stderr, "Problem while saving screensaver preferences file!\n");
|
2004-03-20 21:53:33 +03:00
|
|
|
|
}
|
2005-07-29 16:05:22 +04:00
|
|
|
|
|