summaryrefslogtreecommitdiff
authorkorovkin <korovkin>2006-03-19 14:57:44 (UTC)
committer korovkin <korovkin>2006-03-19 14:57:44 (UTC)
commita71b86fe8ca57753e8209786691b9c7a33d1c1c9 (patch) (unidiff)
tree7463f566a86c5bdff0e4e1380300edc327ebcada
parentbf4d4b814d514762748fe602aeef6c43da102c3a (diff)
downloadopie-a71b86fe8ca57753e8209786691b9c7a33d1c1c9.zip
opie-a71b86fe8ca57753e8209786691b9c7a33d1c1c9.tar.gz
opie-a71b86fe8ca57753e8209786691b9c7a33d1c1c9.tar.bz2
PPP dialog calls rfcomm connect 0 <device MAC address> <port> if ppp script name
is empty.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/manager/pppdialog.cpp78
-rw-r--r--noncore/net/opietooth/manager/pppdialog.h16
2 files changed, 78 insertions, 16 deletions
diff --git a/noncore/net/opietooth/manager/pppdialog.cpp b/noncore/net/opietooth/manager/pppdialog.cpp
index ef007f5..b8d800a 100644
--- a/noncore/net/opietooth/manager/pppdialog.cpp
+++ b/noncore/net/opietooth/manager/pppdialog.cpp
@@ -1,5 +1,6 @@
1 1
2#include "pppdialog.h" 2#include "pppdialog.h"
3#include "rfcommhelper.h"
3#include <qpushbutton.h> 4#include <qpushbutton.h>
4#include <qmultilineedit.h> 5#include <qmultilineedit.h>
5#include <qlineedit.h> 6#include <qlineedit.h>
@@ -12,14 +13,19 @@ using namespace Opie::Core;
12using namespace OpieTooth; 13using namespace OpieTooth;
13 14
14using namespace Opie::Core; 15using namespace Opie::Core;
15PPPDialog::PPPDialog( QWidget* parent, const char* name, bool modal, WFlags fl, const QString& device ) 16
17Connection PPPDialog::conns[NCONNECTS];
18
19PPPDialog::PPPDialog( const QString& device, int port, QWidget* parent,
20 const char* name, bool modal, WFlags fl )
16 : QDialog( parent, name, modal, fl ) { 21 : QDialog( parent, name, modal, fl ) {
17 22
18 if ( !name ) 23 if ( !name )
19 setName( "PPPDialog" ); 24 setName( "PPPDialog" );
20 setCaption( tr( "ppp connection " ) ) ; 25 setCaption( tr( "ppp connection " ) ) ;
21 26
22 m_device = device; 27 m_device = device;
28 m_port = port;
23 29
24 layout = new QVBoxLayout( this ); 30 layout = new QVBoxLayout( this );
25 31
@@ -44,28 +50,72 @@ PPPDialog::PPPDialog( QWidget* parent, const char* name, bool modal, WFlags fl,
44 50
45 connect( connectButton, SIGNAL( clicked() ), this, SLOT( connectToDevice() ) ); 51 connect( connectButton, SIGNAL( clicked() ), this, SLOT( connectToDevice() ) );
46 52
53 connect(&PPPDialog::conns[0].proc,
54 SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int)),
55 this, SLOT(fillOutPut(Opie::Core::OProcess*, char*, int)));
56 connect( &PPPDialog::conns[0].proc,
57 SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int)),
58 this, SLOT(fillErr(Opie::Core::OProcess*, char*, int)));
59 connect( &PPPDialog::conns[0].proc,
60 SIGNAL(processExited(Opie::Core::OProcess*)),
61 this, SLOT(slotProcessExited(Opie::Core::OProcess*)));
47} 62}
48 63
49PPPDialog::~PPPDialog() { 64PPPDialog::~PPPDialog() {
50} 65}
51 66
52void PPPDialog::connectToDevice() { 67void PPPDialog::connectToDevice() {
68 if (PPPDialog::conns[0].proc.isRunning()) {
69 outPut->append(tr("Work in progress"));
70 return;
71 }
53 outPut->clear(); 72 outPut->clear();
73 PPPDialog::conns[0].proc.clearArguments();
54 // vom popupmenu beziehen 74 // vom popupmenu beziehen
55 QString connectScript = "/etc/ppp/peers/" + cmdLine->text(); 75 if (cmdLine->text().isEmpty()) {//Connect by rfcomm
56 OProcess* pppDial = new OProcess(); 76 PPPDialog::conns[0].proc << "rfcomm" << "connect"
57 *pppDial << "pppd" << m_device << "call" << connectScript; 77 << "0" << m_device << QString::number(m_port);
58 connect( pppDial, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int) ), 78 }
59 this, SLOT(fillOutPut(Opie::Core::OProcess*,char*,int) ) ); 79 else {
60 if (!pppDial->start(OProcess::DontCare, OProcess::AllOutput) ) { 80 QString connectScript = "/etc/ppp/peers/" + cmdLine->text();
61 owarn << "could not start" << oendl; 81 PPPDialog::conns[0].proc << "pppd"
62 delete pppDial; 82 << m_device << "call" << connectScript;
83 }
84 if (!PPPDialog::conns[0].proc.start(OProcess::NotifyOnExit, OProcess::All)) {
85 outPut->append(tr("Couldn't start"));
86 }
87 else
88 {
89 PPPDialog::conns[0].proc.resume();
90 outPut->append(tr("Started"));
91 PPPDialog::conns[0].btAddr = m_device;
92 PPPDialog::conns[0].port = m_port;
63 } 93 }
64} 94}
65 95
66void PPPDialog::fillOutPut( OProcess* pppDial, char* cha, int len ) { 96void PPPDialog::fillOutPut( OProcess*, char* cha, int len ) {
67 QCString str(cha, len ); 97 QCString str(cha, len);
68 outPut->insertLine( str ); 98 outPut->append(str);
69 delete pppDial;
70} 99}
71 100
101void PPPDialog::fillErr(OProcess*, char* buf, int len)
102{
103 QCString str(buf, len);
104 outPut->append(str);
105}
106
107void PPPDialog::slotProcessExited(OProcess* proc) {
108 if (proc->normalExit()) {
109 outPut->append( tr("Finished with result ") );
110 outPut->append( QString::number(proc->exitStatus()) );
111 }
112 else
113 outPut->append( tr("Exited abnormally") );
114}
115
116void PPPDialog::closeEvent(QCloseEvent* e)
117{
118 if(PPPDialog::conns[0].proc.isRunning())
119 PPPDialog::conns[0].proc.kill();
120 QDialog::closeEvent(e);
121}
diff --git a/noncore/net/opietooth/manager/pppdialog.h b/noncore/net/opietooth/manager/pppdialog.h
index 05894e2..565fe1e 100644
--- a/noncore/net/opietooth/manager/pppdialog.h
+++ b/noncore/net/opietooth/manager/pppdialog.h
@@ -9,21 +9,32 @@ class QVBoxLayout;
9class QPushButton; 9class QPushButton;
10class QMultiLineEdit; 10class QMultiLineEdit;
11class QLineEdit; 11class QLineEdit;
12 12#define NCONNECTS 10 //Maximal
13 13
14namespace OpieTooth { 14namespace OpieTooth {
15 typedef struct {
16 Opie::Core::OProcess proc; //Connection process
17 QString btAddr; //MAC address
18 int port; //port
19 } Connection;
15 20
16 class PPPDialog : public QDialog { 21 class PPPDialog : public QDialog {
17 22
18 Q_OBJECT 23 Q_OBJECT
19 24
20 public: 25 public:
21 PPPDialog( QWidget* parent = 0, const char* name = 0, bool modal = TRUE, WFlags fl = 0, const QString& device = 0); 26 PPPDialog(const QString& device = 0, int port = 0, QWidget* parent = 0, const char* name = 0, bool modal = TRUE, WFlags fl = 0);
22 ~PPPDialog(); 27 ~PPPDialog();
23 28
24 private slots: 29 private slots:
25 void connectToDevice(); 30 void connectToDevice();
26 void fillOutPut( Opie::Core::OProcess* pppDial, char* cha, int len ); 31 void fillOutPut( Opie::Core::OProcess* pppDial, char* cha, int len );
32 void fillErr(Opie::Core::OProcess*, char*, int);
33 void slotProcessExited(Opie::Core::OProcess* proc);
34 void closeEvent(QCloseEvent* e);
35 public:
36 //Array of connections indexed by rfcomm device number
37 static Connection conns[NCONNECTS];
27 protected: 38 protected:
28 QVBoxLayout* layout; 39 QVBoxLayout* layout;
29 QLineEdit* cmdLine; 40 QLineEdit* cmdLine;
@@ -32,6 +43,7 @@ namespace OpieTooth {
32 43
33 private: 44 private:
34 QString m_device; 45 QString m_device;
46 int m_port;
35 }; 47 };
36} 48}
37#endif 49#endif