Diffstat (limited to 'noncore/apps/opie-console/dialer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-console/dialer.cpp | 73 |
1 files changed, 61 insertions, 12 deletions
diff --git a/noncore/apps/opie-console/dialer.cpp b/noncore/apps/opie-console/dialer.cpp index 89a0e8d..10c16ef 100644 --- a/noncore/apps/opie-console/dialer.cpp +++ b/noncore/apps/opie-console/dialer.cpp @@ -6,9 +6,12 @@ #include <qpushbutton.h> #include <qapp.h> #include <qtimer.h> +#include <qmessagebox.h> #include <unistd.h> #include <string.h> +#include <fcntl.h> +#include <errno.h> // State machine: | When an error occurs, we don't have to // | reset everything. @@ -44,14 +47,20 @@ //int speed = prof.readNumEntry("Speed"); //QString number = prof.readEntry("Number"); -Dialer::Dialer(const Profile& profile, QWidget *parent, const char *name) -: QDialog(parent, name, true), m_profile(profile) +Dialer::Dialer(const Profile& profile, int fd, QWidget *parent, const char *name) +: QDialog(parent, name, true), m_fd(fd), m_profile(profile) { QVBoxLayout *vbox; QLabel *desc; + //m_profile.writeEntry("InitString", "ATZ"); + //m_profile.writeEntry("DialPrefix1", "ATDT"); + //m_profile.writeEntry("Termination", "\n"); + usercancel = 0; + fcntl(m_fd, F_SETFL, O_NONBLOCK); + desc = new QLabel(QObject::tr("Dialing number: %1").arg(m_profile.readEntry("Number")), this); progress = new QProgressBar(this); status = new QLabel("", this); @@ -92,7 +101,7 @@ void Dialer::reset() void Dialer::slotAutostart() { - state = state_preinit; + //state = state_preinit; dial(m_profile.readEntry("Number")); } @@ -102,6 +111,7 @@ void Dialer::dial(const QString& number) { if(!usercancel) { + state = state_preinit; trydial(number); } else break; @@ -118,16 +128,19 @@ void Dialer::trydial(const QString& number) if(state != state_cancel) { switchState(state_preinit); - // ... - QString response = receive(); + send("+++ATH"); + send(""); + //QString response = receive(); } if(state != state_cancel) { switchState(state_init); - //send("ATZ"); - send(m_profile.readEntry("InitString")); + send("ATZ"); + //send(m_profile.readEntry("InitString")); QString response2 = receive(); + if(!response2.contains("\nOK\r")) + reset(); } if(state != state_cancel) @@ -136,6 +149,8 @@ void Dialer::trydial(const QString& number) send("ATM0L0"); QString response3 = receive(); + if(!response3.contains("\nOK\r")) + reset(); } if(state != state_cancel) @@ -144,14 +159,24 @@ void Dialer::trydial(const QString& number) send("ATX1"); QString response4 = receive(); + if(!response4.contains("\nOK\r")) + reset(); } if(state != state_cancel) { switchState(state_dialing); - send(QString("%1 %2").arg(m_profile.readEntry("DialPrefix1")).arg(number)); + 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")) + { + QMessageBox::warning(this, + QObject::tr("Failure"), + QObject::tr("Dialing the number failed.")); + slotCancel(); + } } if(state != state_cancel) @@ -166,12 +191,15 @@ void Dialer::send(const QString& msg) int bytes; QString termination; - termination = m_profile.readEntry("Termination"); +qWarning("Sending: '%s'", m.latin1()); + + termination = "\r"; + //termination = m_profile.readEntry("Termination"); if(termination == "\n") m = m + "\n"; else if(termination == "\r") m = m + "\r"; else m = m + "\r\n"; - bytes = write(0, m.local8Bit(), strlen(m.local8Bit())); + bytes = ::write(m_fd, m.local8Bit(), strlen(m.local8Bit())); if(bytes < 0) { reset(); @@ -180,8 +208,29 @@ void Dialer::send(const QString& msg) QString Dialer::receive() { - for(int i = 0; i < 200000;i++) - qApp->processEvents(); + char buffer[1024]; + int ret; + + 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); + } + else if(ret < 0) + { + if(errno != EAGAIN) reset(); + } + } + + //for(int i = 0; i < 200000;i++) + // qApp->processEvents(); return QString::null; } |