* Enabled default time for shutting off the monitor (after 20 minutes).
* Removed BeOS R5 network password retrieval code. * Cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31652 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -27,75 +27,101 @@ enum {
|
||||
ENABLE_DPMS_SUSPEND = 0x04,
|
||||
ENABLE_DPMS_OFF = 0x08,
|
||||
|
||||
ENABLE_DPMS_MASK = ENABLE_DPMS_STAND_BY | ENABLE_DPMS_SUSPEND | ENABLE_DPMS_OFF
|
||||
ENABLE_DPMS_MASK
|
||||
= ENABLE_DPMS_STAND_BY | ENABLE_DPMS_SUSPEND | ENABLE_DPMS_OFF
|
||||
};
|
||||
|
||||
#define SCREEN_BLANKER_SIG "application/x-vnd.Haiku.screenblanker"
|
||||
|
||||
|
||||
class ScreenSaverSettings {
|
||||
public:
|
||||
ScreenSaverSettings();
|
||||
public:
|
||||
ScreenSaverSettings();
|
||||
|
||||
bool Load();
|
||||
void Save();
|
||||
void Defaults();
|
||||
BPath& Path() { return fSettingsPath; }
|
||||
bool Load();
|
||||
void Save();
|
||||
void Defaults();
|
||||
BPath& Path() { return fSettingsPath; }
|
||||
|
||||
BRect WindowFrame() { return fWindowFrame; }
|
||||
int32 WindowTab() { return fWindowTab; }
|
||||
int32 TimeFlags() { return fTimeFlags; }
|
||||
bigtime_t BlankTime() { return fBlankTime; }
|
||||
bigtime_t StandByTime() { return fStandByTime; }
|
||||
bigtime_t SuspendTime() { return fSuspendTime; }
|
||||
bigtime_t OffTime() { return fOffTime; }
|
||||
// General screen saver settings
|
||||
int32 TimeFlags() { return fTimeFlags; }
|
||||
bigtime_t BlankTime() { return fBlankTime; }
|
||||
bigtime_t StandByTime() { return fStandByTime; }
|
||||
bigtime_t SuspendTime() { return fSuspendTime; }
|
||||
bigtime_t OffTime() { return fOffTime; }
|
||||
|
||||
screen_corner BlankCorner() { return fBlankCorner; }
|
||||
screen_corner NeverBlankCorner() { return fNeverBlankCorner; }
|
||||
bool LockEnable() { return fLockEnabled; }
|
||||
bigtime_t PasswordTime() { return fPasswordTime; }
|
||||
const char *Password() { return fPassword.String(); }
|
||||
const char *LockMethod() { return fLockMethod.String(); }
|
||||
bool IsNetworkPassword() { return strcmp(fLockMethod.String(), "custom") != 0; }
|
||||
const char *ModuleName() { return fModuleName.String(); }
|
||||
status_t GetModuleState(const char *name, BMessage *stateMsg);
|
||||
screen_corner BlankCorner() { return fBlankCorner; }
|
||||
screen_corner NeverBlankCorner() { return fNeverBlankCorner; }
|
||||
bool LockEnable() { return fLockEnabled; }
|
||||
bigtime_t PasswordTime() { return fPasswordTime; }
|
||||
const char* Password() { return fPassword.String(); }
|
||||
const char* LockMethod() { return fLockMethod.String(); }
|
||||
bool IsNetworkPassword()
|
||||
{ return strcmp(fLockMethod.String(), "custom")
|
||||
!= 0; }
|
||||
|
||||
void SetWindowFrame(const BRect &fr) { fWindowFrame = fr; }
|
||||
void SetWindowTab(int32 tab) { fWindowTab = tab; }
|
||||
void SetTimeFlags(int32 tf) { fTimeFlags = tf; }
|
||||
void SetBlankTime(bigtime_t bt) { fBlankTime = bt; }
|
||||
void SetStandByTime(bigtime_t time) { fStandByTime = time; }
|
||||
void SetSuspendTime(bigtime_t time) { fSuspendTime = time; }
|
||||
void SetOffTime(bigtime_t intime) { fOffTime = intime; }
|
||||
void SetBlankCorner(screen_corner in) { fBlankCorner = in; }
|
||||
void SetNeverBlankCorner(screen_corner in) { fNeverBlankCorner = in; }
|
||||
void SetLockEnable(bool en) { fLockEnabled = en; }
|
||||
void SetPasswordTime(bigtime_t pt) { fPasswordTime = pt; }
|
||||
void SetPassword(const char *pw) { fPassword = pw; }
|
||||
// Cannot set network password from here.
|
||||
void SetLockMethod(const char *method) { fLockMethod = method; }
|
||||
void SetModuleName(const char *mn) { fModuleName = mn; }
|
||||
void SetModuleState(const char *name, BMessage *stateMsg);
|
||||
const char* ModuleName() { return fModuleName.String(); }
|
||||
status_t GetModuleState(const char* name,
|
||||
BMessage* stateMessage);
|
||||
|
||||
BMessage& Message();
|
||||
void SetTimeFlags(uint32 flags)
|
||||
{ fTimeFlags = flags; }
|
||||
void SetBlankTime(bigtime_t time)
|
||||
{ fBlankTime = time; }
|
||||
void SetStandByTime(bigtime_t time)
|
||||
{ fStandByTime = time; }
|
||||
void SetSuspendTime(bigtime_t time)
|
||||
{ fSuspendTime = time; }
|
||||
void SetOffTime(bigtime_t intime)
|
||||
{ fOffTime = intime; }
|
||||
void SetBlankCorner(screen_corner in)
|
||||
{ fBlankCorner = in; }
|
||||
void SetNeverBlankCorner(screen_corner in)
|
||||
{ fNeverBlankCorner = in; }
|
||||
void SetLockEnable(bool enable)
|
||||
{ fLockEnabled = enable; }
|
||||
void SetPasswordTime(bigtime_t time)
|
||||
{ fPasswordTime = time; }
|
||||
void SetPassword(const char* password)
|
||||
{ fPassword = password; }
|
||||
// Cannot set network password from here.
|
||||
void SetLockMethod(const char* method)
|
||||
{ fLockMethod = method; }
|
||||
void SetModuleName(const char* name)
|
||||
{ fModuleName = name; }
|
||||
void SetModuleState(const char* name,
|
||||
BMessage* stateMessage);
|
||||
|
||||
private:
|
||||
BRect fWindowFrame;
|
||||
int32 fWindowTab;
|
||||
int32 fTimeFlags;
|
||||
bigtime_t fBlankTime;
|
||||
bigtime_t fStandByTime;
|
||||
bigtime_t fSuspendTime;
|
||||
bigtime_t fOffTime;
|
||||
screen_corner fBlankCorner;
|
||||
screen_corner fNeverBlankCorner;
|
||||
bool fLockEnabled;
|
||||
bigtime_t fPasswordTime;
|
||||
BString fPassword;
|
||||
BString fModuleName;
|
||||
BString fLockMethod;
|
||||
// ScreenSaver preferences settings
|
||||
BRect WindowFrame() { return fWindowFrame; }
|
||||
int32 WindowTab() { return fWindowTab; }
|
||||
|
||||
BMessage fSettings;
|
||||
BPath fSettingsPath, fNetworkPath;
|
||||
void SetWindowFrame(const BRect& frame)
|
||||
{ fWindowFrame = frame; }
|
||||
void SetWindowTab(int32 tab)
|
||||
{ fWindowTab = tab; }
|
||||
|
||||
BMessage& Message();
|
||||
|
||||
private:
|
||||
int32 fTimeFlags;
|
||||
bigtime_t fBlankTime;
|
||||
bigtime_t fStandByTime;
|
||||
bigtime_t fSuspendTime;
|
||||
bigtime_t fOffTime;
|
||||
screen_corner fBlankCorner;
|
||||
screen_corner fNeverBlankCorner;
|
||||
bool fLockEnabled;
|
||||
bigtime_t fPasswordTime;
|
||||
BString fPassword;
|
||||
BString fModuleName;
|
||||
BString fLockMethod;
|
||||
|
||||
BRect fWindowFrame;
|
||||
int32 fWindowTab;
|
||||
|
||||
BMessage fSettings;
|
||||
BPath fSettingsPath;
|
||||
};
|
||||
|
||||
#endif // SCREEN_SAVER_SETTINGS_H
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2006, Haiku.
|
||||
* Copyright 2003-2009, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -7,9 +7,15 @@
|
||||
* Jérôme Duval, [email protected]
|
||||
*/
|
||||
|
||||
/*! This is the class that wraps the screensaver settings, as well as the
|
||||
settings of the screensaver preference application.
|
||||
*/
|
||||
|
||||
|
||||
#include "ScreenSaverSettings.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <Debug.h>
|
||||
#include <File.h>
|
||||
#include <FindDirectory.h>
|
||||
@@ -17,18 +23,14 @@
|
||||
#include <StorageDefs.h>
|
||||
#include <String.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
ScreenSaverSettings::ScreenSaverSettings()
|
||||
ScreenSaverSettings::ScreenSaverSettings()
|
||||
{
|
||||
BPath path;
|
||||
find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
||||
|
||||
fSettingsPath = path;
|
||||
fSettingsPath.Append("ScreenSaver_settings", true);
|
||||
fNetworkPath = path;
|
||||
fNetworkPath.Append("network", true);
|
||||
|
||||
Defaults();
|
||||
}
|
||||
@@ -36,7 +38,7 @@ ScreenSaverSettings::ScreenSaverSettings()
|
||||
|
||||
//! Load the flattened settings BMessage from disk and parse it.
|
||||
bool
|
||||
ScreenSaverSettings::Load()
|
||||
ScreenSaverSettings::Load()
|
||||
{
|
||||
BFile file(fSettingsPath.Path(), B_READ_ONLY);
|
||||
if (file.InitCheck() != B_OK)
|
||||
@@ -86,20 +88,7 @@ ScreenSaverSettings::Load()
|
||||
fModuleName = string;
|
||||
|
||||
if (IsNetworkPassword()) {
|
||||
FILE *networkFile = NULL;
|
||||
char buffer[512], *start;
|
||||
// TODO: this only works under R5 net_server!
|
||||
// This ugly piece opens the networking file and reads the password, if it exists.
|
||||
if ((networkFile = fopen(fNetworkPath.Path(),"r")))
|
||||
while (fgets(buffer, 512, networkFile) != NULL) {
|
||||
if ((start = strstr(buffer,"PASSWORD = ")) != NULL) {
|
||||
char password[14];
|
||||
strncpy(password, start+11,strlen(start+11)-1);
|
||||
password[strlen(start+11)-1] = 0;
|
||||
fPassword = password;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// TODO: this does not work yet
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -111,16 +100,19 @@ ScreenSaverSettings::Defaults()
|
||||
{
|
||||
fWindowFrame = BRect(96.5, 77.0, 542.5, 402);
|
||||
fWindowTab = 0;
|
||||
fTimeFlags = ENABLE_SAVER;
|
||||
|
||||
// Times are in microseconds = seconds * 1000000LL
|
||||
fBlankTime = 900*1000000LL; // 15 minutes
|
||||
|
||||
// All these times are referenced from after the above, i.e. when the screen
|
||||
// saver is running. So standby will start 5 minutes after the screen saver.
|
||||
fStandByTime = 300*1000000LL; // 5 minutes
|
||||
fSuspendTime = 300*1000000LL; // 5 minutes
|
||||
fOffTime = 300*1000000LL; // 5 minutes
|
||||
// Enable blanker + turning off the screen
|
||||
fTimeFlags = ENABLE_SAVER | ENABLE_DPMS_STAND_BY | ENABLE_DPMS_SUSPEND
|
||||
| ENABLE_DPMS_OFF;
|
||||
|
||||
// Times are in microseconds
|
||||
fBlankTime = 900 * 1000000LL; // 15 minutes
|
||||
|
||||
// All these times are relative to fBlankTime; standby will start 5 minutes
|
||||
// after the screen saver.
|
||||
fStandByTime = 300 * 1000000LL; // 5 minutes
|
||||
fSuspendTime = 300 * 1000000LL;
|
||||
fOffTime = 300 * 1000000LL;
|
||||
|
||||
fBlankCorner = NO_CORNER;
|
||||
fNeverBlankCorner = NO_CORNER;
|
||||
@@ -129,7 +121,7 @@ ScreenSaverSettings::Defaults()
|
||||
// This time is NOT referenced to when the screen saver starts, but to when
|
||||
// idle time starts, like fBlankTime. By default it is the same as
|
||||
// fBlankTime.
|
||||
fPasswordTime = 900*1000000LL; // 15 minutes
|
||||
fPasswordTime = 900 * 1000000LL;
|
||||
fPassword = "";
|
||||
fLockMethod = "custom";
|
||||
|
||||
@@ -137,7 +129,7 @@ ScreenSaverSettings::Defaults()
|
||||
}
|
||||
|
||||
|
||||
BMessage &
|
||||
BMessage&
|
||||
ScreenSaverSettings::Message()
|
||||
{
|
||||
// We can't just empty the message, because the module states are stored
|
||||
@@ -180,16 +172,16 @@ ScreenSaverSettings::Message()
|
||||
|
||||
|
||||
status_t
|
||||
ScreenSaverSettings::GetModuleState(const char *name, BMessage *stateMsg)
|
||||
ScreenSaverSettings::GetModuleState(const char* name, BMessage* stateMsg)
|
||||
{
|
||||
BString stateName("modulesettings_");
|
||||
stateName += name;
|
||||
return fSettings.FindMessage(stateName.String(), stateMsg);
|
||||
return fSettings.FindMessage(stateName.String(), stateMsg);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScreenSaverSettings::SetModuleState(const char *name, BMessage *stateMsg)
|
||||
ScreenSaverSettings::SetModuleState(const char* name, BMessage* stateMsg)
|
||||
{
|
||||
BString stateName("modulesettings_");
|
||||
stateName += name;
|
||||
@@ -198,12 +190,13 @@ ScreenSaverSettings::SetModuleState(const char *name, BMessage *stateMsg)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScreenSaverSettings::Save()
|
||||
void
|
||||
ScreenSaverSettings::Save()
|
||||
{
|
||||
BMessage &settings = Message();
|
||||
PRINT_OBJECT(settings);
|
||||
BFile file(fSettingsPath.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
|
||||
BFile file(fSettingsPath.Path(),
|
||||
B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
|
||||
if (file.InitCheck() != B_OK || settings.Flatten(&file) != B_OK)
|
||||
fprintf(stderr, "Problem while saving screensaver preferences file!\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user