author | korovkin <korovkin> | 2006-04-01 17:42:42 (UTC) |
---|---|---|
committer | korovkin <korovkin> | 2006-04-01 17:42:42 (UTC) |
commit | 812083469c80a0a07ad1ba41d6795e05f950710b (patch) (unidiff) | |
tree | a6a8736439877f790c9a003f86cde2af74a853a6 /noncore/net/opietooth/manager/dundialog.cpp | |
parent | 2efba75b536877b4138197af4159849e87b12bde (diff) | |
download | opie-812083469c80a0a07ad1ba41d6795e05f950710b.zip opie-812083469c80a0a07ad1ba41d6795e05f950710b.tar.gz opie-812083469c80a0a07ad1ba41d6795e05f950710b.tar.bz2 |
DUN connection parameters dialog added.
Diffstat (limited to 'noncore/net/opietooth/manager/dundialog.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/opietooth/manager/dundialog.cpp | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/noncore/net/opietooth/manager/dundialog.cpp b/noncore/net/opietooth/manager/dundialog.cpp new file mode 100644 index 0000000..033534c --- a/dev/null +++ b/noncore/net/opietooth/manager/dundialog.cpp | |||
@@ -0,0 +1,131 @@ | |||
1 | |||
2 | #include "dundialog.h" | ||
3 | #include <qpushbutton.h> | ||
4 | #include <qmultilineedit.h> | ||
5 | #include <qlineedit.h> | ||
6 | #include <qlayout.h> | ||
7 | #include <qcheckbox.h> | ||
8 | #include <qlabel.h> | ||
9 | #include <qstring.h> | ||
10 | #include <opie2/oprocess.h> | ||
11 | #include <opie2/odebug.h> | ||
12 | using namespace Opie::Core; | ||
13 | |||
14 | using namespace OpieTooth; | ||
15 | |||
16 | using namespace Opie::Core; | ||
17 | |||
18 | DunDialog::DunDialog( const QString& device, int port, QWidget* parent, | ||
19 | const char* name, bool modal, WFlags fl ) | ||
20 | : QDialog( parent, name, modal, fl ) { | ||
21 | if ( !name ) | ||
22 | setName( "DUNDialog" ); | ||
23 | setCaption( tr( "DUN connection " ) ) ; | ||
24 | |||
25 | m_device = device; | ||
26 | m_port = port; | ||
27 | |||
28 | m_dunConnect = NULL; | ||
29 | layout = new QVBoxLayout( this ); | ||
30 | |||
31 | QLabel* info = new QLabel( this ); | ||
32 | info->setText( tr("Enter an ppp script name:") ); | ||
33 | |||
34 | cmdLine = new QLineEdit( this ); | ||
35 | |||
36 | outPut = new QMultiLineEdit( this ); | ||
37 | QFont outPut_font( outPut->font() ); | ||
38 | outPut_font.setPointSize( 8 ); | ||
39 | outPut->setFont( outPut_font ); | ||
40 | outPut->setWordWrap( QMultiLineEdit::WidgetWidth ); | ||
41 | |||
42 | connectButton = new QPushButton( this ); | ||
43 | connectButton->setText( tr( "Connect" ) ); | ||
44 | |||
45 | doEncryption = new QCheckBox(this, "encrypt"); | ||
46 | doEncryption->setText( tr( "encrypt" ) ); | ||
47 | |||
48 | layout->addWidget(info); | ||
49 | layout->addWidget(cmdLine); | ||
50 | layout->addWidget(doEncryption); | ||
51 | layout->addWidget(outPut); | ||
52 | layout->addWidget(connectButton); | ||
53 | |||
54 | connect( connectButton, SIGNAL( clicked() ), this, SLOT( connectToDevice() ) ); | ||
55 | } | ||
56 | |||
57 | DunDialog::~DunDialog() { | ||
58 | } | ||
59 | |||
60 | void DunDialog::connectToDevice() { | ||
61 | bool doEnc = doEncryption->isChecked(); | ||
62 | if (cmdLine->text() == "") | ||
63 | return; | ||
64 | if (m_dunConnect) { | ||
65 | outPut->append(tr("Work in progress")); | ||
66 | return; | ||
67 | } | ||
68 | m_dunConnect = new OProcess(); | ||
69 | outPut->clear(); | ||
70 | |||
71 | // Fill process command line | ||
72 | *m_dunConnect << tr("dund") | ||
73 | << tr("--connect") << m_device | ||
74 | << tr("--channel") << QString::number(m_port) | ||
75 | << tr("--nodetach"); | ||
76 | if (doEnc) | ||
77 | *m_dunConnect << tr("--encrypt"); | ||
78 | *m_dunConnect << tr("call") | ||
79 | << cmdLine->text(); | ||
80 | if (!m_dunConnect->start(OProcess::NotifyOnExit, | ||
81 | OProcess::All)) { | ||
82 | outPut->append(tr("Couldn't start")); | ||
83 | delete m_dunConnect; | ||
84 | m_dunConnect = NULL; | ||
85 | } | ||
86 | else | ||
87 | { | ||
88 | m_dunConnect->resume(); | ||
89 | outPut->append(tr("Started")); | ||
90 | connect(m_dunConnect, | ||
91 | SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int)), | ||
92 | this, SLOT(fillOutPut(Opie::Core::OProcess*, char*, int))); | ||
93 | connect(m_dunConnect, | ||
94 | SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int)), | ||
95 | this, SLOT(fillErr(Opie::Core::OProcess*, char*, int))); | ||
96 | connect(m_dunConnect, | ||
97 | SIGNAL(processExited(Opie::Core::OProcess*)), | ||
98 | this, SLOT(slotProcessExited(Opie::Core::OProcess*))); | ||
99 | } | ||
100 | } | ||
101 | |||
102 | void DunDialog::fillOutPut( OProcess*, char* cha, int len ) { | ||
103 | QCString str(cha, len); | ||
104 | outPut->append(str); | ||
105 | } | ||
106 | |||
107 | void DunDialog::fillErr(OProcess*, char* buf, int len) | ||
108 | { | ||
109 | QCString str(buf, len); | ||
110 | outPut->append(str); | ||
111 | } | ||
112 | |||
113 | void DunDialog::slotProcessExited(OProcess* proc) { | ||
114 | if (m_dunConnect->normalExit()) { | ||
115 | outPut->append( tr("Finished with result ") ); | ||
116 | outPut->append( QString::number(proc->exitStatus()) ); | ||
117 | } | ||
118 | else | ||
119 | outPut->append( tr("Exited abnormally") ); | ||
120 | delete m_dunConnect; | ||
121 | m_dunConnect = NULL; | ||
122 | } | ||
123 | |||
124 | void DunDialog::closeEvent(QCloseEvent* e) | ||
125 | { | ||
126 | if (m_dunConnect && m_dunConnect->isRunning()) | ||
127 | m_dunConnect->kill(); | ||
128 | QDialog::closeEvent(e); | ||
129 | } | ||
130 | |||
131 | //eof | ||