summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-08-21 22:29:07 (UTC)
committer mickeyl <mickeyl>2005-08-21 22:29:07 (UTC)
commit4def5629dc68465b1dc8bb23c115e2f5f7513804 (patch) (side-by-side diff)
treec2a31fb9e46a3a3e7f797ef3fe0ea66b2f0b69df
parent7f931999d32be3fc90b451347dfec52643d8eeb8 (diff)
downloadopie-4def5629dc68465b1dc8bb23c115e2f5f7513804.zip
opie-4def5629dc68465b1dc8bb23c115e2f5f7513804.tar.gz
opie-4def5629dc68465b1dc8bb23c115e2f5f7513804.tar.bz2
Add some simple interfaces for device scanning (scanning for
discoverable receivers) to support OBEX Send, and requests for taking BT up or down. Patch courtesy Michael Haynie - thanks!
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/applet/bluezapplet.cpp51
-rw-r--r--noncore/net/opietooth/applet/bluezapplet.h5
2 files changed, 56 insertions, 0 deletions
diff --git a/noncore/net/opietooth/applet/bluezapplet.cpp b/noncore/net/opietooth/applet/bluezapplet.cpp
index 8925803..48698b6 100644
--- a/noncore/net/opietooth/applet/bluezapplet.cpp
+++ b/noncore/net/opietooth/applet/bluezapplet.cpp
@@ -42,106 +42,157 @@ 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>
/* STD */
#include <device.h>
namespace OpieTooth {
BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) {
setFixedHeight( AppLnk::smallIconSize() );
setFixedWidth( AppLnk::smallIconSize() );
bluezOnPixmap = Resource::loadImage( "bluetoothapplet/bluezon" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
bluezOffPixmap = Resource::loadImage( "bluetoothapplet/bluezoff" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
//bluezDiscoveryOnPixmap = Resource::loadImage( "bluetoothapplet/magglass" )smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize());
startTimer(4000);
btDevice = 0;
+ btManager = 0;
bluezactive = false;
bluezDiscoveryActive = 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&) ) );
}
BluezApplet::~BluezApplet() {
if ( btDevice ) {
delete btDevice;
}
+ if ( btManager ) {
+ delete btManager;
+ }
}
int BluezApplet::position()
{
return 6;
}
bool BluezApplet::checkBluezStatus() {
if (btDevice) {
if (btDevice->isLoaded() ) {
return true;
} else {
return false;
}
} else {
return false;
}
}
int BluezApplet::setBluezStatus(int c) {
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;
default:
btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" );
break;
}
} else {
if ( btDevice ) {
delete btDevice;
btDevice = 0;
}
}
return 0;
}
int BluezApplet::checkBluezDiscoveryStatus() {
+ return bluezDiscoveryActive;
}
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()") {
+ if (!checkBluezStatus()) {
+ setBluezStatus(1);
+ }
+ } else if ( str == "disableBluetooth()") {
+ if (checkBluezStatus()) {
+ // setBluezStatus(0);
+ }
+ } else if ( str == "listDevices()") {
+ if (!btManager)
+ {
+ btManager = new Manager("hci0");
+ connect( btManager, SIGNAL( foundDevices(const QString&,RemoteDevice::ValueList) ),
+ this, SLOT( fillList(const QString&,RemoteDevice::ValueList) ) ) ;
+ }
+
+ btManager->searchDevices();
+ }
+ }
+
+ // Once the hcitool scan is complete, report back.
+ void BluezApplet::fillList(const QString&, RemoteDevice::ValueList deviceList)
+ {
+ QCopEnvelope e("QPE/BluetoothBack", "devices(QStringMap)");
+
+ QStringList list;
+ QMap<QString, QString> btmap;
+
+ RemoteDevice::ValueList::Iterator it;
+ for( it = deviceList.begin(); it != deviceList.end(); ++it )
+ {
+ btmap[(*it).name()] = (*it).mac();
+ }
+
+ e << btmap;
}
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);
diff --git a/noncore/net/opietooth/applet/bluezapplet.h b/noncore/net/opietooth/applet/bluezapplet.h
index a394e38..3b99c0f 100644
--- a/noncore/net/opietooth/applet/bluezapplet.h
+++ b/noncore/net/opietooth/applet/bluezapplet.h
@@ -11,64 +11,69 @@
    .%+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>
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 checkBluezDiscoveryStatus();
int setBluezDiscoveryStatus(int);
private:
Device* btDevice;
+ Manager *btManager;
QPixmap bluezOnPixmap;
QPixmap bluezOffPixmap;
QPixmap bluezDiscoveryOnPixmap;
bool bluezactive;
bool bluezDiscoveryActive;
private slots:
+ void slotMessage( const QCString& , const QByteArray& );
};
};
#endif