xref: /haiku/src/preferences/time/TimeSettings.cpp (revision 3cb015b1ee509d69c643506e8ff573808c86dcfc)
1 /*
2  * Copyright 2002-2006, Haiku. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors in chronological order:
6  *		Andrew McCall, mccall@digitalparadise.co.uk
7  *		Mike Berg
8  */
9 
10 
11 #include "TimeSettings.h"
12 #include "TimeMessages.h"
13 
14 #include <Application.h>
15 #include <FindDirectory.h>
16 #include <File.h>
17 #include <Path.h>
18 #include <String.h>
19 #include <stdio.h>
20 
21 
22 const char TimeSettings::kTimeSettingsFile[] = "Time_settings";
23 
24 
25 TimeSettings::TimeSettings()
26 {
27 	BPath path;
28 
29 	if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) == B_OK) {
30 		path.Append(kTimeSettingsFile);
31 		BFile file(path.Path(), B_READ_ONLY);
32 		if (file.InitCheck() == B_OK) {
33 			// Now read in the data
34 			if (file.Read(&fCorner, sizeof(BPoint)) != sizeof(BPoint)) {
35 				fCorner.x = 50;
36 				fCorner.y = 50;
37 			}
38 		} else {
39 			fCorner.x = 50;
40 			fCorner.y = 50;
41 		}
42 	} else
43 		be_app->PostMessage(ERROR_DETECTED);
44 }
45 
46 
47 TimeSettings::~TimeSettings()
48 {
49 	BPath path;
50 	if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
51 		return;
52 
53 	path.Append(kTimeSettingsFile);
54 
55 	BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
56 	if (file.InitCheck() == B_OK) {
57 		file.Write(&fCorner, sizeof(BPoint));
58 	}
59 }
60 
61 
62 void
63 TimeSettings::SetWindowCorner(BPoint corner)
64 {
65 	fCorner = corner;
66 }
67