summaryrefslogtreecommitdiff
path: root/core/obex
Side-by-side diff
Diffstat (limited to 'core/obex') (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/obex.cc15
-rw-r--r--core/obex/obexhandler.cpp2
-rw-r--r--core/obex/obeximpl.cpp2
-rw-r--r--core/obex/obexsend.cpp2
-rw-r--r--core/obex/receiver.cpp73
-rw-r--r--core/obex/receiver.h5
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 @@
#include <qapplication.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qtextcodec.h>
#include <qpe/qcopenvelope_qws.h>
#include <opie/oprocess.h>
#include "obex.h"
using namespace OpieObex;
+/* TRANSLATOR OpieObex::Obex */
+
Obex::Obex( QObject *parent, const char* name )
: QObject(parent, name )
{
m_rec = 0;
m_send=0;
m_count = 0;
m_receive = false;
connect( this, SIGNAL(error(int) ), // for recovering to receive
SLOT(slotError() ) );
connect( this, SIGNAL(sent(bool) ),
SLOT(slotError() ) );
};
Obex::~Obex() {
delete m_rec;
delete m_send;
}
void Obex::receive() {
m_receive = true;
m_outp = QString::null;
qWarning("Receive" );
m_rec = new OProcess();
*m_rec << "irobex_palm3";
// connect to the necessary slots
connect(m_rec, SIGNAL(processExited(OProcess*) ),
this, SLOT(slotExited(OProcess*) ) );
connect(m_rec, SIGNAL(receivedStdout(OProcess*, char*, int ) ),
this, SLOT(slotStdOut(OProcess*, char*, int) ) );
if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
qWarning("could not start :(");
emit done( false );
delete m_rec;
m_rec = 0;
}
// emit currentTry(m_count );
}
void Obex::send( const QString& fileName) { // if currently receiving stop it send receive
m_count = 0;
m_file = fileName;
qWarning("send %s", fileName.latin1() );
if (m_rec != 0 ) {
qWarning("running");
if (m_rec->isRunning() ) {
emit error(-1 );
qWarning("is running");
delete m_rec;
@@ -64,119 +66,108 @@ void Obex::send( const QString& fileName) { // if currently receiving stop it se
}else{
qWarning("is not running");
emit error( -1 ); // we did not delete yet but it's not running slotExited is pending
return;
}
}
sendNow();
}
void Obex::sendNow(){
qWarning("sendNow");
if ( m_count >= 25 ) { // could not send
emit error(-1 );
emit sent(false);
return;
}
// OProcess inititialisation
m_send = new OProcess();
*m_send << "irobex_palm3";
*m_send << QFile::encodeName(m_file);
// connect to slots Exited and and StdOut
connect(m_send, SIGNAL(processExited(OProcess*) ),
this, SLOT(slotExited(OProcess*)) );
connect(m_send, SIGNAL(receivedStdout(OProcess*, char*, int )),
this, SLOT(slotStdOut(OProcess*, char*, int) ) );
// now start it
if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) {
qWarning("could not send" );
m_count = 25;
emit error(-1 );
delete m_send;
m_send=0;
}
// end
m_count++;
emit currentTry( m_count );
}
void Obex::slotExited(OProcess* proc ){
if (proc == m_rec ) { // receive process
received();
}else if ( proc == m_send ) {
sendEnd();
}
}
void Obex::slotStdOut(OProcess* proc, char* buf, int len){
if ( proc == m_rec ) { // only receive
- for (int i = 0; i < len; i++ ) {
- printf("%c", buf[i] );
- }
- printf("\n");
- QByteArray ar( len );
+ QByteArray ar( len );
memcpy( ar.data(), buf, len );
qWarning("parsed: %s", ar.data() );
m_outp.append( ar );
}
}
void Obex::received() {
if (m_rec->normalExit() ) {
if ( m_rec->exitStatus() == 0 ) { // we got one
QString filename = parseOut();
qWarning("ACHTUNG %s", filename.latin1() );
- if (filename.contains( 'ö' ) || filename.contains( 'ä' ) || filename.contains('ü' ) ) {
- qWarning("renaming!!!!");
- QFileInfo inf( filename );
- QString newName = "/tmp/opie-obex." + inf.extension();
- ::rename( QFile::encodeName( filename ).data(), newName );
- qWarning("name is %s", QFile::encodeName( filename ).data() );
- }
emit receivedFile( filename );
}
}else{
emit done(false);
};
delete m_rec;
m_rec = 0;
receive();
}
void Obex::sendEnd() {
if (m_send->normalExit() ) {
if ( m_send->exitStatus() == 0 ) {
delete m_send;
m_send=0;
qWarning("done" );
emit sent(true);
}else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready
// let's try it again
delete m_send;
m_send = 0;
qWarning("try sending again" );
sendNow();
}
}else {
emit error( -1 );
delete m_send;
m_send = 0;
}
}
QString Obex::parseOut( ){
QString path;
QStringList list = QStringList::split("\n", m_outp);
QStringList::Iterator it;
for (it = list.begin(); it != list.end(); ++it ) {
if ( (*it).startsWith("Wrote" ) ) {
int pos = (*it).findRev('(' );
if ( pos > 0 ) {
qWarning( "%d %s", pos, (*it).mid(6 ).latin1() ) ;
qWarning("%d %d", (*it).length(), (*it).length()-pos );
path = (*it).remove( pos, (*it).length() - pos );
qWarning("%s", path.latin1() );
path = path.mid(6 );
path = path.stripWhiteSpace();
qWarning("path %s", path.latin1() );
}
}
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 @@
#include <qcopchannel_qws.h>
#include <qpe/qcopenvelope_qws.h>
#include "obexsend.h"
#include "receiver.h"
#include "obexhandler.h"
using namespace OpieObex;
+/* TRANSLATOR OpieObex::ObexHandler */
+
ObexHandler::ObexHandler() {
m_wasRec = false;
m_sender = 0l;
m_receiver = 0l;
QCopChannel* chan = new QCopChannel("QPE/Obex");
connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ),
this, SLOT(irdaMessage(const QCString&, const QByteArray& ) ) );
}
ObexHandler::~ObexHandler() {
delete m_sender;
delete m_receiver;
}
void ObexHandler::doSend(const QString& str, const QString& desc) {
delete m_sender;
m_sender = new SendWidget;
m_sender->raise();
m_sender->showMaximized();
connect(m_sender, SIGNAL(done() ),
this, SLOT(slotSent() ) );
m_sender->send( str, desc );
}
void ObexHandler::doReceive(bool b) {
if (m_receiver && b ) return; // we should enable receiver and it is on
else if (!m_receiver && !b ) return; // we should disbale receiver and it is off
else if (m_receiver && !b ) {
delete m_receiver;
m_receiver=0;
}else if (!m_receiver && b ) {
m_receiver= new Receiver;
}
}
void ObexHandler::slotSent() {
QString file = m_sender->file();
delete m_sender;
m_sender = 0;
QCopEnvelope e ("QPE/Obex", "done(QString)" );
e << file;
doReceive(m_wasRec );
m_wasRec = false;
}
void ObexHandler::irdaMessage( const QCString& msg, const QByteArray& data) {
QDataStream stream( data, IO_ReadOnly );
if ( msg == "send(QString,QString,QString)" ) {
QString name, desc;
stream >> desc;
stream >> name;
m_wasRec = (m_receiver != 0 );
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 @@
#include "obexhandler.h"
#include "obeximpl.h"
using namespace OpieObex;
+/* TRANSLATOR OpieObex::ObexImpl */
+
ObexImpl::ObexImpl() {
m_handler = new ObexHandler;
}
ObexImpl::~ObexImpl() {
delete m_handler;
}
QRESULT ObexImpl::queryInterface( const QUuid& uuid, QUnknownInterface **iface ) {
*iface = 0;
if ( uuid == IID_QUnknown ) {
*iface = this;
}else if ( uuid == IID_ObexInterface )
*iface = this;
if (*iface)
(*iface)->addRef();
return QS_OK;
}
Q_EXPORT_INTERFACE() {
Q_CREATE_INSTANCE( ObexImpl )
}
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 @@
#include <qpushbutton.h>
#include <qlabel.h>
#include <qhbox.h>
#include <qlayout.h>
#include <qtimer.h>
#include <qtl.h>
#include <qcopchannel_qws.h>
#include <qpe/resource.h>
#include <qpe/qcopenvelope_qws.h>
#include "obex.h"
#include "obexsend.h"
using namespace OpieObex;
+/* TRANSLATOR OpieObex::SendWidget */
+
SendWidget::SendWidget( QWidget* parent, const char* name )
: QWidget( parent, name ) {
initUI();
}
SendWidget::~SendWidget() {
}
void SendWidget::initUI() {
m_obex = new Obex(this, "obex");
connect(m_obex, SIGNAL(error(int) ),
this, SLOT(slotIrError(int) ) );
connect(m_obex, SIGNAL(sent(bool) ),
this, SLOT(slotIrSent(bool) ) );
connect(m_obex, SIGNAL(currentTry(unsigned int ) ),
this, SLOT(slotIrTry(unsigned int ) ) );
QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this );
connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ),
this, SLOT(dispatchIrda(const QCString&, const QByteArray& ) ) );
chan = new QCopChannel("QPE/BluetoothBack", this );
connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ),
this, SLOT(dispatchBt(const QCString&, const QByteArray& ) ) );
QVBoxLayout* lay = new QVBoxLayout(this);
QHBox* nameBox = new QHBox(this);
QLabel* name = new QLabel(nameBox);
name->setText( tr("<qt><h1>Sending:</h1></qt>") );
name->setAlignment( AlignLeft | AlignTop );
m_lblFile = new QLabel(nameBox);
lay->addWidget(nameBox, 0);
QFrame* frame = new QFrame(this);
frame->setFrameShape( QFrame::HLine );
frame->setFrameShadow( QFrame::Sunken );
lay->addWidget(frame, 10);
QLabel* devices = new QLabel(this);
devices->setText("<qt><b>Devices:</b></qt>");
devices->setAlignment( AlignLeft | AlignTop );
lay->addWidget( devices,10 );
m_devBox = new DeviceBox(this);
lay->addWidget( m_devBox, 50 );
connect(m_devBox, SIGNAL(selectedDevice(int, int ) ),
this, SLOT(slotSelectedDevice(int, int) ) );
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 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
+#include <stdlib.h> // int system
#include <unistd.h>
#include <fcntl.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qlabel.h>
#include <qhbox.h>
+#include <qregexp.h>
#include <qtextview.h>
#include <qpushbutton.h>
#include <qpe/applnk.h>
#include <qpe/qpeapplication.h>
#include <qpe/qcopenvelope_qws.h>
+#include <qpe/global.h>
#include "obex.h"
#include "receiver.h"
using namespace OpieObex;
+/* TRANSLATOR OpieObex::Receiver */
+
Receiver::Receiver() {
m_obex = new Obex(this, "Receiver");
connect(m_obex, SIGNAL(receivedFile(const QString& ) ),
this, SLOT(slotReceived(const QString& ) ) );
m_obex->receive();
}
Receiver::~Receiver() {
m_obex->setReceiveEnabled( false );
delete m_obex;
}
-void Receiver::slotReceived( const QString& file ) {
+void Receiver::slotReceived( const QString& _file ) {
+ QString file = _file;
int check = checkFile(file);
if ( check == AddressBook )
handleAddr( file );
else if ( check == Datebook )
handleDateTodo( file );
else
handleOther( file );
}
void Receiver::handleAddr( const QString& str ) {
QCopEnvelope e("QPE/Application/addressbook", "setDocument(QString)" );
e << str;
}
/* we can not say for sure if it's a VEevent ot VTodo */
void Receiver::handleDateTodo( const QString& str ) {
QCopEnvelope e0("QPE/Application/todolist", "setDocument(QString)");
e0 << str;
QCopEnvelope e1("QPE/Application/datebook", "setDocument(QString)" );
e1 << str;
}
/*
* Handle other asks if it should accept the
* beamed object and creates a DocLnk
*/
void Receiver::handleOther( const QString& other ) {
OtherHandler* hand = new OtherHandler();
hand->handle( other );
}
-int Receiver::checkFile( const QString& file ) {
+void Receiver::tidyUp( QString& _file, const QString& ending) {
+ /* libversit fails on BASE64 encoding we try to sed it away */
+ QString file = _file;
+ char foo[24]; // big enough
+ (void)::strcpy(foo, "/tmp/opie-XXXXXX");
+
+ int fd = ::mkstemp(foo);
+
+ if ( fd == -1 )
+ return;
+
+ (void)::strncat( foo, ending.latin1(), 4 );
+ _file = QString::fromLatin1( foo );
+ QString cmd = QString("sed -e \"s/^\\(X-MICROSOFT-BODYINK\\)\\;/\\1:/;\" < %2 > %2 ").arg( Global::shellQuote(file)).arg( Global::shellQuote(_file) );
+ qWarning("Executing: %s", cmd.latin1() );
+ (void)::system( cmd.latin1() );
+
+ cmd = QString("rm %1").arg( Global::shellQuote(file) );
+ (void)::system( cmd.latin1() );
+}
+int Receiver::checkFile( QString& file ) {
qWarning("check file!! %s", file.latin1() );
int ret;
+ QString ending;
+
if (file.right(4) == ".vcs" ) {
ret = Datebook;
+ ending = QString::fromLatin1(".vcs");
}else if ( file.right(4) == ".vcf") {
ret = AddressBook;
+ ending = QString::fromLatin1(".vcf");
}else
ret = Other;
+ if (ending.isEmpty() )
+ return ret;
+
+ /**
+ * currently the parser is broken in regard of BASE64 encoding
+ * and M$ likes to send that. So we will executed a small
+ * tidy up system sed script
+ * At this point we can also remove umlaute from the filename
+ */
+ tidyUp( file, ending );
+
qWarning("check it now %d", ret );
return ret;
}
+/* TRANSLATOR OpieObex::OtherHandler */
+
OtherHandler::OtherHandler()
: QVBox()
{
QHBox* box = new QHBox(this);
QLabel* lbl = new QLabel(box);
lbl->setText(tr("<qt><b>Received:</b></qt>"));
m_na = new QLabel(box);
QFrame* frame = new QFrame(this);
frame->setFrameShape( QFrame::HLine );
frame->setFrameShadow( QFrame::Sunken );
m_view = new QTextView(this);
box = new QHBox(this);
QPushButton *but = new QPushButton(box);
but->setText(tr("Accept") );
connect(but, SIGNAL(clicked() ),
this, SLOT(accept()) );
but = new QPushButton(box);
but->setText(tr("Deny") );
connect(but, SIGNAL(clicked() ),
this, SLOT(deny() ) );
raise();
showMaximized();
}
OtherHandler::~OtherHandler() {
}
void OtherHandler::handle( const QString& file ) {
m_file = file;
m_na->setText(file);
DocLnk lnk(file);
qWarning(" %s %s", lnk.type().latin1(), lnk.icon().latin1() );
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() );
m_view->setText( str );
}
/*
* hehe evil evil mmap ahead :)
* we quickly copy the file and then we'll create a DocLnk for it
*/
void OtherHandler::accept() {
QString na = targetName( m_file );
copy(m_file, na );
DocLnk lnk(na);
lnk.writeLink();
QFile::remove(m_file);
delete this;
}
void OtherHandler::deny() {
QFile::remove( m_file );
delete this;
}
QString OtherHandler::targetName( const QString& file ) {
QFileInfo info( file );
+
+ /* $HOME needs to be set!!!! */
+ Global::createDocDir();
+
QString newFile = QPEApplication::documentDir()+ "/"+ info.baseName();
QString newFileBase = newFile;
int trie = 0;
while (QFile::exists(newFile + "."+info.extension() ) ) {
newFile = newFileBase + "_"+QString::number(trie) ;
trie++;
}
newFile += "." + info.extension();
return newFile;
}
/* fast cpy */
void OtherHandler::copy(const QString& src, const QString& file) {
qWarning("src %s, dest %s", src.latin1(),file.latin1() );
- int src_fd = ::open( QFile::encodeName( src ), O_RDONLY );
- int to_fd = ::open( QFile::encodeName( file), O_RDWR| O_CREAT| O_TRUNC,
- S_IRUSR, S_IWUSR, S_IRGRP, S_IRGRP );
-
- struct stat stater;
- ::fstat(src_fd, &stater );
- ::lseek(to_fd, stater.st_size-1, SEEK_SET );
- ::write(to_fd, "", 1 );
-
- void *src_addr, *dest_addr;
- src_addr = ::mmap(0, stater.st_size, PROT_READ,
- MAP_FILE | MAP_SHARED, src_fd, 0 );
- dest_addr= ::mmap(0, stater.st_size, PROT_READ | PROT_WRITE,
- MAP_FILE | MAP_PRIVATE, to_fd, 0 );
-
- ::memcpy(dest_addr , src_addr, stater.st_size );
- ::munmap(src_addr , stater.st_size );
- ::munmap(dest_addr, stater.st_size );
-
+ QString cmd = QString("mv %1 %2").arg( Global::shellQuote( src )).
+ arg( Global::shellQuote( file ) );
+ ::system( cmd.latin1() );
// done
}
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 @@
#ifndef OPIE_OBEX_RECEIVER_H
#define OPIE_OBEX_RECEIVER_H
#include <qobject.h>
#include <qvbox.h>
#include <qstring.h>
class QLabel;
class QTextView;
namespace OpieObex {
class Obex;
class OtherHandler;
class Receiver : public QObject {
Q_OBJECT
public:
enum { Datebook , AddressBook, Other };
Receiver();
~Receiver();
private:
void handleAddr(const QString& );
void handleDateTodo(const QString& );
void handleOther(const QString& );
- int checkFile( const QString& file );
+ /* will alter the file name */
+ int checkFile( QString& file );
bool testDateTodo(const QString& file);
bool testAddressbook(const QString& file);
+ /* called by checkFile */
+ void tidyUp( QString& file, const QString& ending );
private slots:
void slotReceived( const QString& );
private:
Obex* m_obex;
};
class OtherHandler : public QVBox {
Q_OBJECT
public:
OtherHandler();
~OtherHandler();
void handle( const QString& file );
private slots:
void accept();
void deny();
private:
QString targetName( const QString& file );
void copy( const QString& src, const QString& dest );
QLabel* m_na;
QTextView* m_view;
QString m_file;
};
}
#endif