summaryrefslogtreecommitdiff
authorjosef <josef>2002-10-13 15:52:00 (UTC)
committer josef <josef>2002-10-13 15:52:00 (UTC)
commitcb816d85c54242f8958ff77fba334b43be0dcb3d (patch) (side-by-side diff)
tree6764b80acf8789c410cdc59cb308f3f91fcd9083
parent6a9726437a59cf3b18bf57d6e20fb2dfaaa2fc34 (diff)
downloadopie-cb816d85c54242f8958ff77fba334b43be0dcb3d.zip
opie-cb816d85c54242f8958ff77fba334b43be0dcb3d.tar.gz
opie-cb816d85c54242f8958ff77fba334b43be0dcb3d.tar.bz2
- make dialer accessible transparently when opening a modem session
- implement sending data (currently written to stdout for debug purpose)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/dialer.cpp50
-rw-r--r--noncore/apps/opie-console/dialer.h6
-rw-r--r--noncore/apps/opie-console/io_modem.cpp13
-rw-r--r--noncore/apps/opie-console/io_modem.h1
-rw-r--r--noncore/apps/opie-console/opie-console.pro6
5 files changed, 63 insertions, 13 deletions
diff --git a/noncore/apps/opie-console/dialer.cpp b/noncore/apps/opie-console/dialer.cpp
index 8589d14..d20965a 100644
--- a/noncore/apps/opie-console/dialer.cpp
+++ b/noncore/apps/opie-console/dialer.cpp
@@ -1,189 +1,227 @@
#include "dialer.h"
#include <qlayout.h>
#include <qprogressbar.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qapp.h>
#include <qtimer.h>
+#include <unistd.h>
+#include <string.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)
+
+// from atconfigdialog
+//initStringLine->setText( config.readEntry("InitString", MODEM_DEFAULT_INIT_STRING ) );
+//resetStringLine->setText( config.readEntry("ResetString", MODEM_DEFAULT_RESET_STRING ) );
+//dialPref1Line->setText( config.readEntry("DialPrefix1", MODEM_DEFAULT_DIAL_PREFIX1 ) );
+//dialSuf1Line->setText( config.readEntry("DialSuffix1", MODEM_DEFAULT_DIAL_SUFFIX1 ) );
+//dialPref2Line->setText( config.readEntry("DialPrefix2", MODEM_DEFAULT_DIAL_PREFIX1 ) );
+//dialSuf2Line->setText( config.readEntry("DialSuffix2", MODEM_DEFAULT_DIAL_SUFFIX1 ) );
+//dialPref3Line->setText( config.readEntry("DialPrefix3", MODEM_DEFAULT_DIAL_PREFIX1 ) );
+//dialSuf3Line->setText( config.readEntry("DialSuffix3", MODEM_DEFAULT_DIAL_SUFFIX1 ) );
+//connectLine->setText( config.readEntry("DefaultConnect" MODEM_DEFAULT_CONNECT_STRING ) );
+//hangupLine->setText( config.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING ) );
+
+// from modemconfigwidget
+//int rad_flow = prof.readNumEntry("Flow");
+//int rad_parity = prof.readNumEntry("Parity");
+//int speed = prof.readNumEntry("Speed");
+//QString number = prof.readEntry("Number");
+
+Dialer::Dialer(const Profile& profile, QWidget *parent, const char *name)
: QDialog(parent, name, true)
{
QVBoxLayout *vbox;
QLabel *desc;
usercancel = 0;
- m_number = number;
+ m_profile = profile;
- desc = new QLabel(QObject::tr("Dialing number: %1").arg(number), this);
+ desc = new QLabel(QObject::tr("Dialing number: %1").arg(m_profile.readEntry("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);
connect(cancel, SIGNAL(clicked()), SLOT(slotCancel()));
show();
QTimer::singleShot(500, this, SLOT(slotAutostart()));
}
Dialer::~Dialer()
{
}
void Dialer::slotCancel()
{
- if(state != state_online) reset();
+ if(state != state_online)
+ {
+ usercancel = 1;
+ reset();
+ }
else accept();
}
void Dialer::reset()
{
switchState(state_cancel);
- usercancel = 1;
}
void Dialer::slotAutostart()
{
state = state_preinit;
- dial(m_number);
+ dial(m_profile.readEntry("Number"));
}
void Dialer::dial(const QString& number)
{
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();
}
if(state != state_cancel)
{
switchState(state_options);
send("ATM0L0");
QString response3 = receive();
}
if(state != state_cancel)
{
switchState(state_dialtone);
send("ATX1");
QString response4 = receive();
}
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 m = msg;
+ int bytes;
+ QString termination;
+ 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()));
+ if(bytes < 0)
+ {
+ reset();
+ }
}
QString Dialer::receive()
{
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(20);
break;
case state_options:
status->setText(QObject::tr("Reset speakers"));
progress->setProgress(30);
break;
case state_dialtone:
status->setText(QObject::tr("Turning off dialtone"));
progress->setProgress(40);
break;
case state_dialing:
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 20fb3c3..8c83bb6 100644
--- a/noncore/apps/opie-console/dialer.h
+++ b/noncore/apps/opie-console/dialer.h
@@ -1,49 +1,51 @@
#ifndef DIALER_H
#define DIALER_H
#include <qdialog.h>
+#include "profile.h"
+
class QLabel;
class QProgressBar;
class Dialer : public QDialog
{
Q_OBJECT
public:
- Dialer(const QString& number, QWidget *parent = NULL, const char *name = NULL);
+ Dialer(const Profile& profile, 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;
+ Profile m_profile;
};
#endif
diff --git a/noncore/apps/opie-console/io_modem.cpp b/noncore/apps/opie-console/io_modem.cpp
index 4d6035d..41febfb 100644
--- a/noncore/apps/opie-console/io_modem.cpp
+++ b/noncore/apps/opie-console/io_modem.cpp
@@ -1,66 +1,73 @@
#include "io_modem.h"
-IOModem:IOModem( const Profile &config ) : IOSerial( config ) {
+#include "dialer.h"
+IOModem:IOModem( const Profile &config ) : IOSerial( config ) {
+ m_config = config;
}
IOModem::~IOModem() {
}
void IOModem::close() {
IOSerial::close();
}
bool IOModem::open() {
-
-
IOSerial::open();
+ Dialer d(m_profile);
+ int result = d.exec();
+ if(result == QDialog::Accepted)
+ {
+ return true;
+ }
+ else return false;
}
void IOModem::reload( const Profile &config ) {
m_device = config.readEntry("Device", MODEM_DEFAULT_DEVICE);
m_baud = config.readNumEntry("Baud", MODEM_DEFAULT_BAUD);
m_parity = config.readNumEntry("Parity", MODEM_DEFAULT_PARITY);
m_dbits = config.readNumEntry("DataBits", MODEM_DEFAULT_DBITS);
m_sbits = config.readNumEntry("StopBits", MODEM_DEFAULT_SBITS);
m_flow = config.readNumEntry("Flow", MODEM_DEFAULT_FLOW);
m_initString = config.readEntry("InitString", MODEM_DEFAULT_INIT_STRING );
m_resetString = config.readEntry("ResetString", MODEM_DEFAULT_RESET_STRING );
m_dialPref1 = config.readEntry("DialPrefix1", MODEM_DEFAULT_DIAL_PREFIX1 );
m_dialSuf1 = config.readEntry("DialSuffix1", MODEM_DEFAULT_DIAL_SUFFIX1 );
m_dialPref2 = config.readEntry("DialPrefix2", MODEM_DEFAULT_DIAL_PREFIX1 );
m_dialSuf2 = config.readEntry("DialSuffix2", MODEM_DEFAULT_DIAL_SUFFIX1 );
m_dialPref3 = config.readEntry("DialPrefix3", MODEM_DEFAULT_DIAL_PREFIX1 );
m_dialSuf3 = config.readEntry("DialSuffix3", MODEM_DEFAULT_DIAL_SUFFIX1 );
m_connect = config.readEntry("DefaultConnect" MODEM_DEFAULT_CONNECT_STRING );
m_hangup = config.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING );
m_cancel = config.readEntry("CancelString" MODEM_DEFAULT_CANCEL_STRING );
m_dialTime = config.readEntry("DialTime" MODEM_DEFAULT_DIAL_TIME );
m_delayRedial = config.readEntry("DelayRedial", MODEM_DEFAULT_DELAY_REDIAL );
m_numberTries = config.readEntry("NumberTries", MODEM_DEFAULT_NUMBER_TRIES );
m_dtrDropTime = config.readEntry("DTRDRopTime", MODEM_DEFAULT_DTR_DROP_TIME );
m_bpsDetect = config.readEntry("BPSDetect", MODEM_DEFAULT_BPS_DETECT );
m_dcdLines = config.readEntry("DCDLines", MODEM_DEFAULT_DCD_LINES );
m_multiLineUntag = config.readEntry("MultiLineUntag", MODEM_DEFAULT_MULTI_LINE_UNTAG );
}
QString IOModem::identifier() const {
return "modem";
}
QString IOModem::name() const {
return "Modem IO Layer";
}
void IOIrda::slotExited(OProcess* proc ){
close();
}
diff --git a/noncore/apps/opie-console/io_modem.h b/noncore/apps/opie-console/io_modem.h
index f155eb1..6d44349 100644
--- a/noncore/apps/opie-console/io_modem.h
+++ b/noncore/apps/opie-console/io_modem.h
@@ -1,69 +1,70 @@
#ifndef OPIE_IO_MODEM
#define OPIE_IO_MODEM
#include <opie/oprocess.h>
#include "io_serial.h"
/* Default values to be used if the profile information is incomplete */
#define MODEM_DEFAULT_DEVICE "/dev/ttyS0"
#define MODEM_DEFAULT_BAUD 9600
#define MODEM_DEFAULT_PARITY 0
#define MODEM_DEFAULT_DBITS 8
#define MODEM_DEFAULT_SBITS 1
#define MODEM_DEFAULT_FLOW 0
#define MODEM_DEFAULT_INIT_STRING "~^M~ATZ^M~"
#define MODEM_DEFAULT_RESET_STRING "~^M~ATZ^M~"
#define MODEM_DEFAULT_DIAL_PREFIX1 "ATDT"
#define MODEM_DEFAULT_DIAL_SUFFIX1 "^M"
#define MODEM_DEFAULT_DIAL_PREFIX2 "ATDP"
#define MODEM_DEFAULT_DIAL_SUFFIX2 "^M"
#define MODEM_DEFAULT_DIAL_PREFIX3 "ATX1DT"
#define MODEM_DEFAULT_DIAL_SUFFIX3 ";X4D^M"
#define MODEM_DEFAULT_CONNECT_STRING "CONNECT"
#define MODEM_DEFAULT_HANGUP_STRING "~~+++~~ATH^M"
#define MODEM_DEFAULT_CANCEL_STRING "^M"
#define MODEM_DEFAULT_DIAL_TIME 45
#define MODEM_DEFAULT_DELAY_REDIAL 2
#define MODEM_DEFAULT_NUMBER_TRIES 10
#define MODEM_DEFAULT_DTR_DROP_TIME 1
#define MODEM_DEFAULT_BPS_DETECT 0 // bool
#define MODEM_DEFAULT_DCD_LINES 1 //bool
#define MODEM_DEFAULT_MULTI_LINE_UNTAG 0 // bool
/* IOSerial implements a RS232 IO Layer */
class IOModem : public IOSerial {
Q_OBJECT
public:
IOModem(const Profile &);
~IOModem();
QString identifier() const;
QString name() const;
signals:
void received(const QByteArray &);
void error(int, const QString &);
public slots:
bool open();
void close();
void reload(const Profile &);
private:
QString m_initString, m_resetString, m_dialPref1, m_dialSuf1, m_dialPref2,
m_dialSuf2, dialPref3, m_dialSuf3, m_connect, m_hangup, m_cancel;
int m_dialTime, m_delayRedial, m_numberTries, m_dtrDropTime,
m_bpsDetect, m_dcdLines, m_multiLineUntag;
+ const Profile& m_profile;
private slots:
void slotExited(OProcess* proc);
};
#endif
diff --git a/noncore/apps/opie-console/opie-console.pro b/noncore/apps/opie-console/opie-console.pro
index 0b4676b..ef6bc21 100644
--- a/noncore/apps/opie-console/opie-console.pro
+++ b/noncore/apps/opie-console/opie-console.pro
@@ -1,72 +1,74 @@
TEMPLATE = app
#CONFIG = qt warn_on release
CONFIG = qt debug
DESTDIR = $(OPIEDIR)/bin
HEADERS = io_layer.h io_serial.h io_irda.h io_bt.h\
file_layer.h filetransfer.h \
metafactory.h \
session.h \
mainwindow.h \
profile.h \
profileconfig.h \
profilemanager.h \
configwidget.h \
tabwidget.h \
configdialog.h \
emulation_layer.h \
vt102emulation.h \
common.h \
history.h \
screen.h \
keytrans.h \
widget_layer.h \
transferdialog.h \
profiledialogwidget.h \
profileeditordialog.h \
default.h \
terminalwidget.h \
iolayerbase.h \
serialconfigwidget.h irdaconfigwidget.h \
btconfigwidget.h modemconfigwidget.h \
atconfigdialog.h dialdialog.h \
emulation_widget.h procctl.h \
function_keyboard.h \
receive_layer.h filereceive.h \
- script.h
+ script.h \
+ dialer.h
SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.cpp \
file_layer.cpp filetransfer.cpp \
main.cpp \
metafactory.cpp \
session.cpp \
mainwindow.cpp \
profile.cpp \
profileconfig.cpp \
profilemanager.cpp \
tabwidget.cpp \
configdialog.cpp \
emulation_layer.cpp \
vt102emulation.cpp \
history.cpp \
screen.cpp \
keytrans.cpp \
widget_layer.cpp \
transferdialog.cpp \
profiledialogwidget.cpp \
profileeditordialog.cpp \
terminalwidget.cpp \
iolayerbase.cpp \
serialconfigwidget.cpp irdaconfigwidget.cpp \
btconfigwidget.cpp modemconfigwidget.cpp \
atconfigdialog.cpp dialdialog.cpp \
emulation_widget.cpp default.cpp procctl.cpp \
function_keyboard.cpp \
receive_layer.cpp filereceive.cpp \
- script.cpp
+ script.cpp \
+ dialer.cpp
INTERFACES = configurebase.ui editbase.ui
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe -lopie
TARGET = opie-console