00001 00002 #include <stdlib.h> 00003 00004 #include <qdir.h> 00005 #include <qpe/config.h> 00006 #include <opie2/odebug.h> 00007 using namespace Opie::Core; 00008 00009 #include "devicehandler.h" 00010 00011 using namespace OpieTooth; 00012 00013 DeviceHandler::DeviceHandler() { 00014 00015 }; 00016 DeviceHandler::~DeviceHandler() { 00017 00018 } 00019 00020 RemoteDevice::ValueList DeviceHandler::load() { 00021 RemoteDevice::ValueList list; 00022 QString path = QDir::homeDirPath() + "/Settings/bluetooth"; 00023 QDir deviceListSave( path); 00024 00025 // list of .conf files 00026 QStringList devicesFileList = deviceListSave.entryList(); 00027 00028 00029 // cut .conf of to get the mac and also read the name entry in it. 00030 if (!devicesFileList.isEmpty() ) { 00031 QString name; 00032 QString mac; 00033 QStringList::Iterator it; 00034 for (it = devicesFileList.begin(); it != devicesFileList.end(); ++it ) { 00035 if ( (*it) == "." || (*it) == ".." ) 00036 continue; 00037 00038 odebug << (*it).latin1() << oendl; 00039 Config conf(path + "/"+(*it), Config::File); 00040 conf.setGroup("Info"); 00041 name = conf.readEntry("name", "Error"); 00042 mac = conf.readEntry("mac", QString::null); 00043 odebug << "MAC: " + mac << oendl; 00044 odebug << "NAME: " + name << oendl; 00045 if (mac.isEmpty() ) 00046 continue; 00047 RemoteDevice currentDevice( mac , name ); 00048 list.append( currentDevice ); 00049 } 00050 } 00051 return list; 00052 }; 00053 /* 00054 * This is some how rude but make sure all old devices 00055 * are getting deleted 00056 */ 00057 void DeviceHandler::save( const RemoteDevice::ValueList& list) { 00058 QCString rm; 00059 rm += "rm -rf "; 00060 rm += QDir::homeDirPath() + "/Settings/bluetooth"; 00061 system ( rm.data() ); 00062 00063 if (list.isEmpty() ) // no need to create the dir 00064 return; 00065 00069 rm = "mkdir "; 00070 rm += QDir::homeDirPath() + "/Settings/bluetooth"; 00071 owarn << "out " << rm.data() << "" << oendl; 00072 system( rm.data() ); 00073 00074 RemoteDevice::ValueList::ConstIterator it; 00075 // write the config 00076 00077 for ( it = list.begin(); it != list.end(); ++it ) { 00078 odebug << "/Settings/bluetooth/" + (*it).mac() + ".conf" << oendl; 00079 00080 Config conf( QDir::homeDirPath() + 00081 "/Settings/bluetooth/" + 00082 (*it).mac() + ".conf", Config::File ); 00083 00084 conf.setGroup( "Info" ); 00085 conf.writeEntry( "name", (*it).name() ); 00086 conf.writeEntry( "mac", (*it).mac() ); 00087 } 00088 00089 }
1.4.2