summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/obex/obex.cc28
-rw-r--r--core/obex/obexsend.cpp7
-rw-r--r--core/obex/receiver.cpp18
3 files changed, 9 insertions, 44 deletions
diff --git a/core/obex/obex.cc b/core/obex/obex.cc
index 7c40b90..5dfcfb5 100644
--- a/core/obex/obex.cc
+++ b/core/obex/obex.cc
@@ -25,181 +25,161 @@ Obex::Obex( QObject *parent, const char* name )
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;
- owarn << "Receive" << oendl;
m_rec = new OProcess();
*m_rec << "irobex_palm3";
// connect to the necessary slots
connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ),
this, SLOT(slotExited(Opie::Core::OProcess*) ) );
connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) );
if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
- owarn << "could not start :(" oendl;
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;
- owarn << "send " << fileName.latin1() << oendl;
if (m_rec != 0 ) {
- owarn << "running" oendl;
if (m_rec->isRunning() ) {
emit error(-1 );
- owarn << "is running" << oendl;
delete m_rec;
m_rec = 0;
}else{
- owarn << "is not running" << oendl;
emit error( -1 ); // we did not delete yet but it's not running slotExited is pending
return;
}
}
sendNow();
}
void Obex::sendNow(){
- owarn << "sendNow" << oendl;
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(Opie::Core::OProcess*) ),
this, SLOT(slotExited(Opie::Core::OProcess*)) );
connect(m_send, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int )),
this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) );
// now start it
if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) {
- owarn << "could not send" << oendl;
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
+ if (proc == m_rec ) // receive process
received();
- }else if ( proc == m_send ) {
+ else if ( proc == m_send )
sendEnd();
- }
+
}
void Obex::slotStdOut(OProcess* proc, char* buf, int len){
if ( proc == m_rec ) { // only receive
QByteArray ar( len );
memcpy( ar.data(), buf, len );
- owarn << "parsed: " << ar.data() << oendl;
m_outp.append( ar );
}
}
void Obex::received() {
if (m_rec->normalExit() ) {
if ( m_rec->exitStatus() == 0 ) { // we got one
QString filename = parseOut();
- owarn << "ACHTUNG " << filename.latin1() << oendl;
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;
- owarn << "done" << oendl;
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;
- owarn << "try sending again" << oendl;
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 ) {
- owarn << pos << " " << (*it).mid(6 ).latin1() << oendl;
- owarn << (*it).length() << " " << (*it).length()-pos << oendl;
path = (*it).remove( pos, (*it).length() - pos );
- owarn << path.latin1() << oendl;
path = path.mid(6 );
path = path.stripWhiteSpace();
- owarn << "path " << path.latin1() << oendl;
}
}
}
return path;
}
/**
* when sent is done slotError is called we will start receive again
*/
void Obex::slotError() {
- owarn << "slotError" << oendl;
if ( m_receive )
receive();
};
void Obex::setReceiveEnabled( bool receive ) {
if ( !receive ) { //
m_receive = false;
shutDownReceive();
}
}
void Obex::shutDownReceive() {
if (m_rec != 0 ) {
- owarn << "running" << oendl;
if (m_rec->isRunning() ) {
emit error(-1 );
- owarn << "is running" << oendl;
delete m_rec;
m_rec = 0;
}
}
}
diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp
index f3dd11c..675c5e4 100644
--- a/core/obex/obexsend.cpp
+++ b/core/obex/obexsend.cpp
@@ -96,68 +96,64 @@ void SendWidget::send( const QString& file, const QString& desc ) {
m_start++;
}else
m_btDeSearch = m_devBox->addDevice( tr("Searching for bluetooth Devices."), DeviceBox::Search );
if (m_start != 2 ) {
QCopEnvelope e0("QPE/IrDaApplet", "enableIrda()");
QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()");
QCopEnvelope e2("QPE/IrDaApplet", "listDevices()");
QCopEnvelope e3("QPE/Bluetooth", "listDevices()");
}
}
void SendWidget::slotIrDaDevices( const QStringList& list) {
- owarn << "slot it irda devices " << oendl;
for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
int id = m_devBox->addDevice( (*it), DeviceBox::IrDa, tr("Scheduling for beam.") );
m_irDa.insert( id, (*it) );
}
m_devBox->removeDevice( m_irDeSearch );
m_irDaIt = m_irDa.begin();
slotStartIrda();
}
void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) {
for(QMap<QString, QString>::ConstIterator it = str.begin(); it != str.end(); ++it ) {
int id = m_devBox->addDevice( it.key(), DeviceBox::BT, tr("Click to beam") );
m_bt.insert( id, Pair( it.key(), it.data() ) );
}
m_devBox->removeDevice( m_btDeSearch );
}
-void SendWidget::slotSelectedDevice( int name, int dev ) {
- owarn << "Start beam? " << name << " " << dev << "" << oendl;
+void SendWidget::slotSelectedDevice( int name, int ) {
if ( name == m_irDeSearch ) {
for (QMap<int, QString>::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it )
m_devBox->removeDevice( it.key() );
QCopEnvelope e2("QPE/IrDaApplet", "listDevices()");
}
}
void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) {
- owarn << "dispatch irda " << str.data() << "" << oendl;
if ( str == "devices(QStringList)" ) {
QDataStream stream( ar, IO_ReadOnly );
QStringList list;
stream >> list;
slotIrDaDevices( list );
}
}
void SendWidget::dispatchBt( const QCString&, const QByteArray& ) {
}
void SendWidget::slotIrError( int ) {
}
void SendWidget::slotIrSent( bool b) {
- owarn << "irda sent!!" << oendl;
QString text = b ? tr("Sent") : tr("Failure");
m_devBox->setStatus( m_irDaIt.key(), text );
++m_irDaIt;
slotStartIrda();
}
void SendWidget::slotIrTry(unsigned int trI) {
m_devBox->setStatus( m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) ) );
}
void SendWidget::slotStartIrda() {
if (m_irDaIt == m_irDa.end() ) {
m_irDeSearch = m_devBox->addDevice(tr("Search again for IrDa."), DeviceBox::Search );
return;
@@ -196,25 +192,24 @@ int DeviceBox::addDevice( const QString& name, int dev, const QString& status )
void DeviceBox::removeDevice( int id ) {
if (!m_dev.contains(id) ) return;
m_dev.remove( id );
setText( allText() );
}
void DeviceBox::setStatus( int id, const QString& status ) {
if ( !m_dev.contains(id) ) return;
m_dev[id].setStatus(status );
setText( allText() );
}
void DeviceBox::setSource( const QString& str ) {
- owarn << "SetSource:" << str.toInt() << "" << oendl;
int id = str.toInt();
emit selectedDevice( id, m_dev[id].device() );
}
int DeviceBox::idFor ( int id ) {
static int irId = 1501;
static int irBT = 1001;
static int irSr = 501;
static int irEr = 0;
int ret = -1;
switch(id ) {
case IrDa:
diff --git a/core/obex/receiver.cpp b/core/obex/receiver.cpp
index d4ae323..7d9a42a 100644
--- a/core/obex/receiver.cpp
+++ b/core/obex/receiver.cpp
@@ -67,60 +67,57 @@ void Receiver::handleOther( const QString& other ) {
}
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 );
+ (void)::strncat( foo, QFile::encodeName(ending), 4 );
+ _file = QString::fromLocal8Bit( foo );
QString cmd = QString("sed -e \"s/^\\(X-MICROSOFT-BODYINK\\)\\;/\\1:/;\" < %2 > %2 ").arg( Global::shellQuote(file)).arg( Global::shellQuote(_file) );
- owarn << "Executing: " << cmd << "" << oendl;
- (void)::system( cmd.latin1() );
+ (void)::system( QFile::encodeName(cmd) );
cmd = QString("rm %1").arg( Global::shellQuote(file) );
- (void)::system( cmd.latin1() );
+ (void)::system( QFile::encodeName(cmd) );
}
int Receiver::checkFile( QString& file ) {
- owarn << "check file!! " << file << "" << oendl;
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 );
- owarn << "check it now " << ret << "" << oendl;
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);
@@ -143,25 +140,24 @@ OtherHandler::OtherHandler()
this, SLOT(deny() ) );
raise();
showMaximized();
}
OtherHandler::~OtherHandler() {
}
void OtherHandler::handle( const QString& file ) {
m_file = file;
m_na->setText(file);
DocLnk lnk(file);
- owarn << " " << lnk.type() << " " << lnk.icon() << "" << oendl;
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 );
@@ -186,23 +182,17 @@ QString OtherHandler::targetName( const QString& file ) {
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) {
- owarn << "src " << src << ", dest " << file << "" << oendl;
FileManager *fm;
if(!fm->copyFile(src,file)) {
owarn << "Copy failed" << oendl;
}
-
-// QString cmd = QString("mv %1 %2").arg( Global::shellQuote( src )).
-// arg( Global::shellQuote( file ) );
-// ::system( cmd.latin1() );
- // done
}