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