summaryrefslogtreecommitdiff
path: root/noncore
authorjosef <josef>2002-10-13 15:11:18 (UTC)
committer josef <josef>2002-10-13 15:11:18 (UTC)
commit5db679753dac04095a2fa4b03297785ed4ba4030 (patch) (side-by-side diff)
treef54ffa84bbe6fdbd15b227a0b04667714ce9106c /noncore
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') (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
@@ -2,102 +2,185 @@
#include <qlayout.h>
#include <qprogressbar.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qapp.h>
+#include <qtimer.h>
+
+// State machine: | When an error occurs, we don't have to
+// | reset everything.
+// (init) <------+ | But if the user wants to reset,
+// | | | we stop dialing immediately.
+// v | |
+// (options) ----+ | Following the state machine is necessary
+// | \ | to get determinable results.
+// v ^ |
+// (dial) ----+ |
+// | ^ |
+// v | |
+// (online) --+ |
+// | |
+// v |
Dialer::Dialer(const QString& number, QWidget *parent, const char *name)
: QDialog(parent, name, true)
{
QVBoxLayout *vbox;
QLabel *desc;
+ usercancel = 0;
+ m_number = number;
+
desc = new QLabel(QObject::tr("Dialing number: %1").arg(number), this);
progress = new QProgressBar(this);
status = new QLabel("", this);
status->setFrameStyle(QFrame::Panel | QFrame::Sunken);
cancel = new QPushButton(QObject::tr("Cancel"), this);
vbox = new QVBoxLayout(this, 2);
vbox->add(desc);
vbox->add(progress);
vbox->add(status);
vbox->add(cancel);
- reset();
-
connect(cancel, SIGNAL(clicked()), SLOT(slotCancel()));
show();
- dial(number);
+ QTimer::singleShot(500, this, SLOT(slotAutostart()));
}
Dialer::~Dialer()
{
}
void Dialer::slotCancel()
{
if(state != state_online) reset();
- close();
+ else accept();
}
void Dialer::reset()
{
- switchState(state_init);
+ switchState(state_cancel);
+ usercancel = 1;
+}
+
+void Dialer::slotAutostart()
+{
+ state = state_preinit;
+ dial(m_number);
}
void Dialer::dial(const QString& number)
{
- send("ATZ");
- QString response = receive();
+ while(state != state_online)
+ {
+ if(!usercancel)
+ {
+ trydial(number);
+ }
+ else break;
+ }
+
+ if(usercancel)
+ {
+ reject();
+ }
+}
+
+void Dialer::trydial(const QString& number)
+{
+ if(state != state_cancel)
+ {
+ switchState(state_preinit);
+ // ...
+ QString response = receive();
+ }
+
+ if(state != state_cancel)
+ {
+ switchState(state_init);
+ send("ATZ");
+ QString response2 = receive();
+ }
- switchState(state_options);
+ if(state != state_cancel)
+ {
+ switchState(state_options);
- send("ATM0L0");
- QString response2 = receive();
+ send("ATM0L0");
+ QString response3 = receive();
+ }
- switchState(state_dialing);
+ if(state != state_cancel)
+ {
+ switchState(state_dialtone);
- send(QString("ATDT %1").arg(number));
- QString response3 = receive();
+ send("ATX1");
+ QString response4 = receive();
+ }
- switchState(state_online);
+ if(state != state_cancel)
+ {
+ switchState(state_dialing);
+
+ send(QString("ATDT %1").arg(number));
+ QString response5 = receive();
+ }
+
+ if(state != state_cancel)
+ {
+ switchState(state_online);
+ }
}
void Dialer::send(const QString& msg)
{
}
QString Dialer::receive()
{
- for(int i = 0; i < 200000; i++)
+ 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..."));
+ progress->setProgress(0);
+ break;
+ case state_preinit:
+ status->setText(QObject::tr("Searching modem"));
+ progress->setProgress(10);
+ break;
case state_init:
status->setText(QObject::tr("Initializing..."));
- progress->setProgress(10);
+ progress->setProgress(20);
break;
case state_options:
status->setText(QObject::tr("Reset speakers"));
- progress->setProgress(20);
+ progress->setProgress(30);
+ break;
+ case state_dialtone:
+ status->setText(QObject::tr("Turning off dialtone"));
+ progress->setProgress(40);
break;
case state_dialing:
- status->setText(QObject::tr("Dial number"));
- progress->setProgress(30);
+ if(oldstate != state_dialing) status->setText(QObject::tr("Dial number"));
+ else status->setText(QObject::tr("Line busy, redialing number"));
+ progress->setProgress(50);
break;
case state_online:
status->setText(QObject::tr("Connection established"));
progress->setProgress(100);
cancel->setText(QObject::tr("Dismiss"));
break;
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
@@ -12,31 +12,38 @@ class Dialer : public QDialog
public:
Dialer(const QString& number, QWidget *parent = NULL, const char *name = NULL);
~Dialer();
public slots:
void slotCancel();
+ void slotAutostart();
private:
void switchState(int newstate);
void reset();
void dial(const QString& number);
+ void trydial(const QString& number);
void send(const QString& msg);
QString receive();
enum States
{
+ state_cancel,
+ state_preinit,
state_init,
state_options,
+ state_dialtone,
state_dialing,
state_online
};
QLabel *status;
QProgressBar *progress;
QPushButton *cancel;
int state;
+ int usercancel;
+ QString m_number;
};
#endif