summaryrefslogtreecommitdiff
path: root/core/applets/obex
authorzecke <zecke>2002-06-13 19:04:05 (UTC)
committer zecke <zecke>2002-06-13 19:04:05 (UTC)
commited10b73df98c1b4c41a0b940e4f8729fe28c2b8a (patch) (unidiff)
tree9fe7679c82a41b21de3378090ce211c00a8bc178 /core/applets/obex
parent9939c618389465ef5837bf510186d583891e65e3 (diff)
downloadopie-ed10b73df98c1b4c41a0b940e4f8729fe28c2b8a.zip
opie-ed10b73df98c1b4c41a0b940e4f8729fe28c2b8a.tar.gz
opie-ed10b73df98c1b4c41a0b940e4f8729fe28c2b8a.tar.bz2
Stop receiving when wanting to send
Diffstat (limited to 'core/applets/obex') (more/less context) (show whitespace changes)
-rw-r--r--core/applets/obex/obex.cc62
-rw-r--r--core/applets/obex/obex.h4
-rw-r--r--core/applets/obex/obeximpl.cc10
3 files changed, 71 insertions, 5 deletions
diff --git a/core/applets/obex/obex.cc b/core/applets/obex/obex.cc
index 683964b..2218dbc 100644
--- a/core/applets/obex/obex.cc
+++ b/core/applets/obex/obex.cc
@@ -13,12 +13,18 @@ Obex::Obex( QObject *parent, const char* name )
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;
17 connect( this, SIGNAL(error(int) ), // for recovering to receive
18 SLOT(slotError() ) );
19 connect( this, SIGNAL(sent() ),
20 SLOT(slotError() ) );
16}; 21};
17Obex::~Obex() { 22Obex::~Obex() {
18 delete m_rec; 23 delete m_rec;
19 delete m_send; 24 delete m_send;
20} 25}
21void Obex::receive() { 26void Obex::receive() {
27 m_receive = true;
22 qWarning("Receive" ); 28 qWarning("Receive" );
23 m_rec = new OProcess(); 29 m_rec = new OProcess();
24 *m_rec << "irobex_palm3"; 30 *m_rec << "irobex_palm3";
@@ -32,16 +38,34 @@ void Obex::receive() {
32 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 38 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
33 qWarning("could not start :("); 39 qWarning("could not start :(");
34 emit done( false ); 40 emit done( false );
41 delete m_rec;
42 m_rec = 0;
35 } 43 }
36 emit currentTry(m_count ); 44// emit currentTry(m_count );
37 45
38} 46}
39void Obex::send( const QString& fileName) { 47void Obex::send( const QString& fileName) { // if currently receiving stop it send receive
40 m_count = 0; 48 m_count = 0;
41 m_file = fileName; 49 m_file = fileName;
50 qWarning("send");
51 if (m_rec != 0 ) {
52 qWarning("running");
53 if (m_rec->isRunning() ) {
54 emit error(-1 );
55 qWarning("is running");
56 delete m_rec;
57 m_rec = 0;
58
59 }else{
60 qWarning("is not running");
61 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending
62 return;
63 }
64 }
42 sendNow(); 65 sendNow();
43} 66}
44void Obex::sendNow(){ 67void Obex::sendNow(){
68 qWarning("sendNow");
45 if ( m_count >= 25 ) { // could not send 69 if ( m_count >= 25 ) { // could not send
46 emit error(-1 ); 70 emit error(-1 );
47 return; 71 return;
@@ -56,11 +80,14 @@ void Obex::sendNow(){
56 this, SLOT(slotExited(OProcess*)) ); 80 this, SLOT(slotExited(OProcess*)) );
57 connect(m_send, SIGNAL(receivedStdout(OProcess*, char*, int )), 81 connect(m_send, SIGNAL(receivedStdout(OProcess*, char*, int )),
58 this, SLOT(slotStdOut(OProcess*, char*, int) ) ); 82 this, SLOT(slotStdOut(OProcess*, char*, int) ) );
83
59 // now start it 84 // now start it
60 if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) { 85 if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) {
61 qWarning("could not send" ); 86 qWarning("could not send" );
62 m_count = 25; 87 m_count = 25;
63 emit error(-1 ); 88 emit error(-1 );
89 delete m_send;
90 m_send=0;
64 } 91 }
65 // end 92 // end
66 m_count++; 93 m_count++;
@@ -88,9 +115,11 @@ void Obex::recieved() {
88 emit receivedFile( filename ); 115 emit receivedFile( filename );
89 } 116 }
90 }else{ 117 }else{
91 emit error(-1); 118 emit done(false);
92 }; 119 };
93 delete m_rec; 120 delete m_rec;
121 m_rec = 0;
122 receive();
94} 123}
95 124
96void Obex::sendEnd() { 125void Obex::sendEnd() {
@@ -126,3 +155,30 @@ QString Obex::parseOut( ){
126 } 155 }
127 return path; 156 return path;
128} 157}
158/**
159 * when sent is done slotError is called we will start receive again
160 */
161void Obex::slotError() {
162 qWarning("slotError");
163 if ( m_receive )
164 receive();
165};
166void Obex::setReceiveEnabled( bool receive ) {
167 if ( !receive ) { //
168 m_receive = false;
169 shutDownReceive();
170 }
171}
172
173void Obex::shutDownReceive() {
174 if (m_rec != 0 ) {
175 qWarning("running");
176 if (m_rec->isRunning() ) {
177 emit error(-1 );
178 qWarning("is running");
179 delete m_rec;
180 m_rec = 0;
181 }
182 }
183
184}
diff --git a/core/applets/obex/obex.h b/core/applets/obex/obex.h
index 4e78015..2ce44f2 100644
--- a/core/applets/obex/obex.h
+++ b/core/applets/obex/obex.h
@@ -26,6 +26,7 @@ namespace OpieObex {
26 */ 26 */
27 void receive(); 27 void receive();
28 void send( const QString& ); 28 void send( const QString& );
29 void setReceiveEnabled( bool = false );
29 signals: 30 signals:
30 31
31 /** 32 /**
@@ -55,6 +56,8 @@ namespace OpieObex {
55 QString m_outp; 56 QString m_outp;
56 OProcess *m_send; 57 OProcess *m_send;
57 OProcess *m_rec; 58 OProcess *m_rec;
59 bool m_receive : 1;
60 void shutDownReceive();
58 61
59 private slots: 62 private slots:
60 63
@@ -67,6 +70,7 @@ namespace OpieObex {
67 // the process exited 70 // the process exited
68 void slotExited(OProcess* proc) ; 71 void slotExited(OProcess* proc) ;
69 void slotStdOut(OProcess*, char*, int); 72 void slotStdOut(OProcess*, char*, int);
73 void slotError();
70 74
71 private: 75 private:
72 void sendNow(); 76 void sendNow();
diff --git a/core/applets/obex/obeximpl.cc b/core/applets/obex/obeximpl.cc
index 856f100..0c137af 100644
--- a/core/applets/obex/obeximpl.cc
+++ b/core/applets/obex/obeximpl.cc
@@ -49,6 +49,7 @@ void ObexImpl::slotMessage( const QCString& msg, const QByteArray&data ) {
49 stream >> desc; 49 stream >> desc;
50 QString filename; 50 QString filename;
51 stream >> filename; 51 stream >> filename;
52 m_sendgui->raise(); // should be on top
52 m_sendgui->showMaximized(); 53 m_sendgui->showMaximized();
53 m_sendgui->lblPath->setText(filename); 54 m_sendgui->lblPath->setText(filename);
54 connect( (QObject*)m_sendgui->PushButton2, SIGNAL(clicked()), 55 connect( (QObject*)m_sendgui->PushButton2, SIGNAL(clicked()),
@@ -56,9 +57,14 @@ void ObexImpl::slotMessage( const QCString& msg, const QByteArray&data ) {
56 m_obex->send(filename ); 57 m_obex->send(filename );
57 connect( (QObject*)m_obex, SIGNAL( sent() ), this, 58 connect( (QObject*)m_obex, SIGNAL( sent() ), this,
58 SLOT( slotSent() ) ); 59 SLOT( slotSent() ) );
59 }else if(msg == "receive(bool)" ) { // open a GUI 60 }else if(msg == "receive(int)" ) { // open a GUI
60 m_recvgui->showMaximized(); 61 m_recvgui->showMaximized();
62 int receiveD = 0;
63 stream >> receiveD;
64 if ( receiveD == 1)
61 m_obex->receive(); 65 m_obex->receive();
66 else
67 m_obex->setReceiveEnabled( false );
62 68
63 } else if (msg =="done(QString)") { 69 } else if (msg =="done(QString)") {
64 QString text; 70 QString text;
@@ -87,7 +93,7 @@ void ObexImpl::slotSent() {
87void ObexImpl::slotError( int errorCode) { 93void ObexImpl::slotError( int errorCode) {
88 94
89 QString errorString = ""; 95 QString errorString = "";
90 if (errorCode = -1) { 96 if (errorCode == -1) {
91 errorString = "test"; 97 errorString = "test";
92 } 98 }
93 qDebug("Error: " + errorString); 99 qDebug("Error: " + errorString);