summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/obex.cc4
1 files changed, 3 insertions, 1 deletions
diff --git a/core/obex/obex.cc b/core/obex/obex.cc
index 5dfcfb5..36634ec 100644
--- a/core/obex/obex.cc
+++ b/core/obex/obex.cc
@@ -1,174 +1,176 @@
1 1
2#include "obex.h" 2#include "obex.h"
3 3
4/* OPIE */ 4/* OPIE */
5#include <opie2/oprocess.h> 5#include <opie2/oprocess.h>
6#include <opie2/odebug.h> 6#include <opie2/odebug.h>
7 7
8/* QT */ 8/* QT */
9#include <qfileinfo.h> 9#include <qfileinfo.h>
10 10
11 11
12 12
13using namespace OpieObex; 13using namespace OpieObex;
14 14
15using namespace Opie::Core; 15using namespace Opie::Core;
16/* TRANSLATOR OpieObex::Obex */ 16/* TRANSLATOR OpieObex::Obex */
17 17
18Obex::Obex( QObject *parent, const char* name ) 18Obex::Obex( QObject *parent, const char* name )
19 : QObject(parent, name ) 19 : QObject(parent, name )
20{ 20{
21 m_rec = 0; 21 m_rec = 0;
22 m_send=0; 22 m_send=0;
23 m_count = 0; 23 m_count = 0;
24 m_receive = false; 24 m_receive = false;
25 connect( this, SIGNAL(error(int) ), // for recovering to receive 25 connect( this, SIGNAL(error(int) ), // for recovering to receive
26 SLOT(slotError() ) ); 26 SLOT(slotError() ) );
27 connect( this, SIGNAL(sent(bool) ), 27 connect( this, SIGNAL(sent(bool) ),
28 SLOT(slotError() ) ); 28 SLOT(slotError() ) );
29}; 29};
30Obex::~Obex() { 30Obex::~Obex() {
31 delete m_rec; 31 delete m_rec;
32 delete m_send; 32 delete m_send;
33} 33}
34void Obex::receive() { 34void Obex::receive() {
35 m_receive = true; 35 m_receive = true;
36 m_outp = QString::null; 36 m_outp = QString::null;
37 m_rec = new OProcess(); 37 m_rec = new OProcess();
38 *m_rec << "irobex_palm3"; 38 *m_rec << "irobex_palm3";
39 // connect to the necessary slots 39 // connect to the necessary slots
40 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), 40 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ),
41 this, SLOT(slotExited(Opie::Core::OProcess*) ) ); 41 this, SLOT(slotExited(Opie::Core::OProcess*) ) );
42 42
43 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), 43 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
44 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); 44 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) );
45 45
46 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 46 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
47 emit done( false ); 47 emit done( false );
48 delete m_rec; 48 delete m_rec;
49 m_rec = 0; 49 m_rec = 0;
50 } 50 }
51} 51}
52 52
53void Obex::send( const QString& fileName) { // if currently receiving stop it send receive 53void Obex::send( const QString& fileName) { // if currently receiving stop it send receive
54 m_count = 0; 54 m_count = 0;
55 m_file = fileName; 55 m_file = fileName;
56 if (m_rec != 0 ) { 56 if (m_rec != 0 ) {
57 if (m_rec->isRunning() ) { 57 if (m_rec->isRunning() ) {
58 emit error(-1 ); 58 emit error(-1 );
59 delete m_rec; 59 delete m_rec;
60 m_rec = 0; 60 m_rec = 0;
61 61
62 }else{ 62 }else{
63 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending 63 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending
64 return; 64 return;
65 } 65 }
66 } 66 }
67 sendNow(); 67 sendNow();
68} 68}
69void Obex::sendNow(){ 69void Obex::sendNow(){
70 if ( m_count >= 25 ) { // could not send 70 if ( m_count >= 25 ) { // could not send
71 emit error(-1 ); 71 emit error(-1 );
72 emit sent(false); 72 emit sent(false);
73 return; 73 return;
74 } 74 }
75 // OProcess inititialisation 75 // OProcess inititialisation
76 m_send = new OProcess(); 76 m_send = new OProcess();
77 m_send->setWorkingDirectory( QFileInfo(m_file).dirPath(true) );
78
77 *m_send << "irobex_palm3"; 79 *m_send << "irobex_palm3";
78 *m_send << QFile::encodeName(m_file); 80 *m_send << QFile::encodeName(QFileInfo(m_file).fileName());
79 81
80 // connect to slots Exited and and StdOut 82 // connect to slots Exited and and StdOut
81 connect(m_send, SIGNAL(processExited(Opie::Core::OProcess*) ), 83 connect(m_send, SIGNAL(processExited(Opie::Core::OProcess*) ),
82 this, SLOT(slotExited(Opie::Core::OProcess*)) ); 84 this, SLOT(slotExited(Opie::Core::OProcess*)) );
83 connect(m_send, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int )), 85 connect(m_send, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int )),
84 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); 86 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) );
85 87
86 // now start it 88 // now start it
87 if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) { 89 if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) {
88 m_count = 25; 90 m_count = 25;
89 emit error(-1 ); 91 emit error(-1 );
90 delete m_send; 92 delete m_send;
91 m_send=0; 93 m_send=0;
92 } 94 }
93 // end 95 // end
94 m_count++; 96 m_count++;
95 emit currentTry( m_count ); 97 emit currentTry( m_count );
96} 98}
97 99
98void Obex::slotExited(OProcess* proc ){ 100void Obex::slotExited(OProcess* proc ){
99 if (proc == m_rec ) // receive process 101 if (proc == m_rec ) // receive process
100 received(); 102 received();
101 else if ( proc == m_send ) 103 else if ( proc == m_send )
102 sendEnd(); 104 sendEnd();
103 105
104} 106}
105void Obex::slotStdOut(OProcess* proc, char* buf, int len){ 107void Obex::slotStdOut(OProcess* proc, char* buf, int len){
106 if ( proc == m_rec ) { // only receive 108 if ( proc == m_rec ) { // only receive
107 QByteArray ar( len ); 109 QByteArray ar( len );
108 memcpy( ar.data(), buf, len ); 110 memcpy( ar.data(), buf, len );
109 m_outp.append( ar ); 111 m_outp.append( ar );
110 } 112 }
111} 113}
112 114
113void Obex::received() { 115void Obex::received() {
114 if (m_rec->normalExit() ) { 116 if (m_rec->normalExit() ) {
115 if ( m_rec->exitStatus() == 0 ) { // we got one 117 if ( m_rec->exitStatus() == 0 ) { // we got one
116 QString filename = parseOut(); 118 QString filename = parseOut();
117 emit receivedFile( filename ); 119 emit receivedFile( filename );
118 } 120 }
119 }else{ 121 }else{
120 emit done(false); 122 emit done(false);
121 }; 123 };
122 delete m_rec; 124 delete m_rec;
123 m_rec = 0; 125 m_rec = 0;
124 receive(); 126 receive();
125} 127}
126 128
127void Obex::sendEnd() { 129void Obex::sendEnd() {
128 if (m_send->normalExit() ) { 130 if (m_send->normalExit() ) {
129 if ( m_send->exitStatus() == 0 ) { 131 if ( m_send->exitStatus() == 0 ) {
130 delete m_send; 132 delete m_send;
131 m_send=0; 133 m_send=0;
132 emit sent(true); 134 emit sent(true);
133 }else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready 135 }else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready
134 // let's try it again 136 // let's try it again
135 delete m_send; 137 delete m_send;
136 m_send = 0; 138 m_send = 0;
137 sendNow(); 139 sendNow();
138 } 140 }
139 }else { 141 }else {
140 emit error( -1 ); 142 emit error( -1 );
141 delete m_send; 143 delete m_send;
142 m_send = 0; 144 m_send = 0;
143 } 145 }
144} 146}
145QString Obex::parseOut( ){ 147QString Obex::parseOut( ){
146 QString path; 148 QString path;
147 QStringList list = QStringList::split("\n", m_outp); 149 QStringList list = QStringList::split("\n", m_outp);
148 QStringList::Iterator it; 150 QStringList::Iterator it;
149 for (it = list.begin(); it != list.end(); ++it ) { 151 for (it = list.begin(); it != list.end(); ++it ) {
150 if ( (*it).startsWith("Wrote" ) ) { 152 if ( (*it).startsWith("Wrote" ) ) {
151 int pos = (*it).findRev('(' ); 153 int pos = (*it).findRev('(' );
152 if ( pos > 0 ) { 154 if ( pos > 0 ) {
153 155
154 path = (*it).remove( pos, (*it).length() - pos ); 156 path = (*it).remove( pos, (*it).length() - pos );
155 path = path.mid(6 ); 157 path = path.mid(6 );
156 path = path.stripWhiteSpace(); 158 path = path.stripWhiteSpace();
157 } 159 }
158 } 160 }
159 } 161 }
160 return path; 162 return path;
161} 163}
162/** 164/**
163 * when sent is done slotError is called we will start receive again 165 * when sent is done slotError is called we will start receive again
164 */ 166 */
165void Obex::slotError() { 167void Obex::slotError() {
166 if ( m_receive ) 168 if ( m_receive )
167 receive(); 169 receive();
168}; 170};
169void Obex::setReceiveEnabled( bool receive ) { 171void Obex::setReceiveEnabled( bool receive ) {
170 if ( !receive ) { // 172 if ( !receive ) { //
171 m_receive = false; 173 m_receive = false;
172 shutDownReceive(); 174 shutDownReceive();
173 } 175 }
174} 176}