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