author | josef <josef> | 2002-10-18 09:31:09 (UTC) |
---|---|---|
committer | josef <josef> | 2002-10-18 09:31:09 (UTC) |
commit | 997c466fd91843699280a770cbf34e6917dcee8a (patch) (unidiff) | |
tree | 5de950d62700508673b5d79e7bf6b402a3ba49f0 | |
parent | 07a1cb4baaf544e0e594040bbe8e5872ccb34c0f (diff) | |
download | opie-997c466fd91843699280a770cbf34e6917dcee8a.zip opie-997c466fd91843699280a770cbf34e6917dcee8a.tar.gz opie-997c466fd91843699280a770cbf34e6917dcee8a.tar.bz2 |
- improve dialer
It works now correctly for me :)
But a few details must be changed (i.e. no hardcoded values)
-rw-r--r-- | noncore/apps/opie-console/dialer.cpp | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/noncore/apps/opie-console/dialer.cpp b/noncore/apps/opie-console/dialer.cpp index 10c16ef..bd6b50f 100644 --- a/noncore/apps/opie-console/dialer.cpp +++ b/noncore/apps/opie-console/dialer.cpp | |||
@@ -26,251 +26,264 @@ | |||
26 | // v | | | 26 | // v | | |
27 | // (online) --+ | | 27 | // (online) --+ | |
28 | // | | | 28 | // | | |
29 | // v | | 29 | // v | |
30 | 30 | ||
31 | 31 | ||
32 | // from atconfigdialog | 32 | // from atconfigdialog |
33 | //initStringLine->setText( config.readEntry("InitString", MODEM_DEFAULT_INIT_STRING ) ); | 33 | //initStringLine->setText( config.readEntry("InitString", MODEM_DEFAULT_INIT_STRING ) ); |
34 | //resetStringLine->setText( config.readEntry("ResetString", MODEM_DEFAULT_RESET_STRING ) ); | 34 | //resetStringLine->setText( config.readEntry("ResetString", MODEM_DEFAULT_RESET_STRING ) ); |
35 | //dialPref1Line->setText( config.readEntry("DialPrefix1", MODEM_DEFAULT_DIAL_PREFIX1 ) ); | 35 | //dialPref1Line->setText( config.readEntry("DialPrefix1", MODEM_DEFAULT_DIAL_PREFIX1 ) ); |
36 | //dialSuf1Line->setText( config.readEntry("DialSuffix1", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); | 36 | //dialSuf1Line->setText( config.readEntry("DialSuffix1", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); |
37 | //dialPref2Line->setText( config.readEntry("DialPrefix2", MODEM_DEFAULT_DIAL_PREFIX1 ) ); | 37 | //dialPref2Line->setText( config.readEntry("DialPrefix2", MODEM_DEFAULT_DIAL_PREFIX1 ) ); |
38 | //dialSuf2Line->setText( config.readEntry("DialSuffix2", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); | 38 | //dialSuf2Line->setText( config.readEntry("DialSuffix2", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); |
39 | //dialPref3Line->setText( config.readEntry("DialPrefix3", MODEM_DEFAULT_DIAL_PREFIX1 ) ); | 39 | //dialPref3Line->setText( config.readEntry("DialPrefix3", MODEM_DEFAULT_DIAL_PREFIX1 ) ); |
40 | //dialSuf3Line->setText( config.readEntry("DialSuffix3", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); | 40 | //dialSuf3Line->setText( config.readEntry("DialSuffix3", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); |
41 | //connectLine->setText( config.readEntry("DefaultConnect" MODEM_DEFAULT_CONNECT_STRING ) ); | 41 | //connectLine->setText( config.readEntry("DefaultConnect" MODEM_DEFAULT_CONNECT_STRING ) ); |
42 | //hangupLine->setText( config.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING ) ); | 42 | //hangupLine->setText( config.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING ) ); |
43 | 43 | ||
44 | // from modemconfigwidget | 44 | // from modemconfigwidget |
45 | //int rad_flow = prof.readNumEntry("Flow"); | 45 | //int rad_flow = prof.readNumEntry("Flow"); |
46 | //int rad_parity = prof.readNumEntry("Parity"); | 46 | //int rad_parity = prof.readNumEntry("Parity"); |
47 | //int speed = prof.readNumEntry("Speed"); | 47 | //int speed = prof.readNumEntry("Speed"); |
48 | //QString number = prof.readEntry("Number"); | 48 | //QString number = prof.readEntry("Number"); |
49 | 49 | ||
50 | Dialer::Dialer(const Profile& profile, int fd, QWidget *parent, const char *name) | 50 | Dialer::Dialer(const Profile& profile, int fd, QWidget *parent, const char *name) |
51 | : QDialog(parent, name, true), m_fd(fd), m_profile(profile) | 51 | : QDialog(parent, name, true), m_fd(fd), m_profile(profile) |
52 | { | 52 | { |
53 | QVBoxLayout *vbox; | 53 | QVBoxLayout *vbox; |
54 | QLabel *desc; | 54 | QLabel *desc; |
55 | 55 | ||
56 | //m_profile.writeEntry("InitString", "ATZ"); | 56 | //m_profile.writeEntry("InitString", "ATZ"); |
57 | //m_profile.writeEntry("DialPrefix1", "ATDT"); | 57 | //m_profile.writeEntry("DialPrefix1", "ATDT"); |
58 | //m_profile.writeEntry("Termination", "\n"); | 58 | //m_profile.writeEntry("Termination", "\n"); |
59 | 59 | ||
60 | usercancel = 0; | 60 | usercancel = 0; |
61 | 61 | ||
62 | fcntl(m_fd, F_SETFL, O_NONBLOCK); | 62 | fcntl(m_fd, F_SETFL, O_NONBLOCK); |
63 | 63 | ||
64 | desc = new QLabel(QObject::tr("Dialing number: %1").arg(m_profile.readEntry("Number")), this); | 64 | desc = new QLabel(QObject::tr("Dialing number: %1").arg(m_profile.readEntry("Number")), this); |
65 | progress = new QProgressBar(this); | 65 | progress = new QProgressBar(this); |
66 | status = new QLabel("", this); | 66 | status = new QLabel("", this); |
67 | status->setFrameStyle(QFrame::Panel | QFrame::Sunken); | 67 | status->setFrameStyle(QFrame::Panel | QFrame::Sunken); |
68 | cancel = new QPushButton(QObject::tr("Cancel"), this); | 68 | cancel = new QPushButton(QObject::tr("Cancel"), this); |
69 | 69 | ||
70 | vbox = new QVBoxLayout(this, 2); | 70 | vbox = new QVBoxLayout(this, 2); |
71 | vbox->add(desc); | 71 | vbox->add(desc); |
72 | vbox->add(progress); | 72 | vbox->add(progress); |
73 | vbox->add(status); | 73 | vbox->add(status); |
74 | vbox->add(cancel); | 74 | vbox->add(cancel); |
75 | 75 | ||
76 | connect(cancel, SIGNAL(clicked()), SLOT(slotCancel())); | 76 | connect(cancel, SIGNAL(clicked()), SLOT(slotCancel())); |
77 | 77 | ||
78 | show(); | 78 | show(); |
79 | 79 | ||
80 | QTimer::singleShot(500, this, SLOT(slotAutostart())); | 80 | QTimer::singleShot(500, this, SLOT(slotAutostart())); |
81 | } | 81 | } |
82 | 82 | ||
83 | Dialer::~Dialer() | 83 | Dialer::~Dialer() |
84 | { | 84 | { |
85 | } | 85 | } |
86 | 86 | ||
87 | void Dialer::slotCancel() | 87 | void Dialer::slotCancel() |
88 | { | 88 | { |
89 | if(state != state_online) | 89 | if(state != state_online) |
90 | { | 90 | { |
91 | usercancel = 1; | 91 | usercancel = 1; |
92 | reset(); | 92 | reset(); |
93 | } | 93 | } |
94 | else accept(); | 94 | else accept(); |
95 | } | 95 | } |
96 | 96 | ||
97 | void Dialer::reset() | 97 | void Dialer::reset() |
98 | { | 98 | { |
99 | switchState(state_cancel); | 99 | switchState(state_cancel); |
100 | } | 100 | } |
101 | 101 | ||
102 | void Dialer::slotAutostart() | 102 | void Dialer::slotAutostart() |
103 | { | 103 | { |
104 | //state = state_preinit; | 104 | //state = state_preinit; |
105 | dial(m_profile.readEntry("Number")); | 105 | dial(m_profile.readEntry("Number")); |
106 | } | 106 | } |
107 | 107 | ||
108 | void Dialer::dial(const QString& number) | 108 | void Dialer::dial(const QString& number) |
109 | { | 109 | { |
110 | while(state != state_online) | 110 | while(state != state_online) |
111 | { | 111 | { |
112 | if(!usercancel) | 112 | if(!usercancel) |
113 | { | 113 | { |
114 | state = state_preinit; | 114 | state = state_preinit; |
115 | trydial(number); | 115 | trydial(number); |
116 | } | 116 | } |
117 | else break; | 117 | else break; |
118 | } | 118 | } |
119 | 119 | ||
120 | if(usercancel) | 120 | if(usercancel) |
121 | { | 121 | { |
122 | // modem hangup | ||
123 | trydial(QString::null); | ||
122 | reject(); | 124 | reject(); |
123 | } | 125 | } |
124 | } | 126 | } |
125 | 127 | ||
126 | void Dialer::trydial(const QString& number) | 128 | void Dialer::trydial(const QString& number) |
127 | { | 129 | { |
128 | if(state != state_cancel) | 130 | //if(state != state_cancel) |
129 | { | 131 | //{ |
130 | switchState(state_preinit); | 132 | if(state != state_cancel) switchState(state_preinit); |
131 | send("+++ATH"); | 133 | send("+++ATH"); |
132 | send(""); | 134 | send(""); |
133 | //QString response = receive(); | 135 | //QString response = receive(); |
134 | } | 136 | //} |
135 | 137 | ||
136 | if(state != state_cancel) | 138 | if(state != state_cancel) |
137 | { | 139 | { |
138 | switchState(state_init); | 140 | switchState(state_init); |
139 | send("ATZ"); | 141 | send("ATZ"); |
140 | //send(m_profile.readEntry("InitString")); | 142 | //send(m_profile.readEntry("InitString")); |
141 | QString response2 = receive(); | 143 | QString response2 = receive(); |
142 | if(!response2.contains("\nOK\r")) | 144 | if(!response2.contains("\nOK\r")) |
143 | reset(); | 145 | reset(); |
144 | } | 146 | } |
145 | 147 | ||
146 | if(state != state_cancel) | 148 | if(state != state_cancel) |
147 | { | 149 | { |
148 | switchState(state_options); | 150 | switchState(state_options); |
149 | 151 | ||
150 | send("ATM0L0"); | 152 | send("ATM3L3"); |
151 | QString response3 = receive(); | 153 | QString response3 = receive(); |
152 | if(!response3.contains("\nOK\r")) | 154 | if(!response3.contains("\nOK\r")) |
153 | reset(); | 155 | reset(); |
154 | } | 156 | } |
155 | 157 | ||
156 | if(state != state_cancel) | 158 | if(state != state_cancel) |
157 | { | 159 | { |
158 | switchState(state_dialtone); | 160 | switchState(state_dialtone); |
159 | 161 | ||
160 | send("ATX1"); | 162 | send("ATX1"); |
161 | QString response4 = receive(); | 163 | QString response4 = receive(); |
162 | if(!response4.contains("\nOK\r")) | 164 | if(!response4.contains("\nOK\r")) |
163 | reset(); | 165 | reset(); |
164 | } | 166 | } |
165 | 167 | ||
166 | if(state != state_cancel) | 168 | if(state != state_cancel) |
167 | { | 169 | { |
168 | switchState(state_dialing); | 170 | switchState(state_dialing); |
169 | 171 | ||
170 | send(QString("ATDT %1").arg(number)); | 172 | send(QString("ATDT %1").arg(number)); |
171 | //send(QString("%1 %2").arg(m_profile.readEntry("DialPrefix1")).arg(number)); | 173 | //send(QString("%1 %2").arg(m_profile.readEntry("DialPrefix1")).arg(number)); |
172 | QString response5 = receive(); | 174 | QString response5 = receive(); |
173 | if(!response5.contains("\nOK\r")) | 175 | if(!response5.contains("\nCONNECT")) |
174 | { | 176 | { |
175 | QMessageBox::warning(this, | 177 | if(response5.contains("BUSY")) |
176 | QObject::tr("Failure"), | 178 | switchState(state_dialing); |
177 | QObject::tr("Dialing the number failed.")); | 179 | else |
178 | slotCancel(); | 180 | { |
181 | QMessageBox::warning(this, | ||
182 | QObject::tr("Failure"), | ||
183 | QObject::tr("Dialing the number failed.")); | ||
184 | slotCancel(); | ||
185 | } | ||
179 | } | 186 | } |
180 | } | 187 | } |
181 | 188 | ||
182 | if(state != state_cancel) | 189 | if(state != state_cancel) |
183 | { | 190 | { |
184 | switchState(state_online); | 191 | switchState(state_online); |
185 | } | 192 | } |
186 | } | 193 | } |
187 | 194 | ||
188 | void Dialer::send(const QString& msg) | 195 | void Dialer::send(const QString& msg) |
189 | { | 196 | { |
190 | QString m = msg; | 197 | QString m = msg; |
191 | int bytes; | 198 | int bytes; |
192 | QString termination; | 199 | QString termination; |
193 | 200 | ||
194 | qWarning("Sending: '%s'", m.latin1()); | 201 | qWarning("Sending: '%s'", m.latin1()); |
195 | 202 | ||
196 | termination = "\r"; | 203 | termination = "\r"; |
197 | //termination = m_profile.readEntry("Termination"); | 204 | //termination = m_profile.readEntry("Termination"); |
198 | if(termination == "\n") m = m + "\n"; | 205 | if(termination == "\n") m = m + "\n"; |
199 | else if(termination == "\r") m = m + "\r"; | 206 | else if(termination == "\r") m = m + "\r"; |
200 | else m = m + "\r\n"; | 207 | else m = m + "\r\n"; |
201 | 208 | ||
202 | bytes = ::write(m_fd, m.local8Bit(), strlen(m.local8Bit())); | 209 | bytes = ::write(m_fd, m.local8Bit(), strlen(m.local8Bit())); |
203 | if(bytes < 0) | 210 | if(bytes < 0) |
204 | { | 211 | { |
205 | reset(); | 212 | reset(); |
206 | } | 213 | } |
207 | } | 214 | } |
208 | 215 | ||
209 | QString Dialer::receive() | 216 | QString Dialer::receive() |
210 | { | 217 | { |
218 | QString buf; | ||
211 | char buffer[1024]; | 219 | char buffer[1024]; |
212 | int ret; | 220 | int ret; |
213 | 221 | ||
222 | qApp->processEvents(); | ||
223 | |||
214 | while(1) | 224 | while(1) |
215 | { | 225 | { |
216 | ret = ::read(m_fd, buffer, sizeof(buffer)); | 226 | ret = ::read(m_fd, buffer, sizeof(buffer)); |
217 | 227 | ||
218 | if(ret > 0) | 228 | if(ret > 0) |
219 | { | 229 | { |
220 | for(int i = 0; i < ret; i++) | 230 | for(int i = 0; i < ret; i++) |
221 | buffer[i] = buffer[i] & 0x7F; | 231 | buffer[i] = buffer[i] & 0x7F; |
222 | buffer[ret] = 0; | 232 | buffer[ret] = 0; |
223 | qWarning("Receiving: '%s'", buffer); | 233 | qWarning("Got: '%s'", buffer); |
224 | return QString(buffer); | 234 | buf.append(QString(buffer)); |
235 | if(buf.contains("OK") || buf.contains("ERROR") || buf.contains("CONNECT") || (buf.contains("BUSY"))) | ||
236 | { | ||
237 | qWarning("Receiving: '%s'", buf.latin1()); | ||
238 | return buf; | ||
239 | } | ||
225 | } | 240 | } |
226 | else if(ret < 0) | 241 | else if(ret < 0) |
227 | { | 242 | { |
228 | if(errno != EAGAIN) reset(); | 243 | if(errno != EAGAIN) reset(); |
229 | } | 244 | } |
230 | } | 245 | } |
231 | 246 | ||
232 | //for(int i = 0; i < 200000;i++) | ||
233 | //qApp->processEvents(); | ||
234 | return QString::null; | 247 | return QString::null; |
235 | } | 248 | } |
236 | 249 | ||
237 | void Dialer::switchState(int newstate) | 250 | void Dialer::switchState(int newstate) |
238 | { | 251 | { |
239 | int oldstate = state; | 252 | int oldstate = state; |
240 | state = newstate; | 253 | state = newstate; |
241 | 254 | ||
242 | switch(state) | 255 | switch(state) |
243 | { | 256 | { |
244 | case state_cancel: | 257 | case state_cancel: |
245 | status->setText(QObject::tr("Cancelling...")); | 258 | status->setText(QObject::tr("Cancelling...")); |
246 | progress->setProgress(0); | 259 | progress->setProgress(0); |
247 | break; | 260 | break; |
248 | case state_preinit: | 261 | case state_preinit: |
249 | status->setText(QObject::tr("Searching modem")); | 262 | status->setText(QObject::tr("Searching modem")); |
250 | progress->setProgress(10); | 263 | progress->setProgress(10); |
251 | break; | 264 | break; |
252 | case state_init: | 265 | case state_init: |
253 | status->setText(QObject::tr("Initializing...")); | 266 | status->setText(QObject::tr("Initializing...")); |
254 | progress->setProgress(20); | 267 | progress->setProgress(20); |
255 | break; | 268 | break; |
256 | case state_options: | 269 | case state_options: |
257 | status->setText(QObject::tr("Reset speakers")); | 270 | status->setText(QObject::tr("Reset speakers")); |
258 | progress->setProgress(30); | 271 | progress->setProgress(30); |
259 | break; | 272 | break; |
260 | case state_dialtone: | 273 | case state_dialtone: |
261 | status->setText(QObject::tr("Turning off dialtone")); | 274 | status->setText(QObject::tr("Turning off dialtone")); |
262 | progress->setProgress(40); | 275 | progress->setProgress(40); |
263 | break; | 276 | break; |
264 | case state_dialing: | 277 | case state_dialing: |
265 | if(oldstate != state_dialing) status->setText(QObject::tr("Dial number")); | 278 | if(oldstate != state_dialing) status->setText(QObject::tr("Dial number")); |
266 | else status->setText(QObject::tr("Line busy, redialing number")); | 279 | else status->setText(QObject::tr("Line busy, redialing number")); |
267 | progress->setProgress(50); | 280 | progress->setProgress(50); |
268 | break; | 281 | break; |
269 | case state_online: | 282 | case state_online: |
270 | status->setText(QObject::tr("Connection established")); | 283 | status->setText(QObject::tr("Connection established")); |
271 | progress->setProgress(100); | 284 | progress->setProgress(100); |
272 | cancel->setText(QObject::tr("Dismiss")); | 285 | cancel->setText(QObject::tr("Dismiss")); |
273 | break; | 286 | break; |
274 | } | 287 | } |
275 | } | 288 | } |
276 | 289 | ||