Diffstat (limited to 'noncore/apps/opie-console/dialer.cpp') (more/less context) (ignore whitespace changes)
-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 @@ -110,81 +110,88 @@ void Dialer::dial(const QString& number) while(state != state_online) { if(!usercancel) { state = state_preinit; trydial(number); } else break; } if(usercancel) { + // modem hangup + trydial(QString::null); reject(); } } void Dialer::trydial(const QString& number) { - if(state != state_cancel) - { - switchState(state_preinit); + //if(state != state_cancel) + //{ + if(state != state_cancel) switchState(state_preinit); send("+++ATH"); send(""); //QString response = receive(); - } + //} if(state != state_cancel) { switchState(state_init); send("ATZ"); //send(m_profile.readEntry("InitString")); QString response2 = receive(); if(!response2.contains("\nOK\r")) reset(); } if(state != state_cancel) { switchState(state_options); - send("ATM0L0"); + send("ATM3L3"); QString response3 = receive(); if(!response3.contains("\nOK\r")) reset(); } if(state != state_cancel) { switchState(state_dialtone); send("ATX1"); QString response4 = receive(); if(!response4.contains("\nOK\r")) reset(); } if(state != state_cancel) { switchState(state_dialing); send(QString("ATDT %1").arg(number)); //send(QString("%1 %2").arg(m_profile.readEntry("DialPrefix1")).arg(number)); QString response5 = receive(); - if(!response5.contains("\nOK\r")) + if(!response5.contains("\nCONNECT")) { - QMessageBox::warning(this, - QObject::tr("Failure"), - QObject::tr("Dialing the number failed.")); - slotCancel(); + if(response5.contains("BUSY")) + switchState(state_dialing); + else + { + QMessageBox::warning(this, + QObject::tr("Failure"), + QObject::tr("Dialing the number failed.")); + slotCancel(); + } } } if(state != state_cancel) { switchState(state_online); } } void Dialer::send(const QString& msg) { QString m = msg; @@ -199,47 +206,53 @@ qWarning("Sending: '%s'", m.latin1()); else if(termination == "\r") m = m + "\r"; else m = m + "\r\n"; bytes = ::write(m_fd, m.local8Bit(), strlen(m.local8Bit())); if(bytes < 0) { reset(); } } QString Dialer::receive() { + QString buf; char buffer[1024]; int ret; + qApp->processEvents(); + while(1) { ret = ::read(m_fd, buffer, sizeof(buffer)); if(ret > 0) { for(int i = 0; i < ret; i++) buffer[i] = buffer[i] & 0x7F; buffer[ret] = 0; - qWarning("Receiving: '%s'", buffer); - return QString(buffer); +qWarning("Got: '%s'", buffer); + buf.append(QString(buffer)); + if(buf.contains("OK") || buf.contains("ERROR") || buf.contains("CONNECT") || (buf.contains("BUSY"))) +{ +qWarning("Receiving: '%s'", buf.latin1()); + return buf; +} } else if(ret < 0) { if(errno != EAGAIN) reset(); } } - //for(int i = 0; i < 200000;i++) - // qApp->processEvents(); return QString::null; } void Dialer::switchState(int newstate) { int oldstate = state; state = newstate; switch(state) { case state_cancel: status->setText(QObject::tr("Cancelling...")); |