author | josef <josef> | 2002-10-13 15:11:18 (UTC) |
---|---|---|
committer | josef <josef> | 2002-10-13 15:11:18 (UTC) |
commit | 5db679753dac04095a2fa4b03297785ed4ba4030 (patch) (unidiff) | |
tree | f54ffa84bbe6fdbd15b227a0b04667714ce9106c | |
parent | f45beb0cf615324c01d09560139174e95eb72e34 (diff) | |
download | opie-5db679753dac04095a2fa4b03297785ed4ba4030.zip opie-5db679753dac04095a2fa4b03297785ed4ba4030.tar.gz opie-5db679753dac04095a2fa4b03297785ed4ba4030.tar.bz2 |
- implement better state machine, with explanation
- command order as used in kppp's connect.cpp
-rw-r--r-- | noncore/apps/opie-console/dialer.cpp | 121 | ||||
-rw-r--r-- | noncore/apps/opie-console/dialer.h | 7 |
2 files changed, 109 insertions, 19 deletions
diff --git a/noncore/apps/opie-console/dialer.cpp b/noncore/apps/opie-console/dialer.cpp index f6758ed..8589d14 100644 --- a/noncore/apps/opie-console/dialer.cpp +++ b/noncore/apps/opie-console/dialer.cpp | |||
@@ -1,106 +1,189 @@ | |||
1 | #include "dialer.h" | 1 | #include "dialer.h" |
2 | 2 | ||
3 | #include <qlayout.h> | 3 | #include <qlayout.h> |
4 | #include <qprogressbar.h> | 4 | #include <qprogressbar.h> |
5 | #include <qlabel.h> | 5 | #include <qlabel.h> |
6 | #include <qpushbutton.h> | 6 | #include <qpushbutton.h> |
7 | #include <qapp.h> | 7 | #include <qapp.h> |
8 | #include <qtimer.h> | ||
9 | |||
10 | // State machine: | When an error occurs, we don't have to | ||
11 | // | reset everything. | ||
12 | // (init) <------+ | But if the user wants to reset, | ||
13 | // | | | we stop dialing immediately. | ||
14 | // v | | | ||
15 | // (options) ----+ | Following the state machine is necessary | ||
16 | // | \ | to get determinable results. | ||
17 | // v ^ | | ||
18 | // (dial) ----+ | | ||
19 | // | ^ | | ||
20 | // v | | | ||
21 | // (online) --+ | | ||
22 | // | | | ||
23 | // v | | ||
8 | 24 | ||
9 | Dialer::Dialer(const QString& number, QWidget *parent, const char *name) | 25 | Dialer::Dialer(const QString& number, QWidget *parent, const char *name) |
10 | : QDialog(parent, name, true) | 26 | : QDialog(parent, name, true) |
11 | { | 27 | { |
12 | QVBoxLayout *vbox; | 28 | QVBoxLayout *vbox; |
13 | QLabel *desc; | 29 | QLabel *desc; |
14 | 30 | ||
31 | usercancel = 0; | ||
32 | m_number = number; | ||
33 | |||
15 | desc = new QLabel(QObject::tr("Dialing number: %1").arg(number), this); | 34 | desc = new QLabel(QObject::tr("Dialing number: %1").arg(number), this); |
16 | progress = new QProgressBar(this); | 35 | progress = new QProgressBar(this); |
17 | status = new QLabel("", this); | 36 | status = new QLabel("", this); |
18 | status->setFrameStyle(QFrame::Panel | QFrame::Sunken); | 37 | status->setFrameStyle(QFrame::Panel | QFrame::Sunken); |
19 | cancel = new QPushButton(QObject::tr("Cancel"), this); | 38 | cancel = new QPushButton(QObject::tr("Cancel"), this); |
20 | 39 | ||
21 | vbox = new QVBoxLayout(this, 2); | 40 | vbox = new QVBoxLayout(this, 2); |
22 | vbox->add(desc); | 41 | vbox->add(desc); |
23 | vbox->add(progress); | 42 | vbox->add(progress); |
24 | vbox->add(status); | 43 | vbox->add(status); |
25 | vbox->add(cancel); | 44 | vbox->add(cancel); |
26 | 45 | ||
27 | reset(); | ||
28 | |||
29 | connect(cancel, SIGNAL(clicked()), SLOT(slotCancel())); | 46 | connect(cancel, SIGNAL(clicked()), SLOT(slotCancel())); |
30 | 47 | ||
31 | show(); | 48 | show(); |
32 | 49 | ||
33 | dial(number); | 50 | QTimer::singleShot(500, this, SLOT(slotAutostart())); |
34 | } | 51 | } |
35 | 52 | ||
36 | Dialer::~Dialer() | 53 | Dialer::~Dialer() |
37 | { | 54 | { |
38 | } | 55 | } |
39 | 56 | ||
40 | void Dialer::slotCancel() | 57 | void Dialer::slotCancel() |
41 | { | 58 | { |
42 | if(state != state_online) reset(); | 59 | if(state != state_online) reset(); |
43 | close(); | 60 | else accept(); |
44 | } | 61 | } |
45 | 62 | ||
46 | void Dialer::reset() | 63 | void Dialer::reset() |
47 | { | 64 | { |
48 | switchState(state_init); | 65 | switchState(state_cancel); |
66 | usercancel = 1; | ||
67 | } | ||
68 | |||
69 | void Dialer::slotAutostart() | ||
70 | { | ||
71 | state = state_preinit; | ||
72 | dial(m_number); | ||
49 | } | 73 | } |
50 | 74 | ||
51 | void Dialer::dial(const QString& number) | 75 | void Dialer::dial(const QString& number) |
52 | { | 76 | { |
53 | send("ATZ"); | 77 | while(state != state_online) |
54 | QString response = receive(); | 78 | { |
79 | if(!usercancel) | ||
80 | { | ||
81 | trydial(number); | ||
82 | } | ||
83 | else break; | ||
84 | } | ||
85 | |||
86 | if(usercancel) | ||
87 | { | ||
88 | reject(); | ||
89 | } | ||
90 | } | ||
91 | |||
92 | void Dialer::trydial(const QString& number) | ||
93 | { | ||
94 | if(state != state_cancel) | ||
95 | { | ||
96 | switchState(state_preinit); | ||
97 | // ... | ||
98 | QString response = receive(); | ||
99 | } | ||
100 | |||
101 | if(state != state_cancel) | ||
102 | { | ||
103 | switchState(state_init); | ||
104 | send("ATZ"); | ||
105 | QString response2 = receive(); | ||
106 | } | ||
55 | 107 | ||
56 | switchState(state_options); | 108 | if(state != state_cancel) |
109 | { | ||
110 | switchState(state_options); | ||
57 | 111 | ||
58 | send("ATM0L0"); | 112 | send("ATM0L0"); |
59 | QString response2 = receive(); | 113 | QString response3 = receive(); |
114 | } | ||
60 | 115 | ||
61 | switchState(state_dialing); | 116 | if(state != state_cancel) |
117 | { | ||
118 | switchState(state_dialtone); | ||
62 | 119 | ||
63 | send(QString("ATDT %1").arg(number)); | 120 | send("ATX1"); |
64 | QString response3 = receive(); | 121 | QString response4 = receive(); |
122 | } | ||
65 | 123 | ||
66 | switchState(state_online); | 124 | if(state != state_cancel) |
125 | { | ||
126 | switchState(state_dialing); | ||
127 | |||
128 | send(QString("ATDT %1").arg(number)); | ||
129 | QString response5 = receive(); | ||
130 | } | ||
131 | |||
132 | if(state != state_cancel) | ||
133 | { | ||
134 | switchState(state_online); | ||
135 | } | ||
67 | } | 136 | } |
68 | 137 | ||
69 | void Dialer::send(const QString& msg) | 138 | void Dialer::send(const QString& msg) |
70 | { | 139 | { |
71 | 140 | ||
72 | } | 141 | } |
73 | 142 | ||
74 | QString Dialer::receive() | 143 | QString Dialer::receive() |
75 | { | 144 | { |
76 | for(int i = 0; i < 200000; i++) | 145 | for(int i = 0; i < 200000;i++) |
77 | qApp->processEvents(); | 146 | qApp->processEvents(); |
78 | return QString::null; | 147 | return QString::null; |
79 | } | 148 | } |
80 | 149 | ||
81 | void Dialer::switchState(int newstate) | 150 | void Dialer::switchState(int newstate) |
82 | { | 151 | { |
152 | int oldstate = state; | ||
83 | state = newstate; | 153 | state = newstate; |
84 | 154 | ||
85 | switch(state) | 155 | switch(state) |
86 | { | 156 | { |
157 | case state_cancel: | ||
158 | status->setText(QObject::tr("Cancelling...")); | ||
159 | progress->setProgress(0); | ||
160 | break; | ||
161 | case state_preinit: | ||
162 | status->setText(QObject::tr("Searching modem")); | ||
163 | progress->setProgress(10); | ||
164 | break; | ||
87 | case state_init: | 165 | case state_init: |
88 | status->setText(QObject::tr("Initializing...")); | 166 | status->setText(QObject::tr("Initializing...")); |
89 | progress->setProgress(10); | 167 | progress->setProgress(20); |
90 | break; | 168 | break; |
91 | case state_options: | 169 | case state_options: |
92 | status->setText(QObject::tr("Reset speakers")); | 170 | status->setText(QObject::tr("Reset speakers")); |
93 | progress->setProgress(20); | 171 | progress->setProgress(30); |
172 | break; | ||
173 | case state_dialtone: | ||
174 | status->setText(QObject::tr("Turning off dialtone")); | ||
175 | progress->setProgress(40); | ||
94 | break; | 176 | break; |
95 | case state_dialing: | 177 | case state_dialing: |
96 | status->setText(QObject::tr("Dial number")); | 178 | if(oldstate != state_dialing) status->setText(QObject::tr("Dial number")); |
97 | progress->setProgress(30); | 179 | else status->setText(QObject::tr("Line busy, redialing number")); |
180 | progress->setProgress(50); | ||
98 | break; | 181 | break; |
99 | case state_online: | 182 | case state_online: |
100 | status->setText(QObject::tr("Connection established")); | 183 | status->setText(QObject::tr("Connection established")); |
101 | progress->setProgress(100); | 184 | progress->setProgress(100); |
102 | cancel->setText(QObject::tr("Dismiss")); | 185 | cancel->setText(QObject::tr("Dismiss")); |
103 | break; | 186 | break; |
104 | } | 187 | } |
105 | } | 188 | } |
106 | 189 | ||
diff --git a/noncore/apps/opie-console/dialer.h b/noncore/apps/opie-console/dialer.h index f07f110..20fb3c3 100644 --- a/noncore/apps/opie-console/dialer.h +++ b/noncore/apps/opie-console/dialer.h | |||
@@ -1,42 +1,49 @@ | |||
1 | #ifndef DIALER_H | 1 | #ifndef DIALER_H |
2 | #define DIALER_H | 2 | #define DIALER_H |
3 | 3 | ||
4 | #include <qdialog.h> | 4 | #include <qdialog.h> |
5 | 5 | ||
6 | class QLabel; | 6 | class QLabel; |
7 | class QProgressBar; | 7 | class QProgressBar; |
8 | 8 | ||
9 | class Dialer : public QDialog | 9 | class Dialer : public QDialog |
10 | { | 10 | { |
11 | Q_OBJECT | 11 | Q_OBJECT |
12 | public: | 12 | public: |
13 | Dialer(const QString& number, QWidget *parent = NULL, const char *name = NULL); | 13 | Dialer(const QString& number, QWidget *parent = NULL, const char *name = NULL); |
14 | ~Dialer(); | 14 | ~Dialer(); |
15 | 15 | ||
16 | public slots: | 16 | public slots: |
17 | void slotCancel(); | 17 | void slotCancel(); |
18 | void slotAutostart(); | ||
18 | 19 | ||
19 | private: | 20 | private: |
20 | void switchState(int newstate); | 21 | void switchState(int newstate); |
21 | void reset(); | 22 | void reset(); |
22 | void dial(const QString& number); | 23 | void dial(const QString& number); |
24 | void trydial(const QString& number); | ||
23 | 25 | ||
24 | void send(const QString& msg); | 26 | void send(const QString& msg); |
25 | QString receive(); | 27 | QString receive(); |
26 | 28 | ||
27 | enum States | 29 | enum States |
28 | { | 30 | { |
31 | state_cancel, | ||
32 | state_preinit, | ||
29 | state_init, | 33 | state_init, |
30 | state_options, | 34 | state_options, |
35 | state_dialtone, | ||
31 | state_dialing, | 36 | state_dialing, |
32 | state_online | 37 | state_online |
33 | }; | 38 | }; |
34 | 39 | ||
35 | QLabel *status; | 40 | QLabel *status; |
36 | QProgressBar *progress; | 41 | QProgressBar *progress; |
37 | QPushButton *cancel; | 42 | QPushButton *cancel; |
38 | int state; | 43 | int state; |
44 | int usercancel; | ||
45 | QString m_number; | ||
39 | }; | 46 | }; |
40 | 47 | ||
41 | #endif | 48 | #endif |
42 | 49 | ||