author | mickeyl <mickeyl> | 2003-10-29 18:18:19 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-10-29 18:18:19 (UTC) |
commit | 1af1f1d9f398d38a2bc666cd2edff5725da7a770 (patch) (unidiff) | |
tree | b3bb0d90cafc1e933b5b9297a7b2669ce3b184ea /noncore/net/opietooth/manager/rfcommconfhandler.cpp | |
parent | 35615947e11575a61456c8483e7f6d67fe59d5ed (diff) | |
download | opie-1af1f1d9f398d38a2bc666cd2edff5725da7a770.zip opie-1af1f1d9f398d38a2bc666cd2edff5725da7a770.tar.gz opie-1af1f1d9f398d38a2bc666cd2edff5725da7a770.tar.bz2 |
mrege noncore/net/*
Diffstat (limited to 'noncore/net/opietooth/manager/rfcommconfhandler.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/opietooth/manager/rfcommconfhandler.cpp | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/noncore/net/opietooth/manager/rfcommconfhandler.cpp b/noncore/net/opietooth/manager/rfcommconfhandler.cpp new file mode 100644 index 0000000..20453e8 --- a/dev/null +++ b/noncore/net/opietooth/manager/rfcommconfhandler.cpp | |||
@@ -0,0 +1,114 @@ | |||
1 | |||
2 | #include <qtextstream.h> | ||
3 | |||
4 | #include "rfcommconfhandler.h" | ||
5 | |||
6 | |||
7 | using namespace OpieTooth; | ||
8 | |||
9 | // move to lib | ||
10 | |||
11 | |||
12 | RfCommConfObject::RfCommConfObject( int number, QString mac, int channel, QString comment ) { | ||
13 | m_number = number; | ||
14 | m_mac = mac; | ||
15 | m_channel = channel; | ||
16 | m_comment = comment; | ||
17 | // m_foundEntries = 0; | ||
18 | } | ||
19 | |||
20 | void RfCommConfObject::setNumber( int number ) { | ||
21 | m_number = number; | ||
22 | } | ||
23 | |||
24 | void RfCommConfObject::setMac( QString mac ) { | ||
25 | m_mac = mac; | ||
26 | } | ||
27 | |||
28 | void RfCommConfObject::setChannel( int channel ) { | ||
29 | m_channel = channel; | ||
30 | } | ||
31 | |||
32 | void RfCommConfObject::setComment( QString comment ) { | ||
33 | m_comment = comment; | ||
34 | } | ||
35 | |||
36 | |||
37 | RfCommConfObject::~RfCommConfObject() { | ||
38 | } | ||
39 | |||
40 | |||
41 | RfCommConfHandler::RfCommConfHandler( const QString & filename ) { | ||
42 | |||
43 | m_filename = filename; | ||
44 | load(); | ||
45 | } | ||
46 | |||
47 | RfCommConfHandler::~RfCommConfHandler() { | ||
48 | |||
49 | } | ||
50 | |||
51 | void RfCommConfHandler::save( QMap<QString, RfCommConfObject*> devices ) { | ||
52 | |||
53 | QFile rfCommConf( "/tmp/test" ); | ||
54 | QTextStream outStream( &rfCommConf ); | ||
55 | if ( rfCommConf.open( IO_WriteOnly ) ) { | ||
56 | |||
57 | QMap<QString, RfCommConfObject*>::Iterator it; | ||
58 | for( it = devices.begin(); it != devices.end(); ++it ) { | ||
59 | outStream << "rfcomm" + QString("%1").arg( it.data()->number() ) + " {\n"; | ||
60 | outStream << " device " + it.data()->mac() + ";\n"; | ||
61 | outStream << " channel " + QString( "%1" ).arg( it.data()->channel() ) + ";\n"; | ||
62 | outStream << " comment \"" + it.data()->comment() + "\";\n"; | ||
63 | outStream << "}\n\n"; | ||
64 | } | ||
65 | |||
66 | rfCommConf.close(); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | |||
71 | QMap<QString, RfCommConfObject*> RfCommConfHandler::foundEntries() { | ||
72 | return m_foundEntries; | ||
73 | } | ||
74 | |||
75 | void RfCommConfHandler::load() { | ||
76 | |||
77 | QFile rfCommConf( m_filename ); | ||
78 | if ( rfCommConf.open( IO_ReadOnly ) ) { | ||
79 | |||
80 | QStringList list; | ||
81 | QTextStream inStream( &rfCommConf ); | ||
82 | list = QStringList::split( "\n", inStream.read() ); | ||
83 | |||
84 | QString number; | ||
85 | QString mac; | ||
86 | QString channel; | ||
87 | QString comment; | ||
88 | |||
89 | for ( QStringList::Iterator line=list.begin(); line != list.end(); line++ ) { | ||
90 | |||
91 | QString tmpLine = ( *line ).stripWhiteSpace(); | ||
92 | |||
93 | if ( tmpLine.startsWith("rfcomm") ) { | ||
94 | QString number = tmpLine.mid( 6,1 ); | ||
95 | qDebug( tmpLine ); | ||
96 | qDebug( "TEST " + number ); | ||
97 | } else if ( tmpLine.startsWith( "}" ) ) { | ||
98 | m_foundEntries.insert( number, new RfCommConfObject( number.toInt(), mac, channel.toInt(), comment ) ); | ||
99 | } else if ( tmpLine.startsWith( "device" ) ) { | ||
100 | mac = tmpLine.mid( 7, 17 ); | ||
101 | qDebug( "mac" + mac ); | ||
102 | } else if ( tmpLine.startsWith( "channel" ) ) { | ||
103 | channel = tmpLine.mid( 8, 1 ); | ||
104 | qDebug ( "Channel :" + channel ); | ||
105 | } else if ( tmpLine.startsWith( "comment" ) ) { | ||
106 | comment = tmpLine.mid( 9, tmpLine.find( ';' ) - 9 - 1 ); | ||
107 | qDebug( "Comment: " + comment ); | ||
108 | } | ||
109 | } | ||
110 | rfCommConf.close(); | ||
111 | } | ||
112 | save( m_foundEntries ); | ||
113 | qDebug( QString( "ENTries: %1").arg( m_foundEntries.count() ) ); | ||
114 | } | ||