summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/lib
Unidiff
Diffstat (limited to 'noncore/net/opietooth/lib') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/devicehandler.cpp89
-rw-r--r--noncore/net/opietooth/lib/devicehandler.h41
-rw-r--r--noncore/net/opietooth/lib/lib.pro4
3 files changed, 132 insertions, 2 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}
diff --git a/noncore/net/opietooth/lib/devicehandler.h b/noncore/net/opietooth/lib/devicehandler.h
new file mode 100644
index 0000000..5cfe048
--- a/dev/null
+++ b/noncore/net/opietooth/lib/devicehandler.h
@@ -0,0 +1,41 @@
1
2#ifndef OPIE_TOOTH_DEVICE_HANDLER_H
3#define OPIE_TOOTH_DEVICE_HANDLER_H
4
5#include <qvaluelist.h>
6
7#include <remotedevice.h>
8
9namespace OpieTooth {
10 /**
11 * DeviceHandler is responsible for loading
12 * and saving devices from a config File
13 */
14 class DeviceHandler {
15 public:
16 /**
17 * c'tor
18 */
19 DeviceHandler();
20
21 /**
22 * d'tor
23 */
24 ~DeviceHandler();
25
26 /**
27 * loads from $HOME/Settings/bluetooth/ *
28 */
29 RemoteDevice::ValueList load();
30
31 /**
32 * Saves to $HOME/Settings/bluetooth
33 */
34 void save( const RemoteDevice::ValueList & );
35
36 };
37
38
39};
40
41#endif
diff --git a/noncore/net/opietooth/lib/lib.pro b/noncore/net/opietooth/lib/lib.pro
index e11af9a..08d79ea 100644
--- a/noncore/net/opietooth/lib/lib.pro
+++ b/noncore/net/opietooth/lib/lib.pro
@@ -2,10 +2,10 @@ TEMPLATE = lib
2CONFIG += qte warn_on 2CONFIG += qte warn_on
3 HEADERS = connection.h parser.h device.h manager.h remotedevice.h services.h \ 3 HEADERS = connection.h parser.h device.h manager.h remotedevice.h services.h \
4 startpanconnection.h startdunconnection.h obexpush.h \ 4 startpanconnection.h startdunconnection.h obexpush.h \
5 bt-serial.h forwarder.h 5 bt-serial.h forwarder.h devicehandler.h
6 SOURCES = connection.cpp parser.cc device.cc manager.cc remotedevice.cc services.cc \ 6 SOURCES = connection.cpp parser.cc device.cc manager.cc remotedevice.cc services.cc \
7 startpanconnection.cpp startdunconnection.cpp obexpush.cpp \ 7 startpanconnection.cpp startdunconnection.cpp obexpush.cpp \
8 bt-serial.c forwarder.cc 8 bt-serial.c forwarder.cc devicehandler.cpp
9 9
10 TARGET = opietooth1 10 TARGET = opietooth1
11INCLUDEPATH += $(OPIEDIR)/include . 11INCLUDEPATH += $(OPIEDIR)/include .