Diffstat (limited to 'noncore/net/opietooth/manager/devicehandler.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opietooth/manager/devicehandler.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/noncore/net/opietooth/manager/devicehandler.cpp b/noncore/net/opietooth/manager/devicehandler.cpp new file mode 100644 index 0000000..9c5b817 --- a/dev/null +++ b/noncore/net/opietooth/manager/devicehandler.cpp | |||
@@ -0,0 +1,87 @@ | |||
1 | |||
2 | #include <stdlib.h> | ||
3 | |||
4 | #include <qdir.h> | ||
5 | #include <qpe/config.h> | ||
6 | |||
7 | #include "devicehandler.h" | ||
8 | |||
9 | using namespace OpieTooth; | ||
10 | |||
11 | DeviceHandler::DeviceHandler() { | ||
12 | |||
13 | }; | ||
14 | DeviceHandler::~DeviceHandler() { | ||
15 | |||
16 | } | ||
17 | |||
18 | RemoteDevice::ValueList DeviceHandler::load() { | ||
19 | RemoteDevice::ValueList list; | ||
20 | QString path = QDir::homeDirPath() + "/Settings/bluetooth"; | ||
21 | QDir deviceListSave( path); | ||
22 | |||
23 | // list of .conf files | ||
24 | QStringList devicesFileList = deviceListSave.entryList(); | ||
25 | |||
26 | |||
27 | // cut .conf of to get the mac and also read the name entry in it. | ||
28 | if (!devicesFileList.isEmpty() ) { | ||
29 | QString name; | ||
30 | QString mac; | ||
31 | QStringList::Iterator it; | ||
32 | for (it = devicesFileList.begin(); it != devicesFileList.end(); ++it ) { | ||
33 | if ( (*it) == "." || (*it) == ".." ) | ||
34 | continue; | ||
35 | |||
36 | qDebug((*it).latin1() ); | ||
37 | Config conf(path + "/"+(*it), Config::File); | ||
38 | conf.setGroup("Info"); | ||
39 | name = conf.readEntry("name", "Error"); | ||
40 | mac = conf.readEntry("mac", QString::null); | ||
41 | qDebug("MAC: " + mac); | ||
42 | qDebug("NAME: " + name); | ||
43 | if (mac.isEmpty() ) | ||
44 | continue; | ||
45 | RemoteDevice currentDevice( mac , name ); | ||
46 | list.append( currentDevice ); | ||
47 | } | ||
48 | } | ||
49 | return list; | ||
50 | }; | ||
51 | /* | ||
52 | * This is some how rude but make sure all old devices | ||
53 | * are getting deleted | ||
54 | */ | ||
55 | void DeviceHandler::save( const RemoteDevice::ValueList& list) { | ||
56 | QCString rm; | ||
57 | rm += "rm -rf "; | ||
58 | rm += QDir::homeDirPath() + "/Settings/bluetooth"; | ||
59 | system ( rm.data() ); | ||
60 | |||
61 | if (list.isEmpty() ) // no need to create the dir | ||
62 | return; | ||
63 | |||
64 | /** | ||
65 | * Create a new dir | ||
66 | */ | ||
67 | rm = "mkdir "; | ||
68 | rm += QDir::homeDirPath() + "/Settings/bluetooth"; | ||
69 | qWarning("out %s", rm.data() ); | ||
70 | system( rm.data() ); | ||
71 | |||
72 | RemoteDevice::ValueList::ConstIterator it; | ||
73 | // write the config | ||
74 | |||
75 | for ( it = list.begin(); it != list.end(); ++it ) { | ||
76 | qDebug( "/Settings/bluetooth/" + (*it).mac() + ".conf"); | ||
77 | |||
78 | Config conf( QDir::homeDirPath() + | ||
79 | "/Settings/bluetooth/" + | ||
80 | (*it).mac() + ".conf", Config::File ); | ||
81 | |||
82 | conf.setGroup( "Info" ); | ||
83 | conf.writeEntry( "name", (*it).name() ); | ||
84 | conf.writeEntry( "mac", (*it).mac() ); | ||
85 | } | ||
86 | |||
87 | } | ||