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.cc119
1 files changed, 119 insertions, 0 deletions
diff --git a/core/applets/obex/obex.cc b/core/applets/obex/obex.cc
new file mode 100644
index 0000000..f2ceff8
--- a/dev/null
+++ b/core/applets/obex/obex.cc
@@ -0,0 +1,119 @@
1
2
3#include "kprocess.h"
4#include "obex.h"
5
6using namespace OpieObex;
7
8Obex::Obex( QObject *parent, const char* name )
9 : QObject(parent, name )
10{
11 m_rec = 0;
12 m_send=0;
13 m_count = 0;
14};
15Obex::~Obex() {
16 delete m_rec;
17 delete m_send;
18}
19void Obex::receive() {
20 m_rec = new KProcess();
21 *m_rec << "irobex_palm3";
22 // connect to the necessary slots
23 connect(m_rec, SIGNAL(processExited(KProcess*) ),
24 this, SLOT(slotExited(KProcess*) ) );
25
26 connect(m_rec, SIGNAL(receivedStdout(KProcess*, char*, int ) ),
27 this, SLOT(slotStdOut(KProcess*, char*, int) ) );
28
29 if(!m_rec->start(KProcess::NotifyOnExit, KProcess::AllOutput) ) {
30 qWarning("could not start :(");
31 emit done( false );
32 }
33 emit currentTry(m_count );
34
35}
36void Obex::send( const QString& fileName) {
37 m_count = 0;
38 m_file = fileName;
39 sendNow();
40}
41void Obex::sendNow(){
42 if ( m_count >= 15 ) { // could not send
43 emit error(-1 );
44 }
45 // KProcess inititialisation
46 m_send = new KProcess();
47 *m_send << "irobex_palm3";
48 *m_send << m_file;
49
50 // connect to slots Exited and and StdOut
51 connect(m_send, SIGNAL(processExited(KProcess*) ),
52 this, SLOT(slotExited(KProcess*)) );
53 connect(m_send, SIGNAL(receivedStdout(KProcess*, char*, int )),
54 this, SLOT(slotStdOut(KProcess*, char*, int) ) );
55 // now start it
56 if (!m_send->start(/*KProcess::NotifyOnExit, KProcess::AllOutput*/ ) ) {
57 m_count = 15;
58 emit error(-1 );
59 }
60 // end
61 m_count++;
62 emit currentTry( m_count );
63}
64
65void Obex::slotExited(KProcess* proc ){
66 if (proc == m_rec ) { // recieve process
67 recieved();
68 }else if ( proc == m_send ) {
69 sendEnd();
70 }
71}
72void Obex::slotStdOut(KProcess* proc, char* buf, int len){
73 if ( proc == m_rec ) { // only recieve
74 QCString cstring( buf, len );
75 m_outp.append( cstring.data() );
76 }
77}
78
79void Obex::recieved() {
80 if (m_rec->normalExit() ) {
81 if ( m_rec->exitStatus() == 0 ) { // we got one
82 QString filename = parseOut();
83 emit receivedFile( filename );
84 }
85 }else{
86 emit error(-1);
87 };
88 delete m_rec;
89}
90void Obex::sendEnd() {
91 if (m_send->normalExit() ) {
92 if ( m_send->exitStatus() == 0 ) {
93 delete m_send;
94 m_send=0;
95 emit sent();
96 }else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready
97 // let's try it again
98 delete m_send;
99 m_send = 0;
100 sendNow();
101 }
102 }else {
103 emit error( -1 );
104 delete m_send;
105 m_send = 0;
106 }
107}
108QString Obex::parseOut( ){
109 QString path;
110 QStringList list = QStringList::split("\n", m_outp);
111 QStringList::Iterator it;
112 for (it = list.begin(); it != list.end(); ++it ) {
113 if ( (*it).startsWith("Wrote" ) ) {
114 QStringList pathes = QStringList::split(' ', (*it) );
115 path = pathes[1];
116 }
117 }
118 return path;
119}