xref: /haiku/src/preferences/bluetooth/BluetoothSettings.cpp (revision 410ed2fbba58819ac21e27d3676739728416761d)
1 /*
2  * Copyright 2008-2009, Oliver Ruiz Dorantes, <oliver.ruiz.dorantes@gmail.com>
3  * Copyright 2012-2013, Tri-Edge AI <triedgeai@gmail.com>
4  * Copyright 2021, Haiku, Inc.
5  * Distributed under the terms of the MIT License.
6  *
7  * Authors:
8  * 		Fredrik Modéen <fredrik_at_modeen.se>
9  */
10 #include "BluetoothSettings.h"
11 
12 BluetoothSettings::BluetoothSettings()
13 {
14 	find_directory(B_USER_SETTINGS_DIRECTORY, &fPath);
15 	fPath.Append("Bluetooth_settings", true);
16 }
17 
18 
19 BluetoothSettings::~BluetoothSettings()
20 {
21 }
22 
23 
24 void
25 BluetoothSettings::Defaults()
26 {
27 	Data.PickedDevice = bdaddrUtils::NullAddress();
28 	Data.LocalDeviceClass = DeviceClass();
29 	Data.Policy = 0;
30 	Data.InquiryTime = 15;
31 }
32 
33 
34 void
35 BluetoothSettings::Load()
36 {
37 	fFile = new BFile(fPath.Path(), B_READ_ONLY);
38 
39 	if (fFile->InitCheck() == B_OK) {
40 		fFile->Read(&Data, sizeof(Data));
41 	} else
42 		Defaults();
43 
44 	delete fFile;
45 }
46 
47 
48 void
49 BluetoothSettings::Save()
50 {
51 	fFile = new BFile(fPath.Path(), B_WRITE_ONLY | B_CREATE_FILE);
52 
53 	if (fFile->InitCheck() == B_OK) {
54 		fFile->Write(&Data, sizeof(Data));
55 	}
56 
57 	delete fFile;
58 }
59