summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/obex/obex.cc15
1 files changed, 12 insertions, 3 deletions
diff --git a/core/applets/obex/obex.cc b/core/applets/obex/obex.cc
index 2218dbc..fc0be3b 100644
--- a/core/applets/obex/obex.cc
+++ b/core/applets/obex/obex.cc
@@ -1,75 +1,76 @@
1 1
2#include <qapplication.h> 2#include <qapplication.h>
3#include <qmessagebox.h> 3#include <qmessagebox.h>
4#include <qpe/qcopenvelope_qws.h> 4#include <qpe/qcopenvelope_qws.h>
5#include <opie/oprocess.h> 5#include <opie/oprocess.h>
6#include "obex.h" 6#include "obex.h"
7 7
8using namespace OpieObex; 8using namespace OpieObex;
9 9
10Obex::Obex( QObject *parent, const char* name ) 10Obex::Obex( QObject *parent, const char* name )
11 : QObject(parent, name ) 11 : QObject(parent, name )
12{ 12{
13 m_rec = 0; 13 m_rec = 0;
14 m_send=0; 14 m_send=0;
15 m_count = 0; 15 m_count = 0;
16 m_receive = false; 16 m_receive = false;
17 connect( this, SIGNAL(error(int) ), // for recovering to receive 17 connect( this, SIGNAL(error(int) ), // for recovering to receive
18 SLOT(slotError() ) ); 18 SLOT(slotError() ) );
19 connect( this, SIGNAL(sent() ), 19 connect( this, SIGNAL(sent() ),
20 SLOT(slotError() ) ); 20 SLOT(slotError() ) );
21}; 21};
22Obex::~Obex() { 22Obex::~Obex() {
23 delete m_rec; 23 delete m_rec;
24 delete m_send; 24 delete m_send;
25} 25}
26void Obex::receive() { 26void Obex::receive() {
27 m_receive = true; 27 m_receive = true;
28 m_outp = QString::null;
28 qWarning("Receive" ); 29 qWarning("Receive" );
29 m_rec = new OProcess(); 30 m_rec = new OProcess();
30 *m_rec << "irobex_palm3"; 31 *m_rec << "irobex_palm3";
31 // connect to the necessary slots 32 // connect to the necessary slots
32 connect(m_rec, SIGNAL(processExited(OProcess*) ), 33 connect(m_rec, SIGNAL(processExited(OProcess*) ),
33 this, SLOT(slotExited(OProcess*) ) ); 34 this, SLOT(slotExited(OProcess*) ) );
34 35
35 connect(m_rec, SIGNAL(receivedStdout(OProcess*, char*, int ) ), 36 connect(m_rec, SIGNAL(receivedStdout(OProcess*, char*, int ) ),
36 this, SLOT(slotStdOut(OProcess*, char*, int) ) ); 37 this, SLOT(slotStdOut(OProcess*, char*, int) ) );
37 38
38 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 39 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
39 qWarning("could not start :("); 40 qWarning("could not start :(");
40 emit done( false ); 41 emit done( false );
41 delete m_rec; 42 delete m_rec;
42 m_rec = 0; 43 m_rec = 0;
43 } 44 }
44// emit currentTry(m_count ); 45// emit currentTry(m_count );
45 46
46} 47}
47void Obex::send( const QString& fileName) { // if currently receiving stop it send receive 48void Obex::send( const QString& fileName) { // if currently receiving stop it send receive
48 m_count = 0; 49 m_count = 0;
49 m_file = fileName; 50 m_file = fileName;
50 qWarning("send"); 51 qWarning("send");
51 if (m_rec != 0 ) { 52 if (m_rec != 0 ) {
52 qWarning("running"); 53 qWarning("running");
53 if (m_rec->isRunning() ) { 54 if (m_rec->isRunning() ) {
54 emit error(-1 ); 55 emit error(-1 );
55 qWarning("is running"); 56 qWarning("is running");
56 delete m_rec; 57 delete m_rec;
57 m_rec = 0; 58 m_rec = 0;
58 59
59 }else{ 60 }else{
60 qWarning("is not running"); 61 qWarning("is not running");
61 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending 62 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending
62 return; 63 return;
63 } 64 }
64 } 65 }
65 sendNow(); 66 sendNow();
66} 67}
67void Obex::sendNow(){ 68void Obex::sendNow(){
68 qWarning("sendNow"); 69 qWarning("sendNow");
69 if ( m_count >= 25 ) { // could not send 70 if ( m_count >= 25 ) { // could not send
70 emit error(-1 ); 71 emit error(-1 );
71 return; 72 return;
72 } 73 }
73 // OProcess inititialisation 74 // OProcess inititialisation
74 m_send = new OProcess(); 75 m_send = new OProcess();
75 *m_send << "irobex_palm3"; 76 *m_send << "irobex_palm3";
@@ -103,82 +104,90 @@ void Obex::slotExited(OProcess* proc ){
103} 104}
104void Obex::slotStdOut(OProcess* proc, char* buf, int len){ 105void Obex::slotStdOut(OProcess* proc, char* buf, int len){
105 if ( proc == m_rec ) { // only recieve 106 if ( proc == m_rec ) { // only recieve
106 QCString cstring( buf, len ); 107 QCString cstring( buf, len );
107 m_outp.append( cstring.data() ); 108 m_outp.append( cstring.data() );
108 } 109 }
109} 110}
110 111
111void Obex::recieved() { 112void Obex::recieved() {
112 if (m_rec->normalExit() ) { 113 if (m_rec->normalExit() ) {
113 if ( m_rec->exitStatus() == 0 ) { // we got one 114 if ( m_rec->exitStatus() == 0 ) { // we got one
114 QString filename = parseOut(); 115 QString filename = parseOut();
115 emit receivedFile( filename ); 116 emit receivedFile( filename );
116 } 117 }
117 }else{ 118 }else{
118 emit done(false); 119 emit done(false);
119 }; 120 };
120 delete m_rec; 121 delete m_rec;
121 m_rec = 0; 122 m_rec = 0;
122 receive(); 123 receive();
123} 124}
124 125
125void Obex::sendEnd() { 126void Obex::sendEnd() {
126 if (m_send->normalExit() ) { 127 if (m_send->normalExit() ) {
127 if ( m_send->exitStatus() == 0 ) { 128 if ( m_send->exitStatus() == 0 ) {
128 delete m_send; 129 delete m_send;
129 m_send=0; 130 m_send=0;
130 qWarning("done" ); 131 qWarning("done" );
131 emit sent(); 132 emit sent();
132 }else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready 133 }else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready
133 // let's try it again 134 // let's try it again
134 delete m_send; 135 delete m_send;
135 m_send = 0; 136 m_send = 0;
136 qWarning("try sending again" ); 137 qWarning("try sending again" );
137 sendNow(); 138 sendNow();
138 } 139 }
139 }else { 140 }else {
140 emit error( -1 ); 141 emit error( -1 );
141 delete m_send; 142 delete m_send;
142 m_send = 0; 143 m_send = 0;
143 } 144 }
144} 145}
145QString Obex::parseOut( ){ 146QString Obex::parseOut( ){
146 QString path; 147 QString path;
147 QStringList list = QStringList::split("\n", m_outp); 148 QStringList list = QStringList::split("\n", m_outp);
148 QStringList::Iterator it; 149 QStringList::Iterator it;
149 for (it = list.begin(); it != list.end(); ++it ) { 150 for (it = list.begin(); it != list.end(); ++it ) {
150 if ( (*it).startsWith("Wrote" ) ) { 151 if ( (*it).startsWith("Wrote" ) ) {
151 QStringList pathes = QStringList::split(' ', (*it) ); 152 int pos = (*it).findRev('(' );
152 path = pathes[1]; 153 if ( pos > 0 ) {
153 qWarning("path %s", path.latin1() ); 154 qWarning( "%d %s", pos, (*it).mid(6 ).latin1() ) ;
155 qWarning("%d %d", (*it).length(), (*it).length()-pos );
156
157 path = (*it).remove( pos, (*it).length() - pos );
158 qWarning("%s", path.latin1() );
159 path = path.mid(6 );
160 path = path.stripWhiteSpace();
161 qWarning("path %s", path.latin1() );
162 }
154 } 163 }
155 } 164 }
156 return path; 165 return path;
157} 166}
158/** 167/**
159 * when sent is done slotError is called we will start receive again 168 * when sent is done slotError is called we will start receive again
160 */ 169 */
161void Obex::slotError() { 170void Obex::slotError() {
162 qWarning("slotError"); 171 qWarning("slotError");
163 if ( m_receive ) 172 if ( m_receive )
164 receive(); 173 receive();
165}; 174};
166void Obex::setReceiveEnabled( bool receive ) { 175void Obex::setReceiveEnabled( bool receive ) {
167 if ( !receive ) { // 176 if ( !receive ) { //
168 m_receive = false; 177 m_receive = false;
169 shutDownReceive(); 178 shutDownReceive();
170 } 179 }
171} 180}
172 181
173void Obex::shutDownReceive() { 182void Obex::shutDownReceive() {
174 if (m_rec != 0 ) { 183 if (m_rec != 0 ) {
175 qWarning("running"); 184 qWarning("running");
176 if (m_rec->isRunning() ) { 185 if (m_rec->isRunning() ) {
177 emit error(-1 ); 186 emit error(-1 );
178 qWarning("is running"); 187 qWarning("is running");
179 delete m_rec; 188 delete m_rec;
180 m_rec = 0; 189 m_rec = 0;
181 } 190 }
182 } 191 }
183 192
184} 193}