-rw-r--r-- | noncore/net/opietooth/manager/pppdialog.cpp | 62 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/pppdialog.h | 2 |
2 files changed, 41 insertions, 23 deletions
diff --git a/noncore/net/opietooth/manager/pppdialog.cpp b/noncore/net/opietooth/manager/pppdialog.cpp index b8d800a..11091c4 100644 --- a/noncore/net/opietooth/manager/pppdialog.cpp +++ b/noncore/net/opietooth/manager/pppdialog.cpp | |||
@@ -1,104 +1,115 @@ | |||
1 | 1 | ||
2 | #include "pppdialog.h" | 2 | #include "pppdialog.h" |
3 | #include "rfcommhelper.h" | 3 | #include "rfcommhelper.h" |
4 | #include <qpushbutton.h> | 4 | #include <qpushbutton.h> |
5 | #include <qmultilineedit.h> | 5 | #include <qmultilineedit.h> |
6 | #include <qlineedit.h> | 6 | #include <qlineedit.h> |
7 | #include <qlayout.h> | 7 | #include <qlayout.h> |
8 | #include <qcombobox.h> | ||
8 | #include <qlabel.h> | 9 | #include <qlabel.h> |
9 | #include <opie2/oprocess.h> | 10 | #include <opie2/oprocess.h> |
10 | #include <opie2/odebug.h> | 11 | #include <opie2/odebug.h> |
11 | using namespace Opie::Core; | 12 | using namespace Opie::Core; |
12 | 13 | ||
13 | using namespace OpieTooth; | 14 | using namespace OpieTooth; |
14 | 15 | ||
15 | using namespace Opie::Core; | 16 | using namespace Opie::Core; |
16 | 17 | ||
17 | Connection PPPDialog::conns[NCONNECTS]; | 18 | Connection PPPDialog::conns[NCONNECTS]; |
18 | 19 | ||
19 | PPPDialog::PPPDialog( const QString& device, int port, QWidget* parent, | 20 | PPPDialog::PPPDialog( const QString& device, int port, QWidget* parent, |
20 | const char* name, bool modal, WFlags fl ) | 21 | const char* name, bool modal, WFlags fl ) |
21 | : QDialog( parent, name, modal, fl ) { | 22 | : QDialog( parent, name, modal, fl ) { |
23 | int i; //Just an index variable | ||
22 | 24 | ||
23 | if ( !name ) | 25 | if ( !name ) |
24 | setName( "PPPDialog" ); | 26 | setName( "PPPDialog" ); |
25 | setCaption( tr( "ppp connection " ) ) ; | 27 | setCaption( tr( "ppp connection " ) ) ; |
26 | 28 | ||
27 | m_device = device; | 29 | m_device = device; |
28 | m_port = port; | 30 | m_port = port; |
29 | 31 | ||
30 | layout = new QVBoxLayout( this ); | 32 | layout = new QVBoxLayout( this ); |
31 | 33 | ||
32 | QLabel* info = new QLabel( this ); | 34 | QLabel* info = new QLabel( this ); |
33 | info->setText( tr("Enter an ppp script name:") ); | 35 | info->setText( tr("Enter an ppp script name:") ); |
34 | 36 | ||
35 | cmdLine = new QLineEdit( this ); | 37 | cmdLine = new QLineEdit( this ); |
36 | 38 | ||
37 | outPut = new QMultiLineEdit( this ); | 39 | outPut = new QMultiLineEdit( this ); |
38 | QFont outPut_font( outPut->font() ); | 40 | QFont outPut_font( outPut->font() ); |
39 | outPut_font.setPointSize( 8 ); | 41 | outPut_font.setPointSize( 8 ); |
40 | outPut->setFont( outPut_font ); | 42 | outPut->setFont( outPut_font ); |
41 | outPut->setWordWrap( QMultiLineEdit::WidgetWidth ); | 43 | outPut->setWordWrap( QMultiLineEdit::WidgetWidth ); |
42 | 44 | ||
43 | connectButton = new QPushButton( this ); | 45 | connectButton = new QPushButton( this ); |
44 | connectButton->setText( tr( "Connect" ) ); | 46 | connectButton->setText( tr( "Connect" ) ); |
45 | 47 | ||
48 | serPort = new QComboBox(this); | ||
49 | for (i = 0; i < NCONNECTS; i++) { | ||
50 | if (!PPPDialog::conns[i].proc.isRunning()) | ||
51 | serPort->insertItem(tr("rfcomm%1").arg(i)); | ||
52 | } | ||
53 | |||
46 | layout->addWidget(info); | 54 | layout->addWidget(info); |
47 | layout->addWidget(cmdLine); | 55 | layout->addWidget(cmdLine); |
56 | layout->addWidget(serPort); | ||
48 | layout->addWidget(outPut); | 57 | layout->addWidget(outPut); |
49 | layout->addWidget(connectButton); | 58 | layout->addWidget(connectButton); |
50 | 59 | ||
51 | connect( connectButton, SIGNAL( clicked() ), this, SLOT( connectToDevice() ) ); | 60 | connect( connectButton, SIGNAL( clicked() ), this, SLOT( connectToDevice() ) ); |
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*))); | ||
62 | } | 61 | } |
63 | 62 | ||
64 | PPPDialog::~PPPDialog() { | 63 | PPPDialog::~PPPDialog() { |
65 | } | 64 | } |
66 | 65 | ||
67 | void PPPDialog::connectToDevice() { | 66 | void PPPDialog::connectToDevice() { |
68 | if (PPPDialog::conns[0].proc.isRunning()) { | 67 | int portNum = serPort->currentText().right(1).toInt(); |
68 | if (PPPDialog::conns[portNum].proc.isRunning()) { | ||
69 | outPut->append(tr("Work in progress")); | 69 | outPut->append(tr("Work in progress")); |
70 | return; | 70 | return; |
71 | } | 71 | } |
72 | outPut->clear(); | 72 | outPut->clear(); |
73 | PPPDialog::conns[0].proc.clearArguments(); | 73 | PPPDialog::conns[portNum].proc.clearArguments(); |
74 | // vom popupmenu beziehen | 74 | // vom popupmenu beziehen |
75 | if (cmdLine->text().isEmpty()) {//Connect by rfcomm | 75 | if (cmdLine->text().isEmpty()) {//Connect by rfcomm |
76 | PPPDialog::conns[0].proc << "rfcomm" << "connect" | 76 | PPPDialog::conns[portNum].proc << "rfcomm" << "connect" |
77 | << "0" << m_device << QString::number(m_port); | 77 | << QString::number(portNum) << m_device << QString::number(m_port); |
78 | } | 78 | } |
79 | else { | 79 | else { |
80 | QString connectScript = "/etc/ppp/peers/" + cmdLine->text(); | 80 | PPPDialog::conns[portNum].proc << "pppd" |
81 | PPPDialog::conns[0].proc << "pppd" | 81 | << tr("/dev/bluetooth/rfcomm/%1").arg(portNum) |
82 | << m_device << "call" << connectScript; | 82 | << "call" |
83 | << cmdLine->text(); | ||
83 | } | 84 | } |
84 | if (!PPPDialog::conns[0].proc.start(OProcess::NotifyOnExit, OProcess::All)) { | 85 | if (!PPPDialog::conns[portNum].proc.start(OProcess::NotifyOnExit, |
86 | OProcess::All)) { | ||
85 | outPut->append(tr("Couldn't start")); | 87 | outPut->append(tr("Couldn't start")); |
86 | } | 88 | } |
87 | else | 89 | else |
88 | { | 90 | { |
89 | PPPDialog::conns[0].proc.resume(); | 91 | PPPDialog::conns[portNum].proc.resume(); |
90 | outPut->append(tr("Started")); | 92 | outPut->append(tr("Started")); |
91 | PPPDialog::conns[0].btAddr = m_device; | 93 | PPPDialog::conns[portNum].btAddr = m_device; |
92 | PPPDialog::conns[0].port = m_port; | 94 | PPPDialog::conns[portNum].port = m_port; |
95 | connect(&PPPDialog::conns[portNum].proc, | ||
96 | SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int)), | ||
97 | this, SLOT(fillOutPut(Opie::Core::OProcess*, char*, int))); | ||
98 | connect( &PPPDialog::conns[portNum].proc, | ||
99 | SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int)), | ||
100 | this, SLOT(fillErr(Opie::Core::OProcess*, char*, int))); | ||
101 | connect( &PPPDialog::conns[portNum].proc, | ||
102 | SIGNAL(processExited(Opie::Core::OProcess*)), | ||
103 | this, SLOT(slotProcessExited(Opie::Core::OProcess*))); | ||
93 | } | 104 | } |
94 | } | 105 | } |
95 | 106 | ||
96 | void PPPDialog::fillOutPut( OProcess*, char* cha, int len ) { | 107 | void PPPDialog::fillOutPut( OProcess*, char* cha, int len ) { |
97 | QCString str(cha, len); | 108 | QCString str(cha, len); |
98 | outPut->append(str); | 109 | outPut->append(str); |
99 | } | 110 | } |
100 | 111 | ||
101 | void PPPDialog::fillErr(OProcess*, char* buf, int len) | 112 | void PPPDialog::fillErr(OProcess*, char* buf, int len) |
102 | { | 113 | { |
103 | QCString str(buf, len); | 114 | QCString str(buf, len); |
104 | outPut->append(str); | 115 | outPut->append(str); |
@@ -106,16 +117,21 @@ void PPPDialog::fillErr(OProcess*, char* buf, int len) | |||
106 | 117 | ||
107 | void PPPDialog::slotProcessExited(OProcess* proc) { | 118 | void PPPDialog::slotProcessExited(OProcess* proc) { |
108 | if (proc->normalExit()) { | 119 | if (proc->normalExit()) { |
109 | outPut->append( tr("Finished with result ") ); | 120 | outPut->append( tr("Finished with result ") ); |
110 | outPut->append( QString::number(proc->exitStatus()) ); | 121 | outPut->append( QString::number(proc->exitStatus()) ); |
111 | } | 122 | } |
112 | else | 123 | else |
113 | outPut->append( tr("Exited abnormally") ); | 124 | outPut->append( tr("Exited abnormally") ); |
114 | } | 125 | } |
115 | 126 | ||
116 | void PPPDialog::closeEvent(QCloseEvent* e) | 127 | void PPPDialog::closeEvent(QCloseEvent* e) |
117 | { | 128 | { |
118 | if(PPPDialog::conns[0].proc.isRunning()) | 129 | int i; //index variable |
119 | PPPDialog::conns[0].proc.kill(); | 130 | for (i = 0; i < NCONNECTS; i++) { |
131 | if(PPPDialog::conns[i].proc.isRunning()) | ||
132 | PPPDialog::conns[i].proc.kill(); | ||
133 | } | ||
120 | QDialog::closeEvent(e); | 134 | QDialog::closeEvent(e); |
121 | } | 135 | } |
136 | |||
137 | //eof | ||
diff --git a/noncore/net/opietooth/manager/pppdialog.h b/noncore/net/opietooth/manager/pppdialog.h index 565fe1e..e0ffc7f 100644 --- a/noncore/net/opietooth/manager/pppdialog.h +++ b/noncore/net/opietooth/manager/pppdialog.h | |||
@@ -1,23 +1,24 @@ | |||
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 | ||
8 | class QVBoxLayout; | 8 | class QVBoxLayout; |
9 | class QPushButton; | 9 | class QPushButton; |
10 | class QMultiLineEdit; | 10 | class QMultiLineEdit; |
11 | class QLineEdit; | 11 | class QLineEdit; |
12 | class QComboBox; | ||
12 | #define NCONNECTS 10 //Maximal | 13 | #define NCONNECTS 10 //Maximal |
13 | 14 | ||
14 | namespace OpieTooth { | 15 | namespace OpieTooth { |
15 | typedef struct { | 16 | typedef struct { |
16 | Opie::Core::OProcess proc; //Connection process | 17 | Opie::Core::OProcess proc; //Connection process |
17 | QString btAddr; //MAC address | 18 | QString btAddr; //MAC address |
18 | int port; //port | 19 | int port; //port |
19 | } Connection; | 20 | } Connection; |
20 | 21 | ||
21 | class PPPDialog : public QDialog { | 22 | class PPPDialog : public QDialog { |
22 | 23 | ||
23 | Q_OBJECT | 24 | Q_OBJECT |
@@ -31,19 +32,20 @@ namespace OpieTooth { | |||
31 | void fillOutPut( Opie::Core::OProcess* pppDial, char* cha, int len ); | 32 | void fillOutPut( Opie::Core::OProcess* pppDial, char* cha, int len ); |
32 | void fillErr(Opie::Core::OProcess*, char*, int); | 33 | void fillErr(Opie::Core::OProcess*, char*, int); |
33 | void slotProcessExited(Opie::Core::OProcess* proc); | 34 | void slotProcessExited(Opie::Core::OProcess* proc); |
34 | void closeEvent(QCloseEvent* e); | 35 | void closeEvent(QCloseEvent* e); |
35 | public: | 36 | public: |
36 | //Array of connections indexed by rfcomm device number | 37 | //Array of connections indexed by rfcomm device number |
37 | static Connection conns[NCONNECTS]; | 38 | static Connection conns[NCONNECTS]; |
38 | protected: | 39 | protected: |
39 | QVBoxLayout* layout; | 40 | QVBoxLayout* layout; |
40 | QLineEdit* cmdLine; | 41 | QLineEdit* cmdLine; |
41 | QPushButton* connectButton; | 42 | QPushButton* connectButton; |
42 | QMultiLineEdit* outPut; | 43 | QMultiLineEdit* outPut; |
44 | QComboBox* serPort; | ||
43 | 45 | ||
44 | private: | 46 | private: |
45 | QString m_device; | 47 | QString m_device; |
46 | int m_port; | 48 | int m_port; |
47 | }; | 49 | }; |
48 | } | 50 | } |
49 | #endif | 51 | #endif |