-rw-r--r-- | core/obex/obex.cc | 22 | ||||
-rw-r--r-- | core/obex/obexsend.cpp | 141 | ||||
-rw-r--r-- | core/obex/obexsend.h | 47 |
3 files changed, 143 insertions, 67 deletions
diff --git a/core/obex/obex.cc b/core/obex/obex.cc index b8ed6e0..595fed9 100644 --- a/core/obex/obex.cc +++ b/core/obex/obex.cc @@ -3,4 +3,7 @@ #include <qfile.h> -#include <qmessagebox.h> +#include <qfileinfo.h> +#include <qtextcodec.h> + #include <qpe/qcopenvelope_qws.h> + #include <opie/oprocess.h> @@ -108,4 +111,10 @@ void Obex::slotStdOut(OProcess* proc, char* buf, int len){ if ( proc == m_rec ) { // only receive - QString str = QString::fromUtf8( buf, len ); - m_outp.append( str ); + for (int i = 0; i < len; i++ ) { + printf("%c", buf[i] ); + } + printf("\n"); + QByteArray ar( len ); + memcpy( ar.data(), buf, len ); + qWarning("parsed: %s", ar.data() ); + m_outp.append( ar ); } @@ -118,2 +127,9 @@ void Obex::received() { 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 ); diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp index d5ebd81..0da57ca 100644 --- a/core/obex/obexsend.cpp +++ b/core/obex/obexsend.cpp @@ -5,2 +5,3 @@ #include <qtimer.h> +#include <qtl.h> @@ -61,4 +62,4 @@ void SendWidget::initUI() { lay->addWidget( m_devBox, 50 ); - connect(m_devBox, SIGNAL(selectedDevice(const QString&, int ) ), - this, SLOT(slotSelectedDevice(const QString&, int) ) ); + connect(m_devBox, SIGNAL(selectedDevice(int, int ) ), + this, SLOT(slotSelectedDevice(int, int) ) ); @@ -88,12 +89,12 @@ void SendWidget::send( const QString& file, const QString& desc ) { if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) { - m_devBox->addDevice( tr("IrDa is not enabled!"), DeviceBox::Error ); + m_irDeSearch = m_devBox->addDevice( tr("IrDa is not enabled!"), DeviceBox::Error ); m_start++; }else - m_devBox->addDevice( tr("Searching for IrDa Devices."), DeviceBox::Search ); + m_irDeSearch = m_devBox->addDevice( tr("Searching for IrDa Devices."), DeviceBox::Search ); if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) { - m_devBox->addDevice( tr("Bluetooth is not available"), DeviceBox::Error ); + m_btDeSearch = m_devBox->addDevice( tr("Bluetooth is not available"), DeviceBox::Error ); m_start++; }else - m_devBox->addDevice( tr("Searching for bluetooth Devices."), DeviceBox::Search ); + m_btDeSearch = m_devBox->addDevice( tr("Searching for bluetooth Devices."), DeviceBox::Search ); @@ -108,8 +109,8 @@ void SendWidget::slotIrDaDevices( const QStringList& list) { qWarning("slot it irda devices "); - m_irDa = list; - m_start = 0; - for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) - m_devBox->addDevice( (*it), DeviceBox::IrDa, tr("Scheduling for beam.") ); - - m_devBox->removeDevice( tr("Searching for IrDa Devices.") ); + 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(); @@ -117,14 +118,15 @@ void SendWidget::slotIrDaDevices( const QStringList& list) { } + void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) { - m_bt = str; for(QMap<QString, QString>::ConstIterator it = str.begin(); it != str.end(); ++it ) { - m_devBox->addDevice( it.key(), DeviceBox::BT, tr("Click to beam") ); + 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( tr("Searching for bluetooth Devices.") ); + m_devBox->removeDevice( m_btDeSearch ); } -void SendWidget::slotSelectedDevice( const QString& name, int dev ) { - qWarning("Start beam? %s %d", name.latin1(), dev ); - if ( name == tr("Search again for IrDa.") ) { - for (QStringList::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it ) - m_devBox->removeDevice( (*it) ); +void SendWidget::slotSelectedDevice( int name, int dev ) { + qWarning("Start beam? %d %d", name, dev ); + if ( name == m_irDeSearch ) { + for (QMap<int, QString>::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it ) + m_devBox->removeDevice( it.key() ); @@ -142,3 +144,3 @@ void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) { } -void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) { +void SendWidget::dispatchBt( const QCString&, const QByteArray& ) { @@ -151,4 +153,4 @@ void SendWidget::slotIrSent( bool b) { QString text = b ? tr("Sent") : tr("Failure"); -// m_devBox->setStatus( m_irDa[m_start], text ); - m_start++; + m_devBox->setStatus( m_irDaIt.key(), text ); + ++m_irDaIt; slotStartIrda(); @@ -156,10 +158,10 @@ void SendWidget::slotIrSent( bool b) { void SendWidget::slotIrTry(unsigned int trI) { -// m_devBox->setStatus( m_irDa[m_start], tr("Try %1").arg( QString::number( trI ) ) ); + m_devBox->setStatus( m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) ) ); } void SendWidget::slotStartIrda() { - if (m_start >= m_irDa.count() ) { - m_devBox->addDevice(tr("Search again for IrDa."), DeviceBox::Search ); + if (m_irDaIt == m_irDa.end() ) { + m_irDeSearch = m_devBox->addDevice(tr("Search again for IrDa."), DeviceBox::Search ); return; } -// m_devBox->setStatus( m_irDa[m_start], tr("Start sending") ); + m_devBox->setStatus( m_irDaIt.key(), tr("Start sending") ); m_obex->send( m_file ); @@ -181,35 +183,66 @@ DeviceBox::~DeviceBox() { } -void DeviceBox::addDevice( const QString& name, int dev, const QString& status ) { - QString tex; - DeviceItem item( name, status, dev ); - m_dev.insert( name, item ); - tex = item.toString(); - m_devices.prepend(tex); - setText( text()+ "<br>"+tex ); -} -void DeviceBox::removeDevice( const QString& name ) { - if (!m_dev.contains(name) ) return; - m_devices.remove( m_dev[name].toString() ); +int DeviceBox::addDevice( const QString& name, int dev, const QString& status ) { + /* return a id for a range of devices */ + int id = idFor ( dev ); + DeviceItem item( name, status, dev,id ); + m_dev.insert( id, item ); + setText( allText() ); - m_dev.remove(name); - setText( m_devices.join("<br>") ); + return id; +} +void DeviceBox::removeDevice( int id ) { + if (!m_dev.contains(id) ) return; + m_dev.remove( id ); + setText( allText() ); } -void DeviceBox::setStatus( const QString& name, const QString& status ) { - if ( !m_dev.contains(name) ) return; - DeviceItem dev = m_dev[name]; - QString ole = dev.toString(); - dev.setStatus( status ); - int index = m_devices.findIndex( ole ); - m_devices[index] = dev.toString(); - setText( m_devices.join("<br>") ); +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 ) { - qWarning("SetSource:%s", str.latin1() ); - emit selectedDevice( str, m_dev[str].device() ); + qWarning("SetSource:%d", str.toInt() ); + 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: + ret = irId; + irId++; + break; + case BT: + ret = irBT; + irBT++; + break; + case Search: + ret = irSr; + irSr++; + break; + case Error: + ret = irEr; + irEr++; + break; + } + return ret; } +QString DeviceBox::allText() { + QString str; + typedef QMap<int, DeviceItem> DeviceMap; + for (QMap<int, DeviceItem>::Iterator it = m_dev.begin(); it != m_dev.end(); ++it ) { + str += it.data().toString() + "<br>"; + } + return str; +} DeviceItem::DeviceItem( const QString& name, - const QString& status, int dev) + const QString& status, int dev, int id) { @@ -218,2 +251,6 @@ DeviceItem::DeviceItem( const QString& name, m_dev = dev; + m_id = id; +} +int DeviceItem::id()const { + return m_id; } @@ -252,3 +289,3 @@ void DeviceItem::setStatus(const QString& status ) { QString DeviceItem::toString()const { - return "<p><a href=\""+m_name +"\" ><img src=\""+pixmap()+"\" >"+m_name+" "+m_status+" </a></p>" ; + return "<p><a href=\""+QString::number(m_id) +"\" ><img src=\""+pixmap()+"\" >"+m_name+" "+m_status+" </a></p>" ; } diff --git a/core/obex/obexsend.h b/core/obex/obexsend.h index fd819bc..02100f7 100644 --- a/core/obex/obexsend.h +++ b/core/obex/obexsend.h @@ -21,2 +21,14 @@ namespace OpieObex { class Obex; + + struct Pair { + Pair(const QString& first = QString::null, + const QString& second = QString::null) + : m_first(first), m_second(second ) { + } + QString first()const{ return m_first; } + QString second()const { return m_second; } + private: + QString m_first; + QString m_second; + }; class SendWidget : public QWidget{ @@ -40,3 +52,3 @@ namespace OpieObex { void slotBTDevices( const QMap<QString, QString>& ); - void slotSelectedDevice( const QString& name, int dev ); + void slotSelectedDevice( int id, int dev ); void dispatchIrda( const QCString& str, const QByteArray& ar ); @@ -55,6 +67,9 @@ namespace OpieObex { int m_start; - QStringList m_irDa; - QMap<QString, QString> m_bt; + QMap<int, QString> m_irDa; + QMap<int, QString>::Iterator m_irDaIt; + QMap<int, Pair > m_bt; QString m_file; Obex* m_obex; + int m_irDeSearch; // search of irda and bt devices + int m_btDeSearch; }; @@ -63,3 +78,3 @@ namespace OpieObex { DeviceItem( const QString& name = QString::null, - const QString& status = QString::null, int dev = 3); + const QString& status = QString::null, int dev = 3, int id = -1); ~DeviceItem(); @@ -71,2 +86,3 @@ namespace OpieObex { int device()const; + int id()const; QString toString()const; @@ -76,3 +92,9 @@ namespace OpieObex { int m_dev; + int m_id; }; + + /* + * The text field which contains the information about sending... + * + */ class DeviceBox : public QTextBrowser { @@ -85,12 +107,13 @@ namespace OpieObex { void setSource( const QString& str ); - void addDevice( const QString& name, int dev, - const QString& status = QString::null ); - void removeDevice( const QString& name ); - void setStatus( const QString& name, const QString& ); + int addDevice( const QString& name, int dev, + const QString& status = QString::null ); + void removeDevice( int ); + void setStatus( int, const QString& ); signals: - void selectedDevice( const QString& name, int dev ); + void selectedDevice( int id, int dev ); private: - QMap<QString, DeviceItem> m_dev; - QStringList m_devices; - + /* returns a id for a device from a device range */ + int idFor (int deviceType ); + QString allText(); + QMap<int, DeviceItem> m_dev; }; |