1 //****************************************************************************************
5 // Written by: Daniel Switkin
7 // Copyright 1999, Be Incorporated
9 //****************************************************************************************
16 #include <FindDirectory.h>
30 find_directory(B_USER_SETTINGS_DIRECTORY
, &path
);
31 path
.Append("Pulse_settings");
32 fFile
= new BFile(path
.Path(), B_READ_WRITE
| B_CREATE_FILE
);
33 if (fFile
->InitCheck() != B_OK
) {
34 // try to open read-only
35 if (fFile
->SetTo(path
.Path(), B_READ_ONLY
) != B_OK
) {
41 int i
= NORMAL_WINDOW_MODE
;
42 if (!GetInt("window_mode", &window_mode
, &i
)) {
47 // These three prefs require a connection to the app_server
48 BRect r
= GetNormalWindowRect();
49 if (!GetRect("normal_window_rect", &normal_window_rect
, &r
)) {
53 // While normal window position is under user control, size is not.
54 // Width is fixed and height must be dynamically computed each time,
55 // as number of CPUs could change since boot.
56 ComputeNormalWindowSize();
58 r
= GetMiniWindowRect();
59 if (!GetRect("mini_window_rect", &mini_window_rect
, &r
)) {
64 r
.Set(100, 100, 415, 329);
65 if (!GetRect("prefs_window_rect", &prefs_window_rect
, &r
)) {
70 i
= DEFAULT_NORMAL_BAR_COLOR
;
71 if (!GetInt("normal_bar_color", &normal_bar_color
, &i
)) {
76 i
= DEFAULT_MINI_ACTIVE_COLOR
;
77 if (!GetInt("mini_active_color", &mini_active_color
, &i
)) {
82 i
= DEFAULT_MINI_IDLE_COLOR
;
83 if (!GetInt("mini_idle_color", &mini_idle_color
, &i
)) {
88 i
= DEFAULT_MINI_FRAME_COLOR
;
89 if (!GetInt("mini_frame_color", &mini_frame_color
, &i
)) {
94 i
= DEFAULT_DESKBAR_ACTIVE_COLOR
;
95 if (!GetInt("deskbar_active_color", &deskbar_active_color
, &i
)) {
100 i
= DEFAULT_DESKBAR_IDLE_COLOR
;
101 if (!GetInt("deskbar_idle_color", &deskbar_idle_color
, &i
)) {
106 i
= DEFAULT_DESKBAR_FRAME_COLOR
;
107 if (!GetInt("deskbar_frame_color", &deskbar_frame_color
, &i
)) {
112 bool b
= DEFAULT_NORMAL_FADE_COLORS
;
113 if (!GetBool("normal_fade_colors", &normal_fade_colors
, &b
)) {
118 // Use the default size unless it would prevent having at least
119 // a one pixel wide display per CPU... this will only happen with > quad
120 i
= DEFAULT_DESKBAR_ICON_WIDTH
;
121 if (i
< GetMinimumViewWidth())
122 i
= GetMinimumViewWidth();
123 if (!GetInt("deskbar_icon_width", &deskbar_icon_width
, &i
)) {
137 Prefs::GetNormalWindowHeight()
139 system_info sys_info
;
140 get_system_info(&sys_info
);
142 float height
= PROGRESS_MTOP
+ PROGRESS_MBOTTOM
143 + sys_info
.cpu_count
* ITEM_OFFSET
;
144 if (PULSEVIEW_MIN_HEIGHT
> height
)
145 height
= PULSEVIEW_MIN_HEIGHT
;
152 Prefs::ComputeNormalWindowSize()
154 normal_window_rect
.right
= normal_window_rect
.left
+ PULSEVIEW_WIDTH
;
155 normal_window_rect
.bottom
= normal_window_rect
.top
+ GetNormalWindowHeight();
160 Prefs::GetNormalWindowRect()
162 // Dock the window in the lower right hand corner just like the original
163 BRect
r(0, 0, PULSEVIEW_WIDTH
, GetNormalWindowHeight());
164 BRect screen_rect
= BScreen(B_MAIN_SCREEN_ID
).Frame();
165 r
.OffsetTo(screen_rect
.right
- r
.Width() - 5, screen_rect
.bottom
- r
.Height() - 5);
171 Prefs::GetMiniWindowRect()
173 // Lower right hand corner by default
174 BRect screen_rect
= BScreen(B_MAIN_SCREEN_ID
).Frame();
175 screen_rect
.left
= screen_rect
.right
- 30;
176 screen_rect
.top
= screen_rect
.bottom
- 150;
177 screen_rect
.OffsetBy(-5, -5);
183 Prefs::GetInt(const char *name
, int *value
, int *defaultvalue
)
185 status_t err
= fFile
->ReadAttr(name
, B_INT32_TYPE
, 0, value
, 4);
186 if (err
== B_ENTRY_NOT_FOUND
) {
187 *value
= *defaultvalue
;
188 if (fFile
->WriteAttr(name
, B_INT32_TYPE
, 0, defaultvalue
, 4) < 0) {
189 printf("WriteAttr on %s died\n", name
);
192 } else if (err
< 0) {
193 printf("Unknown error reading %s:\n%s\n", name
, strerror(err
));
202 Prefs::GetBool(const char *name
, bool *value
, bool *defaultvalue
)
204 status_t err
= fFile
->ReadAttr(name
, B_BOOL_TYPE
, 0, value
, 1);
205 if (err
== B_ENTRY_NOT_FOUND
) {
206 *value
= *defaultvalue
;
207 if (fFile
->WriteAttr(name
, B_BOOL_TYPE
, 0, defaultvalue
, 1) < 0) {
208 printf("WriteAttr on %s died\n", name
);
211 } else if (err
< 0) {
212 printf("Unknown error reading %s:\n%s\n", name
, strerror(err
));
221 Prefs::GetRect(const char *name
, BRect
*value
, BRect
*defaultvalue
)
223 status_t err
= fFile
->ReadAttr(name
, B_RECT_TYPE
, 0, value
, sizeof(BRect
));
224 if (err
== B_ENTRY_NOT_FOUND
) {
225 *value
= *defaultvalue
;
226 if (fFile
->WriteAttr(name
, B_RECT_TYPE
, 0, defaultvalue
, sizeof(BRect
)) < 0) {
227 printf("WriteAttr on %s died\n", name
);
230 } else if (err
< 0) {
231 printf("Unknown error reading %s:\n%s\n", name
, strerror(err
));
240 Prefs::PutInt(const char *name
, int *value
)
242 status_t err
= fFile
->WriteAttr(name
, B_INT32_TYPE
, 0, value
, 4);
244 printf("Unknown error writing %s:\n%s\n", name
, strerror(err
));
253 Prefs::PutBool(const char *name
, bool *value
)
255 status_t err
= fFile
->WriteAttr(name
, B_BOOL_TYPE
, 0, value
, 1);
257 printf("Unknown error writing %s:\n%s\n", name
, strerror(err
));
266 Prefs::PutRect(const char *name
, BRect
*value
)
268 status_t err
= fFile
->WriteAttr(name
, B_RECT_TYPE
, 0, value
, sizeof(BRect
));
270 printf("Unknown error writing %s:\n%s\n", name
, strerror(err
));
284 if (!PutInt("window_mode", &window_mode
)
285 || !PutRect("normal_window_rect", &normal_window_rect
)
286 || !PutRect("mini_window_rect", &mini_window_rect
)
287 || !PutRect("prefs_window_rect", &prefs_window_rect
)
288 || !PutInt("normal_bar_color", &normal_bar_color
)
289 || !PutInt("mini_active_color", &mini_active_color
)
290 || !PutInt("mini_idle_color", &mini_idle_color
)
291 || !PutInt("mini_frame_color", &mini_frame_color
)
292 || !PutInt("deskbar_active_color", &deskbar_active_color
)
293 || !PutInt("deskbar_idle_color", &deskbar_idle_color
)
294 || !PutInt("deskbar_frame_color", &deskbar_frame_color
)
295 || !PutBool("normal_fade_colors", &normal_fade_colors
)
296 || !PutInt("deskbar_icon_width", &deskbar_icon_width
))