summaryrefslogtreecommitdiff
path: root/core/applets/obex/obex.cc
Unidiff
Diffstat (limited to 'core/applets/obex/obex.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/obex/obex.cc194
1 files changed, 0 insertions, 194 deletions
diff --git a/core/applets/obex/obex.cc b/core/applets/obex/obex.cc
deleted file mode 100644
index 43041f5..0000000
--- a/core/applets/obex/obex.cc
+++ b/dev/null
@@ -1,194 +0,0 @@
1
2#include <qapplication.h>
3#include <qmessagebox.h>
4#include <qpe/qcopenvelope_qws.h>
5#include <opie/oprocess.h>
6#include "obex.h"
7
8using namespace OpieObex;
9
10Obex::Obex( QObject *parent, const char* name )
11 : QObject(parent, name )
12{
13 m_rec = 0;
14 m_send=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() ) );
21};
22Obex::~Obex() {
23 delete m_rec;
24 delete m_send;
25}
26void Obex::receive() {
27 m_receive = true;
28 m_outp = QString::null;
29 qWarning("Receive" );
30 m_rec = new OProcess();
31 *m_rec << "irobex_palm3";
32 // connect to the necessary slots
33 connect(m_rec, SIGNAL(processExited(OProcess*) ),
34 this, SLOT(slotExited(OProcess*) ) );
35
36 connect(m_rec, SIGNAL(receivedStdout(OProcess*, char*, int ) ),
37 this, SLOT(slotStdOut(OProcess*, char*, int) ) );
38
39 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
40 qWarning("could not start :(");
41 emit done( false );
42 delete m_rec;
43 m_rec = 0;
44 }
45// emit currentTry(m_count );
46
47}
48void Obex::send( const QString& fileName) { // if currently receiving stop it send receive
49 m_count = 0;
50 m_file = fileName;
51 qWarning("send");
52 if (m_rec != 0 ) {
53 qWarning("running");
54 if (m_rec->isRunning() ) {
55 emit error(-1 );
56 qWarning("is running");
57 delete m_rec;
58 m_rec = 0;
59
60 }else{
61 qWarning("is not running");
62 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending
63 return;
64 }
65 }
66 sendNow();
67}
68void Obex::sendNow(){
69 qWarning("sendNow");
70 if ( m_count >= 25 ) { // could not send
71 emit error(-1 );
72 return;
73 }
74 // OProcess inititialisation
75 m_send = new OProcess();
76 *m_send << "irobex_palm3";
77 *m_send << m_file;
78
79 // connect to slots Exited and and StdOut
80 connect(m_send, SIGNAL(processExited(OProcess*) ),
81 this, SLOT(slotExited(OProcess*)) );
82 connect(m_send, SIGNAL(receivedStdout(OProcess*, char*, int )),
83 this, SLOT(slotStdOut(OProcess*, char*, int) ) );
84
85 // now start it
86 if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) {
87 qWarning("could not send" );
88 m_count = 25;
89 emit error(-1 );
90 delete m_send;
91 m_send=0;
92 }
93 // end
94 m_count++;
95 emit currentTry( m_count );
96}
97
98void Obex::slotExited(OProcess* proc ){
99 if (proc == m_rec ) { // receive process
100 received();
101 }else if ( proc == m_send ) {
102 sendEnd();
103 }
104}
105void Obex::slotStdOut(OProcess* proc, char* buf, int len){
106 if ( proc == m_rec ) { // only receive
107 QCString cstring( buf, len );
108 m_outp.append( cstring.data() );
109 }
110}
111
112void Obex::received() {
113 if (m_rec->normalExit() ) {
114 if ( m_rec->exitStatus() == 0 ) { // we got one
115 QString filename = parseOut();
116 qWarning("ACHTUNG");
117 emit receivedFile( filename );
118 }
119 }else{
120 emit done(false);
121 };
122 delete m_rec;
123 m_rec = 0;
124 receive();
125}
126
127void Obex::sendEnd() {
128 if (m_send->normalExit() ) {
129 if ( m_send->exitStatus() == 0 ) {
130 delete m_send;
131 m_send=0;
132 qWarning("done" );
133 emit sent();
134 }else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready
135 // let's try it again
136 delete m_send;
137 m_send = 0;
138 qWarning("try sending again" );
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 qWarning( "%d %s", pos, (*it).mid(6 ).latin1() ) ;
156 qWarning("%d %d", (*it).length(), (*it).length()-pos );
157
158 path = (*it).remove( pos, (*it).length() - pos );
159 qWarning("%s", path.latin1() );
160 path = path.mid(6 );
161 path = path.stripWhiteSpace();
162 qWarning("path %s", path.latin1() );
163 }
164 }
165 }
166 return path;
167}
168/**
169 * when sent is done slotError is called we will start receive again
170 */
171void Obex::slotError() {
172 qWarning("slotError");
173 if ( m_receive )
174 receive();
175};
176void Obex::setReceiveEnabled( bool receive ) {
177 if ( !receive ) { //
178 m_receive = false;
179 shutDownReceive();
180 }
181}
182
183void Obex::shutDownReceive() {
184 if (m_rec != 0 ) {
185 qWarning("running");
186 if (m_rec->isRunning() ) {
187 emit error(-1 );
188 qWarning("is running");
189 delete m_rec;
190 m_rec = 0;
191 }
192 }
193
194}