summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/lib
authorkorovkin <korovkin>2006-11-10 20:53:23 (UTC)
committer korovkin <korovkin>2006-11-10 20:53:23 (UTC)
commitb06913999f349254ba1c6e182950cb71d0b7aa67 (patch) (side-by-side diff)
treeb91b3ad0745e9e471b244ca56456af56ba1e69a9 /noncore/net/opietooth/lib
parent961e5561b24452d9cfc2bf7400f6f5952b31431c (diff)
downloadopie-b06913999f349254ba1c6e182950cb71d0b7aa67.zip
opie-b06913999f349254ba1c6e182950cb71d0b7aa67.tar.gz
opie-b06913999f349254ba1c6e182950cb71d0b7aa67.tar.bz2
Files devicehandler.cpp and devicehandler.h moved from manager to
library to be used by obex to load a list of saved receivers.
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 @@
+
+#include <stdlib.h>
+
+#include <qdir.h>
+#include <qpe/config.h>
+#include <opie2/odebug.h>
+using namespace Opie::Core;
+
+#include "devicehandler.h"
+
+using namespace OpieTooth;
+
+DeviceHandler::DeviceHandler() {
+
+};
+DeviceHandler::~DeviceHandler() {
+
+}
+
+RemoteDevice::ValueList DeviceHandler::load() {
+ RemoteDevice::ValueList list;
+QString path = QDir::homeDirPath() + "/Settings/bluetooth";
+ QDir deviceListSave( path);
+
+ // list of .conf files
+ QStringList devicesFileList = deviceListSave.entryList();
+
+
+ // cut .conf of to get the mac and also read the name entry in it.
+ if (!devicesFileList.isEmpty() ) {
+ QString name;
+ QString mac;
+ QStringList::Iterator it;
+ for (it = devicesFileList.begin(); it != devicesFileList.end(); ++it ) {
+ if ( (*it) == "." || (*it) == ".." )
+ continue;
+
+ odebug << (*it).latin1() << oendl;
+ Config conf(path + "/"+(*it), Config::File);
+ conf.setGroup("Info");
+ name = conf.readEntry("name", "Error");
+ mac = conf.readEntry("mac", QString::null);
+ odebug << "MAC: " + mac << oendl;
+ odebug << "NAME: " + name << oendl;
+ if (mac.isEmpty() )
+ continue;
+ RemoteDevice currentDevice( mac , name );
+ list.append( currentDevice );
+ }
+ }
+ return list;
+};
+/*
+ * This is some how rude but make sure all old devices
+ * are getting deleted
+ */
+void DeviceHandler::save( const RemoteDevice::ValueList& list) {
+ QCString rm;
+ rm += "rm -rf ";
+ rm += QDir::homeDirPath() + "/Settings/bluetooth";
+ system ( rm.data() );
+
+ if (list.isEmpty() ) // no need to create the dir
+ return;
+
+ /**
+ * Create a new dir
+ */
+ rm = "mkdir ";
+ rm += QDir::homeDirPath() + "/Settings/bluetooth";
+ owarn << "out " << rm.data() << "" << oendl;
+ system( rm.data() );
+
+ RemoteDevice::ValueList::ConstIterator it;
+ // write the config
+
+ for ( it = list.begin(); it != list.end(); ++it ) {
+ odebug << "/Settings/bluetooth/" + (*it).mac() + ".conf" << oendl;
+
+ Config conf( QDir::homeDirPath() +
+ "/Settings/bluetooth/" +
+ (*it).mac() + ".conf", Config::File );
+
+ conf.setGroup( "Info" );
+ conf.writeEntry( "name", (*it).name() );
+ conf.writeEntry( "mac", (*it).mac() );
+ }
+
+}
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 @@
+
+#ifndef OPIE_TOOTH_DEVICE_HANDLER_H
+#define OPIE_TOOTH_DEVICE_HANDLER_H
+
+#include <qvaluelist.h>
+
+#include <remotedevice.h>
+
+namespace OpieTooth {
+ /**
+ * DeviceHandler is responsible for loading
+ * and saving devices from a config File
+ */
+ class DeviceHandler {
+ public:
+ /**
+ * c'tor
+ */
+ DeviceHandler();
+
+ /**
+ * d'tor
+ */
+ ~DeviceHandler();
+
+ /**
+ * loads from $HOME/Settings/bluetooth/ *
+ */
+ RemoteDevice::ValueList load();
+
+ /**
+ * Saves to $HOME/Settings/bluetooth
+ */
+ void save( const RemoteDevice::ValueList & );
+
+ };
+
+
+};
+
+#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
CONFIG += qte warn_on
HEADERS = connection.h parser.h device.h manager.h remotedevice.h services.h \
startpanconnection.h startdunconnection.h obexpush.h \
- bt-serial.h forwarder.h
+ bt-serial.h forwarder.h devicehandler.h
SOURCES = connection.cpp parser.cc device.cc manager.cc remotedevice.cc services.cc \
startpanconnection.cpp startdunconnection.cpp obexpush.cpp \
- bt-serial.c forwarder.cc
+ bt-serial.c forwarder.cc devicehandler.cpp
TARGET = opietooth1
INCLUDEPATH += $(OPIEDIR)/include .