summaryrefslogtreecommitdiff
authorzecke <zecke>2002-06-13 19:04:05 (UTC)
committer zecke <zecke>2002-06-13 19:04:05 (UTC)
commited10b73df98c1b4c41a0b940e4f8729fe28c2b8a (patch) (unidiff)
tree9fe7679c82a41b21de3378090ce211c00a8bc178
parent9939c618389465ef5837bf510186d583891e65e3 (diff)
downloadopie-ed10b73df98c1b4c41a0b940e4f8729fe28c2b8a.zip
opie-ed10b73df98c1b4c41a0b940e4f8729fe28c2b8a.tar.gz
opie-ed10b73df98c1b4c41a0b940e4f8729fe28c2b8a.tar.bz2
Stop receiving when wanting to send
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/obex/obex.cc164
-rw-r--r--core/applets/obex/obex.h116
-rw-r--r--core/applets/obex/obeximpl.cc12
3 files changed, 179 insertions, 113 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
@@ -10,87 +10,116 @@ using namespace OpieObex;
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;
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() {
22 qWarning("Receive" ); 27 m_receive = true;
23 m_rec = new OProcess(); 28 qWarning("Receive" );
24 *m_rec << "irobex_palm3"; 29 m_rec = new OProcess();
25 // connect to the necessary slots 30 *m_rec << "irobex_palm3";
26 connect(m_rec, SIGNAL(processExited(OProcess*) ), 31 // connect to the necessary slots
27 this, SLOT(slotExited(OProcess*) ) ); 32 connect(m_rec, SIGNAL(processExited(OProcess*) ),
33 this, SLOT(slotExited(OProcess*) ) );
28 34
29 connect(m_rec, SIGNAL(receivedStdout(OProcess*, char*, int ) ), 35 connect(m_rec, SIGNAL(receivedStdout(OProcess*, char*, int ) ),
30 this, SLOT(slotStdOut(OProcess*, char*, int) ) ); 36 this, SLOT(slotStdOut(OProcess*, char*, int) ) );
31 37
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 );
35 } 41 delete m_rec;
36 emit currentTry(m_count ); 42 m_rec = 0;
43 }
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;
42 sendNow(); 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 }
65 sendNow();
43} 66}
44void Obex::sendNow(){ 67void Obex::sendNow(){
45 if ( m_count >= 25 ) { // could not send 68 qWarning("sendNow");
46 emit error(-1 ); 69 if ( m_count >= 25 ) { // could not send
47 return; 70 emit error(-1 );
48 } 71 return;
49 // OProcess inititialisation 72 }
50 m_send = new OProcess(); 73 // OProcess inititialisation
51 *m_send << "irobex_palm3"; 74 m_send = new OProcess();
52 *m_send << m_file; 75 *m_send << "irobex_palm3";
76 *m_send << m_file;
53 77
54 // connect to slots Exited and and StdOut 78 // connect to slots Exited and and StdOut
55 connect(m_send, SIGNAL(processExited(OProcess*) ), 79 connect(m_send, SIGNAL(processExited(OProcess*) ),
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) ) );
59 // now start it 83
60 if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) { 84 // now start it
61 qWarning("could not send" ); 85 if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) {
62 m_count = 25; 86 qWarning("could not send" );
63 emit error(-1 ); 87 m_count = 25;
64 } 88 emit error(-1 );
65 // end 89 delete m_send;
66 m_count++; 90 m_send=0;
67 emit currentTry( m_count ); 91 }
92 // end
93 m_count++;
94 emit currentTry( m_count );
68} 95}
69 96
70void Obex::slotExited(OProcess* proc ){ 97void Obex::slotExited(OProcess* proc ){
71 if (proc == m_rec ) { // recieve process 98 if (proc == m_rec ) { // recieve process
72 recieved(); 99 recieved();
73 }else if ( proc == m_send ) { 100 }else if ( proc == m_send ) {
74 sendEnd(); 101 sendEnd();
75 } 102 }
76} 103}
77void Obex::slotStdOut(OProcess* proc, char* buf, int len){ 104void Obex::slotStdOut(OProcess* proc, char* buf, int len){
78 if ( proc == m_rec ) { // only recieve 105 if ( proc == m_rec ) { // only recieve
79 QCString cstring( buf, len ); 106 QCString cstring( buf, len );
80 m_outp.append( cstring.data() ); 107 m_outp.append( cstring.data() );
81 } 108 }
82} 109}
83 110
84void Obex::recieved() { 111void Obex::recieved() {
85 if (m_rec->normalExit() ) { 112 if (m_rec->normalExit() ) {
86 if ( m_rec->exitStatus() == 0 ) { // we got one 113 if ( m_rec->exitStatus() == 0 ) { // we got one
87 QString filename = parseOut(); 114 QString filename = parseOut();
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
@@ -1,6 +1,6 @@
1 1
2 2
3#ifndef OpieObex_H 3#ifndef OpieObex_H
4#define OpieObex_H 4#define OpieObex_H
5 5
6#include <qobject.h> 6#include <qobject.h>
@@ -9,71 +9,75 @@ class OProcess;
9class QCopChannel; 9class QCopChannel;
10namespace OpieObex { 10namespace OpieObex {
11 class Obex : public QObject { 11 class Obex : public QObject {
12 Q_OBJECT 12 Q_OBJECT
13 public: 13 public:
14 /** 14 /**
15 * Obex c'tor look 15 * Obex c'tor look
16 */ 16 */
17 Obex( QObject *parent, const char* name); 17 Obex( QObject *parent, const char* name);
18 /** 18 /**
19 * d'tor 19 * d'tor
20 */ 20 */
21 ~Obex(); 21 ~Obex();
22 22
23 /** 23 /**
24 * Starting listening to irda after enabled by the applet 24 * Starting listening to irda after enabled by the applet
25 * a signal gets emitted when recieved a file 25 * a signal gets emitted when recieved a file
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 /**
32 * a signal 33 * a signal
33 * @param path The path to the recieved file 34 * @param path The path to the recieved file
34 */ 35 */
35 void receivedFile( const QString& path); 36 void receivedFile( const QString& path);
36 /** 37 /**
37 * error signal if the program couldn't be started or the 38 * error signal if the program couldn't be started or the
38 * the connection timed out 39 * the connection timed out
39 */ 40 */
40 void error( int ); 41 void error( int );
41 /** 42 /**
42 * The current try to receive data 43 * The current try to receive data
43 */ 44 */
44 void currentTry(unsigned int); 45 void currentTry(unsigned int);
45 /** 46 /**
46 * signal sent The file got beamed to the remote location 47 * signal sent The file got beamed to the remote location
47 */ 48 */
48 void sent(); 49 void sent();
49 // private slots 50 // private slots
50 void done(bool); 51 void done(bool);
51 52
52 private: 53 private:
53 uint m_count; 54 uint m_count;
54 QString m_file; 55 QString m_file;
55 QString m_outp; 56 QString m_outp;
56 OProcess *m_send; 57 OProcess *m_send;
57 OProcess *m_rec; 58 OProcess *m_rec;
58 59 bool m_receive : 1;
59 private slots: 60 void shutDownReceive();
60 61
61 /** 62private slots:
62 * send over palm obex 63
63 */ 64 /**
65 * send over palm obex
66 */
67
68 //void send(const QString&);
69
70 // the process exited
71 void slotExited(OProcess* proc) ;
72 void slotStdOut(OProcess*, char*, int);
73 void slotError();
64 74
65 //void send(const QString&);
66
67 // the process exited
68 void slotExited(OProcess* proc) ;
69 void slotStdOut(OProcess*, char*, int);
70
71 private: 75 private:
72 void sendNow(); 76 void sendNow();
73 QString parseOut(); 77 QString parseOut();
74 void recieved(); 78 void recieved();
75 void sendEnd(); 79 void sendEnd();
76 80
77 }; 81 };
78}; 82};
79 83
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();
61 m_obex->receive(); 62 int receiveD = 0;
63 stream >> receiveD;
64 if ( receiveD == 1)
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);