author | josef <josef> | 2002-10-20 09:48:21 (UTC) |
---|---|---|
committer | josef <josef> | 2002-10-20 09:48:21 (UTC) |
commit | 940ba90ed4375f79b6a4934d290abf83980b77ad (patch) (unidiff) | |
tree | c455e88ce9fe99ef79048e3f228b7f4551652537 /noncore/apps/opie-console/dialer.cpp | |
parent | e2694c5aedb3697a373e363cebe72cddb3114a8f (diff) | |
download | opie-940ba90ed4375f79b6a4934d290abf83980b77ad.zip opie-940ba90ed4375f79b6a4934d290abf83980b77ad.tar.gz opie-940ba90ed4375f79b6a4934d290abf83980b77ad.tar.bz2 |
Please review!
- change modem default commands because we don't interpret ~ and friends
(minicom does AFAIK)
- disable unused AT settings for now
- when cancelling dialing, and we didn't yet get a single byte from the modem,
don't hangup
Diffstat (limited to 'noncore/apps/opie-console/dialer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-console/dialer.cpp | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/noncore/apps/opie-console/dialer.cpp b/noncore/apps/opie-console/dialer.cpp index 51d4093..d37e406 100644 --- a/noncore/apps/opie-console/dialer.cpp +++ b/noncore/apps/opie-console/dialer.cpp | |||
@@ -49,24 +49,25 @@ | |||
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 | cleanshutdown = 0; | ||
61 | 62 | ||
62 | fcntl(m_fd, F_SETFL, O_NONBLOCK); | 63 | fcntl(m_fd, F_SETFL, O_NONBLOCK); |
63 | 64 | ||
64 | desc = new QLabel(QObject::tr("Dialing number: %1").arg(m_profile.readEntry("Number")), this); | 65 | desc = new QLabel(QObject::tr("Dialing number: %1").arg(m_profile.readEntry("Number")), this); |
65 | progress = new QProgressBar(this); | 66 | progress = new QProgressBar(this); |
66 | status = new QLabel("", this); | 67 | status = new QLabel("", this); |
67 | status->setFrameStyle(QFrame::Panel | QFrame::Sunken); | 68 | status->setFrameStyle(QFrame::Panel | QFrame::Sunken); |
68 | cancel = new QPushButton(QObject::tr("Cancel"), this); | 69 | cancel = new QPushButton(QObject::tr("Cancel"), this); |
69 | 70 | ||
70 | vbox = new QVBoxLayout(this, 2); | 71 | vbox = new QVBoxLayout(this, 2); |
71 | vbox->add(desc); | 72 | vbox->add(desc); |
72 | vbox->add(progress); | 73 | vbox->add(progress); |
@@ -124,37 +125,37 @@ void Dialer::dial(const QString& number) | |||
124 | } | 125 | } |
125 | 126 | ||
126 | if(usercancel) | 127 | if(usercancel) |
127 | { | 128 | { |
128 | // modem hangup | 129 | // modem hangup |
129 | trydial(QString::null); | 130 | trydial(QString::null); |
130 | reject(); | 131 | reject(); |
131 | } | 132 | } |
132 | } | 133 | } |
133 | 134 | ||
134 | void Dialer::trydial(const QString& number) | 135 | void Dialer::trydial(const QString& number) |
135 | { | 136 | { |
136 | //if(state != state_cancel) | 137 | if(state != state_cancel) switchState(state_preinit); |
137 | //{ | 138 | if(cleanshutdown) |
138 | if(state != state_cancel) switchState(state_preinit); | 139 | { |
139 | send("+++ATH"); | 140 | send(m_profile.readEntry("HangupString")); |
141 | //send("+++ATH"); | ||
140 | send(""); | 142 | send(""); |
141 | //QString response = receive(); | 143 | } |
142 | //} | ||
143 | 144 | ||
144 | if(state != state_cancel) | 145 | if(state != state_cancel) |
145 | { | 146 | { |
146 | switchState(state_init); | 147 | switchState(state_init); |
147 | send("ATZ"); | 148 | //send("ATZ"); |
148 | //send(m_profile.readEntry("InitString")); | 149 | send(m_profile.readEntry("InitString")); |
149 | QString response2 = receive(); | 150 | QString response2 = receive(); |
150 | if(!response2.contains("\nOK\r")) | 151 | if(!response2.contains("\nOK\r")) |
151 | reset(); | 152 | reset(); |
152 | } | 153 | } |
153 | 154 | ||
154 | if(state != state_cancel) | 155 | if(state != state_cancel) |
155 | { | 156 | { |
156 | switchState(state_options); | 157 | switchState(state_options); |
157 | 158 | ||
158 | send("ATM3L3"); | 159 | send("ATM3L3"); |
159 | QString response3 = receive(); | 160 | QString response3 = receive(); |
160 | if(!response3.contains("\nOK\r")) | 161 | if(!response3.contains("\nOK\r")) |
@@ -166,28 +167,28 @@ void Dialer::trydial(const QString& number) | |||
166 | switchState(state_dialtone); | 167 | switchState(state_dialtone); |
167 | 168 | ||
168 | send("ATX1"); | 169 | send("ATX1"); |
169 | QString response4 = receive(); | 170 | QString response4 = receive(); |
170 | if(!response4.contains("\nOK\r")) | 171 | if(!response4.contains("\nOK\r")) |
171 | reset(); | 172 | reset(); |
172 | } | 173 | } |
173 | 174 | ||
174 | if(state != state_cancel) | 175 | if(state != state_cancel) |
175 | { | 176 | { |
176 | switchState(state_dialing); | 177 | switchState(state_dialing); |
177 | 178 | ||
178 | send(QString("ATDT %1").arg(number)); | 179 | //send(QString("ATDT %1").arg(number)); |
179 | //send(QString("%1 %2").arg(m_profile.readEntry("DialPrefix1")).arg(number)); | 180 | send(QString("%1 %2").arg(m_profile.readEntry("DialPrefix1")).arg(number)); |
180 | QString response5 = receive(); | 181 | QString response5 = receive(); |
181 | if(!response5.contains("\nCONNECT")) | 182 | if(!response5.contains("\n" + m_profile.readEntry("DefaultConnect"))) |
182 | { | 183 | { |
183 | if(response5.contains("BUSY")) | 184 | if(response5.contains("BUSY")) |
184 | switchState(state_dialing); | 185 | switchState(state_dialing); |
185 | else | 186 | else |
186 | { | 187 | { |
187 | QMessageBox::warning(this, | 188 | QMessageBox::warning(this, |
188 | QObject::tr("Failure"), | 189 | QObject::tr("Failure"), |
189 | QObject::tr("Dialing the number failed.")); | 190 | QObject::tr("Dialing the number failed.")); |
190 | slotCancel(); | 191 | slotCancel(); |
191 | } | 192 | } |
192 | } | 193 | } |
193 | } | 194 | } |
@@ -195,25 +196,25 @@ void Dialer::trydial(const QString& number) | |||
195 | if(state != state_cancel) | 196 | if(state != state_cancel) |
196 | { | 197 | { |
197 | switchState(state_online); | 198 | switchState(state_online); |
198 | } | 199 | } |
199 | } | 200 | } |
200 | 201 | ||
201 | void Dialer::send(const QString& msg) | 202 | void Dialer::send(const QString& msg) |
202 | { | 203 | { |
203 | QString m = msg; | 204 | QString m = msg; |
204 | int bytes; | 205 | int bytes; |
205 | QString termination; | 206 | QString termination; |
206 | 207 | ||
207 | qWarning("Sending: '%s'", m.latin1()); | 208 | //qWarning("Sending: '%s'", m.latin1()); |
208 | 209 | ||
209 | termination = "\r"; | 210 | termination = "\r"; |
210 | //termination = m_profile.readEntry("Termination"); | 211 | //termination = m_profile.readEntry("Termination"); |
211 | if(termination == "\n") m = m + "\n"; | 212 | if(termination == "\n") m = m + "\n"; |
212 | else if(termination == "\r") m = m + "\r"; | 213 | else if(termination == "\r") m = m + "\r"; |
213 | else m = m + "\r\n"; | 214 | else m = m + "\r\n"; |
214 | 215 | ||
215 | bytes = ::write(m_fd, m.local8Bit(), strlen(m.local8Bit())); | 216 | bytes = ::write(m_fd, m.local8Bit(), strlen(m.local8Bit())); |
216 | if(bytes < 0) | 217 | if(bytes < 0) |
217 | { | 218 | { |
218 | reset(); | 219 | reset(); |
219 | } | 220 | } |
@@ -226,40 +227,44 @@ QString Dialer::receive() | |||
226 | int ret; | 227 | int ret; |
227 | int counter; | 228 | int counter; |
228 | 229 | ||
229 | while(1) | 230 | while(1) |
230 | { | 231 | { |
231 | ret = ::read(m_fd, buffer, sizeof(buffer)); | 232 | ret = ::read(m_fd, buffer, sizeof(buffer)); |
232 | 233 | ||
233 | if(ret > 0) | 234 | if(ret > 0) |
234 | { | 235 | { |
235 | for(int i = 0; i < ret; i++) | 236 | for(int i = 0; i < ret; i++) |
236 | buffer[i] = buffer[i] & 0x7F; | 237 | buffer[i] = buffer[i] & 0x7F; |
237 | buffer[ret] = 0; | 238 | buffer[ret] = 0; |
238 | qWarning("Got: '%s'", buffer); | 239 | //qWarning("Got: '%s'", buffer); |
239 | buf.append(QString(buffer)); | 240 | buf.append(QString(buffer)); |
240 | if(buf.contains("OK") || buf.contains("ERROR") || buf.contains("CONNECT") || (buf.contains("BUSY"))) | 241 | if(buf.contains("OK") || buf.contains("ERROR") || buf.contains("CONNECT") || (buf.contains("BUSY"))) |
241 | { | 242 | { |
242 | qWarning("Receiving: '%s'", buf.latin1()); | 243 | //qWarning("Receiving: '%s'", buf.latin1()); |
244 | cleanshutdown = 1; | ||
243 | return buf; | 245 | return buf; |
244 | } | 246 | } |
245 | } | 247 | } |
246 | else if(ret < 0) | 248 | else if(ret < 0) |
247 | { | 249 | { |
248 | if(errno != EAGAIN) reset(); | 250 | if(errno != EAGAIN) reset(); |
249 | else if(!(counter++ % 100)) qApp->processEvents(); | 251 | else if(!(counter++ % 100)) qApp->processEvents(); |
250 | } | 252 | } |
251 | else if(!(counter++ % 100)) qApp->processEvents(); | 253 | else if(!(counter++ % 100)) qApp->processEvents(); |
254 | |||
255 | if(usercancel) return QString::null; | ||
252 | } | 256 | } |
253 | 257 | ||
258 | cleanshutdown = 1; | ||
254 | return QString::null; | 259 | return QString::null; |
255 | } | 260 | } |
256 | 261 | ||
257 | void Dialer::switchState(int newstate) | 262 | void Dialer::switchState(int newstate) |
258 | { | 263 | { |
259 | int oldstate = state; | 264 | int oldstate = state; |
260 | state = newstate; | 265 | state = newstate; |
261 | 266 | ||
262 | switch(state) | 267 | switch(state) |
263 | { | 268 | { |
264 | case state_cancel: | 269 | case state_cancel: |
265 | status->setText(QObject::tr("Cancelling...")); | 270 | status->setText(QObject::tr("Cancelling...")); |