-rw-r--r-- | core/obex/obex.cpp | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/core/obex/obex.cpp b/core/obex/obex.cpp index 36634ec..95c561a 100644 --- a/core/obex/obex.cpp +++ b/core/obex/obex.cpp | |||
@@ -1,79 +1,102 @@ | |||
1 | /* | ||
2 | =. This file is part of the OPIE Project | ||
3 | .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de> | ||
4 | .>+-= | ||
5 | _;:, .> :=|. This library is free software; you can | ||
6 | .> <, > . <= redistribute it and/or modify it under | ||
7 | :=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
8 | .="- .-=="i, .._ License as published by the Free Software | ||
9 | - . .-<_> .<> Foundation; version 2 of the License. | ||
10 | ._= =} : | ||
11 | .%+i> _;_. | ||
12 | .i_,=:_. -<s. This library is distributed in the hope that | ||
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
14 | : .. .:, . . . without even the implied warranty of | ||
15 | =_ + =;=| MERCHANTABILITY or FITNESS FOR A | ||
16 | _.=:. : :=>: PARTICULAR PURPOSE. See the GNU | ||
17 | ..}^=.= = ; Library General Public License for more | ||
18 | ++= -. . .: details. | ||
19 | : = ...= . :.=- | ||
20 | -. .:....=;==+<; You should have received a copy of the GNU | ||
21 | -_. . . )=. = Library General Public License along with | ||
22 | -- :-= this library; see the file COPYING.LIB. | ||
23 | If not, write to the Free Software Foundation, | ||
24 | Inc., 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | /* | ||
29 | * The Infrared OBEX handling class implementation | ||
30 | */ | ||
1 | 31 | ||
2 | #include "obex.h" | 32 | #include "obex.h" |
3 | 33 | ||
4 | /* OPIE */ | 34 | /* OPIE */ |
5 | #include <opie2/oprocess.h> | 35 | #include <opie2/oprocess.h> |
6 | #include <opie2/odebug.h> | 36 | #include <opie2/odebug.h> |
7 | 37 | ||
8 | /* QT */ | 38 | /* QT */ |
9 | #include <qfileinfo.h> | 39 | #include <qfileinfo.h> |
10 | 40 | ||
11 | 41 | ||
12 | 42 | ||
13 | using namespace OpieObex; | 43 | using namespace OpieObex; |
14 | 44 | ||
15 | using namespace Opie::Core; | 45 | using namespace Opie::Core; |
16 | /* TRANSLATOR OpieObex::Obex */ | 46 | /* TRANSLATOR OpieObex::Obex */ |
17 | 47 | ||
18 | Obex::Obex( QObject *parent, const char* name ) | 48 | Obex::Obex( QObject *parent, const char* name ) |
19 | : QObject(parent, name ) | 49 | : ObexBase(parent, name ) |
20 | { | 50 | { |
21 | m_rec = 0; | 51 | m_rec = 0; |
22 | m_send=0; | 52 | m_send=0; |
23 | m_count = 0; | ||
24 | m_receive = false; | ||
25 | connect( this, SIGNAL(error(int) ), // for recovering to receive | ||
26 | SLOT(slotError() ) ); | ||
27 | connect( this, SIGNAL(sent(bool) ), | ||
28 | SLOT(slotError() ) ); | ||
29 | }; | 53 | }; |
30 | Obex::~Obex() { | 54 | Obex::~Obex() { |
31 | delete m_rec; | 55 | delete m_rec; |
32 | delete m_send; | 56 | delete m_send; |
33 | } | 57 | } |
34 | void Obex::receive() { | 58 | void Obex::receive() { |
35 | m_receive = true; | 59 | ObexBase::receive(); |
36 | m_outp = QString::null; | ||
37 | m_rec = new OProcess(); | 60 | m_rec = new OProcess(); |
38 | *m_rec << "irobex_palm3"; | 61 | *m_rec << "irobex_palm3"; |
39 | // connect to the necessary slots | 62 | // connect to the necessary slots |
40 | connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), | 63 | connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), |
41 | this, SLOT(slotExited(Opie::Core::OProcess*) ) ); | 64 | this, SLOT(slotExited(Opie::Core::OProcess*) ) ); |
42 | 65 | ||
43 | connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), | 66 | connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), |
44 | this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); | 67 | this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); |
45 | 68 | ||
46 | if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { | 69 | if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { |
47 | emit done( false ); | 70 | emit done( false ); |
48 | delete m_rec; | 71 | delete m_rec; |
49 | m_rec = 0; | 72 | m_rec = 0; |
50 | } | 73 | } |
51 | } | 74 | } |
52 | 75 | ||
53 | void Obex::send( const QString& fileName) { // if currently receiving stop it send receive | 76 | // if currently receiving stop it send receive |
54 | m_count = 0; | 77 | void Obex::send(const QString& fileName, const QString& addr) { |
55 | m_file = fileName; | 78 | ObexBase::send(fileName, addr); |
56 | if (m_rec != 0 ) { | 79 | if (m_rec != 0 ) { |
57 | if (m_rec->isRunning() ) { | 80 | if (m_rec->isRunning() ) { |
58 | emit error(-1 ); | 81 | emit error(-1 ); |
59 | delete m_rec; | 82 | delete m_rec; |
60 | m_rec = 0; | 83 | m_rec = 0; |
61 | 84 | ||
62 | }else{ | 85 | }else{ |
63 | emit error( -1 ); // we did not delete yet but it's not running slotExited is pending | 86 | emit error( -1 ); // we did not delete yet but it's not running slotExited is pending |
64 | return; | 87 | return; |
65 | } | 88 | } |
66 | } | 89 | } |
67 | sendNow(); | 90 | sendNow(); |
68 | } | 91 | } |
69 | void Obex::sendNow(){ | 92 | void Obex::sendNow(){ |
70 | if ( m_count >= 25 ) { // could not send | 93 | if ( m_count >= 25 ) { // could not send |
71 | emit error(-1 ); | 94 | emit error(-1 ); |
72 | emit sent(false); | 95 | emit sent(false); |
73 | return; | 96 | return; |
74 | } | 97 | } |
75 | // OProcess inititialisation | 98 | // OProcess inititialisation |
76 | m_send = new OProcess(); | 99 | m_send = new OProcess(); |
77 | m_send->setWorkingDirectory( QFileInfo(m_file).dirPath(true) ); | 100 | m_send->setWorkingDirectory( QFileInfo(m_file).dirPath(true) ); |
78 | 101 | ||
79 | *m_send << "irobex_palm3"; | 102 | *m_send << "irobex_palm3"; |
@@ -144,44 +167,46 @@ void Obex::sendEnd() { | |||
144 | m_send = 0; | 167 | m_send = 0; |
145 | } | 168 | } |
146 | } | 169 | } |
147 | QString Obex::parseOut( ){ | 170 | QString Obex::parseOut( ){ |
148 | QString path; | 171 | QString path; |
149 | QStringList list = QStringList::split("\n", m_outp); | 172 | QStringList list = QStringList::split("\n", m_outp); |
150 | QStringList::Iterator it; | 173 | QStringList::Iterator it; |
151 | for (it = list.begin(); it != list.end(); ++it ) { | 174 | for (it = list.begin(); it != list.end(); ++it ) { |
152 | if ( (*it).startsWith("Wrote" ) ) { | 175 | if ( (*it).startsWith("Wrote" ) ) { |
153 | int pos = (*it).findRev('(' ); | 176 | int pos = (*it).findRev('(' ); |
154 | if ( pos > 0 ) { | 177 | if ( pos > 0 ) { |
155 | 178 | ||
156 | path = (*it).remove( pos, (*it).length() - pos ); | 179 | path = (*it).remove( pos, (*it).length() - pos ); |
157 | path = path.mid(6 ); | 180 | path = path.mid(6 ); |
158 | path = path.stripWhiteSpace(); | 181 | path = path.stripWhiteSpace(); |
159 | } | 182 | } |
160 | } | 183 | } |
161 | } | 184 | } |
162 | return path; | 185 | return path; |
163 | } | 186 | } |
164 | /** | 187 | /** |
165 | * when sent is done slotError is called we will start receive again | 188 | * when sent is done slotError is called we will start receive again |
166 | */ | 189 | */ |
167 | void Obex::slotError() { | 190 | void Obex::slotError() { |
191 | ObexBase::slotError(); | ||
168 | if ( m_receive ) | 192 | if ( m_receive ) |
169 | receive(); | 193 | receive(); |
170 | }; | 194 | }; |
171 | void Obex::setReceiveEnabled( bool receive ) { | 195 | void Obex::setReceiveEnabled( bool receive ) { |
196 | ObexBase::setReceiveEnabled(receive); | ||
172 | if ( !receive ) { // | 197 | if ( !receive ) { // |
173 | m_receive = false; | 198 | m_receive = false; |
174 | shutDownReceive(); | 199 | shutDownReceive(); |
175 | } | 200 | } |
176 | } | 201 | } |
177 | 202 | ||
178 | void Obex::shutDownReceive() { | 203 | void Obex::shutDownReceive() { |
179 | if (m_rec != 0 ) { | 204 | if (m_rec != 0 ) { |
180 | if (m_rec->isRunning() ) { | 205 | if (m_rec->isRunning() ) { |
181 | emit error(-1 ); | 206 | emit error(-1 ); |
182 | delete m_rec; | 207 | delete m_rec; |
183 | m_rec = 0; | 208 | m_rec = 0; |
184 | } | 209 | } |
185 | } | 210 | } |
186 | 211 | ||
187 | } | 212 | } |