-rw-r--r-- | core/obex/obex.cc | 15 | ||||
-rw-r--r-- | core/obex/obexhandler.cpp | 2 | ||||
-rw-r--r-- | core/obex/obeximpl.cpp | 2 | ||||
-rw-r--r-- | core/obex/obexsend.cpp | 2 | ||||
-rw-r--r-- | core/obex/receiver.cpp | 73 | ||||
-rw-r--r-- | core/obex/receiver.h | 5 |
6 files changed, 65 insertions, 34 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 | } |
diff --git a/core/obex/obexhandler.cpp b/core/obex/obexhandler.cpp index 6509d12..5aaf63c 100644 --- a/core/obex/obexhandler.cpp +++ b/core/obex/obexhandler.cpp | |||
@@ -1,58 +1,60 @@ | |||
1 | #include <qcopchannel_qws.h> | 1 | #include <qcopchannel_qws.h> |
2 | 2 | ||
3 | #include <qpe/qcopenvelope_qws.h> | 3 | #include <qpe/qcopenvelope_qws.h> |
4 | 4 | ||
5 | #include "obexsend.h" | 5 | #include "obexsend.h" |
6 | #include "receiver.h" | 6 | #include "receiver.h" |
7 | #include "obexhandler.h" | 7 | #include "obexhandler.h" |
8 | 8 | ||
9 | using namespace OpieObex; | 9 | using namespace OpieObex; |
10 | 10 | ||
11 | /* TRANSLATOR OpieObex::ObexHandler */ | ||
12 | |||
11 | ObexHandler::ObexHandler() { | 13 | ObexHandler::ObexHandler() { |
12 | m_wasRec = false; | 14 | m_wasRec = false; |
13 | m_sender = 0l; | 15 | m_sender = 0l; |
14 | m_receiver = 0l; | 16 | m_receiver = 0l; |
15 | QCopChannel* chan = new QCopChannel("QPE/Obex"); | 17 | QCopChannel* chan = new QCopChannel("QPE/Obex"); |
16 | connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ), | 18 | connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ), |
17 | this, SLOT(irdaMessage(const QCString&, const QByteArray& ) ) ); | 19 | this, SLOT(irdaMessage(const QCString&, const QByteArray& ) ) ); |
18 | } | 20 | } |
19 | ObexHandler::~ObexHandler() { | 21 | ObexHandler::~ObexHandler() { |
20 | delete m_sender; | 22 | delete m_sender; |
21 | delete m_receiver; | 23 | delete m_receiver; |
22 | } | 24 | } |
23 | void ObexHandler::doSend(const QString& str, const QString& desc) { | 25 | void ObexHandler::doSend(const QString& str, const QString& desc) { |
24 | delete m_sender; | 26 | delete m_sender; |
25 | m_sender = new SendWidget; | 27 | m_sender = new SendWidget; |
26 | m_sender->raise(); | 28 | m_sender->raise(); |
27 | m_sender->showMaximized(); | 29 | m_sender->showMaximized(); |
28 | connect(m_sender, SIGNAL(done() ), | 30 | connect(m_sender, SIGNAL(done() ), |
29 | this, SLOT(slotSent() ) ); | 31 | this, SLOT(slotSent() ) ); |
30 | m_sender->send( str, desc ); | 32 | m_sender->send( str, desc ); |
31 | } | 33 | } |
32 | void ObexHandler::doReceive(bool b) { | 34 | void ObexHandler::doReceive(bool b) { |
33 | if (m_receiver && b ) return; // we should enable receiver and it is on | 35 | if (m_receiver && b ) return; // we should enable receiver and it is on |
34 | else if (!m_receiver && !b ) return; // we should disbale receiver and it is off | 36 | else if (!m_receiver && !b ) return; // we should disbale receiver and it is off |
35 | else if (m_receiver && !b ) { | 37 | else if (m_receiver && !b ) { |
36 | delete m_receiver; | 38 | delete m_receiver; |
37 | m_receiver=0; | 39 | m_receiver=0; |
38 | }else if (!m_receiver && b ) { | 40 | }else if (!m_receiver && b ) { |
39 | m_receiver= new Receiver; | 41 | m_receiver= new Receiver; |
40 | } | 42 | } |
41 | } | 43 | } |
42 | void ObexHandler::slotSent() { | 44 | void ObexHandler::slotSent() { |
43 | QString file = m_sender->file(); | 45 | QString file = m_sender->file(); |
44 | delete m_sender; | 46 | delete m_sender; |
45 | m_sender = 0; | 47 | m_sender = 0; |
46 | QCopEnvelope e ("QPE/Obex", "done(QString)" ); | 48 | QCopEnvelope e ("QPE/Obex", "done(QString)" ); |
47 | e << file; | 49 | e << file; |
48 | doReceive(m_wasRec ); | 50 | doReceive(m_wasRec ); |
49 | m_wasRec = false; | 51 | m_wasRec = false; |
50 | } | 52 | } |
51 | void ObexHandler::irdaMessage( const QCString& msg, const QByteArray& data) { | 53 | void ObexHandler::irdaMessage( const QCString& msg, const QByteArray& data) { |
52 | QDataStream stream( data, IO_ReadOnly ); | 54 | QDataStream stream( data, IO_ReadOnly ); |
53 | if ( msg == "send(QString,QString,QString)" ) { | 55 | if ( msg == "send(QString,QString,QString)" ) { |
54 | QString name, desc; | 56 | QString name, desc; |
55 | stream >> desc; | 57 | stream >> desc; |
56 | stream >> name; | 58 | stream >> name; |
57 | m_wasRec = (m_receiver != 0 ); | 59 | m_wasRec = (m_receiver != 0 ); |
58 | doReceive( false ); | 60 | doReceive( false ); |
diff --git a/core/obex/obeximpl.cpp b/core/obex/obeximpl.cpp index 12a078f..5bfc779 100644 --- a/core/obex/obeximpl.cpp +++ b/core/obex/obeximpl.cpp | |||
@@ -1,28 +1,30 @@ | |||
1 | #include "obexhandler.h" | 1 | #include "obexhandler.h" |
2 | #include "obeximpl.h" | 2 | #include "obeximpl.h" |
3 | 3 | ||
4 | using namespace OpieObex; | 4 | using namespace OpieObex; |
5 | 5 | ||
6 | /* TRANSLATOR OpieObex::ObexImpl */ | ||
7 | |||
6 | ObexImpl::ObexImpl() { | 8 | ObexImpl::ObexImpl() { |
7 | m_handler = new ObexHandler; | 9 | m_handler = new ObexHandler; |
8 | } | 10 | } |
9 | ObexImpl::~ObexImpl() { | 11 | ObexImpl::~ObexImpl() { |
10 | delete m_handler; | 12 | delete m_handler; |
11 | } | 13 | } |
12 | QRESULT ObexImpl::queryInterface( const QUuid& uuid, QUnknownInterface **iface ) { | 14 | QRESULT ObexImpl::queryInterface( const QUuid& uuid, QUnknownInterface **iface ) { |
13 | *iface = 0; | 15 | *iface = 0; |
14 | if ( uuid == IID_QUnknown ) { | 16 | if ( uuid == IID_QUnknown ) { |
15 | *iface = this; | 17 | *iface = this; |
16 | }else if ( uuid == IID_ObexInterface ) | 18 | }else if ( uuid == IID_ObexInterface ) |
17 | *iface = this; | 19 | *iface = this; |
18 | 20 | ||
19 | if (*iface) | 21 | if (*iface) |
20 | (*iface)->addRef(); | 22 | (*iface)->addRef(); |
21 | 23 | ||
22 | return QS_OK; | 24 | return QS_OK; |
23 | } | 25 | } |
24 | 26 | ||
25 | 27 | ||
26 | Q_EXPORT_INTERFACE() { | 28 | Q_EXPORT_INTERFACE() { |
27 | Q_CREATE_INSTANCE( ObexImpl ) | 29 | Q_CREATE_INSTANCE( ObexImpl ) |
28 | } | 30 | } |
diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp index 2931cf7..cf5d958 100644 --- a/core/obex/obexsend.cpp +++ b/core/obex/obexsend.cpp | |||
@@ -1,65 +1,67 @@ | |||
1 | #include <qpushbutton.h> | 1 | #include <qpushbutton.h> |
2 | #include <qlabel.h> | 2 | #include <qlabel.h> |
3 | #include <qhbox.h> | 3 | #include <qhbox.h> |
4 | #include <qlayout.h> | 4 | #include <qlayout.h> |
5 | #include <qtimer.h> | 5 | #include <qtimer.h> |
6 | #include <qtl.h> | 6 | #include <qtl.h> |
7 | 7 | ||
8 | #include <qcopchannel_qws.h> | 8 | #include <qcopchannel_qws.h> |
9 | 9 | ||
10 | #include <qpe/resource.h> | 10 | #include <qpe/resource.h> |
11 | #include <qpe/qcopenvelope_qws.h> | 11 | #include <qpe/qcopenvelope_qws.h> |
12 | 12 | ||
13 | #include "obex.h" | 13 | #include "obex.h" |
14 | #include "obexsend.h" | 14 | #include "obexsend.h" |
15 | 15 | ||
16 | using namespace OpieObex; | 16 | using namespace OpieObex; |
17 | 17 | ||
18 | /* TRANSLATOR OpieObex::SendWidget */ | ||
19 | |||
18 | 20 | ||
19 | SendWidget::SendWidget( QWidget* parent, const char* name ) | 21 | SendWidget::SendWidget( QWidget* parent, const char* name ) |
20 | : QWidget( parent, name ) { | 22 | : QWidget( parent, name ) { |
21 | initUI(); | 23 | initUI(); |
22 | } | 24 | } |
23 | SendWidget::~SendWidget() { | 25 | SendWidget::~SendWidget() { |
24 | } | 26 | } |
25 | void SendWidget::initUI() { | 27 | void SendWidget::initUI() { |
26 | m_obex = new Obex(this, "obex"); | 28 | m_obex = new Obex(this, "obex"); |
27 | connect(m_obex, SIGNAL(error(int) ), | 29 | connect(m_obex, SIGNAL(error(int) ), |
28 | this, SLOT(slotIrError(int) ) ); | 30 | this, SLOT(slotIrError(int) ) ); |
29 | connect(m_obex, SIGNAL(sent(bool) ), | 31 | connect(m_obex, SIGNAL(sent(bool) ), |
30 | this, SLOT(slotIrSent(bool) ) ); | 32 | this, SLOT(slotIrSent(bool) ) ); |
31 | connect(m_obex, SIGNAL(currentTry(unsigned int ) ), | 33 | connect(m_obex, SIGNAL(currentTry(unsigned int ) ), |
32 | this, SLOT(slotIrTry(unsigned int ) ) ); | 34 | this, SLOT(slotIrTry(unsigned int ) ) ); |
33 | 35 | ||
34 | QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this ); | 36 | QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this ); |
35 | connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ), | 37 | connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ), |
36 | this, SLOT(dispatchIrda(const QCString&, const QByteArray& ) ) ); | 38 | this, SLOT(dispatchIrda(const QCString&, const QByteArray& ) ) ); |
37 | 39 | ||
38 | chan = new QCopChannel("QPE/BluetoothBack", this ); | 40 | chan = new QCopChannel("QPE/BluetoothBack", this ); |
39 | connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ), | 41 | connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ), |
40 | this, SLOT(dispatchBt(const QCString&, const QByteArray& ) ) ); | 42 | this, SLOT(dispatchBt(const QCString&, const QByteArray& ) ) ); |
41 | 43 | ||
42 | QVBoxLayout* lay = new QVBoxLayout(this); | 44 | QVBoxLayout* lay = new QVBoxLayout(this); |
43 | 45 | ||
44 | QHBox* nameBox = new QHBox(this); | 46 | QHBox* nameBox = new QHBox(this); |
45 | QLabel* name = new QLabel(nameBox); | 47 | QLabel* name = new QLabel(nameBox); |
46 | name->setText( tr("<qt><h1>Sending:</h1></qt>") ); | 48 | name->setText( tr("<qt><h1>Sending:</h1></qt>") ); |
47 | name->setAlignment( AlignLeft | AlignTop ); | 49 | name->setAlignment( AlignLeft | AlignTop ); |
48 | m_lblFile = new QLabel(nameBox); | 50 | m_lblFile = new QLabel(nameBox); |
49 | lay->addWidget(nameBox, 0); | 51 | lay->addWidget(nameBox, 0); |
50 | 52 | ||
51 | QFrame* frame = new QFrame(this); | 53 | QFrame* frame = new QFrame(this); |
52 | frame->setFrameShape( QFrame::HLine ); | 54 | frame->setFrameShape( QFrame::HLine ); |
53 | frame->setFrameShadow( QFrame::Sunken ); | 55 | frame->setFrameShadow( QFrame::Sunken ); |
54 | lay->addWidget(frame, 10); | 56 | lay->addWidget(frame, 10); |
55 | 57 | ||
56 | QLabel* devices = new QLabel(this); | 58 | QLabel* devices = new QLabel(this); |
57 | devices->setText("<qt><b>Devices:</b></qt>"); | 59 | devices->setText("<qt><b>Devices:</b></qt>"); |
58 | devices->setAlignment( AlignLeft | AlignTop ); | 60 | devices->setAlignment( AlignLeft | AlignTop ); |
59 | lay->addWidget( devices,10 ); | 61 | lay->addWidget( devices,10 ); |
60 | 62 | ||
61 | m_devBox = new DeviceBox(this); | 63 | m_devBox = new DeviceBox(this); |
62 | lay->addWidget( m_devBox, 50 ); | 64 | lay->addWidget( m_devBox, 50 ); |
63 | connect(m_devBox, SIGNAL(selectedDevice(int, int ) ), | 65 | connect(m_devBox, SIGNAL(selectedDevice(int, int ) ), |
64 | this, SLOT(slotSelectedDevice(int, int) ) ); | 66 | this, SLOT(slotSelectedDevice(int, int) ) ); |
65 | 67 | ||
diff --git a/core/obex/receiver.cpp b/core/obex/receiver.cpp index 31c6afe..bf9e30c 100644 --- a/core/obex/receiver.cpp +++ b/core/obex/receiver.cpp | |||
@@ -1,172 +1,203 @@ | |||
1 | #include <sys/types.h> | 1 | #include <sys/types.h> |
2 | #include <sys/stat.h> | 2 | #include <sys/stat.h> |
3 | #include <sys/mman.h> | 3 | #include <sys/mman.h> |
4 | #include <stdlib.h> // int system | ||
4 | #include <unistd.h> | 5 | #include <unistd.h> |
5 | 6 | ||
6 | #include <fcntl.h> | 7 | #include <fcntl.h> |
7 | 8 | ||
8 | #include <qfile.h> | 9 | #include <qfile.h> |
9 | #include <qfileinfo.h> | 10 | #include <qfileinfo.h> |
10 | #include <qlabel.h> | 11 | #include <qlabel.h> |
11 | #include <qhbox.h> | 12 | #include <qhbox.h> |
13 | #include <qregexp.h> | ||
12 | #include <qtextview.h> | 14 | #include <qtextview.h> |
13 | #include <qpushbutton.h> | 15 | #include <qpushbutton.h> |
14 | 16 | ||
15 | #include <qpe/applnk.h> | 17 | #include <qpe/applnk.h> |
16 | #include <qpe/qpeapplication.h> | 18 | #include <qpe/qpeapplication.h> |
17 | #include <qpe/qcopenvelope_qws.h> | 19 | #include <qpe/qcopenvelope_qws.h> |
20 | #include <qpe/global.h> | ||
18 | 21 | ||
19 | #include "obex.h" | 22 | #include "obex.h" |
20 | #include "receiver.h" | 23 | #include "receiver.h" |
21 | 24 | ||
22 | using namespace OpieObex; | 25 | using namespace OpieObex; |
23 | 26 | ||
27 | /* TRANSLATOR OpieObex::Receiver */ | ||
28 | |||
24 | Receiver::Receiver() { | 29 | Receiver::Receiver() { |
25 | m_obex = new Obex(this, "Receiver"); | 30 | m_obex = new Obex(this, "Receiver"); |
26 | connect(m_obex, SIGNAL(receivedFile(const QString& ) ), | 31 | connect(m_obex, SIGNAL(receivedFile(const QString& ) ), |
27 | this, SLOT(slotReceived(const QString& ) ) ); | 32 | this, SLOT(slotReceived(const QString& ) ) ); |
28 | m_obex->receive(); | 33 | m_obex->receive(); |
29 | } | 34 | } |
30 | Receiver::~Receiver() { | 35 | Receiver::~Receiver() { |
31 | m_obex->setReceiveEnabled( false ); | 36 | m_obex->setReceiveEnabled( false ); |
32 | delete m_obex; | 37 | delete m_obex; |
33 | } | 38 | } |
34 | void Receiver::slotReceived( const QString& file ) { | 39 | void Receiver::slotReceived( const QString& _file ) { |
40 | QString file = _file; | ||
35 | int check = checkFile(file); | 41 | int check = checkFile(file); |
36 | if ( check == AddressBook ) | 42 | if ( check == AddressBook ) |
37 | handleAddr( file ); | 43 | handleAddr( file ); |
38 | else if ( check == Datebook ) | 44 | else if ( check == Datebook ) |
39 | handleDateTodo( file ); | 45 | handleDateTodo( file ); |
40 | else | 46 | else |
41 | handleOther( file ); | 47 | handleOther( file ); |
42 | } | 48 | } |
43 | void Receiver::handleAddr( const QString& str ) { | 49 | void Receiver::handleAddr( const QString& str ) { |
44 | QCopEnvelope e("QPE/Application/addressbook", "setDocument(QString)" ); | 50 | QCopEnvelope e("QPE/Application/addressbook", "setDocument(QString)" ); |
45 | e << str; | 51 | e << str; |
46 | } | 52 | } |
47 | /* we can not say for sure if it's a VEevent ot VTodo */ | 53 | /* we can not say for sure if it's a VEevent ot VTodo */ |
48 | void Receiver::handleDateTodo( const QString& str ) { | 54 | void Receiver::handleDateTodo( const QString& str ) { |
49 | QCopEnvelope e0("QPE/Application/todolist", "setDocument(QString)"); | 55 | QCopEnvelope e0("QPE/Application/todolist", "setDocument(QString)"); |
50 | e0 << str; | 56 | e0 << str; |
51 | QCopEnvelope e1("QPE/Application/datebook", "setDocument(QString)" ); | 57 | QCopEnvelope e1("QPE/Application/datebook", "setDocument(QString)" ); |
52 | e1 << str; | 58 | e1 << str; |
53 | } | 59 | } |
54 | /* | 60 | /* |
55 | * Handle other asks if it should accept the | 61 | * Handle other asks if it should accept the |
56 | * beamed object and creates a DocLnk | 62 | * beamed object and creates a DocLnk |
57 | */ | 63 | */ |
58 | void Receiver::handleOther( const QString& other ) { | 64 | void Receiver::handleOther( const QString& other ) { |
59 | OtherHandler* hand = new OtherHandler(); | 65 | OtherHandler* hand = new OtherHandler(); |
60 | hand->handle( other ); | 66 | hand->handle( other ); |
61 | } | 67 | } |
62 | int Receiver::checkFile( const QString& file ) { | 68 | void Receiver::tidyUp( QString& _file, const QString& ending) { |
69 | /* libversit fails on BASE64 encoding we try to sed it away */ | ||
70 | QString file = _file; | ||
71 | char foo[24]; // big enough | ||
72 | (void)::strcpy(foo, "/tmp/opie-XXXXXX"); | ||
73 | |||
74 | int fd = ::mkstemp(foo); | ||
75 | |||
76 | if ( fd == -1 ) | ||
77 | return; | ||
78 | |||
79 | (void)::strncat( foo, ending.latin1(), 4 ); | ||
80 | _file = QString::fromLatin1( foo ); | ||
81 | QString cmd = QString("sed -e \"s/^\\(X-MICROSOFT-BODYINK\\)\\;/\\1:/;\" < %2 > %2 ").arg( Global::shellQuote(file)).arg( Global::shellQuote(_file) ); | ||
82 | qWarning("Executing: %s", cmd.latin1() ); | ||
83 | (void)::system( cmd.latin1() ); | ||
84 | |||
85 | cmd = QString("rm %1").arg( Global::shellQuote(file) ); | ||
86 | (void)::system( cmd.latin1() ); | ||
87 | } | ||
88 | int Receiver::checkFile( QString& file ) { | ||
63 | qWarning("check file!! %s", file.latin1() ); | 89 | qWarning("check file!! %s", file.latin1() ); |
64 | int ret; | 90 | int ret; |
91 | QString ending; | ||
92 | |||
65 | if (file.right(4) == ".vcs" ) { | 93 | if (file.right(4) == ".vcs" ) { |
66 | ret = Datebook; | 94 | ret = Datebook; |
95 | ending = QString::fromLatin1(".vcs"); | ||
67 | }else if ( file.right(4) == ".vcf") { | 96 | }else if ( file.right(4) == ".vcf") { |
68 | ret = AddressBook; | 97 | ret = AddressBook; |
98 | ending = QString::fromLatin1(".vcf"); | ||
69 | }else | 99 | }else |
70 | ret = Other; | 100 | ret = Other; |
71 | 101 | ||
72 | 102 | ||
103 | if (ending.isEmpty() ) | ||
104 | return ret; | ||
105 | |||
106 | /** | ||
107 | * currently the parser is broken in regard of BASE64 encoding | ||
108 | * and M$ likes to send that. So we will executed a small | ||
109 | * tidy up system sed script | ||
110 | * At this point we can also remove umlaute from the filename | ||
111 | */ | ||
112 | tidyUp( file, ending ); | ||
113 | |||
73 | qWarning("check it now %d", ret ); | 114 | qWarning("check it now %d", ret ); |
74 | return ret; | 115 | return ret; |
75 | } | 116 | } |
76 | 117 | ||
118 | /* TRANSLATOR OpieObex::OtherHandler */ | ||
119 | |||
77 | OtherHandler::OtherHandler() | 120 | OtherHandler::OtherHandler() |
78 | : QVBox() | 121 | : QVBox() |
79 | { | 122 | { |
80 | QHBox* box = new QHBox(this); | 123 | QHBox* box = new QHBox(this); |
81 | QLabel* lbl = new QLabel(box); | 124 | QLabel* lbl = new QLabel(box); |
82 | lbl->setText(tr("<qt><b>Received:</b></qt>")); | 125 | lbl->setText(tr("<qt><b>Received:</b></qt>")); |
83 | m_na = new QLabel(box); | 126 | m_na = new QLabel(box); |
84 | 127 | ||
85 | QFrame* frame = new QFrame(this); | 128 | QFrame* frame = new QFrame(this); |
86 | frame->setFrameShape( QFrame::HLine ); | 129 | frame->setFrameShape( QFrame::HLine ); |
87 | frame->setFrameShadow( QFrame::Sunken ); | 130 | frame->setFrameShadow( QFrame::Sunken ); |
88 | 131 | ||
89 | m_view = new QTextView(this); | 132 | m_view = new QTextView(this); |
90 | 133 | ||
91 | box = new QHBox(this); | 134 | box = new QHBox(this); |
92 | QPushButton *but = new QPushButton(box); | 135 | QPushButton *but = new QPushButton(box); |
93 | but->setText(tr("Accept") ); | 136 | but->setText(tr("Accept") ); |
94 | connect(but, SIGNAL(clicked() ), | 137 | connect(but, SIGNAL(clicked() ), |
95 | this, SLOT(accept()) ); | 138 | this, SLOT(accept()) ); |
96 | 139 | ||
97 | but = new QPushButton(box); | 140 | but = new QPushButton(box); |
98 | but->setText(tr("Deny") ); | 141 | but->setText(tr("Deny") ); |
99 | connect(but, SIGNAL(clicked() ), | 142 | connect(but, SIGNAL(clicked() ), |
100 | this, SLOT(deny() ) ); | 143 | this, SLOT(deny() ) ); |
101 | 144 | ||
102 | raise(); | 145 | raise(); |
103 | showMaximized(); | 146 | showMaximized(); |
104 | } | 147 | } |
105 | OtherHandler::~OtherHandler() { | 148 | OtherHandler::~OtherHandler() { |
106 | 149 | ||
107 | } | 150 | } |
108 | void OtherHandler::handle( const QString& file ) { | 151 | void OtherHandler::handle( const QString& file ) { |
109 | m_file = file; | 152 | m_file = file; |
110 | m_na->setText(file); | 153 | m_na->setText(file); |
111 | DocLnk lnk(file); | 154 | DocLnk lnk(file); |
112 | qWarning(" %s %s", lnk.type().latin1(), lnk.icon().latin1() ); | 155 | qWarning(" %s %s", lnk.type().latin1(), lnk.icon().latin1() ); |
113 | 156 | ||
114 | QString str = tr("<p>You received a file of type %1 (<img src=\"%2\"> )What do you want to do?").arg(lnk.type() ).arg(lnk.icon() ); | 157 | QString str = tr("<p>You received a file of type %1 (<img src=\"%2\"> )What do you want to do?").arg(lnk.type() ).arg(lnk.icon() ); |
115 | m_view->setText( str ); | 158 | m_view->setText( str ); |
116 | } | 159 | } |
117 | 160 | ||
118 | /* | 161 | /* |
119 | * hehe evil evil mmap ahead :) | 162 | * hehe evil evil mmap ahead :) |
120 | * we quickly copy the file and then we'll create a DocLnk for it | 163 | * we quickly copy the file and then we'll create a DocLnk for it |
121 | */ | 164 | */ |
122 | void OtherHandler::accept() { | 165 | void OtherHandler::accept() { |
123 | QString na = targetName( m_file ); | 166 | QString na = targetName( m_file ); |
124 | copy(m_file, na ); | 167 | copy(m_file, na ); |
125 | DocLnk lnk(na); | 168 | DocLnk lnk(na); |
126 | lnk.writeLink(); | 169 | lnk.writeLink(); |
127 | QFile::remove(m_file); | 170 | QFile::remove(m_file); |
128 | delete this; | 171 | delete this; |
129 | } | 172 | } |
130 | void OtherHandler::deny() { | 173 | void OtherHandler::deny() { |
131 | QFile::remove( m_file ); | 174 | QFile::remove( m_file ); |
132 | delete this; | 175 | delete this; |
133 | } | 176 | } |
134 | QString OtherHandler::targetName( const QString& file ) { | 177 | QString OtherHandler::targetName( const QString& file ) { |
135 | QFileInfo info( file ); | 178 | QFileInfo info( file ); |
179 | |||
180 | /* $HOME needs to be set!!!! */ | ||
181 | Global::createDocDir(); | ||
182 | |||
136 | QString newFile = QPEApplication::documentDir()+ "/"+ info.baseName(); | 183 | QString newFile = QPEApplication::documentDir()+ "/"+ info.baseName(); |
137 | QString newFileBase = newFile; | 184 | QString newFileBase = newFile; |
138 | 185 | ||
139 | int trie = 0; | 186 | int trie = 0; |
140 | while (QFile::exists(newFile + "."+info.extension() ) ) { | 187 | while (QFile::exists(newFile + "."+info.extension() ) ) { |
141 | newFile = newFileBase + "_"+QString::number(trie) ; | 188 | newFile = newFileBase + "_"+QString::number(trie) ; |
142 | trie++; | 189 | trie++; |
143 | } | 190 | } |
144 | newFile += "." + info.extension(); | 191 | newFile += "." + info.extension(); |
145 | 192 | ||
146 | return newFile; | 193 | return newFile; |
147 | } | 194 | } |
148 | 195 | ||
149 | /* fast cpy */ | 196 | /* fast cpy */ |
150 | void OtherHandler::copy(const QString& src, const QString& file) { | 197 | void OtherHandler::copy(const QString& src, const QString& file) { |
151 | qWarning("src %s, dest %s", src.latin1(),file.latin1() ); | 198 | qWarning("src %s, dest %s", src.latin1(),file.latin1() ); |
152 | int src_fd = ::open( QFile::encodeName( src ), O_RDONLY ); | 199 | QString cmd = QString("mv %1 %2").arg( Global::shellQuote( src )). |
153 | int to_fd = ::open( QFile::encodeName( file), O_RDWR| O_CREAT| O_TRUNC, | 200 | arg( Global::shellQuote( file ) ); |
154 | S_IRUSR, S_IWUSR, S_IRGRP, S_IRGRP ); | 201 | ::system( cmd.latin1() ); |
155 | |||
156 | struct stat stater; | ||
157 | ::fstat(src_fd, &stater ); | ||
158 | ::lseek(to_fd, stater.st_size-1, SEEK_SET ); | ||
159 | ::write(to_fd, "", 1 ); | ||
160 | |||
161 | void *src_addr, *dest_addr; | ||
162 | src_addr = ::mmap(0, stater.st_size, PROT_READ, | ||
163 | MAP_FILE | MAP_SHARED, src_fd, 0 ); | ||
164 | dest_addr= ::mmap(0, stater.st_size, PROT_READ | PROT_WRITE, | ||
165 | MAP_FILE | MAP_PRIVATE, to_fd, 0 ); | ||
166 | |||
167 | ::memcpy(dest_addr , src_addr, stater.st_size ); | ||
168 | ::munmap(src_addr , stater.st_size ); | ||
169 | ::munmap(dest_addr, stater.st_size ); | ||
170 | |||
171 | // done | 202 | // done |
172 | } | 203 | } |
diff --git a/core/obex/receiver.h b/core/obex/receiver.h index 5b20146..e1d54df 100644 --- a/core/obex/receiver.h +++ b/core/obex/receiver.h | |||
@@ -1,55 +1,58 @@ | |||
1 | #ifndef OPIE_OBEX_RECEIVER_H | 1 | #ifndef OPIE_OBEX_RECEIVER_H |
2 | #define OPIE_OBEX_RECEIVER_H | 2 | #define OPIE_OBEX_RECEIVER_H |
3 | 3 | ||
4 | #include <qobject.h> | 4 | #include <qobject.h> |
5 | #include <qvbox.h> | 5 | #include <qvbox.h> |
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | 7 | ||
8 | class QLabel; | 8 | class QLabel; |
9 | class QTextView; | 9 | class QTextView; |
10 | namespace OpieObex { | 10 | namespace OpieObex { |
11 | class Obex; | 11 | class Obex; |
12 | class OtherHandler; | 12 | class OtherHandler; |
13 | class Receiver : public QObject { | 13 | class Receiver : public QObject { |
14 | Q_OBJECT | 14 | Q_OBJECT |
15 | public: | 15 | public: |
16 | enum { Datebook , AddressBook, Other }; | 16 | enum { Datebook , AddressBook, Other }; |
17 | Receiver(); | 17 | Receiver(); |
18 | ~Receiver(); | 18 | ~Receiver(); |
19 | 19 | ||
20 | private: | 20 | private: |
21 | void handleAddr(const QString& ); | 21 | void handleAddr(const QString& ); |
22 | void handleDateTodo(const QString& ); | 22 | void handleDateTodo(const QString& ); |
23 | void handleOther(const QString& ); | 23 | void handleOther(const QString& ); |
24 | int checkFile( const QString& file ); | 24 | /* will alter the file name */ |
25 | int checkFile( QString& file ); | ||
25 | bool testDateTodo(const QString& file); | 26 | bool testDateTodo(const QString& file); |
26 | bool testAddressbook(const QString& file); | 27 | bool testAddressbook(const QString& file); |
28 | /* called by checkFile */ | ||
29 | void tidyUp( QString& file, const QString& ending ); | ||
27 | 30 | ||
28 | private slots: | 31 | private slots: |
29 | void slotReceived( const QString& ); | 32 | void slotReceived( const QString& ); |
30 | 33 | ||
31 | private: | 34 | private: |
32 | Obex* m_obex; | 35 | Obex* m_obex; |
33 | }; | 36 | }; |
34 | 37 | ||
35 | class OtherHandler : public QVBox { | 38 | class OtherHandler : public QVBox { |
36 | Q_OBJECT | 39 | Q_OBJECT |
37 | public: | 40 | public: |
38 | OtherHandler(); | 41 | OtherHandler(); |
39 | ~OtherHandler(); | 42 | ~OtherHandler(); |
40 | 43 | ||
41 | void handle( const QString& file ); | 44 | void handle( const QString& file ); |
42 | private slots: | 45 | private slots: |
43 | void accept(); | 46 | void accept(); |
44 | void deny(); | 47 | void deny(); |
45 | private: | 48 | private: |
46 | QString targetName( const QString& file ); | 49 | QString targetName( const QString& file ); |
47 | void copy( const QString& src, const QString& dest ); | 50 | void copy( const QString& src, const QString& dest ); |
48 | QLabel* m_na; | 51 | QLabel* m_na; |
49 | QTextView* m_view; | 52 | QTextView* m_view; |
50 | QString m_file; | 53 | QString m_file; |
51 | }; | 54 | }; |
52 | } | 55 | } |
53 | 56 | ||
54 | 57 | ||
55 | #endif | 58 | #endif |