summaryrefslogtreecommitdiff
path: root/core/obex/obex.cc
authormickeyl <mickeyl>2005-08-22 09:36:38 (UTC)
committer mickeyl <mickeyl>2005-08-22 09:36:38 (UTC)
commit7202ac536ac98e7e433984d98cb9236330b25cc8 (patch) (unidiff)
treec8b5d4e57dd4b9b302999d1f88a89c28e4ee0e5e /core/obex/obex.cc
parent140e4dc44a29678de1ae8b2cef5b1d081993223e (diff)
downloadopie-7202ac536ac98e7e433984d98cb9236330b25cc8.zip
opie-7202ac536ac98e7e433984d98cb9236330b25cc8.tar.gz
opie-7202ac536ac98e7e433984d98cb9236330b25cc8.tar.bz2
Replace the existing, apparently non-working, OBEX Send form with a
completely new implementation. The new implementation supports selective send over both IrDA and Bluetooth, to selected receivers (which are discovered as the form pops up). The form also indicates transfer status as the transfers progress. There is a new QT Designer UI form file, integrated into the build. There are also two new source files for the form to supply the abstract methods (typical of QT2). Patch courtesy Michael Haynie - thanks!
Diffstat (limited to 'core/obex/obex.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/obex.cc187
1 files changed, 0 insertions, 187 deletions
diff --git a/core/obex/obex.cc b/core/obex/obex.cc
deleted file mode 100644
index 36634ec..0000000
--- a/core/obex/obex.cc
+++ b/dev/null
@@ -1,187 +0,0 @@
1
2#include "obex.h"
3
4/* OPIE */
5#include <opie2/oprocess.h>
6#include <opie2/odebug.h>
7
8/* QT */
9#include <qfileinfo.h>
10
11
12
13using namespace OpieObex;
14
15using namespace Opie::Core;
16/* TRANSLATOR OpieObex::Obex */
17
18Obex::Obex( QObject *parent, const char* name )
19 : QObject(parent, name )
20{
21 m_rec = 0;
22 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};
30Obex::~Obex() {
31 delete m_rec;
32 delete m_send;
33}
34void Obex::receive() {
35 m_receive = true;
36 m_outp = QString::null;
37 m_rec = new OProcess();
38 *m_rec << "irobex_palm3";
39 // connect to the necessary slots
40 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ),
41 this, SLOT(slotExited(Opie::Core::OProcess*) ) );
42
43 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
44 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) );
45
46 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
47 emit done( false );
48 delete m_rec;
49 m_rec = 0;
50 }
51}
52
53void Obex::send( const QString& fileName) { // if currently receiving stop it send receive
54 m_count = 0;
55 m_file = fileName;
56 if (m_rec != 0 ) {
57 if (m_rec->isRunning() ) {
58 emit error(-1 );
59 delete m_rec;
60 m_rec = 0;
61
62 }else{
63 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending
64 return;
65 }
66 }
67 sendNow();
68}
69void Obex::sendNow(){
70 if ( m_count >= 25 ) { // could not send
71 emit error(-1 );
72 emit sent(false);
73 return;
74 }
75 // OProcess inititialisation
76 m_send = new OProcess();
77 m_send->setWorkingDirectory( QFileInfo(m_file).dirPath(true) );
78
79 *m_send << "irobex_palm3";
80 *m_send << QFile::encodeName(QFileInfo(m_file).fileName());
81
82 // connect to slots Exited and and StdOut
83 connect(m_send, SIGNAL(processExited(Opie::Core::OProcess*) ),
84 this, SLOT(slotExited(Opie::Core::OProcess*)) );
85 connect(m_send, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int )),
86 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) );
87
88 // now start it
89 if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) {
90 m_count = 25;
91 emit error(-1 );
92 delete m_send;
93 m_send=0;
94 }
95 // end
96 m_count++;
97 emit currentTry( m_count );
98}
99
100void Obex::slotExited(OProcess* proc ){
101 if (proc == m_rec ) // receive process
102 received();
103 else if ( proc == m_send )
104 sendEnd();
105
106}
107void Obex::slotStdOut(OProcess* proc, char* buf, int len){
108 if ( proc == m_rec ) { // only receive
109 QByteArray ar( len );
110 memcpy( ar.data(), buf, len );
111 m_outp.append( ar );
112 }
113}
114
115void Obex::received() {
116 if (m_rec->normalExit() ) {
117 if ( m_rec->exitStatus() == 0 ) { // we got one
118 QString filename = parseOut();
119 emit receivedFile( filename );
120 }
121 }else{
122 emit done(false);
123 };
124 delete m_rec;
125 m_rec = 0;
126 receive();
127}
128
129void Obex::sendEnd() {
130 if (m_send->normalExit() ) {
131 if ( m_send->exitStatus() == 0 ) {
132 delete m_send;
133 m_send=0;
134 emit sent(true);
135 }else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready
136 // let's try it again
137 delete m_send;
138 m_send = 0;
139 sendNow();
140 }
141 }else {
142 emit error( -1 );
143 delete m_send;
144 m_send = 0;
145 }
146}
147QString Obex::parseOut( ){
148 QString path;
149 QStringList list = QStringList::split("\n", m_outp);
150 QStringList::Iterator it;
151 for (it = list.begin(); it != list.end(); ++it ) {
152 if ( (*it).startsWith("Wrote" ) ) {
153 int pos = (*it).findRev('(' );
154 if ( pos > 0 ) {
155
156 path = (*it).remove( pos, (*it).length() - pos );
157 path = path.mid(6 );
158 path = path.stripWhiteSpace();
159 }
160 }
161 }
162 return path;
163}
164/**
165 * when sent is done slotError is called we will start receive again
166 */
167void Obex::slotError() {
168 if ( m_receive )
169 receive();
170};
171void Obex::setReceiveEnabled( bool receive ) {
172 if ( !receive ) { //
173 m_receive = false;
174 shutDownReceive();
175 }
176}
177
178void Obex::shutDownReceive() {
179 if (m_rec != 0 ) {
180 if (m_rec->isRunning() ) {
181 emit error(-1 );
182 delete m_rec;
183 m_rec = 0;
184 }
185 }
186
187}