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