summaryrefslogtreecommitdiff
Unidiff
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,71 +1,121 @@
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>
6#include <qlayout.h> 7#include <qlayout.h>
7#include <qlabel.h> 8#include <qlabel.h>
8#include <opie2/oprocess.h> 9#include <opie2/oprocess.h>
9#include <opie2/odebug.h> 10#include <opie2/odebug.h>
10using namespace Opie::Core; 11using namespace Opie::Core;
11 12
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
26 QLabel* info = new QLabel( this ); 32 QLabel* info = new QLabel( this );
27 info->setText( tr("Enter an ppp script name:") ); 33 info->setText( tr("Enter an ppp script name:") );
28 34
29 cmdLine = new QLineEdit( this ); 35 cmdLine = new QLineEdit( this );
30 36
31 outPut = new QMultiLineEdit( this ); 37 outPut = new QMultiLineEdit( this );
32 QFont outPut_font( outPut->font() ); 38 QFont outPut_font( outPut->font() );
33 outPut_font.setPointSize( 8 ); 39 outPut_font.setPointSize( 8 );
34 outPut->setFont( outPut_font ); 40 outPut->setFont( outPut_font );
35 outPut->setWordWrap( QMultiLineEdit::WidgetWidth ); 41 outPut->setWordWrap( QMultiLineEdit::WidgetWidth );
36 42
37 connectButton = new QPushButton( this ); 43 connectButton = new QPushButton( this );
38 connectButton->setText( tr( "Connect" ) ); 44 connectButton->setText( tr( "Connect" ) );
39 45
40 layout->addWidget(info); 46 layout->addWidget(info);
41 layout->addWidget(cmdLine); 47 layout->addWidget(cmdLine);
42 layout->addWidget(outPut); 48 layout->addWidget(outPut);
43 layout->addWidget(connectButton); 49 layout->addWidget(connectButton);
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
@@ -1,37 +1,49 @@
1#ifndef PPPDIALOG_H 1#ifndef PPPDIALOG_H
2#define PPPDIALOG_H 2#define PPPDIALOG_H
3 3
4 4
5#include <qdialog.h> 5#include <qdialog.h>
6#include <opie2/oprocess.h> 6#include <opie2/oprocess.h>
7 7
8class QVBoxLayout; 8class 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;
30 QPushButton* connectButton; 41 QPushButton* connectButton;
31 QMultiLineEdit* outPut; 42 QMultiLineEdit* outPut;
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