author | korovkin <korovkin> | 2006-11-10 20:53:23 (UTC) |
---|---|---|
committer | korovkin <korovkin> | 2006-11-10 20:53:23 (UTC) |
commit | b06913999f349254ba1c6e182950cb71d0b7aa67 (patch) (unidiff) | |
tree | b91b3ad0745e9e471b244ca56456af56ba1e69a9 /noncore/net/opietooth/lib/devicehandler.cpp | |
parent | 961e5561b24452d9cfc2bf7400f6f5952b31431c (diff) | |
download | opie-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/devicehandler.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/opietooth/lib/devicehandler.cpp | 89 |
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> | ||
7 | using namespace Opie::Core; | ||
8 | |||
9 | #include "devicehandler.h" | ||
10 | |||
11 | using namespace OpieTooth; | ||
12 | |||
13 | DeviceHandler::DeviceHandler() { | ||
14 | |||
15 | }; | ||
16 | DeviceHandler::~DeviceHandler() { | ||
17 | |||
18 | } | ||
19 | |||
20 | RemoteDevice::ValueList DeviceHandler::load() { | ||
21 | RemoteDevice::ValueList list; | ||
22 | QString 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 | */ | ||
57 | void 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 | } | ||