author | korovkin <korovkin> | 2006-05-10 13:32:46 (UTC) |
---|---|---|
committer | korovkin <korovkin> | 2006-05-10 13:32:46 (UTC) |
commit | 5521b2c0508cf6e6a390bd4796e8c9f2c7a6d05f (patch) (side-by-side diff) | |
tree | e9ea63a2fe15982e98886af727649dc6a513faac | |
parent | 620d55ae3b94fa8d2fa696b6626893e4520c3a02 (diff) | |
download | opie-5521b2c0508cf6e6a390bd4796e8c9f2c7a6d05f.zip opie-5521b2c0508cf6e6a390bd4796e8c9f2c7a6d05f.tar.gz opie-5521b2c0508cf6e6a390bd4796e8c9f2c7a6d05f.tar.bz2 |
OBEX push functionality moved to libbluetooth1.
Made some reformatting in device.cc
In bluezapplet.cpp /etc/init.d/bluetooth is started synchronously if it's called from QCopMessage.
-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.cpp | 12 | ||||
-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.h | 2 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/device.cc | 108 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/lib.pro | 7 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/obexpush.cpp | 108 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/obexpush.h | 77 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/obexdialog.cpp | 68 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/obexdialog.h | 15 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/obexftpdialog.cpp | 2 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/obexpopup.cpp | 8 |
10 files changed, 289 insertions, 118 deletions
diff --git a/noncore/net/opietooth/applet/bluezapplet.cpp b/noncore/net/opietooth/applet/bluezapplet.cpp index 90b0c6d..6351d4e 100644 --- a/noncore/net/opietooth/applet/bluezapplet.cpp +++ b/noncore/net/opietooth/applet/bluezapplet.cpp @@ -1,340 +1,344 @@ /* =. This file is part of the OPIE Project .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de> .>+-= _;:, .> :=|. This library is free software; you can .> <, > . <= redistribute it and/or modify it under :=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; version 2 of the License. ._= =} : .%+i> _;_. .i_,=:_. -<s. This library is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=| MERCHANTABILITY or FITNESS FOR A _.=:. : :=>: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. . .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-= this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "bluezapplet.h" /* OPIE */ #include <opie2/otaskbarapplet.h> #include <opie2/odevice.h> #include <opie2/odebug.h> #include <opie2/oresource.h> #include <opie2/oprocess.h> #include <qpe/applnk.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/config.h> using namespace Opie::Core; /* QT */ #include <qapplication.h> #include <qpoint.h> #include <qpainter.h> #include <qlayout.h> #include <qframe.h> #include <qpixmap.h> #include <qstring.h> #include <qtimer.h> #include <qpopupmenu.h> #include <qmessagebox.h> /* STD */ #include <device.h> #define OPIE120 // undefine it fo the latest OPIE namespace OpieTooth { BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { setFixedHeight( AppLnk::smallIconSize() ); setFixedWidth( AppLnk::smallIconSize() ); #ifdef OPIE120 bluezOnPixmap = Resource::loadPixmap( "bluetoothapplet/bluezon" ); bluezOffPixmap = Resource::loadPixmap( "bluetoothapplet/bluezoff" ); bluezDiscoveryOnPixmap = Resource::loadPixmap( "bluetoothapplet/magglass.png" ); #else bluezOnPixmap = OResource::loadImage( "bluetoothapplet/bluezon", OResource::SmallIcon ); bluezOffPixmap = OResource::loadImage( "bluetoothapplet/bluezoff", Opie::Core::OResource::SmallIcon ); bluezDiscoveryOnPixmap = OResource::loadImage( "bluetoothapplet/bluezondiscovery", Opie::Core::OResource::SmallIcon ); #endif startTimer(2000); btDevice = 0; btManager = 0; bluezactive = false; bluezDiscoveryActive = false; doListDevice = false; isScanning = false; m_wasOn = false; // TODO: determine whether this channel has to be closed at destruction time. QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this ); connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), this, SLOT(slotMessage(const QCString&,const QByteArray&) ) ); ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); } BluezApplet::~BluezApplet() { if ( btDevice ) { delete btDevice; } if ( btManager ) { delete btManager; } } int BluezApplet::position() { return 6; } bool BluezApplet::checkBluezStatus() { if (btDevice) { if (btDevice->isLoaded() ) { odebug << "btDevice isLoaded" << oendl; return true; } else { odebug << "btDevice is NOT loaded" << oendl; return false; } } else { odebug << "btDevice is ZERO" << oendl; return false; } } - int BluezApplet::setBluezStatus(int c) { + int BluezApplet::setBluezStatus(int c, bool sync) { if ( c == 1 ) { switch ( ODevice::inst()->model() ) { case Model_iPAQ_H39xx: btDevice = new Device( "/dev/tts/1", "bcsp", "921600" ); break; case Model_iPAQ_H5xxx: btDevice = new Device( "/dev/tts/1", "any", "921600" ); break; #ifndef OPIE120 case Model_MyPal_716: btDevice = new Device( "/dev/ttyS1", "bcsp", "921600" ); break; #endif default: btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" ); break; } - QCopEnvelope e("QPE/System", "execute(QString)"); - e << QString("/etc/init.d/bluetooth start"); + if (sync) { + ::system("/etc/init.d/bluetooth start >/dev/null 2>/dev/null"); + } else { + QCopEnvelope e("QPE/System", "execute(QString)"); + e << QString("/etc/init.d/bluetooth start"); + } } else { ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); if ( btManager ) { delete btManager; btManager = 0; } if ( btDevice ) { delete btDevice; btDevice = 0; } } return 0; } int BluezApplet::checkBluezDiscoveryStatus() { return isScanning; } int BluezApplet::setBluezDiscoveryStatus(int d) { return bluezDiscoveryActive = d; } // FIXME mbhaynie // receiver for QCopChannel("QPE/Bluetooth") messages. void BluezApplet::slotMessage( const QCString& str, const QByteArray& ) { if ( str == "enableBluetooth()") { m_wasOn = checkBluezStatus(); if (!m_wasOn) { - setBluezStatus(1); + setBluezStatus(1, true); sleep(2); } } else if ( str == "disableBluetooth()") { /* * We can down BT only if it was started by qcop. We don't want * to down BT started from menu an break our networking connection */ if (checkBluezStatus() && !m_wasOn) setBluezStatus(0); doListDevice = false; } else if ( str == "listDevices()") { if (checkBluezStatus()) { doListDevice = false; timerEvent(0); if (!btManager) { btManager = new Manager("hci0"); connect( btManager, SIGNAL( foundDevices(const QString&, RemoteDevice::ValueList) ), this, SLOT( fillList(const QString&, RemoteDevice::ValueList) ) ) ; } btManager->searchDevices(); isScanning = true; } else doListDevice = true; } } // Once the hcitool scan is complete, report back. void BluezApplet::fillList(const QString&, RemoteDevice::ValueList deviceList) { QCopEnvelope e("QPE/BluetoothBack", "devices(QStringMap)"); QMap<QString, QString> btmap; RemoteDevice::ValueList::Iterator it; for( it = deviceList.begin(); it != deviceList.end(); ++it ) btmap[(*it).name()] = (*it).mac(); e << btmap; isScanning = false; timerEvent( 0 ); } void BluezApplet::mousePressEvent( QMouseEvent *) { QPopupMenu *menu = new QPopupMenu(); QPopupMenu *signal = new QPopupMenu(); int ret=0; /* Refresh active state */ timerEvent( 0 ); if (bluezactive) { menu->insertItem( tr("Disable Bluetooth"), 0 ); } else { menu->insertItem( tr("Enable Bluetooth"), 1 ); } menu->insertItem( tr("Launch manager"), 2 ); menu->insertSeparator(6); //menu->insertItem( tr("Signal strength"), signal, 5); //menu->insertSeparator(8); if (bluezDiscoveryActive) { menu->insertItem( tr("Disable discovery"), 3 ); } else { menu->insertItem( tr("Enable discovery"), 4 ); } QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); ret = menu->exec(p, 0); menu->hide(); switch(ret) { case 0: setBluezStatus(0); timerEvent( 0 ); break; case 1: setBluezStatus(1); timerEvent( 0 ); break; case 2: // start bluetoothmanager launchManager(); timerEvent( 0 ); break; case 3: setBluezDiscoveryStatus(0); timerEvent( 0 ); break; case 4: setBluezDiscoveryStatus(1); timerEvent(0 ); break; //case 7: // With table of currently-detected devices. } delete signal; delete menu; } /** * Launches the bluetooth manager */ void BluezApplet::launchManager() { QCopEnvelope e("QPE/System", "execute(QString)"); e << QString("bluetooth-manager"); } /** * Refresh timer * @param the timer event */ void BluezApplet::timerEvent( QTimerEvent * ) { bool oldactive = bluezactive; int olddiscovery = bluezDiscoveryActive; bluezactive = checkBluezStatus(); bluezDiscoveryActive = checkBluezDiscoveryStatus(); if ((bluezactive != oldactive) || (bluezDiscoveryActive != olddiscovery)) update(); if (bluezactive && doListDevice) { const QByteArray arr; slotMessage("listDevices()", arr); } } /** * Implementation of the paint event * @param the QPaintEvent */ void BluezApplet::paintEvent( QPaintEvent* ) { QPainter p(this); odebug << "paint bluetooth pixmap" << oendl; if (bluezactive) { #ifdef OPIE120 p.drawPixmap( 0, -1, bluezOnPixmap ); #else p.drawPixmap( 0, 0, bluezOnPixmap ); #endif } else { #ifdef OPIE120 p.drawPixmap( 0, -1, bluezOffPixmap ); #else p.drawPixmap( 0, 0, bluezOffPixmap ); #endif } if (bluezDiscoveryActive) { p.drawPixmap( 0, 0, bluezDiscoveryOnPixmap ); } } }; EXPORT_OPIE_APPLET_v1( OpieTooth::BluezApplet ) diff --git a/noncore/net/opietooth/applet/bluezapplet.h b/noncore/net/opietooth/applet/bluezapplet.h index 90bee3b..1937934 100644 --- a/noncore/net/opietooth/applet/bluezapplet.h +++ b/noncore/net/opietooth/applet/bluezapplet.h @@ -1,81 +1,81 @@ /* =. This file is part of the OPIE Project .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de> .>+-= _;:, .> :=|. This library is free software; you can .> <, > . <= redistribute it and/or modify it under :=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; version 2 of the License. ._= =} : .%+i> _;_. .i_,=:_. -<s. This library is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=| MERCHANTABILITY or FITNESS FOR A _.=:. : :=>: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. . .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-= this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef __BLUEZAPPLET_H__ #define __BLUEZAPPLET_H__ #include <qwidget.h> #include <qpixmap.h> #include <qtimer.h> #include <manager.h> #include <opie2/oprocess.h> namespace OpieTooth { class Device; class BluezApplet : public QWidget { Q_OBJECT public: BluezApplet( QWidget *parent = 0, const char *name=0 ); ~BluezApplet(); static int position(); protected: void timerEvent(QTimerEvent *te ); public slots: void fillList( const QString& device, RemoteDevice::ValueList list ); private: void mousePressEvent( QMouseEvent * ); void paintEvent( QPaintEvent* ); void launchManager(); bool checkBluezStatus(); - int setBluezStatus(int); + int setBluezStatus(int, bool sync = false); int checkBluezDiscoveryStatus(); int setBluezDiscoveryStatus(int); private: Device* btDevice; Manager *btManager; QPixmap bluezOnPixmap; QPixmap bluezOffPixmap; QPixmap bluezDiscoveryOnPixmap; bool bluezactive; bool bluezDiscoveryActive; bool doListDevice; //If I have to list devices after bringing BT up? bool isScanning; //If I'm scanning devices bool m_wasOn; //If BT was started by menu? private slots: void slotMessage( const QCString& , const QByteArray& ); }; }; #endif diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc index 40acbd2..2f04d46 100644 --- a/noncore/net/opietooth/lib/device.cc +++ b/noncore/net/opietooth/lib/device.cc @@ -1,186 +1,182 @@ #include "device.h" /* OPIE */ #include <opie2/oprocess.h> #include <opie2/odebug.h> #include <opie2/odevice.h> using namespace Opie::Core; /* STD */ #include <signal.h> using namespace OpieTooth; using Opie::Core::OProcess; namespace { - int parsePid( const QCString& par ) - { - int id=0; - QString string( par ); - QStringList list = QStringList::split( '\n', string ); + int parsePid( const QCString& par ) + { + int id = 0; + QString string( par ); + QStringList list = QStringList::split( '\n', string ); - for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) - { - owarn << "parsePID: " << (*it).latin1() << oendl; + for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { + owarn << "parsePID: " << (*it).latin1() << oendl; - // FIXME mbhaynie: Surely there is a better way to skip - // verbosity (E.g. the TI device configuration - // script). Apparently the PID is always on a line by - // itself, or is at least the first word of a line. Does - // QString have somethine like startsWithRegex("[0-9]+")? - if( (*it).startsWith("#") ) continue; - if( (*it).startsWith("TI") ) continue; - if( (*it).startsWith("Loading") ) continue; - if( (*it).startsWith("BTS") ) continue; - if( !(*it).startsWith("CSR") ) - { - id = (*it).toInt(); - break; - } - } - return id; + // FIXME mbhaynie: Surely there is a better way to skip + // verbosity (E.g. the TI device configuration + // script). Apparently the PID is always on a line by + // itself, or is at least the first word of a line. Does + // QString have somethine like startsWithRegex("[0-9]+")? + if( (*it).startsWith("#") ) continue; + if( (*it).startsWith("TI") ) continue; + if( (*it).startsWith("Loading") ) continue; + if( (*it).startsWith("BTS") ) continue; + if( !(*it).startsWith("CSR") ) { + id = (*it).toInt(); + break; + } } + return id; + } } Device::Device(const QString &device, const QString &mode, const QString &speed ) : QObject(0, "device") { owarn << "OpieTooth::Device create" << oendl; m_hci = 0; m_process = 0; m_attached = false; m_device = device; m_mode = mode; m_speed = speed; attach(); } Device::~Device(){ detach(); } // FIXME mbhaynie -- If BT is active, and opie is restarted, this // applet thinks bt is down, and will fail to start it again. Not // sure why. void Device::attach(){ owarn << "attaching " << m_device.latin1() << " " << m_mode.latin1() << " " << m_speed.latin1() << oendl; if(m_process == 0 ){ m_output.resize(0); owarn << "new process to create" << oendl; m_process = new OProcess(); *m_process << "hciattach"; *m_process << "-p"; // FIXME -- this is a hack for an odd hciattach interface. if ( ODevice::inst()->modelString() == "HX4700" ) - { - *m_process << "-S" << "/etc/bluetooth/TIInit_3.2.26.bts" << "/dev/ttyS1" << "texas"; - } + *m_process << "-S" << "/etc/bluetooth/TIInit_3.2.26.bts" << "/dev/ttyS1" << "texas"; else - { - *m_process << m_device << m_mode << m_speed; - } + *m_process << m_device << m_mode << m_speed; connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) ); connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) ); if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ owarn << "Could not start" << oendl; delete m_process; m_process = 0; } - }; + } } void Device::detach(){ delete m_hci; + m_hci = 0; delete m_process; + m_process = 0; // kill the pid we got if(m_attached ){ //kill the pid owarn << "killing" << oendl; - kill(pid, 9); + ::kill(pid, 9); } owarn << "detached" << oendl; } bool Device::isLoaded()const{ return m_attached; } QString Device::devName()const { return QString::fromLatin1("hci0"); }; void Device::slotExited( OProcess* proc) { owarn << "prcess exited" << oendl; if(proc== m_process ){ owarn << "proc == m_process" << oendl; if( m_process->normalExit() ){ // normal exit owarn << "normalExit" << oendl; int ret = m_process->exitStatus(); if( ret == 0 ){ // attached - owarn << "attached" << oendl; - owarn << "Output: " << m_output.data() << oendl; - pid = parsePid( m_output ); - owarn << "Pid = " << pid << oendl; - // now hciconfig hci0 up ( determine hciX FIXME) - // and call hciconfig hci0 up - // FIXME hardcoded to hci0 now :( - m_hci = new OProcess( ); - *m_hci << "hciconfig"; - *m_hci << "hci0 up"; - connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), + owarn << "attached" << oendl; + owarn << "Output: " << m_output.data() << oendl; + pid = parsePid( m_output ); + owarn << "Pid = " << pid << oendl; + // now hciconfig hci0 up ( determine hciX FIXME) + // and call hciconfig hci0 up + // FIXME hardcoded to hci0 now :( + m_hci = new OProcess( ); + *m_hci << "hciconfig"; + *m_hci << "hci0 up"; + connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); - if(!m_hci->start() ){ - owarn << "could not start" << oendl; - m_attached = false; - emit device("hci0", false ); - } + if(!m_hci->start() ){ + owarn << "could not start" << oendl; + m_attached = false; + emit device("hci0", false ); + } }else{ owarn << "crass" << oendl; - m_attached = false; - emit device("hci0", false ); + m_attached = false; + emit device("hci0", false ); } } delete m_process; m_process = 0; }else if(proc== m_hci ){ owarn << "M HCI exited" << oendl; if( m_hci->normalExit() ){ owarn << "normal exit" << oendl; int ret = m_hci->exitStatus(); if( ret == 0 ){ - owarn << "attached really really attached" << oendl; - m_attached = true; - emit device("hci0", true ); + owarn << "attached really really attached" << oendl; + m_attached = true; + emit device("hci0", true ); }else{ - owarn << "failed" << oendl; - emit device("hci0", false ); - m_attached = false; + owarn << "failed" << oendl; + emit device("hci0", false ); + m_attached = false; } }// normal exit delete m_hci; m_hci = 0; } } void Device::slotStdOut(OProcess* proc, char* chars, int len) { owarn << "std out" << oendl; if( len <1 ){ owarn << "len < 1 " << oendl; return; } if(proc == m_process ){ QCString string( chars, len+1 ); // \0 == +1 owarn << "output: " << string.data() << oendl; m_output.append( string.data() ); } } void Device::slotStdErr(OProcess* proc, char* chars, int len) { owarn << "std err" << oendl; slotStdOut( proc, chars, len ); } diff --git a/noncore/net/opietooth/lib/lib.pro b/noncore/net/opietooth/lib/lib.pro index 781bf15..e11af9a 100644 --- a/noncore/net/opietooth/lib/lib.pro +++ b/noncore/net/opietooth/lib/lib.pro @@ -1,12 +1,15 @@ TEMPLATE = lib CONFIG += qte warn_on HEADERS = connection.h parser.h device.h manager.h remotedevice.h services.h \ - startpanconnection.h startdunconnection.h bt-serial.h forwarder.h + startpanconnection.h startdunconnection.h obexpush.h \ + bt-serial.h forwarder.h SOURCES = connection.cpp parser.cc device.cc manager.cc remotedevice.cc services.cc \ - startpanconnection.cpp startdunconnection.cpp bt-serial.c forwarder.cc + startpanconnection.cpp startdunconnection.cpp obexpush.cpp \ + bt-serial.c forwarder.cc + TARGET = opietooth1 INCLUDEPATH += $(OPIEDIR)/include . DESTDIR = $(OPIEDIR)/lib LIBS += -lopiecore2 include( $(OPIEDIR)/include.pro ) diff --git a/noncore/net/opietooth/lib/obexpush.cpp b/noncore/net/opietooth/lib/obexpush.cpp new file mode 100644 index 0000000..e0a4bee --- a/dev/null +++ b/noncore/net/opietooth/lib/obexpush.cpp @@ -0,0 +1,108 @@ +/* $Id$ */ +/* OBEX push functions implementation */ +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#include "obexpush.h" + +#include <qfileinfo.h> +#include <qfile.h> + +#include <opie2/odebug.h> +#include <opie2/odebug.h> + +using namespace Opie::Core; +using namespace OpieTooth; + +ObexPush::ObexPush() +{ + pushProc = new OProcess(); + connect(pushProc, SIGNAL(processExited(Opie::Core::OProcess*)), + this, SLOT(slotPushExited(Opie::Core::OProcess*))); + connect(pushProc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int)), + this, SLOT(slotPushOut(Opie::Core::OProcess*, char*, int))); + connect(pushProc, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int)), + this, SLOT(slotPushErr(Opie::Core::OProcess*, char*, int))); + +} + +ObexPush::~ObexPush() +{ + if (pushProc->isRunning()) + pushProc->kill(); + delete pushProc; + pushProc = NULL; +} + +/** + * Function that sends a file + * @param mac destination device MAC address + * @param port service port number + * @param src source file name + * @param dst destination file name + * @return 0 on success, -1 on error, 1 if sending process is running + */ +int ObexPush::send(QString& mac, int port, QString& src, QString& dst) +{ + QString dev = mac; + QString execName = "ussp-push"; + if (pushProc->isRunning()) + return 1; + pushProc->clearArguments(); + dev += "@"; + dev += QString::number(port); + if (!dst.isEmpty()) + *pushProc << execName << "--timeo 30" << dev + << QFile::encodeName(src) << QFile::encodeName(dst); + else + *pushProc << execName << "--timeo 30" << dev + << QFile::encodeName(src) + << QFile::encodeName(QFileInfo(src).fileName()); + odebug << execName << " " << dev << " " << src << " " + << ((!dst.isEmpty())? dst: QFileInfo(src).fileName()) << oendl; + pushProc->setUseShell(true); + if (!pushProc->start(OProcess::NotifyOnExit, OProcess::All)) + return -1; + else + return 0; +} + +void ObexPush::slotPushExited(Opie::Core::OProcess* proc) +{ + if (pushProc != proc) + return; + odebug << "Process exited" << oendl; + if (pushProc->normalExit()) + emit sendComplete(pushProc->exitStatus()); + else + emit sendError(-1); +} + +/** + * Function makes a notification from slotPushOut and slotPushErr + */ +void ObexPush::notifyInfo(Opie::Core::OProcess* proc, char* buf, int len) +{ + if (proc != pushProc) + return; + QCString str(buf, len); + odebug << str << oendl; + emit status(str); +} + +void ObexPush::slotPushOut(Opie::Core::OProcess* proc, char* buf, int len) +{ + notifyInfo(proc, buf, len); +} + +void ObexPush::slotPushErr(Opie::Core::OProcess* proc, char* buf, int len) +{ + notifyInfo(proc, buf, len); +} + +//eof diff --git a/noncore/net/opietooth/lib/obexpush.h b/noncore/net/opietooth/lib/obexpush.h new file mode 100644 index 0000000..8147643 --- a/dev/null +++ b/noncore/net/opietooth/lib/obexpush.h @@ -0,0 +1,77 @@ +/* $Id$ */ +/* OBEX push functions declarations */ +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#ifndef _OBEXPUSH_H_ +#define _OBEXPUSH_H_ +#include <qobject.h> +#include <qstring.h> +#include "services.h" +#include <opie2/oprocess.h> +namespace OpieTooth { + class ObexPush : public QObject { + Q_OBJECT + public: + /** + * Constructor which creates an object + */ + ObexPush(); + + /** + * Public destructor + */ + ~ObexPush(); + + /** + * Function that sends a file + * @param mac destination device MAC address + * @param port service port number + * @param src source file name + * @param dst destination file name + * @return 0 on success, -1 on error, 1 if sending process is running + */ + int send(QString& mac, int port, QString& src, QString& dst); + + /** + * @return true if it's sending and false otherwise + */ + bool isSending() { return pushProc->isRunning(); } + signals: + /** + * Informs that the sending process has completed + * @param status the finish status + */ + void sendComplete(int); + + /** + * Informs that the sending process has finished with error + * @param status the finish status + */ + void sendError(int); + + /** + * Informs that we have a string status update + * @param str status string + */ + void status(QCString&); + protected slots: + void slotPushOut(Opie::Core::OProcess*, char*, int); + void slotPushErr(Opie::Core::OProcess*, char*, int); + void slotPushExited(Opie::Core::OProcess* proc); + protected: + /** + * Function makes a notification from slotPushOut and slotPushErr + */ + void notifyInfo(Opie::Core::OProcess*, char*, int); + protected: + Opie::Core::OProcess* pushProc; //The push process + }; +}; +#endif +//eof diff --git a/noncore/net/opietooth/manager/obexdialog.cpp b/noncore/net/opietooth/manager/obexdialog.cpp index 8d7b593..4b795b7 100644 --- a/noncore/net/opietooth/manager/obexdialog.cpp +++ b/noncore/net/opietooth/manager/obexdialog.cpp @@ -1,140 +1,122 @@ #include "obexdialog.h" #include <errno.h> #include <qpushbutton.h> #include <qmultilineedit.h> #include <qlineedit.h> #include <qlayout.h> #include <qlabel.h> #include <qfileinfo.h> #include <qpe/resource.h> #include <opie2/oprocess.h> #include <opie2/ofiledialog.h> #include <opie2/odebug.h> using namespace Opie::Core; using namespace OpieTooth; using namespace Opie::Core; using namespace Opie::Ui; using namespace Opie::Core; -ObexDialog::ObexDialog(const QString& device, QWidget* parent, const char* name, bool modal, WFlags fl) +ObexDialog::ObexDialog(const QString& device, int port, + QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog( parent, name, modal, fl ) { if ( !name ) setName( "ObexDialog" ); setCaption( tr( "beam files " ) ) ; m_device = device; + m_port = port; layout = new QVBoxLayout( this ); - obexSend = new OProcess(); + obexSend = new ObexPush(); info = new QLabel( this ); info->setText( tr("Which file should be beamed?") ); statLine = new QLabel(this); statLine->setText( tr("Ready") ); status = new QMultiLineEdit(this); status->setReadOnly(true); cmdLine = new QLineEdit( this ); QPushButton *browserButton; browserButton = new QPushButton( Resource::loadIconSet("fileopen"),"",this,"BrowseButton"); connect( browserButton, SIGNAL(released() ), this , SLOT(browse() ) ); chNameLine = new QLineEdit( this ); sendButton = new QPushButton( this ); sendButton->setText( tr( "Send" ) ); layout->addWidget(info); layout->addWidget(status); layout->addWidget(cmdLine); layout->addWidget(browserButton); layout->addWidget(chNameLine); layout->addWidget(sendButton); layout->addWidget(statLine); connect( sendButton, SIGNAL( clicked() ), this, SLOT( sendData() ) ); - connect(obexSend, SIGNAL(processExited(Opie::Core::OProcess*)), - this, SLOT(slotProcessExited(Opie::Core::OProcess*))); - connect(obexSend, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int)), - this, SLOT(slotPushOut(Opie::Core::OProcess*, char*, int))); - connect(obexSend, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int)), - this, SLOT(slotPushErr(Opie::Core::OProcess*, char*, int))); + connect(obexSend, SIGNAL(sendComplete(int)), + this, SLOT(slotPushComplete(int))); + connect(obexSend, SIGNAL(sendError(int)), + this, SLOT(slotPushError(int))); + connect(obexSend, SIGNAL(status(QCString&)), + this, SLOT(slotPushStatus(QCString&))); } ObexDialog::~ObexDialog() { - if (obexSend->isRunning()) - obexSend->kill(); delete obexSend; obexSend = NULL; } void ObexDialog::browse() { MimeTypes types; QStringList all; all << "*/*"; types.insert("All Files", all ); QString str = OFileDialog::getOpenFileName( 1,"/","", types, 0 ); cmdLine->setText( str ); statLine->setText( tr("Ready") ); } void ObexDialog::sendData() { + int result; //function call result QString fileURL = cmdLine->text(); - QString file = QFileInfo( fileURL ).fileName(); QString modifiedName = chNameLine->text(); - QString execName = "ussp-push"; - - if (obexSend->isRunning()) + result = obexSend->send(m_device, m_port, fileURL, modifiedName); + if (result > 0) return; - obexSend->clearArguments(); - // vom popupmenu beziehen - if ( !modifiedName.isEmpty() ) { - *obexSend << execName << "--timeo 30" << m_device << fileURL << modifiedName; - } else { - *obexSend << execName << "--timeo 30" << m_device << fileURL << file; - } - obexSend->setUseShell(true); - if (!obexSend->start(OProcess::NotifyOnExit, OProcess::All) ) { + else if (result < 0) statLine->setText( tr("Error: couln't start process") ); - } else statLine->setText( tr("Sending") ); } -void ObexDialog::slotPushOut(OProcess*, char* buf, int len) { - QCString str(buf, len); +void ObexDialog::slotPushStatus(QCString& str) { status->append(str); } -void ObexDialog::slotPushErr(OProcess*, char* buf, int len) { - QCString str(buf, len); - status->append(str); +void ObexDialog::slotPushComplete(int result) { + status->append( tr("Finished with result ") ); + status->append( QString::number(result) ); + status->append( tr("\n") ); + odebug << result << oendl; + statLine->setText( tr("Finished: ") + tr(strerror(result)) ); } -void ObexDialog::slotProcessExited(OProcess*) { - if (obexSend == NULL) - return; - if (obexSend->normalExit()) { - status->append( tr("Finished with result ") ); - status->append( QString::number(obexSend->exitStatus()) ); - status->append( tr("\n") ); - odebug << obexSend->exitStatus() << oendl; - statLine->setText( tr("Finished: ") + tr(strerror(obexSend->exitStatus())) ); - } - else { - status->append( tr("Exited abnormally\n") ); - statLine->setText( tr("Exited abnormally") ); - } +void ObexDialog::slotPushError(int) { + status->append( tr("Exited abnormally\n") ); + statLine->setText( tr("Exited abnormally") ); } +//eof diff --git a/noncore/net/opietooth/manager/obexdialog.h b/noncore/net/opietooth/manager/obexdialog.h index 44a26f3..063b7f1 100644 --- a/noncore/net/opietooth/manager/obexdialog.h +++ b/noncore/net/opietooth/manager/obexdialog.h @@ -1,48 +1,51 @@ #ifndef OBEXDIALOG_H #define OBEXDIALOG_H #include <qdialog.h> -#include <opie2/oprocess.h> #include <qlabel.h> #include <qmultilineedit.h> +#include "obexpush.h" class QVBoxLayout; class QPushButton; class QMultiLineEdit; class QLineEdit; namespace Opie {namespace Core {class OProcess;}} namespace OpieTooth { class ObexDialog : public QDialog { Q_OBJECT public: - ObexDialog( const QString& device = 0, QWidget* parent = 0, const char* name = 0, bool modal = TRUE, WFlags fl = 0); + ObexDialog( const QString& device = 0, int port = 0, + QWidget* parent = 0, const char* name = 0, + bool modal = TRUE, WFlags fl = 0); ~ObexDialog(); private slots: void browse(); void sendData(); - void slotPushOut(Opie::Core::OProcess*, char*, int); - void slotPushErr(Opie::Core::OProcess*, char*, int); - void slotProcessExited(Opie::Core::OProcess* proc); + void slotPushStatus(QCString&); + void slotPushComplete(int); + void slotPushError(int); protected: QVBoxLayout* layout; QLineEdit* cmdLine; QLineEdit* chNameLine; QPushButton* sendButton; QLabel* info; QMultiLineEdit* status; QLabel* statLine; private: // Device that is used QString m_device; - Opie::Core::OProcess *obexSend; + int m_port; //Port used + ObexPush* obexSend; }; } #endif diff --git a/noncore/net/opietooth/manager/obexftpdialog.cpp b/noncore/net/opietooth/manager/obexftpdialog.cpp index efb3ff2..2a578ac 100644 --- a/noncore/net/opietooth/manager/obexftpdialog.cpp +++ b/noncore/net/opietooth/manager/obexftpdialog.cpp @@ -54,385 +54,385 @@ static void info_cb(int event, const char *msg, int len, void* data); * device - bluetooth address of the device * port - port to connect to */ ObexFtpDialog::ObexFtpDialog(const QString& device, int port, QWidget* parent, const char* name, bool modal, WFlags fl) : ObexFtpDialogBase(parent, name, modal, fl), m_device(device), m_port(port), curdir("") { client = NULL; nRetries = 3; transport = OBEX_TRANS_BLUETOOTH; use_conn = TRUE; use_path = TRUE; progressStatus = 0; localCurdir = "/"; browseLog->setEdited(FALSE); fileList->setSorting(1); fileList->clear(); fileProgress->setTotalSteps(MAX_PROGRESS); statusBar->clear(); localLayout = new QVBoxLayout(localFs); localLayout->setSpacing( 0 ); localLayout->setMargin( 0 ); destFile = new OFileSelector(localFs, OFileSelector::FileSelector, OFileSelector::ExtendedAll, localCurdir, ""); destFile->setCloseVisible(false); destFile->setNewVisible(false); localLayout->addWidget(destFile); nReries->setValue(nRetries); connect(browseOK, SIGNAL(clicked()), SLOT(slotBrowse())); connect(fileList, SIGNAL(clicked(QListViewItem*)), SLOT(slotCd(QListViewItem*))); connect(getButton, SIGNAL(clicked()), SLOT(getFile())); connect(putButton, SIGNAL(clicked()), SLOT(putFile())); connect(delButton, SIGNAL(clicked()), SLOT(delFile())); connect(destFile, SIGNAL(dirSelected (const QString&)), SLOT(updateDir(const QString&))); connect(saveButton, SIGNAL(clicked()), SLOT(slotSaveLog())); connect(browseButton, SIGNAL(clicked()), SLOT(slotBrowseLog())); } ObexFtpDialog::~ObexFtpDialog() { if (client != NULL) { obexftp_disconnect(client); obexftp_close(client); } } void ObexFtpDialog::slotBrowse() { doBrowse(TRUE); } /* * Do device browsing */ void ObexFtpDialog::doBrowse(bool reconnect) { stat_entry_t* ent; //Directory entry void *dir; //Directory to read const uint8_t* use_uuid; //uuid int len; //uuid length FileListItem* root; //root node int fsize; //file size bool numOk; //true if the string is a number int tmp; //just a temp var status(tr("Connecting to ") + m_device); odebug << "Browse device " << m_device << oendl; browseLog->clear(); fileList->clear(); progressStatus = 0; fileProgress->setTotalSteps(MAX_PROGRESS); fileProgress->reset(); //Get parameters tmp = nReries->text().toInt(&numOk); if (numOk) nRetries = tmp; if (uuidType->currentText() == "FBS") { use_uuid = UUID_FBS; len = sizeof(UUID_FBS); } else if (uuidType->currentText() == "S45") { use_uuid = UUID_S45; len = sizeof(UUID_S45); } else { use_uuid = UUID_FBS; len = sizeof(UUID_FBS); } if (!cli_connect_uuid(use_uuid, len, reconnect)) { log(tr("Connection failed: ") + tr(strerror(errno))); errBox("Connection failed"); status("Connection failed"); return; } else { log(QString("Connected to ") + m_device); status(QString("Connected to ") + m_device); } /* List folder */ root = new FileListItem(fileList, NULL); dir = obexftp_opendir(client, curdir); while ((ent = obexftp_readdir(dir)) != NULL) { FileListItem* a; //List view item if (ent->mode != 16877) { fsize = ent->size; } else fsize = 0; log(QString(ent->name) + QString(" ") + QString::number(ent->mode)); a = new FileListItem(fileList, ent, fsize); } obexftp_closedir(dir); } //Error message box int ObexFtpDialog::errBox(QCString msg) { return QMessageBox::critical(this, tr("ObexFTP error"), msg); } int ObexFtpDialog::errBox(QString msg) { return QMessageBox::critical(this, tr("ObexFTP error"), msg); } int ObexFtpDialog::errBox(const char* msg) { return QMessageBox::critical(this, tr("ObexFTP error"), tr(msg)); } //Text in the status bar void ObexFtpDialog::status(QCString msg) { statusBar->setText(msg); statusBar->repaint(); } void ObexFtpDialog::status(QString msg) { statusBar->setText(msg); statusBar->repaint(); } void ObexFtpDialog::status(const char* msg) { statusBar->setText(msg); statusBar->repaint(); } /* * Change directory with item under the cursor */ void ObexFtpDialog::slotCd(QListViewItem* item) { FileListItem* file = (FileListItem*)item; int idx; if (file == NULL) return; odebug << "Item " << file->text(0) << " clicked" << oendl; if (file->gettype() == IS_DIR) { if (file->text(0) == "../") { if (curdir.right(1) == "/") curdir.remove(curdir.length() - 1, 1); idx = curdir.findRev('/'); if (idx >= 0) curdir.remove(idx, curdir.length() - idx); else curdir = ""; } else { if (curdir != "" && curdir.right(1) != "/") curdir += "/"; curdir += file->text(0); } odebug << "Browse " << curdir << oendl; - if (obexftp_setpath(client, curdir, 0) < 0) + if (obexftp_setpath(client, QFile::encodeName(curdir), 0) < 0) log(tr("CD failed: ") + tr(strerror(errno))); doBrowse(); } } /* * Copy file from a remote device to the local device */ void ObexFtpDialog::getFile() { FileListItem* file = (FileListItem*)fileList->selectedItem(); int result; if (file == NULL) return; file2get = "/"; local = localCurdir; if (local == "") { errBox("Select a destination first"); return; } if (local.right(1) != "/") local += "/"; if (file->gettype() == IS_FILE) { if (client == NULL) { errBox("No connection established"); return; } file2get += curdir; if (curdir != "" && curdir.right(1) != "/") file2get += "/"; file2get += file->text(0); local += file->text(0); odebug << "Copy " << file2get << " to " << local << oendl; progressStatus = 0; fileProgress->setTotalSteps(file->getsize() / 1024); fileProgress->reset(); status(tr("Receiving file ") + file2get); result = obexftp_get(client, local, file2get); if (result < 0) { log(file2get + QString(" receive ERROR:\n") + tr(strerror(errno))); errBox(file2get + QString(" receive ERROR")); status(file2get + QString(" receive ERROR")); } else { log(file2get + QString(" received")); status(file2get + QString(" received")); destFile->reread(); } } } /* * Copy file from the local device to a remote device */ void ObexFtpDialog::putFile() { int result; //OPeration result int idx; //Index of a symbol in the string struct stat localFStat; //Local file information if (client == NULL) { errBox("No connection established"); return; } local = destFile->selectedName(); if (local == "") { errBox("No file slected"); return; } result = stat(local, &localFStat); if (result < 0) { errBox(tr("Wrong file selected ") + local + tr(" ") + tr(strerror(errno))); return; } idx = local.findRev('/'); if (idx > 0) { file2get = local.right(local.length() - idx - 1); } else file2get = local; odebug << "Copy " << local << " to " << file2get << oendl; progressStatus = 0; fileProgress->setTotalSteps(localFStat.st_size / 1024); fileProgress->reset(); status(tr("Sending file ") + local); result = obexftp_put_file(client, local, file2get); if (result < 0) { log(local + QString(" send ERROR:\n") + tr(strerror(errno))); errBox(local + QString(" send ERROR")); status(local + QString(" send ERROR")); } else { doBrowse(); log(local + QString(" sent")); status(local + QString(" sent")); } } /* * Delete file on a remote device */ void ObexFtpDialog::delFile() { FileListItem* file = (FileListItem*)fileList->selectedItem(); int result; if (file == NULL) return; file2get = "/"; if (file->gettype() == IS_FILE) { if (client == NULL) { errBox("No connection established"); return; } file2get += curdir; if (curdir != "" && curdir.right(1) != "/") file2get += "/"; file2get += file->text(0); } result = QMessageBox::warning(this, tr("Remove File"), tr("Do you want to remove\n") + file2get, "Yes", "No"); if (result != 0) return; odebug << "Remove " << file2get << oendl; result = obexftp_del(client, file2get); if (result < 0) { log(file2get + QString(" remove ERROR\n") + tr(strerror(errno))); errBox(file2get + QString(" remove ERROR")); status(file2get + QString(" remove ERROR")); } else { doBrowse(); log(file2get + QString(" removed")); status(file2get + QString(" removed")); } } /* connect with given uuid. re-connect every time */ int ObexFtpDialog::cli_connect_uuid(const uint8_t *uuid, int uuid_len, bool reconnect) { int retry; if (client != NULL) { if (reconnect) { obexftp_disconnect(client); obexftp_close(client); sleep(3); } else return TRUE; } /* Open */ client = obexftp_open (transport, NULL, info_cb, this); if(client == NULL) { errBox("Error opening obexftp-client"); return FALSE; } if (!use_conn) client->quirks &= ~OBEXFTP_CONN_HEADER; if (!use_path) client->quirks &= ~OBEXFTP_SPLIT_SETPATH; for (retry = 0; retry < nRetries; retry++) { /* Connect */ switch (transport) { case OBEX_TRANS_IRDA: if (obexftp_connect_uuid(client, NULL, 0, uuid, uuid_len) >= 0) return TRUE; break; case OBEX_TRANS_BLUETOOTH: if (obexftp_connect_uuid(client, m_device, m_port, uuid, uuid_len) >= 0) return TRUE; break; default: errBox("Transport type unknown"); return FALSE; } log(tr("Still trying to connect")); } client = NULL; return FALSE; } /* * Put a message to the log window */ void ObexFtpDialog::log(QString str) { browseLog->append(str); } diff --git a/noncore/net/opietooth/manager/obexpopup.cpp b/noncore/net/opietooth/manager/obexpopup.cpp index d1d1b4a..759a452 100644 --- a/noncore/net/opietooth/manager/obexpopup.cpp +++ b/noncore/net/opietooth/manager/obexpopup.cpp @@ -1,49 +1,47 @@ #include "obexdialog.h" #include "obexpopup.h" /* OPIE */ #include <qpe/qpeapplication.h> #include <opie2/odebug.h> using namespace Opie::Core; /* QT */ #include <qtimer.h> using namespace OpieTooth; /* * c'tor init the QAction */ ObexPopup::ObexPopup(const OpieTooth::Services& service, OpieTooth::BTDeviceItem* item) : QPopupMenu(), m_service(service) { - owarn << "ObexPopup c'tor" << oendl; + odebug << "ObexPopup c'tor" << oendl; m_item = item; /* connect action */ m_push = new QAction( ); // so it's get deleted m_push->setText("Push file"); m_push->addTo( this ); connect(m_push, SIGNAL(activated()), SLOT(slotPush())); } ObexPopup::~ObexPopup() { delete m_push; } void ObexPopup::slotPush() { QString device = m_item->mac(); int port = m_service.protocolDescriptorList().last().port(); - device += "@"; - device += QString::number(port); - owarn << "push something to " << device << oendl; - ObexDialog obexDialog(device); + odebug << "push something to " << device << " " << port << oendl; + ObexDialog obexDialog(device, port); QPEApplication::execDialog( &obexDialog ); } |