summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/manager/bluebase.cpp
Side-by-side diff
Diffstat (limited to 'noncore/net/opietooth/manager/bluebase.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/opietooth/manager/bluebase.cpp84
1 files changed, 53 insertions, 31 deletions
diff --git a/noncore/net/opietooth/manager/bluebase.cpp b/noncore/net/opietooth/manager/bluebase.cpp
index 3f2f138..598ce16 100644
--- a/noncore/net/opietooth/manager/bluebase.cpp
+++ b/noncore/net/opietooth/manager/bluebase.cpp
@@ -16,12 +16,14 @@
***************************************************************************/
#include "bluebase.h"
#include "scandialog.h"
#include "hciconfwrapper.h"
+#include <stdlib.h>
+
#include <qframe.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qvariant.h>
#include <qwhatsthis.h>
@@ -41,12 +43,13 @@
#include <qpe/resource.h>
#include <qpe/config.h>
#include <remotedevice.h>
#include <services.h>
+#include "devicehandler.h"
#include "btconnectionitem.h"
using namespace OpieTooth;
BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl )
: BluetoothBase( parent, name, fl ) {
@@ -63,14 +66,14 @@ using namespace OpieTooth;
connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ),
this, SLOT(startServiceActionHold( QListViewItem *, const QPoint &, int) ) );
connect( m_localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ),
this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) );
connect( m_localDevice, SIGNAL( available( const QString&, bool ) ),
this, SLOT( deviceActive( const QString& , bool ) ) );
- connect( m_localDevice, SIGNAL( connections( Connection::ValueList ) ),
- this, SLOT( addConnectedDevices( Connection::ValueList ) ) );
+ connect( m_localDevice, SIGNAL( connections( ConnectionState::ValueList ) ),
+ this, SLOT( addConnectedDevices( ConnectionState::ValueList ) ) );
//Load all icons needed
m_offPix = Resource::loadPixmap( "editdelete" );
m_onPix = Resource::loadPixmap( "installed" );
QPalette pal = this->palette();
@@ -100,12 +103,13 @@ using namespace OpieTooth;
(void) new BTServiceItem( topLV2, s1 );
writeToHciConfig();
// search conncetions
addConnectedDevices();
m_iconLoader = new BTIconLoader();
+ readSavedDevices();
}
/**
* Reads all options from the config file
*/
void BlueBase::readConfig() {
@@ -137,77 +141,66 @@ using namespace OpieTooth;
cfg.writeEntry( "enableInquiryscan" , m_enableInquiryscan );
writeToHciConfig();
}
void BlueBase::writeToHciConfig() {
-
- HciConfWrapper hciconf ( "/tmp/hcid.conf" );
+ qWarning("writeToHciConfig");
+ HciConfWrapper hciconf ( "/etc/bluetooth/hcid.conf" );
+ hciconf.load();
hciconf.setPinHelper( "/bin/QtPalmtop/bin/blue-pin" );
// hciconf->setPinHelper( "/bin/QtPalmtop/bin/blue-pin" );
hciconf.setName( m_deviceName );
hciconf.setEncrypt( m_useEncryption );
hciconf.setAuth( m_enableAuthentification );
hciconf.setPscan( m_enablePagescan );
hciconf.setIscan( m_enableInquiryscan );
+ hciconf.save();
}
/**
* Read the list of allready known devices
*
*/
void BlueBase::readSavedDevices() {
QValueList<RemoteDevice> loadedDevices;
+ DeviceHandler handler;
+ loadedDevices = handler.load();
- QDir deviceListSave( QDir::homeDirPath() + "/Settings/bluetooth/");
- // list of .conf files
- QStringList devicesFileList = deviceListSave.entryList();
-
- // cut .conf of to get the mac and also read the name entry in it.
-
- for ( QStringList::Iterator it = devicesFileList.begin(); it != devicesFileList.end(); ++it ) {
-
- QString name;
- QString mac;
- qDebug((*it).latin1() );
- Config conf((*it));
- conf.setGroup("Info");
- name = conf.readEntry("name", "Error");
- qDebug("MAC: " + mac);
- qDebug("NAME: " + name);
- RemoteDevice currentDevice( mac , name );
- loadedDevices.append( currentDevice );
- }
addSearchedDevices( loadedDevices );
}
/**
* Write the list of allready known devices
*
*/
void BlueBase::writeSavedDevices() {
QListViewItemIterator it( ListView2 );
BTListItem* item;
BTDeviceItem* device;
-
+ RemoteDevice::ValueList list;
for ( ; it.current(); ++it ) {
item = (BTListItem*)it.current();
if(item->typeId() != BTListItem::Device )
continue;
device = (BTDeviceItem*)item;
- // seperate config file for each device, to store more information in future.
- qDebug( "/Settings/bluetooth/" + device->mac() + ".conf");
- Config conf( QDir::homeDirPath() + "/Settings/bluetooth/" + device->mac() + ".conf", Config::File );
- conf.setGroup( "Info" );
- conf.writeEntry( "name", device->name() );
+
+ list.append( device->remoteDevice() );
}
+ /*
+ * if not empty save the List through DeviceHandler
+ */
+ if ( list.isEmpty() )
+ return;
+ DeviceHandler handler;
+ handler.save( list );
}
/**
* Set up the gui
*/
@@ -260,12 +253,15 @@ using namespace OpieTooth;
void BlueBase::addSearchedDevices( const QValueList<RemoteDevice> &newDevices ) {
BTDeviceItem * deviceItem;
QValueList<RemoteDevice>::ConstIterator it;
for( it = newDevices.begin(); it != newDevices.end() ; ++it ) {
+ if (find( (*it) )) // is already inserted
+ continue;
+
deviceItem = new BTDeviceItem( ListView2 , (*it) );
deviceItem->setExpandable ( true );
// look if device is avail. atm, async
deviceActive( (*it) );
@@ -330,16 +326,20 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin
*/
else if ( ((BTListItem*)item)->type() == "service") {
BTServiceItem* service = (BTServiceItem*)item;
QMap<int, QString> list = service->services().classIdList();
QMap<int, QString>::Iterator it = list.begin();
QPopupMenu *popup =0l;
- if ( it != list.end() )
+ if ( it != list.end() ) {
+ qWarning("Searching id %d %s", it.key(), it.data().latin1() );
popup = m_popHelper.find( it.key(),
service->services(),
service->parent() );
+ }else {
+ qWarning("Empty");
+ }
if ( popup == 0l ) {
qWarning("factory returned 0l");
popup = new QPopupMenu();
}
@@ -402,15 +402,16 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin
QMap<int, QString> list;
QMap<int, QString>::Iterator classIt;
for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) {
serviceItem = new BTServiceItem( deviceItem , (*it2) );
list = (*it2).classIdList();
classIt = list.begin();
- int classId;
+ int classId=0;
if ( classIt != list.end() )
classId = classIt.key();
+
serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) );
}
} else {
Services s1;
s1.setServiceName( tr("no serives found") );
serviceItem = new BTServiceItem( deviceItem, s1 );
@@ -507,6 +508,27 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin
*/
BlueBase::~BlueBase() {
writeSavedDevices();
delete m_iconLoader;
}
+/**
+ * find searches the ListView for a BTDeviceItem containig
+ * the same Device if found return true else false
+ * @param dev RemoteDevice to find
+ * @return returns true if found
+ */
+bool BlueBase::find( const RemoteDevice& rem ) {
+ QListViewItemIterator it( ListView2 );
+ BTListItem* item;
+ BTDeviceItem* device;
+ for (; it.current(); ++it ) {
+ item = (BTListItem*) it.current();
+ if ( item->typeId() != BTListItem::Device )
+ continue;
+
+ device = (BTDeviceItem*)item;
+ if ( rem.equals( device->remoteDevice() ) )
+ return true;
+ }
+ return false; // not found
+}