* This should fix Pulse's broken behaviour on read-only disks.
* Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24274 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+54
-48
@@ -9,37 +9,45 @@
|
|||||||
//****************************************************************************************
|
//****************************************************************************************
|
||||||
|
|
||||||
#include "Prefs.h"
|
#include "Prefs.h"
|
||||||
#include "Common.h"
|
|
||||||
#include "PulseApp.h"
|
|
||||||
#include <FindDirectory.h>
|
|
||||||
#include <Path.h>
|
|
||||||
#include <interface/Screen.h>
|
|
||||||
#include <kernel/OS.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <FindDirectory.h>
|
||||||
|
#include <OS.h>
|
||||||
|
#include <Path.h>
|
||||||
|
#include <Screen.h>
|
||||||
|
|
||||||
|
#include "Common.h"
|
||||||
|
#include "PulseApp.h"
|
||||||
|
|
||||||
|
|
||||||
Prefs::Prefs()
|
Prefs::Prefs()
|
||||||
: fatalerror(false)
|
:
|
||||||
|
fFatalError(false)
|
||||||
{
|
{
|
||||||
BPath path;
|
BPath path;
|
||||||
find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
||||||
path.Append("Pulse_settings");
|
path.Append("Pulse_settings");
|
||||||
file = new BFile(path.Path(), B_READ_WRITE | B_CREATE_FILE);
|
fFile = new BFile(path.Path(), B_READ_WRITE | B_CREATE_FILE);
|
||||||
if (file->InitCheck() != B_OK) {
|
if (fFile->InitCheck() != B_OK) {
|
||||||
fatalerror = true;
|
// try to open read-only
|
||||||
return;
|
if (fFile->SetTo(path.Path(), B_READ_ONLY) != B_OK) {
|
||||||
|
fFatalError = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = NORMAL_WINDOW_MODE;
|
int i = NORMAL_WINDOW_MODE;
|
||||||
if (!GetInt("window_mode", &window_mode, &i)) {
|
if (!GetInt("window_mode", &window_mode, &i)) {
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// These three prefs require a connection to the app_server
|
// These three prefs require a connection to the app_server
|
||||||
BRect r = GetNormalWindowRect();
|
BRect r = GetNormalWindowRect();
|
||||||
if (!GetRect("normal_window_rect", &normal_window_rect, &r)) {
|
if (!GetRect("normal_window_rect", &normal_window_rect, &r)) {
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// While normal window position is under user control, size is not.
|
// While normal window position is under user control, size is not.
|
||||||
@@ -49,61 +57,61 @@ Prefs::Prefs()
|
|||||||
|
|
||||||
r = GetMiniWindowRect();
|
r = GetMiniWindowRect();
|
||||||
if (!GetRect("mini_window_rect", &mini_window_rect, &r)) {
|
if (!GetRect("mini_window_rect", &mini_window_rect, &r)) {
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
r.Set(100, 100, 415, 329);
|
r.Set(100, 100, 415, 329);
|
||||||
if (!GetRect("prefs_window_rect", &prefs_window_rect, &r)) {
|
if (!GetRect("prefs_window_rect", &prefs_window_rect, &r)) {
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = DEFAULT_NORMAL_BAR_COLOR;
|
i = DEFAULT_NORMAL_BAR_COLOR;
|
||||||
if (!GetInt("normal_bar_color", &normal_bar_color, &i)) {
|
if (!GetInt("normal_bar_color", &normal_bar_color, &i)) {
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = DEFAULT_MINI_ACTIVE_COLOR;
|
i = DEFAULT_MINI_ACTIVE_COLOR;
|
||||||
if (!GetInt("mini_active_color", &mini_active_color, &i)) {
|
if (!GetInt("mini_active_color", &mini_active_color, &i)) {
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = DEFAULT_MINI_IDLE_COLOR;
|
i = DEFAULT_MINI_IDLE_COLOR;
|
||||||
if (!GetInt("mini_idle_color", &mini_idle_color, &i)) {
|
if (!GetInt("mini_idle_color", &mini_idle_color, &i)) {
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = DEFAULT_MINI_FRAME_COLOR;
|
i = DEFAULT_MINI_FRAME_COLOR;
|
||||||
if (!GetInt("mini_frame_color", &mini_frame_color, &i)) {
|
if (!GetInt("mini_frame_color", &mini_frame_color, &i)) {
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = DEFAULT_DESKBAR_ACTIVE_COLOR;
|
i = DEFAULT_DESKBAR_ACTIVE_COLOR;
|
||||||
if (!GetInt("deskbar_active_color", &deskbar_active_color, &i)) {
|
if (!GetInt("deskbar_active_color", &deskbar_active_color, &i)) {
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = DEFAULT_DESKBAR_IDLE_COLOR;
|
i = DEFAULT_DESKBAR_IDLE_COLOR;
|
||||||
if (!GetInt("deskbar_idle_color", &deskbar_idle_color, &i)) {
|
if (!GetInt("deskbar_idle_color", &deskbar_idle_color, &i)) {
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = DEFAULT_DESKBAR_FRAME_COLOR;
|
i = DEFAULT_DESKBAR_FRAME_COLOR;
|
||||||
if (!GetInt("deskbar_frame_color", &deskbar_frame_color, &i)) {
|
if (!GetInt("deskbar_frame_color", &deskbar_frame_color, &i)) {
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool b = DEFAULT_NORMAL_FADE_COLORS;
|
bool b = DEFAULT_NORMAL_FADE_COLORS;
|
||||||
if (!GetBool("normal_fade_colors", &normal_fade_colors, &b)) {
|
if (!GetBool("normal_fade_colors", &normal_fade_colors, &b)) {
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +121,7 @@ Prefs::Prefs()
|
|||||||
if (i < GetMinimumViewWidth())
|
if (i < GetMinimumViewWidth())
|
||||||
i = GetMinimumViewWidth();
|
i = GetMinimumViewWidth();
|
||||||
if (!GetInt("deskbar_icon_width", &deskbar_icon_width, &i)) {
|
if (!GetInt("deskbar_icon_width", &deskbar_icon_width, &i)) {
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,7 +129,7 @@ Prefs::Prefs()
|
|||||||
|
|
||||||
Prefs::~Prefs()
|
Prefs::~Prefs()
|
||||||
{
|
{
|
||||||
delete file;
|
delete fFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -131,7 +139,8 @@ Prefs::GetNormalWindowHeight()
|
|||||||
system_info sys_info;
|
system_info sys_info;
|
||||||
get_system_info(&sys_info);
|
get_system_info(&sys_info);
|
||||||
|
|
||||||
float height = PROGRESS_MTOP + PROGRESS_MBOTTOM + sys_info.cpu_count * ITEM_OFFSET;
|
float height = PROGRESS_MTOP + PROGRESS_MBOTTOM
|
||||||
|
+ sys_info.cpu_count * ITEM_OFFSET;
|
||||||
if (PULSEVIEW_MIN_HEIGHT > height)
|
if (PULSEVIEW_MIN_HEIGHT > height)
|
||||||
height = PULSEVIEW_MIN_HEIGHT;
|
height = PULSEVIEW_MIN_HEIGHT;
|
||||||
|
|
||||||
@@ -173,17 +182,16 @@ Prefs::GetMiniWindowRect()
|
|||||||
bool
|
bool
|
||||||
Prefs::GetInt(char *name, int *value, int *defaultvalue)
|
Prefs::GetInt(char *name, int *value, int *defaultvalue)
|
||||||
{
|
{
|
||||||
status_t err = file->ReadAttr(name, B_INT32_TYPE, 0, value, 4);
|
status_t err = fFile->ReadAttr(name, B_INT32_TYPE, 0, value, 4);
|
||||||
if (err == B_ENTRY_NOT_FOUND) {
|
if (err == B_ENTRY_NOT_FOUND) {
|
||||||
*value = *defaultvalue;
|
*value = *defaultvalue;
|
||||||
if (file->WriteAttr(name, B_INT32_TYPE, 0, defaultvalue, 4) < 0) {
|
if (fFile->WriteAttr(name, B_INT32_TYPE, 0, defaultvalue, 4) < 0) {
|
||||||
printf("WriteAttr on %s died\n", name);
|
printf("WriteAttr on %s died\n", name);
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else if (err < 0) {
|
} else if (err < 0) {
|
||||||
printf("Unknown error reading %s:\n%s\n", name, strerror(err));
|
printf("Unknown error reading %s:\n%s\n", name, strerror(err));
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -193,17 +201,16 @@ Prefs::GetInt(char *name, int *value, int *defaultvalue)
|
|||||||
bool
|
bool
|
||||||
Prefs::GetBool(char *name, bool *value, bool *defaultvalue)
|
Prefs::GetBool(char *name, bool *value, bool *defaultvalue)
|
||||||
{
|
{
|
||||||
status_t err = file->ReadAttr(name, B_BOOL_TYPE, 0, value, 1);
|
status_t err = fFile->ReadAttr(name, B_BOOL_TYPE, 0, value, 1);
|
||||||
if (err == B_ENTRY_NOT_FOUND) {
|
if (err == B_ENTRY_NOT_FOUND) {
|
||||||
*value = *defaultvalue;
|
*value = *defaultvalue;
|
||||||
if (file->WriteAttr(name, B_BOOL_TYPE, 0, defaultvalue, 1) < 0) {
|
if (fFile->WriteAttr(name, B_BOOL_TYPE, 0, defaultvalue, 1) < 0) {
|
||||||
printf("WriteAttr on %s died\n", name);
|
printf("WriteAttr on %s died\n", name);
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else if (err < 0) {
|
} else if (err < 0) {
|
||||||
printf("Unknown error reading %s:\n%s\n", name, strerror(err));
|
printf("Unknown error reading %s:\n%s\n", name, strerror(err));
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -213,17 +220,16 @@ Prefs::GetBool(char *name, bool *value, bool *defaultvalue)
|
|||||||
bool
|
bool
|
||||||
Prefs::GetRect(char *name, BRect *value, BRect *defaultvalue)
|
Prefs::GetRect(char *name, BRect *value, BRect *defaultvalue)
|
||||||
{
|
{
|
||||||
status_t err = file->ReadAttr(name, B_RECT_TYPE, 0, value, sizeof(BRect));
|
status_t err = fFile->ReadAttr(name, B_RECT_TYPE, 0, value, sizeof(BRect));
|
||||||
if (err == B_ENTRY_NOT_FOUND) {
|
if (err == B_ENTRY_NOT_FOUND) {
|
||||||
*value = *defaultvalue;
|
*value = *defaultvalue;
|
||||||
if (file->WriteAttr(name, B_RECT_TYPE, 0, defaultvalue, sizeof(BRect)) < 0) {
|
if (fFile->WriteAttr(name, B_RECT_TYPE, 0, defaultvalue, sizeof(BRect)) < 0) {
|
||||||
printf("WriteAttr on %s died\n", name);
|
printf("WriteAttr on %s died\n", name);
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else if (err < 0) {
|
} else if (err < 0) {
|
||||||
printf("Unknown error reading %s:\n%s\n", name, strerror(err));
|
printf("Unknown error reading %s:\n%s\n", name, strerror(err));
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -233,10 +239,10 @@ Prefs::GetRect(char *name, BRect *value, BRect *defaultvalue)
|
|||||||
bool
|
bool
|
||||||
Prefs::PutInt(char *name, int *value)
|
Prefs::PutInt(char *name, int *value)
|
||||||
{
|
{
|
||||||
status_t err = file->WriteAttr(name, B_INT32_TYPE, 0, value, 4);
|
status_t err = fFile->WriteAttr(name, B_INT32_TYPE, 0, value, 4);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
printf("Unknown error writing %s:\n%s\n", name, strerror(err));
|
printf("Unknown error writing %s:\n%s\n", name, strerror(err));
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -246,10 +252,10 @@ Prefs::PutInt(char *name, int *value)
|
|||||||
bool
|
bool
|
||||||
Prefs::PutBool(char *name, bool *value)
|
Prefs::PutBool(char *name, bool *value)
|
||||||
{
|
{
|
||||||
status_t err = file->WriteAttr(name, B_BOOL_TYPE, 0, value, 1);
|
status_t err = fFile->WriteAttr(name, B_BOOL_TYPE, 0, value, 1);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
printf("Unknown error writing %s:\n%s\n", name, strerror(err));
|
printf("Unknown error writing %s:\n%s\n", name, strerror(err));
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -259,10 +265,10 @@ Prefs::PutBool(char *name, bool *value)
|
|||||||
bool
|
bool
|
||||||
Prefs::PutRect(char *name, BRect *value)
|
Prefs::PutRect(char *name, BRect *value)
|
||||||
{
|
{
|
||||||
status_t err = file->WriteAttr(name, B_RECT_TYPE, 0, value, sizeof(BRect));
|
status_t err = fFile->WriteAttr(name, B_RECT_TYPE, 0, value, sizeof(BRect));
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
printf("Unknown error writing %s:\n%s\n", name, strerror(err));
|
printf("Unknown error writing %s:\n%s\n", name, strerror(err));
|
||||||
fatalerror = true;
|
fFatalError = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -272,7 +278,7 @@ Prefs::PutRect(char *name, BRect *value)
|
|||||||
bool
|
bool
|
||||||
Prefs::Save()
|
Prefs::Save()
|
||||||
{
|
{
|
||||||
if (fatalerror)
|
if (fFatalError)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!PutInt("window_mode", &window_mode)
|
if (!PutInt("window_mode", &window_mode)
|
||||||
|
|||||||
@@ -26,10 +26,8 @@ class Prefs {
|
|||||||
deskbar_active_color, deskbar_idle_color, deskbar_frame_color;
|
deskbar_active_color, deskbar_idle_color, deskbar_frame_color;
|
||||||
bool normal_fade_colors;
|
bool normal_fade_colors;
|
||||||
|
|
||||||
bool fatalerror;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BFile *file;
|
BFile *fFile;
|
||||||
|
|
||||||
bool GetInt(char *name, int *value, int *defaultvalue);
|
bool GetInt(char *name, int *value, int *defaultvalue);
|
||||||
bool GetBool(char *name, bool *value, bool *defaultvalue);
|
bool GetBool(char *name, bool *value, bool *defaultvalue);
|
||||||
@@ -42,6 +40,8 @@ class Prefs {
|
|||||||
void ComputeNormalWindowSize();
|
void ComputeNormalWindowSize();
|
||||||
BRect GetNormalWindowRect();
|
BRect GetNormalWindowRect();
|
||||||
BRect GetMiniWindowRect();
|
BRect GetMiniWindowRect();
|
||||||
|
|
||||||
|
bool fFatalError;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // PREFS_H
|
||||||
|
|||||||
Reference in New Issue
Block a user