summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/gprs/opie-networksettings2plugin-network.control2
-rw-r--r--noncore/settings/networksettings2/networksettings2/system.cpp53
-rw-r--r--noncore/settings/networksettings2/networksettings2/system.h7
-rw-r--r--noncore/settings/networksettings2/opietooth2/Opietooth.cpp136
-rw-r--r--noncore/settings/networksettings2/opietooth2/Opietooth.h23
-rw-r--r--noncore/settings/networksettings2/opietooth2/libopietooth2.control2
-rw-r--r--noncore/settings/networksettings2/opietooth2/opietooth2.pro4
7 files changed, 185 insertions, 42 deletions
diff --git a/noncore/settings/networksettings2/gprs/opie-networksettings2plugin-network.control b/noncore/settings/networksettings2/gprs/opie-networksettings2plugin-network.control
index 902ebff..7e904bb 100644
--- a/noncore/settings/networksettings2/gprs/opie-networksettings2plugin-network.control
+++ b/noncore/settings/networksettings2/gprs/opie-networksettings2plugin-network.control
@@ -1,9 +1,9 @@
-Package: opie-networksettings2plugin-GPRS
+Package: opie-networksettings2plugin-gprs
Files: plugins/networksettings2/libGPRS.so*
Priority: optional
Section: opie/settings
Maintainer: Wim Delvaux <wimpie@handhelds.org>
Architecture: arm
Depends: opie-networksettings2, libopiecore2, libopienet2
Description: Setup GPRS network
Version: $QPE_VERSION$EXTRAVERSION
diff --git a/noncore/settings/networksettings2/networksettings2/system.cpp b/noncore/settings/networksettings2/networksettings2/system.cpp
index 141484c..9512579 100644
--- a/noncore/settings/networksettings2/networksettings2/system.cpp
+++ b/noncore/settings/networksettings2/networksettings2/system.cpp
@@ -1,573 +1,586 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <opie2/oprocess.h>
#include <qdir.h>
#include <qregexp.h>
#include <qstringlist.h>
#include <qfile.h>
#include <qtextstream.h>
#include <qapplication.h>
#include "resources.h"
#include "system.h"
#define PROCNETDEV "/proc/net/dev"
#ifndef ARPHRD_IEEE80211
#define ARPHRD_IEEE80211 801
#endif
static char Dig2Hex[] = {
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F'
};
// get HIGH nibble of byte
#define HN(x) Dig2Hex[(((x)&0xf0)>>4)]
// get LOW nibble of byte
#define LN(x) Dig2Hex[((x)&0x0f)]
System::System( void ) : QObject(), ProbedInterfaces() {
- probeInterfaces();
}
System::~System( void ) {
if( ProcDevNet )
delete ProcDevNet;
}
-int System::runAsRoot( QStringList & S ) {
+QDict<InterfaceInfo> & System::interfaces( void ) {
+ if( ProbedInterfaces.count() == 0 ) {
+ probeInterfaces();
+ }
+ return ProbedInterfaces;
+}
+
+int System::runAsRoot( QStringList & S, MyProcess * Prc ) {
char * usr = getenv("USER");
if( S.count() == 0 ) {
// loophole to start shell
return 8888;
}
if( usr == 0 || strcmp( usr, "root" ) ) {
// unknown or non-root user -> use SUDO
S.prepend( "sudo" );
}
if( getenv( "NS2TESTMODE" ) ) {
owarn << "TESTMODE !!! execute "
<< S.join( " ")
<< oendl;
} else {
- MyProcess * P = new MyProcess();
- emit processEvent( tr("Command : ") + S.join( " " ) );
+ MyProcess * P;
- P->process() << S;
-
- connect( P,
- SIGNAL( stdoutLine( const QString & ) ),
- this,
- SIGNAL( stdoutLine( const QString & ) ) );
-
- connect( P,
- SIGNAL( stderrLine( const QString & ) ),
- this,
- SIGNAL( stderrLine( const QString & ) ) );
+ if( Prc ) {
+ P = Prc;
+ } else {
+ P = new MyProcess();
+ emit processEvent( tr("Command : ") + S.join( " " ) );
+
+ connect( P,
+ SIGNAL( stdoutLine( const QString & ) ),
+ this,
+ SIGNAL( stdoutLine( const QString & ) ) );
+
+ connect( P,
+ SIGNAL( stderrLine( const QString & ) ),
+ this,
+ SIGNAL( stderrLine( const QString & ) ) );
+
+ connect( P,
+ SIGNAL(processExited(MyProcess*) ),
+ this, SLOT
+ (SLOT_ProcessExited(MyProcess*) ) );
+ }
- connect( P,
- SIGNAL(processExited(MyProcess*) ),
- this, SLOT
- (SLOT_ProcessExited(MyProcess*) ) );
+ P->process() << S;
Log(("Executing %s\n", S.join( " " ).latin1() ));
if( ! P->process().start( OProcess::DontCare,
OProcess::AllOutput ) ) {
owarn << "Error starting " << S << oendl;
- delete P;
+ if( ! Prc )
+ delete P;
// error starting app
return 1;
}
owarn << "Started " << S << oendl;
}
// all is fine
return 0;
}
int System::execAsUser( QStringList & SL ) {
MyProcess * P = new MyProcess();
CurrentQPEUser CU = NSResources->currentUser();
char * usr = getenv("USER");
if( strcmp( usr, "root" ) == 0 ) {
// find user running qpe
if( CU.UserName.isEmpty() ) {
// if we come here, the exec was not successfull
Log(("User not known \n" ));
return 0;
}
}
// now we are ready to exec the requested command
setuid( CU.Uid );
setgid( CU.Gid );
for( unsigned int i = 0 ; i < CU.EnvList.count() ; i ++ ) {
QString X;
QStringList SL;
X = CU.EnvList[i];
SL = QStringList::split( "=", X );
P->process().setEnvironment( SL[0], SL[1] );
}
P->process() << SL;
emit processEvent( tr("Command : ") + SL.join( " " ) );
Log(("Executing as user %s : %s\n",
CU.UserName.latin1(),
SL.join( " " ).latin1() ));
int rv = ( P->process().start( OProcess::DontCare,
OProcess::NoCommunication ) );
delete P;
if( rv ) {
// if we come here, the exec was not successfull
Log(("Could not exec : %d\n", errno ));
}
return rv;
}
void System::SLOT_ProcessExited( MyProcess * P ) {
QString R;
for( QValueListConstIterator<QCString> it = P->process().args().begin();
it != P->process().args().end();
++it ) {
R += (*it);
R += " ";
}
R += "Returned with " + QString().setNum( P->process().exitStatus() );
emit processEvent( R );
delete P;
}
void System::refreshStatistics( InterfaceInfo & I ) {
if( ! ProcDevNet ) {
return;
}
// cannot seek on dev
ProcDevNet->close();
ProcDevNet->open( IO_ReadOnly );
QString line;
QTextStream procTs(ProcDevNet);
QStringList SL;
int loc = -1;
int version;
procTs.readLine();
line = procTs.readLine();
// get version
if( line.find("compressed") )
version = 3;
else if( line.find( "bytes" ) )
version = 2;
else
version = 1;
while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) {
if( (loc = line.find(":") ) == -1) {
continue;
}
if( I.Name != line.left(loc) )
continue;
// tokenize
SL = QStringList::split( ' ', line, FALSE );
// update data
switch( version ) {
case 1 :
I.RcvBytes = SL[1];
I.RcvErrors = SL[3];
I.RcvDropped = SL[4];
I.SndBytes = SL[6];
I.SndErrors = SL[8];
I.SndDropped = SL[9];
I.Collisions = SL[11];
break;
case 2 :
I.RcvBytes = SL[1];
I.RcvErrors = SL[3];
I.RcvDropped = SL[4];
I.SndBytes = SL[7];
I.SndErrors = SL[9];
I.SndDropped = SL[10];
I.Collisions = SL[12];
break;
case 3 :
I.RcvBytes = SL[1];
I.RcvErrors = SL[3];
I.RcvDropped = SL[4];
I.SndBytes = SL[9];
I.SndErrors = SL[11];
I.SndDropped = SL[12];
I.Collisions = SL[14];
break;
}
break;
}
}
//
// THIS UPDATES THE LIST -> INTERFACES ARE NOT DELETED BUT
// FLAGGED AS ! 'IsUp' IF NO LONGER PRESENT
//
void System::probeInterfaces( void ) {
// probe interfaces
int sockfd;
// get list of all interfaces
struct ifreq ifrs;
InterfaceInfo * IFI;
// flag all as 'down'
for( QDictIterator<InterfaceInfo> it( ProbedInterfaces );
it.current();
++it ) {
it.current()->IsUp = 0;
}
sockfd = socket(PF_INET, SOCK_DGRAM, 0);
if(sockfd == -1) {
owarn << "Cannot open INET socket "
<< errno
<< " "
<< strerror( errno )
<< oendl;
return;
}
// read interfaces from /proc/dev/net
// SIOCGIFCONF does not return ALL interfaces ???!?
ProcDevNet = new QFile(PROCNETDEV);
if( ! ProcDevNet->open(IO_ReadOnly) ) {
owarn << "Cannot open "
<< PROCNETDEV
<< " "
<< errno
<< " "
<< strerror( errno )
<< oendl;
delete ProcDevNet;
ProcDevNet =0;
::close( sockfd );
return;
}
QString line;
QString NicName;
QTextStream procTs(ProcDevNet);
int loc = -1;
procTs.readLine(); // eat a line
procTs.readLine(); // eat a line
while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) {
if((loc = line.find(":")) == -1) {
continue;
}
NicName = line.left(loc);
// set name for ioctl
strcpy( ifrs.ifr_name, NicName.latin1() );
if ( ! ( IFI = ProbedInterfaces.find( NicName ) ) ) {
// new nic
Log(("New NIC found : %s\n", NicName.latin1()));
IFI = new InterfaceInfo;
IFI->Name = line.left(loc);
IFI->Collection = 0;
ProbedInterfaces.insert( IFI->Name, IFI );
// get dynamic info
if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) {
IFI->IsPointToPoint = ((ifrs.ifr_flags & IFF_POINTOPOINT) == IFF_POINTOPOINT);
} else {
IFI->IsPointToPoint = 0;
}
// settings that never change
IFI->DstAddress = "";
if( IFI->IsPointToPoint ) {
if( ioctl(sockfd, SIOCGIFDSTADDR, &ifrs) >= 0 ) {
IFI->DstAddress =
inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_dstaddr)->sin_addr);
}
}
IFI->CardType = 999999;
IFI->MACAddress = "";
if( ioctl(sockfd, SIOCGIFHWADDR, &ifrs) >= 0 ) {
Log(("Family for NIC %s : %d\n", IFI->Name.latin1(),
ifrs.ifr_hwaddr.sa_family ));
IFI->CardType = ifrs.ifr_hwaddr.sa_family;
switch( ifrs.ifr_hwaddr.sa_family ) {
case ARPHRD_ETHER : // regular MAC address
// valid address -> convert to regular ::: format
// length = 6 bytes = 12 DIGITS -> 6 :
IFI->MACAddress.sprintf(
"%c%c:%c%c:%c%c:%c%c:%c%c:%c%c",
HN( ifrs.ifr_hwaddr.sa_data[0] ),
LN( ifrs.ifr_hwaddr.sa_data[0] ),
HN( ifrs.ifr_hwaddr.sa_data[1] ),
LN( ifrs.ifr_hwaddr.sa_data[1] ),
HN( ifrs.ifr_hwaddr.sa_data[2] ),
LN( ifrs.ifr_hwaddr.sa_data[2] ),
HN( ifrs.ifr_hwaddr.sa_data[3] ),
LN( ifrs.ifr_hwaddr.sa_data[3] ),
HN( ifrs.ifr_hwaddr.sa_data[4] ),
LN( ifrs.ifr_hwaddr.sa_data[4] ),
HN( ifrs.ifr_hwaddr.sa_data[5] ),
LN( ifrs.ifr_hwaddr.sa_data[5] )
);
break;
#ifdef ARPHRD_IEEE1394
case ARPHRD_IEEE1394 : // Firewire Eth address
IFI->MACAddress.sprintf(
"%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-00-00",
HN( ifrs.ifr_hwaddr.sa_data[0] ),
LN( ifrs.ifr_hwaddr.sa_data[0] ),
HN( ifrs.ifr_hwaddr.sa_data[1] ),
LN( ifrs.ifr_hwaddr.sa_data[1] ),
HN( ifrs.ifr_hwaddr.sa_data[2] ),
LN( ifrs.ifr_hwaddr.sa_data[2] ),
HN( ifrs.ifr_hwaddr.sa_data[3] ),
LN( ifrs.ifr_hwaddr.sa_data[3] ),
HN( ifrs.ifr_hwaddr.sa_data[4] ),
LN( ifrs.ifr_hwaddr.sa_data[4] ),
HN( ifrs.ifr_hwaddr.sa_data[5] ),
LN( ifrs.ifr_hwaddr.sa_data[5] ),
HN( ifrs.ifr_hwaddr.sa_data[6] ),
LN( ifrs.ifr_hwaddr.sa_data[6] ),
HN( ifrs.ifr_hwaddr.sa_data[7] ),
LN( ifrs.ifr_hwaddr.sa_data[7] ),
HN( ifrs.ifr_hwaddr.sa_data[8] ),
LN( ifrs.ifr_hwaddr.sa_data[8] ),
HN( ifrs.ifr_hwaddr.sa_data[9] ),
LN( ifrs.ifr_hwaddr.sa_data[9] ),
HN( ifrs.ifr_hwaddr.sa_data[10] ),
LN( ifrs.ifr_hwaddr.sa_data[10] ),
HN( ifrs.ifr_hwaddr.sa_data[11] ),
LN( ifrs.ifr_hwaddr.sa_data[11] ),
HN( ifrs.ifr_hwaddr.sa_data[12] ),
LN( ifrs.ifr_hwaddr.sa_data[12] ),
HN( ifrs.ifr_hwaddr.sa_data[13] ),
LN( ifrs.ifr_hwaddr.sa_data[13] )
);
break;
#endif
case ARPHRD_PPP : // PPP
break;
case ARPHRD_IEEE80211 : // WLAN
break;
case ARPHRD_IRDA : // IRDA
break;
}
}
} else // else already probed before -> just update
Log(("Redetected NIC %s\n", NicName.latin1()));
// get dynamic info
if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) {
IFI->IsUp = ((ifrs.ifr_flags & IFF_UP) == IFF_UP);
IFI->HasMulticast = ((ifrs.ifr_flags & IFF_MULTICAST) == IFF_MULTICAST);
} else {
IFI->IsUp = 0;
IFI->HasMulticast = 0;
}
if( ioctl(sockfd, SIOCGIFADDR, &ifrs) >= 0 ) {
IFI->Address =
inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_addr)->sin_addr);
} else {
IFI->Address = "";
IFI->IsUp = 0;
}
if( ioctl(sockfd, SIOCGIFBRDADDR, &ifrs) >= 0 ) {
IFI->BCastAddress =
inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_broadaddr)->sin_addr);
} else {
IFI->BCastAddress = "";
}
if( ioctl(sockfd, SIOCGIFNETMASK, &ifrs) >= 0 ) {
IFI->Netmask =
inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_netmask)->sin_addr);
} else {
IFI->Netmask = "";
}
Log(("NIC %s UP ? %d\n", NicName.latin1(), IFI->IsUp ));
}
::close( sockfd );
}
InterfaceInfo * System::findInterface( const QString & N ) {
InterfaceInfo * Run;
// has PAN connection UP interface ?
for( QDictIterator<InterfaceInfo> It(ProbedInterfaces);
It.current();
++It ) {
Run = It.current();
if( N == Run->Name ) {
// this PAN connection is up
return Run;
}
}
return 0;
}
#include <stdarg.h>
static FILE * logf = 0;
void VLog( char * Format, ... ) {
va_list l;
va_start(l, Format );
if( logf == (FILE *)0 ) {
QString S = getenv("NS2LOG");
if( S == "stderr" ) {
logf = stderr;
} else if( S.isEmpty() ) {
logf = fopen( "/tmp/ns2log", "a" );
} else {
logf = fopen( S, "a" );
}
if( ! logf ) {
fprintf( stderr, "Cannot open logfile %s : %d\n",
S.latin1(), errno );
logf = (FILE *)1;
} else {
fprintf( logf, "____ OPEN LOGFILE ____\n");
}
}
if( (unsigned long)logf > 1 ) {
vfprintf( logf, Format, l );
}
va_end( l );
fflush( logf );
}
void LogClose( void ) {
if( (long)logf > 1 ) {
fprintf( logf, "____ CLOSE LOGFILE ____\n");
if( logf != stderr ) {
fclose( logf );
}
logf = 0;
}
}
QString removeSpaces( const QString & X ) {
QString Y;
Y = X.simplifyWhiteSpace();
Y.replace( QRegExp(" "), "_" );
owarn << X << " **" << Y << "**" << oendl;
return Y;
}
//
//
//
//
//
MyProcess::MyProcess() : QObject(), StdoutBuffer(), StderrBuffer() {
P = new OProcess();
connect( P,
SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int ) ),
this,
SLOT( SLOT_Stdout(Opie::Core::OProcess*,char*,int) ) );
connect( P,
SIGNAL( receivedStderr(Opie::Core::OProcess*, char*, int ) ),
this,
SLOT( SLOT_Stderr(Opie::Core::OProcess*,char*,int) ) );
connect( P,
SIGNAL( processExited(Opie::Core::OProcess*) ),
this,
SLOT( SLOT_ProcessExited(Opie::Core::OProcess*) ) );
}
MyProcess::~MyProcess() {
delete P;
}
void MyProcess::SLOT_Stdout( Opie::Core::OProcess * , char * Buf, int len ) {
char * LB = (char *)alloca( len + 1 );
memcpy( LB, Buf, len );
LB[len] = '\0';
// now input is zero terminated
StdoutBuffer += LB;
owarn << "Received " << len << " bytes on stdout" << oendl;
// see if we have some lines (allow empty lines)
QStringList SL = QStringList::split( "\n", StdoutBuffer, TRUE );
for( unsigned int i = 0; i < SL.count()-1; i ++ ) {
Log(( "Stdout : \"%s\"\n", SL[i].latin1() ) );
emit stdoutLine( SL[i] );
}
// last line is rest
StdoutBuffer = SL[ SL.count()-1 ];
}
void MyProcess::SLOT_Stderr( Opie::Core::OProcess * , char * Buf, int len ) {
char * LB = (char *)alloca( len + 1 );
memcpy( LB, Buf, len );
LB[len] = '\0';
// now input is zero terminated
StderrBuffer += LB;
owarn << "Received " << len << " bytes on stderr" << oendl;
// see if we have some lines (allow empty lines)
QStringList SL = QStringList::split( "\n", StderrBuffer, TRUE );
for( unsigned int i = 0; i < SL.count()-1; i ++ ) {
Log(( "Stderr : \"%s\"\n", SL[i].latin1() ) );
emit stderrLine( SL[i] );
}
// last line is rest
StderrBuffer = SL[ SL.count()-1 ];
}
void MyProcess::SLOT_ProcessExited( Opie::Core::OProcess * ) {
emit processExited( this );
}
diff --git a/noncore/settings/networksettings2/networksettings2/system.h b/noncore/settings/networksettings2/networksettings2/system.h
index e67d695..f7a7274 100644
--- a/noncore/settings/networksettings2/networksettings2/system.h
+++ b/noncore/settings/networksettings2/networksettings2/system.h
@@ -1,135 +1,134 @@
#ifndef __SYSTEM__H
#define __SYSTEM__H
#include <qstring.h>
#include <opie2/oprocess.h>
using namespace Opie::Core;
// for hardware types
#include <net/if_arp.h>
#include <qdict.h>
#include <qobject.h>
#include <stdio.h>
class NodeCollection;
class ANetNodeInstance;
class QFile;
class MyProcess : public QObject {
Q_OBJECT
public :
MyProcess();
~MyProcess();
inline OProcess & process()
{ return *P; }
public slots :
void SLOT_Stdout( Opie::Core::OProcess * P, char *, int );
void SLOT_Stderr( Opie::Core::OProcess * P, char *, int );
void SLOT_ProcessExited( Opie::Core::OProcess * P);
signals :
void stdoutLine( const QString & );
void stderrLine( const QString & );
void processExited( MyProcess * );
private :
QString StdoutBuffer;
QString StderrBuffer;
OProcess * P;
};
class InterfaceInfo {
public :
InterfaceInfo() :
Name(),
MACAddress(),
BCastAddress(),
Netmask(),
DstAddress() {
}
NodeCollection * assignedConnection()
{ return Collection; }
void assignConnection( NodeCollection * NNI )
{ Collection = NNI; }
NodeCollection * Collection; // connection taking care of me
QString Name; // name of interface
int CardType; // type of card
QString MACAddress; // MAC address
QString Address; // IP Address
QString BCastAddress; // Broadcast Address
QString Netmask; // Netmask
QString DstAddress; // Peer address (if P-t-P)
bool IsUp; // interface is UP
bool HasMulticast; // Supports Multicast
bool IsPointToPoint; // IsPointToPoint card
QString RcvBytes;
QString SndBytes;
QString RcvErrors;
QString SndErrors;
QString RcvDropped;
QString SndDropped;
QString Collisions;
};
class System : public QObject {
Q_OBJECT
public :
System( void );
~System( void );
- QDict<InterfaceInfo> & interfaces( void )
- { return ProbedInterfaces; }
+ QDict<InterfaceInfo> & interfaces( void );
InterfaceInfo * interface( const QString& N )
- { return ProbedInterfaces[N]; }
+ { return interfaces()[N]; }
// exec command as root
- int runAsRoot( QStringList & S );
+ int runAsRoot( QStringList & S, MyProcess * Prc = 0 );
// exec command as user
int execAsUser( QStringList & Cmd );
// refresh stats for this interface
void refreshStatistics( InterfaceInfo & );
// reloads interfaces
void probeInterfaces( void );
InterfaceInfo * findInterface( const QString & DevName );
private slots :
void SLOT_ProcessExited( MyProcess * );
signals :
void stdoutLine( const QString & );
void stderrLine( const QString & );
void processEvent( const QString & );
private :
QDict<InterfaceInfo> ProbedInterfaces;
FILE * OutputOfCmd;
QFile * ProcDevNet;
};
#endif
diff --git a/noncore/settings/networksettings2/opietooth2/Opietooth.cpp b/noncore/settings/networksettings2/opietooth2/Opietooth.cpp
index 2d4885c..5a890da 100644
--- a/noncore/settings/networksettings2/opietooth2/Opietooth.cpp
+++ b/noncore/settings/networksettings2/opietooth2/Opietooth.cpp
@@ -1,1037 +1,1151 @@
#include <opie2/odebug.h>
#include <opie2/oledbox.h>
+#include <opie2/ofiledialog.h>
+
using namespace Opie::Core;
using namespace Opie::Ui;
#include <qpe/resource.h>
+#include <qapplication.h>
#include <qcheckbox.h>
+#include <qcombobox.h>
+#include <qdialog.h>
+#include <qdir.h>
+#include <qfile.h>
#include <qgroupbox.h>
-#include <qlabel.h>
-#include <qprogressbar.h>
#include <qheader.h>
-#include <qmessagebox.h>
-#include <qapplication.h>
-#include <qlistbox.h>
-#include <qdialog.h>
-#include <qlayout.h>
-#include <qcombobox.h>
#include <qlabel.h>
+#include <qlayout.h>
+#include <qlistbox.h>
#include <qlistview.h>
+#include <qmessagebox.h>
+#include <qprogressbar.h>
#include <qpushbutton.h>
+#include <qtextstream.h>
#include <Opietooth.h>
#include <OTDriver.h>
#include <OTPeer.h>
#include <OTGateway.h>
#include <OTSDPAttribute.h>
#include <OTSDPService.h>
#include <OTInquiry.h>
+#include <system.h>
+
using namespace Opietooth2;
namespace Opietooth2 {
class PeerLVI : public QListViewItem {
public :
PeerLVI( OTPeer * P, QListView * it ) : QListViewItem (it) {
Peer = P;
}
~PeerLVI( void ) {
}
inline OTPeer * peer( void )
{ return Peer; }
private :
OTPeer * Peer;
};
class ChannelLVI : public QListViewItem {
public :
ChannelLVI( int Ch, QListViewItem * it ) : QListViewItem (it) {
Channel = Ch;
}
~ChannelLVI( void ) {
}
inline int channel( void )
{ return Channel; }
private :
int Channel;
};
class DriverLVI : public QListViewItem {
public :
DriverLVI( OTDriver * P, QListView * it ) : QListViewItem (it) {
Driver = P;
}
~DriverLVI( void ) {
}
inline OTDriver * driver( void )
{ return Driver; }
private :
OTDriver * Driver;
};
class LinkKeyLVI : public QListViewItem {
public :
LinkKeyLVI( int Ch, QListView * it ) : QListViewItem (it) {
LinkKey = Ch;
}
~LinkKeyLVI( void ) {
}
inline int index( void )
{ return LinkKey; }
private :
int LinkKey;
};
};
//
//
//
//
//
OTSniffing::OTSniffing( QWidget * parent ) : OTSniffGUI( parent ) {
OT = OTGateway::getOTGateway();
-
+ HciDump = 0;
+ Sys = new System();
}
OTSniffing::~OTSniffing() {
+ printf( "CLOSE \n" );
+ if ( HciDump ) {
+ HciDump->process().kill();
+ delete HciDump;
+ }
+ delete Sys;
}
-void OTSniffing::SLOT_Trace( void ) {
+void OTSniffing::SLOT_Trace( bool ) {
+ HciDump = new MyProcess();
+ QStringList SL;
+
+ SL << "hcidump";
+ switch( DataFormat_CB->currentItem() ) {
+ case 0 : // Hex
+ SL << "-x";
+ break;
+ case 1 : // Ascii
+ SL << "-a";
+ break;
+ case 2 : // both
+ SL << "-X";
+ break;
+ }
+
+ SL << "-i";
+ SL << OT->scanWith()->devname();
+
+ connect( HciDump,
+ SIGNAL( stdoutLine( const QString & ) ),
+ this,
+ SLOT( SLOT_Show( const QString & ) ) );
+
+ connect( HciDump,
+ SIGNAL(processExited(MyProcess*) ),
+ this,
+ SLOT( SLOT_ProcessExited(MyProcess*) ) );
+
+ if( ! Sys->runAsRoot( SL, HciDump ) ) {
+ QMessageBox::warning(0,
+ tr("Run hcidump"),
+ tr("Cannot start %1").arg(SL.join(" "))
+ );
+ delete HciDump;
+ HciDump = 0;
+ }
+
+}
+
+void OTSniffing::SLOT_Show( const QString & S ) {
+ printf( "%s\n", S.latin1() );
+ Output_LB->insertItem( S );
+ Output_LB->setCurrentItem( Output_LB->count()-1 );
+ Output_LB->ensureCurrentVisible();
+}
+
+void OTSniffing::SLOT_ProcessExited( MyProcess * ) {
+ printf( "Exited\n" );
+ delete HciDump;
+ HciDump = 0;
+}
+
+void OTSniffing::SLOT_Save( void ) {
+ QString S = OFileDialog::getSaveFileName(
+ OFileSelector::Extended,
+ QDir::home().path(),
+ QString::null,
+ MimeTypes(),
+ this );
+
+ if( ! S.isEmpty() ) {
+ QFile F( S );
+ if( ! F.open( IO_WriteOnly ) ) {
+ QMessageBox::warning(0,
+ tr("Save log"),
+ tr("Cannot open %1").arg(S)
+ );
+ return;
+ }
+ QTextStream TS( &F );
+ TS << S << endl;
+ }
+}
+
+void OTSniffing::SLOT_Load( void ) {
+ QString S = OFileDialog::getOpenFileName(
+ OFileSelector::Extended,
+ QDir::home().path(),
+ QString::null,
+ MimeTypes(),
+ this );
+
+ if( ! S.isEmpty() ) {
+ QFile F( S );
+ if( ! F.open( IO_ReadOnly ) ) {
+ QMessageBox::warning(0,
+ tr("Save log"),
+ tr("Cannot open %1").arg(S)
+ );
+ return;
+ }
+ QTextStream TS ( &F );
+ SLOT_ClearLog();
+ S = TS.read();
+ Output_LB->insertStringList( QStringList::split( "\n", S ) );
+ }
}
void OTSniffing::SLOT_ClearLog( void ) {
+ Output_LB->clear();
}
//
//
//
//
//
OTPairing::OTPairing( QWidget * parent, OTIcons * _IC ) :
OTPairingGUI( parent ) {
OT = OTGateway::getOTGateway();
Icons = (_IC ) ? _IC : new OTIcons();
MyIcons = (_IC == 0 );
// unpairing can only be done if bluetooth is disabled
Unpair_But->setEnabled( ! OT->isEnabled() );
if( ! OT->isEnabled() ) {
Unpair_LBL->hide();
} else {
Unpair_LBL->show();
}
// open linkkey file and load pairs
LinkKeyArray Keys = OT->getLinkKeys();
LinkKeyLVI * it;
OTPeer * P;
OTDriver * D;
for( unsigned int i = 0 ;
i < Keys.count();
i ++ ) {
it = new LinkKeyLVI( i, Pairs_LV );
P = 0;
D = OT->findDriver( Keys[i].from() );
if( D ) {
it->setText( 0, D->devname() );
// we are source
P = OT->findPeer( Keys[i].to() );
if( P ) {
// put name
it->setText( 1, P->name() );
} else {
// unknown
it->setText( 1, Keys[i].to().toString() );
}
// and put address as sub
QListViewItem * Sub = new QListViewItem( it );
Sub->setText( 0, D->address().toString() );
Sub->setText( 1, Keys[i].to().toString() );
} else {
// perhaps we are destination
D = OT->findDriver( Keys[i].to() );
if( D ) {
it->setText( 1, D->devname() );
// we are source
P = OT->findPeer( Keys[i].from() );
if( P ) {
// put name
it->setText( 0, P->name() );
} else {
// unknown
it->setText( 0, Keys[i].from().toString() );
}
// and put address as sub
QListViewItem * Sub = new QListViewItem( it );
Sub->setText( 0, Keys[i].from().toString() );
Sub->setText( 1, D->address().toString() );
} else {
// nor source nor destination -> unknown
it->setText( 0, Keys[i].from().toString() );
it->setText( 1, Keys[i].to().toString() );
}
}
}
}
OTPairing::~OTPairing() {
if( MyIcons )
delete Icons;
OTGateway::releaseOTGateway();
}
void OTPairing::SLOT_Unpair( ) {
// find selected pair
QListViewItem * it = Pairs_LV->firstChild();
while( it ) {
if( it->isSelected() ) {
// confirm ?
if( QMessageBox::warning(0,
tr("Break pairing"),
tr("Sure ?"),
tr("Yes, break"),
tr("No, don't break") ) == 0 ) {
LinkKeyLVI * KPIt = (LinkKeyLVI *)it;
// break
OT->removeLinkKey( KPIt->index() );
delete KPIt;
}
return;
}
it= it->nextSibling();
}
}
//
//
//
//
//
OTScan::OTScan( QWidget * parent, OTIcons * _IC ) :
OTScanGUI( parent ), Filter() {
OT = OTGateway::getOTGateway();
Icons = (_IC ) ? _IC : new OTIcons();
MyIcons = (_IC == 0 );
DetectedPeers_LV->header()->hide();
Current = 0;
SelectedPeer = 0;
SelectedChannel = 0;
StrengthTimer = new QTimer( this );
connect( StrengthTimer,
SIGNAL( timeout()),
this,
SLOT( SLOT_UpdateStrength())
);
connect( OT,
SIGNAL( detectedPeer( OTPeer *, bool )),
this,
SLOT( SLOT_NewPeer( OTPeer *, bool ))
);
connect( OT,
SIGNAL( finishedDetecting()),
this,
SLOT( SLOT_FinishedDetecting())
);
// populate with peers we already know about
const PeerVector & P = OT->peers();
for( unsigned int i = 0;
i < P.count();
i ++ ) {
SLOT_NewPeer( P[i], TRUE );
}
// populate State fram
{ QHBoxLayout * H =new QHBoxLayout( State_Frm );
Paired_Led = new OLedBox( green, State_Frm );
QLabel * L1 = new QLabel( tr( "Paired" ), State_Frm );
H->addWidget( Paired_Led );
H->addWidget( L1 );
H->addStretch( 1 );
}
}
OTScan::~OTScan() {
if( MyIcons )
delete Icons;
OTGateway::releaseOTGateway();
// send all peers that we do not care about states
QListViewItem * Lit = DetectedPeers_LV->firstChild();
while( Lit ) {
((PeerLVI *)Lit)->peer()->stopFindingOutState( );
Lit = Lit->nextSibling();
}
}
// static scan dialog function
int OTScan::getDevice( OTPeer *& Peer,
int & Channel,
OTGateway * OT,
const UUIDVector & Filter,
QWidget* Parent ) {
bool IsUp = 0;
unsigned int i;
// check if bluetooth is up
OTDriverList & DL = OT->getDriverList();
for( i = 0;
i < DL.count();
i ++ ) {
if( DL[i]->isUp() ) {
// one device that is up found
IsUp = 1;
break;
}
}
// use this driver
OT->setScanWith( OT->driver(i) );
// create dialog
QDialog * Dlg = new QDialog( Parent, 0, TRUE );
QVBoxLayout * V = new QVBoxLayout( Dlg );
OTScan * Scn = new OTScan( Dlg );
connect( Scn,
SIGNAL( selected() ),
Dlg,
SLOT( accept() )
);
if( Filter ) {
Scn->setScanFilter( Filter );
}
V->addWidget( Scn );
Dlg->setCaption( tr("Scan Neighbourhood" ) );
Dlg->showMaximized();
int rv = Dlg->exec();
if( rv == QDialog::Accepted ) {
// get peer
Peer = Scn->selectedPeer();
if( Peer == 0 ) {
// no peer selected
rv = QDialog::Rejected;
} else {
Channel = Scn->selectedChannel();
}
}
delete Dlg;
return rv;
}
void OTScan::setScanFilter( const UUIDVector & V ) {
Filter = V;
}
void OTScan::resetScanFilter( void ) {
Filter.truncate(0);
}
void OTScan::SLOT_DoScan( bool DoIt ) {
if( DoIt ) {
OT->scanNeighbourhood();
} else {
OT->stopScanOfNeighbourhood();
}
scanMode( DoIt );
}
// double clicked on a device
void OTScan::SLOT_Selected( QListViewItem * it ) {
if( ! it )
return;
if( Filter.count() > 0 ) {
// filter on service
if( it->depth() == 0 ) {
// select a service and not a device
return;
}
// store result
SelectedPeer = ((PeerLVI *)it->parent())->peer();
SelectedChannel = ((ChannelLVI *)it)->channel();
} else {
// click on device
if( it->depth() != 0 ) {
return;
}
SelectedPeer = ((PeerLVI *)it)->peer();
SelectedChannel = 0;
}
owarn << "Selected " << SelectedPeer->address().toString() <<
" Channel " << SelectedChannel << oendl;
emit selected();
}
void OTScan::SLOT_FinishedDetecting( ) {
scanMode( false );
}
void OTScan::SLOT_CleanupOld( ) {
// iterate over all peers and find those that
// are down and have no pairing info
OTPeer * TheP;
const LinkKeyArray & Keys = OT->getLinkKeys();
QListViewItem * Lit = DetectedPeers_LV->firstChild();
while( Lit ) {
TheP = ((PeerLVI *)Lit)->peer();
if( TheP->state() == OTPeer::Peer_Down ) {
unsigned int k;
// what about linkkeys ?
for( k = 0; k < Keys.count(); k ++ ) {
if( TheP->address() == Keys[k].to() ||
TheP->address() == Keys[k].from()
) {
// part of linkkey
owarn << "LINKKEY " << TheP->address().toString() << oendl;
break;
}
}
if( k == Keys.count() ) {
owarn << "RM LINKKEY " << TheP->address().toString() << oendl;
// not found -> remember to remove this peer
QListViewItem * Nit;
OT->removePeer( TheP );
Nit = Lit->nextSibling();
delete Lit;
Lit = Nit;
continue;
}
} else {
owarn << "NODOWN " << TheP->address().toString() << oendl;
}
Lit = Lit->nextSibling();
}
}
void OTScan::SLOT_NewPeer( OTPeer * P, bool IsNew ){
PeerLVI * it = 0;
if( IsNew ) {
it = new PeerLVI( P, DetectedPeers_LV );
} else {
// find peer in table
QListViewItem * Lit = DetectedPeers_LV->firstChild();
while( Lit ) {
if( ((PeerLVI *)Lit)->peer() == P ) {
// this item
it = (PeerLVI *)Lit;
break;
}
Lit = Lit->nextSibling();
}
if( ! it ) {
owarn << "Should not occur" << oendl;
return;
}
}
// update/show info
it->setText( 0, P->name() );
it->setPixmap(0, Icons->deviceIcon(
OT->deviceTypeToName( P->deviceClass() ) ) );
// tell peer to report its state async
connect( P,
SIGNAL( peerStateReport( OTPeer *)),
this,
SLOT( SLOT_PeerState( OTPeer *))
);
if( IsNew ) {
// find state
refreshState( (PeerLVI *)it, 1 );
} else {
// update staet
SLOT_PeerState( P );
}
}
void OTScan::SLOT_PeerState( OTPeer * P ) {
PeerLVI * it = (PeerLVI *)DetectedPeers_LV->firstChild();
while( it ) {
if( it->peer() == P ) {
break;
}
it = (PeerLVI * )it->nextSibling();
}
if( ! it )
return;
switch( P->state() ) {
case OTPeer::Peer_Unknown :
case OTPeer::Peer_Down :
it->setPixmap( 1, 0 );
break;
case OTPeer::Peer_Up :
it->setPixmap( 1, Icons->loadPixmap(
( P->connectedTo() ) ? "connected" : "notconnected" ) );
if( it == Current && ! StrengthTimer->isActive() ) {
// start showing strength
StrengthTimer->start( 1000, FALSE );
SLOT_UpdateStrength();
}
break;
}
}
void OTScan::SLOT_RefreshState( void ) {
QListViewItem * it = DetectedPeers_LV->firstChild();
while( it ) {
if( it->isSelected() ) {
break;
}
it = it->nextSibling();
}
if( ! it )
return;
refreshState( (PeerLVI *)it, 1 );
}
void OTScan::refreshState( PeerLVI * it, bool Force ) {
it->setPixmap( 1, Icons->loadPixmap( "find" ) );
it->peer()->findOutState( 30, Force );
}
void OTScan::SLOT_Show( QListViewItem * it ) {
if( ! it || it->depth() > 0 )
return;
QString S;
Current = (PeerLVI *)it;
Strength_PB->setProgress( 0 ); // reset
Address_LBL->setText( Current->peer()->address().toString() );
Peer_GB->setTitle( Current->peer()->name() );
const LinkKeyArray & Keys = OT->getLinkKeys();
Paired_Led->setOn( FALSE );
for( unsigned int i = 0;
i < Keys.count();
i ++ ) {
if( Current->peer()->address() == Keys[i].to() ) {
Paired_Led->setOn( TRUE );
break;
}
}
if( Current->peer()->state() == OTPeer::Peer_Up ) {
RefreshServices_But->setEnabled( TRUE );
StrengthTimer->start( 1000, FALSE );
SLOT_UpdateStrength();
} else {
RefreshServices_But->setEnabled( FALSE );
}
}
void OTScan::SLOT_UpdateStrength( void ) {
OTDriver * D = Current->peer()->connectedTo();
if( D ) {
long Q = D->getLinkQuality( Current->peer()->address() );
Strength_PB->setProgress( Q );
if( ! Q ) {
// no quality
Strength_PB->setEnabled( TRUE );
StrengthTimer->stop();
}
} else {
Strength_PB->setEnabled( FALSE );
Strength_PB->setProgress( 0 );
// no point in continuing
StrengthTimer->stop();
}
}
void OTScan::SLOT_RefreshServices( void ) {
QListViewItem * it = DetectedPeers_LV->firstChild();
while( it ) {
if( it->isSelected() ) {
break;
}
it = it->nextSibling();
}
if( ! it )
return;
QString S;
PeerLVI * PI = (PeerLVI *)it;
scanMode( true );
qApp->processEvents(0);
ServiceVector & V = PI->peer()->services();
while( PI->firstChild() ) {
// remove children
delete PI->firstChild();
}
for( unsigned int i = 0 ;
i < V.count();
i ++ ) {
QString S;
S = V[i]->name();
if( S.isEmpty() ) {
continue;
}
{ QListViewItem * SIt;
UUIDVector UIDV;
QPixmap Pm;
bool Done = 0;
bool R;
short ID;
SIt = 0;
UIDV = V[i]->classIDList();
// first all UUID ! 1200 12ff (Genericprofiles)
for( unsigned int j = 0;
j < UIDV.count();
j ++ ) {
if( Filter.count() ) {
bool FilterOut = 1;
// filter out if not in list
for( unsigned int ff = 0;
ff < Filter.count();
ff ++ ) {
if( UIDV[j] == Filter[ff] ) {
FilterOut = 0;
break;
}
}
if( FilterOut ) {
// not in filter list
continue;
}
} // else show
ID = UIDV[j].toShort();
if( ID < 0x1200 || ID > 0x12ff ) {
// use this profile
if( R ) {
unsigned int ch;
bool has;
has = V[i]->rfcommChannel( ch );
SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI );
SIt->setText(0, V[i]->name() );
Pm = Icons->serviceIcon( ID, R );
SIt->setPixmap(0, Pm );
Done = 1;
break;
}
}
}
if( ! Done ) {
// check other range too
for( unsigned int j = 0;
j < UIDV.count();
j ++ ) {
if( Filter.count() ) {
bool FilterOut = 1;
// filter out if not in list
for( unsigned int ff = 0;
ff < Filter.count();
ff ++ ) {
if( UIDV[j] == Filter[ff] ) {
FilterOut = 0;
break;
}
}
if( FilterOut ) {
// not in filter list
continue;
}
} // else show
ID = UIDV[j].toShort();
if( ID >= 0x1200 && ID <= 0x12ff ) {
// use this profile
unsigned int ch;
bool has;
has = V[i]->rfcommChannel( ch );
SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI );
SIt->setText(0, V[i]->name() );
Pm = Icons->serviceIcon( ID, R );
SIt->setPixmap(0, Pm );
break;
}
}
}
}
}
scanMode( false );
}
void OTScan::scanMode( bool M ) {
// avoid infinite loop because it triggers DoScan
Detect_But->blockSignals( TRUE );
Detect_But->setOn( M );
Detect_But->setText( (M) ? tr("Scanning") : tr("Scan") );
Detect_But->blockSignals( FALSE );
}
//
//
//
//
//
OTManage::OTManage( QWidget * parent, OTIcons * _IC ) :
OTManageGUI( parent ) {
OT = OTGateway::getOTGateway();
Icons = (_IC ) ? _IC : new OTIcons();
MyIcons = (_IC == 0 );
AllDrivers_LV->setSorting(-1);
connect( OT,
SIGNAL( driverListChanged() ),
this,
SLOT( SLOT_DriverListChanged() )
);
connect( OT,
SIGNAL( stateChange( OTDriver *, bool ) ),
this,
SLOT( SLOT_StateChange( OTDriver *, bool ) )
);
SLOT_DriverListChanged();
AllDrivers_LV->header()->hide();
}
OTManage::~OTManage() {
if( MyIcons )
delete Icons;
OTGateway::releaseOTGateway();
}
void OTManage::SLOT_ShowDriver( QListViewItem * It ) {
if( It == 0 || It->depth() > 0 )
// not toplevel
return;
DriverLVI * it = (DriverLVI *) It;
DriverIsUp_CB->setChecked( it->driver()->isUp() );
}
void OTManage::SLOT_UpDriver( bool Up ) {
QListViewItem * it = AllDrivers_LV->firstChild();
while( it ) {
if( it->isSelected() ) {
OTDriver * D = ((DriverLVI *)it)->driver();
owarn << "UP driver " << D->devname() << oendl;
// this
D->setUp( Up );
return;
}
it = it->nextSibling();
}
}
void OTManage::SLOT_StateChange( OTDriver * D, bool Up ) {
QListViewItem * it = AllDrivers_LV->firstChild();
while( it ) {
if( ((DriverLVI *)it)->driver() == D ) {
it->setPixmap( 0,
Icons->loadPixmap( ( Up ) ? "bluezon" : "bluezoff" ) );
return;
}
it = it->nextSibling();
}
}
void OTManage::SLOT_DriverListChanged( ) {
DriverLVI * It;
QListViewItem * Sub;
QListViewItem * First = 0;
OTDriver* D;
OTDriverList & DL = OT->getDriverList();
AllDrivers_LV->clear();
for( unsigned int i = 0;
i < DL.count();
i ++ ) {
D = DL[i];
It = new DriverLVI( D, AllDrivers_LV );
if( ! First )
First = It;
It->setText( 0, D->devname() );
It->setPixmap( 0,
Icons->loadPixmap( (D->isUp()) ?
"bluezon" : "bluezoff" ) );
Sub = new QListViewItem( It );
Sub->setText( 0, tr( "Name" ) );
Sub->setText( 1, D->name() );
Sub = new QListViewItem( It );
Sub->setText( 0, tr( "Address" ) );
Sub->setText( 1, D->address().toString() );
Sub = new QListViewItem( It );
Sub->setText( 0, tr( "Revision" ) );
Sub->setText( 1, D->revision() );
Sub = new QListViewItem( It );
Sub->setText( 0, tr( "Manufacturer" ) );
Sub->setText( 1, D->manufacturer() );
QString Service, Device;
D->getClass( Service, Device );
Sub = new QListViewItem( It );
Sub->setText( 0, tr( "Service classes" ) );
Sub->setText( 1, Service );
Sub = new QListViewItem( It );
Sub->setText( 0, tr( "Device class" ) );
Sub->setText( 1, Device );
}
if( DL.count() ) {
AllDrivers_LV->setCurrentItem( First );
DriverIsUp_CB->setEnabled( TRUE );
} else {
DriverIsUp_CB->setChecked( FALSE );
DriverIsUp_CB->setEnabled( FALSE );
}
}
void OTManage::SLOT_SetRefreshTimer( int v ) {
OT->setRefreshTimer( v * 1000 );
}
//
//
//
//
//
OTMain::OTMain( QWidget * parent ) : OTMainGUI( parent ) {
Icons = new OTIcons();
SnifWindow = 0;
OT = OTGateway::getOTGateway();
connect( OT,
SIGNAL( deviceEnabled( bool ) ),
this,
SLOT( SLOT_DeviceIsEnabled( bool ) )
);
connect( OT,
SIGNAL( driverListChanged() ),
this,
SLOT( SLOT_DriverListChanged() )
);
connect( OT,
SIGNAL( stateChange( OTDriver *, bool ) ),
this,
SLOT( SLOT_StateChange( OTDriver *, bool ) )
);
if( ! OT->needsEnabling() ) {
MustBeEnabled_CB->hide();
} else {
// detect current state
MustBeEnabled_CB->setChecked(
OT->isEnabled() );
}
SLOT_DriverListChanged();
}
OTMain::~OTMain() {
OTGateway::releaseOTGateway();
delete Icons;
}
void OTMain::SLOT_DriverListChanged() {
OTDriver * D;
OTDriverList & DL = OT->getDriverList();
DeviceList_CB->clear();
for( unsigned int i = 0;
i < DL.count();
i ++ ) {
D = DL[i];
DeviceList_CB->insertItem(
Icons->loadPixmap( (D->isUp()) ?
"bluezon" : "bluezoff" ),
D->devname() );
if( D == OT->scanWith() ) {
DeviceList_CB->setCurrentItem( i );
}
}
Scan_But->setEnabled( OT->getDriverList().count() > 0 );
DeviceList_CB->setEnabled( OT->getDriverList().count() > 0 );
}
void OTMain::SLOT_EnableBluetooth( bool Up ) {
OT->SLOT_SetEnabled( Up );
}
void OTMain::SLOT_DeviceIsEnabled( bool Up ) {
MustBeEnabled_CB->blockSignals( TRUE );
MustBeEnabled_CB->setChecked( Up );
MustBeEnabled_CB->blockSignals( FALSE );
}
void OTMain::SLOT_Manage( void ) {
QDialog * Dlg = new QDialog( this, 0, TRUE );
QVBoxLayout * V = new QVBoxLayout( Dlg );
OTManage * Mng = new OTManage( Dlg, Icons );
V->addWidget( Mng );
Dlg->setCaption( tr("Manage local devices" ) );
Dlg->showMaximized();
Dlg->exec();
delete Dlg;
}
void OTMain::SLOT_Scan( void ) {
OTDriverList & DL = OT->getDriverList();
for( unsigned int i = 0;
i < DL.count();
i ++ ) {
if( DL[i]->isUp() &&
DL[i]->devname() == DeviceList_CB->currentText()
) {
QDialog * Dlg = new QDialog( this, 0, TRUE );
QVBoxLayout * V = new QVBoxLayout( Dlg );
OTScan * Scn = new OTScan( Dlg, Icons );
OT->setScanWith( OT->driver(i) );
V->addWidget( Scn );
Dlg->setCaption( tr("Scan Neighbourhood" ) );
Dlg->showMaximized();
Dlg->exec();
delete Dlg;
return;
}
}
}
void OTMain::SLOT_StateChange( OTDriver * D, bool Up ) {
for( int i = 0;
i < DeviceList_CB->count();
i ++ ) {
if( DeviceList_CB->text(i) == D->devname() ) {
DeviceList_CB->changeItem(
Icons->loadPixmap( (Up) ? "bluezon" : "bluezoff" ),
D->devname(),
i );
return;
}
}
}
void OTMain::SLOT_Pairing( void ) {
QDialog * Dlg = new QDialog( this, 0, TRUE );
QVBoxLayout * V = new QVBoxLayout( Dlg );
OTPairing * Pair = new OTPairing( Dlg, Icons );
V->addWidget( Pair );
Dlg->showMaximized();
Dlg->setCaption( tr("Manage pairing" ) );
Dlg->exec();
delete Dlg;
}
void OTMain::SLOT_Sniffing( void ) {
if( SnifWindow == 0 ) {
- SnifWindow = new OTSniffing( this );
+ SnifWindow = new QDialog( this, 0, FALSE );
+ QVBoxLayout * V = new QVBoxLayout( SnifWindow );
+ OTSniffing * SN = new OTSniffing( SnifWindow );
+ V->addWidget( SN );
}
SnifWindow->showMaximized();
SnifWindow->show();
}
diff --git a/noncore/settings/networksettings2/opietooth2/Opietooth.h b/noncore/settings/networksettings2/opietooth2/Opietooth.h
index 211ae65..2b20975 100644
--- a/noncore/settings/networksettings2/opietooth2/Opietooth.h
+++ b/noncore/settings/networksettings2/opietooth2/Opietooth.h
@@ -1,223 +1,240 @@
#ifndef OPIETOOTH_H
#define OPIETOOTH_H
#include <OTIcons.h>
-namespace Opie { namespace Ui { class OLedBox; }; };
+class MyProcess;
+class System;
+
+namespace Opie {
+
+ namespace Ui {
+
+ class OLedBox;
+
+ };
+
+};
#include <OTSniffGUI.h>
namespace Opietooth2 {
class OTGateway;
class OTDriver;
class OTInquiry;
class OTPeer;
class PeerLVI;
class OTSniffing : public OTSniffGUI {
Q_OBJECT
public :
OTSniffing( QWidget * parent );
~OTSniffing();
private slots :
- void SLOT_Trace( void );
+ void SLOT_Trace( bool );
void SLOT_ClearLog( void );
+ void SLOT_Load( void );
+ void SLOT_Save( void );
+ void SLOT_ProcessExited( MyProcess * );
+ void SLOT_Show( const QString & );
signals :
protected :
private :
OTGateway * OT;
+ MyProcess * HciDump;
+ System * Sys;
};
};
#include <OTPairingGUI.h>
namespace Opietooth2 {
class OTPairing : public OTPairingGUI {
Q_OBJECT
public :
OTPairing( QWidget * parent,
OTIcons * _Ic = 0 );
~OTPairing();
private slots :
void SLOT_Unpair( void );
signals :
protected :
private :
bool MyIcons;
OTIcons * Icons;
OTGateway * OT;
};
};
#include <OTScanGUI.h>
namespace Opietooth2 {
class OTGateway;
class OTDriver;
class OTInquiry;
class OTPeer;
class OTScan : public OTScanGUI {
Q_OBJECT
public :
OTScan( QWidget * parent,
OTIcons * _Ic = 0 );
~OTScan();
// static function to return a device and a channel
static int getDevice( OTPeer *& Peer,
int & Channel,
OTGateway * OT,
const UUIDVector & Filter = 0,
QWidget* Parent = 0);
// show only services that match any of the filter
void setScanFilter( const UUIDVector & Filter );
void resetScanFilter( void );
inline OTPeer * selectedPeer( void )
{ return SelectedPeer; }
inline int selectedChannel( void )
{ return SelectedChannel; }
public slots :
private slots :
void SLOT_DoScan( bool );
void SLOT_NewPeer( OTPeer *, bool );
void SLOT_FinishedDetecting();
void SLOT_Show( QListViewItem *);
void SLOT_RefreshServices( void );
void SLOT_RefreshState( void );
void SLOT_CleanupOld( void );
void SLOT_UpdateStrength( void );
void SLOT_PeerState( OTPeer * );
void SLOT_Selected( QListViewItem * );
signals :
void selected( void );
protected :
private :
void refreshState( PeerLVI *, bool );
void scanMode( bool );
// load scanned devices
bool MyIcons;
OTIcons * Icons;
OTGateway * OT;
OTInquiry * Scanning;
UUIDVector Filter;
Opie::Ui::OLedBox * Paired_Led;
QTimer * StrengthTimer;
PeerLVI * Current;
OTPeer * SelectedPeer;
int SelectedChannel;
};
};
#include <OTManageGUI.h>
namespace Opietooth2 {
class OTManage : public OTManageGUI {
Q_OBJECT
public :
OTManage( QWidget * parent,
OTIcons * _IC = 0 );
~OTManage();
public slots :
private slots :
void SLOT_ShowDriver( QListViewItem * );
void SLOT_UpDriver( bool );
void SLOT_StateChange( OTDriver * , bool );
void SLOT_DriverListChanged();
void SLOT_SetRefreshTimer( int );
signals :
protected :
private :
// load scanned devices
bool MyIcons;
OTIcons * Icons;
OTGateway * OT;
OTInquiry * Scanning;
};
};
#include <OTMainGUI.h>
namespace Opietooth2 {
class OTMain : public OTMainGUI {
Q_OBJECT
public :
OTMain( QWidget * parent );
~OTMain();
public slots :
private slots :
void SLOT_Pairing( void );
void SLOT_Manage( void );
void SLOT_Sniffing( void );
void SLOT_Scan( void );
void SLOT_EnableBluetooth( bool );
void SLOT_DriverListChanged();
void SLOT_DeviceIsEnabled( bool );
void SLOT_StateChange( OTDriver * , bool );
signals :
protected :
private :
// load scanned devices
OTIcons * Icons;
OTGateway * OT;
- OTSniffing * SnifWindow;
+ QDialog * SnifWindow;
};
};
#endif
diff --git a/noncore/settings/networksettings2/opietooth2/libopietooth2.control b/noncore/settings/networksettings2/opietooth2/libopietooth2.control
index fd01fb5..c2c8eb8 100644
--- a/noncore/settings/networksettings2/opietooth2/libopietooth2.control
+++ b/noncore/settings/networksettings2/opietooth2/libopietooth2.control
@@ -1,9 +1,9 @@
Package: libopietooth2
Files: lib/libopietooth2.so.* apps/Settings/opietooth-manager.desktop pics/opietooth/*.png pics/opietooth/icons/*.png
Priority: optional
Section: opie/system
Maintainer: wim delvaux <wim.delvaux@handhelds.org>
Architecture: arm
Version: $QPE_VERSION$EXTRAVERSION
-Depends: task-opie-minimal, libbluetooth1, opie-bluepin | opie-multiauth-bluepingplugin, bluez-utils-nodbus
+Depends: task-opie-minimal, opie-networksettings2, libbluetooth1, opie-bluepin | opie-multiauth-bluepingplugin, bluez-utils-nodbus
Description: Opie bluetooth support library version 2
diff --git a/noncore/settings/networksettings2/opietooth2/opietooth2.pro b/noncore/settings/networksettings2/opietooth2/opietooth2.pro
index cfb527d..e0057a9 100644
--- a/noncore/settings/networksettings2/opietooth2/opietooth2.pro
+++ b/noncore/settings/networksettings2/opietooth2/opietooth2.pro
@@ -1,37 +1,37 @@
TEMPLATE = lib
CONFIG += qt warn_on release
#CONFIG += qt warn_on debug
DESTDIR = $(OPIEDIR)/lib$(PROJMAK)
HEADERS = OTDevice.h \
OTDriver.h \
OTGateway.h \
OTHCISocket.h \
OTInquiry.h \
OTDeviceAddress.h \
OTIcons.h \
OTUUID.h \
OTSDPAttribute.h \
OTSDPService.h \
OTPeer.h \
Opietooth.h
SOURCES = OTDevice.cpp \
OTDriver.cpp \
OTDriverList.cpp \
OTHCISocket.cpp \
OTInquiry.cpp \
OTDeviceAddress.cpp \
OTUUID.cpp \
OTSDPAttribute.cpp \
OTSDPService.cpp \
OTIcons.cpp \
OTPeer.cpp \
OTGateway.cpp \
Opietooth.cpp
-INCLUDEPATH += $(OPIEDIR)/include
+INCLUDEPATH += $(OPIEDIR)/include ../networksettings2
DEPENDPATH += $(OPIEDIR)/include
-LIBS += -lqpe -lopiecore2 -lbluetooth
+LIBS += -lqpe -lopiecore2 -lbluetooth -lnetworksettings2
INTERFACES = OTMainGUI.ui OTSniffGUI.ui OTScanGUI.ui OTManageGUI.ui OTPairingGUI.ui
TARGET = opietooth2
VERSION = 1.0.0
include ( $(OPIEDIR)/include.pro )