summaryrefslogtreecommitdiff
path: root/noncore/apps
authorjosef <josef>2002-10-13 15:11:18 (UTC)
committer josef <josef>2002-10-13 15:11:18 (UTC)
commit5db679753dac04095a2fa4b03297785ed4ba4030 (patch) (unidiff)
treef54ffa84bbe6fdbd15b227a0b04667714ce9106c /noncore/apps
parentf45beb0cf615324c01d09560139174e95eb72e34 (diff)
downloadopie-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
Diffstat (limited to 'noncore/apps') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/dialer.cpp121
-rw-r--r--noncore/apps/opie-console/dialer.h7
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
@@ -5,6 +5,22 @@
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
9Dialer::Dialer(const QString& number, QWidget *parent, const char *name) 25Dialer::Dialer(const QString& number, QWidget *parent, const char *name)
10: QDialog(parent, name, true) 26: QDialog(parent, name, true)
@@ -12,6 +28,9 @@ Dialer::Dialer(const QString& number, QWidget *parent, const char *name)
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);
@@ -24,13 +43,11 @@ Dialer::Dialer(const QString& number, QWidget *parent, const char *name)
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
36Dialer::~Dialer() 53Dialer::~Dialer()
@@ -40,30 +57,82 @@ Dialer::~Dialer()
40void Dialer::slotCancel() 57void 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
46void Dialer::reset() 63void Dialer::reset()
47{ 64{
48 switchState(state_init); 65 switchState(state_cancel);
66 usercancel = 1;
67}
68
69void Dialer::slotAutostart()
70{
71 state = state_preinit;
72 dial(m_number);
49} 73}
50 74
51void Dialer::dial(const QString& number) 75void 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
92void 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
69void Dialer::send(const QString& msg) 138void Dialer::send(const QString& msg)
@@ -73,28 +142,42 @@ void Dialer::send(const QString& msg)
73 142
74QString Dialer::receive() 143QString 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
81void Dialer::switchState(int newstate) 150void 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"));
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
@@ -15,19 +15,24 @@ class Dialer : public QDialog
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 };
@@ -36,6 +41,8 @@ class Dialer : public QDialog
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